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>
51 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
53 #if defined(__NetBSD__) || defined(__FreeBSD__)
57 #include <sys/signal.h>
59 #include <sys/ioctl.h>
64 #include <dahdi/user.h>
65 #include <dahdi/tonezone.h>
66 #include "sig_analog.h"
67 /* Analog signaling is currently still present in chan_dahdi for use with
68 * radio. Sig_analog does not currently handle any radio operations. If
69 * radio only uses analog signaling, then the radio handling logic could
70 * be placed in sig_analog and the duplicated code could be removed.
79 #endif /* defined(HAVE_SS7) */
82 /* put this here until sig_mfcr2 comes along */
83 #define SIG_MFCR2_MAX_CHANNELS 672 /*!< No more than a DS3 per trunk group */
87 #include "asterisk/lock.h"
88 #include "asterisk/channel.h"
89 #include "asterisk/config.h"
90 #include "asterisk/module.h"
91 #include "asterisk/pbx.h"
92 #include "asterisk/file.h"
93 #include "asterisk/ulaw.h"
94 #include "asterisk/alaw.h"
95 #include "asterisk/callerid.h"
96 #include "asterisk/adsi.h"
97 #include "asterisk/cli.h"
98 #include "asterisk/cdr.h"
99 #include "asterisk/cel.h"
100 #include "asterisk/features.h"
101 #include "asterisk/musiconhold.h"
102 #include "asterisk/say.h"
103 #include "asterisk/tdd.h"
104 #include "asterisk/app.h"
105 #include "asterisk/dsp.h"
106 #include "asterisk/astdb.h"
107 #include "asterisk/manager.h"
108 #include "asterisk/causes.h"
109 #include "asterisk/term.h"
110 #include "asterisk/utils.h"
111 #include "asterisk/transcap.h"
112 #include "asterisk/stringfields.h"
113 #include "asterisk/abstract_jb.h"
114 #include "asterisk/smdi.h"
115 #include "asterisk/astobj.h"
116 #include "asterisk/event.h"
117 #include "asterisk/devicestate.h"
118 #include "asterisk/paths.h"
119 #include "asterisk/ccss.h"
120 #include "asterisk/data.h"
123 <application name="DAHDISendKeypadFacility" language="en_US">
125 Send digits out of band over a PRI.
128 <parameter name="digits" required="true" />
131 <para>This application will send the given string of digits in a Keypad
132 Facility IE over the current channel.</para>
135 <application name="DAHDISendCallreroutingFacility" language="en_US">
137 Send an ISDN call rerouting/deflection facility message.
140 <parameter name="destination" required="true">
141 <para>Destination number.</para>
143 <parameter name="original">
144 <para>Original called number.</para>
146 <parameter name="reason">
147 <para>Diversion reason, if not specified defaults to <literal>unknown</literal></para>
151 <para>This application will send an ISDN switch specific call
152 rerouting/deflection facility message over the current channel.
153 Supported switches depend upon the version of libpri in use.</para>
156 <application name="DAHDIAcceptR2Call" language="en_US">
158 Accept an R2 call if its not already accepted (you still need to answer it)
161 <parameter name="charge" required="true">
162 <para>Yes or No.</para>
163 <para>Whether you want to accept the call with charge or without charge.</para>
167 <para>This application will Accept the R2 call either with charge or no charge.</para>
170 <manager name="DAHDITransfer" language="en_US">
172 Transfer DAHDI Channel.
175 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
176 <parameter name="DAHDIChannel" required="true">
177 <para>DAHDI channel name to transfer.</para>
181 <para>Transfer a DAHDI channel.</para>
184 <manager name="DAHDIHangup" language="en_US">
186 Hangup DAHDI Channel.
189 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
190 <parameter name="DAHDIChannel" required="true">
191 <para>DAHDI channel name to hangup.</para>
195 <para>Hangup a DAHDI channel.</para>
198 <manager name="DAHDIDialOffhook" language="en_US">
200 Dial over DAHDI channel while offhook.
203 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
204 <parameter name="DAHDIChannel" required="true" />
205 <parameter name="Number" required="true" />
210 <manager name="DAHDIDNDon" language="en_US">
212 Toggle DAHDI channel Do Not Disturb status ON.
215 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
216 <parameter name="DAHDIChannel" required="true" />
221 <manager name="DAHDIDNDoff" language="en_US">
223 Toggle DAHDI channel Do Not Disturb status OFF.
226 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
227 <parameter name="DAHDIChannel" required="true" />
232 <manager name="DAHDIShowChannels" language="en_US">
234 Show status DAHDI channels.
237 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
238 <parameter name="DAHDIChannel">
239 <para>Specify the specific channel to show. Show all channels if zero or not present.</para>
245 <manager name="DAHDIRestart" language="en_US">
247 Fully Restart DAHDI channels (terminates calls).
250 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
255 <manager name="PRIShowSpans" language="en_US">
257 Show status of PRI spans.
260 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
261 <parameter name="Span">
262 <para>Specify the specific span to show. Show all spans if zero or not present.</para>
270 #define SMDI_MD_WAIT_TIMEOUT 1500 /* 1.5 seconds */
272 static const char * const lbostr[] = {
273 "0 db (CSU)/0-133 feet (DSX-1)",
274 "133-266 feet (DSX-1)",
275 "266-399 feet (DSX-1)",
276 "399-533 feet (DSX-1)",
277 "533-655 feet (DSX-1)",
283 /*! Global jitterbuffer configuration - by default, jb is disabled
284 * \note Values shown here match the defaults shown in chan_dahdi.conf.sample */
285 static struct ast_jb_conf default_jbconf =
289 .resync_threshold = 1000,
293 static struct ast_jb_conf global_jbconf;
296 * \note Define ZHONE_HACK to cause us to go off hook and then back on hook when
297 * the user hangs up to reset the state machine so ring works properly.
298 * This is used to be able to support kewlstart by putting the zhone in
299 * groundstart mode since their forward disconnect supervision is entirely
300 * broken even though their documentation says it isn't and their support
301 * is entirely unwilling to provide any assistance with their channel banks
302 * even though their web site says they support their products for life.
304 /* #define ZHONE_HACK */
306 /*! \brief Typically, how many rings before we should send Caller*ID */
307 #define DEFAULT_CIDRINGS 1
309 #define AST_LAW(p) (((p)->law == DAHDI_LAW_ALAW) ? AST_FORMAT_ALAW : AST_FORMAT_ULAW)
312 /*! \brief Signaling types that need to use MF detection should be placed in this macro */
313 #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))
315 static const char tdesc[] = "DAHDI Telephony Driver"
316 #if defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2)
318 #if defined(HAVE_PRI)
320 #endif /* defined(HAVE_PRI) */
321 #if defined(HAVE_SS7)
322 #if defined(HAVE_PRI)
324 #endif /* defined(HAVE_PRI) */
326 #endif /* defined(HAVE_SS7) */
327 #if defined(HAVE_OPENR2)
328 #if defined(HAVE_PRI) || defined(HAVE_SS7)
330 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
332 #endif /* defined(HAVE_OPENR2) */
333 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2) */
336 static const char config[] = "chan_dahdi.conf";
338 #define SIG_EM DAHDI_SIG_EM
339 #define SIG_EMWINK (0x0100000 | DAHDI_SIG_EM)
340 #define SIG_FEATD (0x0200000 | DAHDI_SIG_EM)
341 #define SIG_FEATDMF (0x0400000 | DAHDI_SIG_EM)
342 #define SIG_FEATB (0x0800000 | DAHDI_SIG_EM)
343 #define SIG_E911 (0x1000000 | DAHDI_SIG_EM)
344 #define SIG_FEATDMF_TA (0x2000000 | DAHDI_SIG_EM)
345 #define SIG_FGC_CAMA (0x4000000 | DAHDI_SIG_EM)
346 #define SIG_FGC_CAMAMF (0x8000000 | DAHDI_SIG_EM)
347 #define SIG_FXSLS DAHDI_SIG_FXSLS
348 #define SIG_FXSGS DAHDI_SIG_FXSGS
349 #define SIG_FXSKS DAHDI_SIG_FXSKS
350 #define SIG_FXOLS DAHDI_SIG_FXOLS
351 #define SIG_FXOGS DAHDI_SIG_FXOGS
352 #define SIG_FXOKS DAHDI_SIG_FXOKS
353 #define SIG_PRI DAHDI_SIG_CLEAR
354 #define SIG_BRI (0x2000000 | DAHDI_SIG_CLEAR)
355 #define SIG_BRI_PTMP (0X4000000 | DAHDI_SIG_CLEAR)
356 #define SIG_SS7 (0x1000000 | DAHDI_SIG_CLEAR)
357 #define SIG_MFCR2 DAHDI_SIG_CAS
358 #define SIG_SF DAHDI_SIG_SF
359 #define SIG_SFWINK (0x0100000 | DAHDI_SIG_SF)
360 #define SIG_SF_FEATD (0x0200000 | DAHDI_SIG_SF)
361 #define SIG_SF_FEATDMF (0x0400000 | DAHDI_SIG_SF)
362 #define SIG_SF_FEATB (0x0800000 | DAHDI_SIG_SF)
363 #define SIG_EM_E1 DAHDI_SIG_EM_E1
366 #define NUM_SPANS DAHDI_MAX_SPANS
371 #define CHAN_PSEUDO -2
373 #define CALLPROGRESS_PROGRESS 1
374 #define CALLPROGRESS_FAX_OUTGOING 2
375 #define CALLPROGRESS_FAX_INCOMING 4
376 #define CALLPROGRESS_FAX (CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING)
378 #define NUM_CADENCE_MAX 25
379 static int num_cadence = 4;
380 static int user_has_defined_cadences = 0;
382 static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX] = {
383 { { 125, 125, 2000, 4000 } }, /*!< Quick chirp followed by normal ring */
384 { { 250, 250, 500, 1000, 250, 250, 500, 4000 } }, /*!< British style ring */
385 { { 125, 125, 125, 125, 125, 4000 } }, /*!< Three short bursts */
386 { { 1000, 500, 2500, 5000 } }, /*!< Long ring */
389 /*! \brief cidrings says in which pause to transmit the cid information, where the first pause
390 * is 1, the second pause is 2 and so on.
393 static int cidrings[NUM_CADENCE_MAX] = {
394 2, /*!< Right after first long ring */
395 4, /*!< Right after long part */
396 3, /*!< After third chirp */
397 2, /*!< Second spell */
400 /* ETSI EN300 659-1 specifies the ring pulse between 200 and 300 mS */
401 static struct dahdi_ring_cadence AS_RP_cadence = {{250, 10000}};
403 #define ISTRUNK(p) ((p->sig == SIG_FXSLS) || (p->sig == SIG_FXSKS) || \
404 (p->sig == SIG_FXSGS) || (p->sig == SIG_PRI))
406 #define CANBUSYDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
407 #define CANPROGRESSDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
409 static char defaultcic[64] = "";
410 static char defaultozz[64] = "";
412 static char parkinglot[AST_MAX_EXTENSION] = ""; /*!< Default parking lot for this channel */
414 /*! Run this script when the MWI state changes on an FXO line, if mwimonitor is enabled */
415 static char mwimonitornotify[PATH_MAX] = "";
416 #ifndef HAVE_DAHDI_LINEREVERSE_VMWI
417 static int mwisend_rpas = 0;
420 static char progzone[10] = "";
422 static int usedistinctiveringdetection = 0;
423 static int distinctiveringaftercid = 0;
425 static int numbufs = 4;
427 static int mwilevel = 512;
428 static int dtmfcid_level = 256;
430 #define REPORT_CHANNEL_ALARMS 1
431 #define REPORT_SPAN_ALARMS 2
432 static int report_alarms = REPORT_CHANNEL_ALARMS;
435 static int pridebugfd = -1;
436 static char pridebugfilename[1024] = "";
439 /*! \brief Wait up to 16 seconds for first digit (FXO logic) */
440 static int firstdigittimeout = 16000;
442 /*! \brief How long to wait for following digits (FXO logic) */
443 static int gendigittimeout = 8000;
445 /*! \brief How long to wait for an extra digit, if there is an ambiguous match */
446 static int matchdigittimeout = 3000;
448 /*! \brief Protect the interface list (of dahdi_pvt's) */
449 AST_MUTEX_DEFINE_STATIC(iflock);
452 static int ifcount = 0;
455 AST_MUTEX_DEFINE_STATIC(pridebugfdlock);
458 /*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
459 when it's doing something critical. */
460 AST_MUTEX_DEFINE_STATIC(monlock);
462 /*! \brief This is the thread for the monitor which checks for input on the channels
463 which are not currently in use. */
464 static pthread_t monitor_thread = AST_PTHREADT_NULL;
465 static ast_cond_t ss_thread_complete;
466 AST_MUTEX_DEFINE_STATIC(ss_thread_lock);
467 AST_MUTEX_DEFINE_STATIC(restart_lock);
468 static int ss_thread_count = 0;
469 static int num_restart_pending = 0;
471 static int restart_monitor(void);
473 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);
475 static int dahdi_sendtext(struct ast_channel *c, const char *text);
477 static void mwi_event_cb(const struct ast_event *event, void *userdata)
479 /* This module does not handle MWI in an event-based manner. However, it
480 * subscribes to MWI for each mailbox that is configured so that the core
481 * knows that we care about it. Then, chan_dahdi will get the MWI from the
482 * event cache instead of checking the mailbox directly. */
485 /*! \brief Avoid the silly dahdi_getevent which ignores a bunch of events */
486 static inline int dahdi_get_event(int fd)
489 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
494 /*! \brief Avoid the silly dahdi_waitevent which ignores a bunch of events */
495 static inline int dahdi_wait_event(int fd)
498 i = DAHDI_IOMUX_SIGEVENT;
499 if (ioctl(fd, DAHDI_IOMUX, &i) == -1)
501 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
506 /*! Chunk size to read -- we use 20ms chunks to make things happy. */
507 #define READ_SIZE 160
509 #define MASK_AVAIL (1 << 0) /*!< Channel available for PRI use */
510 #define MASK_INUSE (1 << 1) /*!< Channel currently in use */
512 #define CALLWAITING_SILENT_SAMPLES ((300 * 8) / READ_SIZE) /*!< 300 ms */
513 #define CALLWAITING_REPEAT_SAMPLES ((10000 * 8) / READ_SIZE) /*!< 10,000 ms */
514 #define CALLWAITING_SUPPRESS_SAMPLES ((100 * 8) / READ_SIZE) /*!< 100 ms */
515 #define CIDCW_EXPIRE_SAMPLES ((500 * 8) / READ_SIZE) /*!< 500 ms */
516 #define MIN_MS_SINCE_FLASH ((2000) ) /*!< 2000 ms */
517 #define DEFAULT_RINGT ((8000 * 8) / READ_SIZE) /*!< 8,000 ms */
522 * \brief Configured ring timeout base.
523 * \note Value computed from "ringtimeout" read in from chan_dahdi.conf if it exists.
525 static int ringt_base = DEFAULT_RINGT;
527 #if defined(HAVE_SS7)
530 struct sig_ss7_linkset ss7;
533 static struct dahdi_ss7 linksets[NUM_SPANS];
535 static int cur_ss7type = -1;
536 static int cur_linkset = -1;
537 static int cur_pointcode = -1;
538 static int cur_cicbeginswith = -1;
539 static int cur_adjpointcode = -1;
540 static int cur_networkindicator = -1;
541 static int cur_defaultdpc = -1;
542 #endif /* defined(HAVE_SS7) */
546 pthread_t r2master; /*!< Thread of master */
547 openr2_context_t *protocol_context; /*!< OpenR2 context handle */
548 struct dahdi_pvt *pvts[SIG_MFCR2_MAX_CHANNELS]; /*!< Member channel pvt structs */
549 int numchans; /*!< Number of channels in this R2 block */
550 int monitored_count; /*!< Number of channels being monitored */
553 struct dahdi_mfcr2_conf {
554 openr2_variant_t variant;
556 int metering_pulse_timeout;
559 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
563 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3
564 int dtmf_end_timeout;
566 signed int get_ani_first:2;
567 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
568 signed int skip_category_request:2;
570 unsigned int call_files:1;
571 unsigned int allow_collect_calls:1;
572 unsigned int charge_calls:1;
573 unsigned int accept_on_offer:1;
574 unsigned int forced_release:1;
575 unsigned int double_answer:1;
576 signed int immediate_accept:2;
577 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
578 signed int dtmf_dialing:2;
579 signed int dtmf_detection:2;
581 char logdir[OR2_MAX_PATH];
582 char r2proto_file[OR2_MAX_PATH];
583 openr2_log_level_t loglevel;
584 openr2_calling_party_category_t category;
587 /* malloc'd array of malloc'd r2links */
588 static struct dahdi_mfcr2 **r2links;
589 /* how many r2links have been malloc'd */
590 static int r2links_count = 0;
592 #endif /* HAVE_OPENR2 */
597 int dchannels[SIG_PRI_NUM_DCHANS]; /*!< What channel are the dchannels on */
598 int mastertrunkgroup; /*!< What trunk group is our master */
599 int prilogicalspan; /*!< Logical span number within trunk group */
600 struct sig_pri_span pri;
603 static struct dahdi_pri pris[NUM_SPANS];
605 #if defined(HAVE_PRI_CCSS)
606 /*! DAHDI PRI CCSS agent and monitor type name. */
607 static const char dahdi_pri_cc_type[] = "DAHDI/PRI";
608 #endif /* defined(HAVE_PRI_CCSS) */
611 /*! Shut up the compiler */
615 #define SUB_REAL 0 /*!< Active call */
616 #define SUB_CALLWAIT 1 /*!< Call-Waiting call on hold */
617 #define SUB_THREEWAY 2 /*!< Three-way call */
619 /* Polarity states */
620 #define POLARITY_IDLE 0
621 #define POLARITY_REV 1
624 struct distRingData {
628 struct ringContextData {
629 char contextData[AST_MAX_CONTEXT];
631 struct dahdi_distRings {
632 struct distRingData ringnum[3];
633 struct ringContextData ringContext[3];
636 static const char * const subnames[] = {
642 struct dahdi_subchannel {
644 struct ast_channel *owner;
646 short buffer[AST_FRIENDLY_OFFSET/2 + READ_SIZE];
647 struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */
648 unsigned int needringing:1;
649 unsigned int needbusy:1;
650 unsigned int needcongestion:1;
651 unsigned int needanswer:1;
652 unsigned int needflash:1;
653 unsigned int needhold:1;
654 unsigned int needunhold:1;
655 unsigned int linear:1;
656 unsigned int inthreeway:1;
657 struct dahdi_confinfo curconf;
660 #define CONF_USER_REAL (1 << 0)
661 #define CONF_USER_THIRDCALL (1 << 1)
665 /* States for sending MWI message
666 * First three states are required for send Ring Pulse Alert Signal
678 struct mwisend_info {
679 struct timeval pause;
680 mwisend_states mwisend_current;
683 /*! Specify the lists dahdi_pvt can be put in. */
685 DAHDI_IFLIST_NONE, /*!< The dahdi_pvt is not in any list. */
686 DAHDI_IFLIST_MAIN, /*!< The dahdi_pvt is in the main interface list */
687 #if defined(HAVE_PRI)
688 DAHDI_IFLIST_NO_B_CHAN, /*!< The dahdi_pvt is in a no B channel interface list */
689 #endif /* defined(HAVE_PRI) */
693 ast_mutex_t lock; /*!< Channel private lock. */
694 struct callerid_state *cs;
695 struct ast_channel *owner; /*!< Our current active owner (if applicable) */
696 /*!< Up to three channels can be associated with this call */
698 struct dahdi_subchannel sub_unused; /*!< Just a safety precaution */
699 struct dahdi_subchannel subs[3]; /*!< Sub-channels */
700 struct dahdi_confinfo saveconf; /*!< Saved conference info */
702 struct dahdi_pvt *slaves[MAX_SLAVES]; /*!< Slave to us (follows our conferencing) */
703 struct dahdi_pvt *master; /*!< Master to us (we follow their conferencing) */
704 int inconference; /*!< If our real should be in the conference */
706 int bufsize; /*!< Size of the buffers */
707 int buf_no; /*!< Number of buffers */
708 int buf_policy; /*!< Buffer policy */
709 int faxbuf_no; /*!< Number of Fax buffers */
710 int faxbuf_policy; /*!< Fax buffer policy */
711 int sig; /*!< Signalling style */
713 * \brief Nonzero if the signaling type is sent over a radio.
714 * \note Set to a couple of nonzero values but it is only tested like a boolean.
717 int outsigmod; /*!< Outbound Signalling style (modifier) */
718 int oprmode; /*!< "Operator Services" mode */
719 struct dahdi_pvt *oprpeer; /*!< "Operator Services" peer tech_pvt ptr */
720 /*! \brief Amount of gain to increase during caller id */
722 /*! \brief Rx gain set by chan_dahdi.conf */
724 /*! \brief Tx gain set by chan_dahdi.conf */
727 float txdrc; /*!< Dynamic Range Compression factor. a number between 1 and 6ish */
730 int tonezone; /*!< tone zone for this chan, or -1 for default */
731 enum DAHDI_IFLIST which_iflist; /*!< Which interface list is this structure listed? */
732 struct dahdi_pvt *next; /*!< Next channel in list */
733 struct dahdi_pvt *prev; /*!< Prev channel in list */
738 * \brief TRUE if ADSI (Analog Display Services Interface) available
739 * \note Set from the "adsi" value read in from chan_dahdi.conf
743 * \brief TRUE if we can use a polarity reversal to mark when an outgoing
744 * call is answered by the remote party.
745 * \note Set from the "answeronpolarityswitch" value read in from chan_dahdi.conf
747 unsigned int answeronpolarityswitch:1;
749 * \brief TRUE if busy detection is enabled.
750 * (Listens for the beep-beep busy pattern.)
751 * \note Set from the "busydetect" value read in from chan_dahdi.conf
753 unsigned int busydetect:1;
755 * \brief TRUE if call return is enabled.
756 * (*69, if your dialplan doesn't catch this first)
757 * \note Set from the "callreturn" value read in from chan_dahdi.conf
759 unsigned int callreturn:1;
761 * \brief TRUE if busy extensions will hear the call-waiting tone
762 * and can use hook-flash to switch between callers.
763 * \note Can be disabled by dialing *70.
764 * \note Initialized with the "callwaiting" value read in from chan_dahdi.conf
766 unsigned int callwaiting:1;
768 * \brief TRUE if send caller ID for Call Waiting
769 * \note Set from the "callwaitingcallerid" value read in from chan_dahdi.conf
771 unsigned int callwaitingcallerid:1;
773 * \brief TRUE if support for call forwarding enabled.
774 * Dial *72 to enable call forwarding.
775 * Dial *73 to disable call forwarding.
776 * \note Set from the "cancallforward" value read in from chan_dahdi.conf
778 unsigned int cancallforward:1;
780 * \brief TRUE if support for call parking is enabled.
781 * \note Set from the "canpark" value read in from chan_dahdi.conf
783 unsigned int canpark:1;
784 /*! \brief TRUE if to wait for a DTMF digit to confirm answer */
785 unsigned int confirmanswer:1;
787 * \brief TRUE if the channel is to be destroyed on hangup.
788 * (Used by pseudo channels.)
790 unsigned int destroy:1;
791 unsigned int didtdd:1; /*!< flag to say its done it once */
792 /*! \brief TRUE if analog type line dialed no digits in Dial() */
793 unsigned int dialednone:1;
795 * \brief TRUE if in the process of dialing digits or sending something.
796 * \note This is used as a receive squelch for ISDN until connected.
798 unsigned int dialing:1;
799 /*! \brief TRUE if the transfer capability of the call is digital. */
800 unsigned int digital:1;
801 /*! \brief TRUE if Do-Not-Disturb is enabled, present only for non sig_analog */
803 /*! \brief XXX BOOLEAN Purpose??? */
804 unsigned int echobreak:1;
806 * \brief TRUE if echo cancellation enabled when bridged.
807 * \note Initialized with the "echocancelwhenbridged" value read in from chan_dahdi.conf
808 * \note Disabled if the echo canceller is not setup.
810 unsigned int echocanbridged:1;
811 /*! \brief TRUE if echo cancellation is turned on. */
812 unsigned int echocanon:1;
813 /*! \brief TRUE if a fax tone has already been handled. */
814 unsigned int faxhandled:1;
815 /*! TRUE if dynamic faxbuffers are configured for use, default is OFF */
816 unsigned int usefaxbuffers:1;
817 /*! TRUE while buffer configuration override is in use */
818 unsigned int bufferoverrideinuse:1;
819 /*! \brief TRUE if over a radio and dahdi_read() has been called. */
820 unsigned int firstradio:1;
822 * \brief TRUE if the call will be considered "hung up" on a polarity reversal.
823 * \note Set from the "hanguponpolarityswitch" value read in from chan_dahdi.conf
825 unsigned int hanguponpolarityswitch:1;
826 /*! \brief TRUE if DTMF detection needs to be done by hardware. */
827 unsigned int hardwaredtmf:1;
829 * \brief TRUE if the outgoing caller ID is blocked/hidden.
830 * \note Caller ID can be disabled by dialing *67.
831 * \note Caller ID can be enabled by dialing *82.
832 * \note Initialized with the "hidecallerid" value read in from chan_dahdi.conf
834 unsigned int hidecallerid:1;
836 * \brief TRUE if hide just the name not the number for legacy PBX use.
837 * \note Only applies to PRI channels.
838 * \note Set from the "hidecalleridname" value read in from chan_dahdi.conf
840 unsigned int hidecalleridname:1;
841 /*! \brief TRUE if DTMF detection is disabled. */
842 unsigned int ignoredtmf:1;
844 * \brief TRUE if the channel should be answered immediately
845 * without attempting to gather any digits.
846 * \note Set from the "immediate" value read in from chan_dahdi.conf
848 unsigned int immediate:1;
849 /*! \brief TRUE if in an alarm condition. */
850 unsigned int inalarm:1;
851 /*! \brief TRUE if TDD in MATE mode */
853 /*! \brief TRUE if we originated the call leg. */
854 unsigned int outgoing:1;
855 /* unsigned int overlapdial:1; unused and potentially confusing */
857 * \brief TRUE if busy extensions will hear the call-waiting tone
858 * and can use hook-flash to switch between callers.
859 * \note Set from the "callwaiting" value read in from chan_dahdi.conf
861 unsigned int permcallwaiting:1;
863 * \brief TRUE if the outgoing caller ID is blocked/restricted/hidden.
864 * \note Set from the "hidecallerid" value read in from chan_dahdi.conf
866 unsigned int permhidecallerid:1;
868 * \brief TRUE if PRI congestion/busy indications are sent out-of-band.
869 * \note Set from the "priindication" value read in from chan_dahdi.conf
871 unsigned int priindication_oob:1;
873 * \brief TRUE if PRI B channels are always exclusively selected.
874 * \note Set from the "priexclusive" value read in from chan_dahdi.conf
876 unsigned int priexclusive:1;
878 * \brief TRUE if we will pulse dial.
879 * \note Set from the "pulsedial" value read in from chan_dahdi.conf
881 unsigned int pulse:1;
882 /*! \brief TRUE if a pulsed digit was detected. (Pulse dial phone detected) */
883 unsigned int pulsedial:1;
884 unsigned int restartpending:1; /*!< flag to ensure counted only once for restart */
886 * \brief TRUE if caller ID is restricted.
887 * \note Set but not used. Should be deleted. Redundant with permhidecallerid.
888 * \note Set from the "restrictcid" value read in from chan_dahdi.conf
890 unsigned int restrictcid:1;
892 * \brief TRUE if three way calling is enabled
893 * \note Set from the "threewaycalling" value read in from chan_dahdi.conf
895 unsigned int threewaycalling:1;
897 * \brief TRUE if call transfer is enabled
898 * \note For FXS ports (either direct analog or over T1/E1):
899 * Support flash-hook call transfer
900 * \note For digital ports using ISDN PRI protocols:
901 * Support switch-side transfer (called 2BCT, RLT or other names)
902 * \note Set from the "transfer" value read in from chan_dahdi.conf
904 unsigned int transfer:1;
906 * \brief TRUE if caller ID is used on this channel.
907 * \note PRI and SS7 spans will save caller ID from the networking peer.
908 * \note FXS ports will generate the caller ID spill.
909 * \note FXO ports will listen for the caller ID spill.
910 * \note Set from the "usecallerid" value read in from chan_dahdi.conf
912 unsigned int use_callerid:1;
914 * \brief TRUE if we will use the calling presentation setting
915 * from the Asterisk channel for outgoing calls.
916 * \note Only applies to PRI and SS7 channels.
917 * \note Set from the "usecallingpres" value read in from chan_dahdi.conf
919 unsigned int use_callingpres:1;
921 * \brief TRUE if distinctive rings are to be detected.
922 * \note For FXO lines
923 * \note Set indirectly from the "usedistinctiveringdetection" value read in from chan_dahdi.conf
925 unsigned int usedistinctiveringdetection:1;
927 * \brief TRUE if we should use the callerid from incoming call on dahdi transfer.
928 * \note Set from the "useincomingcalleridondahditransfer" value read in from chan_dahdi.conf
930 unsigned int dahditrcallerid:1;
932 * \brief TRUE if allowed to flash-transfer to busy channels.
933 * \note Set from the "transfertobusy" value read in from chan_dahdi.conf
935 unsigned int transfertobusy:1;
937 * \brief TRUE if the FXO port monitors for neon type MWI indications from the other end.
938 * \note Set if the "mwimonitor" value read in contains "neon" from chan_dahdi.conf
940 unsigned int mwimonitor_neon:1;
942 * \brief TRUE if the FXO port monitors for fsk type MWI indications from the other end.
943 * \note Set if the "mwimonitor" value read in contains "fsk" from chan_dahdi.conf
945 unsigned int mwimonitor_fsk:1;
947 * \brief TRUE if the FXO port monitors for rpas precursor to fsk MWI indications from the other end.
948 * \note RPAS - Ring Pulse Alert Signal
949 * \note Set if the "mwimonitor" value read in contains "rpas" from chan_dahdi.conf
951 unsigned int mwimonitor_rpas:1;
952 /*! \brief TRUE if an MWI monitor thread is currently active */
953 unsigned int mwimonitoractive:1;
954 /*! \brief TRUE if a MWI message sending thread is active */
955 unsigned int mwisendactive:1;
957 * \brief TRUE if channel is out of reset and ready
958 * \note Set but not used.
960 unsigned int inservice:1;
962 * \brief TRUE if the channel is locally blocked.
963 * \note Applies to SS7 and MFCR2 channels.
965 unsigned int locallyblocked:1;
967 * \brief TRUE if the channel is remotely blocked.
968 * \note Applies to SS7 and MFCR2 channels.
970 unsigned int remotelyblocked:1;
972 * \brief TRUE if the channel alarms will be managed also as Span ones
973 * \note Applies to all channels
975 unsigned int manages_span_alarms:1;
977 #if defined(HAVE_PRI)
978 struct sig_pri_span *pri;
982 * \brief TRUE if SMDI (Simplified Message Desk Interface) is enabled
983 * \note Set from the "usesmdi" value read in from chan_dahdi.conf
985 unsigned int use_smdi:1;
986 struct mwisend_info mwisend_data;
987 /*! \brief The SMDI interface to get SMDI messages from. */
988 struct ast_smdi_interface *smdi_iface;
990 /*! \brief Distinctive Ring data */
991 struct dahdi_distRings drings;
994 * \brief The configured context for incoming calls.
995 * \note The "context" string read in from chan_dahdi.conf
997 char context[AST_MAX_CONTEXT];
999 * \brief A description for the channel configuration
1000 * \note The "description" string read in from chan_dahdi.conf
1002 char description[32];
1004 * \brief Saved context string.
1006 char defcontext[AST_MAX_CONTEXT];
1007 /*! \brief Extension to use in the dialplan. */
1008 char exten[AST_MAX_EXTENSION];
1010 * \brief Language configured for calls.
1011 * \note The "language" string read in from chan_dahdi.conf
1013 char language[MAX_LANGUAGE];
1015 * \brief The configured music-on-hold class to use for calls.
1016 * \note The "musicclass" or "mohinterpret" or "musiconhold" string read in from chan_dahdi.conf
1018 char mohinterpret[MAX_MUSICCLASS];
1020 * \brief Suggested music-on-hold class for peer channel to use for calls.
1021 * \note The "mohsuggest" string read in from chan_dahdi.conf
1023 char mohsuggest[MAX_MUSICCLASS];
1024 char parkinglot[AST_MAX_EXTENSION]; /*!< Parking lot for this channel */
1025 #if defined(HAVE_PRI) || defined(HAVE_SS7)
1026 /*! \brief Automatic Number Identification number (Alternate PRI caller ID number) */
1027 char cid_ani[AST_MAX_EXTENSION];
1028 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
1029 /*! \brief Automatic Number Identification code from PRI */
1031 /*! \brief Caller ID number from an incoming call. */
1032 char cid_num[AST_MAX_EXTENSION];
1034 * \brief Caller ID tag from incoming call
1035 * \note the "cid_tag" string read in from chan_dahdi.conf
1037 char cid_tag[AST_MAX_EXTENSION];
1038 /*! \brief Caller ID Q.931 TON/NPI field values. Set by PRI. Zero otherwise. */
1040 /*! \brief Caller ID name from an incoming call. */
1041 char cid_name[AST_MAX_EXTENSION];
1042 /*! \brief Caller ID subaddress from an incoming call. */
1043 char cid_subaddr[AST_MAX_EXTENSION];
1044 char *origcid_num; /*!< malloced original callerid */
1045 char *origcid_name; /*!< malloced original callerid */
1046 /*! \brief Call waiting number. */
1047 char callwait_num[AST_MAX_EXTENSION];
1048 /*! \brief Call waiting name. */
1049 char callwait_name[AST_MAX_EXTENSION];
1050 /*! \brief Redirecting Directory Number Information Service (RDNIS) number */
1051 char rdnis[AST_MAX_EXTENSION];
1052 /*! \brief Dialed Number Identifier */
1053 char dnid[AST_MAX_EXTENSION];
1055 * \brief Bitmapped groups this belongs to.
1056 * \note The "group" bitmapped group string read in from chan_dahdi.conf
1059 /*! \brief Default call PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW. */
1061 /*! \brief Active PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW */
1063 int confno; /*!< Our conference */
1064 int confusers; /*!< Who is using our conference */
1065 int propconfno; /*!< Propagated conference number */
1067 * \brief Bitmapped call groups this belongs to.
1068 * \note The "callgroup" bitmapped group string read in from chan_dahdi.conf
1070 ast_group_t callgroup;
1072 * \brief Bitmapped pickup groups this belongs to.
1073 * \note The "pickupgroup" bitmapped group string read in from chan_dahdi.conf
1075 ast_group_t pickupgroup;
1077 * \brief Channel variable list with associated values to set when a channel is created.
1078 * \note The "setvar" strings read in from chan_dahdi.conf
1080 struct ast_variable *vars;
1081 int channel; /*!< Channel Number */
1082 int span; /*!< Span number */
1083 time_t guardtime; /*!< Must wait this much time before using for new call */
1084 int cid_signalling; /*!< CID signalling type bell202 or v23 */
1085 int cid_start; /*!< CID start indicator, polarity or ring or DTMF without warning event */
1086 int dtmfcid_holdoff_state; /*!< State indicator that allows for line to settle before checking for dtmf energy */
1087 struct timeval dtmfcid_delay; /*!< Time value used for allow line to settle */
1088 int callingpres; /*!< The value of calling presentation that we're going to use when placing a PRI call */
1089 int callwaitingrepeat; /*!< How many samples to wait before repeating call waiting */
1090 int cidcwexpire; /*!< When to stop waiting for CID/CW CAS response (In samples) */
1091 int cid_suppress_expire; /*!< How many samples to suppress after a CID spill. */
1092 /*! \brief Analog caller ID waveform sample buffer */
1093 unsigned char *cidspill;
1094 /*! \brief Position in the cidspill buffer to send out next. */
1096 /*! \brief Length of the cidspill buffer containing samples. */
1098 /*! \brief Ring timeout timer?? */
1101 * \brief Ring timeout base.
1102 * \note Value computed indirectly from "ringtimeout" read in from chan_dahdi.conf
1106 * \brief Number of most significant digits/characters to strip from the dialed number.
1107 * \note Feature is deprecated. Use dialplan logic.
1108 * \note The characters are stripped before the PRI TON/NPI prefix
1109 * characters are processed.
1113 * \brief TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
1115 * After CAS is sent, the call waiting caller id will be sent if the phone
1116 * gives a positive reply.
1119 /*! \brief Number of call waiting rings. */
1121 /*! \brief Echo cancel parameters. */
1123 struct dahdi_echocanparams head;
1124 struct dahdi_echocanparam params[DAHDI_MAX_ECHOCANPARAMS];
1127 * \brief Echo training time. 0 = disabled
1128 * \note Set from the "echotraining" value read in from chan_dahdi.conf
1131 /*! \brief Filled with 'w'. XXX Purpose?? */
1134 * \brief Number of times to see "busy" tone before hanging up.
1135 * \note Set from the "busycount" value read in from chan_dahdi.conf
1139 * \brief Busy cadence pattern description.
1140 * \note Set from the "busypattern" value read from chan_dahdi.conf
1142 struct ast_dsp_busy_pattern busy_cadence;
1144 * \brief Bitmapped call progress detection flags. CALLPROGRESS_xxx values.
1145 * \note Bits set from the "callprogress" and "faxdetect" values read in from chan_dahdi.conf
1149 * \brief Number of milliseconds to wait for dialtone.
1150 * \note Set from the "waitfordialtone" value read in from chan_dahdi.conf
1152 int waitfordialtone;
1153 struct timeval waitingfordt; /*!< Time we started waiting for dialtone */
1154 struct timeval flashtime; /*!< Last flash-hook time */
1155 /*! \brief Opaque DSP configuration structure. */
1156 struct ast_dsp *dsp;
1157 /*! \brief DAHDI dial operation command struct for ioctl() call. */
1158 struct dahdi_dialoperation dop;
1159 int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
1160 /*! \brief Second part of SIG_FEATDMF_TA wink operation. */
1162 char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
1163 int amaflags; /*!< AMA Flags */
1164 struct tdd_state *tdd; /*!< TDD flag */
1165 /*! \brief Accumulated call forwarding number. */
1166 char call_forward[AST_MAX_EXTENSION];
1168 * \brief Voice mailbox location.
1169 * \note Set from the "mailbox" string read in from chan_dahdi.conf
1171 char mailbox[AST_MAX_EXTENSION];
1172 /*! \brief Opaque event subscription parameters for message waiting indication support. */
1173 struct ast_event_sub *mwi_event_sub;
1174 /*! \brief Delayed dialing for E911. Overlap digits for ISDN. */
1176 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
1177 struct dahdi_vmwi_info mwisend_setting; /*!< Which VMWI methods to use */
1178 unsigned int mwisend_fsk: 1; /*! Variable for enabling FSK MWI handling in chan_dahdi */
1179 unsigned int mwisend_rpas:1; /*! Variable for enabling Ring Pulse Alert before MWI FSK Spill */
1181 int distinctivering; /*!< Which distinctivering to use */
1182 int dtmfrelax; /*!< whether to run in relaxed DTMF mode */
1183 /*! \brief Holding place for event injected from outside normal operation. */
1186 * \brief Minimal time period (ms) between the answer polarity
1187 * switch and hangup polarity switch.
1189 int polarityonanswerdelay;
1190 /*! \brief Start delay time if polarityonanswerdelay is nonzero. */
1191 struct timeval polaritydelaytv;
1193 * \brief Send caller ID on FXS after this many rings. Set to 1 for US.
1194 * \note Set from the "sendcalleridafter" value read in from chan_dahdi.conf
1196 int sendcalleridafter;
1197 /*! \brief Current line interface polarity. POLARITY_IDLE, POLARITY_REV */
1199 /*! \brief DSP feature flags: DSP_FEATURE_xxx */
1201 #if defined(HAVE_SS7)
1202 /*! \brief SS7 control parameters */
1203 struct sig_ss7_linkset *ss7;
1204 #endif /* defined(HAVE_SS7) */
1206 struct dahdi_mfcr2 *mfcr2;
1207 openr2_chan_t *r2chan;
1208 openr2_calling_party_category_t mfcr2_recvd_category;
1209 openr2_calling_party_category_t mfcr2_category;
1210 int mfcr2_dnis_index;
1211 int mfcr2_ani_index;
1213 int mfcr2_answer_pending:1;
1214 int mfcr2_charge_calls:1;
1215 int mfcr2_allow_collect_calls:1;
1216 int mfcr2_forced_release:1;
1217 int mfcr2_dnis_matched:1;
1218 int mfcr2_call_accepted:1;
1219 int mfcr2_accept_on_offer:1;
1220 int mfcr2_progress_sent:1;
1222 /*! \brief DTMF digit in progress. 0 when no digit in progress. */
1224 /*! \brief TRUE if confrence is muted. */
1227 struct ast_cc_config_params *cc_params;
1228 /* DAHDI channel names may differ greatly from the
1229 * string that was provided to an app such as Dial. We
1230 * need to save the original string passed to dahdi_request
1231 * for call completion purposes. This way, we can replicate
1232 * the original dialed string later.
1234 char dialstring[AST_CHANNEL_NAME];
1237 #define DATA_EXPORT_DAHDI_PVT(MEMBER) \
1238 MEMBER(dahdi_pvt, cid_rxgain, AST_DATA_DOUBLE) \
1239 MEMBER(dahdi_pvt, rxgain, AST_DATA_DOUBLE) \
1240 MEMBER(dahdi_pvt, txgain, AST_DATA_DOUBLE) \
1241 MEMBER(dahdi_pvt, txdrc, AST_DATA_DOUBLE) \
1242 MEMBER(dahdi_pvt, rxdrc, AST_DATA_DOUBLE) \
1243 MEMBER(dahdi_pvt, adsi, AST_DATA_BOOLEAN) \
1244 MEMBER(dahdi_pvt, answeronpolarityswitch, AST_DATA_BOOLEAN) \
1245 MEMBER(dahdi_pvt, busydetect, AST_DATA_BOOLEAN) \
1246 MEMBER(dahdi_pvt, callreturn, AST_DATA_BOOLEAN) \
1247 MEMBER(dahdi_pvt, callwaiting, AST_DATA_BOOLEAN) \
1248 MEMBER(dahdi_pvt, callwaitingcallerid, AST_DATA_BOOLEAN) \
1249 MEMBER(dahdi_pvt, cancallforward, AST_DATA_BOOLEAN) \
1250 MEMBER(dahdi_pvt, canpark, AST_DATA_BOOLEAN) \
1251 MEMBER(dahdi_pvt, confirmanswer, AST_DATA_BOOLEAN) \
1252 MEMBER(dahdi_pvt, destroy, AST_DATA_BOOLEAN) \
1253 MEMBER(dahdi_pvt, didtdd, AST_DATA_BOOLEAN) \
1254 MEMBER(dahdi_pvt, dialednone, AST_DATA_BOOLEAN) \
1255 MEMBER(dahdi_pvt, dialing, AST_DATA_BOOLEAN) \
1256 MEMBER(dahdi_pvt, digital, AST_DATA_BOOLEAN) \
1257 MEMBER(dahdi_pvt, dnd, AST_DATA_BOOLEAN) \
1258 MEMBER(dahdi_pvt, echobreak, AST_DATA_BOOLEAN) \
1259 MEMBER(dahdi_pvt, echocanbridged, AST_DATA_BOOLEAN) \
1260 MEMBER(dahdi_pvt, echocanon, AST_DATA_BOOLEAN) \
1261 MEMBER(dahdi_pvt, faxhandled, AST_DATA_BOOLEAN) \
1262 MEMBER(dahdi_pvt, usefaxbuffers, AST_DATA_BOOLEAN) \
1263 MEMBER(dahdi_pvt, bufferoverrideinuse, AST_DATA_BOOLEAN) \
1264 MEMBER(dahdi_pvt, firstradio, AST_DATA_BOOLEAN) \
1265 MEMBER(dahdi_pvt, hanguponpolarityswitch, AST_DATA_BOOLEAN) \
1266 MEMBER(dahdi_pvt, hardwaredtmf, AST_DATA_BOOLEAN) \
1267 MEMBER(dahdi_pvt, hidecallerid, AST_DATA_BOOLEAN) \
1268 MEMBER(dahdi_pvt, hidecalleridname, AST_DATA_BOOLEAN) \
1269 MEMBER(dahdi_pvt, ignoredtmf, AST_DATA_BOOLEAN) \
1270 MEMBER(dahdi_pvt, immediate, AST_DATA_BOOLEAN) \
1271 MEMBER(dahdi_pvt, inalarm, AST_DATA_BOOLEAN) \
1272 MEMBER(dahdi_pvt, mate, AST_DATA_BOOLEAN) \
1273 MEMBER(dahdi_pvt, outgoing, AST_DATA_BOOLEAN) \
1274 MEMBER(dahdi_pvt, permcallwaiting, AST_DATA_BOOLEAN) \
1275 MEMBER(dahdi_pvt, priindication_oob, AST_DATA_BOOLEAN) \
1276 MEMBER(dahdi_pvt, priexclusive, AST_DATA_BOOLEAN) \
1277 MEMBER(dahdi_pvt, pulse, AST_DATA_BOOLEAN) \
1278 MEMBER(dahdi_pvt, pulsedial, AST_DATA_BOOLEAN) \
1279 MEMBER(dahdi_pvt, restartpending, AST_DATA_BOOLEAN) \
1280 MEMBER(dahdi_pvt, restrictcid, AST_DATA_BOOLEAN) \
1281 MEMBER(dahdi_pvt, threewaycalling, AST_DATA_BOOLEAN) \
1282 MEMBER(dahdi_pvt, transfer, AST_DATA_BOOLEAN) \
1283 MEMBER(dahdi_pvt, use_callerid, AST_DATA_BOOLEAN) \
1284 MEMBER(dahdi_pvt, use_callingpres, AST_DATA_BOOLEAN) \
1285 MEMBER(dahdi_pvt, usedistinctiveringdetection, AST_DATA_BOOLEAN) \
1286 MEMBER(dahdi_pvt, dahditrcallerid, AST_DATA_BOOLEAN) \
1287 MEMBER(dahdi_pvt, transfertobusy, AST_DATA_BOOLEAN) \
1288 MEMBER(dahdi_pvt, mwimonitor_neon, AST_DATA_BOOLEAN) \
1289 MEMBER(dahdi_pvt, mwimonitor_fsk, AST_DATA_BOOLEAN) \
1290 MEMBER(dahdi_pvt, mwimonitor_rpas, AST_DATA_BOOLEAN) \
1291 MEMBER(dahdi_pvt, mwimonitoractive, AST_DATA_BOOLEAN) \
1292 MEMBER(dahdi_pvt, mwisendactive, AST_DATA_BOOLEAN) \
1293 MEMBER(dahdi_pvt, inservice, AST_DATA_BOOLEAN) \
1294 MEMBER(dahdi_pvt, locallyblocked, AST_DATA_BOOLEAN) \
1295 MEMBER(dahdi_pvt, remotelyblocked, AST_DATA_BOOLEAN) \
1296 MEMBER(dahdi_pvt, manages_span_alarms, AST_DATA_BOOLEAN) \
1297 MEMBER(dahdi_pvt, use_smdi, AST_DATA_BOOLEAN) \
1298 MEMBER(dahdi_pvt, context, AST_DATA_STRING) \
1299 MEMBER(dahdi_pvt, defcontext, AST_DATA_STRING) \
1300 MEMBER(dahdi_pvt, description, AST_DATA_STRING) \
1301 MEMBER(dahdi_pvt, exten, AST_DATA_STRING) \
1302 MEMBER(dahdi_pvt, language, AST_DATA_STRING) \
1303 MEMBER(dahdi_pvt, mohinterpret, AST_DATA_STRING) \
1304 MEMBER(dahdi_pvt, mohsuggest, AST_DATA_STRING) \
1305 MEMBER(dahdi_pvt, parkinglot, AST_DATA_STRING)
1307 AST_DATA_STRUCTURE(dahdi_pvt, DATA_EXPORT_DAHDI_PVT);
1309 static struct dahdi_pvt *iflist = NULL; /*!< Main interface list start */
1310 static struct dahdi_pvt *ifend = NULL; /*!< Main interface list end */
1312 #if defined(HAVE_PRI)
1313 static struct dahdi_parms_pseudo {
1314 int buf_no; /*!< Number of buffers */
1315 int buf_policy; /*!< Buffer policy */
1316 int faxbuf_no; /*!< Number of Fax buffers */
1317 int faxbuf_policy; /*!< Fax buffer policy */
1318 } dahdi_pseudo_parms;
1319 #endif /* defined(HAVE_PRI) */
1321 /*! \brief Channel configuration from chan_dahdi.conf .
1322 * This struct is used for parsing the [channels] section of chan_dahdi.conf.
1323 * Generally there is a field here for every possible configuration item.
1325 * The state of fields is saved along the parsing and whenever a 'channel'
1326 * statement is reached, the current dahdi_chan_conf is used to configure the
1327 * channel (struct dahdi_pvt)
1329 * \see dahdi_chan_init for the default values.
1331 struct dahdi_chan_conf {
1332 struct dahdi_pvt chan;
1334 struct dahdi_pri pri;
1337 #if defined(HAVE_SS7)
1338 struct dahdi_ss7 ss7;
1339 #endif /* defined(HAVE_SS7) */
1342 struct dahdi_mfcr2_conf mfcr2;
1344 struct dahdi_params timing;
1345 int is_sig_auto; /*!< Use channel signalling from DAHDI? */
1346 /*! Continue configuration even if a channel is not there. */
1347 int ignore_failed_channels;
1350 * \brief The serial port to listen for SMDI data on
1351 * \note Set from the "smdiport" string read in from chan_dahdi.conf
1353 char smdi_port[SMDI_MAX_FILENAME_LEN];
1356 /*! returns a new dahdi_chan_conf with default values (by-value) */
1357 static struct dahdi_chan_conf dahdi_chan_conf_default(void)
1359 /* recall that if a field is not included here it is initialized
1360 * to 0 or equivalent
1362 struct dahdi_chan_conf conf = {
1365 .nsf = PRI_NSF_NONE,
1366 .switchtype = PRI_SWITCH_NI2,
1367 .dialplan = PRI_UNKNOWN + 1,
1368 .localdialplan = PRI_NATIONAL_ISDN + 1,
1369 .nodetype = PRI_CPE,
1370 .qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL,
1372 #if defined(HAVE_PRI_CCSS)
1373 .cc_ptmp_recall_mode = 1,/* specificRecall */
1374 .cc_qsig_signaling_link_req = 1,/* retain */
1375 .cc_qsig_signaling_link_rsp = 1,/* retain */
1376 #endif /* defined(HAVE_PRI_CCSS) */
1381 .internationalprefix = "",
1382 .nationalprefix = "",
1384 .privateprefix = "",
1385 .unknownprefix = "",
1386 .resetinterval = -1,
1389 #if defined(HAVE_SS7)
1391 .called_nai = SS7_NAI_NATIONAL,
1392 .calling_nai = SS7_NAI_NATIONAL,
1393 .internationalprefix = "",
1394 .nationalprefix = "",
1395 .subscriberprefix = "",
1398 #endif /* defined(HAVE_SS7) */
1401 .variant = OR2_VAR_ITU,
1402 .mfback_timeout = -1,
1403 .metering_pulse_timeout = -1,
1406 .get_ani_first = -1,
1407 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
1408 .skip_category_request = -1,
1411 .allow_collect_calls = 0,
1413 .accept_on_offer = 1,
1414 .forced_release = 0,
1416 .immediate_accept = -1,
1417 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
1419 .dtmf_detection = -1,
1420 .dtmf_time_on = OR2_DEFAULT_DTMF_ON,
1421 .dtmf_time_off = OR2_DEFAULT_DTMF_OFF,
1423 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3
1424 .dtmf_end_timeout = -1,
1428 .loglevel = OR2_LOG_ERROR | OR2_LOG_WARNING,
1429 .category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER
1433 .context = "default",
1437 .mohinterpret = "default",
1440 .transfertobusy = 1,
1442 .cid_signalling = CID_SIG_BELL,
1443 .cid_start = CID_START_RING,
1444 .dahditrcallerid = 0,
1453 .echocancel.head.tap_length = 1,
1461 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
1464 .polarityonanswerdelay = 600,
1466 .sendcalleridafter = DEFAULT_CIDRINGS,
1468 .buf_policy = DAHDI_POLICY_IMMEDIATE,
1471 .cc_params = ast_cc_config_params_init(),
1484 .smdi_port = "/dev/ttyS0",
1491 static struct ast_channel *dahdi_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
1492 static int dahdi_digit_begin(struct ast_channel *ast, char digit);
1493 static int dahdi_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
1494 static int dahdi_sendtext(struct ast_channel *c, const char *text);
1495 static int dahdi_call(struct ast_channel *ast, char *rdest, int timeout);
1496 static int dahdi_hangup(struct ast_channel *ast);
1497 static int dahdi_answer(struct ast_channel *ast);
1498 static struct ast_frame *dahdi_read(struct ast_channel *ast);
1499 static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame);
1500 static struct ast_frame *dahdi_exception(struct ast_channel *ast);
1501 static int dahdi_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen);
1502 static int dahdi_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
1503 static int dahdi_setoption(struct ast_channel *chan, int option, void *data, int datalen);
1504 static int dahdi_queryoption(struct ast_channel *chan, int option, void *data, int *datalen);
1505 static int dahdi_func_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
1506 static int dahdi_func_write(struct ast_channel *chan, const char *function, char *data, const char *value);
1507 static int dahdi_devicestate(void *data);
1508 static int dahdi_cc_callback(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback);
1510 static struct ast_channel_tech dahdi_tech = {
1512 .description = tdesc,
1513 .requester = dahdi_request,
1514 .send_digit_begin = dahdi_digit_begin,
1515 .send_digit_end = dahdi_digit_end,
1516 .send_text = dahdi_sendtext,
1518 .hangup = dahdi_hangup,
1519 .answer = dahdi_answer,
1521 .write = dahdi_write,
1522 .bridge = dahdi_bridge,
1523 .exception = dahdi_exception,
1524 .indicate = dahdi_indicate,
1525 .fixup = dahdi_fixup,
1526 .setoption = dahdi_setoption,
1527 .queryoption = dahdi_queryoption,
1528 .func_channel_read = dahdi_func_read,
1529 .func_channel_write = dahdi_func_write,
1530 .devicestate = dahdi_devicestate,
1531 .cc_callback = dahdi_cc_callback,
1534 #define GET_CHANNEL(p) ((p)->channel)
1536 #define SIG_PRI_LIB_HANDLE_CASES \
1543 * \brief Determine if sig_pri handles the signaling.
1546 * \param signaling Signaling to determine if is for sig_pri.
1548 * \return TRUE if the signaling is for sig_pri.
1550 static inline int dahdi_sig_pri_lib_handles(int signaling)
1554 switch (signaling) {
1555 case SIG_PRI_LIB_HANDLE_CASES:
1566 static enum analog_sigtype dahdisig_to_analogsig(int sig)
1570 return ANALOG_SIG_FXOLS;
1572 return ANALOG_SIG_FXOGS;
1574 return ANALOG_SIG_FXOKS;
1576 return ANALOG_SIG_FXSLS;
1578 return ANALOG_SIG_FXSGS;
1580 return ANALOG_SIG_FXSKS;
1582 return ANALOG_SIG_EMWINK;
1584 return ANALOG_SIG_EM;
1586 return ANALOG_SIG_EM_E1;
1588 return ANALOG_SIG_FEATD;
1590 return ANALOG_SIG_FEATDMF;
1594 return ANALOG_SIG_FGC_CAMA;
1595 case SIG_FGC_CAMAMF:
1596 return ANALOG_SIG_FGC_CAMAMF;
1598 return ANALOG_SIG_FEATB;
1600 return ANALOG_SIG_SFWINK;
1602 return ANALOG_SIG_SF;
1604 return ANALOG_SIG_SF_FEATD;
1605 case SIG_SF_FEATDMF:
1606 return ANALOG_SIG_SF_FEATDMF;
1607 case SIG_FEATDMF_TA:
1608 return ANALOG_SIG_FEATDMF_TA;
1610 return ANALOG_SIG_FEATB;
1617 static int analog_tone_to_dahditone(enum analog_tone tone)
1620 case ANALOG_TONE_RINGTONE:
1621 return DAHDI_TONE_RINGTONE;
1622 case ANALOG_TONE_STUTTER:
1623 return DAHDI_TONE_STUTTER;
1624 case ANALOG_TONE_CONGESTION:
1625 return DAHDI_TONE_CONGESTION;
1626 case ANALOG_TONE_DIALTONE:
1627 return DAHDI_TONE_DIALTONE;
1628 case ANALOG_TONE_DIALRECALL:
1629 return DAHDI_TONE_DIALRECALL;
1630 case ANALOG_TONE_INFO:
1631 return DAHDI_TONE_INFO;
1637 static int analogsub_to_dahdisub(enum analog_sub analogsub)
1641 switch (analogsub) {
1642 case ANALOG_SUB_REAL:
1645 case ANALOG_SUB_CALLWAIT:
1646 index = SUB_CALLWAIT;
1648 case ANALOG_SUB_THREEWAY:
1649 index = SUB_THREEWAY;
1652 ast_log(LOG_ERROR, "Unidentified sub!\n");
1659 static enum analog_event dahdievent_to_analogevent(int event);
1660 static int bump_gains(struct dahdi_pvt *p);
1661 static int dahdi_setlinear(int dfd, int linear);
1663 static int my_start_cid_detect(void *pvt, int cid_signalling)
1665 struct dahdi_pvt *p = pvt;
1666 int index = SUB_REAL;
1667 p->cs = callerid_new(cid_signalling);
1669 ast_log(LOG_ERROR, "Unable to alloc callerid\n");
1673 dahdi_setlinear(p->subs[index].dfd, 0);
1678 static int my_stop_cid_detect(void *pvt)
1680 struct dahdi_pvt *p = pvt;
1681 int index = SUB_REAL;
1683 callerid_free(p->cs);
1684 dahdi_setlinear(p->subs[index].dfd, p->subs[index].linear);
1688 static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_event *ev, size_t timeout)
1690 struct dahdi_pvt *p = pvt;
1691 struct analog_pvt *analog_p = p->sig_pvt;
1692 struct pollfd poller;
1694 int index = SUB_REAL;
1696 unsigned char buf[256];
1698 struct ast_format tmpfmt;
1700 poller.fd = p->subs[SUB_REAL].dfd;
1701 poller.events = POLLPRI | POLLIN;
1704 res = poll(&poller, 1, timeout);
1706 if (poller.revents & POLLPRI) {
1707 *ev = dahdievent_to_analogevent(dahdi_get_event(p->subs[SUB_REAL].dfd));
1711 if (poller.revents & POLLIN) {
1713 /* Change API: remove cid_signalling from get_callerid, add a new start_cid_detect and stop_cid_detect function
1714 * to enable slin mode and allocate cid detector. get_callerid should be able to be called any number of times until
1715 * either a timeout occurs or CID is detected (returns 0). returning 1 should be event received, and -1 should be
1716 * a failure and die, and returning 2 means no event was received. */
1717 res = read(p->subs[index].dfd, buf, sizeof(buf));
1719 if (errno != ELAST) {
1720 ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
1721 callerid_free(p->cs);
1726 if (analog_p->ringt > 0) {
1727 if (!(--analog_p->ringt)) {
1728 /* only return if we timeout from a ring event */
1733 if (p->cid_signalling == CID_SIG_V23_JP) {
1734 res = callerid_feed_jp(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1736 res = callerid_feed(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1740 * The previous diagnostic message output likely
1741 * explains why it failed.
1743 ast_log(LOG_WARNING, "Failed to decode CallerID\n");
1748 callerid_get(p->cs, &name, &num, &flags);
1750 ast_copy_string(namebuf, name, ANALOG_MAX_CID);
1752 ast_copy_string(numbuf, num, ANALOG_MAX_CID);
1754 ast_debug(1, "CallerID number: %s, name: %s, flags=%d\n", num, name, flags);
1759 *ev = ANALOG_EVENT_NONE;
1763 static const char *event2str(int event);
1764 static int restore_gains(struct dahdi_pvt *p);
1766 static int my_distinctive_ring(struct ast_channel *chan, void *pvt, int idx, int *ringdata)
1768 unsigned char buf[256];
1770 int curRingData[RING_PATTERNS];
1776 int checkaftercid = 0;
1778 struct dahdi_pvt *p = pvt;
1779 struct analog_pvt *analog_p = p->sig_pvt;
1781 if (ringdata == NULL) {
1782 ringdata = curRingData;
1787 /* We must have a ring by now, so, if configured, lets try to listen for
1788 * distinctive ringing */
1789 if ((checkaftercid && distinctiveringaftercid) || !checkaftercid) {
1790 /* Clear the current ring data array so we don't have old data in it. */
1791 for (receivedRingT = 0; receivedRingT < RING_PATTERNS; receivedRingT++)
1792 ringdata[receivedRingT] = 0;
1794 if (checkaftercid && distinctiveringaftercid)
1795 ast_verb(3, "Detecting post-CID distinctive ring\n");
1796 /* Check to see if context is what it should be, if not set to be. */
1797 else if (strcmp(p->context,p->defcontext) != 0) {
1798 ast_copy_string(p->context, p->defcontext, sizeof(p->context));
1799 ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
1803 i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
1804 if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) {
1805 ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
1809 if (i & DAHDI_IOMUX_SIGEVENT) {
1810 res = dahdi_get_event(p->subs[idx].dfd);
1811 if (res == DAHDI_EVENT_NOALARM) {
1813 analog_p->inalarm = 0;
1815 ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
1817 /* Let us detect distinctive ring */
1819 ringdata[receivedRingT] = analog_p->ringt;
1821 if (analog_p->ringt < analog_p->ringt_base/2)
1823 /* Increment the ringT counter so we can match it against
1824 values in chan_dahdi.conf for distinctive ring */
1825 if (++receivedRingT == RING_PATTERNS)
1827 } else if (i & DAHDI_IOMUX_READ) {
1828 res = read(p->subs[idx].dfd, buf, sizeof(buf));
1830 if (errno != ELAST) {
1831 ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
1837 if (analog_p->ringt > 0) {
1838 if (!(--analog_p->ringt)) {
1846 if ((checkaftercid && usedistinctiveringdetection) || !checkaftercid) {
1847 /* this only shows up if you have n of the dring patterns filled in */
1848 ast_verb(3, "Detected ring pattern: %d,%d,%d\n",ringdata[0],ringdata[1],ringdata[2]);
1849 for (counter = 0; counter < 3; counter++) {
1850 /* Check to see if the rings we received match any of the ones in chan_dahdi.conf for this channel */
1852 /* this only shows up if you have n of the dring patterns filled in */
1853 ast_verb(3, "Checking %d,%d,%d\n",
1854 p->drings.ringnum[counter].ring[0],
1855 p->drings.ringnum[counter].ring[1],
1856 p->drings.ringnum[counter].ring[2]);
1857 for (counter1 = 0; counter1 < 3; counter1++) {
1858 ast_verb(3, "Ring pattern check range: %d\n", p->drings.ringnum[counter].range);
1859 if (p->drings.ringnum[counter].ring[counter1] == -1) {
1860 ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n",
1861 ringdata[counter1]);
1863 } else if (ringdata[counter1] <= (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range) &&
1864 ringdata[counter1] >= (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range)) {
1865 ast_verb(3, "Ring pattern matched in range: %d to %d\n",
1866 (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range),
1867 (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range));
1872 if (distMatches == 3) {
1873 /* The ring matches, set the context to whatever is for distinctive ring.. */
1874 ast_copy_string(p->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(p->context));
1875 ast_copy_string(chan->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(chan->context));
1876 ast_verb(3, "Distinctive Ring matched context %s\n",p->context);
1881 /* Restore linear mode (if appropriate) for Caller*ID processing */
1882 dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
1888 static int my_stop_callwait(void *pvt)
1890 struct dahdi_pvt *p = pvt;
1891 p->callwaitingrepeat = 0;
1893 p->cid_suppress_expire = 0;
1898 static int send_callerid(struct dahdi_pvt *p);
1899 static int save_conference(struct dahdi_pvt *p);
1900 static int restore_conference(struct dahdi_pvt *p);
1902 static int my_callwait(void *pvt)
1904 struct dahdi_pvt *p = pvt;
1905 struct ast_format tmpfmt;
1906 p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
1908 ast_log(LOG_WARNING, "Spill already exists?!?\n");
1909 ast_free(p->cidspill);
1913 * SAS: Subscriber Alert Signal, 440Hz for 300ms
1914 * CAS: CPE Alert Signal, 2130Hz * 2750Hz sine waves
1916 if (!(p->cidspill = ast_malloc(2400 /* SAS */ + 680 /* CAS */ + READ_SIZE * 4)))
1920 memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4);
1921 if (!p->callwaitrings && p->callwaitingcallerid) {
1922 ast_gen_cas(p->cidspill, 1, 2400 + 680, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1924 p->cidlen = 2400 + 680 + READ_SIZE * 4;
1926 ast_gen_cas(p->cidspill, 1, 2400, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1928 p->cidlen = 2400 + READ_SIZE * 4;
1936 static int my_send_callerid(void *pvt, int cwcid, struct ast_party_caller *caller)
1938 struct dahdi_pvt *p = pvt;
1939 struct ast_format tmpfmt;
1941 ast_debug(2, "Starting cid spill\n");
1944 ast_log(LOG_WARNING, "cidspill already exists??\n");
1945 ast_free(p->cidspill);
1948 if ((p->cidspill = ast_malloc(MAX_CALLERID_SIZE))) {
1950 p->cidlen = ast_callerid_generate(p->cidspill,
1951 caller->id.name.str,
1952 caller->id.number.str,
1953 ast_format_set(&tmpfmt, AST_LAW(p), 0));
1955 ast_verb(3, "CPE supports Call Waiting Caller*ID. Sending '%s/%s'\n",
1956 caller->id.name.str, caller->id.number.str);
1959 p->cidlen = ast_callerid_callwaiting_generate(p->cidspill,
1960 caller->id.name.str,
1961 caller->id.number.str,
1962 ast_format_set(&tmpfmt, AST_LAW(p), 0));
1963 p->cidlen += READ_SIZE * 4;
1966 p->cid_suppress_expire = 0;
1972 static int my_dsp_reset_and_flush_digits(void *pvt)
1974 struct dahdi_pvt *p = pvt;
1976 ast_dsp_digitreset(p->dsp);
1981 static int my_dsp_set_digitmode(void *pvt, enum analog_dsp_digitmode mode)
1983 struct dahdi_pvt *p = pvt;
1985 if (p->channel == CHAN_PSEUDO)
1986 ast_log(LOG_ERROR, "You have assumed incorrectly sir!\n");
1988 if (mode == ANALOG_DIGITMODE_DTMF) {
1989 /* If we do hardware dtmf, no need for a DSP */
1990 if (p->hardwaredtmf) {
1992 ast_dsp_free(p->dsp);
1999 p->dsp = ast_dsp_new();
2001 ast_log(LOG_ERROR, "Unable to allocate DSP\n");
2006 ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax);
2007 } else if (mode == ANALOG_DIGITMODE_MF) {
2009 p->dsp = ast_dsp_new();
2011 ast_log(LOG_ERROR, "Unable to allocate DSP\n");
2015 ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MF | p->dtmfrelax);
2020 static int dahdi_wink(struct dahdi_pvt *p, int index);
2022 static int my_wink(void *pvt, enum analog_sub sub)
2024 struct dahdi_pvt *p = pvt;
2025 int index = analogsub_to_dahdisub(sub);
2026 if (index != SUB_REAL) {
2027 ast_log(LOG_ERROR, "We used a sub other than SUB_REAL (incorrect assumption sir)\n");
2029 return dahdi_wink(p, index);
2032 static void wakeup_sub(struct dahdi_pvt *p, int a);
2034 static int reset_conf(struct dahdi_pvt *p);
2036 static inline int dahdi_confmute(struct dahdi_pvt *p, int muted);
2038 static void my_handle_dtmf(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
2040 struct ast_frame *f = *dest;
2041 struct dahdi_pvt *p = pvt;
2042 int idx = analogsub_to_dahdisub(analog_index);
2044 ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n",
2045 f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End",
2046 f->subclass.integer, f->subclass.integer, ast->name);
2048 if (f->subclass.integer == 'f') {
2049 if (f->frametype == AST_FRAME_DTMF_END) {
2050 /* Fax tone -- Handle and return NULL */
2051 if ((p->callprogress & CALLPROGRESS_FAX) && !p->faxhandled) {
2052 /* If faxbuffers are configured, use them for the fax transmission */
2053 if (p->usefaxbuffers && !p->bufferoverrideinuse) {
2054 struct dahdi_bufferinfo bi = {
2055 .txbufpolicy = p->faxbuf_policy,
2056 .bufsize = p->bufsize,
2057 .numbufs = p->faxbuf_no
2061 if ((res = ioctl(p->subs[idx].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) {
2062 ast_log(LOG_WARNING, "Channel '%s' unable to set buffer policy, reason: %s\n", ast->name, strerror(errno));
2064 p->bufferoverrideinuse = 1;
2069 p->dsp_features &= ~DSP_FEATURE_FAX_DETECT;
2070 ast_dsp_set_features(p->dsp, p->dsp_features);
2071 ast_debug(1, "Disabling FAX tone detection on %s after tone received\n", ast->name);
2073 if (strcmp(ast->exten, "fax")) {
2074 const char *target_context = S_OR(ast->macrocontext, ast->context);
2076 /* We need to unlock 'ast' here because ast_exists_extension has the
2077 * potential to start autoservice on the channel. Such action is prone
2080 ast_mutex_unlock(&p->lock);
2081 ast_channel_unlock(ast);
2082 if (ast_exists_extension(ast, target_context, "fax", 1,
2083 S_COR(ast->caller.id.number.valid, ast->caller.id.number.str, NULL))) {
2084 ast_channel_lock(ast);
2085 ast_mutex_lock(&p->lock);
2086 ast_verb(3, "Redirecting %s to fax extension\n", ast->name);
2087 /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
2088 pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten);
2089 if (ast_async_goto(ast, target_context, "fax", 1))
2090 ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context);
2092 ast_channel_lock(ast);
2093 ast_mutex_lock(&p->lock);
2094 ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
2097 ast_debug(1, "Already in a fax extension, not redirecting\n");
2100 ast_debug(1, "Fax already handled\n");
2102 dahdi_confmute(p, 0);
2104 p->subs[idx].f.frametype = AST_FRAME_NULL;
2105 p->subs[idx].f.subclass.integer = 0;
2106 *dest = &p->subs[idx].f;
2110 static void my_lock_private(void *pvt)
2112 struct dahdi_pvt *p = pvt;
2113 ast_mutex_lock(&p->lock);
2116 static void my_unlock_private(void *pvt)
2118 struct dahdi_pvt *p = pvt;
2119 ast_mutex_unlock(&p->lock);
2122 static void my_deadlock_avoidance_private(void *pvt)
2124 struct dahdi_pvt *p = pvt;
2126 DEADLOCK_AVOIDANCE(&p->lock);
2131 * \brief Post an AMI DAHDI channel association event.
2134 * \param p DAHDI private pointer
2135 * \param chan Channel associated with the private pointer
2139 static void dahdi_ami_channel_event(struct dahdi_pvt *p, struct ast_channel *chan)
2143 if (p->channel < CHAN_PSEUDO) {
2145 snprintf(ch_name, sizeof(ch_name), "no-media (%d)", p->channel);
2146 } else if (p->channel == CHAN_PSEUDO) {
2147 /* Pseudo channel */
2148 strcpy(ch_name, "pseudo");
2151 snprintf(ch_name, sizeof(ch_name), "%d", p->channel);
2153 ast_manager_event(chan, EVENT_FLAG_CALL, "DAHDIChannel",
2157 "DAHDIChannel: %s\r\n",
2167 * \brief Post an AMI DAHDI channel association event.
2170 * \param pvt DAHDI private pointer
2171 * \param chan Channel associated with the private pointer
2175 static void my_ami_channel_event(void *pvt, struct ast_channel *chan)
2177 struct dahdi_pvt *p = pvt;
2179 dahdi_ami_channel_event(p, chan);
2183 /* linear_mode = 0 - turn linear mode off, >0 - turn linear mode on
2184 * returns the last value of the linear setting
2186 static int my_set_linear_mode(void *pvt, enum analog_sub sub, int linear_mode)
2188 struct dahdi_pvt *p = pvt;
2190 int idx = analogsub_to_dahdisub(sub);
2192 dahdi_setlinear(p->subs[idx].dfd, linear_mode);
2193 oldval = p->subs[idx].linear;
2194 p->subs[idx].linear = linear_mode ? 1 : 0;
2198 static void my_set_inthreeway(void *pvt, enum analog_sub sub, int inthreeway)
2200 struct dahdi_pvt *p = pvt;
2201 int idx = analogsub_to_dahdisub(sub);
2203 p->subs[idx].inthreeway = inthreeway;
2206 static int get_alarms(struct dahdi_pvt *p);
2207 static void handle_alarms(struct dahdi_pvt *p, int alms);
2208 static void my_get_and_handle_alarms(void *pvt)
2211 struct dahdi_pvt *p = pvt;
2213 res = get_alarms(p);
2214 handle_alarms(p, res);
2217 static void *my_get_sigpvt_bridged_channel(struct ast_channel *chan)
2219 struct dahdi_pvt *p = ast_bridged_channel(chan)->tech_pvt;
2226 static int my_get_sub_fd(void *pvt, enum analog_sub sub)
2228 struct dahdi_pvt *p = pvt;
2229 int dahdi_sub = analogsub_to_dahdisub(sub);
2230 return p->subs[dahdi_sub].dfd;
2233 static void my_set_cadence(void *pvt, int *cidrings, struct ast_channel *ast)
2235 struct dahdi_pvt *p = pvt;
2237 /* Choose proper cadence */
2238 if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) {
2239 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &cadences[p->distinctivering - 1]))
2240 ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s': %s\n", p->distinctivering, ast->name, strerror(errno));
2241 *cidrings = cidrings[p->distinctivering - 1];
2243 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, NULL))
2244 ast_log(LOG_WARNING, "Unable to reset default ring on '%s': %s\n", ast->name, strerror(errno));
2245 *cidrings = p->sendcalleridafter;
2249 static void my_set_alarm(void *pvt, int in_alarm)
2251 struct dahdi_pvt *p = pvt;
2253 p->inalarm = in_alarm;
2256 static void my_set_dialing(void *pvt, int is_dialing)
2258 struct dahdi_pvt *p = pvt;
2260 p->dialing = is_dialing;
2263 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2264 static void my_set_digital(void *pvt, int is_digital)
2266 struct dahdi_pvt *p = pvt;
2268 p->digital = is_digital;
2270 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2272 #if defined(HAVE_SS7)
2273 static void my_set_inservice(void *pvt, int is_inservice)
2275 struct dahdi_pvt *p = pvt;
2277 p->inservice = is_inservice;
2279 #endif /* defined(HAVE_SS7) */
2281 #if defined(HAVE_SS7)
2282 static void my_set_locallyblocked(void *pvt, int is_blocked)
2284 struct dahdi_pvt *p = pvt;
2286 p->locallyblocked = is_blocked;
2288 #endif /* defined(HAVE_SS7) */
2290 #if defined(HAVE_SS7)
2291 static void my_set_remotelyblocked(void *pvt, int is_blocked)
2293 struct dahdi_pvt *p = pvt;
2295 p->remotelyblocked = is_blocked;
2297 #endif /* defined(HAVE_SS7) */
2299 static void my_set_ringtimeout(void *pvt, int ringt)
2301 struct dahdi_pvt *p = pvt;
2305 static void my_set_waitingfordt(void *pvt, struct ast_channel *ast)
2307 struct dahdi_pvt *p = pvt;
2309 if (p->waitfordialtone && CANPROGRESSDETECT(p) && p->dsp) {
2310 ast_debug(1, "Defer dialing for %dms or dialtone\n", p->waitfordialtone);
2311 gettimeofday(&p->waitingfordt, NULL);
2312 ast_setstate(ast, AST_STATE_OFFHOOK);
2316 static int my_check_waitingfordt(void *pvt)
2318 struct dahdi_pvt *p = pvt;
2320 if (p->waitingfordt.tv_usec) {
2327 static void my_set_confirmanswer(void *pvt, int flag)
2329 struct dahdi_pvt *p = pvt;
2330 p->confirmanswer = flag;
2333 static int my_check_confirmanswer(void *pvt)
2335 struct dahdi_pvt *p = pvt;
2336 if (p->confirmanswer) {
2343 static void my_set_callwaiting(void *pvt, int callwaiting_enable)
2345 struct dahdi_pvt *p = pvt;
2347 p->callwaiting = callwaiting_enable;
2350 static void my_cancel_cidspill(void *pvt)
2352 struct dahdi_pvt *p = pvt;
2354 ast_free(p->cidspill);
2356 restore_conference(p);
2359 static int my_confmute(void *pvt, int mute)
2361 struct dahdi_pvt *p = pvt;
2362 return dahdi_confmute(p, mute);
2365 static void my_set_pulsedial(void *pvt, int flag)
2367 struct dahdi_pvt *p = pvt;
2368 p->pulsedial = flag;
2371 static void my_set_new_owner(void *pvt, struct ast_channel *new_owner)
2373 struct dahdi_pvt *p = pvt;
2375 p->owner = new_owner;
2378 static const char *my_get_orig_dialstring(void *pvt)
2380 struct dahdi_pvt *p = pvt;
2382 return p->dialstring;
2385 static void my_increase_ss_count(void)
2387 ast_mutex_lock(&ss_thread_lock);
2389 ast_mutex_unlock(&ss_thread_lock);
2392 static void my_decrease_ss_count(void)
2394 ast_mutex_lock(&ss_thread_lock);
2396 ast_cond_signal(&ss_thread_complete);
2397 ast_mutex_unlock(&ss_thread_lock);
2400 static void my_all_subchannels_hungup(void *pvt)
2402 struct dahdi_pvt *p = pvt;
2409 ast_dsp_free(p->dsp);
2413 p->law = p->law_default;
2414 law = p->law_default;
2415 res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law);
2417 ast_log(LOG_WARNING, "Unable to set law on channel %d to default: %s\n", p->channel, strerror(errno));
2419 dahdi_setlinear(p->subs[SUB_REAL].dfd, 0);
2425 /* Cleanup owners here */
2426 for (i = 0; i < 3; i++) {
2427 p->subs[i].owner = NULL;
2433 if (num_restart_pending == 0) {
2438 static int conf_del(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index);
2440 static int my_conf_del(void *pvt, enum analog_sub sub)
2442 struct dahdi_pvt *p = pvt;
2443 int x = analogsub_to_dahdisub(sub);
2445 return conf_del(p, &p->subs[x], x);
2448 static int conf_add(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index, int slavechannel);
2450 static int my_conf_add(void *pvt, enum analog_sub sub)
2452 struct dahdi_pvt *p = pvt;
2453 int x = analogsub_to_dahdisub(sub);
2455 return conf_add(p, &p->subs[x], x, 0);
2458 static int isslavenative(struct dahdi_pvt *p, struct dahdi_pvt **out);
2460 static int my_complete_conference_update(void *pvt, int needconference)
2462 struct dahdi_pvt *p = pvt;
2463 int needconf = needconference;
2466 struct dahdi_pvt *slave = NULL;
2468 useslavenative = isslavenative(p, &slave);
2470 /* If we have a slave, add him to our conference now. or DAX
2471 if this is slave native */
2472 for (x = 0; x < MAX_SLAVES; x++) {
2475 conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p));
2477 conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, 0);
2482 /* If we're supposed to be in there, do so now */
2483 if (p->inconference && !p->subs[SUB_REAL].inthreeway) {
2485 conf_add(p, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(slave));
2487 conf_add(p, &p->subs[SUB_REAL], SUB_REAL, 0);
2491 /* If we have a master, add ourselves to his conference */
2493 if (isslavenative(p->master, NULL)) {
2494 conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p->master));
2496 conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, 0);
2500 /* Nobody is left (or should be left) in our conference.
2508 static int check_for_conference(struct dahdi_pvt *p);
2510 static int my_check_for_conference(void *pvt)
2512 struct dahdi_pvt *p = pvt;
2513 return check_for_conference(p);
2516 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)
2518 struct dahdi_pvt *p = pvt;
2523 da = analogsub_to_dahdisub(a);
2524 db = analogsub_to_dahdisub(b);
2526 tchan = p->subs[da].chan;
2527 p->subs[da].chan = p->subs[db].chan;
2528 p->subs[db].chan = tchan;
2530 tinthreeway = p->subs[da].inthreeway;
2531 p->subs[da].inthreeway = p->subs[db].inthreeway;
2532 p->subs[db].inthreeway = tinthreeway;
2534 p->subs[da].owner = ast_a;
2535 p->subs[db].owner = ast_b;
2538 ast_channel_set_fd(ast_a, 0, p->subs[da].dfd);
2540 ast_channel_set_fd(ast_b, 0, p->subs[db].dfd);
2548 static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const char *linkedid);
2550 static struct ast_channel *my_new_analog_ast_channel(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
2552 struct dahdi_pvt *p = pvt;
2553 int dsub = analogsub_to_dahdisub(sub);
2555 return dahdi_new(p, state, startpbx, dsub, 0, requestor ? requestor->linkedid : "");
2558 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2559 static int dahdi_setlaw(int dfd, int law)
2562 res = ioctl(dfd, DAHDI_SETLAW, &law);
2567 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2569 #if defined(HAVE_PRI)
2570 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)
2572 struct dahdi_pvt *p = pvt;
2577 case SIG_PRI_LIB_HANDLE_CASES:
2578 if (((struct sig_pri_chan *) p->sig_pvt)->no_b_channel) {
2579 /* PRI nobch pseudo channel. Does not handle ioctl(DAHDI_AUDIOMODE) */
2584 /* Set to audio mode at this point */
2586 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &audio) == -1) {
2587 ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n",
2588 p->channel, audio, strerror(errno));
2593 if (law != SIG_PRI_DEFLAW) {
2594 dahdi_setlaw(p->subs[SUB_REAL].dfd, (law == SIG_PRI_ULAW) ? DAHDI_LAW_MULAW : DAHDI_LAW_ALAW);
2597 ast_copy_string(p->exten, exten, sizeof(p->exten));
2600 case SIG_PRI_DEFLAW:
2604 newlaw = DAHDI_LAW_ALAW;
2607 newlaw = DAHDI_LAW_MULAW;
2610 return dahdi_new(p, state, 0, SUB_REAL, newlaw, requestor ? requestor->linkedid : "");
2612 #endif /* defined(HAVE_PRI) */
2614 static int set_actual_gain(int fd, float rxgain, float txgain, float rxdrc, float txdrc, int law);
2616 #if defined(HAVE_PRI)
2619 * \brief Open the PRI channel media path.
2622 * \param p Channel private control structure.
2626 static void my_pri_open_media(void *p)
2628 struct dahdi_pvt *pvt = p;
2633 dfd = pvt->subs[SUB_REAL].dfd;
2635 /* Open the media path. */
2637 res = ioctl(dfd, DAHDI_AUDIOMODE, &set_val);
2639 ast_log(LOG_WARNING, "Unable to enable audio mode on channel %d (%s)\n",
2640 pvt->channel, strerror(errno));
2643 /* Set correct companding law for this call. */
2644 res = dahdi_setlaw(dfd, pvt->law);
2646 ast_log(LOG_WARNING, "Unable to set law on channel %d\n", pvt->channel);
2649 /* Set correct gain for this call. */
2651 res = set_actual_gain(dfd, 0, 0, pvt->rxdrc, pvt->txdrc, pvt->law);
2653 res = set_actual_gain(dfd, pvt->rxgain, pvt->txgain, pvt->rxdrc, pvt->txdrc,
2657 ast_log(LOG_WARNING, "Unable to set gains on channel %d\n", pvt->channel);
2660 if (pvt->dsp_features && pvt->dsp) {
2661 ast_dsp_set_features(pvt->dsp, pvt->dsp_features);
2662 pvt->dsp_features = 0;
2665 #endif /* defined(HAVE_PRI) */
2667 static int unalloc_sub(struct dahdi_pvt *p, int x);
2669 static int my_unallocate_sub(void *pvt, enum analog_sub analogsub)
2671 struct dahdi_pvt *p = pvt;
2673 return unalloc_sub(p, analogsub_to_dahdisub(analogsub));
2676 static int alloc_sub(struct dahdi_pvt *p, int x);
2678 static int my_allocate_sub(void *pvt, enum analog_sub analogsub)
2680 struct dahdi_pvt *p = pvt;
2682 return alloc_sub(p, analogsub_to_dahdisub(analogsub));
2685 static int has_voicemail(struct dahdi_pvt *p);
2687 static int my_has_voicemail(void *pvt)
2689 struct dahdi_pvt *p = pvt;
2691 return has_voicemail(p);
2694 static int my_play_tone(void *pvt, enum analog_sub sub, enum analog_tone tone)
2696 struct dahdi_pvt *p = pvt;
2699 index = analogsub_to_dahdisub(sub);
2701 return tone_zone_play_tone(p->subs[index].dfd, analog_tone_to_dahditone(tone));
2704 static enum analog_event dahdievent_to_analogevent(int event)
2706 enum analog_event res;
2709 case DAHDI_EVENT_ONHOOK:
2710 res = ANALOG_EVENT_ONHOOK;
2712 case DAHDI_EVENT_RINGOFFHOOK:
2713 res = ANALOG_EVENT_RINGOFFHOOK;
2715 case DAHDI_EVENT_WINKFLASH:
2716 res = ANALOG_EVENT_WINKFLASH;
2718 case DAHDI_EVENT_ALARM:
2719 res = ANALOG_EVENT_ALARM;
2721 case DAHDI_EVENT_NOALARM:
2722 res = ANALOG_EVENT_NOALARM;
2724 case DAHDI_EVENT_DIALCOMPLETE:
2725 res = ANALOG_EVENT_DIALCOMPLETE;
2727 case DAHDI_EVENT_RINGERON:
2728 res = ANALOG_EVENT_RINGERON;
2730 case DAHDI_EVENT_RINGEROFF:
2731 res = ANALOG_EVENT_RINGEROFF;
2733 case DAHDI_EVENT_HOOKCOMPLETE:
2734 res = ANALOG_EVENT_HOOKCOMPLETE;
2736 case DAHDI_EVENT_PULSE_START:
2737 res = ANALOG_EVENT_PULSE_START;
2739 case DAHDI_EVENT_POLARITY:
2740 res = ANALOG_EVENT_POLARITY;
2742 case DAHDI_EVENT_RINGBEGIN:
2743 res = ANALOG_EVENT_RINGBEGIN;
2745 case DAHDI_EVENT_EC_DISABLED:
2746 res = ANALOG_EVENT_EC_DISABLED;
2748 case DAHDI_EVENT_REMOVED:
2749 res = ANALOG_EVENT_REMOVED;
2751 case DAHDI_EVENT_NEONMWI_ACTIVE:
2752 res = ANALOG_EVENT_NEONMWI_ACTIVE;
2754 case DAHDI_EVENT_NEONMWI_INACTIVE:
2755 res = ANALOG_EVENT_NEONMWI_INACTIVE;
2757 #ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
2758 case DAHDI_EVENT_TX_CED_DETECTED:
2759 res = ANALOG_EVENT_TX_CED_DETECTED;
2761 case DAHDI_EVENT_RX_CED_DETECTED:
2762 res = ANALOG_EVENT_RX_CED_DETECTED;
2764 case DAHDI_EVENT_EC_NLP_DISABLED:
2765 res = ANALOG_EVENT_EC_NLP_DISABLED;
2767 case DAHDI_EVENT_EC_NLP_ENABLED:
2768 res = ANALOG_EVENT_EC_NLP_ENABLED;
2771 case DAHDI_EVENT_PULSEDIGIT:
2772 res = ANALOG_EVENT_PULSEDIGIT;
2774 case DAHDI_EVENT_DTMFDOWN:
2775 res = ANALOG_EVENT_DTMFDOWN;
2777 case DAHDI_EVENT_DTMFUP:
2778 res = ANALOG_EVENT_DTMFUP;
2781 switch(event & 0xFFFF0000) {
2782 case DAHDI_EVENT_PULSEDIGIT:
2783 case DAHDI_EVENT_DTMFDOWN:
2784 case DAHDI_EVENT_DTMFUP:
2785 /* The event includes a digit number in the low word.
2786 * Converting it to a 'enum analog_event' would remove
2787 * that information. Thus it is returned as-is.
2792 res = ANALOG_EVENT_ERROR;
2799 static inline int dahdi_wait_event(int fd);
2801 static int my_wait_event(void *pvt)
2803 struct dahdi_pvt *p = pvt;
2805 return dahdi_wait_event(p->subs[SUB_REAL].dfd);
2808 static int my_get_event(void *pvt)
2810 struct dahdi_pvt *p = pvt;
2813 if (p->fake_event) {
2814 res = p->fake_event;
2817 res = dahdi_get_event(p->subs[SUB_REAL].dfd);
2819 return dahdievent_to_analogevent(res);
2822 static int my_is_off_hook(void *pvt)
2824 struct dahdi_pvt *p = pvt;
2826 struct dahdi_params par;
2828 memset(&par, 0, sizeof(par));
2830 if (p->subs[SUB_REAL].dfd > -1)
2831 res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par);
2833 /* Assume not off hook on CVRS */
2835 par.rxisoffhook = 0;
2838 ast_log(LOG_WARNING, "Unable to check hook state on channel %d: %s\n", p->channel, strerror(errno));
2841 if ((p->sig == SIG_FXSKS) || (p->sig == SIG_FXSGS)) {
2842 /* When "onhook" that means no battery on the line, and thus
2843 it is out of service..., if it's on a TDM card... If it's a channel
2844 bank, there is no telling... */
2845 return (par.rxbits > -1) || par.rxisoffhook;
2848 return par.rxisoffhook;
2851 static void dahdi_enable_ec(struct dahdi_pvt *p);
2852 static void dahdi_disable_ec(struct dahdi_pvt *p);
2854 static int my_set_echocanceller(void *pvt, int enable)
2856 struct dahdi_pvt *p = pvt;
2861 dahdi_disable_ec(p);
2866 static int dahdi_ring_phone(struct dahdi_pvt *p);
2868 static int my_ring(void *pvt)
2870 struct dahdi_pvt *p = pvt;
2872 return dahdi_ring_phone(p);
2875 static int my_flash(void *pvt)
2877 struct dahdi_pvt *p = pvt;
2878 int func = DAHDI_FLASH;
2879 return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &func);
2882 static inline int dahdi_set_hook(int fd, int hs);
2884 static int my_off_hook(void *pvt)
2886 struct dahdi_pvt *p = pvt;
2887 return dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK);
2890 static void my_set_needringing(void *pvt, int value)
2892 struct dahdi_pvt *p = pvt;
2893 p->subs[SUB_REAL].needringing = value;
2896 static void my_set_polarity(void *pvt, int value)
2898 struct dahdi_pvt *p = pvt;
2900 if (p->channel == CHAN_PSEUDO) {
2903 p->polarity = value;
2904 ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETPOLARITY, &value);
2907 static void my_start_polarityswitch(void *pvt)
2909 struct dahdi_pvt *p = pvt;
2911 if (p->answeronpolarityswitch || p->hanguponpolarityswitch) {
2912 my_set_polarity(pvt, 0);
2916 static void my_answer_polarityswitch(void *pvt)
2918 struct dahdi_pvt *p = pvt;
2920 if (!p->answeronpolarityswitch) {
2924 my_set_polarity(pvt, 1);
2927 static void my_hangup_polarityswitch(void *pvt)
2929 struct dahdi_pvt *p = pvt;
2931 if (!p->hanguponpolarityswitch) {
2935 if (p->answeronpolarityswitch) {
2936 my_set_polarity(pvt, 0);
2938 my_set_polarity(pvt, 1);
2942 static int my_start(void *pvt)
2944 struct dahdi_pvt *p = pvt;
2945 int x = DAHDI_START;
2947 return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
2950 static int my_dial_digits(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop)
2952 int index = analogsub_to_dahdisub(sub);
2954 struct dahdi_pvt *p = pvt;
2955 struct dahdi_dialoperation ddop;
2957 if (dop->op != ANALOG_DIAL_OP_REPLACE) {
2958 ast_log(LOG_ERROR, "Fix the dial_digits callback!\n");
2962 if (sub != ANALOG_SUB_REAL) {
2963 ast_log(LOG_ERROR, "Trying to dial_digits '%s' on channel %d subchannel %d\n",
2964 dop->dialstr, p->channel, sub);
2968 ddop.op = DAHDI_DIAL_OP_REPLACE;
2969 ast_copy_string(ddop.dialstr, dop->dialstr, sizeof(ddop.dialstr));
2971 ast_debug(1, "Channel %d: Sending '%s' to DAHDI_DIAL.\n", p->channel, ddop.dialstr);
2973 res = ioctl(p->subs[index].dfd, DAHDI_DIAL, &ddop);
2975 ast_debug(1, "DAHDI_DIAL ioctl failed on %s: %s\n", p->owner->name, strerror(errno));
2981 static void dahdi_train_ec(struct dahdi_pvt *p);
2983 static int my_train_echocanceller(void *pvt)
2985 struct dahdi_pvt *p = pvt;
2992 static int my_is_dialing(void *pvt, enum analog_sub sub)
2994 struct dahdi_pvt *p = pvt;
2998 index = analogsub_to_dahdisub(sub);
3000 if (ioctl(p->subs[index].dfd, DAHDI_DIALING, &x)) {
3001 ast_debug(1, "DAHDI_DIALING ioctl failed!\n");
3008 static int my_on_hook(void *pvt)
3010 struct dahdi_pvt *p = pvt;
3011 return dahdi_set_hook(p->subs[ANALOG_SUB_REAL].dfd, DAHDI_ONHOOK);
3014 #if defined(HAVE_PRI)
3015 static void my_pri_fixup_chans(void *chan_old, void *chan_new)
3017 struct dahdi_pvt *old_chan = chan_old;
3018 struct dahdi_pvt *new_chan = chan_new;
3020 new_chan->owner = old_chan->owner;
3021 old_chan->owner = NULL;
3022 if (new_chan->owner) {
3023 new_chan->owner->tech_pvt = new_chan;
3024 new_chan->owner->fds[0] = new_chan->subs[SUB_REAL].dfd;
3025 new_chan->subs[SUB_REAL].owner = old_chan->subs[SUB_REAL].owner;
3026 old_chan->subs[SUB_REAL].owner = NULL;
3028 /* Copy any DSP that may be present */
3029 new_chan->dsp = old_chan->dsp;
3030 new_chan->dsp_features = old_chan->dsp_features;
3031 old_chan->dsp = NULL;
3032 old_chan->dsp_features = 0;
3034 /* Transfer flags from the old channel. */
3035 new_chan->dialing = old_chan->dialing;
3036 new_chan->digital = old_chan->digital;
3037 new_chan->outgoing = old_chan->outgoing;
3038 old_chan->dialing = 0;
3039 old_chan->digital = 0;
3040 old_chan->outgoing = 0;
3042 /* More stuff to transfer to the new channel. */
3043 new_chan->law = old_chan->law;
3044 strcpy(new_chan->dialstring, old_chan->dialstring);
3046 #endif /* defined(HAVE_PRI) */
3048 #if defined(HAVE_PRI)
3049 static int sig_pri_tone_to_dahditone(enum sig_pri_tone tone)
3052 case SIG_PRI_TONE_RINGTONE:
3053 return DAHDI_TONE_RINGTONE;
3054 case SIG_PRI_TONE_STUTTER:
3055 return DAHDI_TONE_STUTTER;
3056 case SIG_PRI_TONE_CONGESTION:
3057 return DAHDI_TONE_CONGESTION;
3058 case SIG_PRI_TONE_DIALTONE:
3059 return DAHDI_TONE_DIALTONE;
3060 case SIG_PRI_TONE_DIALRECALL:
3061 return DAHDI_TONE_DIALRECALL;
3062 case SIG_PRI_TONE_INFO:
3063 return DAHDI_TONE_INFO;
3064 case SIG_PRI_TONE_BUSY:
3065 return DAHDI_TONE_BUSY;
3070 #endif /* defined(HAVE_PRI) */
3072 #if defined(HAVE_PRI)
3073 static void my_handle_dchan_exception(struct sig_pri_span *pri, int index)
3077 ioctl(pri->fds[index], DAHDI_GETEVENT, &x);
3079 ast_log(LOG_NOTICE, "PRI got event: %s (%d) on D-channel of span %d\n", event2str(x), x, pri->span);
3081 /* Keep track of alarm state */
3083 case DAHDI_EVENT_ALARM:
3084 pri_event_alarm(pri, index, 0);
3086 case DAHDI_EVENT_NOALARM:
3087 pri_event_noalarm(pri, index, 0);
3093 #endif /* defined(HAVE_PRI) */
3095 #if defined(HAVE_PRI)
3096 static int my_pri_play_tone(void *pvt, enum sig_pri_tone tone)
3098 struct dahdi_pvt *p = pvt;
3100 return tone_zone_play_tone(p->subs[SUB_REAL].dfd, sig_pri_tone_to_dahditone(tone));
3102 #endif /* defined(HAVE_PRI) */
3104 #if defined(HAVE_PRI) || defined(HAVE_SS7)
3107 * \brief Set the caller id information.
3110 * \param pvt DAHDI private structure
3111 * \param caller Caller-id information to set.
3115 static void my_set_callerid(void *pvt, const struct ast_party_caller *caller)
3117 struct dahdi_pvt *p = pvt;
3119 ast_copy_string(p->cid_num,
3120 S_COR(caller->id.number.valid, caller->id.number.str, ""),
3121 sizeof(p->cid_num));
3122 ast_copy_string(p->cid_name,
3123 S_COR(caller->id.name.valid, caller->id.name.str, ""),
3124 sizeof(p->cid_name));
3125 ast_copy_string(p->cid_subaddr,
3126 S_COR(caller->id.subaddress.valid, caller->id.subaddress.str, ""),
3127 sizeof(p->cid_subaddr));
3128 p->cid_ton = caller->id.number.plan;
3129 p->callingpres = ast_party_id_presentation(&caller->id);
3130 if (caller->id.tag) {
3131 ast_copy_string(p->cid_tag, caller->id.tag, sizeof(p->cid_tag));
3133 ast_copy_string(p->cid_ani,
3134 S_COR(caller->ani.number.valid, caller->ani.number.str, ""),
3135 sizeof(p->cid_ani));
3136 p->cid_ani2 = caller->ani2;
3138 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
3140 #if defined(HAVE_PRI) || defined(HAVE_SS7)
3143 * \brief Set the Dialed Number Identifier.
3146 * \param pvt DAHDI private structure
3147 * \param dnid Dialed Number Identifier string.
3151 static void my_set_dnid(void *pvt, const char *dnid)
3153 struct dahdi_pvt *p = pvt;
3155 ast_copy_string(p->dnid, dnid, sizeof(p->dnid));
3157 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
3159 #if defined(HAVE_PRI)
3162 * \brief Set the Redirecting Directory Number Information Service (RDNIS).
3165 * \param pvt DAHDI private structure
3166 * \param rdnis Redirecting Directory Number Information Service (RDNIS) string.
3170 static void my_set_rdnis(void *pvt, const char *rdnis)
3172 struct dahdi_pvt *p = pvt;
3174 ast_copy_string(p->rdnis, rdnis, sizeof(p->rdnis));
3176 #endif /* defined(HAVE_PRI) */
3178 #if defined(HAVE_PRI)
3181 * \brief Make a dialstring for native ISDN CC to recall properly.
3184 * \param priv Channel private control structure.
3185 * \param buf Where to put the modified dialstring.
3186 * \param buf_size Size of modified dialstring buffer.
3189 * original dialstring:
3190 * DAHDI/[i<span>-](g|G|r|R)<group#(0-63)>[c|r<cadance#>|d][/extension[/options]]
3192 * The modified dialstring will have prefixed the channel-group section
3193 * with the ISDN channel restriction.
3196 * DAHDI/i<span>-(g|G|r|R)<group#(0-63)>[c|r<cadance#>|d][/extension[/options]]
3198 * The routine will check to see if the ISDN channel restriction is already
3199 * in the original dialstring.
3203 static void my_pri_make_cc_dialstring(void *priv, char *buf, size_t buf_size)
3206 struct dahdi_pvt *pvt;
3207 AST_DECLARE_APP_ARGS(args,
3208 AST_APP_ARG(tech); /* channel technology token */
3209 AST_APP_ARG(group); /* channel/group token */
3210 //AST_APP_ARG(ext); /* extension token */
3211 //AST_APP_ARG(opts); /* options token */
3212 //AST_APP_ARG(other); /* Any remining unused arguments */