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
42 <depend>dahdi</depend>
43 <depend>tonezone</depend>
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 QSIG call rerouting facility over a PRI.
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 a Callrerouting Facility IE over the
152 current channel.</para>
155 <application name="DAHDIAcceptR2Call" language="en_US">
157 Accept an R2 call if its not already accepted (you still need to answer it)
160 <parameter name="charge" required="true">
161 <para>Yes or No.</para>
162 <para>Whether you want to accept the call with charge or without charge.</para>
166 <para>This application will Accept the R2 call either with charge or no charge.</para>
169 <manager name="DAHDITransfer" language="en_US">
171 Transfer DAHDI Channel.
174 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
175 <parameter name="DAHDIChannel" required="true">
176 <para>DAHDI channel name to transfer.</para>
180 <para>Transfer a DAHDI channel.</para>
183 <manager name="DAHDIHangup" language="en_US">
185 Hangup DAHDI Channel.
188 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
189 <parameter name="DAHDIChannel" required="true">
190 <para>DAHDI channel name to hangup.</para>
194 <para>Hangup a DAHDI channel.</para>
197 <manager name="DAHDIDialOffhook" language="en_US">
199 Dial over DAHDI channel while offhook.
202 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
203 <parameter name="DAHDIChannel" required="true" />
204 <parameter name="Number" required="true" />
209 <manager name="DAHDIDNDon" language="en_US">
211 Toggle DAHDI channel Do Not Disturb status ON.
214 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
215 <parameter name="DAHDIChannel" required="true" />
220 <manager name="DAHDIDNDoff" language="en_US">
222 Toggle DAHDI channel Do Not Disturb status OFF.
225 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
226 <parameter name="DAHDIChannel" required="true" />
231 <manager name="DAHDIShowChannels" language="en_US">
233 Show status DAHDI channels.
236 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
237 <parameter name="DAHDIChannel" required="true" />
242 <manager name="DAHDIRestart" language="en_US">
244 Fully Restart DAHDI channels (terminates calls).
247 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
254 #define SMDI_MD_WAIT_TIMEOUT 1500 /* 1.5 seconds */
256 static const char * const lbostr[] = {
257 "0 db (CSU)/0-133 feet (DSX-1)",
258 "133-266 feet (DSX-1)",
259 "266-399 feet (DSX-1)",
260 "399-533 feet (DSX-1)",
261 "533-655 feet (DSX-1)",
267 /*! Global jitterbuffer configuration - by default, jb is disabled */
268 static struct ast_jb_conf default_jbconf =
272 .resync_threshold = -1,
276 static struct ast_jb_conf global_jbconf;
279 * \note Define ZHONE_HACK to cause us to go off hook and then back on hook when
280 * the user hangs up to reset the state machine so ring works properly.
281 * This is used to be able to support kewlstart by putting the zhone in
282 * groundstart mode since their forward disconnect supervision is entirely
283 * broken even though their documentation says it isn't and their support
284 * is entirely unwilling to provide any assistance with their channel banks
285 * even though their web site says they support their products for life.
287 /* #define ZHONE_HACK */
289 /*! \brief Typically, how many rings before we should send Caller*ID */
290 #define DEFAULT_CIDRINGS 1
292 #define AST_LAW(p) (((p)->law == DAHDI_LAW_ALAW) ? AST_FORMAT_ALAW : AST_FORMAT_ULAW)
295 /*! \brief Signaling types that need to use MF detection should be placed in this macro */
296 #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))
298 static const char tdesc[] = "DAHDI Telephony Driver"
299 #if defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2)
301 #if defined(HAVE_PRI)
303 #endif /* defined(HAVE_PRI) */
304 #if defined(HAVE_SS7)
305 #if defined(HAVE_PRI)
307 #endif /* defined(HAVE_PRI) */
309 #endif /* defined(HAVE_SS7) */
310 #if defined(HAVE_OPENR2)
311 #if defined(HAVE_PRI) || defined(HAVE_SS7)
313 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
315 #endif /* defined(HAVE_OPENR2) */
316 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2) */
319 static const char config[] = "chan_dahdi.conf";
321 #define SIG_EM DAHDI_SIG_EM
322 #define SIG_EMWINK (0x0100000 | DAHDI_SIG_EM)
323 #define SIG_FEATD (0x0200000 | DAHDI_SIG_EM)
324 #define SIG_FEATDMF (0x0400000 | DAHDI_SIG_EM)
325 #define SIG_FEATB (0x0800000 | DAHDI_SIG_EM)
326 #define SIG_E911 (0x1000000 | DAHDI_SIG_EM)
327 #define SIG_FEATDMF_TA (0x2000000 | DAHDI_SIG_EM)
328 #define SIG_FGC_CAMA (0x4000000 | DAHDI_SIG_EM)
329 #define SIG_FGC_CAMAMF (0x8000000 | DAHDI_SIG_EM)
330 #define SIG_FXSLS DAHDI_SIG_FXSLS
331 #define SIG_FXSGS DAHDI_SIG_FXSGS
332 #define SIG_FXSKS DAHDI_SIG_FXSKS
333 #define SIG_FXOLS DAHDI_SIG_FXOLS
334 #define SIG_FXOGS DAHDI_SIG_FXOGS
335 #define SIG_FXOKS DAHDI_SIG_FXOKS
336 #define SIG_PRI DAHDI_SIG_CLEAR
337 #define SIG_BRI (0x2000000 | DAHDI_SIG_CLEAR)
338 #define SIG_BRI_PTMP (0X4000000 | DAHDI_SIG_CLEAR)
339 #define SIG_SS7 (0x1000000 | DAHDI_SIG_CLEAR)
340 #define SIG_MFCR2 DAHDI_SIG_CAS
341 #define SIG_SF DAHDI_SIG_SF
342 #define SIG_SFWINK (0x0100000 | DAHDI_SIG_SF)
343 #define SIG_SF_FEATD (0x0200000 | DAHDI_SIG_SF)
344 #define SIG_SF_FEATDMF (0x0400000 | DAHDI_SIG_SF)
345 #define SIG_SF_FEATB (0x0800000 | DAHDI_SIG_SF)
346 #define SIG_EM_E1 DAHDI_SIG_EM_E1
349 #define NUM_SPANS DAHDI_MAX_SPANS
354 #define CHAN_PSEUDO -2
356 #define CALLPROGRESS_PROGRESS 1
357 #define CALLPROGRESS_FAX_OUTGOING 2
358 #define CALLPROGRESS_FAX_INCOMING 4
359 #define CALLPROGRESS_FAX (CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING)
361 #define NUM_CADENCE_MAX 25
362 static int num_cadence = 4;
363 static int user_has_defined_cadences = 0;
365 static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX] = {
366 { { 125, 125, 2000, 4000 } }, /*!< Quick chirp followed by normal ring */
367 { { 250, 250, 500, 1000, 250, 250, 500, 4000 } }, /*!< British style ring */
368 { { 125, 125, 125, 125, 125, 4000 } }, /*!< Three short bursts */
369 { { 1000, 500, 2500, 5000 } }, /*!< Long ring */
372 /*! \brief cidrings says in which pause to transmit the cid information, where the first pause
373 * is 1, the second pause is 2 and so on.
376 static int cidrings[NUM_CADENCE_MAX] = {
377 2, /*!< Right after first long ring */
378 4, /*!< Right after long part */
379 3, /*!< After third chirp */
380 2, /*!< Second spell */
383 /* ETSI EN300 659-1 specifies the ring pulse between 200 and 300 mS */
384 static struct dahdi_ring_cadence AS_RP_cadence = {{250, 10000}};
386 #define ISTRUNK(p) ((p->sig == SIG_FXSLS) || (p->sig == SIG_FXSKS) || \
387 (p->sig == SIG_FXSGS) || (p->sig == SIG_PRI))
389 #define CANBUSYDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
390 #define CANPROGRESSDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
392 static char defaultcic[64] = "";
393 static char defaultozz[64] = "";
395 static char parkinglot[AST_MAX_EXTENSION] = ""; /*!< Default parking lot for this channel */
397 /*! Run this script when the MWI state changes on an FXO line, if mwimonitor is enabled */
398 static char mwimonitornotify[PATH_MAX] = "";
399 #ifndef HAVE_DAHDI_LINEREVERSE_VMWI
400 static int mwisend_rpas = 0;
403 static char progzone[10] = "";
405 static int usedistinctiveringdetection = 0;
406 static int distinctiveringaftercid = 0;
408 static int numbufs = 4;
410 static int mwilevel = 512;
411 static int dtmfcid_level = 256;
413 #define REPORT_CHANNEL_ALARMS 1
414 #define REPORT_SPAN_ALARMS 2
415 static int report_alarms = REPORT_CHANNEL_ALARMS;
418 static int pridebugfd = -1;
419 static char pridebugfilename[1024] = "";
422 /*! \brief Wait up to 16 seconds for first digit (FXO logic) */
423 static int firstdigittimeout = 16000;
425 /*! \brief How long to wait for following digits (FXO logic) */
426 static int gendigittimeout = 8000;
428 /*! \brief How long to wait for an extra digit, if there is an ambiguous match */
429 static int matchdigittimeout = 3000;
431 /*! \brief Protect the interface list (of dahdi_pvt's) */
432 AST_MUTEX_DEFINE_STATIC(iflock);
435 static int ifcount = 0;
438 AST_MUTEX_DEFINE_STATIC(pridebugfdlock);
441 /*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
442 when it's doing something critical. */
443 AST_MUTEX_DEFINE_STATIC(monlock);
445 /*! \brief This is the thread for the monitor which checks for input on the channels
446 which are not currently in use. */
447 static pthread_t monitor_thread = AST_PTHREADT_NULL;
448 static ast_cond_t ss_thread_complete;
449 AST_MUTEX_DEFINE_STATIC(ss_thread_lock);
450 AST_MUTEX_DEFINE_STATIC(restart_lock);
451 static int ss_thread_count = 0;
452 static int num_restart_pending = 0;
454 static int restart_monitor(void);
456 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);
458 static int dahdi_sendtext(struct ast_channel *c, const char *text);
460 static void mwi_event_cb(const struct ast_event *event, void *userdata)
462 /* This module does not handle MWI in an event-based manner. However, it
463 * subscribes to MWI for each mailbox that is configured so that the core
464 * knows that we care about it. Then, chan_dahdi will get the MWI from the
465 * event cache instead of checking the mailbox directly. */
468 /*! \brief Avoid the silly dahdi_getevent which ignores a bunch of events */
469 static inline int dahdi_get_event(int fd)
472 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
477 /*! \brief Avoid the silly dahdi_waitevent which ignores a bunch of events */
478 static inline int dahdi_wait_event(int fd)
481 i = DAHDI_IOMUX_SIGEVENT;
482 if (ioctl(fd, DAHDI_IOMUX, &i) == -1)
484 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
489 /*! Chunk size to read -- we use 20ms chunks to make things happy. */
490 #define READ_SIZE 160
492 #define MASK_AVAIL (1 << 0) /*!< Channel available for PRI use */
493 #define MASK_INUSE (1 << 1) /*!< Channel currently in use */
495 #define CALLWAITING_SILENT_SAMPLES ((300 * 8) / READ_SIZE) /*!< 300 ms */
496 #define CALLWAITING_REPEAT_SAMPLES ((10000 * 8) / READ_SIZE) /*!< 10,000 ms */
497 #define CALLWAITING_SUPPRESS_SAMPLES ((100 * 8) / READ_SIZE) /*!< 100 ms */
498 #define CIDCW_EXPIRE_SAMPLES ((500 * 8) / READ_SIZE) /*!< 500 ms */
499 #define MIN_MS_SINCE_FLASH ((2000) ) /*!< 2000 ms */
500 #define DEFAULT_RINGT ((8000 * 8) / READ_SIZE) /*!< 8,000 ms */
505 * \brief Configured ring timeout base.
506 * \note Value computed from "ringtimeout" read in from chan_dahdi.conf if it exists.
508 static int ringt_base = DEFAULT_RINGT;
510 #if defined(HAVE_SS7)
513 struct sig_ss7_linkset ss7;
516 static struct dahdi_ss7 linksets[NUM_SPANS];
518 static int cur_ss7type = -1;
519 static int cur_linkset = -1;
520 static int cur_pointcode = -1;
521 static int cur_cicbeginswith = -1;
522 static int cur_adjpointcode = -1;
523 static int cur_networkindicator = -1;
524 static int cur_defaultdpc = -1;
525 #endif /* defined(HAVE_SS7) */
529 pthread_t r2master; /*!< Thread of master */
530 openr2_context_t *protocol_context; /*!< OpenR2 context handle */
531 struct dahdi_pvt *pvts[SIG_MFCR2_MAX_CHANNELS]; /*!< Member channel pvt structs */
532 int numchans; /*!< Number of channels in this R2 block */
533 int monitored_count; /*!< Number of channels being monitored */
536 struct dahdi_mfcr2_conf {
537 openr2_variant_t variant;
539 int metering_pulse_timeout;
542 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
546 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3
547 int dtmf_end_timeout;
549 signed int get_ani_first:2;
550 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
551 signed int skip_category_request:2;
553 unsigned int call_files:1;
554 unsigned int allow_collect_calls:1;
555 unsigned int charge_calls:1;
556 unsigned int accept_on_offer:1;
557 unsigned int forced_release:1;
558 unsigned int double_answer:1;
559 signed int immediate_accept:2;
560 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
561 signed int dtmf_dialing:2;
562 signed int dtmf_detection:2;
564 char logdir[OR2_MAX_PATH];
565 char r2proto_file[OR2_MAX_PATH];
566 openr2_log_level_t loglevel;
567 openr2_calling_party_category_t category;
570 /* malloc'd array of malloc'd r2links */
571 static struct dahdi_mfcr2 **r2links;
572 /* how many r2links have been malloc'd */
573 static int r2links_count = 0;
575 #endif /* HAVE_OPENR2 */
580 int dchannels[SIG_PRI_NUM_DCHANS]; /*!< What channel are the dchannels on */
581 int mastertrunkgroup; /*!< What trunk group is our master */
582 int prilogicalspan; /*!< Logical span number within trunk group */
583 struct sig_pri_span pri;
586 static struct dahdi_pri pris[NUM_SPANS];
588 #if defined(HAVE_PRI_CCSS)
589 /*! DAHDI PRI CCSS agent and monitor type name. */
590 static const char dahdi_pri_cc_type[] = "DAHDI/PRI";
591 #endif /* defined(HAVE_PRI_CCSS) */
594 /*! Shut up the compiler */
598 #define SUB_REAL 0 /*!< Active call */
599 #define SUB_CALLWAIT 1 /*!< Call-Waiting call on hold */
600 #define SUB_THREEWAY 2 /*!< Three-way call */
602 /* Polarity states */
603 #define POLARITY_IDLE 0
604 #define POLARITY_REV 1
607 struct distRingData {
611 struct ringContextData {
612 char contextData[AST_MAX_CONTEXT];
614 struct dahdi_distRings {
615 struct distRingData ringnum[3];
616 struct ringContextData ringContext[3];
619 static const char * const subnames[] = {
625 struct dahdi_subchannel {
627 struct ast_channel *owner;
629 short buffer[AST_FRIENDLY_OFFSET/2 + READ_SIZE];
630 struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */
631 unsigned int needringing:1;
632 unsigned int needbusy:1;
633 unsigned int needcongestion:1;
634 unsigned int needanswer:1;
635 unsigned int needflash:1;
636 unsigned int needhold:1;
637 unsigned int needunhold:1;
638 unsigned int linear:1;
639 unsigned int inthreeway:1;
640 struct dahdi_confinfo curconf;
643 #define CONF_USER_REAL (1 << 0)
644 #define CONF_USER_THIRDCALL (1 << 1)
648 /* States for sending MWI message
649 * First three states are required for send Ring Pulse Alert Signal
661 struct mwisend_info {
662 struct timeval pause;
663 mwisend_states mwisend_current;
666 /*! Specify the lists dahdi_pvt can be put in. */
668 DAHDI_IFLIST_NONE, /*!< The dahdi_pvt is not in any list. */
669 DAHDI_IFLIST_MAIN, /*!< The dahdi_pvt is in the main interface list */
670 #if defined(HAVE_PRI)
671 DAHDI_IFLIST_NO_B_CHAN, /*!< The dahdi_pvt is in a no B channel interface list */
672 #endif /* defined(HAVE_PRI) */
676 ast_mutex_t lock; /*!< Channel private lock. */
677 struct callerid_state *cs;
678 struct ast_channel *owner; /*!< Our current active owner (if applicable) */
679 /*!< Up to three channels can be associated with this call */
681 struct dahdi_subchannel sub_unused; /*!< Just a safety precaution */
682 struct dahdi_subchannel subs[3]; /*!< Sub-channels */
683 struct dahdi_confinfo saveconf; /*!< Saved conference info */
685 struct dahdi_pvt *slaves[MAX_SLAVES]; /*!< Slave to us (follows our conferencing) */
686 struct dahdi_pvt *master; /*!< Master to us (we follow their conferencing) */
687 int inconference; /*!< If our real should be in the conference */
689 int bufsize; /*!< Size of the buffers */
690 int buf_no; /*!< Number of buffers */
691 int buf_policy; /*!< Buffer policy */
692 int faxbuf_no; /*!< Number of Fax buffers */
693 int faxbuf_policy; /*!< Fax buffer policy */
694 int sig; /*!< Signalling style */
696 * \brief Nonzero if the signaling type is sent over a radio.
697 * \note Set to a couple of nonzero values but it is only tested like a boolean.
700 int outsigmod; /*!< Outbound Signalling style (modifier) */
701 int oprmode; /*!< "Operator Services" mode */
702 struct dahdi_pvt *oprpeer; /*!< "Operator Services" peer tech_pvt ptr */
703 /*! \brief Amount of gain to increase during caller id */
705 /*! \brief Rx gain set by chan_dahdi.conf */
707 /*! \brief Tx gain set by chan_dahdi.conf */
710 float txdrc; /*!< Dynamic Range Compression factor. a number between 1 and 6ish */
713 int tonezone; /*!< tone zone for this chan, or -1 for default */
714 enum DAHDI_IFLIST which_iflist; /*!< Which interface list is this structure listed? */
715 struct dahdi_pvt *next; /*!< Next channel in list */
716 struct dahdi_pvt *prev; /*!< Prev channel in list */
721 * \brief TRUE if ADSI (Analog Display Services Interface) available
722 * \note Set from the "adsi" value read in from chan_dahdi.conf
726 * \brief TRUE if we can use a polarity reversal to mark when an outgoing
727 * call is answered by the remote party.
728 * \note Set from the "answeronpolarityswitch" value read in from chan_dahdi.conf
730 unsigned int answeronpolarityswitch:1;
732 * \brief TRUE if busy detection is enabled.
733 * (Listens for the beep-beep busy pattern.)
734 * \note Set from the "busydetect" value read in from chan_dahdi.conf
736 unsigned int busydetect:1;
738 * \brief TRUE if call return is enabled.
739 * (*69, if your dialplan doesn't catch this first)
740 * \note Set from the "callreturn" value read in from chan_dahdi.conf
742 unsigned int callreturn:1;
744 * \brief TRUE if busy extensions will hear the call-waiting tone
745 * and can use hook-flash to switch between callers.
746 * \note Can be disabled by dialing *70.
747 * \note Initialized with the "callwaiting" value read in from chan_dahdi.conf
749 unsigned int callwaiting:1;
751 * \brief TRUE if send caller ID for Call Waiting
752 * \note Set from the "callwaitingcallerid" value read in from chan_dahdi.conf
754 unsigned int callwaitingcallerid:1;
756 * \brief TRUE if support for call forwarding enabled.
757 * Dial *72 to enable call forwarding.
758 * Dial *73 to disable call forwarding.
759 * \note Set from the "cancallforward" value read in from chan_dahdi.conf
761 unsigned int cancallforward:1;
763 * \brief TRUE if support for call parking is enabled.
764 * \note Set from the "canpark" value read in from chan_dahdi.conf
766 unsigned int canpark:1;
767 /*! \brief TRUE if to wait for a DTMF digit to confirm answer */
768 unsigned int confirmanswer:1;
770 * \brief TRUE if the channel is to be destroyed on hangup.
771 * (Used by pseudo channels.)
773 unsigned int destroy:1;
774 unsigned int didtdd:1; /*!< flag to say its done it once */
775 /*! \brief TRUE if analog type line dialed no digits in Dial() */
776 unsigned int dialednone:1;
778 * \brief TRUE if in the process of dialing digits or sending something.
779 * \note This is used as a receive squelch for ISDN until connected.
781 unsigned int dialing:1;
782 /*! \brief TRUE if the transfer capability of the call is digital. */
783 unsigned int digital:1;
784 /*! \brief TRUE if Do-Not-Disturb is enabled, present only for non sig_analog */
786 /*! \brief XXX BOOLEAN Purpose??? */
787 unsigned int echobreak:1;
789 * \brief TRUE if echo cancellation enabled when bridged.
790 * \note Initialized with the "echocancelwhenbridged" value read in from chan_dahdi.conf
791 * \note Disabled if the echo canceller is not setup.
793 unsigned int echocanbridged:1;
794 /*! \brief TRUE if echo cancellation is turned on. */
795 unsigned int echocanon:1;
796 /*! \brief TRUE if a fax tone has already been handled. */
797 unsigned int faxhandled:1;
798 /*! TRUE if dynamic faxbuffers are configured for use, default is OFF */
799 unsigned int usefaxbuffers:1;
800 /*! TRUE while buffer configuration override is in use */
801 unsigned int bufferoverrideinuse:1;
802 /*! \brief TRUE if over a radio and dahdi_read() has been called. */
803 unsigned int firstradio:1;
805 * \brief TRUE if the call will be considered "hung up" on a polarity reversal.
806 * \note Set from the "hanguponpolarityswitch" value read in from chan_dahdi.conf
808 unsigned int hanguponpolarityswitch:1;
809 /*! \brief TRUE if DTMF detection needs to be done by hardware. */
810 unsigned int hardwaredtmf:1;
812 * \brief TRUE if the outgoing caller ID is blocked/hidden.
813 * \note Caller ID can be disabled by dialing *67.
814 * \note Caller ID can be enabled by dialing *82.
815 * \note Initialized with the "hidecallerid" value read in from chan_dahdi.conf
817 unsigned int hidecallerid:1;
819 * \brief TRUE if hide just the name not the number for legacy PBX use.
820 * \note Only applies to PRI channels.
821 * \note Set from the "hidecalleridname" value read in from chan_dahdi.conf
823 unsigned int hidecalleridname:1;
824 /*! \brief TRUE if DTMF detection is disabled. */
825 unsigned int ignoredtmf:1;
827 * \brief TRUE if the channel should be answered immediately
828 * without attempting to gather any digits.
829 * \note Set from the "immediate" value read in from chan_dahdi.conf
831 unsigned int immediate:1;
832 /*! \brief TRUE if in an alarm condition. */
833 unsigned int inalarm:1;
834 /*! \brief TRUE if TDD in MATE mode */
836 /*! \brief TRUE if we originated the call leg. */
837 unsigned int outgoing:1;
838 /* unsigned int overlapdial:1; unused and potentially confusing */
840 * \brief TRUE if busy extensions will hear the call-waiting tone
841 * and can use hook-flash to switch between callers.
842 * \note Set from the "callwaiting" value read in from chan_dahdi.conf
844 unsigned int permcallwaiting:1;
846 * \brief TRUE if the outgoing caller ID is blocked/restricted/hidden.
847 * \note Set from the "hidecallerid" value read in from chan_dahdi.conf
849 unsigned int permhidecallerid:1;
851 * \brief TRUE if PRI congestion/busy indications are sent out-of-band.
852 * \note Set from the "priindication" value read in from chan_dahdi.conf
854 unsigned int priindication_oob:1;
856 * \brief TRUE if PRI B channels are always exclusively selected.
857 * \note Set from the "priexclusive" value read in from chan_dahdi.conf
859 unsigned int priexclusive:1;
861 * \brief TRUE if we will pulse dial.
862 * \note Set from the "pulsedial" value read in from chan_dahdi.conf
864 unsigned int pulse:1;
865 /*! \brief TRUE if a pulsed digit was detected. (Pulse dial phone detected) */
866 unsigned int pulsedial:1;
867 unsigned int restartpending:1; /*!< flag to ensure counted only once for restart */
869 * \brief TRUE if caller ID is restricted.
870 * \note Set but not used. Should be deleted. Redundant with permhidecallerid.
871 * \note Set from the "restrictcid" value read in from chan_dahdi.conf
873 unsigned int restrictcid:1;
875 * \brief TRUE if three way calling is enabled
876 * \note Set from the "threewaycalling" value read in from chan_dahdi.conf
878 unsigned int threewaycalling:1;
880 * \brief TRUE if call transfer is enabled
881 * \note For FXS ports (either direct analog or over T1/E1):
882 * Support flash-hook call transfer
883 * \note For digital ports using ISDN PRI protocols:
884 * Support switch-side transfer (called 2BCT, RLT or other names)
885 * \note Set from the "transfer" value read in from chan_dahdi.conf
887 unsigned int transfer:1;
889 * \brief TRUE if caller ID is used on this channel.
890 * \note PRI and SS7 spans will save caller ID from the networking peer.
891 * \note FXS ports will generate the caller ID spill.
892 * \note FXO ports will listen for the caller ID spill.
893 * \note Set from the "usecallerid" value read in from chan_dahdi.conf
895 unsigned int use_callerid:1;
897 * \brief TRUE if we will use the calling presentation setting
898 * from the Asterisk channel for outgoing calls.
899 * \note Only applies to PRI and SS7 channels.
900 * \note Set from the "usecallingpres" value read in from chan_dahdi.conf
902 unsigned int use_callingpres:1;
904 * \brief TRUE if distinctive rings are to be detected.
905 * \note For FXO lines
906 * \note Set indirectly from the "usedistinctiveringdetection" value read in from chan_dahdi.conf
908 unsigned int usedistinctiveringdetection:1;
910 * \brief TRUE if we should use the callerid from incoming call on dahdi transfer.
911 * \note Set from the "useincomingcalleridondahditransfer" value read in from chan_dahdi.conf
913 unsigned int dahditrcallerid:1;
915 * \brief TRUE if allowed to flash-transfer to busy channels.
916 * \note Set from the "transfertobusy" value read in from chan_dahdi.conf
918 unsigned int transfertobusy:1;
920 * \brief TRUE if the FXO port monitors for neon type MWI indications from the other end.
921 * \note Set if the "mwimonitor" value read in contains "neon" from chan_dahdi.conf
923 unsigned int mwimonitor_neon:1;
925 * \brief TRUE if the FXO port monitors for fsk type MWI indications from the other end.
926 * \note Set if the "mwimonitor" value read in contains "fsk" from chan_dahdi.conf
928 unsigned int mwimonitor_fsk:1;
930 * \brief TRUE if the FXO port monitors for rpas precursor to fsk MWI indications from the other end.
931 * \note RPAS - Ring Pulse Alert Signal
932 * \note Set if the "mwimonitor" value read in contains "rpas" from chan_dahdi.conf
934 unsigned int mwimonitor_rpas:1;
935 /*! \brief TRUE if an MWI monitor thread is currently active */
936 unsigned int mwimonitoractive:1;
937 /*! \brief TRUE if a MWI message sending thread is active */
938 unsigned int mwisendactive:1;
940 * \brief TRUE if channel is out of reset and ready
941 * \note Set but not used.
943 unsigned int inservice:1;
945 * \brief TRUE if the channel is locally blocked.
946 * \note Applies to SS7 and MFCR2 channels.
948 unsigned int locallyblocked:1;
950 * \brief TRUE if the channel is remotely blocked.
951 * \note Applies to SS7 and MFCR2 channels.
953 unsigned int remotelyblocked:1;
955 * \brief TRUE if the channel alarms will be managed also as Span ones
956 * \note Applies to all channels
958 unsigned int manages_span_alarms:1;
960 #if defined(HAVE_PRI)
961 struct sig_pri_span *pri;
965 * \brief TRUE if SMDI (Simplified Message Desk Interface) is enabled
966 * \note Set from the "usesmdi" value read in from chan_dahdi.conf
968 unsigned int use_smdi:1;
969 struct mwisend_info mwisend_data;
970 /*! \brief The SMDI interface to get SMDI messages from. */
971 struct ast_smdi_interface *smdi_iface;
973 /*! \brief Distinctive Ring data */
974 struct dahdi_distRings drings;
977 * \brief The configured context for incoming calls.
978 * \note The "context" string read in from chan_dahdi.conf
980 char context[AST_MAX_CONTEXT];
982 * \brief Saved context string.
984 char defcontext[AST_MAX_CONTEXT];
985 /*! \brief Extension to use in the dialplan. */
986 char exten[AST_MAX_EXTENSION];
988 * \brief Language configured for calls.
989 * \note The "language" string read in from chan_dahdi.conf
991 char language[MAX_LANGUAGE];
993 * \brief The configured music-on-hold class to use for calls.
994 * \note The "musicclass" or "mohinterpret" or "musiconhold" string read in from chan_dahdi.conf
996 char mohinterpret[MAX_MUSICCLASS];
998 * \brief Suggested music-on-hold class for peer channel to use for calls.
999 * \note The "mohsuggest" string read in from chan_dahdi.conf
1001 char mohsuggest[MAX_MUSICCLASS];
1002 char parkinglot[AST_MAX_EXTENSION]; /*!< Parking lot for this channel */
1003 #if defined(HAVE_PRI) || defined(HAVE_SS7)
1004 /*! \brief Automatic Number Identification number (Alternate PRI caller ID number) */
1005 char cid_ani[AST_MAX_EXTENSION];
1006 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
1007 /*! \brief Automatic Number Identification code from PRI */
1009 /*! \brief Caller ID number from an incoming call. */
1010 char cid_num[AST_MAX_EXTENSION];
1012 * \brief Caller ID tag from incoming call
1013 * \note the "cid_tag" string read in from chan_dahdi.conf
1015 char cid_tag[AST_MAX_EXTENSION];
1016 /*! \brief Caller ID Q.931 TON/NPI field values. Set by PRI. Zero otherwise. */
1018 /*! \brief Caller ID name from an incoming call. */
1019 char cid_name[AST_MAX_EXTENSION];
1020 /*! \brief Caller ID subaddress from an incoming call. */
1021 char cid_subaddr[AST_MAX_EXTENSION];
1022 char *origcid_num; /*!< malloced original callerid */
1023 char *origcid_name; /*!< malloced original callerid */
1024 /*! \brief Call waiting number. */
1025 char callwait_num[AST_MAX_EXTENSION];
1026 /*! \brief Call waiting name. */
1027 char callwait_name[AST_MAX_EXTENSION];
1028 /*! \brief Redirecting Directory Number Information Service (RDNIS) number */
1029 char rdnis[AST_MAX_EXTENSION];
1030 /*! \brief Dialed Number Identifier */
1031 char dnid[AST_MAX_EXTENSION];
1033 * \brief Bitmapped groups this belongs to.
1034 * \note The "group" bitmapped group string read in from chan_dahdi.conf
1037 /*! \brief Default call PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW. */
1039 /*! \brief Active PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW */
1041 int confno; /*!< Our conference */
1042 int confusers; /*!< Who is using our conference */
1043 int propconfno; /*!< Propagated conference number */
1045 * \brief Bitmapped call groups this belongs to.
1046 * \note The "callgroup" bitmapped group string read in from chan_dahdi.conf
1048 ast_group_t callgroup;
1050 * \brief Bitmapped pickup groups this belongs to.
1051 * \note The "pickupgroup" bitmapped group string read in from chan_dahdi.conf
1053 ast_group_t pickupgroup;
1055 * \brief Channel variable list with associated values to set when a channel is created.
1056 * \note The "setvar" strings read in from chan_dahdi.conf
1058 struct ast_variable *vars;
1059 int channel; /*!< Channel Number */
1060 int span; /*!< Span number */
1061 time_t guardtime; /*!< Must wait this much time before using for new call */
1062 int cid_signalling; /*!< CID signalling type bell202 or v23 */
1063 int cid_start; /*!< CID start indicator, polarity or ring or DTMF without warning event */
1064 int dtmfcid_holdoff_state; /*!< State indicator that allows for line to settle before checking for dtmf energy */
1065 struct timeval dtmfcid_delay; /*!< Time value used for allow line to settle */
1066 int callingpres; /*!< The value of calling presentation that we're going to use when placing a PRI call */
1067 int callwaitingrepeat; /*!< How many samples to wait before repeating call waiting */
1068 int cidcwexpire; /*!< When to stop waiting for CID/CW CAS response (In samples) */
1069 int cid_suppress_expire; /*!< How many samples to suppress after a CID spill. */
1070 /*! \brief Analog caller ID waveform sample buffer */
1071 unsigned char *cidspill;
1072 /*! \brief Position in the cidspill buffer to send out next. */
1074 /*! \brief Length of the cidspill buffer containing samples. */
1076 /*! \brief Ring timeout timer?? */
1079 * \brief Ring timeout base.
1080 * \note Value computed indirectly from "ringtimeout" read in from chan_dahdi.conf
1084 * \brief Number of most significant digits/characters to strip from the dialed number.
1085 * \note Feature is deprecated. Use dialplan logic.
1086 * \note The characters are stripped before the PRI TON/NPI prefix
1087 * characters are processed.
1091 * \brief TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
1093 * After CAS is sent, the call waiting caller id will be sent if the phone
1094 * gives a positive reply.
1097 /*! \brief Number of call waiting rings. */
1099 /*! \brief Echo cancel parameters. */
1101 struct dahdi_echocanparams head;
1102 struct dahdi_echocanparam params[DAHDI_MAX_ECHOCANPARAMS];
1105 * \brief Echo training time. 0 = disabled
1106 * \note Set from the "echotraining" value read in from chan_dahdi.conf
1109 /*! \brief Filled with 'w'. XXX Purpose?? */
1112 * \brief Number of times to see "busy" tone before hanging up.
1113 * \note Set from the "busycount" value read in from chan_dahdi.conf
1117 * \brief Length of "busy" tone on time.
1118 * \note Set from the "busypattern" value read in from chan_dahdi.conf
1120 int busy_tonelength;
1122 * \brief Length of "busy" tone off time.
1123 * \note Set from the "busypattern" value read in from chan_dahdi.conf
1125 int busy_quietlength;
1127 * \brief Bitmapped call progress detection flags. CALLPROGRESS_xxx values.
1128 * \note Bits set from the "callprogress" and "faxdetect" values read in from chan_dahdi.conf
1132 * \brief Number of milliseconds to wait for dialtone.
1133 * \note Set from the "waitfordialtone" value read in from chan_dahdi.conf
1135 int waitfordialtone;
1136 struct timeval waitingfordt; /*!< Time we started waiting for dialtone */
1137 struct timeval flashtime; /*!< Last flash-hook time */
1138 /*! \brief Opaque DSP configuration structure. */
1139 struct ast_dsp *dsp;
1140 /*! \brief DAHDI dial operation command struct for ioctl() call. */
1141 struct dahdi_dialoperation dop;
1142 int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
1143 /*! \brief Second part of SIG_FEATDMF_TA wink operation. */
1145 char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
1146 int amaflags; /*!< AMA Flags */
1147 struct tdd_state *tdd; /*!< TDD flag */
1148 /*! \brief Accumulated call forwarding number. */
1149 char call_forward[AST_MAX_EXTENSION];
1151 * \brief Voice mailbox location.
1152 * \note Set from the "mailbox" string read in from chan_dahdi.conf
1154 char mailbox[AST_MAX_EXTENSION];
1155 /*! \brief Opaque event subscription parameters for message waiting indication support. */
1156 struct ast_event_sub *mwi_event_sub;
1157 /*! \brief Delayed dialing for E911. Overlap digits for ISDN. */
1159 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
1160 struct dahdi_vmwi_info mwisend_setting; /*!< Which VMWI methods to use */
1161 unsigned int mwisend_fsk: 1; /*! Variable for enabling FSK MWI handling in chan_dahdi */
1162 unsigned int mwisend_rpas:1; /*! Variable for enabling Ring Pulse Alert before MWI FSK Spill */
1164 int distinctivering; /*!< Which distinctivering to use */
1165 int dtmfrelax; /*!< whether to run in relaxed DTMF mode */
1166 /*! \brief Holding place for event injected from outside normal operation. */
1169 * \brief Minimal time period (ms) between the answer polarity
1170 * switch and hangup polarity switch.
1172 int polarityonanswerdelay;
1173 /*! \brief Start delay time if polarityonanswerdelay is nonzero. */
1174 struct timeval polaritydelaytv;
1176 * \brief Send caller ID on FXS after this many rings. Set to 1 for US.
1177 * \note Set from the "sendcalleridafter" value read in from chan_dahdi.conf
1179 int sendcalleridafter;
1180 /*! \brief Current line interface polarity. POLARITY_IDLE, POLARITY_REV */
1182 /*! \brief DSP feature flags: DSP_FEATURE_xxx */
1184 #if defined(HAVE_SS7)
1185 /*! \brief SS7 control parameters */
1186 struct sig_ss7_linkset *ss7;
1187 #endif /* defined(HAVE_SS7) */
1189 struct dahdi_mfcr2 *mfcr2;
1190 openr2_chan_t *r2chan;
1191 openr2_calling_party_category_t mfcr2_recvd_category;
1192 openr2_calling_party_category_t mfcr2_category;
1193 int mfcr2_dnis_index;
1194 int mfcr2_ani_index;
1196 int mfcr2_answer_pending:1;
1197 int mfcr2_charge_calls:1;
1198 int mfcr2_allow_collect_calls:1;
1199 int mfcr2_forced_release:1;
1200 int mfcr2_dnis_matched:1;
1201 int mfcr2_call_accepted:1;
1202 int mfcr2_accept_on_offer:1;
1203 int mfcr2_progress_sent:1;
1205 /*! \brief DTMF digit in progress. 0 when no digit in progress. */
1207 /*! \brief TRUE if confrence is muted. */
1210 struct ast_cc_config_params *cc_params;
1211 /* DAHDI channel names may differ greatly from the
1212 * string that was provided to an app such as Dial. We
1213 * need to save the original string passed to dahdi_request
1214 * for call completion purposes. This way, we can replicate
1215 * the original dialed string later.
1217 char dialstring[AST_CHANNEL_NAME];
1220 #define DATA_EXPORT_DAHDI_PVT(MEMBER) \
1221 MEMBER(dahdi_pvt, cid_rxgain, AST_DATA_DOUBLE) \
1222 MEMBER(dahdi_pvt, rxgain, AST_DATA_DOUBLE) \
1223 MEMBER(dahdi_pvt, txgain, AST_DATA_DOUBLE) \
1224 MEMBER(dahdi_pvt, txdrc, AST_DATA_DOUBLE) \
1225 MEMBER(dahdi_pvt, rxdrc, AST_DATA_DOUBLE) \
1226 MEMBER(dahdi_pvt, adsi, AST_DATA_BOOLEAN) \
1227 MEMBER(dahdi_pvt, answeronpolarityswitch, AST_DATA_BOOLEAN) \
1228 MEMBER(dahdi_pvt, busydetect, AST_DATA_BOOLEAN) \
1229 MEMBER(dahdi_pvt, callreturn, AST_DATA_BOOLEAN) \
1230 MEMBER(dahdi_pvt, callwaiting, AST_DATA_BOOLEAN) \
1231 MEMBER(dahdi_pvt, callwaitingcallerid, AST_DATA_BOOLEAN) \
1232 MEMBER(dahdi_pvt, cancallforward, AST_DATA_BOOLEAN) \
1233 MEMBER(dahdi_pvt, canpark, AST_DATA_BOOLEAN) \
1234 MEMBER(dahdi_pvt, confirmanswer, AST_DATA_BOOLEAN) \
1235 MEMBER(dahdi_pvt, destroy, AST_DATA_BOOLEAN) \
1236 MEMBER(dahdi_pvt, didtdd, AST_DATA_BOOLEAN) \
1237 MEMBER(dahdi_pvt, dialednone, AST_DATA_BOOLEAN) \
1238 MEMBER(dahdi_pvt, dialing, AST_DATA_BOOLEAN) \
1239 MEMBER(dahdi_pvt, digital, AST_DATA_BOOLEAN) \
1240 MEMBER(dahdi_pvt, dnd, AST_DATA_BOOLEAN) \
1241 MEMBER(dahdi_pvt, echobreak, AST_DATA_BOOLEAN) \
1242 MEMBER(dahdi_pvt, echocanbridged, AST_DATA_BOOLEAN) \
1243 MEMBER(dahdi_pvt, echocanon, AST_DATA_BOOLEAN) \
1244 MEMBER(dahdi_pvt, faxhandled, AST_DATA_BOOLEAN) \
1245 MEMBER(dahdi_pvt, usefaxbuffers, AST_DATA_BOOLEAN) \
1246 MEMBER(dahdi_pvt, bufferoverrideinuse, AST_DATA_BOOLEAN) \
1247 MEMBER(dahdi_pvt, firstradio, AST_DATA_BOOLEAN) \
1248 MEMBER(dahdi_pvt, hanguponpolarityswitch, AST_DATA_BOOLEAN) \
1249 MEMBER(dahdi_pvt, hardwaredtmf, AST_DATA_BOOLEAN) \
1250 MEMBER(dahdi_pvt, hidecallerid, AST_DATA_BOOLEAN) \
1251 MEMBER(dahdi_pvt, hidecalleridname, AST_DATA_BOOLEAN) \
1252 MEMBER(dahdi_pvt, ignoredtmf, AST_DATA_BOOLEAN) \
1253 MEMBER(dahdi_pvt, immediate, AST_DATA_BOOLEAN) \
1254 MEMBER(dahdi_pvt, inalarm, AST_DATA_BOOLEAN) \
1255 MEMBER(dahdi_pvt, mate, AST_DATA_BOOLEAN) \
1256 MEMBER(dahdi_pvt, outgoing, AST_DATA_BOOLEAN) \
1257 MEMBER(dahdi_pvt, permcallwaiting, AST_DATA_BOOLEAN) \
1258 MEMBER(dahdi_pvt, priindication_oob, AST_DATA_BOOLEAN) \
1259 MEMBER(dahdi_pvt, priexclusive, AST_DATA_BOOLEAN) \
1260 MEMBER(dahdi_pvt, pulse, AST_DATA_BOOLEAN) \
1261 MEMBER(dahdi_pvt, pulsedial, AST_DATA_BOOLEAN) \
1262 MEMBER(dahdi_pvt, restartpending, AST_DATA_BOOLEAN) \
1263 MEMBER(dahdi_pvt, restrictcid, AST_DATA_BOOLEAN) \
1264 MEMBER(dahdi_pvt, threewaycalling, AST_DATA_BOOLEAN) \
1265 MEMBER(dahdi_pvt, transfer, AST_DATA_BOOLEAN) \
1266 MEMBER(dahdi_pvt, use_callerid, AST_DATA_BOOLEAN) \
1267 MEMBER(dahdi_pvt, use_callingpres, AST_DATA_BOOLEAN) \
1268 MEMBER(dahdi_pvt, usedistinctiveringdetection, AST_DATA_BOOLEAN) \
1269 MEMBER(dahdi_pvt, dahditrcallerid, AST_DATA_BOOLEAN) \
1270 MEMBER(dahdi_pvt, transfertobusy, AST_DATA_BOOLEAN) \
1271 MEMBER(dahdi_pvt, mwimonitor_neon, AST_DATA_BOOLEAN) \
1272 MEMBER(dahdi_pvt, mwimonitor_fsk, AST_DATA_BOOLEAN) \
1273 MEMBER(dahdi_pvt, mwimonitor_rpas, AST_DATA_BOOLEAN) \
1274 MEMBER(dahdi_pvt, mwimonitoractive, AST_DATA_BOOLEAN) \
1275 MEMBER(dahdi_pvt, mwisendactive, AST_DATA_BOOLEAN) \
1276 MEMBER(dahdi_pvt, inservice, AST_DATA_BOOLEAN) \
1277 MEMBER(dahdi_pvt, locallyblocked, AST_DATA_BOOLEAN) \
1278 MEMBER(dahdi_pvt, remotelyblocked, AST_DATA_BOOLEAN) \
1279 MEMBER(dahdi_pvt, manages_span_alarms, AST_DATA_BOOLEAN) \
1280 MEMBER(dahdi_pvt, use_smdi, AST_DATA_BOOLEAN) \
1281 MEMBER(dahdi_pvt, context, AST_DATA_STRING) \
1282 MEMBER(dahdi_pvt, defcontext, AST_DATA_STRING) \
1283 MEMBER(dahdi_pvt, exten, AST_DATA_STRING) \
1284 MEMBER(dahdi_pvt, language, AST_DATA_STRING) \
1285 MEMBER(dahdi_pvt, mohinterpret, AST_DATA_STRING) \
1286 MEMBER(dahdi_pvt, mohsuggest, AST_DATA_STRING) \
1287 MEMBER(dahdi_pvt, parkinglot, AST_DATA_STRING)
1289 AST_DATA_STRUCTURE(dahdi_pvt, DATA_EXPORT_DAHDI_PVT);
1291 static struct dahdi_pvt *iflist = NULL; /*!< Main interface list start */
1292 static struct dahdi_pvt *ifend = NULL; /*!< Main interface list end */
1294 #if defined(HAVE_PRI)
1295 static struct dahdi_parms_pseudo {
1296 int buf_no; /*!< Number of buffers */
1297 int buf_policy; /*!< Buffer policy */
1298 int faxbuf_no; /*!< Number of Fax buffers */
1299 int faxbuf_policy; /*!< Fax buffer policy */
1300 } dahdi_pseudo_parms;
1301 #endif /* defined(HAVE_PRI) */
1303 /*! \brief Channel configuration from chan_dahdi.conf .
1304 * This struct is used for parsing the [channels] section of chan_dahdi.conf.
1305 * Generally there is a field here for every possible configuration item.
1307 * The state of fields is saved along the parsing and whenever a 'channel'
1308 * statement is reached, the current dahdi_chan_conf is used to configure the
1309 * channel (struct dahdi_pvt)
1311 * \see dahdi_chan_init for the default values.
1313 struct dahdi_chan_conf {
1314 struct dahdi_pvt chan;
1316 struct dahdi_pri pri;
1319 #if defined(HAVE_SS7)
1320 struct dahdi_ss7 ss7;
1321 #endif /* defined(HAVE_SS7) */
1324 struct dahdi_mfcr2_conf mfcr2;
1326 struct dahdi_params timing;
1327 int is_sig_auto; /*!< Use channel signalling from DAHDI? */
1328 /*! Continue configuration even if a channel is not there. */
1329 int ignore_failed_channels;
1332 * \brief The serial port to listen for SMDI data on
1333 * \note Set from the "smdiport" string read in from chan_dahdi.conf
1335 char smdi_port[SMDI_MAX_FILENAME_LEN];
1338 /*! returns a new dahdi_chan_conf with default values (by-value) */
1339 static struct dahdi_chan_conf dahdi_chan_conf_default(void)
1341 /* recall that if a field is not included here it is initialized
1342 * to 0 or equivalent
1344 struct dahdi_chan_conf conf = {
1347 .nsf = PRI_NSF_NONE,
1348 .switchtype = PRI_SWITCH_NI2,
1349 .dialplan = PRI_UNKNOWN + 1,
1350 .localdialplan = PRI_NATIONAL_ISDN + 1,
1351 .nodetype = PRI_CPE,
1352 .qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL,
1354 #if defined(HAVE_PRI_CCSS)
1355 .cc_ptmp_recall_mode = 1,/* specificRecall */
1356 .cc_qsig_signaling_link_req = 1,/* retain */
1357 .cc_qsig_signaling_link_rsp = 1,/* retain */
1358 #endif /* defined(HAVE_PRI_CCSS) */
1363 .internationalprefix = "",
1364 .nationalprefix = "",
1366 .privateprefix = "",
1367 .unknownprefix = "",
1368 .resetinterval = -1,
1371 #if defined(HAVE_SS7)
1373 .called_nai = SS7_NAI_NATIONAL,
1374 .calling_nai = SS7_NAI_NATIONAL,
1375 .internationalprefix = "",
1376 .nationalprefix = "",
1377 .subscriberprefix = "",
1380 #endif /* defined(HAVE_SS7) */
1383 .variant = OR2_VAR_ITU,
1384 .mfback_timeout = -1,
1385 .metering_pulse_timeout = -1,
1388 .get_ani_first = -1,
1389 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
1390 .skip_category_request = -1,
1393 .allow_collect_calls = 0,
1395 .accept_on_offer = 1,
1396 .forced_release = 0,
1398 .immediate_accept = -1,
1399 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
1401 .dtmf_detection = -1,
1402 .dtmf_time_on = OR2_DEFAULT_DTMF_ON,
1403 .dtmf_time_off = OR2_DEFAULT_DTMF_OFF,
1405 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3
1406 .dtmf_end_timeout = -1,
1410 .loglevel = OR2_LOG_ERROR | OR2_LOG_WARNING,
1411 .category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER
1415 .context = "default",
1419 .mohinterpret = "default",
1422 .transfertobusy = 1,
1424 .cid_signalling = CID_SIG_BELL,
1425 .cid_start = CID_START_RING,
1426 .dahditrcallerid = 0,
1435 .echocancel.head.tap_length = 1,
1443 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
1446 .polarityonanswerdelay = 600,
1448 .sendcalleridafter = DEFAULT_CIDRINGS,
1450 .buf_policy = DAHDI_POLICY_IMMEDIATE,
1453 .cc_params = ast_cc_config_params_init(),
1466 .smdi_port = "/dev/ttyS0",
1473 static struct ast_channel *dahdi_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
1474 static int dahdi_digit_begin(struct ast_channel *ast, char digit);
1475 static int dahdi_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
1476 static int dahdi_sendtext(struct ast_channel *c, const char *text);
1477 static int dahdi_call(struct ast_channel *ast, char *rdest, int timeout);
1478 static int dahdi_hangup(struct ast_channel *ast);
1479 static int dahdi_answer(struct ast_channel *ast);
1480 static struct ast_frame *dahdi_read(struct ast_channel *ast);
1481 static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame);
1482 static struct ast_frame *dahdi_exception(struct ast_channel *ast);
1483 static int dahdi_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen);
1484 static int dahdi_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
1485 static int dahdi_setoption(struct ast_channel *chan, int option, void *data, int datalen);
1486 static int dahdi_queryoption(struct ast_channel *chan, int option, void *data, int *datalen);
1487 static int dahdi_func_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
1488 static int dahdi_func_write(struct ast_channel *chan, const char *function, char *data, const char *value);
1489 static int dahdi_devicestate(void *data);
1490 static int dahdi_cc_callback(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback);
1492 static const struct ast_channel_tech dahdi_tech = {
1494 .description = tdesc,
1495 .capabilities = AST_FORMAT_SLINEAR | AST_FORMAT_ULAW | AST_FORMAT_ALAW,
1496 .requester = dahdi_request,
1497 .send_digit_begin = dahdi_digit_begin,
1498 .send_digit_end = dahdi_digit_end,
1499 .send_text = dahdi_sendtext,
1501 .hangup = dahdi_hangup,
1502 .answer = dahdi_answer,
1504 .write = dahdi_write,
1505 .bridge = dahdi_bridge,
1506 .exception = dahdi_exception,
1507 .indicate = dahdi_indicate,
1508 .fixup = dahdi_fixup,
1509 .setoption = dahdi_setoption,
1510 .queryoption = dahdi_queryoption,
1511 .func_channel_read = dahdi_func_read,
1512 .func_channel_write = dahdi_func_write,
1513 .devicestate = dahdi_devicestate,
1514 .cc_callback = dahdi_cc_callback,
1517 #define GET_CHANNEL(p) ((p)->channel)
1519 #define SIG_PRI_LIB_HANDLE_CASES \
1526 * \brief Determine if sig_pri handles the signaling.
1529 * \param signaling Signaling to determine if is for sig_pri.
1531 * \return TRUE if the signaling is for sig_pri.
1533 static inline int dahdi_sig_pri_lib_handles(int signaling)
1537 switch (signaling) {
1538 case SIG_PRI_LIB_HANDLE_CASES:
1549 static enum analog_sigtype dahdisig_to_analogsig(int sig)
1553 return ANALOG_SIG_FXOLS;
1555 return ANALOG_SIG_FXOGS;
1557 return ANALOG_SIG_FXOKS;
1559 return ANALOG_SIG_FXSLS;
1561 return ANALOG_SIG_FXSGS;
1563 return ANALOG_SIG_FXSKS;
1565 return ANALOG_SIG_EMWINK;
1567 return ANALOG_SIG_EM;
1569 return ANALOG_SIG_EM_E1;
1571 return ANALOG_SIG_FEATD;
1573 return ANALOG_SIG_FEATDMF;
1577 return ANALOG_SIG_FGC_CAMA;
1578 case SIG_FGC_CAMAMF:
1579 return ANALOG_SIG_FGC_CAMAMF;
1581 return ANALOG_SIG_FEATB;
1583 return ANALOG_SIG_SFWINK;
1585 return ANALOG_SIG_SF;
1587 return ANALOG_SIG_SF_FEATD;
1588 case SIG_SF_FEATDMF:
1589 return ANALOG_SIG_SF_FEATDMF;
1590 case SIG_FEATDMF_TA:
1591 return ANALOG_SIG_FEATDMF_TA;
1593 return ANALOG_SIG_FEATB;
1600 static int analog_tone_to_dahditone(enum analog_tone tone)
1603 case ANALOG_TONE_RINGTONE:
1604 return DAHDI_TONE_RINGTONE;
1605 case ANALOG_TONE_STUTTER:
1606 return DAHDI_TONE_STUTTER;
1607 case ANALOG_TONE_CONGESTION:
1608 return DAHDI_TONE_CONGESTION;
1609 case ANALOG_TONE_DIALTONE:
1610 return DAHDI_TONE_DIALTONE;
1611 case ANALOG_TONE_DIALRECALL:
1612 return DAHDI_TONE_DIALRECALL;
1613 case ANALOG_TONE_INFO:
1614 return DAHDI_TONE_INFO;
1620 static int analogsub_to_dahdisub(enum analog_sub analogsub)
1624 switch (analogsub) {
1625 case ANALOG_SUB_REAL:
1628 case ANALOG_SUB_CALLWAIT:
1629 index = SUB_CALLWAIT;
1631 case ANALOG_SUB_THREEWAY:
1632 index = SUB_THREEWAY;
1635 ast_log(LOG_ERROR, "Unidentified sub!\n");
1642 static enum analog_event dahdievent_to_analogevent(int event);
1643 static int bump_gains(struct dahdi_pvt *p);
1644 static int dahdi_setlinear(int dfd, int linear);
1646 static int my_start_cid_detect(void *pvt, int cid_signalling)
1648 struct dahdi_pvt *p = pvt;
1649 int index = SUB_REAL;
1650 p->cs = callerid_new(cid_signalling);
1652 ast_log(LOG_ERROR, "Unable to alloc callerid\n");
1656 dahdi_setlinear(p->subs[index].dfd, 0);
1661 static int my_stop_cid_detect(void *pvt)
1663 struct dahdi_pvt *p = pvt;
1664 int index = SUB_REAL;
1666 callerid_free(p->cs);
1667 dahdi_setlinear(p->subs[index].dfd, p->subs[index].linear);
1671 static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_event *ev, size_t timeout)
1673 struct dahdi_pvt *p = pvt;
1674 struct analog_pvt *analog_p = p->sig_pvt;
1675 struct pollfd poller;
1677 int index = SUB_REAL;
1679 unsigned char buf[256];
1682 poller.fd = p->subs[SUB_REAL].dfd;
1683 poller.events = POLLPRI | POLLIN;
1686 res = poll(&poller, 1, timeout);
1688 if (poller.revents & POLLPRI) {
1689 *ev = dahdievent_to_analogevent(dahdi_get_event(p->subs[SUB_REAL].dfd));
1693 if (poller.revents & POLLIN) {
1695 /* Change API: remove cid_signalling from get_callerid, add a new start_cid_detect and stop_cid_detect function
1696 * to enable slin mode and allocate cid detector. get_callerid should be able to be called any number of times until
1697 * either a timeout occurs or CID is detected (returns 0). returning 1 should be event received, and -1 should be
1698 * a failure and die, and returning 2 means no event was received. */
1699 res = read(p->subs[index].dfd, buf, sizeof(buf));
1701 if (errno != ELAST) {
1702 ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
1703 callerid_free(p->cs);
1708 if (analog_p->ringt > 0) {
1709 if (!(--analog_p->ringt)) {
1710 /* only return if we timeout from a ring event */
1715 if (p->cid_signalling == CID_SIG_V23_JP) {
1716 res = callerid_feed_jp(p->cs, buf, res, AST_LAW(p));
1718 res = callerid_feed(p->cs, buf, res, AST_LAW(p));
1722 * The previous diagnostic message output likely
1723 * explains why it failed.
1725 ast_log(LOG_WARNING, "Failed to decode CallerID\n");
1730 callerid_get(p->cs, &name, &num, &flags);
1732 ast_copy_string(namebuf, name, ANALOG_MAX_CID);
1734 ast_copy_string(numbuf, num, ANALOG_MAX_CID);
1736 ast_log(LOG_DEBUG, "CallerID number: %s, name: %s, flags=%d\n", num, name, flags);
1741 *ev = ANALOG_EVENT_NONE;
1745 static const char *event2str(int event);
1746 static int restore_gains(struct dahdi_pvt *p);
1748 static int my_distinctive_ring(struct ast_channel *chan, void *pvt, int idx, int *ringdata)
1750 unsigned char buf[256];
1752 int curRingData[RING_PATTERNS];
1758 int checkaftercid = 0;
1760 struct dahdi_pvt *p = pvt;
1761 struct analog_pvt *analog_p = p->sig_pvt;
1763 if (ringdata == NULL) {
1764 ringdata = curRingData;
1769 /* We must have a ring by now, so, if configured, lets try to listen for
1770 * distinctive ringing */
1771 if ((checkaftercid && distinctiveringaftercid) || !checkaftercid) {
1772 /* Clear the current ring data array so we don't have old data in it. */
1773 for (receivedRingT = 0; receivedRingT < RING_PATTERNS; receivedRingT++)
1774 ringdata[receivedRingT] = 0;
1776 if (checkaftercid && distinctiveringaftercid)
1777 ast_verb(3, "Detecting post-CID distinctive ring\n");
1778 /* Check to see if context is what it should be, if not set to be. */
1779 else if (strcmp(p->context,p->defcontext) != 0) {
1780 ast_copy_string(p->context, p->defcontext, sizeof(p->context));
1781 ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
1785 i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
1786 if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) {
1787 ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
1791 if (i & DAHDI_IOMUX_SIGEVENT) {
1792 res = dahdi_get_event(p->subs[idx].dfd);
1793 if (res == DAHDI_EVENT_NOALARM) {
1795 analog_p->inalarm = 0;
1797 ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
1799 /* Let us detect distinctive ring */
1801 ringdata[receivedRingT] = analog_p->ringt;
1803 if (analog_p->ringt < analog_p->ringt_base/2)
1805 /* Increment the ringT counter so we can match it against
1806 values in chan_dahdi.conf for distinctive ring */
1807 if (++receivedRingT == RING_PATTERNS)
1809 } else if (i & DAHDI_IOMUX_READ) {
1810 res = read(p->subs[idx].dfd, buf, sizeof(buf));
1812 if (errno != ELAST) {
1813 ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
1819 if (analog_p->ringt > 0) {
1820 if (!(--analog_p->ringt)) {
1828 if ((checkaftercid && usedistinctiveringdetection) || !checkaftercid) {
1829 /* this only shows up if you have n of the dring patterns filled in */
1830 ast_verb(3, "Detected ring pattern: %d,%d,%d\n",ringdata[0],ringdata[1],ringdata[2]);
1831 for (counter = 0; counter < 3; counter++) {
1832 /* Check to see if the rings we received match any of the ones in chan_dahdi.conf for this channel */
1834 /* this only shows up if you have n of the dring patterns filled in */
1835 ast_verb(3, "Checking %d,%d,%d\n",
1836 p->drings.ringnum[counter].ring[0],
1837 p->drings.ringnum[counter].ring[1],
1838 p->drings.ringnum[counter].ring[2]);
1839 for (counter1 = 0; counter1 < 3; counter1++) {
1840 ast_verb(3, "Ring pattern check range: %d\n", p->drings.ringnum[counter].range);
1841 if (p->drings.ringnum[counter].ring[counter1] == -1) {
1842 ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n",
1843 ringdata[counter1]);
1845 } else if (ringdata[counter1] <= (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range) &&
1846 ringdata[counter1] >= (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range)) {
1847 ast_verb(3, "Ring pattern matched in range: %d to %d\n",
1848 (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range),
1849 (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range));
1854 if (distMatches == 3) {
1855 /* The ring matches, set the context to whatever is for distinctive ring.. */
1856 ast_copy_string(p->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(p->context));
1857 ast_copy_string(chan->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(chan->context));
1858 ast_verb(3, "Distinctive Ring matched context %s\n",p->context);
1863 /* Restore linear mode (if appropriate) for Caller*ID processing */
1864 dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
1870 static int my_stop_callwait(void *pvt)
1872 struct dahdi_pvt *p = pvt;
1873 p->callwaitingrepeat = 0;
1875 p->cid_suppress_expire = 0;
1880 static int send_callerid(struct dahdi_pvt *p);
1881 static int save_conference(struct dahdi_pvt *p);
1882 static int restore_conference(struct dahdi_pvt *p);
1884 static int my_callwait(void *pvt)
1886 struct dahdi_pvt *p = pvt;
1887 p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
1889 ast_log(LOG_WARNING, "Spill already exists?!?\n");
1890 ast_free(p->cidspill);
1894 * SAS: Subscriber Alert Signal, 440Hz for 300ms
1895 * CAS: CPE Alert Signal, 2130Hz * 2750Hz sine waves
1897 if (!(p->cidspill = ast_malloc(2400 /* SAS */ + 680 /* CAS */ + READ_SIZE * 4)))
1901 memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4);
1902 if (!p->callwaitrings && p->callwaitingcallerid) {
1903 ast_gen_cas(p->cidspill, 1, 2400 + 680, AST_LAW(p));
1905 p->cidlen = 2400 + 680 + READ_SIZE * 4;
1907 ast_gen_cas(p->cidspill, 1, 2400, AST_LAW(p));
1909 p->cidlen = 2400 + READ_SIZE * 4;
1917 static int my_send_callerid(void *pvt, int cwcid, struct ast_party_caller *caller)
1919 struct dahdi_pvt *p = pvt;
1921 ast_debug(2, "Starting cid spill\n");
1924 ast_log(LOG_WARNING, "cidspill already exists??\n");
1925 ast_free(p->cidspill);
1928 if ((p->cidspill = ast_malloc(MAX_CALLERID_SIZE))) {
1930 p->cidlen = ast_callerid_generate(p->cidspill,
1931 caller->id.name.str,
1932 caller->id.number.str,
1935 ast_verb(3, "CPE supports Call Waiting Caller*ID. Sending '%s/%s'\n",
1936 caller->id.name.str, caller->id.number.str);
1939 p->cidlen = ast_callerid_callwaiting_generate(p->cidspill,
1940 caller->id.name.str,
1941 caller->id.number.str,
1943 p->cidlen += READ_SIZE * 4;
1946 p->cid_suppress_expire = 0;
1952 static int my_dsp_reset_and_flush_digits(void *pvt)
1954 struct dahdi_pvt *p = pvt;
1956 ast_dsp_digitreset(p->dsp);
1961 static int my_dsp_set_digitmode(void *pvt, enum analog_dsp_digitmode mode)
1963 struct dahdi_pvt *p = pvt;
1965 if (p->channel == CHAN_PSEUDO)
1966 ast_log(LOG_ERROR, "You have assumed incorrectly sir!\n");
1968 if (mode == ANALOG_DIGITMODE_DTMF) {
1969 /* If we do hardware dtmf, no need for a DSP */
1970 if (p->hardwaredtmf) {
1972 ast_dsp_free(p->dsp);
1979 p->dsp = ast_dsp_new();
1981 ast_log(LOG_ERROR, "Unable to allocate DSP\n");
1986 ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax);
1987 } else if (mode == ANALOG_DIGITMODE_MF) {
1989 p->dsp = ast_dsp_new();
1991 ast_log(LOG_ERROR, "Unable to allocate DSP\n");
1995 ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MF | p->dtmfrelax);
2000 static int dahdi_wink(struct dahdi_pvt *p, int index);
2002 static int my_wink(void *pvt, enum analog_sub sub)
2004 struct dahdi_pvt *p = pvt;
2005 int index = analogsub_to_dahdisub(sub);
2006 if (index != SUB_REAL) {
2007 ast_log(LOG_ERROR, "We used a sub other than SUB_REAL (incorrect assumption sir)\n");
2009 return dahdi_wink(p, index);
2012 static void wakeup_sub(struct dahdi_pvt *p, int a);
2014 static int reset_conf(struct dahdi_pvt *p);
2016 static inline int dahdi_confmute(struct dahdi_pvt *p, int muted);
2018 static void my_handle_dtmf(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
2020 struct ast_frame *f = *dest;
2021 struct dahdi_pvt *p = pvt;
2022 int idx = analogsub_to_dahdisub(analog_index);
2024 ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n",
2025 f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End",
2026 f->subclass.integer, f->subclass.integer, ast->name);
2028 if (f->subclass.integer == 'f') {
2029 if (f->frametype == AST_FRAME_DTMF_END) {
2030 /* Fax tone -- Handle and return NULL */
2031 if ((p->callprogress & CALLPROGRESS_FAX) && !p->faxhandled) {
2032 /* If faxbuffers are configured, use them for the fax transmission */
2033 if (p->usefaxbuffers && !p->bufferoverrideinuse) {
2034 struct dahdi_bufferinfo bi = {
2035 .txbufpolicy = p->faxbuf_policy,
2036 .bufsize = p->bufsize,
2037 .numbufs = p->faxbuf_no
2041 if ((res = ioctl(p->subs[idx].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) {
2042 ast_log(LOG_WARNING, "Channel '%s' unable to set buffer policy, reason: %s\n", ast->name, strerror(errno));
2044 p->bufferoverrideinuse = 1;
2049 p->dsp_features &= ~DSP_FEATURE_FAX_DETECT;
2050 ast_dsp_set_features(p->dsp, p->dsp_features);
2051 ast_debug(1, "Disabling FAX tone detection on %s after tone received\n", ast->name);
2053 if (strcmp(ast->exten, "fax")) {
2054 const char *target_context = S_OR(ast->macrocontext, ast->context);
2056 /* We need to unlock 'ast' here because ast_exists_extension has the
2057 * potential to start autoservice on the channel. Such action is prone
2060 ast_mutex_unlock(&p->lock);
2061 ast_channel_unlock(ast);
2062 if (ast_exists_extension(ast, target_context, "fax", 1,
2063 S_COR(ast->caller.id.number.valid, ast->caller.id.number.str, NULL))) {
2064 ast_channel_lock(ast);
2065 ast_mutex_lock(&p->lock);
2066 ast_verb(3, "Redirecting %s to fax extension\n", ast->name);
2067 /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
2068 pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten);
2069 if (ast_async_goto(ast, target_context, "fax", 1))
2070 ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context);
2072 ast_channel_lock(ast);
2073 ast_mutex_lock(&p->lock);
2074 ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
2077 ast_debug(1, "Already in a fax extension, not redirecting\n");
2080 ast_debug(1, "Fax already handled\n");
2082 dahdi_confmute(p, 0);
2084 p->subs[idx].f.frametype = AST_FRAME_NULL;
2085 p->subs[idx].f.subclass.integer = 0;
2086 *dest = &p->subs[idx].f;
2090 static void my_lock_private(void *pvt)
2092 struct dahdi_pvt *p = pvt;
2093 ast_mutex_lock(&p->lock);
2096 static void my_unlock_private(void *pvt)
2098 struct dahdi_pvt *p = pvt;
2099 ast_mutex_unlock(&p->lock);
2102 static void my_deadlock_avoidance_private(void *pvt)
2104 struct dahdi_pvt *p = pvt;
2106 DEADLOCK_AVOIDANCE(&p->lock);
2109 /* linear_mode = 0 - turn linear mode off, >0 - turn linear mode on
2110 * returns the last value of the linear setting
2112 static int my_set_linear_mode(void *pvt, enum analog_sub sub, int linear_mode)
2114 struct dahdi_pvt *p = pvt;
2116 int idx = analogsub_to_dahdisub(sub);
2118 dahdi_setlinear(p->subs[idx].dfd, linear_mode);
2119 oldval = p->subs[idx].linear;
2120 p->subs[idx].linear = linear_mode ? 1 : 0;
2124 static void my_set_inthreeway(void *pvt, enum analog_sub sub, int inthreeway)
2126 struct dahdi_pvt *p = pvt;
2127 int idx = analogsub_to_dahdisub(sub);
2129 p->subs[idx].inthreeway = inthreeway;
2132 static int get_alarms(struct dahdi_pvt *p);
2133 static void handle_alarms(struct dahdi_pvt *p, int alms);
2134 static void my_get_and_handle_alarms(void *pvt)
2137 struct dahdi_pvt *p = pvt;
2139 res = get_alarms(p);
2140 handle_alarms(p, res);
2143 static void *my_get_sigpvt_bridged_channel(struct ast_channel *chan)
2145 struct dahdi_pvt *p = ast_bridged_channel(chan)->tech_pvt;
2152 static int my_get_sub_fd(void *pvt, enum analog_sub sub)
2154 struct dahdi_pvt *p = pvt;
2155 int dahdi_sub = analogsub_to_dahdisub(sub);
2156 return p->subs[dahdi_sub].dfd;
2159 static void my_set_cadence(void *pvt, int *cidrings, struct ast_channel *ast)
2161 struct dahdi_pvt *p = pvt;
2163 /* Choose proper cadence */
2164 if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) {
2165 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &cadences[p->distinctivering - 1]))
2166 ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s': %s\n", p->distinctivering, ast->name, strerror(errno));
2167 *cidrings = cidrings[p->distinctivering - 1];
2169 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, NULL))
2170 ast_log(LOG_WARNING, "Unable to reset default ring on '%s': %s\n", ast->name, strerror(errno));
2171 *cidrings = p->sendcalleridafter;
2175 static void my_set_alarm(void *pvt, int in_alarm)
2177 struct dahdi_pvt *p = pvt;
2179 p->inalarm = in_alarm;
2182 static void my_set_dialing(void *pvt, int is_dialing)
2184 struct dahdi_pvt *p = pvt;
2186 p->dialing = is_dialing;
2189 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2190 static void my_set_digital(void *pvt, int is_digital)
2192 struct dahdi_pvt *p = pvt;
2194 p->digital = is_digital;
2196 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2198 #if defined(HAVE_SS7)
2199 static void my_set_inservice(void *pvt, int is_inservice)
2201 struct dahdi_pvt *p = pvt;
2203 p->inservice = is_inservice;
2205 #endif /* defined(HAVE_SS7) */
2207 #if defined(HAVE_SS7)
2208 static void my_set_locallyblocked(void *pvt, int is_blocked)
2210 struct dahdi_pvt *p = pvt;
2212 p->locallyblocked = is_blocked;
2214 #endif /* defined(HAVE_SS7) */
2216 #if defined(HAVE_SS7)
2217 static void my_set_remotelyblocked(void *pvt, int is_blocked)
2219 struct dahdi_pvt *p = pvt;
2221 p->remotelyblocked = is_blocked;
2223 #endif /* defined(HAVE_SS7) */
2225 static void my_set_ringtimeout(void *pvt, int ringt)
2227 struct dahdi_pvt *p = pvt;
2231 static void my_set_waitingfordt(void *pvt, struct ast_channel *ast)
2233 struct dahdi_pvt *p = pvt;
2235 if (p->waitfordialtone && CANPROGRESSDETECT(p) && p->dsp) {
2236 ast_log(LOG_DEBUG, "Defer dialing for %dms or dialtone\n", p->waitfordialtone);
2237 gettimeofday(&p->waitingfordt, NULL);
2238 ast_setstate(ast, AST_STATE_OFFHOOK);
2242 static int my_check_waitingfordt(void *pvt)
2244 struct dahdi_pvt *p = pvt;
2246 if (p->waitingfordt.tv_usec) {
2253 static void my_set_confirmanswer(void *pvt, int flag)
2255 struct dahdi_pvt *p = pvt;
2256 p->confirmanswer = flag;
2259 static int my_check_confirmanswer(void *pvt)
2261 struct dahdi_pvt *p = pvt;
2262 if (p->confirmanswer) {
2269 static void my_set_callwaiting(void *pvt, int callwaiting_enable)
2271 struct dahdi_pvt *p = pvt;
2273 p->callwaiting = callwaiting_enable;
2276 static void my_cancel_cidspill(void *pvt)
2278 struct dahdi_pvt *p = pvt;
2280 ast_free(p->cidspill);
2282 restore_conference(p);
2285 static int my_confmute(void *pvt, int mute)
2287 struct dahdi_pvt *p = pvt;
2288 return dahdi_confmute(p, mute);
2291 static void my_set_pulsedial(void *pvt, int flag)
2293 struct dahdi_pvt *p = pvt;
2294 p->pulsedial = flag;
2297 static void my_set_new_owner(void *pvt, struct ast_channel *new_owner)
2299 struct dahdi_pvt *p = pvt;
2301 p->owner = new_owner;
2304 static const char *my_get_orig_dialstring(void *pvt)
2306 struct dahdi_pvt *p = pvt;
2308 return p->dialstring;
2311 static void my_increase_ss_count(void)
2313 ast_mutex_lock(&ss_thread_lock);
2315 ast_mutex_unlock(&ss_thread_lock);
2318 static void my_decrease_ss_count(void)
2320 ast_mutex_lock(&ss_thread_lock);
2322 ast_cond_signal(&ss_thread_complete);
2323 ast_mutex_unlock(&ss_thread_lock);
2326 static void my_all_subchannels_hungup(void *pvt)
2328 struct dahdi_pvt *p = pvt;
2335 ast_dsp_free(p->dsp);
2339 p->law = p->law_default;
2340 law = p->law_default;
2341 res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law);
2343 ast_log(LOG_WARNING, "Unable to set law on channel %d to default: %s\n", p->channel, strerror(errno));
2345 dahdi_setlinear(p->subs[SUB_REAL].dfd, 0);
2351 /* Cleanup owners here */
2352 for (i = 0; i < 3; i++) {
2353 p->subs[i].owner = NULL;
2359 if (num_restart_pending == 0) {
2364 static int conf_del(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index);
2366 static int my_conf_del(void *pvt, enum analog_sub sub)
2368 struct dahdi_pvt *p = pvt;
2369 int x = analogsub_to_dahdisub(sub);
2371 return conf_del(p, &p->subs[x], x);
2374 static int conf_add(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index, int slavechannel);
2376 static int my_conf_add(void *pvt, enum analog_sub sub)
2378 struct dahdi_pvt *p = pvt;
2379 int x = analogsub_to_dahdisub(sub);
2381 return conf_add(p, &p->subs[x], x, 0);
2384 static int isslavenative(struct dahdi_pvt *p, struct dahdi_pvt **out);
2386 static int my_complete_conference_update(void *pvt, int needconference)
2388 struct dahdi_pvt *p = pvt;
2389 int needconf = needconference;
2392 struct dahdi_pvt *slave = NULL;
2394 useslavenative = isslavenative(p, &slave);
2396 /* If we have a slave, add him to our conference now. or DAX
2397 if this is slave native */
2398 for (x = 0; x < MAX_SLAVES; x++) {
2401 conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p));
2403 conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, 0);
2408 /* If we're supposed to be in there, do so now */
2409 if (p->inconference && !p->subs[SUB_REAL].inthreeway) {
2411 conf_add(p, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(slave));
2413 conf_add(p, &p->subs[SUB_REAL], SUB_REAL, 0);
2417 /* If we have a master, add ourselves to his conference */
2419 if (isslavenative(p->master, NULL)) {
2420 conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p->master));
2422 conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, 0);
2426 /* Nobody is left (or should be left) in our conference.
2434 static int check_for_conference(struct dahdi_pvt *p);
2436 static int my_check_for_conference(void *pvt)
2438 struct dahdi_pvt *p = pvt;
2439 return check_for_conference(p);
2442 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)
2444 struct dahdi_pvt *p = pvt;
2449 da = analogsub_to_dahdisub(a);
2450 db = analogsub_to_dahdisub(b);
2452 tchan = p->subs[da].chan;
2453 p->subs[da].chan = p->subs[db].chan;
2454 p->subs[db].chan = tchan;
2456 tinthreeway = p->subs[da].inthreeway;
2457 p->subs[da].inthreeway = p->subs[db].inthreeway;
2458 p->subs[db].inthreeway = tinthreeway;
2460 p->subs[da].owner = ast_a;
2461 p->subs[db].owner = ast_b;
2464 ast_channel_set_fd(ast_a, 0, p->subs[da].dfd);
2466 ast_channel_set_fd(ast_b, 0, p->subs[db].dfd);
2474 static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const char *linkedid);
2476 static struct ast_channel *my_new_analog_ast_channel(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
2478 struct dahdi_pvt *p = pvt;
2479 int dsub = analogsub_to_dahdisub(sub);
2481 return dahdi_new(p, state, startpbx, dsub, 0, requestor ? requestor->linkedid : "");
2484 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2485 static int dahdi_setlaw(int dfd, int law)
2488 res = ioctl(dfd, DAHDI_SETLAW, &law);
2493 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2495 #if defined(HAVE_PRI)
2496 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)
2498 struct dahdi_pvt *p = pvt;
2503 case SIG_PRI_LIB_HANDLE_CASES:
2504 if (((struct sig_pri_chan *) p->sig_pvt)->no_b_channel) {
2505 /* PRI nobch pseudo channel. Does not handle ioctl(DAHDI_AUDIOMODE) */
2510 /* Set to audio mode at this point */
2512 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &audio) == -1) {
2513 ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n",
2514 p->channel, audio, strerror(errno));
2519 if (law != SIG_PRI_DEFLAW) {
2520 dahdi_setlaw(p->subs[SUB_REAL].dfd, (law == SIG_PRI_ULAW) ? DAHDI_LAW_MULAW : DAHDI_LAW_ALAW);
2523 ast_copy_string(p->exten, exten, sizeof(p->exten));
2526 case SIG_PRI_DEFLAW:
2530 newlaw = DAHDI_LAW_ALAW;
2533 newlaw = DAHDI_LAW_MULAW;
2536 return dahdi_new(p, state, 0, SUB_REAL, newlaw, requestor ? requestor->linkedid : "");
2538 #endif /* defined(HAVE_PRI) */
2540 static int set_actual_gain(int fd, float rxgain, float txgain, float rxdrc, float txdrc, int law);
2542 #if defined(HAVE_PRI)
2545 * \brief Open the PRI channel media path.
2548 * \param p Channel private control structure.
2552 static void my_pri_open_media(void *p)
2554 struct dahdi_pvt *pvt = p;
2559 dfd = pvt->subs[SUB_REAL].dfd;
2561 /* Open the media path. */
2563 res = ioctl(dfd, DAHDI_AUDIOMODE, &set_val);
2565 ast_log(LOG_WARNING, "Unable to enable audio mode on channel %d (%s)\n",
2566 pvt->channel, strerror(errno));
2569 /* Set correct companding law for this call. */
2570 res = dahdi_setlaw(dfd, pvt->law);
2572 ast_log(LOG_WARNING, "Unable to set law on channel %d\n", pvt->channel);
2575 /* Set correct gain for this call. */
2577 res = set_actual_gain(dfd, 0, 0, pvt->rxdrc, pvt->txdrc, pvt->law);
2579 res = set_actual_gain(dfd, pvt->rxgain, pvt->txgain, pvt->rxdrc, pvt->txdrc,
2583 ast_log(LOG_WARNING, "Unable to set gains on channel %d\n", pvt->channel);
2586 if (pvt->dsp_features && pvt->dsp) {
2587 ast_dsp_set_features(pvt->dsp, pvt->dsp_features);
2588 pvt->dsp_features = 0;
2591 #endif /* defined(HAVE_PRI) */
2593 static int unalloc_sub(struct dahdi_pvt *p, int x);
2595 static int my_unallocate_sub(void *pvt, enum analog_sub analogsub)
2597 struct dahdi_pvt *p = pvt;
2599 return unalloc_sub(p, analogsub_to_dahdisub(analogsub));
2602 static int alloc_sub(struct dahdi_pvt *p, int x);
2604 static int my_allocate_sub(void *pvt, enum analog_sub analogsub)
2606 struct dahdi_pvt *p = pvt;
2608 return alloc_sub(p, analogsub_to_dahdisub(analogsub));
2611 static int has_voicemail(struct dahdi_pvt *p);
2613 static int my_has_voicemail(void *pvt)
2615 struct dahdi_pvt *p = pvt;
2617 return has_voicemail(p);
2620 static int my_play_tone(void *pvt, enum analog_sub sub, enum analog_tone tone)
2622 struct dahdi_pvt *p = pvt;
2625 index = analogsub_to_dahdisub(sub);
2627 return tone_zone_play_tone(p->subs[index].dfd, analog_tone_to_dahditone(tone));
2630 static enum analog_event dahdievent_to_analogevent(int event)
2632 enum analog_event res;
2635 case DAHDI_EVENT_ONHOOK:
2636 res = ANALOG_EVENT_ONHOOK;
2638 case DAHDI_EVENT_RINGOFFHOOK:
2639 res = ANALOG_EVENT_RINGOFFHOOK;
2641 case DAHDI_EVENT_WINKFLASH:
2642 res = ANALOG_EVENT_WINKFLASH;
2644 case DAHDI_EVENT_ALARM:
2645 res = ANALOG_EVENT_ALARM;
2647 case DAHDI_EVENT_NOALARM:
2648 res = ANALOG_EVENT_NOALARM;
2650 case DAHDI_EVENT_DIALCOMPLETE:
2651 res = ANALOG_EVENT_DIALCOMPLETE;
2653 case DAHDI_EVENT_RINGERON:
2654 res = ANALOG_EVENT_RINGERON;
2656 case DAHDI_EVENT_RINGEROFF:
2657 res = ANALOG_EVENT_RINGEROFF;
2659 case DAHDI_EVENT_HOOKCOMPLETE:
2660 res = ANALOG_EVENT_HOOKCOMPLETE;
2662 case DAHDI_EVENT_PULSE_START:
2663 res = ANALOG_EVENT_PULSE_START;
2665 case DAHDI_EVENT_POLARITY:
2666 res = ANALOG_EVENT_POLARITY;
2668 case DAHDI_EVENT_RINGBEGIN:
2669 res = ANALOG_EVENT_RINGBEGIN;
2671 case DAHDI_EVENT_EC_DISABLED:
2672 res = ANALOG_EVENT_EC_DISABLED;
2674 case DAHDI_EVENT_REMOVED:
2675 res = ANALOG_EVENT_REMOVED;
2677 case DAHDI_EVENT_NEONMWI_ACTIVE:
2678 res = ANALOG_EVENT_NEONMWI_ACTIVE;
2680 case DAHDI_EVENT_NEONMWI_INACTIVE:
2681 res = ANALOG_EVENT_NEONMWI_INACTIVE;
2683 #ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
2684 case DAHDI_EVENT_TX_CED_DETECTED:
2685 res = ANALOG_EVENT_TX_CED_DETECTED;
2687 case DAHDI_EVENT_RX_CED_DETECTED:
2688 res = ANALOG_EVENT_RX_CED_DETECTED;
2690 case DAHDI_EVENT_EC_NLP_DISABLED:
2691 res = ANALOG_EVENT_EC_NLP_DISABLED;
2693 case DAHDI_EVENT_EC_NLP_ENABLED:
2694 res = ANALOG_EVENT_EC_NLP_ENABLED;
2697 case DAHDI_EVENT_PULSEDIGIT:
2698 res = ANALOG_EVENT_PULSEDIGIT;
2700 case DAHDI_EVENT_DTMFDOWN:
2701 res = ANALOG_EVENT_DTMFDOWN;
2703 case DAHDI_EVENT_DTMFUP:
2704 res = ANALOG_EVENT_DTMFUP;
2707 switch(event & 0xFFFF0000) {
2708 case DAHDI_EVENT_PULSEDIGIT:
2709 case DAHDI_EVENT_DTMFDOWN:
2710 case DAHDI_EVENT_DTMFUP:
2711 /* The event includes a digit number in the low word.
2712 * Converting it to a 'enum analog_event' would remove
2713 * that information. Thus it is returned as-is.
2718 res = ANALOG_EVENT_ERROR;
2725 static inline int dahdi_wait_event(int fd);
2727 static int my_wait_event(void *pvt)
2729 struct dahdi_pvt *p = pvt;
2731 return dahdi_wait_event(p->subs[SUB_REAL].dfd);
2734 static int my_get_event(void *pvt)
2736 struct dahdi_pvt *p = pvt;
2739 if (p->fake_event) {
2740 res = p->fake_event;
2743 res = dahdi_get_event(p->subs[SUB_REAL].dfd);
2745 return dahdievent_to_analogevent(res);
2748 static int my_is_off_hook(void *pvt)
2750 struct dahdi_pvt *p = pvt;
2752 struct dahdi_params par;
2754 memset(&par, 0, sizeof(par));
2756 if (p->subs[SUB_REAL].dfd > -1)
2757 res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par);
2759 /* Assume not off hook on CVRS */
2761 par.rxisoffhook = 0;
2764 ast_log(LOG_WARNING, "Unable to check hook state on channel %d: %s\n", p->channel, strerror(errno));
2767 if ((p->sig == SIG_FXSKS) || (p->sig == SIG_FXSGS)) {
2768 /* When "onhook" that means no battery on the line, and thus
2769 it is out of service..., if it's on a TDM card... If it's a channel
2770 bank, there is no telling... */
2771 return (par.rxbits > -1) || par.rxisoffhook;
2774 return par.rxisoffhook;
2777 static void dahdi_enable_ec(struct dahdi_pvt *p);
2778 static void dahdi_disable_ec(struct dahdi_pvt *p);
2780 static int my_set_echocanceller(void *pvt, int enable)
2782 struct dahdi_pvt *p = pvt;
2787 dahdi_disable_ec(p);
2792 static int dahdi_ring_phone(struct dahdi_pvt *p);
2794 static int my_ring(void *pvt)
2796 struct dahdi_pvt *p = pvt;
2798 return dahdi_ring_phone(p);
2801 static int my_flash(void *pvt)
2803 struct dahdi_pvt *p = pvt;
2804 int func = DAHDI_FLASH;
2805 return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &func);
2808 static inline int dahdi_set_hook(int fd, int hs);
2810 static int my_off_hook(void *pvt)
2812 struct dahdi_pvt *p = pvt;
2813 return dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK);
2816 static void my_set_needringing(void *pvt, int value)
2818 struct dahdi_pvt *p = pvt;
2819 p->subs[SUB_REAL].needringing = value;
2822 static void my_set_polarity(void *pvt, int value)
2824 struct dahdi_pvt *p = pvt;
2826 if (p->channel == CHAN_PSEUDO) {
2829 p->polarity = value;
2830 ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETPOLARITY, &value);
2833 static void my_start_polarityswitch(void *pvt)
2835 struct dahdi_pvt *p = pvt;
2837 if (p->answeronpolarityswitch || p->hanguponpolarityswitch) {
2838 my_set_polarity(pvt, 0);
2842 static void my_answer_polarityswitch(void *pvt)
2844 struct dahdi_pvt *p = pvt;
2846 if (!p->answeronpolarityswitch) {
2850 my_set_polarity(pvt, 1);
2853 static void my_hangup_polarityswitch(void *pvt)
2855 struct dahdi_pvt *p = pvt;
2857 if (!p->hanguponpolarityswitch) {
2861 if (p->answeronpolarityswitch) {
2862 my_set_polarity(pvt, 0);
2864 my_set_polarity(pvt, 1);
2868 static int my_start(void *pvt)
2870 struct dahdi_pvt *p = pvt;
2871 int x = DAHDI_START;
2873 return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
2876 static int my_dial_digits(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop)
2878 int index = analogsub_to_dahdisub(sub);
2880 struct dahdi_pvt *p = pvt;
2881 struct dahdi_dialoperation ddop;
2883 if (dop->op != ANALOG_DIAL_OP_REPLACE) {
2884 ast_log(LOG_ERROR, "Fix the dial_digits callback!\n");
2888 if (sub != ANALOG_SUB_REAL)
2889 printf("Trying to dial digits on sub %d\n", sub);
2891 ddop.op = DAHDI_DIAL_OP_REPLACE;
2892 strncpy(ddop.dialstr, dop->dialstr, sizeof(ddop.dialstr));
2894 printf("Dialing %s on %d\n", ddop.dialstr, p->channel);
2896 res = ioctl(p->subs[index].dfd, DAHDI_DIAL, &ddop);
2899 ast_log(LOG_DEBUG, "DAHDI_DIAL ioctl failed on %s: %s\n", p->owner->name, strerror(errno));
2904 static void dahdi_train_ec(struct dahdi_pvt *p);
2906 static int my_train_echocanceller(void *pvt)
2908 struct dahdi_pvt *p = pvt;
2915 static int my_is_dialing(void *pvt, enum analog_sub sub)
2917 struct dahdi_pvt *p = pvt;
2921 index = analogsub_to_dahdisub(sub);
2923 if (ioctl(p->subs[index].dfd, DAHDI_DIALING, &x)) {
2924 ast_log(LOG_DEBUG, "DAHDI_DIALING ioctl failed!\n");
2931 static int my_on_hook(void *pvt)
2933 struct dahdi_pvt *p = pvt;
2934 return dahdi_set_hook(p->subs[ANALOG_SUB_REAL].dfd, DAHDI_ONHOOK);
2937 #if defined(HAVE_PRI)
2938 static void my_pri_fixup_chans(void *chan_old, void *chan_new)
2940 struct dahdi_pvt *old_chan = chan_old;
2941 struct dahdi_pvt *new_chan = chan_new;
2943 new_chan->owner = old_chan->owner;
2944 old_chan->owner = NULL;
2945 if (new_chan->owner) {
2946 new_chan->owner->tech_pvt = new_chan;
2947 new_chan->owner->fds[0] = new_chan->subs[SUB_REAL].dfd;
2948 new_chan->subs[SUB_REAL].owner = old_chan->subs[SUB_REAL].owner;
2949 old_chan->subs[SUB_REAL].owner = NULL;
2951 /* Copy any DSP that may be present */
2952 new_chan->dsp = old_chan->dsp;
2953 new_chan->dsp_features = old_chan->dsp_features;
2954 old_chan->dsp = NULL;
2955 old_chan->dsp_features = 0;
2957 /* Transfer flags from the old channel. */
2958 new_chan->dialing = old_chan->dialing;
2959 new_chan->digital = old_chan->digital;
2960 new_chan->outgoing = old_chan->outgoing;
2961 old_chan->dialing = 0;
2962 old_chan->digital = 0;
2963 old_chan->outgoing = 0;
2965 /* More stuff to transfer to the new channel. */
2966 new_chan->law = old_chan->law;
2967 strcpy(new_chan->dialstring, old_chan->dialstring);
2969 #endif /* defined(HAVE_PRI) */
2971 #if defined(HAVE_PRI)
2972 static int sig_pri_tone_to_dahditone(enum sig_pri_tone tone)
2975 case SIG_PRI_TONE_RINGTONE:
2976 return DAHDI_TONE_RINGTONE;
2977 case SIG_PRI_TONE_STUTTER:
2978 return DAHDI_TONE_STUTTER;
2979 case SIG_PRI_TONE_CONGESTION:
2980 return DAHDI_TONE_CONGESTION;
2981 case SIG_PRI_TONE_DIALTONE:
2982 return DAHDI_TONE_DIALTONE;
2983 case SIG_PRI_TONE_DIALRECALL:
2984 return DAHDI_TONE_DIALRECALL;
2985 case SIG_PRI_TONE_INFO:
2986 return DAHDI_TONE_INFO;
2987 case SIG_PRI_TONE_BUSY:
2988 return DAHDI_TONE_BUSY;
2993 #endif /* defined(HAVE_PRI) */
2995 #if defined(HAVE_PRI)
2996 static void my_handle_dchan_exception(struct sig_pri_span *pri, int index)
3000 res = ioctl(pri->fds[index], DAHDI_GETEVENT, &x);
3002 ast_log(LOG_NOTICE, "PRI got event: %s (%d) on D-channel of span %d\n", event2str(x), x, pri->span);
3004 /* Keep track of alarm state */
3006 case DAHDI_EVENT_ALARM:
3007 pri_event_alarm(pri, index, 0);
3009 case DAHDI_EVENT_NOALARM:
3010 pri_event_noalarm(pri, index, 0);
3016 #endif /* defined(HAVE_PRI) */
3018 #if defined(HAVE_PRI)
3019 static int my_pri_play_tone(void *pvt, enum sig_pri_tone tone)
3021 struct dahdi_pvt *p = pvt;
3023 return tone_zone_play_tone(p->subs[SUB_REAL].dfd, sig_pri_tone_to_dahditone(tone));
3025 #endif /* defined(HAVE_PRI) */
3027 #if defined(HAVE_PRI) || defined(HAVE_SS7)
3030 * \brief Set the caller id information.
3033 * \param pvt DAHDI private structure
3034 * \param caller Caller-id information to set.
3038 static void my_set_callerid(void *pvt, const struct ast_party_caller *caller)
3040 struct dahdi_pvt *p = pvt;
3042 ast_copy_string(p->cid_num,
3043 S_COR(caller->id.number.valid, caller->id.number.str, ""),
3044 sizeof(p->cid_num));
3045 ast_copy_string(p->cid_name,
3046 S_COR(caller->id.name.valid, caller->id.name.str, ""),
3047 sizeof(p->cid_name));
3048 ast_copy_string(p->cid_subaddr,
3049 S_COR(caller->id.subaddress.valid, caller->id.subaddress.str, ""),
3050 sizeof(p->cid_subaddr));
3051 p->cid_ton = caller->id.number.plan;
3052 p->callingpres = ast_party_id_presentation(&caller->id);
3053 if (caller->id.tag) {
3054 ast_copy_string(p->cid_tag, caller->id.tag, sizeof(p->cid_tag));
3056 ast_copy_string(p->cid_ani,
3057 S_COR(caller->ani.number.valid, caller->ani.number.str, ""),
3058 sizeof(p->cid_ani));
3059 p->cid_ani2 = caller->ani2;
3061 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
3063 #if defined(HAVE_PRI) || defined(HAVE_SS7)
3066 * \brief Set the Dialed Number Identifier.
3069 * \param pvt DAHDI private structure
3070 * \param dnid Dialed Number Identifier string.
3074 static void my_set_dnid(void *pvt, const char *dnid)
3076 struct dahdi_pvt *p = pvt;
3078 ast_copy_string(p->dnid, dnid, sizeof(p->dnid));
3080 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
3082 #if defined(HAVE_PRI)
3085 * \brief Set the Redirecting Directory Number Information Service (RDNIS).
3088 * \param pvt DAHDI private structure
3089 * \param rdnis Redirecting Directory Number Information Service (RDNIS) string.
3093 static void my_set_rdnis(void *pvt, const char *rdnis)
3095 struct dahdi_pvt *p = pvt;
3097 ast_copy_string(p->rdnis, rdnis, sizeof(p->rdnis));
3099 #endif /* defined(HAVE_PRI) */
3101 #if defined(HAVE_PRI)
3104 * \brief Make a dialstring for native ISDN CC to recall properly.
3107 * \param priv Channel private control structure.
3108 * \param buf Where to put the modified dialstring.
3109 * \param buf_size Size of modified dialstring buffer.
3112 * original dialstring:
3113 * DAHDI/[i<span>-](g|G|r|R)<group#(0-63)>[c|r<cadance#>|d][/extension[/options]]
3115 * The modified dialstring will have prefixed the channel-group section
3116 * with the ISDN channel restriction.
3119 * DAHDI/i<span>-(g|G|r|R)<group#(0-63)>[c|r<cadance#>|d][/extension[/options]]
3121 * The routine will check to see if the ISDN channel restriction is already
3122 * in the original dialstring.
3126 static void my_pri_make_cc_dialstring(void *priv, char *buf, size_t buf_size)
3129 struct dahdi_pvt *pvt;
3130 AST_DECLARE_APP_ARGS(args,
3131 AST_APP_ARG(tech); /* channel technology token */
3132 AST_APP_ARG(group); /* channel/group token */
3133 //AST_APP_ARG(ext); /* extension token */
3134 //AST_APP_ARG(opts); /* options token */
3135 //AST_APP_ARG(other); /* Any remining unused arguments */
3139 dial = ast_strdupa(pvt->dialstring);
3140 AST_NONSTANDARD_APP_ARGS(args, dial, '/');
3142 ast_copy_string(buf, pvt->dialstring, buf_size);
3146 /* Append the ISDN span channel restriction to the dialstring. */
3147 snprintf(buf, buf_size, "%s/i%d-", args.tech, pvt->pri->span);
3150 if (isdigit(args.group[0]) || args.group[0] == 'i' || strchr(args.group, '!')) {
3151 /* The ISDN span channel restriction is not needed or already
3152 * in the dialstring. */
3153 ast_copy_string(buf, pvt->dialstring, buf_size);
3156 /* Insert the ISDN span channel restriction into the dialstring. */
3157 snprintf(buf, buf_size, "%s/i%d-%s", args.tech, pvt->pri->span, args.group);
3159 #endif /* defined(HAVE_PRI) */
3161 #if defined(HAVE_PRI)
3164 * \brief Reevaluate the PRI span device state.
3167 * \param pri Asterisk D channel control structure.
3171 * \note Assumes the pri->lock is already obtained.
3173 static void dahdi_pri_update_span_devstate(struct sig_pri_span *pri)
3176 unsigned num_b_chans; /* Number of B channels provisioned on the span. */
3177 unsigned in_use; /* Number of B channels in use on the span. */
3178 unsigned in_alarm; /* TRUE if the span is in alarm condition. */
3179 enum ast_device_state new_state;
3181 /* Count the number of B channels and the number of B channels in use. */
3185 for (idx = pri->numchans; idx--;) {
3186 if (pri->pvts[idx] && !pri->pvts[idx]->no_b_channel) {
3187 /* This is a B channel interface. */
3189 if (pri->pvts[idx]->owner
3190 #if defined(HAVE_PRI_SERVICE_MESSAGES)
3191 /* Out-of-service B channels are "in-use". */
3192 || pri->pvts[idx]->service_status
3193 #endif /* defined(HAVE_PRI_SERVICE_MESSAGES) */
3197 if (!pri->pvts[idx]->inalarm) {
3198 /* There is a channel that is not in alarm. */
3204 /* Update the span congestion device state and report any change. */
3206 new_state = AST_DEVICE_UNAVAILABLE;
3208 new_state = num_b_chans == in_use ? AST_DEVICE_BUSY : AST_DEVICE_NOT_INUSE;
3210 if (pri->congestion_devstate != new_state) {
3211 pri->congestion_devstate = new_state;
3212 ast_devstate_changed(AST_DEVICE_UNKNOWN, "DAHDI/I%d/congestion", pri->span);