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.
32 * \ingroup channel_drivers
34 * \todo Deprecate the "musiconhold" configuration option post 1.4
38 * \li The channel chan_dahdi uses the configuration file \ref chan_dahdi.conf
39 * \addtogroup configuration_file
42 /*! \page chan_dahdi.conf chan_dahdi.conf
43 * \verbinclude chan_dahdi.conf.sample
47 <use type="module">res_smdi</use>
48 <depend>dahdi</depend>
49 <depend>tonezone</depend>
50 <use type="external">pri</use>
51 <use type="external">ss7</use>
52 <use type="external">openr2</use>
53 <support_level>core</support_level>
58 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
60 #if defined(__NetBSD__) || defined(__FreeBSD__)
64 #include <sys/signal.h>
66 #include <sys/ioctl.h>
71 #include <dahdi/user.h>
72 #include <dahdi/tonezone.h>
73 #include "sig_analog.h"
74 /* Analog signaling is currently still present in chan_dahdi for use with
75 * radio. Sig_analog does not currently handle any radio operations. If
76 * radio only uses analog signaling, then the radio handling logic could
77 * be placed in sig_analog and the duplicated code could be removed.
83 #error "Upgrade your libpri"
85 #endif /* defined(HAVE_PRI) */
89 #if defined(LIBSS7_ABI_COMPATIBILITY)
90 #error "Your installed libss7 is not compatible"
92 #endif /* defined(HAVE_SS7) */
95 /* put this here until sig_mfcr2 comes along */
96 #define SIG_MFCR2_MAX_CHANNELS 672 /*!< No more than a DS3 per trunk group */
100 #include "asterisk/lock.h"
101 #include "asterisk/channel.h"
102 #include "asterisk/config.h"
103 #include "asterisk/module.h"
104 #include "asterisk/pbx.h"
105 #include "asterisk/file.h"
106 #include "asterisk/ulaw.h"
107 #include "asterisk/alaw.h"
108 #include "asterisk/callerid.h"
109 #include "asterisk/adsi.h"
110 #include "asterisk/cli.h"
111 #include "asterisk/cdr.h"
112 #include "asterisk/cel.h"
113 #include "asterisk/features.h"
114 #include "asterisk/musiconhold.h"
115 #include "asterisk/say.h"
116 #include "asterisk/tdd.h"
117 #include "asterisk/app.h"
118 #include "asterisk/dsp.h"
119 #include "asterisk/astdb.h"
120 #include "asterisk/manager.h"
121 #include "asterisk/causes.h"
122 #include "asterisk/term.h"
123 #include "asterisk/utils.h"
124 #include "asterisk/transcap.h"
125 #include "asterisk/stringfields.h"
126 #include "asterisk/abstract_jb.h"
127 #include "asterisk/smdi.h"
128 #include "asterisk/astobj.h"
129 #include "asterisk/event.h"
130 #include "asterisk/devicestate.h"
131 #include "asterisk/paths.h"
132 #include "asterisk/ccss.h"
133 #include "asterisk/data.h"
136 <application name="DAHDISendKeypadFacility" language="en_US">
138 Send digits out of band over a PRI.
141 <parameter name="digits" required="true" />
144 <para>This application will send the given string of digits in a Keypad
145 Facility IE over the current channel.</para>
148 <application name="DAHDISendCallreroutingFacility" language="en_US">
150 Send an ISDN call rerouting/deflection facility message.
153 <parameter name="destination" required="true">
154 <para>Destination number.</para>
156 <parameter name="original">
157 <para>Original called number.</para>
159 <parameter name="reason">
160 <para>Diversion reason, if not specified defaults to <literal>unknown</literal></para>
164 <para>This application will send an ISDN switch specific call
165 rerouting/deflection facility message over the current channel.
166 Supported switches depend upon the version of libpri in use.</para>
169 <application name="DAHDIAcceptR2Call" language="en_US">
171 Accept an R2 call if its not already accepted (you still need to answer it)
174 <parameter name="charge" required="true">
175 <para>Yes or No.</para>
176 <para>Whether you want to accept the call with charge or without charge.</para>
180 <para>This application will Accept the R2 call either with charge or no charge.</para>
183 <manager name="DAHDITransfer" language="en_US">
185 Transfer 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 number to transfer.</para>
194 <para>Simulate a flash hook event by the user connected to the channel.</para>
195 <note><para>Valid only for analog channels.</para></note>
198 <manager name="DAHDIHangup" language="en_US">
200 Hangup DAHDI Channel.
203 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
204 <parameter name="DAHDIChannel" required="true">
205 <para>DAHDI channel number to hangup.</para>
209 <para>Simulate an on-hook event by the user connected to the channel.</para>
210 <note><para>Valid only for analog channels.</para></note>
213 <manager name="DAHDIDialOffhook" language="en_US">
215 Dial over DAHDI channel while offhook.
218 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
219 <parameter name="DAHDIChannel" required="true">
220 <para>DAHDI channel number to dial digits.</para>
222 <parameter name="Number" required="true">
223 <para>Digits to dial.</para>
227 <para>Generate DTMF control frames to the bridged peer.</para>
230 <manager name="DAHDIDNDon" language="en_US">
232 Toggle DAHDI channel Do Not Disturb status ON.
235 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
236 <parameter name="DAHDIChannel" required="true">
237 <para>DAHDI channel number to set DND on.</para>
241 <para>Equivalent to the CLI command "dahdi set dnd <variable>channel</variable> on".</para>
242 <note><para>Feature only supported by analog channels.</para></note>
245 <manager name="DAHDIDNDoff" language="en_US">
247 Toggle DAHDI channel Do Not Disturb status OFF.
250 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
251 <parameter name="DAHDIChannel" required="true">
252 <para>DAHDI channel number to set DND off.</para>
256 <para>Equivalent to the CLI command "dahdi set dnd <variable>channel</variable> off".</para>
257 <note><para>Feature only supported by analog channels.</para></note>
260 <manager name="DAHDIShowChannels" language="en_US">
262 Show status of DAHDI channels.
265 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
266 <parameter name="DAHDIChannel">
267 <para>Specify the specific channel number to show. Show all channels if zero or not present.</para>
271 <para>Similar to the CLI command "dahdi show channels".</para>
274 <manager name="DAHDIRestart" language="en_US">
276 Fully Restart DAHDI channels (terminates calls).
279 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
282 <para>Equivalent to the CLI command "dahdi restart".</para>
285 <manager name="PRIShowSpans" language="en_US">
287 Show status of PRI spans.
290 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
291 <parameter name="Span">
292 <para>Specify the specific span to show. Show all spans if zero or not present.</para>
296 <para>Similar to the CLI command "pri show spans".</para>
301 #define SMDI_MD_WAIT_TIMEOUT 1500 /* 1.5 seconds */
303 static const char * const lbostr[] = {
304 "0 db (CSU)/0-133 feet (DSX-1)",
305 "133-266 feet (DSX-1)",
306 "266-399 feet (DSX-1)",
307 "399-533 feet (DSX-1)",
308 "533-655 feet (DSX-1)",
314 /*! Global jitterbuffer configuration - by default, jb is disabled
315 * \note Values shown here match the defaults shown in chan_dahdi.conf.sample */
316 static struct ast_jb_conf default_jbconf =
320 .resync_threshold = 1000,
324 static struct ast_jb_conf global_jbconf;
327 * \note Define ZHONE_HACK to cause us to go off hook and then back on hook when
328 * the user hangs up to reset the state machine so ring works properly.
329 * This is used to be able to support kewlstart by putting the zhone in
330 * groundstart mode since their forward disconnect supervision is entirely
331 * broken even though their documentation says it isn't and their support
332 * is entirely unwilling to provide any assistance with their channel banks
333 * even though their web site says they support their products for life.
335 /* #define ZHONE_HACK */
337 /*! \brief Typically, how many rings before we should send Caller*ID */
338 #define DEFAULT_CIDRINGS 1
340 #define AST_LAW(p) (((p)->law == DAHDI_LAW_ALAW) ? AST_FORMAT_ALAW : AST_FORMAT_ULAW)
343 /*! \brief Signaling types that need to use MF detection should be placed in this macro */
344 #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))
346 static const char tdesc[] = "DAHDI Telephony Driver"
347 #if defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2)
349 #if defined(HAVE_PRI)
351 #endif /* defined(HAVE_PRI) */
352 #if defined(HAVE_SS7)
353 #if defined(HAVE_PRI)
355 #endif /* defined(HAVE_PRI) */
357 #endif /* defined(HAVE_SS7) */
358 #if defined(HAVE_OPENR2)
359 #if defined(HAVE_PRI) || defined(HAVE_SS7)
361 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
363 #endif /* defined(HAVE_OPENR2) */
364 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2) */
367 static const char config[] = "chan_dahdi.conf";
369 #define SIG_EM DAHDI_SIG_EM
370 #define SIG_EMWINK (0x0100000 | DAHDI_SIG_EM)
371 #define SIG_FEATD (0x0200000 | DAHDI_SIG_EM)
372 #define SIG_FEATDMF (0x0400000 | DAHDI_SIG_EM)
373 #define SIG_FEATB (0x0800000 | DAHDI_SIG_EM)
374 #define SIG_E911 (0x1000000 | DAHDI_SIG_EM)
375 #define SIG_FEATDMF_TA (0x2000000 | DAHDI_SIG_EM)
376 #define SIG_FGC_CAMA (0x4000000 | DAHDI_SIG_EM)
377 #define SIG_FGC_CAMAMF (0x8000000 | DAHDI_SIG_EM)
378 #define SIG_FXSLS DAHDI_SIG_FXSLS
379 #define SIG_FXSGS DAHDI_SIG_FXSGS
380 #define SIG_FXSKS DAHDI_SIG_FXSKS
381 #define SIG_FXOLS DAHDI_SIG_FXOLS
382 #define SIG_FXOGS DAHDI_SIG_FXOGS
383 #define SIG_FXOKS DAHDI_SIG_FXOKS
384 #define SIG_PRI DAHDI_SIG_CLEAR
385 #define SIG_BRI (0x2000000 | DAHDI_SIG_CLEAR)
386 #define SIG_BRI_PTMP (0X4000000 | DAHDI_SIG_CLEAR)
387 #define SIG_SS7 (0x1000000 | DAHDI_SIG_CLEAR)
388 #define SIG_MFCR2 DAHDI_SIG_CAS
389 #define SIG_SF DAHDI_SIG_SF
390 #define SIG_SFWINK (0x0100000 | DAHDI_SIG_SF)
391 #define SIG_SF_FEATD (0x0200000 | DAHDI_SIG_SF)
392 #define SIG_SF_FEATDMF (0x0400000 | DAHDI_SIG_SF)
393 #define SIG_SF_FEATB (0x0800000 | DAHDI_SIG_SF)
394 #define SIG_EM_E1 DAHDI_SIG_EM_E1
397 #define NUM_SPANS DAHDI_MAX_SPANS
402 #define CHAN_PSEUDO -2
404 #define CALLPROGRESS_PROGRESS 1
405 #define CALLPROGRESS_FAX_OUTGOING 2
406 #define CALLPROGRESS_FAX_INCOMING 4
407 #define CALLPROGRESS_FAX (CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING)
409 #define NUM_CADENCE_MAX 25
410 static int num_cadence = 4;
411 static int user_has_defined_cadences = 0;
413 static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX] = {
414 { { 125, 125, 2000, 4000 } }, /*!< Quick chirp followed by normal ring */
415 { { 250, 250, 500, 1000, 250, 250, 500, 4000 } }, /*!< British style ring */
416 { { 125, 125, 125, 125, 125, 4000 } }, /*!< Three short bursts */
417 { { 1000, 500, 2500, 5000 } }, /*!< Long ring */
420 /*! \brief cidrings says in which pause to transmit the cid information, where the first pause
421 * is 1, the second pause is 2 and so on.
424 static int cidrings[NUM_CADENCE_MAX] = {
425 2, /*!< Right after first long ring */
426 4, /*!< Right after long part */
427 3, /*!< After third chirp */
428 2, /*!< Second spell */
431 /* ETSI EN300 659-1 specifies the ring pulse between 200 and 300 mS */
432 static struct dahdi_ring_cadence AS_RP_cadence = {{250, 10000}};
434 #define ISTRUNK(p) ((p->sig == SIG_FXSLS) || (p->sig == SIG_FXSKS) || \
435 (p->sig == SIG_FXSGS) || (p->sig == SIG_PRI))
437 #define CANBUSYDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
438 #define CANPROGRESSDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
440 static char defaultcic[64] = "";
441 static char defaultozz[64] = "";
443 /*! Run this script when the MWI state changes on an FXO line, if mwimonitor is enabled */
444 static char mwimonitornotify[PATH_MAX] = "";
445 #ifndef HAVE_DAHDI_LINEREVERSE_VMWI
446 static int mwisend_rpas = 0;
449 static char progzone[10] = "";
451 static int usedistinctiveringdetection = 0;
452 static int distinctiveringaftercid = 0;
454 static int numbufs = 4;
456 static int mwilevel = 512;
457 static int dtmfcid_level = 256;
459 #define REPORT_CHANNEL_ALARMS 1
460 #define REPORT_SPAN_ALARMS 2
461 static int report_alarms = REPORT_CHANNEL_ALARMS;
464 static int pridebugfd = -1;
465 static char pridebugfilename[1024] = "";
468 /*! \brief Wait up to 16 seconds for first digit (FXO logic) */
469 static int firstdigittimeout = 16000;
471 /*! \brief How long to wait for following digits (FXO logic) */
472 static int gendigittimeout = 8000;
474 /*! \brief How long to wait for an extra digit, if there is an ambiguous match */
475 static int matchdigittimeout = 3000;
477 /*! \brief Protect the interface list (of dahdi_pvt's) */
478 AST_MUTEX_DEFINE_STATIC(iflock);
481 static int ifcount = 0;
484 AST_MUTEX_DEFINE_STATIC(pridebugfdlock);
487 /*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
488 when it's doing something critical. */
489 AST_MUTEX_DEFINE_STATIC(monlock);
491 /*! \brief This is the thread for the monitor which checks for input on the channels
492 which are not currently in use. */
493 static pthread_t monitor_thread = AST_PTHREADT_NULL;
494 static ast_cond_t ss_thread_complete;
495 AST_MUTEX_DEFINE_STATIC(ss_thread_lock);
496 AST_MUTEX_DEFINE_STATIC(restart_lock);
497 static int ss_thread_count = 0;
498 static int num_restart_pending = 0;
500 static int restart_monitor(void);
502 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);
504 static int dahdi_sendtext(struct ast_channel *c, const char *text);
506 static void mwi_event_cb(const struct ast_event *event, void *userdata)
508 /* This module does not handle MWI in an event-based manner. However, it
509 * subscribes to MWI for each mailbox that is configured so that the core
510 * knows that we care about it. Then, chan_dahdi will get the MWI from the
511 * event cache instead of checking the mailbox directly. */
514 /*! \brief Avoid the silly dahdi_getevent which ignores a bunch of events */
515 static inline int dahdi_get_event(int fd)
518 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
523 /*! \brief Avoid the silly dahdi_waitevent which ignores a bunch of events */
524 static inline int dahdi_wait_event(int fd)
527 i = DAHDI_IOMUX_SIGEVENT;
528 if (ioctl(fd, DAHDI_IOMUX, &i) == -1)
530 if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
535 /*! Chunk size to read -- we use 20ms chunks to make things happy. */
536 #define READ_SIZE 160
538 #define MASK_AVAIL (1 << 0) /*!< Channel available for PRI use */
539 #define MASK_INUSE (1 << 1) /*!< Channel currently in use */
541 #define CALLWAITING_SILENT_SAMPLES ((300 * 8) / READ_SIZE) /*!< 300 ms */
542 #define CALLWAITING_REPEAT_SAMPLES ((10000 * 8) / READ_SIZE) /*!< 10,000 ms */
543 #define CALLWAITING_SUPPRESS_SAMPLES ((100 * 8) / READ_SIZE) /*!< 100 ms */
544 #define CIDCW_EXPIRE_SAMPLES ((500 * 8) / READ_SIZE) /*!< 500 ms */
545 #define MIN_MS_SINCE_FLASH ((2000) ) /*!< 2000 ms */
546 #define DEFAULT_RINGT ((8000 * 8) / READ_SIZE) /*!< 8,000 ms */
547 #define DEFAULT_DIALTONE_DETECT_TIMEOUT ((10000 * 8) / READ_SIZE) /*!< 10,000 ms */
552 * \brief Configured ring timeout base.
553 * \note Value computed from "ringtimeout" read in from chan_dahdi.conf if it exists.
555 static int ringt_base = DEFAULT_RINGT;
557 #if defined(HAVE_SS7)
560 struct sig_ss7_linkset ss7;
563 static struct dahdi_ss7 linksets[NUM_SPANS];
565 static int cur_ss7type = -1;
566 static int cur_linkset = -1;
567 static int cur_pointcode = -1;
568 static int cur_cicbeginswith = -1;
569 static int cur_adjpointcode = -1;
570 static int cur_networkindicator = -1;
571 static int cur_defaultdpc = -1;
572 #endif /* defined(HAVE_SS7) */
576 pthread_t r2master; /*!< Thread of master */
577 openr2_context_t *protocol_context; /*!< OpenR2 context handle */
578 struct dahdi_pvt *pvts[SIG_MFCR2_MAX_CHANNELS]; /*!< Member channel pvt structs */
579 int numchans; /*!< Number of channels in this R2 block */
580 int monitored_count; /*!< Number of channels being monitored */
583 struct dahdi_mfcr2_conf {
584 openr2_variant_t variant;
586 int metering_pulse_timeout;
589 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
593 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3
594 int dtmf_end_timeout;
596 signed int get_ani_first:2;
597 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
598 signed int skip_category_request:2;
600 unsigned int call_files:1;
601 unsigned int allow_collect_calls:1;
602 unsigned int charge_calls:1;
603 unsigned int accept_on_offer:1;
604 unsigned int forced_release:1;
605 unsigned int double_answer:1;
606 signed int immediate_accept:2;
607 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
608 signed int dtmf_dialing:2;
609 signed int dtmf_detection:2;
611 char logdir[OR2_MAX_PATH];
612 char r2proto_file[OR2_MAX_PATH];
613 openr2_log_level_t loglevel;
614 openr2_calling_party_category_t category;
617 /* malloc'd array of malloc'd r2links */
618 static struct dahdi_mfcr2 **r2links;
619 /* how many r2links have been malloc'd */
620 static int r2links_count = 0;
622 #endif /* HAVE_OPENR2 */
627 int dchannels[SIG_PRI_NUM_DCHANS]; /*!< What channel are the dchannels on */
628 int mastertrunkgroup; /*!< What trunk group is our master */
629 int prilogicalspan; /*!< Logical span number within trunk group */
630 struct sig_pri_span pri;
633 static struct dahdi_pri pris[NUM_SPANS];
635 #if defined(HAVE_PRI_CCSS)
636 /*! DAHDI PRI CCSS agent and monitor type name. */
637 static const char dahdi_pri_cc_type[] = "DAHDI/PRI";
638 #endif /* defined(HAVE_PRI_CCSS) */
641 /*! Shut up the compiler */
645 #define SUB_REAL 0 /*!< Active call */
646 #define SUB_CALLWAIT 1 /*!< Call-Waiting call on hold */
647 #define SUB_THREEWAY 2 /*!< Three-way call */
649 /* Polarity states */
650 #define POLARITY_IDLE 0
651 #define POLARITY_REV 1
654 struct distRingData {
658 struct ringContextData {
659 char contextData[AST_MAX_CONTEXT];
661 struct dahdi_distRings {
662 struct distRingData ringnum[3];
663 struct ringContextData ringContext[3];
666 static const char * const subnames[] = {
672 struct dahdi_subchannel {
674 struct ast_channel *owner;
676 short buffer[AST_FRIENDLY_OFFSET/2 + READ_SIZE];
677 struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */
678 unsigned int needringing:1;
679 unsigned int needbusy:1;
680 unsigned int needcongestion:1;
681 unsigned int needanswer:1;
682 unsigned int needflash:1;
683 unsigned int needhold:1;
684 unsigned int needunhold:1;
685 unsigned int linear:1;
686 unsigned int inthreeway:1;
687 struct dahdi_confinfo curconf;
690 #define CONF_USER_REAL (1 << 0)
691 #define CONF_USER_THIRDCALL (1 << 1)
695 /* States for sending MWI message
696 * First three states are required for send Ring Pulse Alert Signal
708 struct mwisend_info {
709 struct timeval pause;
710 mwisend_states mwisend_current;
713 /*! Specify the lists dahdi_pvt can be put in. */
715 DAHDI_IFLIST_NONE, /*!< The dahdi_pvt is not in any list. */
716 DAHDI_IFLIST_MAIN, /*!< The dahdi_pvt is in the main interface list */
717 #if defined(HAVE_PRI)
718 DAHDI_IFLIST_NO_B_CHAN, /*!< The dahdi_pvt is in a no B channel interface list */
719 #endif /* defined(HAVE_PRI) */
723 ast_mutex_t lock; /*!< Channel private lock. */
724 struct callerid_state *cs;
725 struct ast_channel *owner; /*!< Our current active owner (if applicable) */
726 /*!< Up to three channels can be associated with this call */
728 struct dahdi_subchannel sub_unused; /*!< Just a safety precaution */
729 struct dahdi_subchannel subs[3]; /*!< Sub-channels */
730 struct dahdi_confinfo saveconf; /*!< Saved conference info */
732 struct dahdi_pvt *slaves[MAX_SLAVES]; /*!< Slave to us (follows our conferencing) */
733 struct dahdi_pvt *master; /*!< Master to us (we follow their conferencing) */
734 int inconference; /*!< If our real should be in the conference */
736 int bufsize; /*!< Size of the buffers */
737 int buf_no; /*!< Number of buffers */
738 int buf_policy; /*!< Buffer policy */
739 int faxbuf_no; /*!< Number of Fax buffers */
740 int faxbuf_policy; /*!< Fax buffer policy */
741 int sig; /*!< Signalling style */
743 * \brief Nonzero if the signaling type is sent over a radio.
744 * \note Set to a couple of nonzero values but it is only tested like a boolean.
747 int outsigmod; /*!< Outbound Signalling style (modifier) */
748 int oprmode; /*!< "Operator Services" mode */
749 struct dahdi_pvt *oprpeer; /*!< "Operator Services" peer tech_pvt ptr */
750 /*! \brief Amount of gain to increase during caller id */
752 /*! \brief Rx gain set by chan_dahdi.conf */
754 /*! \brief Tx gain set by chan_dahdi.conf */
757 float txdrc; /*!< Dynamic Range Compression factor. a number between 1 and 6ish */
760 int tonezone; /*!< tone zone for this chan, or -1 for default */
761 enum DAHDI_IFLIST which_iflist; /*!< Which interface list is this structure listed? */
762 struct dahdi_pvt *next; /*!< Next channel in list */
763 struct dahdi_pvt *prev; /*!< Prev channel in list */
768 * \brief TRUE if ADSI (Analog Display Services Interface) available
769 * \note Set from the "adsi" value read in from chan_dahdi.conf
773 * \brief TRUE if we can use a polarity reversal to mark when an outgoing
774 * call is answered by the remote party.
775 * \note Set from the "answeronpolarityswitch" value read in from chan_dahdi.conf
777 unsigned int answeronpolarityswitch:1;
779 * \brief TRUE if busy detection is enabled.
780 * (Listens for the beep-beep busy pattern.)
781 * \note Set from the "busydetect" value read in from chan_dahdi.conf
783 unsigned int busydetect:1;
785 * \brief TRUE if call return is enabled.
786 * (*69, if your dialplan doesn't catch this first)
787 * \note Set from the "callreturn" value read in from chan_dahdi.conf
789 unsigned int callreturn:1;
791 * \brief TRUE if busy extensions will hear the call-waiting tone
792 * and can use hook-flash to switch between callers.
793 * \note Can be disabled by dialing *70.
794 * \note Initialized with the "callwaiting" value read in from chan_dahdi.conf
796 unsigned int callwaiting:1;
798 * \brief TRUE if send caller ID for Call Waiting
799 * \note Set from the "callwaitingcallerid" value read in from chan_dahdi.conf
801 unsigned int callwaitingcallerid:1;
803 * \brief TRUE if support for call forwarding enabled.
804 * Dial *72 to enable call forwarding.
805 * Dial *73 to disable call forwarding.
806 * \note Set from the "cancallforward" value read in from chan_dahdi.conf
808 unsigned int cancallforward:1;
810 * \brief TRUE if support for call parking is enabled.
811 * \note Set from the "canpark" value read in from chan_dahdi.conf
813 unsigned int canpark:1;
814 /*! \brief TRUE if to wait for a DTMF digit to confirm answer */
815 unsigned int confirmanswer:1;
817 * \brief TRUE if the channel is to be destroyed on hangup.
818 * (Used by pseudo channels.)
820 unsigned int destroy:1;
821 unsigned int didtdd:1; /*!< flag to say its done it once */
822 /*! \brief TRUE if analog type line dialed no digits in Dial() */
823 unsigned int dialednone:1;
825 * \brief TRUE if in the process of dialing digits or sending something.
826 * \note This is used as a receive squelch for ISDN until connected.
828 unsigned int dialing:1;
829 /*! \brief TRUE if the transfer capability of the call is digital. */
830 unsigned int digital:1;
831 /*! \brief TRUE if Do-Not-Disturb is enabled, present only for non sig_analog */
833 /*! \brief XXX BOOLEAN Purpose??? */
834 unsigned int echobreak:1;
836 * \brief TRUE if echo cancellation enabled when bridged.
837 * \note Initialized with the "echocancelwhenbridged" value read in from chan_dahdi.conf
838 * \note Disabled if the echo canceller is not setup.
840 unsigned int echocanbridged:1;
841 /*! \brief TRUE if echo cancellation is turned on. */
842 unsigned int echocanon:1;
843 /*! \brief TRUE if a fax tone has already been handled. */
844 unsigned int faxhandled:1;
845 /*! TRUE if dynamic faxbuffers are configured for use, default is OFF */
846 unsigned int usefaxbuffers:1;
847 /*! TRUE while buffer configuration override is in use */
848 unsigned int bufferoverrideinuse:1;
849 /*! \brief TRUE if over a radio and dahdi_read() has been called. */
850 unsigned int firstradio:1;
852 * \brief TRUE if the call will be considered "hung up" on a polarity reversal.
853 * \note Set from the "hanguponpolarityswitch" value read in from chan_dahdi.conf
855 unsigned int hanguponpolarityswitch:1;
856 /*! \brief TRUE if DTMF detection needs to be done by hardware. */
857 unsigned int hardwaredtmf:1;
859 * \brief TRUE if the outgoing caller ID is blocked/hidden.
860 * \note Caller ID can be disabled by dialing *67.
861 * \note Caller ID can be enabled by dialing *82.
862 * \note Initialized with the "hidecallerid" value read in from chan_dahdi.conf
864 unsigned int hidecallerid:1;
866 * \brief TRUE if hide just the name not the number for legacy PBX use.
867 * \note Only applies to PRI channels.
868 * \note Set from the "hidecalleridname" value read in from chan_dahdi.conf
870 unsigned int hidecalleridname:1;
871 /*! \brief TRUE if DTMF detection is disabled. */
872 unsigned int ignoredtmf:1;
874 * \brief TRUE if the channel should be answered immediately
875 * without attempting to gather any digits.
876 * \note Set from the "immediate" value read in from chan_dahdi.conf
878 unsigned int immediate:1;
879 /*! \brief TRUE if in an alarm condition. */
880 unsigned int inalarm:1;
881 /*! \brief TRUE if TDD in MATE mode */
883 /*! \brief TRUE if we originated the call leg. */
884 unsigned int outgoing:1;
885 /* unsigned int overlapdial:1; unused and potentially confusing */
887 * \brief TRUE if busy extensions will hear the call-waiting tone
888 * and can use hook-flash to switch between callers.
889 * \note Set from the "callwaiting" value read in from chan_dahdi.conf
891 unsigned int permcallwaiting:1;
893 * \brief TRUE if the outgoing caller ID is blocked/restricted/hidden.
894 * \note Set from the "hidecallerid" value read in from chan_dahdi.conf
896 unsigned int permhidecallerid:1;
898 * \brief TRUE if PRI congestion/busy indications are sent out-of-band.
899 * \note Set from the "priindication" value read in from chan_dahdi.conf
901 unsigned int priindication_oob:1;
903 * \brief TRUE if PRI B channels are always exclusively selected.
904 * \note Set from the "priexclusive" value read in from chan_dahdi.conf
906 unsigned int priexclusive:1;
908 * \brief TRUE if we will pulse dial.
909 * \note Set from the "pulsedial" value read in from chan_dahdi.conf
911 unsigned int pulse:1;
912 /*! \brief TRUE if a pulsed digit was detected. (Pulse dial phone detected) */
913 unsigned int pulsedial:1;
914 unsigned int restartpending:1; /*!< flag to ensure counted only once for restart */
916 * \brief TRUE if caller ID is restricted.
917 * \note Set but not used. Should be deleted. Redundant with permhidecallerid.
918 * \note Set from the "restrictcid" value read in from chan_dahdi.conf
920 unsigned int restrictcid:1;
922 * \brief TRUE if three way calling is enabled
923 * \note Set from the "threewaycalling" value read in from chan_dahdi.conf
925 unsigned int threewaycalling:1;
927 * \brief TRUE if call transfer is enabled
928 * \note For FXS ports (either direct analog or over T1/E1):
929 * Support flash-hook call transfer
930 * \note For digital ports using ISDN PRI protocols:
931 * Support switch-side transfer (called 2BCT, RLT or other names)
932 * \note Set from the "transfer" value read in from chan_dahdi.conf
934 unsigned int transfer:1;
936 * \brief TRUE if caller ID is used on this channel.
937 * \note PRI and SS7 spans will save caller ID from the networking peer.
938 * \note FXS ports will generate the caller ID spill.
939 * \note FXO ports will listen for the caller ID spill.
940 * \note Set from the "usecallerid" value read in from chan_dahdi.conf
942 unsigned int use_callerid:1;
944 * \brief TRUE if we will use the calling presentation setting
945 * from the Asterisk channel for outgoing calls.
946 * \note Only applies to PRI and SS7 channels.
947 * \note Set from the "usecallingpres" value read in from chan_dahdi.conf
949 unsigned int use_callingpres:1;
951 * \brief TRUE if distinctive rings are to be detected.
952 * \note For FXO lines
953 * \note Set indirectly from the "usedistinctiveringdetection" value read in from chan_dahdi.conf
955 unsigned int usedistinctiveringdetection:1;
957 * \brief TRUE if we should use the callerid from incoming call on dahdi transfer.
958 * \note Set from the "useincomingcalleridondahditransfer" value read in from chan_dahdi.conf
960 unsigned int dahditrcallerid:1;
962 * \brief TRUE if allowed to flash-transfer to busy channels.
963 * \note Set from the "transfertobusy" value read in from chan_dahdi.conf
965 unsigned int transfertobusy:1;
967 * \brief TRUE if the FXO port monitors for neon type MWI indications from the other end.
968 * \note Set if the "mwimonitor" value read in contains "neon" from chan_dahdi.conf
970 unsigned int mwimonitor_neon:1;
972 * \brief TRUE if the FXO port monitors for fsk type MWI indications from the other end.
973 * \note Set if the "mwimonitor" value read in contains "fsk" from chan_dahdi.conf
975 unsigned int mwimonitor_fsk:1;
977 * \brief TRUE if the FXO port monitors for rpas precursor to fsk MWI indications from the other end.
978 * \note RPAS - Ring Pulse Alert Signal
979 * \note Set if the "mwimonitor" value read in contains "rpas" from chan_dahdi.conf
981 unsigned int mwimonitor_rpas:1;
982 /*! \brief TRUE if an MWI monitor thread is currently active */
983 unsigned int mwimonitoractive:1;
984 /*! \brief TRUE if a MWI message sending thread is active */
985 unsigned int mwisendactive:1;
987 * \brief TRUE if channel is out of reset and ready
988 * \note Set but not used.
990 unsigned int inservice:1;
992 * \brief TRUE if the channel is locally blocked.
993 * \note Applies to SS7 and MFCR2 channels.
995 unsigned int locallyblocked:1;
997 * \brief TRUE if the channel is remotely blocked.
998 * \note Applies to SS7 and MFCR2 channels.
1000 unsigned int remotelyblocked:1;
1002 * \brief TRUE if the channel alarms will be managed also as Span ones
1003 * \note Applies to all channels
1005 unsigned int manages_span_alarms:1;
1007 #if defined(HAVE_PRI)
1008 struct sig_pri_span *pri;
1012 * \brief TRUE if SMDI (Simplified Message Desk Interface) is enabled
1013 * \note Set from the "usesmdi" value read in from chan_dahdi.conf
1015 unsigned int use_smdi:1;
1016 struct mwisend_info mwisend_data;
1017 /*! \brief The SMDI interface to get SMDI messages from. */
1018 struct ast_smdi_interface *smdi_iface;
1020 /*! \brief Distinctive Ring data */
1021 struct dahdi_distRings drings;
1024 * \brief The configured context for incoming calls.
1025 * \note The "context" string read in from chan_dahdi.conf
1027 char context[AST_MAX_CONTEXT];
1029 * \brief A description for the channel configuration
1030 * \note The "description" string read in from chan_dahdi.conf
1032 char description[32];
1034 * \brief Saved context string.
1036 char defcontext[AST_MAX_CONTEXT];
1037 /*! \brief Extension to use in the dialplan. */
1038 char exten[AST_MAX_EXTENSION];
1040 * \brief Language configured for calls.
1041 * \note The "language" string read in from chan_dahdi.conf
1043 char language[MAX_LANGUAGE];
1045 * \brief The configured music-on-hold class to use for calls.
1046 * \note The "musicclass" or "mohinterpret" or "musiconhold" string read in from chan_dahdi.conf
1048 char mohinterpret[MAX_MUSICCLASS];
1050 * \brief Suggested music-on-hold class for peer channel to use for calls.
1051 * \note The "mohsuggest" string read in from chan_dahdi.conf
1053 char mohsuggest[MAX_MUSICCLASS];
1054 char parkinglot[AST_MAX_EXTENSION]; /*!< Parking lot for this channel */
1055 #if defined(HAVE_PRI) || defined(HAVE_SS7)
1056 /*! \brief Automatic Number Identification number (Alternate PRI caller ID number) */
1057 char cid_ani[AST_MAX_EXTENSION];
1058 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
1059 /*! \brief Automatic Number Identification code from PRI */
1061 /*! \brief Caller ID number from an incoming call. */
1062 char cid_num[AST_MAX_EXTENSION];
1064 * \brief Caller ID tag from incoming call
1065 * \note the "cid_tag" string read in from chan_dahdi.conf
1067 char cid_tag[AST_MAX_EXTENSION];
1068 /*! \brief Caller ID Q.931 TON/NPI field values. Set by PRI. Zero otherwise. */
1070 /*! \brief Caller ID name from an incoming call. */
1071 char cid_name[AST_MAX_EXTENSION];
1072 /*! \brief Caller ID subaddress from an incoming call. */
1073 char cid_subaddr[AST_MAX_EXTENSION];
1074 char *origcid_num; /*!< malloced original callerid */
1075 char *origcid_name; /*!< malloced original callerid */
1076 /*! \brief Call waiting number. */
1077 char callwait_num[AST_MAX_EXTENSION];
1078 /*! \brief Call waiting name. */
1079 char callwait_name[AST_MAX_EXTENSION];
1080 /*! \brief Redirecting Directory Number Information Service (RDNIS) number */
1081 char rdnis[AST_MAX_EXTENSION];
1082 /*! \brief Dialed Number Identifier */
1083 char dnid[AST_MAX_EXTENSION];
1085 * \brief Bitmapped groups this belongs to.
1086 * \note The "group" bitmapped group string read in from chan_dahdi.conf
1089 /*! \brief Default call PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW. */
1091 /*! \brief Active PCM encoding format: DAHDI_LAW_ALAW or DAHDI_LAW_MULAW */
1093 int confno; /*!< Our conference */
1094 int confusers; /*!< Who is using our conference */
1095 int propconfno; /*!< Propagated conference number */
1097 * \brief Bitmapped call groups this belongs to.
1098 * \note The "callgroup" bitmapped group string read in from chan_dahdi.conf
1100 ast_group_t callgroup;
1102 * \brief Bitmapped pickup groups this belongs to.
1103 * \note The "pickupgroup" bitmapped group string read in from chan_dahdi.conf
1105 ast_group_t pickupgroup;
1107 * \brief Named call groups this belongs to.
1108 * \note The "namedcallgroup" string read in from chan_dahdi.conf
1110 struct ast_namedgroups *named_callgroups;
1112 * \brief Named pickup groups this belongs to.
1113 * \note The "namedpickupgroup" string read in from chan_dahdi.conf
1115 struct ast_namedgroups *named_pickupgroups;
1117 * \brief Channel variable list with associated values to set when a channel is created.
1118 * \note The "setvar" strings read in from chan_dahdi.conf
1120 struct ast_variable *vars;
1121 int channel; /*!< Channel Number */
1122 int span; /*!< Span number */
1123 time_t guardtime; /*!< Must wait this much time before using for new call */
1124 int cid_signalling; /*!< CID signalling type bell202 or v23 */
1125 int cid_start; /*!< CID start indicator, polarity or ring or DTMF without warning event */
1126 int dtmfcid_holdoff_state; /*!< State indicator that allows for line to settle before checking for dtmf energy */
1127 struct timeval dtmfcid_delay; /*!< Time value used for allow line to settle */
1128 int callingpres; /*!< The value of calling presentation that we're going to use when placing a PRI call */
1129 int callwaitingrepeat; /*!< How many samples to wait before repeating call waiting */
1130 int cidcwexpire; /*!< When to stop waiting for CID/CW CAS response (In samples) */
1131 int cid_suppress_expire; /*!< How many samples to suppress after a CID spill. */
1132 /*! \brief Analog caller ID waveform sample buffer */
1133 unsigned char *cidspill;
1134 /*! \brief Position in the cidspill buffer to send out next. */
1136 /*! \brief Length of the cidspill buffer containing samples. */
1138 /*! \brief Ring timeout timer?? */
1141 * \brief Ring timeout base.
1142 * \note Value computed indirectly from "ringtimeout" read in from chan_dahdi.conf
1146 * \brief Number of most significant digits/characters to strip from the dialed number.
1147 * \note Feature is deprecated. Use dialplan logic.
1148 * \note The characters are stripped before the PRI TON/NPI prefix
1149 * characters are processed.
1153 * \brief TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
1155 * After CAS is sent, the call waiting caller id will be sent if the phone
1156 * gives a positive reply.
1159 /*! \brief Number of call waiting rings. */
1161 /*! \brief Echo cancel parameters. */
1163 struct dahdi_echocanparams head;
1164 struct dahdi_echocanparam params[DAHDI_MAX_ECHOCANPARAMS];
1167 * \brief Echo training time. 0 = disabled
1168 * \note Set from the "echotraining" value read in from chan_dahdi.conf
1171 /*! \brief Filled with 'w'. XXX Purpose?? */
1174 * \brief Number of times to see "busy" tone before hanging up.
1175 * \note Set from the "busycount" value read in from chan_dahdi.conf
1179 * \brief Busy cadence pattern description.
1180 * \note Set from the "busypattern" value read from chan_dahdi.conf
1182 struct ast_dsp_busy_pattern busy_cadence;
1184 * \brief Bitmapped call progress detection flags. CALLPROGRESS_xxx values.
1185 * \note Bits set from the "callprogress" and "faxdetect" values read in from chan_dahdi.conf
1189 * \brief Number of milliseconds to wait for dialtone.
1190 * \note Set from the "waitfordialtone" value read in from chan_dahdi.conf
1192 int waitfordialtone;
1194 * \brief Number of frames to watch for dialtone in incoming calls
1195 * \note Set from the "dialtone_detect" value read in from chan_dahdi.conf
1197 int dialtone_detect;
1198 int dialtone_scanning_time_elapsed; /*!< Amount of audio scanned for dialtone, in frames */
1199 struct timeval waitingfordt; /*!< Time we started waiting for dialtone */
1200 struct timeval flashtime; /*!< Last flash-hook time */
1201 /*! \brief Opaque DSP configuration structure. */
1202 struct ast_dsp *dsp;
1203 /*! \brief DAHDI dial operation command struct for ioctl() call. */
1204 struct dahdi_dialoperation dop;
1205 int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
1206 /*! \brief Second part of SIG_FEATDMF_TA wink operation. */
1208 char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
1209 int amaflags; /*!< AMA Flags */
1210 struct tdd_state *tdd; /*!< TDD flag */
1211 /*! \brief Accumulated call forwarding number. */
1212 char call_forward[AST_MAX_EXTENSION];
1214 * \brief Voice mailbox location.
1215 * \note Set from the "mailbox" string read in from chan_dahdi.conf
1217 char mailbox[AST_MAX_EXTENSION];
1218 /*! \brief Opaque event subscription parameters for message waiting indication support. */
1219 struct ast_event_sub *mwi_event_sub;
1220 /*! \brief Delayed dialing for E911. Overlap digits for ISDN. */
1222 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
1223 struct dahdi_vmwi_info mwisend_setting; /*!< Which VMWI methods to use */
1224 unsigned int mwisend_fsk: 1; /*! Variable for enabling FSK MWI handling in chan_dahdi */
1225 unsigned int mwisend_rpas:1; /*! Variable for enabling Ring Pulse Alert before MWI FSK Spill */
1227 int distinctivering; /*!< Which distinctivering to use */
1228 int dtmfrelax; /*!< whether to run in relaxed DTMF mode */
1229 /*! \brief Holding place for event injected from outside normal operation. */
1232 * \brief Minimal time period (ms) between the answer polarity
1233 * switch and hangup polarity switch.
1235 int polarityonanswerdelay;
1236 /*! \brief Start delay time if polarityonanswerdelay is nonzero. */
1237 struct timeval polaritydelaytv;
1239 * \brief Send caller ID on FXS after this many rings. Set to 1 for US.
1240 * \note Set from the "sendcalleridafter" value read in from chan_dahdi.conf
1242 int sendcalleridafter;
1243 /*! \brief Current line interface polarity. POLARITY_IDLE, POLARITY_REV */
1245 /*! \brief DSP feature flags: DSP_FEATURE_xxx */
1247 #if defined(HAVE_SS7)
1248 /*! \brief SS7 control parameters */
1249 struct sig_ss7_linkset *ss7;
1250 #endif /* defined(HAVE_SS7) */
1252 struct dahdi_mfcr2 *mfcr2;
1253 openr2_chan_t *r2chan;
1254 openr2_calling_party_category_t mfcr2_recvd_category;
1255 openr2_calling_party_category_t mfcr2_category;
1256 int mfcr2_dnis_index;
1257 int mfcr2_ani_index;
1259 int mfcr2_answer_pending:1;
1260 int mfcr2_charge_calls:1;
1261 int mfcr2_allow_collect_calls:1;
1262 int mfcr2_forced_release:1;
1263 int mfcr2_dnis_matched:1;
1264 int mfcr2_call_accepted:1;
1265 int mfcr2_accept_on_offer:1;
1266 int mfcr2_progress_sent:1;
1268 /*! \brief DTMF digit in progress. 0 when no digit in progress. */
1270 /*! \brief TRUE if confrence is muted. */
1273 struct ast_cc_config_params *cc_params;
1274 /* DAHDI channel names may differ greatly from the
1275 * string that was provided to an app such as Dial. We
1276 * need to save the original string passed to dahdi_request
1277 * for call completion purposes. This way, we can replicate
1278 * the original dialed string later.
1280 char dialstring[AST_CHANNEL_NAME];
1283 #define DATA_EXPORT_DAHDI_PVT(MEMBER) \
1284 MEMBER(dahdi_pvt, cid_rxgain, AST_DATA_DOUBLE) \
1285 MEMBER(dahdi_pvt, rxgain, AST_DATA_DOUBLE) \
1286 MEMBER(dahdi_pvt, txgain, AST_DATA_DOUBLE) \
1287 MEMBER(dahdi_pvt, txdrc, AST_DATA_DOUBLE) \
1288 MEMBER(dahdi_pvt, rxdrc, AST_DATA_DOUBLE) \
1289 MEMBER(dahdi_pvt, adsi, AST_DATA_BOOLEAN) \
1290 MEMBER(dahdi_pvt, answeronpolarityswitch, AST_DATA_BOOLEAN) \
1291 MEMBER(dahdi_pvt, busydetect, AST_DATA_BOOLEAN) \
1292 MEMBER(dahdi_pvt, callreturn, AST_DATA_BOOLEAN) \
1293 MEMBER(dahdi_pvt, callwaiting, AST_DATA_BOOLEAN) \
1294 MEMBER(dahdi_pvt, callwaitingcallerid, AST_DATA_BOOLEAN) \
1295 MEMBER(dahdi_pvt, cancallforward, AST_DATA_BOOLEAN) \
1296 MEMBER(dahdi_pvt, canpark, AST_DATA_BOOLEAN) \
1297 MEMBER(dahdi_pvt, confirmanswer, AST_DATA_BOOLEAN) \
1298 MEMBER(dahdi_pvt, destroy, AST_DATA_BOOLEAN) \
1299 MEMBER(dahdi_pvt, didtdd, AST_DATA_BOOLEAN) \
1300 MEMBER(dahdi_pvt, dialednone, AST_DATA_BOOLEAN) \
1301 MEMBER(dahdi_pvt, dialing, AST_DATA_BOOLEAN) \
1302 MEMBER(dahdi_pvt, digital, AST_DATA_BOOLEAN) \
1303 MEMBER(dahdi_pvt, dnd, AST_DATA_BOOLEAN) \
1304 MEMBER(dahdi_pvt, echobreak, AST_DATA_BOOLEAN) \
1305 MEMBER(dahdi_pvt, echocanbridged, AST_DATA_BOOLEAN) \
1306 MEMBER(dahdi_pvt, echocanon, AST_DATA_BOOLEAN) \
1307 MEMBER(dahdi_pvt, faxhandled, AST_DATA_BOOLEAN) \
1308 MEMBER(dahdi_pvt, usefaxbuffers, AST_DATA_BOOLEAN) \
1309 MEMBER(dahdi_pvt, bufferoverrideinuse, AST_DATA_BOOLEAN) \
1310 MEMBER(dahdi_pvt, firstradio, AST_DATA_BOOLEAN) \
1311 MEMBER(dahdi_pvt, hanguponpolarityswitch, AST_DATA_BOOLEAN) \
1312 MEMBER(dahdi_pvt, hardwaredtmf, AST_DATA_BOOLEAN) \
1313 MEMBER(dahdi_pvt, hidecallerid, AST_DATA_BOOLEAN) \
1314 MEMBER(dahdi_pvt, hidecalleridname, AST_DATA_BOOLEAN) \
1315 MEMBER(dahdi_pvt, ignoredtmf, AST_DATA_BOOLEAN) \
1316 MEMBER(dahdi_pvt, immediate, AST_DATA_BOOLEAN) \
1317 MEMBER(dahdi_pvt, inalarm, AST_DATA_BOOLEAN) \
1318 MEMBER(dahdi_pvt, mate, AST_DATA_BOOLEAN) \
1319 MEMBER(dahdi_pvt, outgoing, AST_DATA_BOOLEAN) \
1320 MEMBER(dahdi_pvt, permcallwaiting, AST_DATA_BOOLEAN) \
1321 MEMBER(dahdi_pvt, priindication_oob, AST_DATA_BOOLEAN) \
1322 MEMBER(dahdi_pvt, priexclusive, AST_DATA_BOOLEAN) \
1323 MEMBER(dahdi_pvt, pulse, AST_DATA_BOOLEAN) \
1324 MEMBER(dahdi_pvt, pulsedial, AST_DATA_BOOLEAN) \
1325 MEMBER(dahdi_pvt, restartpending, AST_DATA_BOOLEAN) \
1326 MEMBER(dahdi_pvt, restrictcid, AST_DATA_BOOLEAN) \
1327 MEMBER(dahdi_pvt, threewaycalling, AST_DATA_BOOLEAN) \
1328 MEMBER(dahdi_pvt, transfer, AST_DATA_BOOLEAN) \
1329 MEMBER(dahdi_pvt, use_callerid, AST_DATA_BOOLEAN) \
1330 MEMBER(dahdi_pvt, use_callingpres, AST_DATA_BOOLEAN) \
1331 MEMBER(dahdi_pvt, usedistinctiveringdetection, AST_DATA_BOOLEAN) \
1332 MEMBER(dahdi_pvt, dahditrcallerid, AST_DATA_BOOLEAN) \
1333 MEMBER(dahdi_pvt, transfertobusy, AST_DATA_BOOLEAN) \
1334 MEMBER(dahdi_pvt, mwimonitor_neon, AST_DATA_BOOLEAN) \
1335 MEMBER(dahdi_pvt, mwimonitor_fsk, AST_DATA_BOOLEAN) \
1336 MEMBER(dahdi_pvt, mwimonitor_rpas, AST_DATA_BOOLEAN) \
1337 MEMBER(dahdi_pvt, mwimonitoractive, AST_DATA_BOOLEAN) \
1338 MEMBER(dahdi_pvt, mwisendactive, AST_DATA_BOOLEAN) \
1339 MEMBER(dahdi_pvt, inservice, AST_DATA_BOOLEAN) \
1340 MEMBER(dahdi_pvt, locallyblocked, AST_DATA_BOOLEAN) \
1341 MEMBER(dahdi_pvt, remotelyblocked, AST_DATA_BOOLEAN) \
1342 MEMBER(dahdi_pvt, manages_span_alarms, AST_DATA_BOOLEAN) \
1343 MEMBER(dahdi_pvt, use_smdi, AST_DATA_BOOLEAN) \
1344 MEMBER(dahdi_pvt, context, AST_DATA_STRING) \
1345 MEMBER(dahdi_pvt, defcontext, AST_DATA_STRING) \
1346 MEMBER(dahdi_pvt, description, AST_DATA_STRING) \
1347 MEMBER(dahdi_pvt, exten, AST_DATA_STRING) \
1348 MEMBER(dahdi_pvt, language, AST_DATA_STRING) \
1349 MEMBER(dahdi_pvt, mohinterpret, AST_DATA_STRING) \
1350 MEMBER(dahdi_pvt, mohsuggest, AST_DATA_STRING) \
1351 MEMBER(dahdi_pvt, parkinglot, AST_DATA_STRING)
1353 AST_DATA_STRUCTURE(dahdi_pvt, DATA_EXPORT_DAHDI_PVT);
1355 static struct dahdi_pvt *iflist = NULL; /*!< Main interface list start */
1356 static struct dahdi_pvt *ifend = NULL; /*!< Main interface list end */
1358 #if defined(HAVE_PRI)
1359 static struct dahdi_parms_pseudo {
1360 int buf_no; /*!< Number of buffers */
1361 int buf_policy; /*!< Buffer policy */
1362 int faxbuf_no; /*!< Number of Fax buffers */
1363 int faxbuf_policy; /*!< Fax buffer policy */
1364 } dahdi_pseudo_parms;
1365 #endif /* defined(HAVE_PRI) */
1367 /*! \brief Channel configuration from chan_dahdi.conf .
1368 * This struct is used for parsing the [channels] section of chan_dahdi.conf.
1369 * Generally there is a field here for every possible configuration item.
1371 * The state of fields is saved along the parsing and whenever a 'channel'
1372 * statement is reached, the current dahdi_chan_conf is used to configure the
1373 * channel (struct dahdi_pvt)
1375 * \see dahdi_chan_init for the default values.
1377 struct dahdi_chan_conf {
1378 struct dahdi_pvt chan;
1380 struct dahdi_pri pri;
1383 #if defined(HAVE_SS7)
1384 struct dahdi_ss7 ss7;
1385 #endif /* defined(HAVE_SS7) */
1388 struct dahdi_mfcr2_conf mfcr2;
1390 struct dahdi_params timing;
1391 int is_sig_auto; /*!< Use channel signalling from DAHDI? */
1392 /*! Continue configuration even if a channel is not there. */
1393 int ignore_failed_channels;
1396 * \brief The serial port to listen for SMDI data on
1397 * \note Set from the "smdiport" string read in from chan_dahdi.conf
1399 char smdi_port[SMDI_MAX_FILENAME_LEN];
1402 /*! returns a new dahdi_chan_conf with default values (by-value) */
1403 static struct dahdi_chan_conf dahdi_chan_conf_default(void)
1405 /* recall that if a field is not included here it is initialized
1406 * to 0 or equivalent
1408 struct dahdi_chan_conf conf = {
1411 .nsf = PRI_NSF_NONE,
1412 .switchtype = PRI_SWITCH_NI2,
1413 .dialplan = PRI_UNKNOWN + 1,
1414 .localdialplan = PRI_NATIONAL_ISDN + 1,
1415 .nodetype = PRI_CPE,
1416 .qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL,
1418 #if defined(HAVE_PRI_CCSS)
1419 .cc_ptmp_recall_mode = 1,/* specificRecall */
1420 .cc_qsig_signaling_link_req = 1,/* retain */
1421 .cc_qsig_signaling_link_rsp = 1,/* retain */
1422 #endif /* defined(HAVE_PRI_CCSS) */
1427 .internationalprefix = "",
1428 .nationalprefix = "",
1430 .privateprefix = "",
1431 .unknownprefix = "",
1432 .colp_send = SIG_PRI_COLP_UPDATE,
1433 .resetinterval = -1,
1436 #if defined(HAVE_SS7)
1438 .called_nai = SS7_NAI_NATIONAL,
1439 .calling_nai = SS7_NAI_NATIONAL,
1440 .internationalprefix = "",
1441 .nationalprefix = "",
1442 .subscriberprefix = "",
1445 #endif /* defined(HAVE_SS7) */
1448 .variant = OR2_VAR_ITU,
1449 .mfback_timeout = -1,
1450 .metering_pulse_timeout = -1,
1453 .get_ani_first = -1,
1454 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
1455 .skip_category_request = -1,
1458 .allow_collect_calls = 0,
1460 .accept_on_offer = 1,
1461 .forced_release = 0,
1463 .immediate_accept = -1,
1464 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
1466 .dtmf_detection = -1,
1467 .dtmf_time_on = OR2_DEFAULT_DTMF_ON,
1468 .dtmf_time_off = OR2_DEFAULT_DTMF_OFF,
1470 #if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3
1471 .dtmf_end_timeout = -1,
1475 .loglevel = OR2_LOG_ERROR | OR2_LOG_WARNING,
1476 .category = OR2_CALLING_PARTY_CATEGORY_NATIONAL_SUBSCRIBER
1480 .context = "default",
1484 .mohinterpret = "default",
1487 .transfertobusy = 1,
1489 .cid_signalling = CID_SIG_BELL,
1490 .cid_start = CID_START_RING,
1491 .dahditrcallerid = 0,
1500 .echocancel.head.tap_length = 1,
1508 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
1511 .polarityonanswerdelay = 600,
1513 .sendcalleridafter = DEFAULT_CIDRINGS,
1515 .buf_policy = DAHDI_POLICY_IMMEDIATE,
1518 .cc_params = ast_cc_config_params_init(),
1531 .smdi_port = "/dev/ttyS0",
1538 static struct ast_channel *dahdi_request(const char *type, struct ast_format_cap *cap, const struct ast_channel *requestor, const char *data, int *cause);
1539 static int dahdi_digit_begin(struct ast_channel *ast, char digit);
1540 static int dahdi_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
1541 static int dahdi_sendtext(struct ast_channel *c, const char *text);
1542 static int dahdi_call(struct ast_channel *ast, const char *rdest, int timeout);
1543 static int dahdi_hangup(struct ast_channel *ast);
1544 static int dahdi_answer(struct ast_channel *ast);
1545 static struct ast_frame *dahdi_read(struct ast_channel *ast);
1546 static int dahdi_write(struct ast_channel *ast, struct ast_frame *frame);
1547 static struct ast_frame *dahdi_exception(struct ast_channel *ast);
1548 static int dahdi_indicate(struct ast_channel *chan, int condition, const void *data, size_t datalen);
1549 static int dahdi_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
1550 static int dahdi_setoption(struct ast_channel *chan, int option, void *data, int datalen);
1551 static int dahdi_queryoption(struct ast_channel *chan, int option, void *data, int *datalen);
1552 static int dahdi_func_read(struct ast_channel *chan, const char *function, char *data, char *buf, size_t len);
1553 static int dahdi_func_write(struct ast_channel *chan, const char *function, char *data, const char *value);
1554 static int dahdi_devicestate(const char *data);
1555 static int dahdi_cc_callback(struct ast_channel *inbound, const char *dest, ast_cc_callback_fn callback);
1557 static struct ast_channel_tech dahdi_tech = {
1559 .description = tdesc,
1560 .requester = dahdi_request,
1561 .send_digit_begin = dahdi_digit_begin,
1562 .send_digit_end = dahdi_digit_end,
1563 .send_text = dahdi_sendtext,
1565 .hangup = dahdi_hangup,
1566 .answer = dahdi_answer,
1568 .write = dahdi_write,
1569 .bridge = dahdi_bridge,
1570 .exception = dahdi_exception,
1571 .indicate = dahdi_indicate,
1572 .fixup = dahdi_fixup,
1573 .setoption = dahdi_setoption,
1574 .queryoption = dahdi_queryoption,
1575 .func_channel_read = dahdi_func_read,
1576 .func_channel_write = dahdi_func_write,
1577 .devicestate = dahdi_devicestate,
1578 .cc_callback = dahdi_cc_callback,
1581 #define GET_CHANNEL(p) ((p)->channel)
1583 #define SIG_PRI_LIB_HANDLE_CASES \
1590 * \brief Determine if sig_pri handles the signaling.
1593 * \param signaling Signaling to determine if is for sig_pri.
1595 * \return TRUE if the signaling is for sig_pri.
1597 static inline int dahdi_sig_pri_lib_handles(int signaling)
1601 switch (signaling) {
1602 case SIG_PRI_LIB_HANDLE_CASES:
1613 static int analog_lib_handles(int signalling, int radio, int oprmode)
1615 switch (signalling) {
1629 case SIG_FGC_CAMAMF:
1634 case SIG_SF_FEATDMF:
1635 case SIG_FEATDMF_TA:
1639 /* The rest of the function should cover the remainder of signalling types */
1654 static enum analog_sigtype dahdisig_to_analogsig(int sig)
1658 return ANALOG_SIG_FXOLS;
1660 return ANALOG_SIG_FXOGS;
1662 return ANALOG_SIG_FXOKS;
1664 return ANALOG_SIG_FXSLS;
1666 return ANALOG_SIG_FXSGS;
1668 return ANALOG_SIG_FXSKS;
1670 return ANALOG_SIG_EMWINK;
1672 return ANALOG_SIG_EM;
1674 return ANALOG_SIG_EM_E1;
1676 return ANALOG_SIG_FEATD;
1678 return ANALOG_SIG_FEATDMF;
1682 return ANALOG_SIG_FGC_CAMA;
1683 case SIG_FGC_CAMAMF:
1684 return ANALOG_SIG_FGC_CAMAMF;
1686 return ANALOG_SIG_FEATB;
1688 return ANALOG_SIG_SFWINK;
1690 return ANALOG_SIG_SF;
1692 return ANALOG_SIG_SF_FEATD;
1693 case SIG_SF_FEATDMF:
1694 return ANALOG_SIG_SF_FEATDMF;
1695 case SIG_FEATDMF_TA:
1696 return ANALOG_SIG_FEATDMF_TA;
1698 return ANALOG_SIG_FEATB;
1705 static int analog_tone_to_dahditone(enum analog_tone tone)
1708 case ANALOG_TONE_RINGTONE:
1709 return DAHDI_TONE_RINGTONE;
1710 case ANALOG_TONE_STUTTER:
1711 return DAHDI_TONE_STUTTER;
1712 case ANALOG_TONE_CONGESTION:
1713 return DAHDI_TONE_CONGESTION;
1714 case ANALOG_TONE_DIALTONE:
1715 return DAHDI_TONE_DIALTONE;
1716 case ANALOG_TONE_DIALRECALL:
1717 return DAHDI_TONE_DIALRECALL;
1718 case ANALOG_TONE_INFO:
1719 return DAHDI_TONE_INFO;
1725 static int analogsub_to_dahdisub(enum analog_sub analogsub)
1729 switch (analogsub) {
1730 case ANALOG_SUB_REAL:
1733 case ANALOG_SUB_CALLWAIT:
1734 index = SUB_CALLWAIT;
1736 case ANALOG_SUB_THREEWAY:
1737 index = SUB_THREEWAY;
1740 ast_log(LOG_ERROR, "Unidentified sub!\n");
1749 * \brief Send a dial string to DAHDI.
1752 * \param pvt DAHDI private pointer
1753 * \param operation DAHDI dial operation to do to string
1754 * \param dial_str Dial string to send
1756 * \retval 0 on success.
1757 * \retval non-zero on error.
1759 static int dahdi_dial_str(struct dahdi_pvt *pvt, int operation, const char *dial_str)
1764 struct dahdi_dialoperation zo = {
1768 /* Convert the W's to ww. */
1770 for (offset = 0; offset < sizeof(zo.dialstr) - 1; ++offset) {
1775 /* Convert 'W' to "ww" */
1777 if (offset >= sizeof(zo.dialstr) - 3) {
1778 /* No room to expand */
1781 zo.dialstr[offset] = 'w';
1783 zo.dialstr[offset] = 'w';
1786 zo.dialstr[offset] = *pos++;
1788 /* The zo initialization has already terminated the dialstr. */
1790 ast_debug(1, "Channel %d: Dial str '%s' expanded to '%s' sent to DAHDI_DIAL.\n",
1791 pvt->channel, dial_str, zo.dialstr);
1792 res = ioctl(pvt->subs[SUB_REAL].dfd, DAHDI_DIAL, &zo);
1794 ast_log(LOG_WARNING, "Channel %d: Couldn't dial '%s': %s\n",
1795 pvt->channel, dial_str, strerror(errno));
1801 static enum analog_event dahdievent_to_analogevent(int event);
1802 static int bump_gains(struct dahdi_pvt *p);
1803 static int dahdi_setlinear(int dfd, int linear);
1805 static int my_start_cid_detect(void *pvt, int cid_signalling)
1807 struct dahdi_pvt *p = pvt;
1808 int index = SUB_REAL;
1809 p->cs = callerid_new(cid_signalling);
1811 ast_log(LOG_ERROR, "Unable to alloc callerid\n");
1815 dahdi_setlinear(p->subs[index].dfd, 0);
1820 static int my_stop_cid_detect(void *pvt)
1822 struct dahdi_pvt *p = pvt;
1823 int index = SUB_REAL;
1825 callerid_free(p->cs);
1826 dahdi_setlinear(p->subs[index].dfd, p->subs[index].linear);
1830 static int my_get_callerid(void *pvt, char *namebuf, char *numbuf, enum analog_event *ev, size_t timeout)
1832 struct dahdi_pvt *p = pvt;
1833 struct analog_pvt *analog_p = p->sig_pvt;
1834 struct pollfd poller;
1836 int index = SUB_REAL;
1838 unsigned char buf[256];
1840 struct ast_format tmpfmt;
1842 poller.fd = p->subs[SUB_REAL].dfd;
1843 poller.events = POLLPRI | POLLIN;
1846 res = poll(&poller, 1, timeout);
1848 if (poller.revents & POLLPRI) {
1849 *ev = dahdievent_to_analogevent(dahdi_get_event(p->subs[SUB_REAL].dfd));
1853 if (poller.revents & POLLIN) {
1855 /* Change API: remove cid_signalling from get_callerid, add a new start_cid_detect and stop_cid_detect function
1856 * to enable slin mode and allocate cid detector. get_callerid should be able to be called any number of times until
1857 * either a timeout occurs or CID is detected (returns 0). returning 1 should be event received, and -1 should be
1858 * a failure and die, and returning 2 means no event was received. */
1859 res = read(p->subs[index].dfd, buf, sizeof(buf));
1861 if (errno != ELAST) {
1862 ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
1863 callerid_free(p->cs);
1868 if (analog_p->ringt > 0) {
1869 if (!(--analog_p->ringt)) {
1870 /* only return if we timeout from a ring event */
1875 if (p->cid_signalling == CID_SIG_V23_JP) {
1876 res = callerid_feed_jp(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1878 res = callerid_feed(p->cs, buf, res, ast_format_set(&tmpfmt, AST_LAW(p), 0));
1882 * The previous diagnostic message output likely
1883 * explains why it failed.
1885 ast_log(LOG_WARNING, "Failed to decode CallerID\n");
1890 callerid_get(p->cs, &name, &num, &flags);
1892 ast_copy_string(namebuf, name, ANALOG_MAX_CID);
1894 ast_copy_string(numbuf, num, ANALOG_MAX_CID);
1896 ast_debug(1, "CallerID number: %s, name: %s, flags=%d\n", num, name, flags);
1901 *ev = ANALOG_EVENT_NONE;
1905 static const char *event2str(int event);
1906 static int restore_gains(struct dahdi_pvt *p);
1908 static int my_distinctive_ring(struct ast_channel *chan, void *pvt, int idx, int *ringdata)
1910 unsigned char buf[256];
1912 int curRingData[RING_PATTERNS];
1918 int checkaftercid = 0;
1920 struct dahdi_pvt *p = pvt;
1921 struct analog_pvt *analog_p = p->sig_pvt;
1923 if (ringdata == NULL) {
1924 ringdata = curRingData;
1929 /* We must have a ring by now, so, if configured, lets try to listen for
1930 * distinctive ringing */
1931 if ((checkaftercid && distinctiveringaftercid) || !checkaftercid) {
1932 /* Clear the current ring data array so we don't have old data in it. */
1933 for (receivedRingT = 0; receivedRingT < RING_PATTERNS; receivedRingT++)
1934 ringdata[receivedRingT] = 0;
1936 if (checkaftercid && distinctiveringaftercid)
1937 ast_verb(3, "Detecting post-CID distinctive ring\n");
1938 /* Check to see if context is what it should be, if not set to be. */
1939 else if (strcmp(p->context,p->defcontext) != 0) {
1940 ast_copy_string(p->context, p->defcontext, sizeof(p->context));
1941 ast_channel_context_set(chan, p->defcontext);
1945 i = DAHDI_IOMUX_READ | DAHDI_IOMUX_SIGEVENT;
1946 if ((res = ioctl(p->subs[idx].dfd, DAHDI_IOMUX, &i))) {
1947 ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
1951 if (i & DAHDI_IOMUX_SIGEVENT) {
1952 res = dahdi_get_event(p->subs[idx].dfd);
1953 if (res == DAHDI_EVENT_NOALARM) {
1955 analog_p->inalarm = 0;
1957 ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
1959 /* Let us detect distinctive ring */
1961 ringdata[receivedRingT] = analog_p->ringt;
1963 if (analog_p->ringt < analog_p->ringt_base/2)
1965 /* Increment the ringT counter so we can match it against
1966 values in chan_dahdi.conf for distinctive ring */
1967 if (++receivedRingT == RING_PATTERNS)
1969 } else if (i & DAHDI_IOMUX_READ) {
1970 res = read(p->subs[idx].dfd, buf, sizeof(buf));
1972 if (errno != ELAST) {
1973 ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
1979 if (analog_p->ringt > 0) {
1980 if (!(--analog_p->ringt)) {
1988 if ((checkaftercid && usedistinctiveringdetection) || !checkaftercid) {
1989 /* this only shows up if you have n of the dring patterns filled in */
1990 ast_verb(3, "Detected ring pattern: %d,%d,%d\n",ringdata[0],ringdata[1],ringdata[2]);
1991 for (counter = 0; counter < 3; counter++) {
1992 /* Check to see if the rings we received match any of the ones in chan_dahdi.conf for this channel */
1994 /* this only shows up if you have n of the dring patterns filled in */
1995 ast_verb(3, "Checking %d,%d,%d\n",
1996 p->drings.ringnum[counter].ring[0],
1997 p->drings.ringnum[counter].ring[1],
1998 p->drings.ringnum[counter].ring[2]);
1999 for (counter1 = 0; counter1 < 3; counter1++) {
2000 ast_verb(3, "Ring pattern check range: %d\n", p->drings.ringnum[counter].range);
2001 if (p->drings.ringnum[counter].ring[counter1] == -1) {
2002 ast_verb(3, "Pattern ignore (-1) detected, so matching pattern %d regardless.\n",
2003 ringdata[counter1]);
2005 } else if (ringdata[counter1] <= (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range) &&
2006 ringdata[counter1] >= (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range)) {
2007 ast_verb(3, "Ring pattern matched in range: %d to %d\n",
2008 (p->drings.ringnum[counter].ring[counter1] - p->drings.ringnum[counter].range),
2009 (p->drings.ringnum[counter].ring[counter1] + p->drings.ringnum[counter].range));
2014 if (distMatches == 3) {
2015 /* The ring matches, set the context to whatever is for distinctive ring.. */
2016 ast_copy_string(p->context, S_OR(p->drings.ringContext[counter].contextData, p->defcontext), sizeof(p->context));
2017 ast_channel_context_set(chan, S_OR(p->drings.ringContext[counter].contextData, p->defcontext));
2018 ast_verb(3, "Distinctive Ring matched context %s\n",p->context);
2023 /* Restore linear mode (if appropriate) for Caller*ID processing */
2024 dahdi_setlinear(p->subs[idx].dfd, p->subs[idx].linear);
2030 static int my_stop_callwait(void *pvt)
2032 struct dahdi_pvt *p = pvt;
2033 p->callwaitingrepeat = 0;
2035 p->cid_suppress_expire = 0;
2040 static int send_callerid(struct dahdi_pvt *p);
2041 static int save_conference(struct dahdi_pvt *p);
2042 static int restore_conference(struct dahdi_pvt *p);
2044 static int my_callwait(void *pvt)
2046 struct dahdi_pvt *p = pvt;
2047 struct ast_format tmpfmt;
2048 p->callwaitingrepeat = CALLWAITING_REPEAT_SAMPLES;
2050 ast_log(LOG_WARNING, "Spill already exists?!?\n");
2051 ast_free(p->cidspill);
2055 * SAS: Subscriber Alert Signal, 440Hz for 300ms
2056 * CAS: CPE Alert Signal, 2130Hz * 2750Hz sine waves
2058 if (!(p->cidspill = ast_malloc(2400 /* SAS */ + 680 /* CAS */ + READ_SIZE * 4)))
2062 memset(p->cidspill, 0x7f, 2400 + 600 + READ_SIZE * 4);
2063 if (!p->callwaitrings && p->callwaitingcallerid) {
2064 ast_gen_cas(p->cidspill, 1, 2400 + 680, ast_format_set(&tmpfmt, AST_LAW(p), 0));
2066 p->cidlen = 2400 + 680 + READ_SIZE * 4;
2068 ast_gen_cas(p->cidspill, 1, 2400, ast_format_set(&tmpfmt, AST_LAW(p), 0));
2070 p->cidlen = 2400 + READ_SIZE * 4;
2078 static int my_send_callerid(void *pvt, int cwcid, struct ast_party_caller *caller)
2080 struct dahdi_pvt *p = pvt;
2081 struct ast_format tmpfmt;
2083 ast_debug(2, "Starting cid spill\n");
2086 ast_log(LOG_WARNING, "cidspill already exists??\n");
2087 ast_free(p->cidspill);
2090 if ((p->cidspill = ast_malloc(MAX_CALLERID_SIZE))) {
2092 p->cidlen = ast_callerid_generate(p->cidspill,
2093 caller->id.name.str,
2094 caller->id.number.str,
2095 ast_format_set(&tmpfmt, AST_LAW(p), 0));
2097 ast_verb(3, "CPE supports Call Waiting Caller*ID. Sending '%s/%s'\n",
2098 caller->id.name.str, caller->id.number.str);
2101 p->cidlen = ast_callerid_callwaiting_generate(p->cidspill,
2102 caller->id.name.str,
2103 caller->id.number.str,
2104 ast_format_set(&tmpfmt, AST_LAW(p), 0));
2105 p->cidlen += READ_SIZE * 4;
2108 p->cid_suppress_expire = 0;
2114 static int my_dsp_reset_and_flush_digits(void *pvt)
2116 struct dahdi_pvt *p = pvt;
2118 ast_dsp_digitreset(p->dsp);
2123 static int my_dsp_set_digitmode(void *pvt, enum analog_dsp_digitmode mode)
2125 struct dahdi_pvt *p = pvt;
2127 if (p->channel == CHAN_PSEUDO)
2128 ast_log(LOG_ERROR, "You have assumed incorrectly sir!\n");
2130 if (mode == ANALOG_DIGITMODE_DTMF) {
2131 /* If we do hardware dtmf, no need for a DSP */
2132 if (p->hardwaredtmf) {
2134 ast_dsp_free(p->dsp);
2141 p->dsp = ast_dsp_new();
2143 ast_log(LOG_ERROR, "Unable to allocate DSP\n");
2148 ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | p->dtmfrelax);
2149 } else if (mode == ANALOG_DIGITMODE_MF) {
2151 p->dsp = ast_dsp_new();
2153 ast_log(LOG_ERROR, "Unable to allocate DSP\n");
2157 ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_MF | p->dtmfrelax);
2162 static int dahdi_wink(struct dahdi_pvt *p, int index);
2164 static int my_wink(void *pvt, enum analog_sub sub)
2166 struct dahdi_pvt *p = pvt;
2167 int index = analogsub_to_dahdisub(sub);
2168 if (index != SUB_REAL) {
2169 ast_log(LOG_ERROR, "We used a sub other than SUB_REAL (incorrect assumption sir)\n");
2171 return dahdi_wink(p, index);
2174 static void wakeup_sub(struct dahdi_pvt *p, int a);
2176 static int reset_conf(struct dahdi_pvt *p);
2178 static inline int dahdi_confmute(struct dahdi_pvt *p, int muted);
2180 static void my_handle_dtmf(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
2182 struct ast_frame *f = *dest;
2183 struct dahdi_pvt *p = pvt;
2184 int idx = analogsub_to_dahdisub(analog_index);
2186 ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n",
2187 f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End",
2188 f->subclass.integer, f->subclass.integer, ast_channel_name(ast));
2190 if (f->subclass.integer == 'f') {
2191 if (f->frametype == AST_FRAME_DTMF_END) {
2192 /* Fax tone -- Handle and return NULL */
2193 if ((p->callprogress & CALLPROGRESS_FAX) && !p->faxhandled) {
2194 /* If faxbuffers are configured, use them for the fax transmission */
2195 if (p->usefaxbuffers && !p->bufferoverrideinuse) {
2196 struct dahdi_bufferinfo bi = {
2197 .txbufpolicy = p->faxbuf_policy,
2198 .bufsize = p->bufsize,
2199 .numbufs = p->faxbuf_no
2203 if ((res = ioctl(p->subs[idx].dfd, DAHDI_SET_BUFINFO, &bi)) < 0) {
2204 ast_log(LOG_WARNING, "Channel '%s' unable to set buffer policy, reason: %s\n", ast_channel_name(ast), strerror(errno));
2206 p->bufferoverrideinuse = 1;
2211 p->dsp_features &= ~DSP_FEATURE_FAX_DETECT;
2212 ast_dsp_set_features(p->dsp, p->dsp_features);
2213 ast_debug(1, "Disabling FAX tone detection on %s after tone received\n", ast_channel_name(ast));
2215 if (strcmp(ast_channel_exten(ast), "fax")) {
2216 const char *target_context = S_OR(ast_channel_macrocontext(ast), ast_channel_context(ast));
2218 /* We need to unlock 'ast' here because ast_exists_extension has the
2219 * potential to start autoservice on the channel. Such action is prone
2222 ast_mutex_unlock(&p->lock);
2223 ast_channel_unlock(ast);
2224 if (ast_exists_extension(ast, target_context, "fax", 1,
2225 S_COR(ast_channel_caller(ast)->id.number.valid, ast_channel_caller(ast)->id.number.str, NULL))) {
2226 ast_channel_lock(ast);
2227 ast_mutex_lock(&p->lock);
2228 ast_verb(3, "Redirecting %s to fax extension\n", ast_channel_name(ast));
2229 /* Save the DID/DNIS when we transfer the fax call to a "fax" extension */
2230 pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast_channel_exten(ast));
2231 if (ast_async_goto(ast, target_context, "fax", 1))
2232 ast_log(LOG_WARNING, "Failed to async goto '%s' into fax of '%s'\n", ast_channel_name(ast), target_context);
2234 ast_channel_lock(ast);
2235 ast_mutex_lock(&p->lock);
2236 ast_log(LOG_NOTICE, "Fax detected, but no fax extension\n");
2239 ast_debug(1, "Already in a fax extension, not redirecting\n");
2242 ast_debug(1, "Fax already handled\n");
2244 dahdi_confmute(p, 0);
2246 p->subs[idx].f.frametype = AST_FRAME_NULL;
2247 p->subs[idx].f.subclass.integer = 0;
2248 *dest = &p->subs[idx].f;
2252 static void my_lock_private(void *pvt)
2254 struct dahdi_pvt *p = pvt;
2255 ast_mutex_lock(&p->lock);
2258 static void my_unlock_private(void *pvt)
2260 struct dahdi_pvt *p = pvt;
2261 ast_mutex_unlock(&p->lock);
2264 static void my_deadlock_avoidance_private(void *pvt)
2266 struct dahdi_pvt *p = pvt;
2268 DEADLOCK_AVOIDANCE(&p->lock);
2273 * \brief Post an AMI DAHDI channel association event.
2276 * \param p DAHDI private pointer
2277 * \param chan Channel associated with the private pointer
2281 static void dahdi_ami_channel_event(struct dahdi_pvt *p, struct ast_channel *chan)
2285 if (p->channel < CHAN_PSEUDO) {
2287 snprintf(ch_name, sizeof(ch_name), "no-media (%d)", p->channel);
2288 } else if (p->channel == CHAN_PSEUDO) {
2289 /* Pseudo channel */
2290 strcpy(ch_name, "pseudo");
2293 snprintf(ch_name, sizeof(ch_name), "%d", p->channel);
2296 <managerEventInstance>
2297 <synopsis>Raised when a DAHDI channel is created or an underlying technology is associated with a DAHDI channel.</synopsis>
2298 </managerEventInstance>
2300 ast_manager_event(chan, EVENT_FLAG_CALL, "DAHDIChannel",
2304 "DAHDIChannel: %s\r\n",
2305 ast_channel_name(chan),
2306 ast_channel_uniqueid(chan),
2314 * \brief Post an AMI DAHDI channel association event.
2317 * \param pvt DAHDI private pointer
2318 * \param chan Channel associated with the private pointer
2322 static void my_ami_channel_event(void *pvt, struct ast_channel *chan)
2324 struct dahdi_pvt *p = pvt;
2326 dahdi_ami_channel_event(p, chan);
2330 /* linear_mode = 0 - turn linear mode off, >0 - turn linear mode on
2331 * returns the last value of the linear setting
2333 static int my_set_linear_mode(void *pvt, enum analog_sub sub, int linear_mode)
2335 struct dahdi_pvt *p = pvt;
2337 int idx = analogsub_to_dahdisub(sub);
2339 dahdi_setlinear(p->subs[idx].dfd, linear_mode);
2340 oldval = p->subs[idx].linear;
2341 p->subs[idx].linear = linear_mode ? 1 : 0;
2345 static void my_set_inthreeway(void *pvt, enum analog_sub sub, int inthreeway)
2347 struct dahdi_pvt *p = pvt;
2348 int idx = analogsub_to_dahdisub(sub);
2350 p->subs[idx].inthreeway = inthreeway;
2353 static int get_alarms(struct dahdi_pvt *p);
2354 static void handle_alarms(struct dahdi_pvt *p, int alms);
2355 static void my_get_and_handle_alarms(void *pvt)
2358 struct dahdi_pvt *p = pvt;
2360 res = get_alarms(p);
2361 handle_alarms(p, res);
2364 static void *my_get_sigpvt_bridged_channel(struct ast_channel *chan)
2366 struct ast_channel *bridged = ast_bridged_channel(chan);
2368 if (bridged && ast_channel_tech(bridged) == &dahdi_tech) {
2369 struct dahdi_pvt *p = ast_channel_tech_pvt(bridged);
2371 if (analog_lib_handles(p->sig, p->radio, p->oprmode)) {
2378 static int my_get_sub_fd(void *pvt, enum analog_sub sub)
2380 struct dahdi_pvt *p = pvt;
2381 int dahdi_sub = analogsub_to_dahdisub(sub);
2382 return p->subs[dahdi_sub].dfd;
2385 static void my_set_cadence(void *pvt, int *cid_rings, struct ast_channel *ast)
2387 struct dahdi_pvt *p = pvt;
2389 /* Choose proper cadence */
2390 if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) {
2391 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &cadences[p->distinctivering - 1]))
2392 ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s': %s\n", p->distinctivering, ast_channel_name(ast), strerror(errno));
2393 *cid_rings = cidrings[p->distinctivering - 1];
2395 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, NULL))
2396 ast_log(LOG_WARNING, "Unable to reset default ring on '%s': %s\n", ast_channel_name(ast), strerror(errno));
2397 *cid_rings = p->sendcalleridafter;
2401 static void my_set_alarm(void *pvt, int in_alarm)
2403 struct dahdi_pvt *p = pvt;
2405 p->inalarm = in_alarm;
2408 static void my_set_dialing(void *pvt, int is_dialing)
2410 struct dahdi_pvt *p = pvt;
2412 p->dialing = is_dialing;
2415 static void my_set_outgoing(void *pvt, int is_outgoing)
2417 struct dahdi_pvt *p = pvt;
2419 p->outgoing = is_outgoing;
2422 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2423 static void my_set_digital(void *pvt, int is_digital)
2425 struct dahdi_pvt *p = pvt;
2427 p->digital = is_digital;
2429 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2431 #if defined(HAVE_SS7)
2432 static void my_set_inservice(void *pvt, int is_inservice)
2434 struct dahdi_pvt *p = pvt;
2436 p->inservice = is_inservice;
2438 #endif /* defined(HAVE_SS7) */
2440 #if defined(HAVE_SS7)
2441 static void my_set_locallyblocked(void *pvt, int is_blocked)
2443 struct dahdi_pvt *p = pvt;
2445 p->locallyblocked = is_blocked;
2447 #endif /* defined(HAVE_SS7) */
2449 #if defined(HAVE_SS7)
2450 static void my_set_remotelyblocked(void *pvt, int is_blocked)
2452 struct dahdi_pvt *p = pvt;
2454 p->remotelyblocked = is_blocked;
2456 #endif /* defined(HAVE_SS7) */
2458 static void my_set_ringtimeout(void *pvt, int ringt)
2460 struct dahdi_pvt *p = pvt;
2464 static void my_set_waitingfordt(void *pvt, struct ast_channel *ast)
2466 struct dahdi_pvt *p = pvt;
2468 if (p->waitfordialtone && CANPROGRESSDETECT(p) && p->dsp) {
2469 ast_debug(1, "Defer dialing for %dms or dialtone\n", p->waitfordialtone);
2470 gettimeofday(&p->waitingfordt, NULL);
2471 ast_setstate(ast, AST_STATE_OFFHOOK);
2475 static int my_check_waitingfordt(void *pvt)
2477 struct dahdi_pvt *p = pvt;
2479 if (p->waitingfordt.tv_usec) {
2486 static void my_set_confirmanswer(void *pvt, int flag)
2488 struct dahdi_pvt *p = pvt;
2489 p->confirmanswer = flag;
2492 static int my_check_confirmanswer(void *pvt)
2494 struct dahdi_pvt *p = pvt;
2495 if (p->confirmanswer) {
2502 static void my_set_callwaiting(void *pvt, int callwaiting_enable)
2504 struct dahdi_pvt *p = pvt;
2506 p->callwaiting = callwaiting_enable;
2509 static void my_cancel_cidspill(void *pvt)
2511 struct dahdi_pvt *p = pvt;
2513 ast_free(p->cidspill);
2515 restore_conference(p);
2518 static int my_confmute(void *pvt, int mute)
2520 struct dahdi_pvt *p = pvt;
2521 return dahdi_confmute(p, mute);
2524 static void my_set_pulsedial(void *pvt, int flag)
2526 struct dahdi_pvt *p = pvt;
2527 p->pulsedial = flag;
2530 static void my_set_new_owner(void *pvt, struct ast_channel *new_owner)
2532 struct dahdi_pvt *p = pvt;
2534 p->owner = new_owner;
2537 static const char *my_get_orig_dialstring(void *pvt)
2539 struct dahdi_pvt *p = pvt;
2541 return p->dialstring;
2544 static void my_increase_ss_count(void)
2546 ast_mutex_lock(&ss_thread_lock);
2548 ast_mutex_unlock(&ss_thread_lock);
2551 static void my_decrease_ss_count(void)
2553 ast_mutex_lock(&ss_thread_lock);
2555 ast_cond_signal(&ss_thread_complete);
2556 ast_mutex_unlock(&ss_thread_lock);
2559 static void my_all_subchannels_hungup(void *pvt)
2561 struct dahdi_pvt *p = pvt;
2568 ast_dsp_free(p->dsp);
2572 p->law = p->law_default;
2573 law = p->law_default;
2574 res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETLAW, &law);
2576 ast_log(LOG_WARNING, "Unable to set law on channel %d to default: %s\n", p->channel, strerror(errno));
2578 dahdi_setlinear(p->subs[SUB_REAL].dfd, 0);
2584 /* Cleanup owners here */
2585 for (i = 0; i < 3; i++) {
2586 p->subs[i].owner = NULL;
2592 if (num_restart_pending == 0) {
2597 static int conf_del(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index);
2599 static int my_conf_del(void *pvt, enum analog_sub sub)
2601 struct dahdi_pvt *p = pvt;
2602 int x = analogsub_to_dahdisub(sub);
2604 return conf_del(p, &p->subs[x], x);
2607 static int conf_add(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index, int slavechannel);
2609 static int my_conf_add(void *pvt, enum analog_sub sub)
2611 struct dahdi_pvt *p = pvt;
2612 int x = analogsub_to_dahdisub(sub);
2614 return conf_add(p, &p->subs[x], x, 0);
2617 static int isslavenative(struct dahdi_pvt *p, struct dahdi_pvt **out);
2619 static int my_complete_conference_update(void *pvt, int needconference)
2621 struct dahdi_pvt *p = pvt;
2622 int needconf = needconference;
2625 struct dahdi_pvt *slave = NULL;
2627 useslavenative = isslavenative(p, &slave);
2629 /* If we have a slave, add him to our conference now. or DAX
2630 if this is slave native */
2631 for (x = 0; x < MAX_SLAVES; x++) {
2634 conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p));
2636 conf_add(p, &p->slaves[x]->subs[SUB_REAL], SUB_REAL, 0);
2641 /* If we're supposed to be in there, do so now */
2642 if (p->inconference && !p->subs[SUB_REAL].inthreeway) {
2644 conf_add(p, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(slave));
2646 conf_add(p, &p->subs[SUB_REAL], SUB_REAL, 0);
2650 /* If we have a master, add ourselves to his conference */
2652 if (isslavenative(p->master, NULL)) {
2653 conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, GET_CHANNEL(p->master));
2655 conf_add(p->master, &p->subs[SUB_REAL], SUB_REAL, 0);
2659 /* Nobody is left (or should be left) in our conference.
2667 static int check_for_conference(struct dahdi_pvt *p);
2669 static int my_check_for_conference(void *pvt)
2671 struct dahdi_pvt *p = pvt;
2672 return check_for_conference(p);
2675 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)
2677 struct dahdi_pvt *p = pvt;
2682 da = analogsub_to_dahdisub(a);
2683 db = analogsub_to_dahdisub(b);
2685 tchan = p->subs[da].chan;
2686 p->subs[da].chan = p->subs[db].chan;
2687 p->subs[db].chan = tchan;
2689 tinthreeway = p->subs[da].inthreeway;
2690 p->subs[da].inthreeway = p->subs[db].inthreeway;
2691 p->subs[db].inthreeway = tinthreeway;
2693 p->subs[da].owner = ast_a;
2694 p->subs[db].owner = ast_b;
2697 ast_channel_set_fd(ast_a, 0, p->subs[da].dfd);
2699 ast_channel_set_fd(ast_b, 0, p->subs[db].dfd);
2709 * \brief performs duties of dahdi_new, but also removes and possibly unbinds (if callid_created is 1) before returning
2710 * \note this variant of dahdi should only be used in conjunction with ast_callid_threadstorage_auto()
2712 * \param callid_created value returned from ast_callid_threadstorage_auto()
2714 static struct ast_channel *dahdi_new_callid_clean(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const char *linked, struct ast_callid *callid, int callid_created);
2716 static struct ast_channel *dahdi_new(struct dahdi_pvt *i, int state, int startpbx, int idx, int law, const char *linkedid, struct ast_callid *callid);
2718 static struct ast_channel *my_new_analog_ast_channel(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
2720 struct ast_callid *callid = NULL;
2721 int callid_created = ast_callid_threadstorage_auto(&callid);
2722 struct dahdi_pvt *p = pvt;
2723 int dsub = analogsub_to_dahdisub(sub);
2725 return dahdi_new_callid_clean(p, state, startpbx, dsub, 0, requestor ? ast_channel_linkedid(requestor) : "", callid, callid_created);
2728 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2729 static int dahdi_setlaw(int dfd, int law)
2732 res = ioctl(dfd, DAHDI_SETLAW, &law);
2737 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2739 #if defined(HAVE_PRI)
2740 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)
2742 struct dahdi_pvt *p = pvt;
2745 struct ast_callid *callid = NULL;
2746 int callid_created = ast_callid_threadstorage_auto(&callid);
2749 case SIG_PRI_LIB_HANDLE_CASES:
2750 if (((struct sig_pri_chan *) p->sig_pvt)->no_b_channel) {
2751 /* PRI nobch pseudo channel. Does not handle ioctl(DAHDI_AUDIOMODE) */
2756 /* Set to audio mode at this point */
2758 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &audio) == -1) {
2759 ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n",
2760 p->channel, audio, strerror(errno));
2765 if (law != SIG_PRI_DEFLAW) {
2766 dahdi_setlaw(p->subs[SUB_REAL].dfd, (law == SIG_PRI_ULAW) ? DAHDI_LAW_MULAW : DAHDI_LAW_ALAW);
2769 ast_copy_string(p->exten, exten, sizeof(p->exten));
2772 case SIG_PRI_DEFLAW:
2776 newlaw = DAHDI_LAW_ALAW;
2779 newlaw = DAHDI_LAW_MULAW;
2783 return dahdi_new_callid_clean(p, state, 0, SUB_REAL, newlaw, requestor ? ast_channel_linkedid(requestor) : "", callid, callid_created);
2785 #endif /* defined(HAVE_PRI) */
2787 static int set_actual_gain(int fd, float rxgain, float txgain, float rxdrc, float txdrc, int law);
2789 #if defined(HAVE_PRI) || defined(HAVE_SS7)
2792 * \brief Open the PRI/SS7 channel media path.
2795 * \param p Channel private control structure.
2799 static void my_pri_ss7_open_media(void *p)
2801 struct dahdi_pvt *pvt = p;
2806 dfd = pvt->subs[SUB_REAL].dfd;
2808 /* Open the media path. */
2810 res = ioctl(dfd, DAHDI_AUDIOMODE, &set_val);
2812 ast_log(LOG_WARNING, "Unable to enable audio mode on channel %d (%s)\n",
2813 pvt->channel, strerror(errno));
2816 /* Set correct companding law for this call. */
2817 res = dahdi_setlaw(dfd, pvt->law);
2819 ast_log(LOG_WARNING, "Unable to set law on channel %d\n", pvt->channel);
2822 /* Set correct gain for this call. */
2824 res = set_actual_gain(dfd, 0, 0, pvt->rxdrc, pvt->txdrc, pvt->law);
2826 res = set_actual_gain(dfd, pvt->rxgain, pvt->txgain, pvt->rxdrc, pvt->txdrc,
2830 ast_log(LOG_WARNING, "Unable to set gains on channel %d\n", pvt->channel);
2833 if (pvt->dsp_features && pvt->dsp) {
2834 ast_dsp_set_features(pvt->dsp, pvt->dsp_features);
2835 pvt->dsp_features = 0;
2838 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
2840 #if defined(HAVE_PRI)
2843 * \brief Ask DAHDI to dial the given dial string.
2846 * \param p Channel private control structure.
2847 * \param dial_string String to pass to DAHDI to dial.
2849 * \note The channel private lock needs to be held when calling.
2853 static void my_pri_dial_digits(void *p, const char *dial_string)
2855 char dial_str[DAHDI_MAX_DTMF_BUF];
2856 struct dahdi_pvt *pvt = p;
2859 snprintf(dial_str, sizeof(dial_str), "T%s", dial_string);
2860 res = dahdi_dial_str(pvt, DAHDI_DIAL_OP_APPEND, dial_str);
2865 #endif /* defined(HAVE_PRI) */
2867 static int unalloc_sub(struct dahdi_pvt *p, int x);
2869 static int my_unallocate_sub(void *pvt, enum analog_sub analogsub)
2871 struct dahdi_pvt *p = pvt;
2873 return unalloc_sub(p, analogsub_to_dahdisub(analogsub));
2876 static int alloc_sub(struct dahdi_pvt *p, int x);
2878 static int my_allocate_sub(void *pvt, enum analog_sub analogsub)
2880 struct dahdi_pvt *p = pvt;
2882 return alloc_sub(p, analogsub_to_dahdisub(analogsub));
2885 static int has_voicemail(struct dahdi_pvt *p);
2887 static int my_has_voicemail(void *pvt)
2889 struct dahdi_pvt *p = pvt;
2891 return has_voicemail(p);
2894 static int my_play_tone(void *pvt, enum analog_sub sub, enum analog_tone tone)
2896 struct dahdi_pvt *p = pvt;
2899 index = analogsub_to_dahdisub(sub);
2901 return tone_zone_play_tone(p->subs[index].dfd, analog_tone_to_dahditone(tone));
2904 static enum analog_event dahdievent_to_analogevent(int event)
2906 enum analog_event res;
2909 case DAHDI_EVENT_ONHOOK:
2910 res = ANALOG_EVENT_ONHOOK;
2912 case DAHDI_EVENT_RINGOFFHOOK:
2913 res = ANALOG_EVENT_RINGOFFHOOK;
2915 case DAHDI_EVENT_WINKFLASH:
2916 res = ANALOG_EVENT_WINKFLASH;
2918 case DAHDI_EVENT_ALARM:
2919 res = ANALOG_EVENT_ALARM;
2921 case DAHDI_EVENT_NOALARM:
2922 res = ANALOG_EVENT_NOALARM;
2924 case DAHDI_EVENT_DIALCOMPLETE:
2925 res = ANALOG_EVENT_DIALCOMPLETE;
2927 case DAHDI_EVENT_RINGERON:
2928 res = ANALOG_EVENT_RINGERON;
2930 case DAHDI_EVENT_RINGEROFF:
2931 res = ANALOG_EVENT_RINGEROFF;
2933 case DAHDI_EVENT_HOOKCOMPLETE:
2934 res = ANALOG_EVENT_HOOKCOMPLETE;
2936 case DAHDI_EVENT_PULSE_START:
2937 res = ANALOG_EVENT_PULSE_START;
2939 case DAHDI_EVENT_POLARITY:
2940 res = ANALOG_EVENT_POLARITY;
2942 case DAHDI_EVENT_RINGBEGIN:
2943 res = ANALOG_EVENT_RINGBEGIN;
2945 case DAHDI_EVENT_EC_DISABLED:
2946 res = ANALOG_EVENT_EC_DISABLED;
2948 case DAHDI_EVENT_REMOVED:
2949 res = ANALOG_EVENT_REMOVED;
2951 case DAHDI_EVENT_NEONMWI_ACTIVE:
2952 res = ANALOG_EVENT_NEONMWI_ACTIVE;
2954 case DAHDI_EVENT_NEONMWI_INACTIVE:
2955 res = ANALOG_EVENT_NEONMWI_INACTIVE;
2957 #ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
2958 case DAHDI_EVENT_TX_CED_DETECTED:
2959 res = ANALOG_EVENT_TX_CED_DETECTED;
2961 case DAHDI_EVENT_RX_CED_DETECTED:
2962 res = ANALOG_EVENT_RX_CED_DETECTED;
2964 case DAHDI_EVENT_EC_NLP_DISABLED:
2965 res = ANALOG_EVENT_EC_NLP_DISABLED;
2967 case DAHDI_EVENT_EC_NLP_ENABLED:
2968 res = ANALOG_EVENT_EC_NLP_ENABLED;
2971 case DAHDI_EVENT_PULSEDIGIT:
2972 res = ANALOG_EVENT_PULSEDIGIT;
2974 case DAHDI_EVENT_DTMFDOWN:
2975 res = ANALOG_EVENT_DTMFDOWN;
2977 case DAHDI_EVENT_DTMFUP:
2978 res = ANALOG_EVENT_DTMFUP;
2981 switch(event & 0xFFFF0000) {
2982 case DAHDI_EVENT_PULSEDIGIT:
2983 case DAHDI_EVENT_DTMFDOWN:
2984 case DAHDI_EVENT_DTMFUP:
2985 /* The event includes a digit number in the low word.
2986 * Converting it to a 'enum analog_event' would remove
2987 * that information. Thus it is returned as-is.
2992 res = ANALOG_EVENT_ERROR;
2999 static inline int dahdi_wait_event(int fd);
3001 static int my_wait_event(void *pvt)
3003 struct dahdi_pvt *p = pvt;
3005 return dahdi_wait_event(p->subs[SUB_REAL].dfd);
3008 static int my_get_event(void *pvt)
3010 struct dahdi_pvt *p = pvt;
3013 if (p->fake_event) {
3014 res = p->fake_event;
3017 res = dahdi_get_event(p->subs[SUB_REAL].dfd);
3019 return dahdievent_to_analogevent(res);
3022 static int my_is_off_hook(void *pvt)
3024 struct dahdi_pvt *p = pvt;
3026 struct dahdi_params par;
3028 memset(&par, 0, sizeof(par));
3030 if (p->subs[SUB_REAL].dfd > -1)
3031 res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, &par);
3033 /* Assume not off hook on CVRS */
3035 par.rxisoffhook = 0;
3038 ast_log(LOG_WARNING, "Unable to check hook state on channel %d: %s\n", p->channel, strerror(errno));
3041 if ((p->sig == SIG_FXSKS) || (p->sig == SIG_FXSGS)) {
3042 /* When "onhook" that means no battery on the line, and thus
3043 it is out of service..., if it's on a TDM card... If it's a channel
3044 bank, there is no telling... */
3045 return (par.rxbits > -1) || par.rxisoffhook;
3048 return par.rxisoffhook;
3051 static void dahdi_enable_ec(struct dahdi_pvt *p);
3052 static void dahdi_disable_ec(struct dahdi_pvt *p);
3054 static int my_set_echocanceller(void *pvt, int enable)
3056 struct dahdi_pvt *p = pvt;
3061 dahdi_disable_ec(p);
3066 static int dahdi_ring_phone(struct dahdi_pvt *p);
3068 static int my_ring(void *pvt)
3070 struct dahdi_pvt *p = pvt;
3072 return dahdi_ring_phone(p);
3075 static int my_flash(void *pvt)
3077 struct dahdi_pvt *p = pvt;
3078 int func = DAHDI_FLASH;
3079 return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &func);
3082 static inline int dahdi_set_hook(int fd, int hs);
3084 static int my_off_hook(void *pvt)
3086 struct dahdi_pvt *p = pvt;
3087 return dahdi_set_hook(p->subs[SUB_REAL].dfd, DAHDI_OFFHOOK);
3090 static void my_set_needringing(void *pvt, int value)
3092 struct dahdi_pvt *p = pvt;
3093 p->subs[SUB_REAL].needringing = value;
3096 static void my_set_polarity(void *pvt, int value)
3098 struct dahdi_pvt *p = pvt;
3100 if (p->channel == CHAN_PSEUDO) {
3103 p->polarity = value;
3104 ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETPOLARITY, &value);
3107 static void my_start_polarityswitch(void *pvt)
3109 struct dahdi_pvt *p = pvt;
3111 if (p->answeronpolarityswitch || p->hanguponpolarityswitch) {
3112 my_set_polarity(pvt, 0);
3116 static void my_answer_polarityswitch(void *pvt)
3118 struct dahdi_pvt *p = pvt;
3120 if (!p->answeronpolarityswitch) {
3124 my_set_polarity(pvt, 1);
3127 static void my_hangup_polarityswitch(void *pvt)
3129 struct dahdi_pvt *p = pvt;
3131 if (!p->hanguponpolarityswitch) {
3135 if (p->answeronpolarityswitch) {
3136 my_set_polarity(pvt, 0);
3138 my_set_polarity(pvt, 1);
3142 static int my_start(void *pvt)
3144 struct dahdi_pvt *p = pvt;
3145 int x = DAHDI_START;
3147 return ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x);
3150 static int my_dial_digits(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop)
3152 struct dahdi_pvt *p = pvt;
3154 if (dop->op != ANALOG_DIAL_OP_REPLACE) {
3155 ast_log(LOG_ERROR, "Fix the dial_digits callback!\n");
3159 if (sub != ANALOG_SUB_REAL) {
3160 ast_log(LOG_ERROR, "Trying to dial_digits '%s' on channel %d subchannel %d\n",
3161 dop->dialstr, p->channel, sub);
3165 return dahdi_dial_str(p, DAHDI_DIAL_OP_REPLACE, dop->dialstr);
3168 static void dahdi_train_ec(struct dahdi_pvt *p);
3170 static int my_train_echocanceller(void *pvt)
3172 struct dahdi_pvt *p = pvt;
3179 static int my_is_dialing(void *pvt, enum analog_sub sub)
3181 struct dahdi_pvt *p = pvt;
3185 index = analogsub_to_dahdisub(sub);
3187 if (ioctl(p->subs[index].dfd, DAHDI_DIALING, &x)) {
3188 ast_debug(1, "DAHDI_DIALING ioctl failed!\n");
3195 static int my_on_hook(void *pvt)
3197 struct dahdi_pvt *p = pvt;
3198 return dahdi_set_hook(p->subs[ANALOG_SUB_REAL].dfd, DAHDI_ONHOOK);
3201 #if defined(HAVE_PRI)
3202 static void my_pri_fixup_chans(void *chan_old, void *chan_new)
3204 struct dahdi_pvt *old_chan = chan_old;
3205 struct dahdi_pvt *new_chan = chan_new;
3207 new_chan->owner = old_chan->owner;
3208 old_chan->owner = NULL;
3209 if (new_chan->owner) {
3210 ast_channel_tech_pvt_set(new_chan->owner, new_chan);
3211 ast_channel_internal_fd_set(new_chan->owner, 0, new_chan->subs[SUB_REAL].dfd);
3212 new_chan->subs[SUB_REAL].owner = old_chan->subs[SUB_REAL].owner;
3213 old_chan->subs[SUB_REAL].owner = NULL;
3215 /* Copy any DSP that may be present */
3216 new_chan->dsp = old_chan->dsp;
3217 new_chan->dsp_features = old_chan->dsp_features;
3218 old_chan->dsp = NULL;
3219 old_chan->dsp_features = 0;
3221 /* Transfer flags from the old channel. */
3222 new_chan->dialing = old_chan->dialing;
3223 new_chan->digital = old_chan->digital;
3224 new_chan->outgoing = old_chan->outgoing;
3225 old_chan->dialing = 0;
3226 old_chan->digital = 0;
3227 old_chan->outgoing = 0;
3229 /* More stuff to transfer to the new channel. */
3230 new_chan->law = old_chan->law;
3231 strcpy(new_chan->dialstring, old_chan->dialstring);
3233 #endif /* defined(HAVE_PRI) */
3235 #if defined(HAVE_PRI)
3236 static int sig_pri_tone_to_dahditone(enum sig_pri_tone tone)
3239 case SIG_PRI_TONE_RINGTONE:
3240 return DAHDI_TONE_RINGTONE;
3241 case SIG_PRI_TONE_STUTTER:
3242 return DAHDI_TONE_STUTTER;
3243 case SIG_PRI_TONE_CONGESTION:
3244 return DAHDI_TONE_CONGESTION;
3245 case SIG_PRI_TONE_DIALTONE:
3246 return DAHDI_TONE_DIALTONE;
3247 case SIG_PRI_TONE_DIALRECALL:
3248 return DAHDI_TONE_DIALRECALL;
3249 case SIG_PRI_TONE_INFO:
3250 return DAHDI_TONE_INFO;
3251 case SIG_PRI_TONE_BUSY:
3252 return DAHDI_TONE_BUSY;
3257 #endif /* defined(HAVE_PRI) */
3259 #if defined(HAVE_PRI)
3260 static void my_handle_dchan_exception(struct sig_pri_span *pri, int index)
3264 ioctl(pri->fds[index], DAHDI_GETEVENT, &x);
3266 case DAHDI_EVENT_NONE:
3268 case DAHDI_EVENT_ALARM:
3269 case DAHDI_EVENT_NOALARM:
3270 if (sig_pri_is_alarm_ignored(pri)) {
3275 ast_log(LOG_NOTICE, "PRI got event: %s (%d) on D-channel of span %d\n",
3276 event2str(x), x, pri->span);
3279 /* Keep track of alarm state */
3281 case DAHDI_EVENT_ALARM:
3282 pri_event_alarm(pri, index, 0);
3284 case DAHDI_EVENT_NOALARM:
3285 pri_event_noalarm(pri, index, 0);
3291 #endif /* defined(HAVE_PRI) */
3293 #if defined(HAVE_PRI)
3294 static int my_pri_play_tone(void *pvt, enum sig_pri_tone tone)
3296 struct dahdi_pvt *p = pvt;
3298 return tone_zone_play_tone(p->subs[SUB_REAL].dfd, sig_pri_tone_to_dahditone(tone));
3300 #endif /* defined(HAVE_PRI) */
3302 #if defined(HAVE_PRI) || defined(HAVE_SS7)
3305 * \brief Set the caller id information.
3308 * \param pvt DAHDI private structure
3309 * \param caller Caller-id information to set.
3313 static void my_set_callerid(void *pvt, const struct ast_party_caller *caller)
3315 struct dahdi_pvt *p = pvt;
3317 ast_copy_string(p->cid_num,
3318 S_COR(caller->id.number.valid, caller->id.number.str, ""),
3319 sizeof(p->cid_num));
3320 ast_copy_string(p->cid_name,
3321 S_COR(caller->id.name.valid, caller->id.name.str, ""),
3322 sizeof(p->cid_name));
3323 ast_copy_string(p->cid_subaddr,
3324 S_COR(caller->id.subaddress.valid, caller->id.subaddress.str, ""),
3325 sizeof(p->cid_subaddr));
3326 p->cid_ton = caller->id.number.plan;
3327 p->callingpres = ast_party_id_presentation(&caller->id);
3328 if (caller->id.tag) {
3329 ast_copy_string(p->cid_tag, caller->id.tag, sizeof(p->cid_tag));
3331 ast_copy_string(p->cid_ani,
3332 S_COR(caller->ani.number.valid, caller->ani.number.str, ""),
3333 sizeof(p->cid_ani));
3334 p->cid_ani2 = caller->ani2;
3336 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
3338 #if defined(HAVE_PRI) || defined(HAVE_SS7)
3341 * \brief Set the Dialed Number Identifier.
3344 * \param pvt DAHDI private structure
3345 * \param dnid Dialed Number Identifier string.
3349 static void my_set_dnid(void *pvt, const char *dnid)
3351 struct dahdi_pvt *p = pvt;
3353 ast_copy_string(p->dnid, dnid, sizeof(p->dnid));
3355 #endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
3357 #if defined(HAVE_PRI)
3360 * \brief Set the Redirecting Directory Number Information Service (RDNIS).
3363 * \param pvt DAHDI private structure
3364 * \param rdnis Redirecting Directory Number Information Service (RDNIS) string.
3368 static void my_set_rdnis(void *pvt, const char *rdnis)
3370 struct dahdi_pvt *p = pvt;
3372 ast_copy_string(p->rdnis, rdnis, sizeof(p->rdnis));
3374 #endif /* defined(HAVE_PRI) */
3376 #if defined(HAVE_PRI)
3379 * \brief Make a dialstring for native ISDN CC to recall properly.
3382 * \param priv Channel private control structure.
3383 * \param buf Where to put the modified dialstring.
3384 * \param buf_size Size of modified dialstring buffer.
3387 * original dialstring:
3388 * DAHDI/[i<span>-](g|G|r|R)<group#(0-63)>[c|r<cadance#>|d][/extension[/options]]
3390 * The modified dialstring will have prefixed the channel-group section
3391 * with the ISDN channel restriction.
3394 * DAHDI/i<span>-(g|G|r|R)<group#(0-63)>[c|r<cadance#>|d][/extension[/options]]
3396 * The routine will check to see if the ISDN channel restriction is already
3397 * in the original dialstring.
3401 static void my_pri_make_cc_dialstring(void *priv, char *buf, size_t buf_size)
3404 struct dahdi_pvt *pvt;
3405 AST_DECLARE_APP_ARGS(args,
3406 AST_APP_ARG(tech); /* channel technology token */
3407 AST_APP_ARG(group); /* channel/group token */
3408 //AST_APP_ARG(ext); /* extension token */
3409 //AST_APP_ARG(opts); /* options token */
3410 //AST_APP_ARG(other); /* Any remining unused arguments */
3414 dial = ast_strdupa(pvt->dialstring);
3415 AST_NONSTANDARD_APP_ARGS(args, dial, '/');
3417 ast_copy_string(buf, pvt->dialstring, buf_size);
3421 /* Append the ISDN span channel restriction to the dialstring. */
3422 snprintf(buf, buf_size, "%s/i%d-", args.tech, pvt->pri->span);
3425 if (isdigit(args.group[0]) || args.group[0] == 'i' || strchr(args.group, '!')) {
3426 /* The ISDN span channel restriction is not needed or already
3427 * in the dialstring. */
3428 ast_copy_string(buf, pvt->dialstring, buf_size);
3431 /* Insert the ISDN span channel restriction into the dialstring. */
3432 snprintf(buf, buf_size, "%s/i%d-%s", args.tech, pvt->pri->span, args.group);
3434 #endif /* defined(HAVE_PRI) */
3436 #if defined(HAVE_PRI)
3439 * \brief Reevaluate the PRI span device state.
3442 * \param pri Asterisk D channel control structure.
3446 * \note Assumes the pri->lock is already obtained.
3448 static void dahdi_pri_update_span_devstate(struct sig_pri_span *pri)
3451 unsigned num_b_chans; /* Number of B channels provisioned on the span. */
3452 unsigned in_use; /* Number of B channels in use on the span. */
3453 unsigned in_alarm; /* TRUE if the span is in alarm condition. */
3454 enum ast_device_state new_state;
3456 /* Count the number of B channels and the number of B channels in use. */
3460 for (idx = pri->numchans; idx--;) {
3461 if (pri->pvts[idx] && !pri->pvts[idx]->no_b_channel) {
3462 /* This is a B channel interface. */
3464 if (!sig_pri_is_chan_available(pri->pvts[idx])) {
3467 if (!pri->pvts[idx]->inalarm) {
3468 /* There is a channel that is not in alarm. */
3474 /* Update the span congestion device state and report any change. */
3476 new_state = AST_DEVICE_UNAVAILABLE;
3478 new_state = num_b_chans == in_use ? AST_DEVICE_BUSY : AST_DEVICE_NOT_INUSE;
3480 if (pri->congestion_devstate != new_state) {
3481 pri->congestion_devstate = new_state;
3482 ast_devstate_changed(AST_DEVICE_UNKNOWN, "DAHDI/I%d/congestion", pri->span);
3484 #if defined(THRESHOLD_DEVSTATE_PLACEHOLDER)
3485 /* Update the span threshold device state and report any change. */
3487 new_state = AST_DEVICE_UNAVAILABLE;
3488 } else if (!in_use) {
3489 new_state = AST_DEVICE_NOT_INUSE;
3490 } else if (!pri->user_busy_threshold) {
3491 new_state = in_use < num_b_chans ? AST_DEVICE_INUSE : AST_DEVICE_BUSY;
3493 new_state = in_use < pri->user_busy_threshold ? AST_DEVICE_INUSE
3496 if (pri->threshold_devstate != new_state) {
3497 pri->threshold_devstate = new_state;
3498 ast_devstate_changed(AST_DEVICE_UNKNOWN, "DAHDI/I%d/threshold", pri->span);
3500 #endif /* defined(THRESHOLD_DEVSTATE_PLACEHOLDER) */
3502 #endif /* defined(HAVE_PRI) */
3504 #if defined(HAVE_PRI)
3507 * \brief Reference this module.
3512 static void my_module_ref(void)
3514 ast_module_ref(ast_module_info->self);
3516 #endif /* defined(HAVE_PRI) */
3518 #if defined(HAVE_PRI)
3521 * \brief Unreference this module.
3526 static void my_module_unref(void)
3528 ast_module_unref(ast_module_info->self);
3530 #endif /* defined(HAVE_PRI) */
3532 #if defined(HAVE_PRI)
3533 #if defined(HAVE_PRI_CALL_WAITING)
3534 static void my_pri_init_config(void *priv, struct sig_pri_span *pri);
3535 #endif /* defined(HAVE_PRI_CALL_WAITING) */
3536 static int dahdi_new_pri_nobch_channel(struct sig_pri_span *pri);
3538 struct sig_pri_callback sig_pri_callbacks =
3540 .handle_dchan_exception = my_handle_dchan_exception,
3541 .play_tone = my_pri_play_tone,
3542 .set_echocanceller = my_set_echocanceller,
3543 .dsp_reset_and_flush_digits = my_dsp_reset_and_flush_digits,
3544 .lock_private = my_lock_private,
3545 .unlock_private = my_unlock_private,
3546 .deadlock_avoidance_private = my_deadlock_avoidance_private,
3547 .new_ast_channel = my_new_pri_ast_channel,
3548 .fixup_chans = my_pri_fixup_chans,
3549 .set_alarm = my_set_alarm,
3550 .set_dialing = my_set_dialing,
3551 .set_outgoing = my_set_outgoing,
3552 .set_digital = my_set_digital,
3553 .set_callerid = my_set_callerid,
3554 .set_dnid = my_set_dnid,
3555 .set_rdnis = my_set_rdnis,
3556 .new_nobch_intf = dahdi_new_pri_nobch_channel,
3557 #if defined(HAVE_PRI_CALL_WAITING)
3558 .init_config = my_pri_init_config,
3559 #endif /* defined(HAVE_PRI_CALL_WAITING) */
3560 .get_orig_dialstring = my_get_orig_dialstring,
3561 .make_cc_dialstring = my_pri_make_cc_dialstring,
3562 .update_span_devstate = dahdi_pri_update_span_devstate,
3563 .module_ref = my_module_ref,
3564 .module_unref = my_module_unref,
3565 .dial_digits = my_pri_dial_digits,
3566 .open_media = my_pri_ss7_open_media,
3567 .ami_channel_event = my_ami_channel_event,
3569 #endif /* defined(HAVE_PRI) */
3571 #if defined(HAVE_SS7)
3574 * \brief Handle the SS7 link exception.
3577 * \param linkset Controlling linkset for the channel.
3578 * \param which Link index of the signaling channel.
3582 static void my_handle_link_exception(struct sig_ss7_linkset *linkset, int which)
3586 if (ioctl(linkset->fds[which], DAHDI_GETEVENT, &event)) {
3587 ast_log(LOG_ERROR, "SS7: Error in exception retrieval on span %d/%d!\n",
3588 linkset->span, which);
3592 case DAHDI_EVENT_NONE:
3594 case DAHDI_EVENT_ALARM:
3595 ast_log(LOG_ERROR, "SS7 got event: %s(%d) on span %d/%d\n",
3596 event2str(event), event, linkset->span, which);
3597 sig_ss7_link_alarm(linkset, which);
3599 case DAHDI_EVENT_NOALARM:
3600 ast_log(LOG_ERROR, "SS7 got event: %s(%d) on span %d/%d\n",
3601 event2str(event), event, linkset->span, which);
3602 sig_ss7_link_noalarm(linkset, which);
3605 ast_log(LOG_NOTICE, "SS7 got event: %s(%d) on span %d/%d\n",
3606 event2str(event), event, linkset->span, which);
3610 #endif /* defined(HAVE_SS7) */
3612 #if defined(HAVE_SS7)
3613 static void my_ss7_set_loopback(void *pvt, int enable)
3615 struct dahdi_pvt *p = pvt;
3617 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_LOOPBACK, &enable)) {
3618 ast_log(LOG_WARNING, "Unable to set loopback on channel %d: %s\n", p->channel,
3622 #endif /* defined(HAVE_SS7) */
3624 #if defined(HAVE_SS7)
3627 * \brief Create a new asterisk channel structure for SS7.
3630 * \param pvt Private channel structure.
3631 * \param state Initial state of new channel.
3632 * \param law Combanding law to use.
3633 * \param exten Dialplan extension for incoming call.
3634 * \param requestor Channel requesting this new channel.
3636 * \retval ast_channel on success.
3637 * \retval NULL on error.
3639 static struct ast_channel *my_new_ss7_ast_channel(void *pvt, int state, enum sig_ss7_law law, char *exten, const struct ast_channel *requestor)
3641 struct dahdi_pvt *p = pvt;
3644 struct ast_callid *callid = NULL;
3645 int callid_created = ast_callid_threadstorage_auto(&callid);
3647 /* Set to audio mode at this point */
3649 if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_AUDIOMODE, &audio) == -1)
3650 ast_log(LOG_WARNING, "Unable to set audio mode on channel %d to %d: %s\n",
3651 p->channel, audio, strerror(errno));
3653 if (law != SIG_SS7_DEFLAW) {
3654 dahdi_setlaw(p->subs[SUB_REAL].dfd,
3655 (law == SIG_SS7_ULAW) ? DAHDI_LAW_MULAW : DAHDI_LAW_ALAW);
3658 ast_copy_string(p->exten, exten, sizeof(p->exten));
3662 case SIG_SS7_DEFLAW:
3666 newlaw = DAHDI_LAW_ALAW;
3669 newlaw = DAHDI_LAW_MULAW;
3672 return dahdi_new_callid_clean(p, state, 0, SUB_REAL, newlaw, requestor ? ast_channel_linkedid(requestor) : "", callid, callid_created);
3674 #endif /* defined(HAVE_SS7) */
3676 #if defined(HAVE_SS7)
3677 static int sig_ss7_tone_to_dahditone(enum sig_ss7_tone tone)
3680 case SIG_SS7_TONE_RINGTONE:
3681 return DAHDI_TONE_RINGTONE;
3682 case SIG_SS7_TONE_STUTTER:
3683 return DAHDI_TONE_STUTTER;
3684 case SIG_SS7_TONE_CONGESTION:
3685 return DAHDI_TONE_CONGESTION;
3686 case SIG_SS7_TONE_DIALTONE:
3687 return DAHDI_TONE_DIALTONE;
3688 case SIG_SS7_TONE_DIALRECALL:
3689 return DAHDI_TONE_DIALRECALL;
3690 case SIG_SS7_TONE_INFO:
3691 return DAHDI_TONE_INFO;
3692 case SIG_SS7_TONE_BUSY:
3693 return DAHDI_TONE_BUSY;
3698 #endif /* defined(HAVE_SS7) */
3700 #if defined(HAVE_SS7)
3701 static int my_ss7_play_tone(void *pvt, enum sig_ss7_tone tone)
3703 struct dahdi_pvt *p = pvt;
3705 return tone_zone_play_tone(p->subs[SUB_REAL].dfd, sig_ss7_tone_to_dahditone(tone));
3707 #endif /* defined(HAVE_SS7) */
3709 #if defined(HAVE_SS7)
3710 struct sig_ss7_callback sig_ss7_callbacks =
3712 .lock_private = my_lock_private,
3713 .unlock_private = my_unlock_private,
3714 .deadlock_avoidance_private = my_deadlock_avoidance_private,
3716 .set_echocanceller = my_set_echocanceller,
3717 .set_loopback = my_ss7_set_loopback,
3719 .new_ast_channel = my_new_ss7_ast_channel,
3720 .play_tone = my_ss7_play_tone,
3722 .handle_link_exception = my_handle_link_exception,
3723 .set_alarm = my_set_alarm,
3724 .set_dialing = my_set_dialing,
3725 .set_outgoing = my_set_outgoing,
3726 .set_digital = my_set_digital,
3727 .set_inservice = my_set_inservice,
3728 .set_locallyblocked = my_set_locallyblocked,
3729 .set_remotelyblocked = my_set_remotelyblocked,
3730 .set_callerid = my_set_callerid,
3731 .set_dnid = my_set_dnid,
3732 .open_media = my_pri_ss7_open_media,
3734 #endif /* defined(HAVE_SS7) */
3737 * \brief Send MWI state change
3739 * \arg mailbox_full This is the mailbox associated with the FXO line that the
3740 * MWI state has changed on.