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 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" required="true" />
243 <manager name="DAHDIRestart" language="en_US">
245 Fully Restart DAHDI channels (terminates calls).
248 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
255 #define SMDI_MD_WAIT_TIMEOUT 1500 /* 1.5 seconds */
257 static const char * const lbostr[] = {
258 "0 db (CSU)/0-133 feet (DSX-1)",
259 "133-266 feet (DSX-1)",
260 "266-399 feet (DSX-1)",
261 "399-533 feet (DSX-1)",
262 "533-655 feet (DSX-1)",
268 /*! Global jitterbuffer configuration - by default, jb is disabled */
269 static struct ast_jb_conf default_jbconf =
273 .resync_threshold = -1,
277 static struct ast_jb_conf global_jbconf;
280 * \note Define ZHONE_HACK to cause us to go off hook and then back on hook when
281 * the user hangs up to reset the state machine so ring works properly.
282 * This is used to be able to support kewlstart by putting the zhone in
283 * groundstart mode since their forward disconnect supervision is entirely
284 * broken even though their documentation says it isn't and their support
285 * is entirely unwilling to provide any assistance with their channel banks
286 * even though their web site says they support their products for life.
288 /* #define ZHONE_HACK */
290 /*! \brief Typically, how many rings before we should send Caller*ID */
291 #define DEFAULT_CIDRINGS 1
293 #define AST_LAW(p) (((p)->law == DAHDI_LAW_ALAW) ? AST_FORMAT_ALAW : AST_FORMAT_ULAW)
296 /*! \brief Signaling types that need to use MF detection should be placed in this macro */
297 #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))
299 static const char tdesc[] = "DAHDI Telephony Driver"
300 #if defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2)
302 #if defined(HAVE_PRI)
304 #endif /* defined(HAVE_PRI) */
305 #if defined(HAVE_SS7)
306 #if defined(HAVE_PRI)
308 #endif /* defined(HAVE_PRI) */
310 #endif /* defined(HAVE_SS7) */
311 #if defined(HAVE_OPENR2)
312 #if defined(HAVE_PRI) || defined(HAVE_SS7)
314 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
316 #endif /* defined(HAVE_OPENR2) */
317 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2) */
320 static const char config[] = "chan_dahdi.conf";
322 #define SIG_EM DAHDI_SIG_EM
323 #define SIG_EMWINK (0x0100000 | DAHDI_SIG_EM)
324 #define SIG_FEATD (0x0200000 | DAHDI_SIG_EM)
325 #define SIG_FEATDMF (0x0400000 | DAHDI_SIG_EM)
326 #define SIG_FEATB (0x0800000 | DAHDI_SIG_EM)
327 #define SIG_E911 (0x1000000 | DAHDI_SIG_EM)
328 #define SIG_FEATDMF_TA (0x2000000 | DAHDI_SIG_EM)
329 #define SIG_FGC_CAMA (0x4000000 | DAHDI_SIG_EM)
330 #define SIG_FGC_CAMAMF (0x8000000 | DAHDI_SIG_EM)
331 #define SIG_FXSLS DAHDI_SIG_FXSLS
332 #define SIG_FXSGS DAHDI_SIG_FXSGS
333 #define SIG_FXSKS DAHDI_SIG_FXSKS
334 #define SIG_FXOLS DAHDI_SIG_FXOLS
335 #define SIG_FXOGS DAHDI_SIG_FXOGS
336 #define SIG_FXOKS DAHDI_SIG_FXOKS
337 #define SIG_PRI DAHDI_SIG_CLEAR
338 #define SIG_BRI (0x2000000 | DAHDI_SIG_CLEAR)
339 #define SIG_BRI_PTMP (0X4000000 | DAHDI_SIG_CLEAR)
340 #define SIG_SS7 (0x1000000 | DAHDI_SIG_CLEAR)
341 #define SIG_MFCR2 DAHDI_SIG_CAS
342 #define SIG_SF DAHDI_SIG_SF
343 #define SIG_SFWINK (0x0100000 | DAHDI_SIG_SF)
344 #define SIG_SF_FEATD (0x0200000 | DAHDI_SIG_SF)
345 #define SIG_SF_FEATDMF (0x0400000 | DAHDI_SIG_SF)
346 #define SIG_SF_FEATB (0x0800000 | DAHDI_SIG_SF)
347 #define SIG_EM_E1 DAHDI_SIG_EM_E1
350 #define NUM_SPANS DAHDI_MAX_SPANS
355 #define CHAN_PSEUDO -2
357 #define CALLPROGRESS_PROGRESS 1
358 #define CALLPROGRESS_FAX_OUTGOING 2
359 #define CALLPROGRESS_FAX_INCOMING 4
360 #define CALLPROGRESS_FAX (CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING)
362 #define NUM_CADENCE_MAX 25
363 static int num_cadence = 4;
364 static int user_has_defined_cadences = 0;
366 static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX] = {
367 { { 125, 125, 2000, 4000 } }, /*!< Quick chirp followed by normal ring */
368 { { 250, 250, 500, 1000, 250, 250, 500, 4000 } }, /*!< British style ring */
369 { { 125, 125, 125, 125, 125, 4000 } }, /*!< Three short bursts */
370 { { 1000, 500, 2500, 5000 } }, /*!< Long ring */
373 /*! \brief cidrings says in which pause to transmit the cid information, where the first pause
374 * is 1, the second pause is 2 and so on.
377 static int cidrings[NUM_CADENCE_MAX] = {
378 2, /*!< Right after first long ring */
379 4, /*!< Right after long part */
380 3, /*!< After third chirp */
381 2, /*!< Second spell */
384 /* ETSI EN300 659-1 specifies the ring pulse between 200 and 300 mS */
385 static struct dahdi_ring_cadence AS_RP_cadence = {{250, 10000}};
387 #define ISTRUNK(p) ((p->sig == SIG_FXSLS) || (p->sig == SIG_FXSKS) || \
388 (p->sig == SIG_FXSGS) || (p->sig == SIG_PRI))
390 #define CANBUSYDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
391 #define CANPROGRESSDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
393 static char defaultcic[64] = "";
394 static char defaultozz[64] = "";
396 static char parkinglot[AST_MAX_EXTENSION] = ""; /*!< Default parking lot for this channel */
398 /*! Run this script when the MWI state changes on an FXO line, if mwimonitor is enabled */
399 static char mwimonitornotify[PATH_MAX] = "";
400 #ifndef HAVE_DAHDI_LINEREVERSE_VMWI
401 static int mwisend_rpas = 0;
404 static char progzone[10] = "";
406 static int usedistinctiveringdetection = 0;
407 static int distinctiveringaftercid = 0;
409 static int numbufs = 4;
411 static int mwilevel = 512;
412 static int dtmfcid_level = 256;
414 #define REPORT_CHANNEL_ALARMS 1
415 #define REPORT_SPAN_ALARMS 2
416 static int report_alarms = REPORT_CHANNEL_ALARMS;
419 static int pridebugfd = -1;
420 static char pridebugfilename[1024] = "";
423 /*! \brief Wait up to 16 seconds for first digit (FXO logic) */
424 static int firstdigittimeout = 16000;
426 /*! \brief How long to wait for following digits (FXO logic) */
427 static int gendigittimeout = 8000;
429 /*! \brief How long to wait for an extra digit, if there is an ambiguous match */
430 static int matchdigittimeout = 3000;
432 /*! \brief Protect the interface list (of dahdi_pvt's) */
433 AST_MUTEX_DEFINE_STATIC(iflock);
436 static int ifcount = 0;
439 AST_MUTEX_DEFINE_STATIC(pridebugfdlock);
442 /*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
443 when it's doing something critical. */
444 AST_MUTEX_DEFINE_STATIC(monlock);
446 /*! \brief This is the thread for the monitor which checks for input on the channels
447 which are not currently in use. */
448 static pthread_t monitor_thread = AST_PTHREADT_NULL;
449 static ast_cond_t ss_thread_complete;
450 AST_MUTEX_DEFINE_STATIC(ss_thread_lock);
451 AST_MUTEX_DEFINE_STATIC(restart_lock);
452 static int ss_thread_count = 0;
453 static int num_restart_pending = 0;
455 static int restart_monitor(void);
457 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);
459 static int dahdi_sendtext(struct ast_channel *c, const char *text);
461 static void mwi_event_cb(const struct ast_event *event, void *userdata)
463 /* This module does not handle MWI in an event-based manner. However, it
464 * subscribes to MWI for each mailbox that is configured so that the core
465 * knows that we care about it. Then, chan_dahdi will get the MWI from the
466 * event cache instead of checking the mailbox directly. */
469 /*! \brief Avoid the silly dahdi_getevent which ignores a bunch of events */
470 static inline int dahdi_get_event(int fd)
473 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
478 /*! \brief Avoid the silly dahdi_waitevent which ignores a bunch of events */
479 static inline int dahdi_wait_event(int fd)
482 i = DAHDI_IOMUX_SIGEVENT;
483 if (ioctl(fd, DAHDI_IOMUX, &i) == -1)
485 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
490 /*! Chunk size to read -- we use 20ms chunks to make things happy. */
491 #define READ_SIZE 160
493 #define MASK_AVAIL (1 << 0) /*!< Channel available for PRI use */
494 #define MASK_INUSE (1 << 1) /*!< Channel currently in use */
496 #define CALLWAITING_SILENT_SAMPLES ((300 * 8) / READ_SIZE) /*!< 300 ms */
497 #define CALLWAITING_REPEAT_SAMPLES ((10000 * 8) / READ_SIZE) /*!< 10,000 ms */
498 #define CALLWAITING_SUPPRESS_SAMPLES ((100 * 8) / READ_SIZE) /*!< 100 ms */
499 #define CIDCW_EXPIRE_SAMPLES ((500 * 8) / READ_SIZE) /*!< 500 ms */
500 #define MIN_MS_SINCE_FLASH ((2000) ) /*!< 2000 ms */
501 #define DEFAULT_RINGT ((8000 * 8) / READ_SIZE) /*!< 8,000 ms */
506 * \brief Configured ring timeout base.
507 * \note Value computed from "ringtimeout" read in from chan_dahdi.conf if it exists.
509 static int ringt_base = DEFAULT_RINGT;
511 #if defined(HAVE_SS7)
514 struct sig_ss7_linkset ss7;
517 static struct dahdi_ss7 linksets[NUM_SPANS];
519 static int cur_ss7type = -1;
520 static int cur_linkset = -1;
521 static int cur_pointcode = -1;
522 static int cur_cicbeginswith = -1;
523 static int cur_adjpointcode = -1;
524 static int cur_networkindicator = -1;
525 static int cur_defaultdpc = -1;
526 #endif /* defined(HAVE_SS7) */
530 pthread_t r2master; /*!< Thread of master */
531 openr2_context_t *protocol_context; /*!< OpenR2 context handle */
532 struct dahdi_pvt *pvts[SIG_MFCR2_MAX_CHANNELS]; /*!< Member channel pvt structs */
533 int numchans; /*!< Number of channels in this R2 block */
534 int monitored_count; /*!< Number of channels being monitored */
537 struct dahdi_mfcr2_conf {
538 openr2_variant_t variant;
540 int metering_pulse_timeout;
543 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
547 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3
548 int dtmf_end_timeout;
550 signed int get_ani_first:2;
551 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
552 signed int skip_category_request:2;
554 unsigned int call_files:1;
555 unsigned int allow_collect_calls:1;
556 unsigned int charge_calls:1;
557 unsigned int accept_on_offer:1;
558 unsigned int forced_release:1;
559 unsigned int double_answer:1;
560 signed int immediate_accept:2;
561 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
562 signed int dtmf_dialing:2;
563 signed int dtmf_detection:2;
565 char logdir[OR2_MAX_PATH];
566 char r2proto_file[OR2_MAX_PATH];
567 openr2_log_level_t loglevel;
568 openr2_calling_party_category_t category;
571 /* malloc'd array of malloc'd r2links */
572 static struct dahdi_mfcr2 **r2links;
573 /* how many r2links have been malloc'd */
574 static int r2links_count = 0;
576 #endif /* HAVE_OPENR2 */
581 int dchannels[SIG_PRI_NUM_DCHANS]; /*!< What channel are the dchannels on */
582 int mastertrunkgroup; /*!< What trunk group is our master */
583 int prilogicalspan; /*!< Logical span number within trunk group */
584 struct sig_pri_span pri;
587 static struct dahdi_pri pris[NUM_SPANS];
589 #if defined(HAVE_PRI_CCSS)
590 /*! DAHDI PRI CCSS agent and monitor type name. */
591 static const char dahdi_pri_cc_type[] = "DAHDI/PRI";
592 #endif /* defined(HAVE_PRI_CCSS) */
595 /*! Shut up the compiler */
599 #define SUB_REAL 0 /*!< Active call */
600 #define SUB_CALLWAIT 1 /*!< Call-Waiting call on hold */
601 #define SUB_THREEWAY 2 /*!< Three-way call */
603 /* Polarity states */
604 #define POLARITY_IDLE 0
605 #define POLARITY_REV 1
608 struct distRingData {
612 struct ringContextData {
613 char contextData[AST_MAX_CONTEXT];
615 struct dahdi_distRings {
616 struct distRingData ringnum[3];
617 struct ringContextData ringContext[3];
620 static const char * const subnames[] = {
626 struct dahdi_subchannel {
628 struct ast_channel *owner;
630 short buffer[AST_FRIENDLY_OFFSET/2 + READ_SIZE];
631 struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */
632 unsigned int needringing:1;
633 unsigned int needbusy:1;
634 unsigned int needcongestion:1;
635 unsigned int needanswer:1;
636 unsigned int needflash:1;
637 unsigned int needhold:1;
638 unsigned int needunhold:1;
639 unsigned int linear:1;
640 unsigned int inthreeway:1;
641 struct dahdi_confinfo curconf;
644 #define CONF_USER_REAL (1 << 0)
645 #define CONF_USER_THIRDCALL (1 << 1)
649 /* States for sending MWI message
650 * First three states are required for send Ring Pulse Alert Signal
662 struct mwisend_info {
663 struct timeval pause;
664 mwisend_states mwisend_current;
667 /*! Specify the lists dahdi_pvt can be put in. */
669 DAHDI_IFLIST_NONE, /*!< The dahdi_pvt is not in any list. */
670 DAHDI_IFLIST_MAIN, /*!< The dahdi_pvt is in the main interface list */
671 #if defined(HAVE_PRI)
672 DAHDI_IFLIST_NO_B_CHAN, /*!< The dahdi_pvt is in a no B channel interface list */
673 #endif /* defined(HAVE_PRI) */
677 ast_mutex_t lock; /*!< Channel private lock. */
678 struct callerid_state *cs;
679 struct ast_channel *owner; /*!< Our current active owner (if applicable) */
680 /*!< Up to three channels can be associated with this call */
682 struct dahdi_subchannel sub_unused; /*!< Just a safety precaution */
683 struct dahdi_subchannel subs[3]; /*!< Sub-channels */
684 struct dahdi_confinfo saveconf; /*!< Saved conference info */
686 struct dahdi_pvt *slaves[MAX_SLAVES]; /*!< Slave to us (follows our conferencing) */
687 struct dahdi_pvt *master; /*!< Master to us (we follow their conferencing) */
688 int inconference; /*!< If our real should be in the conference */
690 int bufsize; /*!< Size of the buffers */
691 int buf_no; /*!< Number of buffers */
692 int buf_policy; /*!< Buffer policy */
693 int faxbuf_no; /*!< Number of Fax buffers */
694 int faxbuf_policy; /*!< Fax buffer policy */
695 int sig; /*!< Signalling style */
697 * \brief Nonzero if the signaling type is sent over a radio.
698 * \note Set to a couple of nonzero values but it is only tested like a boolean.
701 int outsigmod; /*!< Outbound Signalling style (modifier) */
702 int oprmode; /*!< "Operator Services" mode */
703 struct dahdi_pvt *oprpeer; /*!< "Operator Services" peer tech_pvt ptr */
704 /*! \brief Amount of gain to increase during caller id */
706 /*! \brief Rx gain set by chan_dahdi.conf */
708 /*! \brief Tx gain set by chan_dahdi.conf */
711 float txdrc; /*!< Dynamic Range Compression factor. a number between 1 and 6ish */
714 int tonezone; /*!< tone zone for this chan, or -1 for default */
715 enum DAHDI_IFLIST which_iflist; /*!< Which interface list is this structure listed? */
716 struct dahdi_pvt *next; /*!< Next channel in list */
717 struct dahdi_pvt *prev; /*!< Prev channel in list */
722 * \brief TRUE if ADSI (Analog Display Services Interface) available
723 * \note Set from the "adsi" value read in from chan_dahdi.conf
727 * \brief TRUE if we can use a polarity reversal to mark when an outgoing
728 * call is answered by the remote party.
729 * \note Set from the "answeronpolarityswitch" value read in from chan_dahdi.conf
731 unsigned int answeronpolarityswitch:1;
733 * \brief TRUE if busy detection is enabled.
734 * (Listens for the beep-beep busy pattern.)
735 * \note Set from the "busydetect" value read in from chan_dahdi.conf
737 unsigned int busydetect:1;
739 * \brief TRUE if call return is enabled.
740 * (*69, if your dialplan doesn't catch this first)
741 * \note Set from the "callreturn" value read in from chan_dahdi.conf
743 unsigned int callreturn:1;
745 * \brief TRUE if busy extensions will hear the call-waiting tone
746 * and can use hook-flash to switch between callers.
747 * \note Can be disabled by dialing *70.
748 * \note Initialized with the "callwaiting" value read in from chan_dahdi.conf
750 unsigned int callwaiting:1;
752 * \brief TRUE if send caller ID for Call Waiting
753 * \note Set from the "callwaitingcallerid" value read in from chan_dahdi.conf
755 unsigned int callwaitingcallerid:1;
757 * \brief TRUE if support for call forwarding enabled.
758 * Dial *72 to enable call forwarding.
759 * Dial *73 to disable call forwarding.
760 * \note Set from the "cancallforward" value read in from chan_dahdi.conf
762 unsigned int cancallforward:1;
764 * \brief TRUE if support for call parking is enabled.
765 * \note Set from the "canpark" value read in from chan_dahdi.conf
767 unsigned int canpark:1;
768 /*! \brief TRUE if to wait for a DTMF digit to confirm answer */
769 unsigned int confirmanswer:1;
771 * \brief TRUE if the channel is to be destroyed on hangup.
772 * (Used by pseudo channels.)
774 unsigned int destroy:1;
775 unsigned int didtdd:1; /*!< flag to say its done it once */
776 /*! \brief TRUE if analog type line dialed no digits in Dial() */
777 unsigned int dialednone:1;
779 * \brief TRUE if in the process of dialing digits or sending something.
780 * \note This is used as a receive squelch for ISDN until connected.
782 unsigned int dialing:1;
783 /*! \brief TRUE if the transfer capability of the call is digital. */
784 unsigned int digital:1;
785 /*! \brief TRUE if Do-Not-Disturb is enabled, present only for non sig_analog */
787 /*! \brief XXX BOOLEAN Purpose??? */
788 unsigned int echobreak:1;
790 * \brief TRUE if echo cancellation enabled when bridged.
791 * \note Initialized with the "echocancelwhenbridged" value read in from chan_dahdi.conf
792 * \note Disabled if the echo canceller is not setup.
794 unsigned int echocanbridged:1;
795 /*! \brief TRUE if echo cancellation is turned on. */
796 unsigned int echocanon:1;
797 /*! \brief TRUE if a fax tone has already been handled. */
798 unsigned int faxhandled:1;
799 /*! TRUE if dynamic faxbuffers are configured for use, default is OFF */
800 unsigned int usefaxbuffers:1;
801 /*! TRUE while buffer configuration override is in use */
802 unsigned int bufferoverrideinuse:1;
803 /*! \brief TRUE if over a radio and dahdi_read() has been called. */
804 unsigned int firstradio:1;
806 * \brief TRUE if the call will be considered "hung up" on a polarity reversal.
807 * \note Set from the "hanguponpolarityswitch" value read in from chan_dahdi.conf
809 unsigned int hanguponpolarityswitch:1;
810 /*! \brief TRUE if DTMF detection needs to be done by hardware. */
811 unsigned int hardwaredtmf:1;
813 * \brief TRUE if the outgoing caller ID is blocked/hidden.
814 * \note Caller ID can be disabled by dialing *67.
815 * \note Caller ID can be enabled by dialing *82.
816 * \note Initialized with the "hidecallerid" value read in from chan_dahdi.conf
818 unsigned int hidecallerid:1;
820 * \brief TRUE if hide just the name not the number for legacy PBX use.
821 * \note Only applies to PRI channels.
822 * \note Set from the "hidecalleridname" value read in from chan_dahdi.conf
824 unsigned int hidecalleridname:1;
825 /*! \brief TRUE if DTMF detection is disabled. */
826 unsigned int ignoredtmf:1;
828 * \brief TRUE if the channel should be answered immediately
829 * without attempting to gather any digits.
830 * \note Set from the "immediate" value read in from chan_dahdi.conf
832 unsigned int immediate:1;
833 /*! \brief TRUE if in an alarm condition. */
834 unsigned int inalarm:1;
835 /*! \brief TRUE if TDD in MATE mode */
837 /*! \brief TRUE if we originated the call leg. */
838 unsigned int outgoing:1;
839 /* unsigned int overlapdial:1; unused and potentially confusing */
841 * \brief TRUE if busy extensions will hear the call-waiting tone
842 * and can use hook-flash to switch between callers.
843 * \note Set from the "callwaiting" value read in from chan_dahdi.conf
845 unsigned int permcallwaiting:1;
847 * \brief TRUE if the outgoing caller ID is blocked/restricted/hidden.
848 * \note Set from the "hidecallerid" value read in from chan_dahdi.conf
850 unsigned int permhidecallerid:1;
852 * \brief TRUE if PRI congestion/busy indications are sent out-of-band.
853 * \note Set from the "priindication" value read in from chan_dahdi.conf
855 unsigned int priindication_oob:1;
857 * \brief TRUE if PRI B channels are always exclusively selected.
858 * \note Set from the "priexclusive" value read in from chan_dahdi.conf
860 unsigned int priexclusive:1;
862 * \brief TRUE if we will pulse dial.
863 * \note Set from the "pulsedial" value read in from chan_dahdi.conf
865 unsigned int pulse:1;
866 /*! \brief TRUE if a pulsed digit was detected. (Pulse dial phone detected) */
867 unsigned int pulsedial:1;
868 unsigned int restartpending:1; /*!< flag to ensure counted only once for restart */
870 * \brief TRUE if caller ID is restricted.
871 * \note Set but not used. Should be deleted. Redundant with permhidecallerid.
872 * \note Set from the "restrictcid" value read in from chan_dahdi.conf
874 unsigned int restrictcid:1;
876 * \brief TRUE if three way calling is enabled
877 * \note Set from the "threewaycalling" value read in from chan_dahdi.conf
879 unsigned int threewaycalling:1;
881 * \brief TRUE if call transfer is enabled
882 * \note For FXS ports (either direct analog or over T1/E1):
883 * Support flash-hook call transfer
884 * \note For digital ports using ISDN PRI protocols:
885 * Support switch-side transfer (called 2BCT, RLT or other names)
886 * \note Set from the "transfer" value read in from chan_dahdi.conf
888 unsigned int transfer:1;
890 * \brief TRUE if caller ID is used on this channel.
891 * \note PRI and SS7 spans will save caller ID from the networking peer.
892 * \note FXS ports will generate the caller ID spill.
893 * \note FXO ports will listen for the caller ID spill.
894 * \note Set from the "usecallerid" value read in from chan_dahdi.conf
896 unsigned int use_callerid:1;
898 * \brief TRUE if we will use the calling presentation setting
899 * from the Asterisk channel for outgoing calls.
900 * \note Only applies to PRI and SS7 channels.
901 * \note Set from the "usecallingpres" value read in from chan_dahdi.conf
903 unsigned int use_callingpres:1;
905 * \brief TRUE if distinctive rings are to be detected.
906 * \note For FXO lines
907 * \note Set indirectly from the "usedistinctiveringdetection" value read in from chan_dahdi.conf
909 unsigned int usedistinctiveringdetection:1;
911 * \brief TRUE if we should use the callerid from incoming call on dahdi transfer.
912 * \note Set from the "useincomingcalleridondahditransfer" value read in from chan_dahdi.conf
914 unsigned int dahditrcallerid:1;
916 * \brief TRUE if allowed to flash-transfer to busy channels.
917 * \note Set from the "transfertobusy" value read in from chan_dahdi.conf
919 unsigned int transfertobusy:1;
921 * \brief TRUE if the FXO port monitors for neon type MWI indications from the other end.
922 * \note Set if the "mwimonitor" value read in contains "neon" from chan_dahdi.conf
924 unsigned int mwimonitor_neon:1;
926 * \brief TRUE if the FXO port monitors for fsk type MWI indications from the other end.
927 * \note Set if the "mwimonitor" value read in contains "fsk" from chan_dahdi.conf
929 unsigned int mwimonitor_fsk:1;
931 * \brief TRUE if the FXO port monitors for rpas precursor to fsk MWI indications from the other end.
932 * \note RPAS - Ring Pulse Alert Signal
933 * \note Set if the "mwimonitor" value read in contains "rpas" from chan_dahdi.conf
935 unsigned int mwimonitor_rpas:1;
936 /*! \brief TRUE if an MWI monitor thread is currently active */
937 unsigned int mwimonitoractive:1;
938 /*! \brief TRUE if a MWI message sending thread is active */
939 unsigned int mwisendactive:1;
941 * \brief TRUE if channel is out of reset and ready
942 * \note Set but not used.
944 unsigned int inservice:1;
946 * \brief TRUE if the channel is locally blocked.
947 * \note Applies to SS7 and MFCR2 channels.
949 unsigned int locallyblocked:1;
951 * \brief TRUE if the channel is remotely blocked.
952 * \note Applies to SS7 and MFCR2 channels.
954 unsigned int remotelyblocked:1;
956 * \brief TRUE if the channel alarms will be managed also as Span ones
957 * \note Applies to all channels
959 unsigned int manages_span_alarms:1;
961 #if defined(HAVE_PRI)
962 struct sig_pri_span *pri;
966 * \brief TRUE if SMDI (Simplified Message Desk Interface) is enabled
967 * \note Set from the "usesmdi" value read in from chan_dahdi.conf
969 unsigned int use_smdi:1;
970 struct mwisend_info mwisend_data;
971 /*! \brief The SMDI interface to get SMDI messages from. */
972 struct ast_smdi_interface *smdi_iface;
974 /*! \brief Distinctive Ring data */
975 struct dahdi_distRings drings;
978 * \brief The configured context for incoming calls.
979 * \note The "context" string read in from chan_dahdi.conf
981 char context[AST_MAX_CONTEXT];
983 * \brief Saved context string.
985 char defcontext[AST_MAX_CONTEXT];
986 /*! \brief Extension to use in the dialplan. */
987 char exten[AST_MAX_EXTENSION];
989 * \brief Language configured for calls.
990 * \note The "language" string read in from chan_dahdi.conf
992 char language[MAX_LANGUAGE];
994 * \brief The configured music-on-hold class to use for calls.
995 * \note The "musicclass" or "mohinterpret" or "musiconhold" string read in from chan_dahdi.conf
997 char mohinterpret[MAX_MUSICCLASS];
999 * \brief Suggested music-on-hold class for peer channel to use for calls.
1000 * \note The "mohsuggest" string read in from chan_dahdi.conf
1002 char mohsuggest[MAX_MUSICCLASS];
1003 char parkinglot[AST_MAX_EXTENSION]; /*!< Parking lot for this channel */
1004 #if defined(HAVE_PRI) || defined(HAVE_SS7)
1005 /*! \brief Automatic Number Identification number (Alternate PRI caller ID number) */
1006 char cid_ani[AST_MAX_EXTENSION];
1007 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
1008 /*! \brief Automatic Number Identification code from PRI */
1010 /*! \brief Caller ID number from an incoming call. */
1011 char cid_num[AST_MAX_EXTENSION];
1013 * \brief Caller ID tag from incoming call
1014 * \note the "cid_tag" string read in from chan_dahdi.conf
1016 char cid_tag[AST_MAX_EXTENSION];
1017 /*! \brief Caller ID Q.931 TON/NPI field values. Set by PRI. Zero otherwise. */
1019 /*! \brief Caller ID name from an incoming call. */
1020 char cid_name[AST_MAX_EXTENSION];
1021 /*! \brief Caller ID subaddress from an incoming call. */
1022 char cid_subaddr[AST_MAX_EXTENSION];
1023 char *origcid_num; /*!< malloced original callerid */
1024 char *origcid_name; /*!< malloced original callerid */
1025 /*! \brief Call waiting number. */
1026 char callwait_num[AST_MAX_EXTENSION];
1027 /*! \brief Call waiting name. */
1028 char callwait_name[AST_MAX_EXTENSION];
1029 /*! \brief Redirecting Directory Number Information Service (RDNIS) number */
1030 char rdnis[AST_MAX_EXTENSION];
1031 /*! \brief Dialed Number Identifier */
1032 char dnid[AST_MAX_EXTENSION];
1034 * \brief Bitmapped groups this belongs to.
1035 * \note The "group" bitmapped group string read in from chan_dahdi.conf
1038 /*! \brief Default call PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW. */
1040 /*! \brief Active PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW */
1042 int confno; /*!< Our conference */
1043 int confusers; /*!< Who is using our conference */
1044 int propconfno; /*!< Propagated conference number */
1046 * \brief Bitmapped call groups this belongs to.
1047 * \note The "callgroup" bitmapped group string read in from chan_dahdi.conf
1049 ast_group_t callgroup;
1051 * \brief Bitmapped pickup groups this belongs to.
1052 * \note The "pickupgroup" bitmapped group string read in from chan_dahdi.conf
1054 ast_group_t pickupgroup;
1056 * \brief Channel variable list with associated values to set when a channel is created.
1057 * \note The "setvar" strings read in from chan_dahdi.conf
1059 struct ast_variable *vars;
1060 int channel; /*!< Channel Number */
1061 int span; /*!< Span number */
1062 time_t guardtime; /*!< Must wait this much time before using for new call */
1063 int cid_signalling; /*!< CID signalling type bell202 or v23 */
1064 int cid_start; /*!< CID start indicator, polarity or ring or DTMF without warning event */
1065 int dtmfcid_holdoff_state; /*!< State indicator that allows for line to settle before checking for dtmf energy */
1066 struct timeval dtmfcid_delay; /*!< Time value used for allow line to settle */
1067 int callingpres; /*!< The value of calling presentation that we're going to use when placing a PRI call */
1068 int callwaitingrepeat; /*!< How many samples to wait before repeating call waiting */
1069 int cidcwexpire; /*!< When to stop waiting for CID/CW CAS response (In samples) */
1070 int cid_suppress_expire; /*!< How many samples to suppress after a CID spill. */
1071 /*! \brief Analog caller ID waveform sample buffer */
1072 unsigned char *cidspill;
1073 /*! \brief Position in the cidspill buffer to send out next. */
1075 /*! \brief Length of the cidspill buffer containing samples. */
1077 /*! \brief Ring timeout timer?? */
1080 * \brief Ring timeout base.
1081 * \note Value computed indirectly from "ringtimeout" read in from chan_dahdi.conf
1085 * \brief Number of most significant digits/characters to strip from the dialed number.
1086 * \note Feature is deprecated. Use dialplan logic.
1087 * \note The characters are stripped before the PRI TON/NPI prefix
1088 * characters are processed.
1092 * \brief TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
1094 * After CAS is sent, the call waiting caller id will be sent if the phone
1095 * gives a positive reply.
1098 /*! \brief Number of call waiting rings. */
1100 /*! \brief Echo cancel parameters. */
1102 struct dahdi_echocanparams head;
1103 struct dahdi_echocanparam params[DAHDI_MAX_ECHOCANPARAMS];
1106 * \brief Echo training time. 0 = disabled
1107 * \note Set from the "echotraining" value read in from chan_dahdi.conf
1110 /*! \brief Filled with 'w'. XXX Purpose?? */
1113 * \brief Number of times to see "busy" tone before hanging up.
1114 * \note Set from the "busycount" value read in from chan_dahdi.conf
1118 * \brief Busy cadence pattern description.
1119 * \note Set from the "busypattern" value read from chan_dahdi.conf
1121 struct ast_dsp_busy_pattern busy_cadence;
1123 * \brief Bitmapped call progress detection flags. CALLPROGRESS_xxx values.
1124 * \note Bits set from the "callprogress" and "faxdetect" values read in from chan_dahdi.conf
1128 * \brief Number of milliseconds to wait for dialtone.
1129 * \note Set from the "waitfordialtone" value read in from chan_dahdi.conf
1131 int waitfordialtone;
1132 struct timeval waitingfordt; /*!< Time we started waiting for dialtone */
1133 struct timeval flashtime; /*!< Last flash-hook time */
1134 /*! \brief Opaque DSP configuration structure. */
1135 struct ast_dsp *dsp;
1136 /*! \brief DAHDI dial operation command struct for ioctl() call. */
1137 struct dahdi_dialoperation dop;
1138 int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
1139 /*! \brief Second part of SIG_FEATDMF_TA wink operation. */
1141 char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
1142 int amaflags; /*!< AMA Flags */
1143 struct tdd_state *tdd; /*!< TDD flag */
1144 /*! \brief Accumulated call forwarding number. */
1145 char call_forward[AST_MAX_EXTENSION];
1147 * \brief Voice mailbox location.
1148 * \note Set from the "mailbox" string read in from chan_dahdi.conf
1150 char mailbox[AST_MAX_EXTENSION];
1151 /*! \brief Opaque event subscription parameters for message waiting indication support. */
1152 struct ast_event_sub *mwi_event_sub;
1153 /*! \brief Delayed dialing for E911. Overlap digits for ISDN. */
1155 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
1156 struct dahdi_vmwi_info mwisend_setting; /*!< Which VMWI methods to use */
1157 unsigned int mwisend_fsk: 1; /*! Variable for enabling FSK MWI handling in chan_dahdi */
1158 unsigned int mwisend_rpas:1; /*! Variable for enabling Ring Pulse Alert before MWI FSK Spill */
1160 int distinctivering; /*!< Which distinctivering to use */
1161 int dtmfrelax; /*!< whether to run in relaxed DTMF mode */
1162 /*! \brief Holding place for event injected from outside normal operation. */
1165 * \brief Minimal time period (ms) between the answer polarity
1166 * switch and hangup polarity switch.
1168 int polarityonanswerdelay;
1169 /*! \brief Start delay time if polarityonanswerdelay is nonzero. */
1170 struct timeval polaritydelaytv;
1172 * \brief Send caller ID on FXS after this many rings. Set to 1 for US.
1173 * \note Set from the "sendcalleridafter" value read in from chan_dahdi.conf
1175 int sendcalleridafter;
1176 /*! \brief Current line interface polarity. POLARITY_IDLE, POLARITY_REV */
1178 /*! \brief DSP feature flags: DSP_FEATURE_xxx */
1180 #if defined(HAVE_SS7)
1181 /*! \brief SS7 control parameters */
1182 struct sig_ss7_linkset *ss7;
1183 #endif /* defined(HAVE_SS7) */
1185 struct dahdi_mfcr2 *mfcr2;
1186 openr2_chan_t *r2chan;
1187 openr2_calling_party_category_t mfcr2_recvd_category;
1188 openr2_calling_party_category_t mfcr2_category;
1189 int mfcr2_dnis_index;
1190 int mfcr2_ani_index;
1192 int mfcr2_answer_pending:1;
1193 int mfcr2_charge_calls:1;
1194 int mfcr2_allow_collect_calls:1;
1195 int mfcr2_forced_release:1;
1196 int mfcr2_dnis_matched:1;
1197 int mfcr2_call_accepted:1;
1198 int mfcr2_accept_on_offer:1;
1199 int mfcr2_progress_sent:1;
1201 /*! \brief DTMF digit in progress. 0 when no digit in progress. */
1203 /*! \brief TRUE if confrence is muted. */
1206 struct ast_cc_config_params *cc_params;
1207 /* DAHDI channel names may differ greatly from the
1208 * string that was provided to an app such as Dial. We
1209 * need to save the original string passed to dahdi_request
1210 * for call completion purposes. This way, we can replicate
1211 * the original dialed string later.
1213 char dialstring[AST_CHANNEL_NAME];
1216 #define DATA_EXPORT_DAHDI_PVT(MEMBER) \
1217 MEMBER(dahdi_pvt, cid_rxgain, AST_DATA_DOUBLE) \
1218 MEMBER(dahdi_pvt, rxgain, AST_DATA_DOUBLE) \
1219 MEMBER(dahdi_pvt, txgain, AST_DATA_DOUBLE) \
1220 MEMBER(dahdi_pvt, txdrc, AST_DATA_DOUBLE) \
1221 MEMBER(dahdi_pvt, rxdrc, AST_DATA_DOUBLE) \
1222 MEMBER(dahdi_pvt, adsi, AST_DATA_BOOLEAN) \
1223 MEMBER(dahdi_pvt, answeronpolarityswitch, AST_DATA_BOOLEAN) \
1224 MEMBER(dahdi_pvt, busydetect, AST_DATA_BOOLEAN) \
1225 MEMBER(dahdi_pvt, callreturn, AST_DATA_BOOLEAN) \
1226 MEMBER(dahdi_pvt, callwaiting, AST_DATA_BOOLEAN) \
1227 MEMBER(dahdi_pvt, callwaitingcallerid, AST_DATA_BOOLEAN) \
1228 MEMBER(dahdi_pvt, cancallforward, AST_DATA_BOOLEAN) \
1229 MEMBER(dahdi_pvt, canpark, AST_DATA_BOOLEAN) \
1230 MEMBER(dahdi_pvt, confirmanswer, AST_DATA_BOOLEAN) \
1231 MEMBER(dahdi_pvt, destroy, AST_DATA_BOOLEAN) \
1232 MEMBER(dahdi_pvt, didtdd, AST_DATA_BOOLEAN) \
1233 MEMBER(dahdi_pvt, dialednone, AST_DATA_BOOLEAN) \
1234 MEMBER(dahdi_pvt, dialing, AST_DATA_BOOLEAN) \
1235 MEMBER(dahdi_pvt, digital, AST_DATA_BOOLEAN) \
1236 MEMBER(dahdi_pvt, dnd, AST_DATA_BOOLEAN) \
1237 MEMBER(dahdi_pvt, echobreak, AST_DATA_BOOLEAN) \
1238 MEMBER(dahdi_pvt, echocanbridged, AST_DATA_BOOLEAN) \
1239 MEMBER(dahdi_pvt, echocanon, AST_DATA_BOOLEAN) \
1240 MEMBER(dahdi_pvt, faxhandled, AST_DATA_BOOLEAN) \
1241 MEMBER(dahdi_pvt, usefaxbuffers, AST_DATA_BOOLEAN) \
1242 MEMBER(dahdi_pvt, bufferoverrideinuse, AST_DATA_BOOLEAN) \
1243 MEMBER(dahdi_pvt, firstradio, AST_DATA_BOOLEAN) \
1244 MEMBER(dahdi_pvt, hanguponpolarityswitch, AST_DATA_BOOLEAN) \
1245 MEMBER(dahdi_pvt, hardwaredtmf, AST_DATA_BOOLEAN) \
1246 MEMBER(dahdi_pvt, hidecallerid, AST_DATA_BOOLEAN) \
1247 MEMBER(dahdi_pvt, hidecalleridname, AST_DATA_BOOLEAN) \
1248 MEMBER(dahdi_pvt, ignoredtmf, AST_DATA_BOOLEAN) \
1249 MEMBER(dahdi_pvt, immediate, AST_DATA_BOOLEAN) \
1250 MEMBER(dahdi_pvt, inalarm, AST_DATA_BOOLEAN) \
1251 MEMBER(dahdi_pvt, mate, AST_DATA_BOOLEAN) \
1252 MEMBER(dahdi_pvt, outgoing, AST_DATA_BOOLEAN) \
1253 MEMBER(dahdi_pvt, permcallwaiting, AST_DATA_BOOLEAN) \
1254 MEMBER(dahdi_pvt, priindication_oob, AST_DATA_BOOLEAN) \
1255 MEMBER(dahdi_pvt, priexclusive, AST_DATA_BOOLEAN) \
1256 MEMBER(dahdi_pvt, pulse, AST_DATA_BOOLEAN) \
1257 MEMBER(dahdi_pvt, pulsedial, AST_DATA_BOOLEAN) \
1258 MEMBER(dahdi_pvt, restartpending, AST_DATA_BOOLEAN) \
1259 MEMBER(dahdi_pvt, restrictcid, AST_DATA_BOOLEAN) \
1260 MEMBER(dahdi_pvt, threewaycalling, AST_DATA_BOOLEAN) \
1261 MEMBER(dahdi_pvt, transfer, AST_DATA_BOOLEAN) \
1262 MEMBER(dahdi_pvt, use_callerid, AST_DATA_BOOLEAN) \
1263 MEMBER(dahdi_pvt, use_callingpres, AST_DATA_BOOLEAN) \
1264 MEMBER(dahdi_pvt, usedistinctiveringdetection, AST_DATA_BOOLEAN) \
1265 MEMBER(dahdi_pvt, dahditrcallerid, AST_DATA_BOOLEAN) \
1266 MEMBER(dahdi_pvt, transfertobusy, AST_DATA_BOOLEAN) \
1267 MEMBER(dahdi_pvt, mwimonitor_neon, AST_DATA_BOOLEAN) \
1268 MEMBER(dahdi_pvt, mwimonitor_fsk, AST_DATA_BOOLEAN) \
1269 MEMBER(dahdi_pvt, mwimonitor_rpas, AST_DATA_BOOLEAN) \
1270 MEMBER(dahdi_pvt, mwimonitoractive, AST_DATA_BOOLEAN) \
1271 MEMBER(dahdi_pvt, mwisendactive, AST_DATA_BOOLEAN) \
1272 MEMBER(dahdi_pvt, inservice, AST_DATA_BOOLEAN) \
1273 MEMBER(dahdi_pvt, locallyblocked, AST_DATA_BOOLEAN) \
1274 MEMBER(dahdi_pvt, remotelyblocked, AST_DATA_BOOLEAN) \
1275 MEMBER(dahdi_pvt, manages_span_alarms, AST_DATA_BOOLEAN) \
1276 MEMBER(dahdi_pvt, use_smdi, AST_DATA_BOOLEAN) \
1277 MEMBER(dahdi_pvt, context, AST_DATA_STRING) \
1278 MEMBER(dahdi_pvt, defcontext, AST_DATA_STRING) \
1279 MEMBER(dahdi_pvt, exten, AST_DATA_STRING) \
1280 MEMBER(dahdi_pvt, language, AST_DATA_STRING) \
1281 MEMBER(dahdi_pvt, mohinterpret, AST_DATA_STRING) \
1282 MEMBER(dahdi_pvt, mohsuggest, AST_DATA_STRING) \
1283 MEMBER(dahdi_pvt, parkinglot, AST_DATA_STRING)
1285 AST_DATA_STRUCTURE(dahdi_pvt, DATA_EXPORT_DAHDI_PVT);
1287 static struct dahdi_pvt *iflist = NULL; /*!< Main interface list start */
1288 static struct dahdi_pvt *ifend = NULL; /*!< Main interface list end */
1290 #if defined(HAVE_PRI)
1291 static struct dahdi_parms_pseudo {
1292 int buf_no; /*!< Number of buffers */
1293 int buf_policy; /*!< Buffer policy */
1294 int faxbuf_no; /*!< Number of Fax buffers */
1295 int faxbuf_policy; /*!< Fax buffer policy */
1296 } dahdi_pseudo_parms;
1297 #endif /* defined(HAVE_PRI) */
1299 /*! \brief Channel configuration from chan_dahdi.conf .
1300 * This struct is used for parsing the [channels] section of chan_dahdi.conf.
1301 * Generally there is a field here for every possible configuration item.
1303 * The state of fields is saved along the parsing and whenever a 'channel'
1304 * statement is reached, the current dahdi_chan_conf is used to configure the
1305 * channel (struct dahdi_pvt)
1307 * \see dahdi_chan_init for the default values.
1309 struct dahdi_chan_conf {
1310 struct dahdi_pvt chan;
1312 struct dahdi_pri pri;
1315 #if defined(HAVE_SS7)
1316 struct dahdi_ss7 ss7;
1317 #endif /* defined(HAVE_SS7) */
1320 struct dahdi_mfcr2_conf mfcr2;
1322 struct dahdi_params timing;
1323 int is_sig_auto; /*!< Use channel signalling from DAHDI? */
1324 /*! Continue configuration even if a channel is not there. */
1325 int ignore_failed_channels;
1328 * \brief The serial port to listen for SMDI data on
1329 * \note Set from the "smdiport" string read in from chan_dahdi.conf
1331 char smdi_port[SMDI_MAX_FILENAME_LEN];
1334 /*! returns a new dahdi_chan_conf with default values (by-value) */
1335 static struct dahdi_chan_conf dahdi_chan_conf_default(void)
1337 /* recall that if a field is not included here it is initialized
1338 * to 0 or equivalent
1340 struct dahdi_chan_conf conf = {
1343 .nsf = PRI_NSF_NONE,
1344 .switchtype = PRI_SWITCH_NI2,
1345 .dialplan = PRI_UNKNOWN + 1,
1346 .localdialplan = PRI_NATIONAL_ISDN + 1,
1347 .nodetype = PRI_CPE,
1348 .qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL,
1350 #if defined(HAVE_PRI_CCSS)
1351 .cc_ptmp_recall_mode = 1,/* specificRecall */
1352 .cc_qsig_signaling_link_req = 1,/* retain */
1353 .cc_qsig_signaling_link_rsp = 1,/* retain */
1354 #endif /* defined(HAVE_PRI_CCSS) */
1359 .internationalprefix = "",
1360 .nationalprefix = "",
1362 .privateprefix = "",
1363 .unknownprefix = "",
1364 .resetinterval = -1,
1367 #if defined(HAVE_SS7)
1369 .called_nai = SS7_NAI_NATIONAL,
1370 .calling_nai = SS7_NAI_NATIONAL,
1371 .internationalprefix = "",
1372 .nationalprefix = "",
1373 .subscriberprefix = "",
1376 #endif /* defined(HAVE_SS7) */
1379 .variant = OR2_VAR_ITU,
1380 .mfback_timeout = -1,
1381 .metering_pulse_timeout = -1,
1384 .get_ani_first = -1,
1385 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
1386 .skip_category_request = -1,
1389 .allow_collect_calls = 0,
1391 .accept_on_offer = 1,
1392 .forced_release = 0,
1394 .immediate_accept = -1,
1395 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
1397 .dtmf_detection = -1,
1398 .dtmf_time_on = OR2_DEFAULT_DTMF_ON,
1399 .dtmf_time_off = OR2_DEFAULT_DTMF_OFF,
1401 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3
1402 .dtmf_end_timeout = -1,
1406 .loglevel = OR2_LOG_ERROR | OR2_LOG_WARNING,
1407 .category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER
1411 .context = "default",
1415 .mohinterpret = "default",
1418 .transfertobusy = 1,
1420 .cid_signalling = CID_SIG_BELL,
1421 .cid_start = CID_START_RING,
1422 .dahditrcallerid = 0,
1431 .echocancel.head.tap_length = 1,
1439 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
1442 .polarityonanswerdelay = 600,
1444 .sendcalleridafter = DEFAULT_CIDRINGS,
1446 .buf_policy = DAHDI_POLICY_IMMEDIATE,
1449 .cc_params = ast_cc_config_params_init(),
1462 .smdi_port = "/dev/ttyS0",
1469 static struct ast_channel *dahdi_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, void *data, int *cause);
1470 static int dahdi_digit_begin(struct ast_channel *ast, char digit);
1471 static int dahdi_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
1472 static int dahdi_sendtext(struct ast_channel *c, const char *text);
1473 static int dahdi_call(struct ast_channel *ast, char *rdest, int timeout);
1474 static int dahdi_hangup(struct ast_channel *ast);
1475 static int dahdi_answer(struct ast_channel *ast);
1476 static struct ast_frame *dahdi_read(struct ast_channel *ast);
1477 static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame);
1478 static struct ast_frame *dahdi_exception(struct ast_channel *ast);
1479 static int dahdi_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen);
1480 static int dahdi_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
1481 static int dahdi_setoption(struct ast_channel *chan, int option, void *data, int datalen);
1482 static int dahdi_queryoption(struct ast_channel *chan, int option, void *data, int *datalen);
1483 static int dahdi_func_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
1484 static int dahdi_func_write(struct ast_channel *chan, const char *function, char *data, const char *value);
1485 static int dahdi_devicestate(void *data);
1486 static int dahdi_cc_callback(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback);
1488 static struct ast_channel_tech dahdi_tech = {
1490 .description = tdesc,
1491 .requester = dahdi_request,
1492 .send_digit_begin = dahdi_digit_begin,
1493 .send_digit_end = dahdi_digit_end,
1494 .send_text = dahdi_sendtext,
1496 .hangup = dahdi_hangup,
1497 .answer = dahdi_answer,
1499 .write = dahdi_write,
1500 .bridge = dahdi_bridge,
1501 .exception = dahdi_exception,
1502 .indicate = dahdi_indicate,
1503 .fixup = dahdi_fixup,
1504 .setoption = dahdi_setoption,
1505 .queryoption = dahdi_queryoption,
1506 .func_channel_read = dahdi_func_read,
1507 .func_channel_write = dahdi_func_write,
1508 .devicestate = dahdi_devicestate,
1509 .cc_callback = dahdi_cc_callback,
1512 #define GET_CHANNEL(p) ((p)->channel)
1514 #define SIG_PRI_LIB_HANDLE_CASES \
1521 * \brief Determine if sig_pri handles the signaling.
1524 * \param signaling Signaling to determine if is for sig_pri.
1526 * \return TRUE if the signaling is for sig_pri.
1528 static inline int dahdi_sig_pri_lib_handles(int signaling)
1532 switch (signaling) {
1533 case SIG_PRI_LIB_HANDLE_CASES:
1544 static enum analog_sigtype dahdisig_to_analogsig(int sig)
1548 return ANALOG_SIG_FXOLS;
1550 return ANALOG_SIG_FXOGS;
1552 return ANALOG_SIG_FXOKS;
1554 return ANALOG_SIG_FXSLS;
1556 return ANALOG_SIG_FXSGS;
1558 return ANALOG_SIG_FXSKS;
1560 return ANALOG_SIG_EMWINK;
1562 return ANALOG_SIG_EM;
1564 return ANALOG_SIG_EM_E1;
1566 return ANALOG_SIG_FEATD;
1568 return ANALOG_SIG_FEATDMF;
1572 return ANALOG_SIG_FGC_CAMA;
1573 case SIG_FGC_CAMAMF:
1574 return ANALOG_SIG_FGC_CAMAMF;
1576 return ANALOG_SIG_FEATB;
1578 return ANALOG_SIG_SFWINK;
1580 return ANALOG_SIG_SF;
1582 return ANALOG_SIG_SF_FEATD;
1583 case SIG_SF_FEATDMF:
1584 return ANALOG_SIG_SF_FEATDMF;
1585 case SIG_FEATDMF_TA:
1586 return ANALOG_SIG_FEATDMF_TA;
1588 return ANALOG_SIG_FEATB;
1595 static int analog_tone_to_dahditone(enum analog_tone tone)
1598 case ANALOG_TONE_RINGTONE:
1599 return DAHDI_TONE_RINGTONE;
1600 case ANALOG_TONE_STUTTER:
1601 return DAHDI_TONE_STUTTER;
1602 case ANALOG_TONE_CONGESTION:
1603 return DAHDI_TONE_CONGESTION;
1604 case ANALOG_TONE_DIALTONE:
1605 return DAHDI_TONE_DIALTONE;
1606 case ANALOG_TONE_DIALRECALL:
1607 return DAHDI_TONE_DIALRECALL;
1608 case ANALOG_TONE_INFO:
1609 return DAHDI_TONE_INFO;
1615 static int analogsub_to_dahdisub(enum analog_sub analogsub)
1619 switch (analogsub) {
1620 case ANALOG_SUB_REAL:
1623 case ANALOG_SUB_CALLWAIT:
1624 index = SUB_CALLWAIT;
1626 case ANALOG_SUB_THREEWAY:
1627 index = SUB_THREEWAY;
1630 ast_log(LOG_ERROR, "Unidentified sub!\n");
1637 static enum analog_event dahdievent_to_analogevent(int event);
1638 static int bump_gains(struct dahdi_pvt *p);
1639 static int dahdi_setlinear(int dfd, int linear);
1641 static int my_start_cid_detect(void *pvt, int cid_signalling)
1643 struct dahdi_pvt *p = pvt;
1644 int index = SUB_REAL;
1645 p->cs = callerid_new(cid_signalling);
1647 ast_log(LOG_ERROR, "Unable to alloc callerid\n");
1651 dahdi_setlinear(p->subs[index].dfd, 0);
1656 static int my_stop_cid_detect(void *pvt)
1658 struct dahdi_pvt *p = pvt;
1659 int index = SUB_REAL;
1661 callerid_free(p->cs);
1662 dahdi_setlinear(p->subs[index].dfd, p->subs[index].linear);
1666 static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_event *ev, size_t timeout)
1668 struct dahdi_pvt *p = pvt;
1669 struct analog_pvt *analog_p = p->sig_pvt;
1670 struct pollfd poller;
1672 int index = SUB_REAL;
1674 unsigned char buf[256];
1676 struct ast_format tmpfmt;
1678 poller.fd = p->subs[SUB_REAL].dfd;
1679 poller.events = POLLPRI | POLLIN;
1682 res = poll(&poller, 1, timeout);
1684 if (poller.revents & POLLPRI) {
1685 *ev = dahdievent_to_analogevent(dahdi_get_event(p->subs[SUB_REAL].dfd));
1689 if (poller.revents & POLLIN) {
1691 /* Change API: remove cid_signalling from get_callerid, add a new start_cid_detect and stop_cid_detect function
1692 * to enable slin mode and allocate cid detector. get_callerid should be able to be called any number of times until
1693 * either a timeout occurs or CID is detected (returns 0). returning 1 should be event received, and -1 should be
1694 * a failure and die, and returning 2 means no event was received. */
1695 res = read(p->subs[index].dfd, buf, sizeof(buf));
1697 if (errno != ELAST) {
1698 ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
1699 callerid_free(p->cs);
1704 if (analog_p->ringt > 0) {
1705 if (!(--analog_p->ringt)) {
1706 /* only return if we timeout from a ring event */
1711 if (p->cid_signalling == CID_SIG_V23_JP) {
1712 res = callerid_feed_jp(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1714 res = callerid_feed(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1718 * The previous diagnostic message output likely
1719 * explains why it failed.
1721 ast_log(LOG_WARNING, "Failed to decode CallerID\n");
1726 callerid_get(p->cs, &name, &num, &flags);
1728 ast_copy_string(namebuf, name, ANALOG_MAX_CID);
1730 ast_copy_string(numbuf, num, ANALOG_MAX_CID);
1732 ast_debug(1, "CallerID number: %s, name: %s, flags=%d\n", num, name, flags);
1737 *ev = ANALOG_EVENT_NONE;
1741 static const char *event2str(int event);
1742 static int restore_gains(struct dahdi_pvt *p);
1744 static int my_distinctive_ring(struct ast_channel *chan, void *pvt, int idx, int *ringdata)
1746 unsigned char buf[256];
1748 int curRingData[RING_PATTERNS];
1754 int checkaftercid = 0;
1756 struct dahdi_pvt *p = pvt;
1757 struct analog_pvt *analog_p = p->sig_pvt;
1759 if (ringdata == NULL) {
1760 ringdata = curRingData;
1765 /* We must have a ring by now, so, if configured, lets try to listen for
1766 * distinctive ringing */
1767 if ((checkaftercid && distinctiveringaftercid) || !checkaftercid) {
1768 /* Clear the current ring data array so we don't have old data in it. */
1769 for (receivedRingT = 0; receivedRingT < RING_PATTERNS; receivedRingT++)
1770 ringdata[receivedRingT] = 0;
1772 if (checkaftercid && distinctiveringaftercid)
1773 ast_verb(3, "Detecting post-CID distinctive ring\n");
1774 /* Check to see if context is what it should be, if not set to be. */
1775 else if (strcmp(p->context,p->defcontext) != 0) {
1776 ast_copy_string(p->context, p->defcontext, sizeof(p->context));
1777 ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
1781 i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
1782 if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) {
1783 ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
1787 if (i & DAHDI_IOMUX_SIGEVENT) {
1788 res = dahdi_get_event(p->subs[idx].dfd);
1789 if (res == DAHDI_EVENT_NOALARM) {
1791 analog_p->inalarm = 0;
1793 ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
1795 /* Let us detect distinctive ring */
1797 ringdata[receivedRingT] = analog_p->ringt;
1799 if (analog_p->ringt < analog_p->ringt_base/2)
1801 /* Increment the ringT counter so we can match it against
1802 values in chan_dahdi.conf for distinctive ring */
1803 if (++receivedRingT == RING_PATTERNS)
1805 } else if (i & DAHDI_IOMUX_READ) {
1806 res = read(p->subs[idx].dfd, buf, sizeof(buf));
1808 if (errno != ELAST) {
1809 ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
1815 if (analog_p->ringt > 0) {
1816 if (!(--analog_p->ringt)) {
1824 if ((checkaftercid && usedistinctiveringdetection) || !checkaftercid) {
1825 /* this only shows up if you have n of the dring patterns filled in */
1826 ast_verb(3, "Detected ring pattern: %d,%d,%d\n",ringdata[0],ringdata[1],ringdata[2]);
1827 for (counter = 0; counter < 3; counter++) {
1828 /* Check to see if the rings we received match any of the ones in chan_dahdi.conf for this channel */
1830 /* this only shows up if you have n of the dring patterns filled in */
1831 ast_verb(3, "Checking %d,%d,%d\n",
1832 p->drings.ringnum[counter].ring[0],
1833 p->drings.ringnum[counter].ring[1],
1834 p->drings.ringnum[counter].ring[2]);
1835 for (counter1 = 0; counter1 < 3; counter1++) {
1836 ast_verb(3, "Ring pattern check range: %d\n", p->drings.ringnum[counter].range);
1837 if (p->drings.ringnum[counter].ring[counter1] == -1) {
1838 ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n",
1839 ringdata[counter1]);
1841 } else if (ringdata[counter1] <= (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range) &&
1842 ringdata[counter1] >= (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range)) {
1843 ast_verb(3, "Ring pattern matched in range: %d to %d\n",
1844 (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range),
1845 (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range));
1850 if (distMatches == 3) {
1851 /* The ring matches, set the context to whatever is for distinctive ring.. */
1852 ast_copy_string(p->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(p->context));
1853 ast_copy_string(chan->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(chan->context));
1854 ast_verb(3, "Distinctive Ring matched context %s\n",p->context);
1859 /* Restore linear mode (if appropriate) for Caller*ID processing */
1860 dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
1866 static int my_stop_callwait(void *pvt)
1868 struct dahdi_pvt *p = pvt;
1869 p->callwaitingrepeat = 0;
1871 p->cid_suppress_expire = 0;
1876 static int send_callerid(struct dahdi_pvt *p);
1877 static int save_conference(struct dahdi_pvt *p);
1878 static int restore_conference(struct dahdi_pvt *p);
1880 static int my_callwait(void *pvt)
1882 struct dahdi_pvt *p = pvt;
1883 struct ast_format tmpfmt;
1884 p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
1886 ast_log(LOG_WARNING, "Spill already exists?!?\n");
1887 ast_free(p->cidspill);
1891 * SAS: Subscriber Alert Signal, 440Hz for 300ms
1892 * CAS: CPE Alert Signal, 2130Hz * 2750Hz sine waves
1894 if (!(p->cidspill = ast_malloc(2400 /* SAS */ + 680 /* CAS */ + READ_SIZE * 4)))
1898 memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4);
1899 if (!p->callwaitrings && p->callwaitingcallerid) {
1900 ast_gen_cas(p->cidspill, 1, 2400 + 680, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1902 p->cidlen = 2400 + 680 + READ_SIZE * 4;
1904 ast_gen_cas(p->cidspill, 1, 2400, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1906 p->cidlen = 2400 + READ_SIZE * 4;
1914 static int my_send_callerid(void *pvt, int cwcid, struct ast_party_caller *caller)
1916 struct dahdi_pvt *p = pvt;
1917 struct ast_format tmpfmt;
1919 ast_debug(2, "Starting cid spill\n");
1922 ast_log(LOG_WARNING, "cidspill already exists??\n");
1923 ast_free(p->cidspill);
1926 if ((p->cidspill = ast_malloc(MAX_CALLERID_SIZE))) {
1928 p->cidlen = ast_callerid_generate(p->cidspill,
1929 caller->id.name.str,
1930 caller->id.number.str,
1931 ast_format_set(&tmpfmt, AST_LAW(p), 0));
1933 ast_verb(3, "CPE supports Call Waiting Caller*ID. Sending '%s/%s'\n",
1934 caller->id.name.str, caller->id.number.str);
1937 p->cidlen = ast_callerid_callwaiting_generate(p->cidspill,
1938 caller->id.name.str,
1939 caller->id.number.str,
1940 ast_format_set(&tmpfmt, AST_LAW(p), 0));
1941 p->cidlen += READ_SIZE * 4;
1944 p->cid_suppress_expire = 0;
1950 static int my_dsp_reset_and_flush_digits(void *pvt)
1952 struct dahdi_pvt *p = pvt;
1954 ast_dsp_digitreset(p->dsp);
1959 static int my_dsp_set_digitmode(void *pvt, enum analog_dsp_digitmode mode)
1961 struct dahdi_pvt *p = pvt;
1963 if (p->channel == CHAN_PSEUDO)
1964 ast_log(LOG_ERROR, "You have assumed incorrectly sir!\n");
1966 if (mode == ANALOG_DIGITMODE_DTMF) {
1967 /* If we do hardware dtmf, no need for a DSP */
1968 if (p->hardwaredtmf) {
1970 ast_dsp_free(p->dsp);
1977 p->dsp = ast_dsp_new();
1979 ast_log(LOG_ERROR, "Unable to allocate DSP\n");
1984 ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax);
1985 } else if (mode == ANALOG_DIGITMODE_MF) {
1987 p->dsp = ast_dsp_new();
1989 ast_log(LOG_ERROR, "Unable to allocate DSP\n");
1993 ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MF | p->dtmfrelax);
1998 static int dahdi_wink(struct dahdi_pvt *p, int index);
2000 static int my_wink(void *pvt, enum analog_sub sub)
2002 struct dahdi_pvt *p = pvt;
2003 int index = analogsub_to_dahdisub(sub);
2004 if (index != SUB_REAL) {
2005 ast_log(LOG_ERROR, "We used a sub other than SUB_REAL (incorrect assumption sir)\n");
2007 return dahdi_wink(p, index);
2010 static void wakeup_sub(struct dahdi_pvt *p, int a);
2012 static int reset_conf(struct dahdi_pvt *p);
2014 static inline int dahdi_confmute(struct dahdi_pvt *p, int muted);
2016 static void my_handle_dtmf(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
2018 struct ast_frame *f = *dest;
2019 struct dahdi_pvt *p = pvt;
2020 int idx = analogsub_to_dahdisub(analog_index);
2022 ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n",
2023 f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End",
2024 f->subclass.integer, f->subclass.integer, ast->name);
2026 if (f->subclass.integer == 'f') {
2027 if (f->frametype == AST_FRAME_DTMF_END) {
2028 /* Fax tone -- Handle and return NULL */
2029 if ((p->callprogress & CALLPROGRESS_FAX) && !p->faxhandled) {
2030 /* If faxbuffers are configured, use them for the fax transmission */
2031 if (p->usefaxbuffers && !p->bufferoverrideinuse) {
2032 struct dahdi_bufferinfo bi = {
2033 .txbufpolicy = p->faxbuf_policy,
2034 .bufsize = p->bufsize,
2035 .numbufs = p->faxbuf_no
2039 if ((res = ioctl(p->subs[idx].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) {
2040 ast_log(LOG_WARNING, "Channel '%s' unable to set buffer policy, reason: %s\n", ast->name, strerror(errno));
2042 p->bufferoverrideinuse = 1;
2047 p->dsp_features &= ~DSP_FEATURE_FAX_DETECT;
2048 ast_dsp_set_features(p->dsp, p->dsp_features);
2049 ast_debug(1, "Disabling FAX tone detection on %s after tone received\n", ast->name);
2051 if (strcmp(ast->exten, "fax")) {
2052 const char *target_context = S_OR(ast->macrocontext, ast->context);
2054 /* We need to unlock 'ast' here because ast_exists_extension has the
2055 * potential to start autoservice on the channel. Such action is prone
2058 ast_mutex_unlock(&p->lock);
2059 ast_channel_unlock(ast);
2060 if (ast_exists_extension(ast, target_context, "fax", 1,
2061 S_COR(ast->caller.id.number.valid, ast->caller.id.number.str, NULL))) {
2062 ast_channel_lock(ast);
2063 ast_mutex_lock(&p->lock);
2064 ast_verb(3, "Redirecting %s to fax extension\n", ast->name);
2065 /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
2066 pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten);
2067 if (ast_async_goto(ast, target_context, "fax", 1))
2068 ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context);
2070 ast_channel_lock(ast);
2071 ast_mutex_lock(&p->lock);
2072 ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
2075 ast_debug(1, "Already in a fax extension, not redirecting\n");
2078 ast_debug(1, "Fax already handled\n");
2080 dahdi_confmute(p, 0);
2082 p->subs[idx].f.frametype = AST_FRAME_NULL;
2083 p->subs[idx].f.subclass.integer = 0;
2084 *dest = &p->subs[idx].f;
2088 static void my_lock_private(void *pvt)
2090 struct dahdi_pvt *p = pvt;
2091 ast_mutex_lock(&p->lock);
2094 static void my_unlock_private(void *pvt)
2096 struct dahdi_pvt *p = pvt;
2097 ast_mutex_unlock(&p->lock);
2100 static void my_deadlock_avoidance_private(void *pvt)
2102 struct dahdi_pvt *p = pvt;
2104 DEADLOCK_AVOIDANCE(&p->lock);
2109 * \brief Post an AMI DAHDI channel association event.
2112 * \param p DAHDI private pointer
2113 * \param chan Channel associated with the private pointer
2117 static void dahdi_ami_channel_event(struct dahdi_pvt *p, struct ast_channel *chan)
2121 if (p->channel < CHAN_PSEUDO) {
2123 snprintf(ch_name, sizeof(ch_name), "no-media (%d)", p->channel);
2124 } else if (p->channel == CHAN_PSEUDO) {
2125 /* Pseudo channel */
2126 strcpy(ch_name, "pseudo");
2129 snprintf(ch_name, sizeof(ch_name), "%d", p->channel);
2131 ast_manager_event(chan, EVENT_FLAG_CALL, "DAHDIChannel",
2135 "DAHDIChannel: %s\r\n",
2145 * \brief Post an AMI DAHDI channel association event.
2148 * \param pvt DAHDI private pointer
2149 * \param chan Channel associated with the private pointer
2153 static void my_ami_channel_event(void *pvt, struct ast_channel *chan)
2155 struct dahdi_pvt *p = pvt;
2157 dahdi_ami_channel_event(p, chan);
2161 /* linear_mode = 0 - turn linear mode off, >0 - turn linear mode on
2162 * returns the last value of the linear setting
2164 static int my_set_linear_mode(void *pvt, enum analog_sub sub, int linear_mode)
2166 struct dahdi_pvt *p = pvt;
2168 int idx = analogsub_to_dahdisub(sub);
2170 dahdi_setlinear(p->subs[idx].dfd, linear_mode);
2171 oldval = p->subs[idx].linear;
2172 p->subs[idx].linear = linear_mode ? 1 : 0;
2176 static void my_set_inthreeway(void *pvt, enum analog_sub sub, int inthreeway)
2178 struct dahdi_pvt *p = pvt;
2179 int idx = analogsub_to_dahdisub(sub);
2181 p->subs[idx].inthreeway = inthreeway;
2184 static int get_alarms(struct dahdi_pvt *p);
2185 static void handle_alarms(struct dahdi_pvt *p, int alms);
2186 static void my_get_and_handle_alarms(void *pvt)
2189 struct dahdi_pvt *p = pvt;
2191 res = get_alarms(p);
2192 handle_alarms(p, res);
2195 static void *my_get_sigpvt_bridged_channel(struct ast_channel *chan)
2197 struct dahdi_pvt *p = ast_bridged_channel(chan)->tech_pvt;
2204 static int my_get_sub_fd(void *pvt, enum analog_sub sub)
2206 struct dahdi_pvt *p = pvt;
2207 int dahdi_sub = analogsub_to_dahdisub(sub);
2208 return p->subs[dahdi_sub].dfd;
2211 static void my_set_cadence(void *pvt, int *cidrings, struct ast_channel *ast)
2213 struct dahdi_pvt *p = pvt;
2215 /* Choose proper cadence */
2216 if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) {
2217 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &cadences[p->distinctivering - 1]))
2218 ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s': %s\n", p->distinctivering, ast->name, strerror(errno));
2219 *cidrings = cidrings[p->distinctivering - 1];
2221 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, NULL))
2222 ast_log(LOG_WARNING, "Unable to reset default ring on '%s': %s\n", ast->name, strerror(errno));
2223 *cidrings = p->sendcalleridafter;
2227 static void my_set_alarm(void *pvt, int in_alarm)
2229 struct dahdi_pvt *p = pvt;
2231 p->inalarm = in_alarm;
2234 static void my_set_dialing(void *pvt, int is_dialing)
2236 struct dahdi_pvt *p = pvt;
2238 p->dialing = is_dialing;
2241 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2242 static void my_set_digital(void *pvt, int is_digital)
2244 struct dahdi_pvt *p = pvt;
2246 p->digital = is_digital;
2248 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2250 #if defined(HAVE_SS7)
2251 static void my_set_inservice(void *pvt, int is_inservice)
2253 struct dahdi_pvt *p = pvt;
2255 p->inservice = is_inservice;
2257 #endif /* defined(HAVE_SS7) */
2259 #if defined(HAVE_SS7)
2260 static void my_set_locallyblocked(void *pvt, int is_blocked)
2262 struct dahdi_pvt *p = pvt;
2264 p->locallyblocked = is_blocked;
2266 #endif /* defined(HAVE_SS7) */
2268 #if defined(HAVE_SS7)
2269 static void my_set_remotelyblocked(void *pvt, int is_blocked)
2271 struct dahdi_pvt *p = pvt;
2273 p->remotelyblocked = is_blocked;
2275 #endif /* defined(HAVE_SS7) */
2277 static void my_set_ringtimeout(void *pvt, int ringt)
2279 struct dahdi_pvt *p = pvt;
2283 static void my_set_waitingfordt(void *pvt, struct ast_channel *ast)
2285 struct dahdi_pvt *p = pvt;
2287 if (p->waitfordialtone && CANPROGRESSDETECT(p) && p->dsp) {
2288 ast_debug(1, "Defer dialing for %dms or dialtone\n", p->waitfordialtone);
2289 gettimeofday(&p->waitingfordt, NULL);
2290 ast_setstate(ast, AST_STATE_OFFHOOK);
2294 static int my_check_waitingfordt(void *pvt)
2296 struct dahdi_pvt *p = pvt;
2298 if (p->waitingfordt.tv_usec) {
2305 static void my_set_confirmanswer(void *pvt, int flag)
2307 struct dahdi_pvt *p = pvt;
2308 p->confirmanswer = flag;
2311 static int my_check_confirmanswer(void *pvt)
2313 struct dahdi_pvt *p = pvt;
2314 if (p->confirmanswer) {
2321 static void my_set_callwaiting(void *pvt, int callwaiting_enable)
2323 struct dahdi_pvt *p = pvt;
2325 p->callwaiting = callwaiting_enable;
2328 static void my_cancel_cidspill(void *pvt)
2330 struct dahdi_pvt *p = pvt;
2332 ast_free(p->cidspill);
2334 restore_conference(p);
2337 static int my_confmute(void *pvt, int mute)
2339 struct dahdi_pvt *p = pvt;
2340 return dahdi_confmute(p, mute);
2343 static void my_set_pulsedial(void *pvt, int flag)
2345 struct dahdi_pvt *p = pvt;
2346 p->pulsedial = flag;
2349 static void my_set_new_owner(void *pvt, struct ast_channel *new_owner)
2351 struct dahdi_pvt *p = pvt;
2353 p->owner = new_owner;
2356 static const char *my_get_orig_dialstring(void *pvt)
2358 struct dahdi_pvt *p = pvt;
2360 return p->dialstring;
2363 static void my_increase_ss_count(void)
2365 ast_mutex_lock(&ss_thread_lock);
2367 ast_mutex_unlock(&ss_thread_lock);
2370 static void my_decrease_ss_count(void)
2372 ast_mutex_lock(&ss_thread_lock);
2374 ast_cond_signal(&ss_thread_complete);
2375 ast_mutex_unlock(&ss_thread_lock);
2378 static void my_all_subchannels_hungup(void *pvt)
2380 struct dahdi_pvt *p = pvt;
2387 ast_dsp_free(p->dsp);
2391 p->law = p->law_default;
2392 law = p->law_default;
2393 res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law);
2395 ast_log(LOG_WARNING, "Unable to set law on channel %d to default: %s\n", p->channel, strerror(errno));
2397 dahdi_setlinear(p->subs[SUB_REAL].dfd, 0);
2403 /* Cleanup owners here */
2404 for (i = 0; i < 3; i++) {
2405 p->subs[i].owner = NULL;
2411 if (num_restart_pending == 0) {
2416 static int conf_del(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index);
2418 static int my_conf_del(void *pvt, enum analog_sub sub)
2420 struct dahdi_pvt *p = pvt;
2421 int x = analogsub_to_dahdisub(sub);
2423 return conf_del(p, &p->subs[x], x);
2426 static int conf_add(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index, int slavechannel);
2428 static int my_conf_add(void *pvt, enum analog_sub sub)
2430 struct dahdi_pvt *p = pvt;
2431 int x = analogsub_to_dahdisub(sub);
2433 return conf_add(p, &p->subs[x], x, 0);
2436 static int isslavenative(struct dahdi_pvt *p, struct dahdi_pvt **out);
2438 static int my_complete_conference_update(void *pvt, int needconference)
2440 struct dahdi_pvt *p = pvt;
2441 int needconf = needconference;
2444 struct dahdi_pvt *slave = NULL;
2446 useslavenative = isslavenative(p, &slave);
2448 /* If we have a slave, add him to our conference now. or DAX
2449 if this is slave native */
2450 for (x = 0; x < MAX_SLAVES; x++) {
2453 conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p));
2455 conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, 0);
2460 /* If we're supposed to be in there, do so now */
2461 if (p->inconference && !p->subs[SUB_REAL].inthreeway) {
2463 conf_add(p, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(slave));
2465 conf_add(p, &p->subs[SUB_REAL], SUB_REAL, 0);
2469 /* If we have a master, add ourselves to his conference */
2471 if (isslavenative(p->master, NULL)) {
2472 conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p->master));
2474 conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, 0);
2478 /* Nobody is left (or should be left) in our conference.
2486 static int check_for_conference(struct dahdi_pvt *p);
2488 static int my_check_for_conference(void *pvt)
2490 struct dahdi_pvt *p = pvt;
2491 return check_for_conference(p);
2494 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)
2496 struct dahdi_pvt *p = pvt;
2501 da = analogsub_to_dahdisub(a);
2502 db = analogsub_to_dahdisub(b);
2504 tchan = p->subs[da].chan;
2505 p->subs[da].chan = p->subs[db].chan;
2506 p->subs[db].chan = tchan;
2508 tinthreeway = p->subs[da].inthreeway;
2509 p->subs[da].inthreeway = p->subs[db].inthreeway;
2510 p->subs[db].inthreeway = tinthreeway;
2512 p->subs[da].owner = ast_a;
2513 p->subs[db].owner = ast_b;
2516 ast_channel_set_fd(ast_a, 0, p->subs[da].dfd);
2518 ast_channel_set_fd(ast_b, 0, p->subs[db].dfd);
2526 static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const char *linkedid);
2528 static struct ast_channel *my_new_analog_ast_channel(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
2530 struct dahdi_pvt *p = pvt;
2531 int dsub = analogsub_to_dahdisub(sub);
2533 return dahdi_new(p, state, startpbx, dsub, 0, requestor ? requestor->linkedid : "");
2536 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2537 static int dahdi_setlaw(int dfd, int law)
2540 res = ioctl(dfd, DAHDI_SETLAW, &law);
2545 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2547 #if defined(HAVE_PRI)
2548 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)
2550 struct dahdi_pvt *p = pvt;
2555 case SIG_PRI_LIB_HANDLE_CASES:
2556 if (((struct sig_pri_chan *) p->sig_pvt)->no_b_channel) {
2557 /* PRI nobch pseudo channel. Does not handle ioctl(DAHDI_AUDIOMODE) */
2562 /* Set to audio mode at this point */
2564 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &audio) == -1) {
2565 ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n",
2566 p->channel, audio, strerror(errno));
2571 if (law != SIG_PRI_DEFLAW) {
2572 dahdi_setlaw(p->subs[SUB_REAL].dfd, (law == SIG_PRI_ULAW) ? DAHDI_LAW_MULAW : DAHDI_LAW_ALAW);
2575 ast_copy_string(p->exten, exten, sizeof(p->exten));
2578 case SIG_PRI_DEFLAW:
2582 newlaw = DAHDI_LAW_ALAW;
2585 newlaw = DAHDI_LAW_MULAW;
2588 return dahdi_new(p, state, 0, SUB_REAL, newlaw, requestor ? requestor->linkedid : "");
2590 #endif /* defined(HAVE_PRI) */
2592 static int set_actual_gain(int fd, float rxgain, float txgain, float rxdrc, float txdrc, int law);
2594 #if defined(HAVE_PRI)
2597 * \brief Open the PRI channel media path.
2600 * \param p Channel private control structure.
2604 static void my_pri_open_media(void *p)
2606 struct dahdi_pvt *pvt = p;
2611 dfd = pvt->subs[SUB_REAL].dfd;
2613 /* Open the media path. */
2615 res = ioctl(dfd, DAHDI_AUDIOMODE, &set_val);
2617 ast_log(LOG_WARNING, "Unable to enable audio mode on channel %d (%s)\n",
2618 pvt->channel, strerror(errno));
2621 /* Set correct companding law for this call. */
2622 res = dahdi_setlaw(dfd, pvt->law);
2624 ast_log(LOG_WARNING, "Unable to set law on channel %d\n", pvt->channel);
2627 /* Set correct gain for this call. */
2629 res = set_actual_gain(dfd, 0, 0, pvt->rxdrc, pvt->txdrc, pvt->law);
2631 res = set_actual_gain(dfd, pvt->rxgain, pvt->txgain, pvt->rxdrc, pvt->txdrc,
2635 ast_log(LOG_WARNING, "Unable to set gains on channel %d\n", pvt->channel);
2638 if (pvt->dsp_features && pvt->dsp) {
2639 ast_dsp_set_features(pvt->dsp, pvt->dsp_features);
2640 pvt->dsp_features = 0;
2643 #endif /* defined(HAVE_PRI) */
2645 static int unalloc_sub(struct dahdi_pvt *p, int x);
2647 static int my_unallocate_sub(void *pvt, enum analog_sub analogsub)
2649 struct dahdi_pvt *p = pvt;
2651 return unalloc_sub(p, analogsub_to_dahdisub(analogsub));
2654 static int alloc_sub(struct dahdi_pvt *p, int x);
2656 static int my_allocate_sub(void *pvt, enum analog_sub analogsub)
2658 struct dahdi_pvt *p = pvt;
2660 return alloc_sub(p, analogsub_to_dahdisub(analogsub));
2663 static int has_voicemail(struct dahdi_pvt *p);
2665 static int my_has_voicemail(void *pvt)
2667 struct dahdi_pvt *p = pvt;
2669 return has_voicemail(p);
2672 static int my_play_tone(void *pvt, enum analog_sub sub, enum analog_tone tone)
2674 struct dahdi_pvt *p = pvt;
2677 index = analogsub_to_dahdisub(sub);
2679 return tone_zone_play_tone(p->subs[index].dfd, analog_tone_to_dahditone(tone));
2682 static enum analog_event dahdievent_to_analogevent(int event)
2684 enum analog_event res;
2687 case DAHDI_EVENT_ONHOOK:
2688 res = ANALOG_EVENT_ONHOOK;
2690 case DAHDI_EVENT_RINGOFFHOOK:
2691 res = ANALOG_EVENT_RINGOFFHOOK;
2693 case DAHDI_EVENT_WINKFLASH:
2694 res = ANALOG_EVENT_WINKFLASH;
2696 case DAHDI_EVENT_ALARM:
2697 res = ANALOG_EVENT_ALARM;
2699 case DAHDI_EVENT_NOALARM:
2700 res = ANALOG_EVENT_NOALARM;
2702 case DAHDI_EVENT_DIALCOMPLETE:
2703 res = ANALOG_EVENT_DIALCOMPLETE;
2705 case DAHDI_EVENT_RINGERON:
2706 res = ANALOG_EVENT_RINGERON;
2708 case DAHDI_EVENT_RINGEROFF:
2709 res = ANALOG_EVENT_RINGEROFF;
2711 case DAHDI_EVENT_HOOKCOMPLETE:
2712 res = ANALOG_EVENT_HOOKCOMPLETE;
2714 case DAHDI_EVENT_PULSE_START:
2715 res = ANALOG_EVENT_PULSE_START;
2717 case DAHDI_EVENT_POLARITY:
2718 res = ANALOG_EVENT_POLARITY;
2720 case DAHDI_EVENT_RINGBEGIN:
2721 res = ANALOG_EVENT_RINGBEGIN;
2723 case DAHDI_EVENT_EC_DISABLED:
2724 res = ANALOG_EVENT_EC_DISABLED;
2726 case DAHDI_EVENT_REMOVED:
2727 res = ANALOG_EVENT_REMOVED;
2729 case DAHDI_EVENT_NEONMWI_ACTIVE:
2730 res = ANALOG_EVENT_NEONMWI_ACTIVE;
2732 case DAHDI_EVENT_NEONMWI_INACTIVE:
2733 res = ANALOG_EVENT_NEONMWI_INACTIVE;
2735 #ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
2736 case DAHDI_EVENT_TX_CED_DETECTED:
2737 res = ANALOG_EVENT_TX_CED_DETECTED;
2739 case DAHDI_EVENT_RX_CED_DETECTED:
2740 res = ANALOG_EVENT_RX_CED_DETECTED;
2742 case DAHDI_EVENT_EC_NLP_DISABLED:
2743 res = ANALOG_EVENT_EC_NLP_DISABLED;
2745 case DAHDI_EVENT_EC_NLP_ENABLED:
2746 res = ANALOG_EVENT_EC_NLP_ENABLED;
2749 case DAHDI_EVENT_PULSEDIGIT:
2750 res = ANALOG_EVENT_PULSEDIGIT;
2752 case DAHDI_EVENT_DTMFDOWN:
2753 res = ANALOG_EVENT_DTMFDOWN;
2755 case DAHDI_EVENT_DTMFUP:
2756 res = ANALOG_EVENT_DTMFUP;
2759 switch(event & 0xFFFF0000) {
2760 case DAHDI_EVENT_PULSEDIGIT:
2761 case DAHDI_EVENT_DTMFDOWN:
2762 case DAHDI_EVENT_DTMFUP:
2763 /* The event includes a digit number in the low word.
2764 * Converting it to a 'enum analog_event' would remove
2765 * that information. Thus it is returned as-is.
2770 res = ANALOG_EVENT_ERROR;
2777 static inline int dahdi_wait_event(int fd);
2779 static int my_wait_event(void *pvt)
2781 struct dahdi_pvt *p = pvt;
2783 return dahdi_wait_event(p->subs[SUB_REAL].dfd);
2786 static int my_get_event(void *pvt)
2788 struct dahdi_pvt *p = pvt;
2791 if (p->fake_event) {
2792 res = p->fake_event;
2795 res = dahdi_get_event(p->subs[SUB_REAL].dfd);
2797 return dahdievent_to_analogevent(res);
2800 static int my_is_off_hook(void *pvt)
2802 struct dahdi_pvt *p = pvt;
2804 struct dahdi_params par;
2806 memset(&par, 0, sizeof(par));
2808 if (p->subs[SUB_REAL].dfd > -1)
2809 res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par);
2811 /* Assume not off hook on CVRS */
2813 par.rxisoffhook = 0;
2816 ast_log(LOG_WARNING, "Unable to check hook state on channel %d: %s\n", p->channel, strerror(errno));
2819 if ((p->sig == SIG_FXSKS) || (p->sig == SIG_FXSGS)) {
2820 /* When "onhook" that means no battery on the line, and thus
2821 it is out of service..., if it's on a TDM card... If it's a channel
2822 bank, there is no telling... */
2823 return (par.rxbits > -1) || par.rxisoffhook;
2826 return par.rxisoffhook;
2829 static void dahdi_enable_ec(struct dahdi_pvt *p);
2830 static void dahdi_disable_ec(struct dahdi_pvt *p);
2832 static int my_set_echocanceller(void *pvt, int enable)
2834 struct dahdi_pvt *p = pvt;
2839 dahdi_disable_ec(p);
2844 static int dahdi_ring_phone(struct dahdi_pvt *p);
2846 static int my_ring(void *pvt)
2848 struct dahdi_pvt *p = pvt;
2850 return dahdi_ring_phone(p);
2853 static int my_flash(void *pvt)
2855 struct dahdi_pvt *p = pvt;
2856 int func = DAHDI_FLASH;
2857 return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &func);
2860 static inline int dahdi_set_hook(int fd, int hs);
2862 static int my_off_hook(void *pvt)
2864 struct dahdi_pvt *p = pvt;
2865 return dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK);
2868 static void my_set_needringing(void *pvt, int value)
2870 struct dahdi_pvt *p = pvt;
2871 p->subs[SUB_REAL].needringing = value;
2874 static void my_set_polarity(void *pvt, int value)
2876 struct dahdi_pvt *p = pvt;
2878 if (p->channel == CHAN_PSEUDO) {
2881 p->polarity = value;
2882 ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETPOLARITY, &value);
2885 static void my_start_polarityswitch(void *pvt)
2887 struct dahdi_pvt *p = pvt;
2889 if (p->answeronpolarityswitch || p->hanguponpolarityswitch) {
2890 my_set_polarity(pvt, 0);
2894 static void my_answer_polarityswitch(void *pvt)
2896 struct dahdi_pvt *p = pvt;
2898 if (!p->answeronpolarityswitch) {
2902 my_set_polarity(pvt, 1);
2905 static void my_hangup_polarityswitch(void *pvt)
2907 struct dahdi_pvt *p = pvt;
2909 if (!p->hanguponpolarityswitch) {
2913 if (p->answeronpolarityswitch) {
2914 my_set_polarity(pvt, 0);
2916 my_set_polarity(pvt, 1);
2920 static int my_start(void *pvt)
2922 struct dahdi_pvt *p = pvt;
2923 int x = DAHDI_START;
2925 return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
2928 static int my_dial_digits(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop)
2930 int index = analogsub_to_dahdisub(sub);
2932 struct dahdi_pvt *p = pvt;
2933 struct dahdi_dialoperation ddop;
2935 if (dop->op != ANALOG_DIAL_OP_REPLACE) {
2936 ast_log(LOG_ERROR, "Fix the dial_digits callback!\n");
2940 if (sub != ANALOG_SUB_REAL)
2941 printf("Trying to dial digits on sub %d\n", sub);
2943 ddop.op = DAHDI_DIAL_OP_REPLACE;
2944 strncpy(ddop.dialstr, dop->dialstr, sizeof(ddop.dialstr));
2946 printf("Dialing %s on %d\n", ddop.dialstr, p->channel);
2948 res = ioctl(p->subs[index].dfd, DAHDI_DIAL, &ddop);
2951 ast_debug(1, "DAHDI_DIAL ioctl failed on %s: %s\n", p->owner->name, strerror(errno));
2956 static void dahdi_train_ec(struct dahdi_pvt *p);
2958 static int my_train_echocanceller(void *pvt)
2960 struct dahdi_pvt *p = pvt;
2967 static int my_is_dialing(void *pvt, enum analog_sub sub)
2969 struct dahdi_pvt *p = pvt;
2973 index = analogsub_to_dahdisub(sub);
2975 if (ioctl(p->subs[index].dfd, DAHDI_DIALING, &x)) {
2976 ast_debug(1, "DAHDI_DIALING ioctl failed!\n");
2983 static int my_on_hook(void *pvt)
2985 struct dahdi_pvt *p = pvt;
2986 return dahdi_set_hook(p->subs[ANALOG_SUB_REAL].dfd, DAHDI_ONHOOK);
2989 #if defined(HAVE_PRI)
2990 static void my_pri_fixup_chans(void *chan_old, void *chan_new)
2992 struct dahdi_pvt *old_chan = chan_old;
2993 struct dahdi_pvt *new_chan = chan_new;
2995 new_chan->owner = old_chan->owner;
2996 old_chan->owner = NULL;
2997 if (new_chan->owner) {
2998 new_chan->owner->tech_pvt = new_chan;
2999 new_chan->owner->fds[0] = new_chan->subs[SUB_REAL].dfd;
3000 new_chan->subs[SUB_REAL].owner = old_chan->subs[SUB_REAL].owner;
3001 old_chan->subs[SUB_REAL].owner = NULL;
3003 /* Copy any DSP that may be present */
3004 new_chan->dsp = old_chan->dsp;
3005 new_chan->dsp_features = old_chan->dsp_features;
3006 old_chan->dsp = NULL;
3007 old_chan->dsp_features = 0;
3009 /* Transfer flags from the old channel. */
3010 new_chan->dialing = old_chan->dialing;
3011 new_chan->digital = old_chan->digital;
3012 new_chan->outgoing = old_chan->outgoing;
3013 old_chan->dialing = 0;
3014 old_chan->digital = 0;
3015 old_chan->outgoing = 0;
3017 /* More stuff to transfer to the new channel. */
3018 new_chan->law = old_chan->law;
3019 strcpy(new_chan->dialstring, old_chan->dialstring);
3021 #endif /* defined(HAVE_PRI) */
3023 #if defined(HAVE_PRI)
3024 static int sig_pri_tone_to_dahditone(enum sig_pri_tone tone)
3027 case SIG_PRI_TONE_RINGTONE:
3028 return DAHDI_TONE_RINGTONE;
3029 case SIG_PRI_TONE_STUTTER:
3030 return DAHDI_TONE_STUTTER;
3031 case SIG_PRI_TONE_CONGESTION:
3032 return DAHDI_TONE_CONGESTION;
3033 case SIG_PRI_TONE_DIALTONE:
3034 return DAHDI_TONE_DIALTONE;
3035 case SIG_PRI_TONE_DIALRECALL:
3036 return DAHDI_TONE_DIALRECALL;
3037 case SIG_PRI_TONE_INFO:
3038 return DAHDI_TONE_INFO;
3039 case SIG_PRI_TONE_BUSY:
3040 return DAHDI_TONE_BUSY;
3045 #endif /* defined(HAVE_PRI) */
3047 #if defined(HAVE_PRI)
3048 static void my_handle_dchan_exception(struct sig_pri_span *pri, int index)
3052 res = ioctl(pri->fds[index], DAHDI_GETEVENT, &x);
3054 ast_log(LOG_NOTICE, "PRI got event: %s (%d) on D-channel of span %d\n", event2str(x), x, pri->span);
3056 /* Keep track of alarm state */
3058 case DAHDI_EVENT_ALARM:
3059 pri_event_alarm(pri, index, 0);
3061 case DAHDI_EVENT_NOALARM:
3062 pri_event_noalarm(pri, index, 0);
3068 #endif /* defined(HAVE_PRI) */
3070 #if defined(HAVE_PRI)
3071 static int my_pri_play_tone(void *pvt, enum sig_pri_tone tone)
3073 struct dahdi_pvt *p = pvt;
3075 return tone_zone_play_tone(p->subs[SUB_REAL].dfd, sig_pri_tone_to_dahditone(tone));
3077 #endif /* defined(HAVE_PRI) */
3079 #if defined(HAVE_PRI) || defined(HAVE_SS7)
3082 * \brief Set the caller id information.
3085 * \param pvt DAHDI private structure
3086 * \param caller Caller-id information to set.
3090 static void my_set_callerid(void *pvt, const struct ast_party_caller *caller)
3092 struct dahdi_pvt *p = pvt;
3094 ast_copy_string(p->cid_num,
3095 S_COR(caller->id.number.valid, caller->id.number.str, ""),
3096 sizeof(p->cid_num));
3097 ast_copy_string(p->cid_name,
3098 S_COR(caller->id.name.valid, caller->id.name.str, ""),
3099 sizeof(p->cid_name));
3100 ast_copy_string(p->cid_subaddr,
3101 S_COR(caller->id.subaddress.valid, caller->id.subaddress.str, ""),
3102 sizeof(p->cid_subaddr));
3103 p->cid_ton = caller->id.number.plan;
3104 p->callingpres = ast_party_id_presentation(&caller->id);
3105 if (caller->id.tag) {
3106 ast_copy_string(p->cid_tag, caller->id.tag, sizeof(p->cid_tag));
3108 ast_copy_string(p->cid_ani,
3109 S_COR(caller->ani.number.valid, caller->ani.number.str, ""),
3110 sizeof(p->cid_ani));
3111 p->cid_ani2 = caller->ani2;
3113 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
3115 #if defined(HAVE_PRI) || defined(HAVE_SS7)
3118 * \brief Set the Dialed Number Identifier.
3121 * \param pvt DAHDI private structure
3122 * \param dnid Dialed Number Identifier string.
3126 static void my_set_dnid(void *pvt, const char *dnid)
3128 struct dahdi_pvt *p = pvt;
3130 ast_copy_string(p->dnid, dnid, sizeof(p->dnid));
3132 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
3134 #if defined(HAVE_PRI)
3137 * \brief Set the Redirecting Directory Number Information Service (RDNIS).
3140 * \param pvt DAHDI private structure
3141 * \param rdnis Redirecting Directory Number Information Service (RDNIS) string.
3145 static void my_set_rdnis(void *pvt, const char *rdnis)
3147 struct dahdi_pvt *p = pvt;
3149 ast_copy_string(p->rdnis, rdnis, sizeof(p->rdnis));
3151 #endif /* defined(HAVE_PRI) */
3153 #if defined(HAVE_PRI)
3156 * \brief Make a dialstring for native ISDN CC to recall properly.
3159 * \param priv Channel private control structure.
3160 * \param buf Where to put the modified dialstring.
3161 * \param buf_size Size of modified dialstring buffer.
3164 * original dialstring:
3165 * DAHDI/[i<span>-](g|G|r|R)<group#(0-63)>[c|r<cadance#>|d][/extension[/options]]
3167 * The modified dialstring will have prefixed the channel-group section
3168 * with the ISDN channel restriction.
3171 * DAHDI/i<span>-(g|G|r|R)<group#(0-63)>[c|r<cadance#>|d][/extension[/options]]
3173 * The routine will check to see if the ISDN channel restriction is already
3174 * in the original dialstring.
3178 static void my_pri_make_cc_dialstring(void *priv, char *buf, size_t buf_size)
3181 struct dahdi_pvt *pvt;
3182 AST_DECLARE_APP_ARGS(args,
3183 AST_APP_ARG(tech); /* channel technology token */
3184 AST_APP_ARG(group); /* channel/group token */
3185 //AST_APP_ARG(ext); /* extension token */
3186 //AST_APP_ARG(opts); /* options token */
3187 //AST_APP_ARG(other); /* Any remining unused arguments */
3191 dial = ast_strdupa(pvt->dialstring);
3192 AST_NONSTANDARD_APP_ARGS(args, dial, '/');
3194 ast_copy_string(buf, pvt->dialstring, buf_size);
3198 /* Append the ISDN span channel restriction to the dialstring. */
3199 snprintf(buf, buf_size, "%s/i%d-", args.tech, pvt->pri->span);
3202 if (isdigit(args.group[0]) || args.group[0] == 'i' || strchr(args.group, '!')) {
3203 /* The ISDN span channel restriction is not needed or already
3204 * in the dialstring. */
3205 ast_copy_string(buf, pvt->dialstring, buf_size);
3208 /* Insert the ISDN span channel restriction into the dialstring. */
3209 snprintf(buf, buf_size, "%s/i%d-%s", args.tech, pvt->pri->span, args.group);
3211 #endif /* defined(HAVE_PRI) */
3213 #if defined(HAVE_PRI)
3216 * \brief Reevaluate the PRI span device state.