2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2008, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief DAHDI for Pseudo TDM
23 * \author Mark Spencer <markster@digium.com>
25 * Connects to the DAHDI telephony library as well as
26 * libpri. Libpri is optional and needed only if you are
27 * going to use ISDN connections.
29 * You need to install libraries before you attempt to compile
30 * and install the DAHDI channel.
33 * \arg \ref Config_dahdi
35 * \ingroup channel_drivers
37 * \todo Deprecate the "musiconhold" configuration option post 1.4
41 <depend>res_smdi</depend>
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 CIDCW_EXPIRE_SAMPLES ( (500 * 8) / READ_SIZE) /*!< 500 ms */
498 #define MIN_MS_SINCE_FLASH ( (2000) ) /*!< 2000 ms */
499 #define DEFAULT_RINGT ( (8000 * 8) / READ_SIZE) /*!< 8,000 ms */
504 * \brief Configured ring timeout base.
505 * \note Value computed from "ringtimeout" read in from chan_dahdi.conf if it exists.
507 static int ringt_base = DEFAULT_RINGT;
509 #if defined(HAVE_SS7)
512 struct sig_ss7_linkset ss7;
515 static struct dahdi_ss7 linksets[NUM_SPANS];
517 static int cur_ss7type = -1;
518 static int cur_linkset = -1;
519 static int cur_pointcode = -1;
520 static int cur_cicbeginswith = -1;
521 static int cur_adjpointcode = -1;
522 static int cur_networkindicator = -1;
523 static int cur_defaultdpc = -1;
524 #endif /* defined(HAVE_SS7) */
528 pthread_t r2master; /*!< Thread of master */
529 openr2_context_t *protocol_context; /*!< OpenR2 context handle */
530 struct dahdi_pvt *pvts[SIG_MFCR2_MAX_CHANNELS]; /*!< Member channel pvt structs */
531 int numchans; /*!< Number of channels in this R2 block */
532 int monitored_count; /*!< Number of channels being monitored */
535 struct dahdi_mfcr2_conf {
536 openr2_variant_t variant;
538 int metering_pulse_timeout;
541 signed int get_ani_first:2;
542 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
543 signed int skip_category_request:2;
545 unsigned int call_files:1;
546 unsigned int allow_collect_calls:1;
547 unsigned int charge_calls:1;
548 unsigned int accept_on_offer:1;
549 unsigned int forced_release:1;
550 unsigned int double_answer:1;
551 signed int immediate_accept:2;
552 char logdir[OR2_MAX_PATH];
553 char r2proto_file[OR2_MAX_PATH];
554 openr2_log_level_t loglevel;
555 openr2_calling_party_category_t category;
558 /* malloc'd array of malloc'd r2links */
559 static struct dahdi_mfcr2 **r2links;
560 /* how many r2links have been malloc'd */
561 static int r2links_count = 0;
563 #endif /* HAVE_OPENR2 */
568 int dchannels[SIG_PRI_NUM_DCHANS]; /*!< What channel are the dchannels on */
569 int mastertrunkgroup; /*!< What trunk group is our master */
570 int prilogicalspan; /*!< Logical span number within trunk group */
571 struct sig_pri_pri pri;
574 static struct dahdi_pri pris[NUM_SPANS];
576 #if defined(HAVE_PRI_CCSS)
577 /*! DAHDI PRI CCSS agent and monitor type name. */
578 static const char dahdi_pri_cc_type[] = "DAHDI/PRI";
579 #endif /* defined(HAVE_PRI_CCSS) */
582 /*! Shut up the compiler */
586 #define SUB_REAL 0 /*!< Active call */
587 #define SUB_CALLWAIT 1 /*!< Call-Waiting call on hold */
588 #define SUB_THREEWAY 2 /*!< Three-way call */
590 /* Polarity states */
591 #define POLARITY_IDLE 0
592 #define POLARITY_REV 1
595 struct distRingData {
599 struct ringContextData {
600 char contextData[AST_MAX_CONTEXT];
602 struct dahdi_distRings {
603 struct distRingData ringnum[3];
604 struct ringContextData ringContext[3];
607 static const char * const subnames[] = {
613 struct dahdi_subchannel {
615 struct ast_channel *owner;
617 short buffer[AST_FRIENDLY_OFFSET/2 + READ_SIZE];
618 struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */
619 unsigned int needringing:1;
620 unsigned int needbusy:1;
621 unsigned int needcongestion:1;
622 unsigned int needanswer:1;
623 unsigned int needflash:1;
624 unsigned int needhold:1;
625 unsigned int needunhold:1;
626 unsigned int linear:1;
627 unsigned int inthreeway:1;
628 struct dahdi_confinfo curconf;
631 #define CONF_USER_REAL (1 << 0)
632 #define CONF_USER_THIRDCALL (1 << 1)
636 /* States for sending MWI message
637 * First three states are required for send Ring Pulse Alert Signal
649 struct mwisend_info {
650 struct timeval pause;
651 mwisend_states mwisend_current;
654 /*! Specify the lists dahdi_pvt can be put in. */
656 DAHDI_IFLIST_NONE, /*!< The dahdi_pvt is not in any list. */
657 DAHDI_IFLIST_MAIN, /*!< The dahdi_pvt is in the main interface list */
658 #if defined(HAVE_PRI)
659 DAHDI_IFLIST_NO_B_CHAN, /*!< The dahdi_pvt is in a no B channel interface list */
660 #endif /* defined(HAVE_PRI) */
664 ast_mutex_t lock; /*!< Channel private lock. */
665 struct callerid_state *cs;
666 struct ast_channel *owner; /*!< Our current active owner (if applicable) */
667 /*!< Up to three channels can be associated with this call */
669 struct dahdi_subchannel sub_unused; /*!< Just a safety precaution */
670 struct dahdi_subchannel subs[3]; /*!< Sub-channels */
671 struct dahdi_confinfo saveconf; /*!< Saved conference info */
673 struct dahdi_pvt *slaves[MAX_SLAVES]; /*!< Slave to us (follows our conferencing) */
674 struct dahdi_pvt *master; /*!< Master to us (we follow their conferencing) */
675 int inconference; /*!< If our real should be in the conference */
677 int bufsize; /*!< Size of the buffers */
678 int buf_no; /*!< Number of buffers */
679 int buf_policy; /*!< Buffer policy */
680 int faxbuf_no; /*!< Number of Fax buffers */
681 int faxbuf_policy; /*!< Fax buffer policy */
682 int sig; /*!< Signalling style */
684 * \brief Nonzero if the signaling type is sent over a radio.
685 * \note Set to a couple of nonzero values but it is only tested like a boolean.
688 int outsigmod; /*!< Outbound Signalling style (modifier) */
689 int oprmode; /*!< "Operator Services" mode */
690 struct dahdi_pvt *oprpeer; /*!< "Operator Services" peer tech_pvt ptr */
691 /*! \brief Amount of gain to increase during caller id */
693 /*! \brief Rx gain set by chan_dahdi.conf */
695 /*! \brief Tx gain set by chan_dahdi.conf */
698 float txdrc; /*!< Dynamic Range Compression factor. a number between 1 and 6ish */
701 int tonezone; /*!< tone zone for this chan, or -1 for default */
702 enum DAHDI_IFLIST which_iflist; /*!< Which interface list is this structure listed? */
703 struct dahdi_pvt *next; /*!< Next channel in list */
704 struct dahdi_pvt *prev; /*!< Prev channel in list */
709 * \brief TRUE if ADSI (Analog Display Services Interface) available
710 * \note Set from the "adsi" value read in from chan_dahdi.conf
714 * \brief TRUE if we can use a polarity reversal to mark when an outgoing
715 * call is answered by the remote party.
716 * \note Set from the "answeronpolarityswitch" value read in from chan_dahdi.conf
718 unsigned int answeronpolarityswitch:1;
720 * \brief TRUE if busy detection is enabled.
721 * (Listens for the beep-beep busy pattern.)
722 * \note Set from the "busydetect" value read in from chan_dahdi.conf
724 unsigned int busydetect:1;
726 * \brief TRUE if call return is enabled.
727 * (*69, if your dialplan doesn't catch this first)
728 * \note Set from the "callreturn" value read in from chan_dahdi.conf
730 unsigned int callreturn:1;
732 * \brief TRUE if busy extensions will hear the call-waiting tone
733 * and can use hook-flash to switch between callers.
734 * \note Can be disabled by dialing *70.
735 * \note Initialized with the "callwaiting" value read in from chan_dahdi.conf
737 unsigned int callwaiting:1;
739 * \brief TRUE if send caller ID for Call Waiting
740 * \note Set from the "callwaitingcallerid" value read in from chan_dahdi.conf
742 unsigned int callwaitingcallerid:1;
744 * \brief TRUE if support for call forwarding enabled.
745 * Dial *72 to enable call forwarding.
746 * Dial *73 to disable call forwarding.
747 * \note Set from the "cancallforward" value read in from chan_dahdi.conf
749 unsigned int cancallforward:1;
751 * \brief TRUE if support for call parking is enabled.
752 * \note Set from the "canpark" value read in from chan_dahdi.conf
754 unsigned int canpark:1;
755 /*! \brief TRUE if to wait for a DTMF digit to confirm answer */
756 unsigned int confirmanswer:1;
758 * \brief TRUE if the channel is to be destroyed on hangup.
759 * (Used by pseudo channels.)
761 unsigned int destroy:1;
762 unsigned int didtdd:1; /*!< flag to say its done it once */
763 /*! \brief TRUE if analog type line dialed no digits in Dial() */
764 unsigned int dialednone:1;
766 * \brief TRUE if in the process of dialing digits or sending something.
767 * \note This is used as a receive squelch for ISDN until connected.
769 unsigned int dialing:1;
770 /*! \brief TRUE if the transfer capability of the call is digital. */
771 unsigned int digital:1;
772 /*! \brief TRUE if Do-Not-Disturb is enabled, present only for non sig_analog */
774 /*! \brief XXX BOOLEAN Purpose??? */
775 unsigned int echobreak:1;
777 * \brief TRUE if echo cancellation enabled when bridged.
778 * \note Initialized with the "echocancelwhenbridged" value read in from chan_dahdi.conf
779 * \note Disabled if the echo canceller is not setup.
781 unsigned int echocanbridged:1;
782 /*! \brief TRUE if echo cancellation is turned on. */
783 unsigned int echocanon:1;
784 /*! \brief TRUE if a fax tone has already been handled. */
785 unsigned int faxhandled:1;
786 /*! TRUE if dynamic faxbuffers are configured for use, default is OFF */
787 unsigned int usefaxbuffers:1;
788 /*! TRUE while buffer configuration override is in use */
789 unsigned int bufferoverrideinuse:1;
790 /*! \brief TRUE if over a radio and dahdi_read() has been called. */
791 unsigned int firstradio:1;
793 * \brief TRUE if the call will be considered "hung up" on a polarity reversal.
794 * \note Set from the "hanguponpolarityswitch" value read in from chan_dahdi.conf
796 unsigned int hanguponpolarityswitch:1;
797 /*! \brief TRUE if DTMF detection needs to be done by hardware. */
798 unsigned int hardwaredtmf:1;
800 * \brief TRUE if the outgoing caller ID is blocked/hidden.
801 * \note Caller ID can be disabled by dialing *67.
802 * \note Caller ID can be enabled by dialing *82.
803 * \note Initialized with the "hidecallerid" value read in from chan_dahdi.conf
805 unsigned int hidecallerid:1;
807 * \brief TRUE if hide just the name not the number for legacy PBX use.
808 * \note Only applies to PRI channels.
809 * \note Set from the "hidecalleridname" value read in from chan_dahdi.conf
811 unsigned int hidecalleridname:1;
812 /*! \brief TRUE if DTMF detection is disabled. */
813 unsigned int ignoredtmf:1;
815 * \brief TRUE if the channel should be answered immediately
816 * without attempting to gather any digits.
817 * \note Set from the "immediate" value read in from chan_dahdi.conf
819 unsigned int immediate:1;
820 /*! \brief TRUE if in an alarm condition. */
821 unsigned int inalarm:1;
822 /*! \brief TRUE if TDD in MATE mode */
824 /*! \brief TRUE if we originated the call leg. */
825 unsigned int outgoing:1;
826 /* unsigned int overlapdial:1; unused and potentially confusing */
828 * \brief TRUE if busy extensions will hear the call-waiting tone
829 * and can use hook-flash to switch between callers.
830 * \note Set from the "callwaiting" value read in from chan_dahdi.conf
832 unsigned int permcallwaiting:1;
834 * \brief TRUE if the outgoing caller ID is blocked/restricted/hidden.
835 * \note Set from the "hidecallerid" value read in from chan_dahdi.conf
837 unsigned int permhidecallerid:1;
839 * \brief TRUE if PRI congestion/busy indications are sent out-of-band.
840 * \note Set from the "priindication" value read in from chan_dahdi.conf
842 unsigned int priindication_oob:1;
844 * \brief TRUE if PRI B channels are always exclusively selected.
845 * \note Set from the "priexclusive" value read in from chan_dahdi.conf
847 unsigned int priexclusive:1;
849 * \brief TRUE if we will pulse dial.
850 * \note Set from the "pulsedial" value read in from chan_dahdi.conf
852 unsigned int pulse:1;
853 /*! \brief TRUE if a pulsed digit was detected. (Pulse dial phone detected) */
854 unsigned int pulsedial:1;
855 unsigned int restartpending:1; /*!< flag to ensure counted only once for restart */
857 * \brief TRUE if caller ID is restricted.
858 * \note Set but not used. Should be deleted. Redundant with permhidecallerid.
859 * \note Set from the "restrictcid" value read in from chan_dahdi.conf
861 unsigned int restrictcid:1;
863 * \brief TRUE if three way calling is enabled
864 * \note Set from the "threewaycalling" value read in from chan_dahdi.conf
866 unsigned int threewaycalling:1;
868 * \brief TRUE if call transfer is enabled
869 * \note For FXS ports (either direct analog or over T1/E1):
870 * Support flash-hook call transfer
871 * \note For digital ports using ISDN PRI protocols:
872 * Support switch-side transfer (called 2BCT, RLT or other names)
873 * \note Set from the "transfer" value read in from chan_dahdi.conf
875 unsigned int transfer:1;
877 * \brief TRUE if caller ID is used on this channel.
878 * \note PRI and SS7 spans will save caller ID from the networking peer.
879 * \note FXS ports will generate the caller ID spill.
880 * \note FXO ports will listen for the caller ID spill.
881 * \note Set from the "usecallerid" value read in from chan_dahdi.conf
883 unsigned int use_callerid:1;
885 * \brief TRUE if we will use the calling presentation setting
886 * from the Asterisk channel for outgoing calls.
887 * \note Only applies to PRI and SS7 channels.
888 * \note Set from the "usecallingpres" value read in from chan_dahdi.conf
890 unsigned int use_callingpres:1;
892 * \brief TRUE if distinctive rings are to be detected.
893 * \note For FXO lines
894 * \note Set indirectly from the "usedistinctiveringdetection" value read in from chan_dahdi.conf
896 unsigned int usedistinctiveringdetection:1;
898 * \brief TRUE if we should use the callerid from incoming call on dahdi transfer.
899 * \note Set from the "useincomingcalleridondahditransfer" value read in from chan_dahdi.conf
901 unsigned int dahditrcallerid:1;
903 * \brief TRUE if allowed to flash-transfer to busy channels.
904 * \note Set from the "transfertobusy" value read in from chan_dahdi.conf
906 unsigned int transfertobusy:1;
908 * \brief TRUE if the FXO port monitors for neon type MWI indications from the other end.
909 * \note Set if the "mwimonitor" value read in contains "neon" from chan_dahdi.conf
911 unsigned int mwimonitor_neon:1;
913 * \brief TRUE if the FXO port monitors for fsk type MWI indications from the other end.
914 * \note Set if the "mwimonitor" value read in contains "fsk" from chan_dahdi.conf
916 unsigned int mwimonitor_fsk:1;
918 * \brief TRUE if the FXO port monitors for rpas precursor to fsk MWI indications from the other end.
919 * \note RPAS - Ring Pulse Alert Signal
920 * \note Set if the "mwimonitor" value read in contains "rpas" from chan_dahdi.conf
922 unsigned int mwimonitor_rpas:1;
923 /*! \brief TRUE if an MWI monitor thread is currently active */
924 unsigned int mwimonitoractive:1;
925 /*! \brief TRUE if a MWI message sending thread is active */
926 unsigned int mwisendactive:1;
928 * \brief TRUE if channel is out of reset and ready
929 * \note Set but not used.
931 unsigned int inservice:1;
933 * \brief TRUE if the channel is locally blocked.
934 * \note Applies to SS7 and MFCR2 channels.
936 unsigned int locallyblocked:1;
938 * \brief TRUE if the channel is remotely blocked.
939 * \note Applies to SS7 and MFCR2 channels.
941 unsigned int remotelyblocked:1;
943 * \brief TRUE if the channel alarms will be managed also as Span ones
944 * \note Applies to all channels
946 unsigned int manages_span_alarms:1;
948 #if defined(HAVE_PRI)
949 struct sig_pri_pri *pri;
953 * \brief TRUE if SMDI (Simplified Message Desk Interface) is enabled
954 * \note Set from the "usesmdi" value read in from chan_dahdi.conf
956 unsigned int use_smdi:1;
957 struct mwisend_info mwisend_data;
958 /*! \brief The serial port to listen for SMDI data on */
959 struct ast_smdi_interface *smdi_iface;
961 /*! \brief Distinctive Ring data */
962 struct dahdi_distRings drings;
965 * \brief The configured context for incoming calls.
966 * \note The "context" string read in from chan_dahdi.conf
968 char context[AST_MAX_CONTEXT];
970 * \brief Saved context string.
972 char defcontext[AST_MAX_CONTEXT];
973 /*! \brief Extension to use in the dialplan. */
974 char exten[AST_MAX_EXTENSION];
976 * \brief Language configured for calls.
977 * \note The "language" string read in from chan_dahdi.conf
979 char language[MAX_LANGUAGE];
981 * \brief The configured music-on-hold class to use for calls.
982 * \note The "musicclass" or "mohinterpret" or "musiconhold" string read in from chan_dahdi.conf
984 char mohinterpret[MAX_MUSICCLASS];
986 * \brief Suggested music-on-hold class for peer channel to use for calls.
987 * \note The "mohsuggest" string read in from chan_dahdi.conf
989 char mohsuggest[MAX_MUSICCLASS];
990 char parkinglot[AST_MAX_EXTENSION]; /*!< Parking lot for this channel */
991 #if defined(HAVE_PRI) || defined(HAVE_SS7)
992 /*! \brief Automatic Number Identification number (Alternate PRI caller ID number) */
993 char cid_ani[AST_MAX_EXTENSION];
994 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
995 /*! \brief Automatic Number Identification code from PRI */
997 /*! \brief Caller ID number from an incoming call. */
998 char cid_num[AST_MAX_EXTENSION];
1000 * \brief Caller ID tag from incoming call
1001 * \note the "cid_tag" string read in from chan_dahdi.conf
1003 char cid_tag[AST_MAX_EXTENSION];
1004 /*! \brief Caller ID Q.931 TON/NPI field values. Set by PRI. Zero otherwise. */
1006 /*! \brief Caller ID name from an incoming call. */
1007 char cid_name[AST_MAX_EXTENSION];
1008 /*! \brief Caller ID subaddress from an incoming call. */
1009 char cid_subaddr[AST_MAX_EXTENSION];
1010 char *origcid_num; /*!< malloced original callerid */
1011 char *origcid_name; /*!< malloced original callerid */
1012 /*! \brief Call waiting number. */
1013 char callwait_num[AST_MAX_EXTENSION];
1014 /*! \brief Call waiting name. */
1015 char callwait_name[AST_MAX_EXTENSION];
1016 /*! \brief Redirecting Directory Number Information Service (RDNIS) number */
1017 char rdnis[AST_MAX_EXTENSION];
1018 /*! \brief Dialed Number Identifier */
1019 char dnid[AST_MAX_EXTENSION];
1021 * \brief Bitmapped groups this belongs to.
1022 * \note The "group" bitmapped group string read in from chan_dahdi.conf
1025 /*! \brief Default call PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW. */
1027 /*! \brief Active PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW */
1029 int confno; /*!< Our conference */
1030 int confusers; /*!< Who is using our conference */
1031 int propconfno; /*!< Propagated conference number */
1033 * \brief Bitmapped call groups this belongs to.
1034 * \note The "callgroup" bitmapped group string read in from chan_dahdi.conf
1036 ast_group_t callgroup;
1038 * \brief Bitmapped pickup groups this belongs to.
1039 * \note The "pickupgroup" bitmapped group string read in from chan_dahdi.conf
1041 ast_group_t pickupgroup;
1043 * \brief Channel variable list with associated values to set when a channel is created.
1044 * \note The "setvar" strings read in from chan_dahdi.conf
1046 struct ast_variable *vars;
1047 int channel; /*!< Channel Number */
1048 int span; /*!< Span number */
1049 time_t guardtime; /*!< Must wait this much time before using for new call */
1050 int cid_signalling; /*!< CID signalling type bell202 or v23 */
1051 int cid_start; /*!< CID start indicator, polarity or ring or DTMF without warning event */
1052 int dtmfcid_holdoff_state; /*!< State indicator that allows for line to settle before checking for dtmf energy */
1053 struct timeval dtmfcid_delay; /*!< Time value used for allow line to settle */
1054 int callingpres; /*!< The value of calling presentation that we're going to use when placing a PRI call */
1055 int callwaitingrepeat; /*!< How many samples to wait before repeating call waiting */
1056 int cidcwexpire; /*!< When to expire our muting for CID/CW */
1057 /*! \brief Analog caller ID waveform sample buffer */
1058 unsigned char *cidspill;
1059 /*! \brief Position in the cidspill buffer to send out next. */
1061 /*! \brief Length of the cidspill buffer containing samples. */
1063 /*! \brief Ring timeout timer?? */
1066 * \brief Ring timeout base.
1067 * \note Value computed indirectly from "ringtimeout" read in from chan_dahdi.conf
1071 * \brief Number of most significant digits/characters to strip from the dialed number.
1072 * \note Feature is deprecated. Use dialplan logic.
1073 * \note The characters are stripped before the PRI TON/NPI prefix
1074 * characters are processed.
1077 /*! \brief BOOLEAN. XXX Meaning what?? */
1079 /*! \brief Number of call waiting rings. */
1081 /*! \brief Echo cancel parameters. */
1083 struct dahdi_echocanparams head;
1084 struct dahdi_echocanparam params[DAHDI_MAX_ECHOCANPARAMS];
1087 * \brief Echo training time. 0 = disabled
1088 * \note Set from the "echotraining" value read in from chan_dahdi.conf
1091 /*! \brief Filled with 'w'. XXX Purpose?? */
1094 * \brief Number of times to see "busy" tone before hanging up.
1095 * \note Set from the "busycount" value read in from chan_dahdi.conf
1099 * \brief Length of "busy" tone on time.
1100 * \note Set from the "busypattern" value read in from chan_dahdi.conf
1102 int busy_tonelength;
1104 * \brief Length of "busy" tone off time.
1105 * \note Set from the "busypattern" value read in from chan_dahdi.conf
1107 int busy_quietlength;
1109 * \brief Bitmapped call progress detection flags. CALLPROGRESS_xxx values.
1110 * \note Bits set from the "callprogress" and "faxdetect" values read in from chan_dahdi.conf
1114 * \brief Number of milliseconds to wait for dialtone.
1115 * \note Set from the "waitfordialtone" value read in from chan_dahdi.conf
1117 int waitfordialtone;
1118 struct timeval waitingfordt; /*!< Time we started waiting for dialtone */
1119 struct timeval flashtime; /*!< Last flash-hook time */
1120 /*! \brief Opaque DSP configuration structure. */
1121 struct ast_dsp *dsp;
1122 /*! \brief DAHDI dial operation command struct for ioctl() call. */
1123 struct dahdi_dialoperation dop;
1124 int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
1125 /*! \brief Second part of SIG_FEATDMF_TA wink operation. */
1127 char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
1128 int amaflags; /*!< AMA Flags */
1129 struct tdd_state *tdd; /*!< TDD flag */
1130 /*! \brief Accumulated call forwarding number. */
1131 char call_forward[AST_MAX_EXTENSION];
1133 * \brief Voice mailbox location.
1134 * \note Set from the "mailbox" string read in from chan_dahdi.conf
1136 char mailbox[AST_MAX_EXTENSION];
1137 /*! \brief Opaque event subscription parameters for message waiting indication support. */
1138 struct ast_event_sub *mwi_event_sub;
1139 /*! \brief Delayed dialing for E911. Overlap digits for ISDN. */
1141 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
1142 struct dahdi_vmwi_info mwisend_setting; /*!< Which VMWI methods to use */
1143 unsigned int mwisend_fsk: 1; /*! Variable for enabling FSK MWI handling in chan_dahdi */
1144 unsigned int mwisend_rpas:1; /*! Variable for enabling Ring Pulse Alert before MWI FSK Spill */
1146 int distinctivering; /*!< Which distinctivering to use */
1147 int dtmfrelax; /*!< whether to run in relaxed DTMF mode */
1148 /*! \brief Holding place for event injected from outside normal operation. */
1151 * \brief Minimal time period (ms) between the answer polarity
1152 * switch and hangup polarity switch.
1154 int polarityonanswerdelay;
1155 /*! \brief Start delay time if polarityonanswerdelay is nonzero. */
1156 struct timeval polaritydelaytv;
1158 * \brief Send caller ID on FXS after this many rings. Set to 1 for US.
1159 * \note Set from the "sendcalleridafter" value read in from chan_dahdi.conf
1161 int sendcalleridafter;
1162 /*! \brief Current line interface polarity. POLARITY_IDLE, POLARITY_REV */
1164 /*! \brief DSP feature flags: DSP_FEATURE_xxx */
1166 #if defined(HAVE_SS7)
1167 /*! \brief SS7 control parameters */
1168 struct sig_ss7_linkset *ss7;
1169 #endif /* defined(HAVE_SS7) */
1171 struct dahdi_mfcr2 *mfcr2;
1172 openr2_chan_t *r2chan;
1173 openr2_calling_party_category_t mfcr2_recvd_category;
1174 openr2_calling_party_category_t mfcr2_category;
1175 int mfcr2_dnis_index;
1176 int mfcr2_ani_index;
1178 int mfcr2_answer_pending:1;
1179 int mfcr2_charge_calls:1;
1180 int mfcr2_allow_collect_calls:1;
1181 int mfcr2_forced_release:1;
1182 int mfcr2_dnis_matched:1;
1183 int mfcr2_call_accepted:1;
1184 int mfcr2_accept_on_offer:1;
1186 /*! \brief DTMF digit in progress. 0 when no digit in progress. */
1188 /*! \brief TRUE if confrence is muted. */
1191 struct ast_cc_config_params *cc_params;
1192 /* DAHDI channel names may differ greatly from the
1193 * string that was provided to an app such as Dial. We
1194 * need to save the original string passed to dahdi_request
1195 * for call completion purposes. This way, we can replicate
1196 * the original dialed string later.
1198 char dialstring[AST_CHANNEL_NAME];
1201 #define DATA_EXPORT_DAHDI_PVT(MEMBER) \
1202 MEMBER(dahdi_pvt, cid_rxgain, AST_DATA_DOUBLE) \
1203 MEMBER(dahdi_pvt, rxgain, AST_DATA_DOUBLE) \
1204 MEMBER(dahdi_pvt, txgain, AST_DATA_DOUBLE) \
1205 MEMBER(dahdi_pvt, txdrc, AST_DATA_DOUBLE) \
1206 MEMBER(dahdi_pvt, rxdrc, AST_DATA_DOUBLE) \
1207 MEMBER(dahdi_pvt, adsi, AST_DATA_BOOLEAN) \
1208 MEMBER(dahdi_pvt, answeronpolarityswitch, AST_DATA_BOOLEAN) \
1209 MEMBER(dahdi_pvt, busydetect, AST_DATA_BOOLEAN) \
1210 MEMBER(dahdi_pvt, callreturn, AST_DATA_BOOLEAN) \
1211 MEMBER(dahdi_pvt, callwaiting, AST_DATA_BOOLEAN) \
1212 MEMBER(dahdi_pvt, callwaitingcallerid, AST_DATA_BOOLEAN) \
1213 MEMBER(dahdi_pvt, cancallforward, AST_DATA_BOOLEAN) \
1214 MEMBER(dahdi_pvt, canpark, AST_DATA_BOOLEAN) \
1215 MEMBER(dahdi_pvt, confirmanswer, AST_DATA_BOOLEAN) \
1216 MEMBER(dahdi_pvt, destroy, AST_DATA_BOOLEAN) \
1217 MEMBER(dahdi_pvt, didtdd, AST_DATA_BOOLEAN) \
1218 MEMBER(dahdi_pvt, dialednone, AST_DATA_BOOLEAN) \
1219 MEMBER(dahdi_pvt, dialing, AST_DATA_BOOLEAN) \
1220 MEMBER(dahdi_pvt, digital, AST_DATA_BOOLEAN) \
1221 MEMBER(dahdi_pvt, dnd, AST_DATA_BOOLEAN) \
1222 MEMBER(dahdi_pvt, echobreak, AST_DATA_BOOLEAN) \
1223 MEMBER(dahdi_pvt, echocanbridged, AST_DATA_BOOLEAN) \
1224 MEMBER(dahdi_pvt, echocanon, AST_DATA_BOOLEAN) \
1225 MEMBER(dahdi_pvt, faxhandled, AST_DATA_BOOLEAN) \
1226 MEMBER(dahdi_pvt, usefaxbuffers, AST_DATA_BOOLEAN) \
1227 MEMBER(dahdi_pvt, bufferoverrideinuse, AST_DATA_BOOLEAN) \
1228 MEMBER(dahdi_pvt, firstradio, AST_DATA_BOOLEAN) \
1229 MEMBER(dahdi_pvt, hanguponpolarityswitch, AST_DATA_BOOLEAN) \
1230 MEMBER(dahdi_pvt, hardwaredtmf, AST_DATA_BOOLEAN) \
1231 MEMBER(dahdi_pvt, hidecallerid, AST_DATA_BOOLEAN) \
1232 MEMBER(dahdi_pvt, hidecalleridname, AST_DATA_BOOLEAN) \
1233 MEMBER(dahdi_pvt, ignoredtmf, AST_DATA_BOOLEAN) \
1234 MEMBER(dahdi_pvt, immediate, AST_DATA_BOOLEAN) \
1235 MEMBER(dahdi_pvt, inalarm, AST_DATA_BOOLEAN) \
1236 MEMBER(dahdi_pvt, mate, AST_DATA_BOOLEAN) \
1237 MEMBER(dahdi_pvt, outgoing, AST_DATA_BOOLEAN) \
1238 MEMBER(dahdi_pvt, permcallwaiting, AST_DATA_BOOLEAN) \
1239 MEMBER(dahdi_pvt, priindication_oob, AST_DATA_BOOLEAN) \
1240 MEMBER(dahdi_pvt, priexclusive, AST_DATA_BOOLEAN) \
1241 MEMBER(dahdi_pvt, pulse, AST_DATA_BOOLEAN) \
1242 MEMBER(dahdi_pvt, pulsedial, AST_DATA_BOOLEAN) \
1243 MEMBER(dahdi_pvt, restartpending, AST_DATA_BOOLEAN) \
1244 MEMBER(dahdi_pvt, restrictcid, AST_DATA_BOOLEAN) \
1245 MEMBER(dahdi_pvt, threewaycalling, AST_DATA_BOOLEAN) \
1246 MEMBER(dahdi_pvt, transfer, AST_DATA_BOOLEAN) \
1247 MEMBER(dahdi_pvt, use_callerid, AST_DATA_BOOLEAN) \
1248 MEMBER(dahdi_pvt, use_callingpres, AST_DATA_BOOLEAN) \
1249 MEMBER(dahdi_pvt, usedistinctiveringdetection, AST_DATA_BOOLEAN) \
1250 MEMBER(dahdi_pvt, dahditrcallerid, AST_DATA_BOOLEAN) \
1251 MEMBER(dahdi_pvt, transfertobusy, AST_DATA_BOOLEAN) \
1252 MEMBER(dahdi_pvt, mwimonitor_neon, AST_DATA_BOOLEAN) \
1253 MEMBER(dahdi_pvt, mwimonitor_fsk, AST_DATA_BOOLEAN) \
1254 MEMBER(dahdi_pvt, mwimonitor_rpas, AST_DATA_BOOLEAN) \
1255 MEMBER(dahdi_pvt, mwimonitoractive, AST_DATA_BOOLEAN) \
1256 MEMBER(dahdi_pvt, mwisendactive, AST_DATA_BOOLEAN) \
1257 MEMBER(dahdi_pvt, inservice, AST_DATA_BOOLEAN) \
1258 MEMBER(dahdi_pvt, locallyblocked, AST_DATA_BOOLEAN) \
1259 MEMBER(dahdi_pvt, remotelyblocked, AST_DATA_BOOLEAN) \
1260 MEMBER(dahdi_pvt, manages_span_alarms, AST_DATA_BOOLEAN) \
1261 MEMBER(dahdi_pvt, use_smdi, AST_DATA_BOOLEAN) \
1262 MEMBER(dahdi_pvt, context, AST_DATA_STRING) \
1263 MEMBER(dahdi_pvt, defcontext, AST_DATA_STRING) \
1264 MEMBER(dahdi_pvt, exten, AST_DATA_STRING) \
1265 MEMBER(dahdi_pvt, language, AST_DATA_STRING) \
1266 MEMBER(dahdi_pvt, mohinterpret, AST_DATA_STRING) \
1267 MEMBER(dahdi_pvt, mohsuggest, AST_DATA_STRING) \
1268 MEMBER(dahdi_pvt, parkinglot, AST_DATA_STRING)
1270 AST_DATA_STRUCTURE(dahdi_pvt, DATA_EXPORT_DAHDI_PVT);
1272 static struct dahdi_pvt *iflist = NULL; /*!< Main interface list start */
1273 static struct dahdi_pvt *ifend = NULL; /*!< Main interface list end */
1275 #if defined(HAVE_PRI)
1276 static struct dahdi_parms_pseudo {
1277 int buf_no; /*!< Number of buffers */
1278 int buf_policy; /*!< Buffer policy */
1279 int faxbuf_no; /*!< Number of Fax buffers */
1280 int faxbuf_policy; /*!< Fax buffer policy */
1281 } dahdi_pseudo_parms;
1282 #endif /* defined(HAVE_PRI) */
1284 /*! \brief Channel configuration from chan_dahdi.conf .
1285 * This struct is used for parsing the [channels] section of chan_dahdi.conf.
1286 * Generally there is a field here for every possible configuration item.
1288 * The state of fields is saved along the parsing and whenever a 'channel'
1289 * statement is reached, the current dahdi_chan_conf is used to configure the
1290 * channel (struct dahdi_pvt)
1292 * \see dahdi_chan_init for the default values.
1294 struct dahdi_chan_conf {
1295 struct dahdi_pvt chan;
1297 struct dahdi_pri pri;
1300 #if defined(HAVE_SS7)
1301 struct dahdi_ss7 ss7;
1302 #endif /* defined(HAVE_SS7) */
1305 struct dahdi_mfcr2_conf mfcr2;
1307 struct dahdi_params timing;
1308 int is_sig_auto; /*!< Use channel signalling from DAHDI? */
1309 /*! Continue configuration even if a channel is not there. */
1310 int ignore_failed_channels;
1313 * \brief The serial port to listen for SMDI data on
1314 * \note Set from the "smdiport" string read in from chan_dahdi.conf
1316 char smdi_port[SMDI_MAX_FILENAME_LEN];
1319 /*! returns a new dahdi_chan_conf with default values (by-value) */
1320 static struct dahdi_chan_conf dahdi_chan_conf_default(void)
1322 /* recall that if a field is not included here it is initialized
1323 * to 0 or equivalent
1325 struct dahdi_chan_conf conf = {
1328 .nsf = PRI_NSF_NONE,
1329 .switchtype = PRI_SWITCH_NI2,
1330 .dialplan = PRI_UNKNOWN + 1,
1331 .localdialplan = PRI_NATIONAL_ISDN + 1,
1332 .nodetype = PRI_CPE,
1333 .qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL,
1335 #if defined(HAVE_PRI_CCSS)
1336 .cc_ptmp_recall_mode = 1,/* specificRecall */
1337 .cc_qsig_signaling_link_req = 1,/* retain */
1338 .cc_qsig_signaling_link_rsp = 1,/* retain */
1339 #endif /* defined(HAVE_PRI_CCSS) */
1344 .internationalprefix = "",
1345 .nationalprefix = "",
1347 .privateprefix = "",
1348 .unknownprefix = "",
1349 .resetinterval = -1,
1352 #if defined(HAVE_SS7)
1354 .called_nai = SS7_NAI_NATIONAL,
1355 .calling_nai = SS7_NAI_NATIONAL,
1356 .internationalprefix = "",
1357 .nationalprefix = "",
1358 .subscriberprefix = "",
1361 #endif /* defined(HAVE_SS7) */
1364 .variant = OR2_VAR_ITU,
1365 .mfback_timeout = -1,
1366 .metering_pulse_timeout = -1,
1369 .get_ani_first = -1,
1370 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
1371 .skip_category_request = -1,
1374 .allow_collect_calls = 0,
1376 .accept_on_offer = 1,
1377 .forced_release = 0,
1379 .immediate_accept = -1,
1382 .loglevel = OR2_LOG_ERROR | OR2_LOG_WARNING,
1383 .category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER
1387 .context = "default",
1391 .mohinterpret = "default",
1394 .transfertobusy = 1,
1396 .cid_signalling = CID_SIG_BELL,
1397 .cid_start = CID_START_RING,
1398 .dahditrcallerid = 0,
1407 .echocancel.head.tap_length = 1,
1415 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
1418 .polarityonanswerdelay = 600,
1420 .sendcalleridafter = DEFAULT_CIDRINGS,
1422 .buf_policy = DAHDI_POLICY_IMMEDIATE,
1425 .cc_params = ast_cc_config_params_init(),
1438 .smdi_port = "/dev/ttyS0",
1445 static struct ast_channel *dahdi_request(const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause);
1446 static int dahdi_digit_begin(struct ast_channel *ast, char digit);
1447 static int dahdi_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
1448 static int dahdi_sendtext(struct ast_channel *c, const char *text);
1449 static int dahdi_call(struct ast_channel *ast, char *rdest, int timeout);
1450 static int dahdi_hangup(struct ast_channel *ast);
1451 static int dahdi_answer(struct ast_channel *ast);
1452 static struct ast_frame *dahdi_read(struct ast_channel *ast);
1453 static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame);
1454 static struct ast_frame *dahdi_exception(struct ast_channel *ast);
1455 static int dahdi_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen);
1456 static int dahdi_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
1457 static int dahdi_setoption(struct ast_channel *chan, int option, void *data, int datalen);
1458 static int dahdi_queryoption(struct ast_channel *chan, int option, void *data, int *datalen);
1459 static int dahdi_func_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
1460 static int dahdi_func_write(struct ast_channel *chan, const char *function, char *data, const char *value);
1461 static int dahdi_devicestate(void *data);
1462 static int dahdi_cc_callback(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback);
1464 static const struct ast_channel_tech dahdi_tech = {
1466 .description = tdesc,
1467 .capabilities = AST_FORMAT_SLINEAR | AST_FORMAT_ULAW | AST_FORMAT_ALAW,
1468 .requester = dahdi_request,
1469 .send_digit_begin = dahdi_digit_begin,
1470 .send_digit_end = dahdi_digit_end,
1471 .send_text = dahdi_sendtext,
1473 .hangup = dahdi_hangup,
1474 .answer = dahdi_answer,
1476 .write = dahdi_write,
1477 .bridge = dahdi_bridge,
1478 .exception = dahdi_exception,
1479 .indicate = dahdi_indicate,
1480 .fixup = dahdi_fixup,
1481 .setoption = dahdi_setoption,
1482 .queryoption = dahdi_queryoption,
1483 .func_channel_read = dahdi_func_read,
1484 .func_channel_write = dahdi_func_write,
1485 .devicestate = dahdi_devicestate,
1486 .cc_callback = dahdi_cc_callback,
1489 #define GET_CHANNEL(p) ((p)->channel)
1491 #define SIG_PRI_LIB_HANDLE_CASES \
1498 * \brief Determine if sig_pri handles the signaling.
1501 * \param signaling Signaling to determine if is for sig_pri.
1503 * \return TRUE if the signaling is for sig_pri.
1505 static inline int dahdi_sig_pri_lib_handles(int signaling)
1509 switch (signaling) {
1510 case SIG_PRI_LIB_HANDLE_CASES:
1521 static enum analog_sigtype dahdisig_to_analogsig(int sig)
1525 return ANALOG_SIG_FXOLS;
1527 return ANALOG_SIG_FXOGS;
1529 return ANALOG_SIG_FXOKS;
1531 return ANALOG_SIG_FXSLS;
1533 return ANALOG_SIG_FXSGS;
1535 return ANALOG_SIG_FXSKS;
1537 return ANALOG_SIG_EMWINK;
1539 return ANALOG_SIG_EM;
1541 return ANALOG_SIG_EM_E1;
1543 return ANALOG_SIG_FEATD;
1545 return ANALOG_SIG_FEATDMF;
1549 return ANALOG_SIG_FGC_CAMA;
1550 case SIG_FGC_CAMAMF:
1551 return ANALOG_SIG_FGC_CAMAMF;
1553 return ANALOG_SIG_FEATB;
1555 return ANALOG_SIG_SFWINK;
1557 return ANALOG_SIG_SF;
1559 return ANALOG_SIG_SF_FEATD;
1560 case SIG_SF_FEATDMF:
1561 return ANALOG_SIG_SF_FEATDMF;
1562 case SIG_FEATDMF_TA:
1563 return ANALOG_SIG_FEATDMF_TA;
1565 return ANALOG_SIG_FEATB;
1572 static int analog_tone_to_dahditone(enum analog_tone tone)
1575 case ANALOG_TONE_RINGTONE:
1576 return DAHDI_TONE_RINGTONE;
1577 case ANALOG_TONE_STUTTER:
1578 return DAHDI_TONE_STUTTER;
1579 case ANALOG_TONE_CONGESTION:
1580 return DAHDI_TONE_CONGESTION;
1581 case ANALOG_TONE_DIALTONE:
1582 return DAHDI_TONE_DIALTONE;
1583 case ANALOG_TONE_DIALRECALL:
1584 return DAHDI_TONE_DIALRECALL;
1585 case ANALOG_TONE_INFO:
1586 return DAHDI_TONE_INFO;
1592 static int analogsub_to_dahdisub(enum analog_sub analogsub)
1596 switch (analogsub) {
1597 case ANALOG_SUB_REAL:
1600 case ANALOG_SUB_CALLWAIT:
1601 index = SUB_CALLWAIT;
1603 case ANALOG_SUB_THREEWAY:
1604 index = SUB_THREEWAY;
1607 ast_log(LOG_ERROR, "Unidentified sub!\n");
1614 static enum analog_event dahdievent_to_analogevent(int event);
1615 static int bump_gains(struct dahdi_pvt *p);
1616 static int dahdi_setlinear(int dfd, int linear);
1618 static int my_start_cid_detect(void *pvt, int cid_signalling)
1620 struct dahdi_pvt *p = pvt;
1621 int index = SUB_REAL;
1622 p->cs = callerid_new(cid_signalling);
1624 ast_log(LOG_ERROR, "Unable to alloc callerid\n");
1628 dahdi_setlinear(p->subs[index].dfd, 0);
1633 static int my_stop_cid_detect(void *pvt)
1635 struct dahdi_pvt *p = pvt;
1636 int index = SUB_REAL;
1638 callerid_free(p->cs);
1639 dahdi_setlinear(p->subs[index].dfd, p->subs[index].linear);
1643 static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_event *ev, size_t timeout)
1645 struct dahdi_pvt *p = pvt;
1646 struct analog_pvt *analog_p = p->sig_pvt;
1647 struct pollfd poller;
1649 int index = SUB_REAL;
1651 unsigned char buf[256];
1654 poller.fd = p->subs[SUB_REAL].dfd;
1655 poller.events = POLLPRI | POLLIN;
1658 res = poll(&poller, 1, timeout);
1660 if (poller.revents & POLLPRI) {
1661 *ev = dahdievent_to_analogevent(dahdi_get_event(p->subs[SUB_REAL].dfd));
1665 if (poller.revents & POLLIN) {
1667 /* Change API: remove cid_signalling from get_callerid, add a new start_cid_detect and stop_cid_detect function
1668 * to enable slin mode and allocate cid detector. get_callerid should be able to be called any number of times until
1669 * either a timeout occurs or CID is detected (returns 0). returning 1 should be event received, and -1 should be
1670 * a failure and die, and returning 2 means no event was received. */
1671 res = read(p->subs[index].dfd, buf, sizeof(buf));
1673 if (errno != ELAST) {
1674 ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
1675 callerid_free(p->cs);
1680 if (analog_p->ringt > 0) {
1681 if (!(--analog_p->ringt)) {
1682 /* only return if we timeout from a ring event */
1687 if (p->cid_signalling == CID_SIG_V23_JP) {
1688 res = callerid_feed_jp(p->cs, buf, res, AST_LAW(p));
1690 res = callerid_feed(p->cs, buf, res, AST_LAW(p));
1694 * The previous diagnostic message output likely
1695 * explains why it failed.
1697 ast_log(LOG_WARNING, "Failed to decode CallerID\n");
1702 callerid_get(p->cs, &name, &num, &flags);
1704 ast_copy_string(namebuf, name, ANALOG_MAX_CID);
1706 ast_copy_string(numbuf, num, ANALOG_MAX_CID);
1708 ast_log(LOG_DEBUG, "CallerID number: %s, name: %s, flags=%d\n", num, name, flags);
1713 *ev = ANALOG_EVENT_NONE;
1717 static const char *event2str(int event);
1718 static int restore_gains(struct dahdi_pvt *p);
1720 static int my_distinctive_ring(struct ast_channel *chan, void *pvt, int idx, int *ringdata)
1722 unsigned char buf[256];
1724 int curRingData[RING_PATTERNS];
1730 int checkaftercid = 0;
1732 struct dahdi_pvt *p = pvt;
1733 struct analog_pvt *analog_p = p->sig_pvt;
1735 if (ringdata == NULL) {
1736 ringdata = curRingData;
1741 /* We must have a ring by now, so, if configured, lets try to listen for
1742 * distinctive ringing */
1743 if ((checkaftercid && distinctiveringaftercid) || !checkaftercid) {
1744 /* Clear the current ring data array so we don't have old data in it. */
1745 for (receivedRingT = 0; receivedRingT < RING_PATTERNS; receivedRingT++)
1746 ringdata[receivedRingT] = 0;
1748 if (checkaftercid && distinctiveringaftercid)
1749 ast_verb(3, "Detecting post-CID distinctive ring\n");
1750 /* Check to see if context is what it should be, if not set to be. */
1751 else if (strcmp(p->context,p->defcontext) != 0) {
1752 ast_copy_string(p->context, p->defcontext, sizeof(p->context));
1753 ast_copy_string(chan->context,p->defcontext,sizeof(chan->context));
1757 i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
1758 if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) {
1759 ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
1763 if (i & DAHDI_IOMUX_SIGEVENT) {
1764 res = dahdi_get_event(p->subs[idx].dfd);
1765 if (res == DAHDI_EVENT_NOALARM) {
1767 analog_p->inalarm = 0;
1769 ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
1771 /* Let us detect distinctive ring */
1773 ringdata[receivedRingT] = analog_p->ringt;
1775 if (analog_p->ringt < analog_p->ringt_base/2)
1777 /* Increment the ringT counter so we can match it against
1778 values in chan_dahdi.conf for distinctive ring */
1779 if (++receivedRingT == RING_PATTERNS)
1781 } else if (i & DAHDI_IOMUX_READ) {
1782 res = read(p->subs[idx].dfd, buf, sizeof(buf));
1784 if (errno != ELAST) {
1785 ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
1791 if (analog_p->ringt > 0) {
1792 if (!(--analog_p->ringt)) {
1800 if ((checkaftercid && usedistinctiveringdetection) || !checkaftercid) {
1801 /* this only shows up if you have n of the dring patterns filled in */
1802 ast_verb(3, "Detected ring pattern: %d,%d,%d\n",ringdata[0],ringdata[1],ringdata[2]);
1803 for (counter = 0; counter < 3; counter++) {
1804 /* Check to see if the rings we received match any of the ones in chan_dahdi.conf for this channel */
1806 /* this only shows up if you have n of the dring patterns filled in */
1807 ast_verb(3, "Checking %d,%d,%d\n",
1808 p->drings.ringnum[counter].ring[0],
1809 p->drings.ringnum[counter].ring[1],
1810 p->drings.ringnum[counter].ring[2]);
1811 for (counter1 = 0; counter1 < 3; counter1++) {
1812 ast_verb(3, "Ring pattern check range: %d\n", p->drings.ringnum[counter].range);
1813 if (p->drings.ringnum[counter].ring[counter1] == -1) {
1814 ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n",
1815 ringdata[counter1]);
1817 } else if (ringdata[counter1] <= (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range) &&
1818 ringdata[counter1] >= (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range)) {
1819 ast_verb(3, "Ring pattern matched in range: %d to %d\n",
1820 (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range),
1821 (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range));
1826 if (distMatches == 3) {
1827 /* The ring matches, set the context to whatever is for distinctive ring.. */
1828 ast_copy_string(p->context, p->drings.ringContext[counter].contextData, sizeof(p->context));
1829 ast_copy_string(chan->context, p->drings.ringContext[counter].contextData, sizeof(chan->context));
1830 ast_verb(3, "Distinctive Ring matched context %s\n",p->context);
1835 /* Restore linear mode (if appropriate) for Caller*ID processing */
1836 dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
1842 static int send_callerid(struct dahdi_pvt *p);
1844 static int my_stop_callwait(void *pvt)
1846 struct dahdi_pvt *p = pvt;
1847 p->callwaitingrepeat = 0;
1853 static int save_conference(struct dahdi_pvt *p);
1855 static int my_callwait(void *pvt)
1857 struct dahdi_pvt *p = pvt;
1858 p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
1860 ast_log(LOG_WARNING, "Spill already exists?!?\n");
1861 ast_free(p->cidspill);
1863 if (!(p->cidspill = ast_malloc(2400 /* SAS */ + 680 /* CAS */ + READ_SIZE * 4)))
1867 memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4);
1868 if (!p->callwaitrings && p->callwaitingcallerid) {
1869 ast_gen_cas(p->cidspill, 1, 2400 + 680, AST_LAW(p));
1871 p->cidlen = 2400 + 680 + READ_SIZE * 4;
1873 ast_gen_cas(p->cidspill, 1, 2400, AST_LAW(p));
1875 p->cidlen = 2400 + READ_SIZE * 4;
1883 static int my_send_callerid(void *pvt, int cwcid, struct ast_party_caller *caller)
1885 struct dahdi_pvt *p = pvt;
1887 ast_debug(2, "Starting cid spill\n");
1890 ast_log(LOG_WARNING, "cidspill already exists??\n");
1891 ast_free(p->cidspill);
1894 if ((p->cidspill = ast_malloc(MAX_CALLERID_SIZE))) {
1896 p->cidlen = ast_callerid_generate(p->cidspill,
1897 caller->id.name.str,
1898 caller->id.number.str,
1903 p->cidlen = ast_callerid_callwaiting_generate(p->cidspill,
1904 caller->id.name.str,
1905 caller->id.number.str,
1907 p->cidlen += READ_SIZE * 4;
1915 static int my_dsp_reset_and_flush_digits(void *pvt)
1917 struct dahdi_pvt *p = pvt;
1919 ast_dsp_digitreset(p->dsp);
1924 static int my_dsp_set_digitmode(void *pvt, enum analog_dsp_digitmode mode)
1926 struct dahdi_pvt *p = pvt;
1928 if (p->channel == CHAN_PSEUDO)
1929 ast_log(LOG_ERROR, "You have assumed incorrectly sir!\n");
1931 if (mode == ANALOG_DIGITMODE_DTMF) {
1932 /* If we do hardware dtmf, no need for a DSP */
1933 if (p->hardwaredtmf) {
1935 ast_dsp_free(p->dsp);
1942 p->dsp = ast_dsp_new();
1944 ast_log(LOG_ERROR, "Unable to allocate DSP\n");
1949 ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax);
1950 } else if (mode == ANALOG_DIGITMODE_MF) {
1952 p->dsp = ast_dsp_new();
1954 ast_log(LOG_ERROR, "Unable to allocate DSP\n");
1958 ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MF | p->dtmfrelax);
1963 static int dahdi_wink(struct dahdi_pvt *p, int index);
1965 static int my_wink(void *pvt, enum analog_sub sub)
1967 struct dahdi_pvt *p = pvt;
1968 int index = analogsub_to_dahdisub(sub);
1969 if (index != SUB_REAL) {
1970 ast_log(LOG_ERROR, "We used a sub other than SUB_REAL (incorrect assumption sir)\n");
1972 return dahdi_wink(p, index);
1975 static void wakeup_sub(struct dahdi_pvt *p, int a);
1977 static int reset_conf(struct dahdi_pvt *p);
1979 static inline int dahdi_confmute(struct dahdi_pvt *p, int muted);
1981 static void my_handle_dtmfup(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
1983 struct ast_frame *f = *dest;
1984 struct dahdi_pvt *p = pvt;
1985 int idx = analogsub_to_dahdisub(analog_index);
1987 ast_debug(1, "DTMF digit: %c on %s\n", f->subclass.integer, ast->name);
1989 if (f->subclass.integer == 'f') {
1990 /* Fax tone -- Handle and return NULL */
1991 if ((p->callprogress & CALLPROGRESS_FAX) && !p->faxhandled) {
1992 /* If faxbuffers are configured, use them for the fax transmission */
1993 if (p->usefaxbuffers && !p->bufferoverrideinuse) {
1994 struct dahdi_bufferinfo bi = {
1995 .txbufpolicy = p->faxbuf_policy,
1996 .bufsize = p->bufsize,
1997 .numbufs = p->faxbuf_no
2001 if ((res = ioctl(p->subs[idx].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) {
2002 ast_log(LOG_WARNING, "Channel '%s' unable to set buffer policy, reason: %s\n", ast->name, strerror(errno));
2004 p->bufferoverrideinuse = 1;
2008 if (strcmp(ast->exten, "fax")) {
2009 const char *target_context = S_OR(ast->macrocontext, ast->context);
2011 /* We need to unlock 'ast' here because ast_exists_extension has the
2012 * potential to start autoservice on the channel. Such action is prone
2015 ast_mutex_unlock(&p->lock);
2016 ast_channel_unlock(ast);
2017 if (ast_exists_extension(ast, target_context, "fax", 1,
2018 S_COR(ast->caller.id.number.valid, ast->caller.id.number.str, NULL))) {
2019 ast_channel_lock(ast);
2020 ast_mutex_lock(&p->lock);
2021 ast_verb(3, "Redirecting %s to fax extension\n", ast->name);
2022 /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
2023 pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten);
2024 if (ast_async_goto(ast, target_context, "fax", 1))
2025 ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context);
2027 ast_channel_lock(ast);
2028 ast_mutex_lock(&p->lock);
2029 ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
2032 ast_debug(1, "Already in a fax extension, not redirecting\n");
2035 ast_debug(1, "Fax already handled\n");
2037 dahdi_confmute(p, 0);
2038 p->subs[idx].f.frametype = AST_FRAME_NULL;
2039 p->subs[idx].f.subclass.integer = 0;
2040 *dest = &p->subs[idx].f;
2044 static void my_lock_private(void *pvt)
2046 struct dahdi_pvt *p = pvt;
2047 ast_mutex_lock(&p->lock);
2050 static void my_unlock_private(void *pvt)
2052 struct dahdi_pvt *p = pvt;
2053 ast_mutex_unlock(&p->lock);
2056 /* linear_mode = 0 - turn linear mode off, >0 - turn linear mode on
2057 * returns the last value of the linear setting
2059 static int my_set_linear_mode(void *pvt, int idx, int linear_mode)
2061 struct dahdi_pvt *p = pvt;
2064 if (0 > linear_mode || !dahdi_setlinear(p->subs[idx].dfd, linear_mode)) {
2067 oldval = p->subs[idx].linear;
2068 p->subs[idx].linear = linear_mode;
2072 static int get_alarms(struct dahdi_pvt *p);
2073 static void handle_alarms(struct dahdi_pvt *p, int alms);
2074 static void my_get_and_handle_alarms(void *pvt)
2077 struct dahdi_pvt *p = pvt;
2079 res = get_alarms(p);
2080 handle_alarms(p, res);
2083 static void *my_get_sigpvt_bridged_channel(struct ast_channel *chan)
2085 struct dahdi_pvt *p = ast_bridged_channel(chan)->tech_pvt;
2092 static int my_get_sub_fd(void *pvt, enum analog_sub sub)
2094 struct dahdi_pvt *p = pvt;
2095 int dahdi_sub = analogsub_to_dahdisub(sub);
2096 return p->subs[dahdi_sub].dfd;
2099 static void my_set_cadence(void *pvt, int *cidrings, struct ast_channel *ast)
2101 struct dahdi_pvt *p = pvt;
2103 /* Choose proper cadence */
2104 if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) {
2105 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &cadences[p->distinctivering - 1]))
2106 ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s': %s\n", p->distinctivering, ast->name, strerror(errno));
2107 *cidrings = cidrings[p->distinctivering - 1];
2109 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, NULL))
2110 ast_log(LOG_WARNING, "Unable to reset default ring on '%s': %s\n", ast->name, strerror(errno));
2111 *cidrings = p->sendcalleridafter;
2115 static void my_set_alarm(void *pvt, int in_alarm)
2117 struct dahdi_pvt *p = pvt;
2119 p->inalarm = in_alarm;
2122 static void my_set_dialing(void *pvt, int is_dialing)
2124 struct dahdi_pvt *p = pvt;
2126 p->dialing = is_dialing;
2129 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2130 static void my_set_digital(void *pvt, int is_digital)
2132 struct dahdi_pvt *p = pvt;
2134 p->digital = is_digital;
2136 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2138 #if defined(HAVE_SS7)
2139 static void my_set_inservice(void *pvt, int is_inservice)
2141 struct dahdi_pvt *p = pvt;
2143 p->inservice = is_inservice;
2145 #endif /* defined(HAVE_SS7) */
2147 #if defined(HAVE_SS7)
2148 static void my_set_locallyblocked(void *pvt, int is_blocked)
2150 struct dahdi_pvt *p = pvt;
2152 p->locallyblocked = is_blocked;
2154 #endif /* defined(HAVE_SS7) */
2156 #if defined(HAVE_SS7)
2157 static void my_set_remotelyblocked(void *pvt, int is_blocked)
2159 struct dahdi_pvt *p = pvt;
2161 p->remotelyblocked = is_blocked;
2163 #endif /* defined(HAVE_SS7) */
2165 static void my_set_ringtimeout(void *pvt, int ringt)
2167 struct dahdi_pvt *p = pvt;
2171 static void my_set_waitingfordt(void *pvt, struct ast_channel *ast)
2173 struct dahdi_pvt *p = pvt;
2175 if (p->waitfordialtone && CANPROGRESSDETECT(p) && p->dsp) {
2176 ast_log(LOG_DEBUG, "Defer dialing for %dms or dialtone\n", p->waitfordialtone);
2177 gettimeofday(&p->waitingfordt, NULL);
2178 ast_setstate(ast, AST_STATE_OFFHOOK);
2182 static int my_check_waitingfordt(void *pvt)
2184 struct dahdi_pvt *p = pvt;
2186 if (p->waitingfordt.tv_usec) {
2193 static void my_set_confirmanswer(void *pvt, int flag)
2195 struct dahdi_pvt *p = pvt;
2196 p->confirmanswer = flag;
2199 static int my_check_confirmanswer(void *pvt)
2201 struct dahdi_pvt *p = pvt;
2202 if (p->confirmanswer) {
2209 static void my_cancel_cidspill(void *pvt)
2211 struct dahdi_pvt *p = pvt;
2213 ast_free(p->cidspill);
2218 static int my_confmute(void *pvt, int mute)
2220 struct dahdi_pvt *p = pvt;
2221 return dahdi_confmute(p, mute);
2224 static void my_set_pulsedial(void *pvt, int flag)
2226 struct dahdi_pvt *p = pvt;
2227 p->pulsedial = flag;
2230 static const char *my_get_orig_dialstring(void *pvt)
2232 struct dahdi_pvt *p = pvt;
2234 return p->dialstring;
2237 static void my_increase_ss_count(void)
2239 ast_mutex_lock(&ss_thread_lock);
2241 ast_mutex_unlock(&ss_thread_lock);
2244 static void my_decrease_ss_count(void)
2246 ast_mutex_lock(&ss_thread_lock);
2248 ast_cond_signal(&ss_thread_complete);
2249 ast_mutex_unlock(&ss_thread_lock);
2252 static void my_all_subchannels_hungup(void *pvt)
2254 struct dahdi_pvt *p = pvt;
2261 ast_dsp_free(p->dsp);
2265 p->law = p->law_default;
2266 law = p->law_default;
2267 res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law);
2269 ast_log(LOG_WARNING, "Unable to set law on channel %d to default: %s\n", p->channel, strerror(errno));
2271 dahdi_setlinear(p->subs[SUB_REAL].dfd, 0);
2277 /* Cleanup owners here */
2278 for (i = 0; i < 3; i++) {
2279 p->subs[i].owner = NULL;
2285 if (num_restart_pending == 0) {
2290 static int conf_del(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index);
2292 static int my_conf_del(void *pvt, enum analog_sub sub)
2294 struct dahdi_pvt *p = pvt;
2295 int x = analogsub_to_dahdisub(sub);
2297 return conf_del(p, &p->subs[x], x);
2300 static int conf_add(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index, int slavechannel);
2302 static int my_conf_add(void *pvt, enum analog_sub sub)
2304 struct dahdi_pvt *p = pvt;
2305 int x = analogsub_to_dahdisub(sub);
2307 return conf_add(p, &p->subs[x], x, 0);
2310 static int isslavenative(struct dahdi_pvt *p, struct dahdi_pvt **out);
2312 static int my_complete_conference_update(void *pvt, int needconference)
2314 struct dahdi_pvt *p = pvt;
2315 int needconf = needconference;
2318 struct dahdi_pvt *slave = NULL;
2320 useslavenative = isslavenative(p, &slave);
2322 /* If we have a slave, add him to our conference now. or DAX
2323 if this is slave native */
2324 for (x = 0; x < MAX_SLAVES; x++) {
2327 conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p));
2329 conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, 0);
2334 /* If we're supposed to be in there, do so now */
2335 if (p->inconference && !p->subs[SUB_REAL].inthreeway) {
2337 conf_add(p, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(slave));
2339 conf_add(p, &p->subs[SUB_REAL], SUB_REAL, 0);
2343 /* If we have a master, add ourselves to his conference */
2345 if (isslavenative(p->master, NULL)) {
2346 conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p->master));
2348 conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, 0);
2352 /* Nobody is left (or should be left) in our conference.
2360 static int check_for_conference(struct dahdi_pvt *p);
2362 static int my_check_for_conference(void *pvt)
2364 struct dahdi_pvt *p = pvt;
2365 return check_for_conference(p);
2368 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)
2370 struct dahdi_pvt *p = pvt;
2374 da = analogsub_to_dahdisub(a);
2375 db = analogsub_to_dahdisub(b);
2377 tchan = p->subs[da].chan;
2379 p->subs[da].chan = p->subs[db].chan;
2381 p->subs[db].chan = tchan;
2384 ast_channel_set_fd(ast_a, 0, p->subs[da].dfd);
2386 ast_channel_set_fd(ast_b, 0, p->subs[db].dfd);
2388 p->subs[da].owner = ast_a;
2389 p->subs[db].owner = ast_b;
2397 static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const char *linkedid);
2399 static struct ast_channel *my_new_analog_ast_channel(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
2401 struct dahdi_pvt *p = pvt;
2402 int dsub = analogsub_to_dahdisub(sub);
2404 return dahdi_new(p, state, startpbx, dsub, 0, requestor ? requestor->linkedid : "");
2407 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2408 static int dahdi_setlaw(int dfd, int law)
2411 res = ioctl(dfd, DAHDI_SETLAW, &law);
2416 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2418 #if defined(HAVE_PRI)
2419 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)
2421 struct dahdi_pvt *p = pvt;
2426 case SIG_PRI_LIB_HANDLE_CASES:
2427 if (((struct sig_pri_chan *) p->sig_pvt)->no_b_channel) {
2428 /* PRI nobch pseudo channel. Does not handle ioctl(DAHDI_AUDIOMODE) */
2433 /* Set to audio mode at this point */
2435 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &audio) == -1) {
2436 ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n",
2437 p->channel, audio, strerror(errno));
2442 if (law != SIG_PRI_DEFLAW) {
2443 dahdi_setlaw(p->subs[SUB_REAL].dfd, (law == SIG_PRI_ULAW) ? DAHDI_LAW_MULAW : DAHDI_LAW_ALAW);
2446 ast_copy_string(p->exten, exten, sizeof(p->exten));
2449 case SIG_PRI_DEFLAW:
2453 newlaw = DAHDI_LAW_ALAW;
2456 newlaw = DAHDI_LAW_MULAW;
2459 return dahdi_new(p, state, 0, SUB_REAL, newlaw, requestor ? requestor->linkedid : "");
2461 #endif /* defined(HAVE_PRI) */
2463 static int set_actual_gain(int fd, float rxgain, float txgain, float rxdrc, float txdrc, int law);
2465 #if defined(HAVE_PRI)
2468 * \brief Open the PRI channel media path.
2471 * \param p Channel private control structure.
2475 static void my_pri_open_media(void *p)
2477 struct dahdi_pvt *pvt = p;
2482 dfd = pvt->subs[SUB_REAL].dfd;
2484 /* Open the media path. */
2486 res = ioctl(dfd, DAHDI_AUDIOMODE, &set_val);
2488 ast_log(LOG_WARNING, "Unable to enable audio mode on channel %d (%s)\n",
2489 pvt->channel, strerror(errno));
2492 /* Set correct companding law for this call. */
2493 res = dahdi_setlaw(dfd, pvt->law);
2495 ast_log(LOG_WARNING, "Unable to set law on channel %d\n", pvt->channel);
2498 /* Set correct gain for this call. */
2500 res = set_actual_gain(dfd, 0, 0, pvt->rxdrc, pvt->txdrc, pvt->law);
2502 res = set_actual_gain(dfd, pvt->rxgain, pvt->txgain, pvt->rxdrc, pvt->txdrc,
2506 ast_log(LOG_WARNING, "Unable to set gains on channel %d\n", pvt->channel);
2509 #endif /* defined(HAVE_PRI) */
2511 static int unalloc_sub(struct dahdi_pvt *p, int x);
2513 static int my_unallocate_sub(void *pvt, enum analog_sub analogsub)
2515 struct dahdi_pvt *p = pvt;
2517 return unalloc_sub(p, analogsub_to_dahdisub(analogsub));
2520 static int alloc_sub(struct dahdi_pvt *p, int x);
2522 static int my_allocate_sub(void *pvt, enum analog_sub analogsub)
2524 struct dahdi_pvt *p = pvt;
2526 return alloc_sub(p, analogsub_to_dahdisub(analogsub));
2529 static int has_voicemail(struct dahdi_pvt *p);
2531 static int my_has_voicemail(void *pvt)
2533 struct dahdi_pvt *p = pvt;
2535 return has_voicemail(p);
2538 static int my_play_tone(void *pvt, enum analog_sub sub, enum analog_tone tone)
2540 struct dahdi_pvt *p = pvt;
2543 index = analogsub_to_dahdisub(sub);
2545 return tone_zone_play_tone(p->subs[index].dfd, analog_tone_to_dahditone(tone));
2548 static enum analog_event dahdievent_to_analogevent(int event)
2550 enum analog_event res;
2553 case DAHDI_EVENT_ONHOOK:
2554 res = ANALOG_EVENT_ONHOOK;
2556 case DAHDI_EVENT_RINGOFFHOOK:
2557 res = ANALOG_EVENT_RINGOFFHOOK;
2559 case DAHDI_EVENT_WINKFLASH:
2560 res = ANALOG_EVENT_WINKFLASH;
2562 case DAHDI_EVENT_ALARM:
2563 res = ANALOG_EVENT_ALARM;
2565 case DAHDI_EVENT_NOALARM:
2566 res = ANALOG_EVENT_NOALARM;
2568 case DAHDI_EVENT_DIALCOMPLETE:
2569 res = ANALOG_EVENT_DIALCOMPLETE;
2571 case DAHDI_EVENT_RINGERON:
2572 res = ANALOG_EVENT_RINGERON;
2574 case DAHDI_EVENT_RINGEROFF:
2575 res = ANALOG_EVENT_RINGEROFF;
2577 case DAHDI_EVENT_HOOKCOMPLETE:
2578 res = ANALOG_EVENT_HOOKCOMPLETE;
2580 case DAHDI_EVENT_PULSE_START:
2581 res = ANALOG_EVENT_PULSE_START;
2583 case DAHDI_EVENT_POLARITY:
2584 res = ANALOG_EVENT_POLARITY;
2586 case DAHDI_EVENT_RINGBEGIN:
2587 res = ANALOG_EVENT_RINGBEGIN;
2589 case DAHDI_EVENT_EC_DISABLED:
2590 res = ANALOG_EVENT_EC_DISABLED;
2592 case DAHDI_EVENT_REMOVED:
2593 res = ANALOG_EVENT_REMOVED;
2595 case DAHDI_EVENT_NEONMWI_ACTIVE:
2596 res = ANALOG_EVENT_NEONMWI_ACTIVE;
2598 case DAHDI_EVENT_NEONMWI_INACTIVE:
2599 res = ANALOG_EVENT_NEONMWI_INACTIVE;
2601 #ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
2602 case DAHDI_EVENT_TX_CED_DETECTED:
2603 res = ANALOG_EVENT_TX_CED_DETECTED;
2605 case DAHDI_EVENT_RX_CED_DETECTED:
2606 res = ANALOG_EVENT_RX_CED_DETECTED;
2608 case DAHDI_EVENT_EC_NLP_DISABLED:
2609 res = ANALOG_EVENT_EC_NLP_DISABLED;
2611 case DAHDI_EVENT_EC_NLP_ENABLED:
2612 res = ANALOG_EVENT_EC_NLP_ENABLED;
2615 case DAHDI_EVENT_PULSEDIGIT:
2616 res = ANALOG_EVENT_PULSEDIGIT;
2618 case DAHDI_EVENT_DTMFDOWN:
2619 res = ANALOG_EVENT_DTMFDOWN;
2621 case DAHDI_EVENT_DTMFUP:
2622 res = ANALOG_EVENT_DTMFUP;
2625 switch(event & 0xFFFF0000) {
2626 case DAHDI_EVENT_PULSEDIGIT:
2627 case DAHDI_EVENT_DTMFDOWN:
2628 case DAHDI_EVENT_DTMFUP:
2629 /* The event includes a digit number in the low word.
2630 * Converting it to a 'enum analog_event' would remove
2631 * that information. Thus it is returned as-is.
2636 res = ANALOG_EVENT_ERROR;
2643 static inline int dahdi_wait_event(int fd);
2645 static int my_wait_event(void *pvt)
2647 struct dahdi_pvt *p = pvt;
2649 return dahdi_wait_event(p->subs[SUB_REAL].dfd);
2652 static int my_get_event(void *pvt)
2654 struct dahdi_pvt *p = pvt;
2657 if (p->fake_event) {
2658 res = p->fake_event;
2661 res = dahdi_get_event(p->subs[SUB_REAL].dfd);
2663 return dahdievent_to_analogevent(res);
2666 static int my_is_off_hook(void *pvt)
2668 struct dahdi_pvt *p = pvt;
2670 struct dahdi_params par;
2672 memset(&par, 0, sizeof(par));
2674 if (p->subs[SUB_REAL].dfd > -1)
2675 res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par);
2677 /* Assume not off hook on CVRS */
2679 par.rxisoffhook = 0;
2682 ast_log(LOG_WARNING, "Unable to check hook state on channel %d: %s\n", p->channel, strerror(errno));
2685 if ((p->sig == SIG_FXSKS) || (p->sig == SIG_FXSGS)) {
2686 /* When "onhook" that means no battery on the line, and thus
2687 it is out of service..., if it's on a TDM card... If it's a channel
2688 bank, there is no telling... */
2689 return (par.rxbits > -1) || par.rxisoffhook;
2692 return par.rxisoffhook;
2695 static void dahdi_enable_ec(struct dahdi_pvt *p);
2696 static void dahdi_disable_ec(struct dahdi_pvt *p);
2698 static int my_set_echocanceller(void *pvt, int enable)
2700 struct dahdi_pvt *p = pvt;
2705 dahdi_disable_ec(p);
2710 static int dahdi_ring_phone(struct dahdi_pvt *p);
2712 static int my_ring(void *pvt)
2714 struct dahdi_pvt *p = pvt;
2716 return dahdi_ring_phone(p);
2719 static int my_flash(void *pvt)
2721 struct dahdi_pvt *p = pvt;
2722 int func = DAHDI_FLASH;
2723 return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &func);
2726 static inline int dahdi_set_hook(int fd, int hs);
2728 static int my_off_hook(void *pvt)
2730 struct dahdi_pvt *p = pvt;
2731 return dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK);
2734 static void my_set_needringing(void *pvt, int value)
2736 struct dahdi_pvt *p = pvt;
2737 p->subs[SUB_REAL].needringing = value;
2740 static int my_start(void *pvt)
2742 struct dahdi_pvt *p = pvt;
2743 int x = DAHDI_START;
2745 return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
2748 static int my_dial_digits(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop)
2750 int index = analogsub_to_dahdisub(sub);
2752 struct dahdi_pvt *p = pvt;
2753 struct dahdi_dialoperation ddop;
2755 if (dop->op != ANALOG_DIAL_OP_REPLACE) {
2756 ast_log(LOG_ERROR, "Fix the dial_digits callback!\n");
2760 if (sub != ANALOG_SUB_REAL)
2761 printf("Trying to dial digits on sub %d\n", sub);
2763 ddop.op = DAHDI_DIAL_OP_REPLACE;
2764 strncpy(ddop.dialstr, dop->dialstr, sizeof(ddop.dialstr));
2766 printf("Dialing %s on %d\n", ddop.dialstr, p->channel);
2768 res = ioctl(p->subs[index].dfd, DAHDI_DIAL, &ddop);
2771 ast_log(LOG_DEBUG, "DAHDI_DIAL ioctl failed on %s: %s\n", p->owner->name, strerror(errno));
2776 static void dahdi_train_ec(struct dahdi_pvt *p);
2778 static int my_train_echocanceller(void *pvt)
2780 struct dahdi_pvt *p = pvt;
2787 static int my_is_dialing(void *pvt, enum analog_sub sub)
2789 struct dahdi_pvt *p = pvt;
2793 index = analogsub_to_dahdisub(sub);
2795 if (ioctl(p->subs[index].dfd, DAHDI_DIALING, &x)) {
2796 ast_log(LOG_DEBUG, "DAHDI_DIALING ioctl failed!\n");
2803 static int my_on_hook(void *pvt)
2805 struct dahdi_pvt *p = pvt;
2806 return dahdi_set_hook(p->subs[ANALOG_SUB_REAL].dfd, DAHDI_ONHOOK);
2809 #if defined(HAVE_PRI)
2810 static void my_pri_fixup_chans(void *chan_old, void *chan_new)
2812 struct dahdi_pvt *old_chan = chan_old;
2813 struct dahdi_pvt *new_chan = chan_new;
2815 new_chan->owner = old_chan->owner;
2816 old_chan->owner = NULL;
2817 if (new_chan->owner) {
2818 new_chan->owner->tech_pvt = new_chan;
2819 new_chan->owner->fds[0] = new_chan->subs[SUB_REAL].dfd;
2820 new_chan->subs[SUB_REAL].owner = old_chan->subs[SUB_REAL].owner;
2821 old_chan->subs[SUB_REAL].owner = NULL;
2823 /* Copy any DSP that may be present */
2824 new_chan->dsp = old_chan->dsp;
2825 new_chan->dsp_features = old_chan->dsp_features;
2826 old_chan->dsp = NULL;
2827 old_chan->dsp_features = 0;
2829 /* Transfer flags from the old channel. */
2830 new_chan->dialing = old_chan->dialing;
2831 new_chan->digital = old_chan->digital;
2832 new_chan->outgoing = old_chan->outgoing;
2833 old_chan->dialing = 0;
2834 old_chan->digital = 0;
2835 old_chan->outgoing = 0;
2837 /* More stuff to transfer to the new channel. */
2838 new_chan->law = old_chan->law;
2840 #endif /* defined(HAVE_PRI) */
2842 #if defined(HAVE_PRI)
2843 static int sig_pri_tone_to_dahditone(enum sig_pri_tone tone)
2846 case SIG_PRI_TONE_RINGTONE:
2847 return DAHDI_TONE_RINGTONE;
2848 case SIG_PRI_TONE_STUTTER:
2849 return DAHDI_TONE_STUTTER;
2850 case SIG_PRI_TONE_CONGESTION:
2851 return DAHDI_TONE_CONGESTION;
2852 case SIG_PRI_TONE_DIALTONE:
2853 return DAHDI_TONE_DIALTONE;
2854 case SIG_PRI_TONE_DIALRECALL:
2855 return DAHDI_TONE_DIALRECALL;
2856 case SIG_PRI_TONE_INFO:
2857 return DAHDI_TONE_INFO;
2858 case SIG_PRI_TONE_BUSY:
2859 return DAHDI_TONE_BUSY;
2864 #endif /* defined(HAVE_PRI) */
2866 #if defined(HAVE_PRI)
2867 static void my_handle_dchan_exception(struct sig_pri_pri *pri, int index)
2871 res = ioctl(pri->fds[index], DAHDI_GETEVENT, &x);
2873 ast_log(LOG_NOTICE, "PRI got event: %s (%d) on D-channel of span %d\n", event2str(x), x, pri->span);
2875 /* Keep track of alarm state */
2877 case DAHDI_EVENT_ALARM:
2878 pri_event_alarm(pri, index, 0);
2880 case DAHDI_EVENT_NOALARM:
2881 pri_event_noalarm(pri, index, 0);
2887 #endif /* defined(HAVE_PRI) */
2889 #if defined(HAVE_PRI)
2890 static int my_pri_play_tone(void *pvt, enum sig_pri_tone tone)
2892 struct dahdi_pvt *p = pvt;
2894 return tone_zone_play_tone(p->subs[SUB_REAL].dfd, sig_pri_tone_to_dahditone(tone));
2896 #endif /* defined(HAVE_PRI) */
2898 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2901 * \brief Set the caller id information.
2904 * \param pvt DAHDI private structure
2905 * \param caller Caller-id information to set.
2909 static void my_set_callerid(void *pvt, const struct ast_party_caller *caller)
2911 struct dahdi_pvt *p = pvt;
2913 ast_copy_string(p->cid_num,
2914 S_COR(caller->id.number.valid, caller->id.number.str, ""),
2915 sizeof(p->cid_num));
2916 ast_copy_string(p->cid_name,
2917 S_COR(caller->id.name.valid, caller->id.name.str, ""),
2918 sizeof(p->cid_name));
2919 ast_copy_string(p->cid_subaddr,
2920 S_COR(caller->id.subaddress.valid, caller->id.subaddress.str, ""),
2921 sizeof(p->cid_subaddr));
2922 p->cid_ton = caller->id.number.plan;
2923 p->callingpres = ast_party_id_presentation(&caller->id);
2924 if (caller->id.tag) {
2925 ast_copy_string(p->cid_tag, caller->id.tag, sizeof(p->cid_tag));
2927 ast_copy_string(p->cid_ani,
2928 S_COR(caller->ani.number.valid, caller->ani.number.str, ""),
2929 sizeof(p->cid_ani));
2930 p->cid_ani2 = caller->ani2;
2932 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2934 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2937 * \brief Set the Dialed Number Identifier.
2940 * \param pvt DAHDI private structure
2941 * \param dnid Dialed Number Identifier string.
2945 static void my_set_dnid(void *pvt, const char *dnid)
2947 struct dahdi_pvt *p = pvt;
2949 ast_copy_string(p->dnid, dnid, sizeof(p->dnid));
2951 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2953 #if defined(HAVE_PRI)
2956 * \brief Set the Redirecting Directory Number Information Service (RDNIS).
2959 * \param pvt DAHDI private structure
2960 * \param rdnis Redirecting Directory Number Information Service (RDNIS) string.
2964 static void my_set_rdnis(void *pvt, const char *rdnis)
2966 struct dahdi_pvt *p = pvt;
2968 ast_copy_string(p->rdnis, rdnis, sizeof(p->rdnis));
2970 #endif /* defined(HAVE_PRI) */
2972 #if defined(HAVE_PRI)
2975 * \brief Make a dialstring for native ISDN CC to recall properly.
2978 * \param priv Channel private control structure.
2979 * \param buf Where to put the modified dialstring.
2980 * \param buf_size Size of modified dialstring buffer.
2983 * original dialstring:
2984 * DAHDI/[i<span>-](g|G|r|R)<group#(0-63)>[c|r<cadance#>|d][/extension[/options]]
2986 * The modified dialstring will have prefixed the channel-group section
2987 * with the ISDN channel restriction.
2990 * DAHDI/i<span>-(g|G|r|R)<group#(0-63)>[c|r<cadance#>|d][/extension[/options]]
2992 * The routine will check to see if the ISDN channel restriction is already
2993 * in the original dialstring.
2997 static void my_pri_make_cc_dialstring(void *priv, char *buf, size_t buf_size)
3000 struct dahdi_pvt *pvt;
3001 AST_DECLARE_APP_ARGS(args,
3002 AST_APP_ARG(tech); /* channel technology token */
3003 AST_APP_ARG(group); /* channel/group token */
3004 //AST_APP_ARG(ext); /* extension token */
3005 //AST_APP_ARG(opts); /* options token */
3006 //AST_APP_ARG(other); /* Any remining unused arguments */
3010 dial = ast_strdupa(pvt->dialstring);
3011 AST_NONSTANDARD_APP_ARGS(args, dial, '/');
3013 ast_copy_string(buf, pvt->dialstring, buf_size);
3017 /* Append the ISDN span channel restriction to the dialstring. */
3018 snprintf(buf, buf_size, "%s/i%d-", args.tech, pvt->pri->span);
3021 if (isdigit(args.group[0]) || args.group[0] == 'i' || strchr(args.group, '!')) {
3022 /* The ISDN span channel restriction is not needed or already
3023 * in the dialstring. */
3024 ast_copy_string(buf, pvt->dialstring, buf_size);
3027 /* Insert the ISDN span channel restriction into the dialstring. */
3028 snprintf(buf, buf_size, "%s/i%d-%s", args.tech, pvt->pri->span, args.group);
3030 #endif /* defined(HAVE_PRI) */
3032 #if defined(HAVE_PRI)
3035 * \brief Reevaluate the PRI span device state.
3038 * \param pri Asterisk D channel control structure.
3042 * \note Assumes the pri->lock is already obtained.
3044 static void dahdi_pri_update_span_devstate(struct sig_pri_pri *pri)
3047 unsigned num_b_chans; /* Number of B channels provisioned on the span. */
3048 unsigned in_use; /* Number of B channels in use on the span. */
3049 unsigned in_alarm; /* TRUE if the span is in alarm condition. */
3050 enum ast_device_state new_state;
3052 /* Count the number of B channels and the number of B channels in use. */
3056 for (idx = pri->numchans; idx--;) {
3057 if (pri->pvts[idx] && !pri->pvts[idx]->no_b_channel) {
3058 /* This is a B channel interface. */
3060 if (pri->pvts[idx]->owner
3061 #if defined(HAVE_PRI_SERVICE_MESSAGES)
3062 /* Out-of-service B channels are "in-use". */
3063 && pri->pvts[idx]->service_status
3064 #endif /* defined(HAVE_PRI_SERVICE_MESSAGES) */
3068 if (!pri->pvts[idx]->inalarm) {
3069 /* There is a channel that is not in alarm. */
3075 /* Update the span congestion device state and report any change. */
3077 new_state = AST_DEVICE_UNAVAILABLE;
3079 new_state = num_b_chans == in_use ? AST_DEVICE_BUSY : AST_DEVICE_NOT_INUSE;
3081 if (pri->congestion_devstate != new_state) {
3082 pri->congestion_devstate = new_state;
3083 ast_devstate_changed(AST_DEVICE_UNKNOWN, "DAHDI/I%d/congestion", pri->span);
3085 #if defined(THRESHOLD_DEVSTATE_PLACEHOLDER)
3086 /* Update the span threshold device state and report any change. */
3088 new_state = AST_DEVICE_UNAVAILABLE;
3089 } else if (!in_use) {
3090 new_state = AST_DEVICE_NOT_INUSE;
3091 } else if (!pri->user_busy_threshold) {
3092 new_state = in_use < num_b_chans ? AST_DEVICE_INUSE : AST_DEVICE_BUSY;
3094 new_state = in_use < pri->user_busy_threshold ? AST_DEVICE_INUSE
3097 if (pri->threshold_devstate != new_state) {
3098 pri->threshold_devstate = new_state;
3099 ast_devstate_changed(AST_DEVICE_UNKNOWN, "DAHDI/I%d/threshold", pri->span);
3101 #endif /* defined(THRESHOLD_DEVSTATE_PLACEHOLDER) */
3103 #endif /* defined(HAVE_PRI) */
3105 #if defined(HAVE_PRI)
3108 * \brief Reference this module.
3113 static void my_module_ref(void)
3115 ast_module_ref(ast_module_info->self);
3117 #endif /* defined(HAVE_PRI) */
3119 #if defined(HAVE_PRI)
3122 * \brief Unreference this module.
3127 static void my_module_unref(void)
3129 ast_module_unref(ast_module_info->self);
3131 #endif /* defined(HAVE_PRI) */
3133 #if defined(HAVE_PRI)
3134 #if defined(HAVE_PRI_CALL_WAITING)
3135 static void my_pri_init_config(void *priv, struct sig_pri_pri *pri);
3136 #endif /* defined(HAVE_PRI_CALL_WAITING) */
3137 static int dahdi_new_pri_nobch_channel(struct sig_pri_pri *pri);
3139 static struct sig_pri_callback dahdi_pri_callbacks =
3141 .handle_dchan_exception = my_handle_dchan_exception,
3142 .play_tone = my_pri_play_tone,
3143 .set_echocanceller = my_set_echocanceller,
3144 .dsp_reset_and_flush_digits = my_dsp_reset_and_flush_digits,
3145 .lock_private = my_lock_private,
3146 .unlock_private = my_unlock_private,
3147 .new_ast_channel = my_new_pri_ast_channel,
3148 .fixup_chans = my_pri_fixup_chans,
3149 .set_alarm = my_set_alarm,
3150 .set_dialing = my_set_dialing,
3151 .set_digital = my_set_digital,
3152 .set_callerid = my_set_callerid,
3153 .set_dnid = my_set_dnid,
3154 .set_rdnis = my_set_rdnis,
3155 .new_nobch_intf = dahdi_new_pri_nobch_channel,
3156 #if defined(HAVE_PRI_CALL_WAITING)
3157 .init_config = my_pri_init_config,
3158 #endif /* defined(HAVE_PRI_CALL_WAITING) */
3159 .get_orig_dialstring = my_get_orig_dialstring,
3160 .make_cc_dialstring = my_pri_make_cc_dialstring,
3161 .update_span_devstate = dahdi_pri_update_span_devstate,
3162 .module_ref = my_module_ref,
3163 .module_unref = my_module_unref,
3164 .open_media = my_pri_open_media,
3166 #endif /* defined(HAVE_PRI) */
3168 #if defined(HAVE_SS7)
3171 * \brief Handle the SS7 link exception.
3174 * \param linkset Controlling linkset for the channel.
3175 * \param which Link index of the signaling channel.
3179 static void my_handle_link_exception(struct sig_ss7_linkset *linkset, int which)
3183 if (ioctl(linkset->fds[which], DAHDI_GETEVENT, &event)) {
3184 ast_log(LOG_ERROR, "SS7: Error in exception retrieval on span %d/%d!\n",
3185 linkset->span, which);
3189 case DAHDI_EVENT_NONE:
3191 case DAHDI_EVENT_ALARM:
3192 ast_log(LOG_ERROR, "SS7 got event: %s(%d) on span %d/%d\n",
3193 event2str(event), event, linkset->span, which);
3194 sig_ss7_link_alarm(linkset, which);
3196 case DAHDI_EVENT_NOALARM:
3197 ast_log(LOG_ERROR, "SS7 got event: %s(%d) on span %d/%d\n",
3198 event2str(event), event, linkset->span, which);
3199 sig_ss7_link_noalarm(linkset, which);
3202 ast_log(LOG_NOTICE, "SS7 got event: %s(%d) on span %d/%d\n",
3203 event2str(event), event, linkset->span, which);
3207 #endif /* defined(HAVE_SS7) */
3209 #if defined(HAVE_SS7)
3210 static void my_ss7_set_loopback(void *pvt, int enable)
3212 struct dahdi_pvt *p = pvt;
3214 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_LOOPBACK, &enable)) {
3215 ast_log(LOG_WARNING, "Unable to set loopback on channel %d: %s\n", p->channel,
3219 #endif /* defined(HAVE_SS7) */
3221 #if defined(HAVE_SS7)