forked from asterisk/asterisk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchan_dahdi.c
19777 lines (18183 loc) · 599 KB
/
chan_dahdi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 1999 - 2008, Digium, Inc.
*
* Mark Spencer <[email protected]>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*! \file
*
* \brief DAHDI for Pseudo TDM
*
* \author Mark Spencer <[email protected]>
*
* Connects to the DAHDI telephony library as well as
* libpri. Libpri is optional and needed only if you are
* going to use ISDN connections.
*
* You need to install libraries before you attempt to compile
* and install the DAHDI channel.
*
* \ingroup channel_drivers
*
* \todo Deprecate the "musiconhold" configuration option post 1.4
*/
/*! \li \ref chan_dahdi.c uses the configuration file \ref chan_dahdi.conf
* \addtogroup configuration_file
*/
/*! \page chan_dahdi.conf chan_dahdi.conf
* \verbinclude chan_dahdi.conf.sample
*/
/*** MODULEINFO
<use type="module">res_smdi</use>
<depend>dahdi</depend>
<depend>tonezone</depend>
<use type="external">pri</use>
<use type="external">ss7</use>
<use type="external">openr2</use>
<support_level>core</support_level>
***/
#include "asterisk.h"
#if defined(__NetBSD__) || defined(__FreeBSD__)
#include <pthread.h>
#endif
#include <signal.h>
#include <sys/stat.h>
#include <math.h>
#include "sig_analog.h"
/* Analog signaling is currently still present in chan_dahdi for use with
* radio. Sig_analog does not currently handle any radio operations. If
* radio only uses analog signaling, then the radio handling logic could
* be placed in sig_analog and the duplicated code could be removed.
*/
#if defined(HAVE_PRI)
#include "sig_pri.h"
#ifndef PRI_RESTART
#error "Upgrade your libpri"
#endif
#endif /* defined(HAVE_PRI) */
#if defined(HAVE_SS7)
#include "sig_ss7.h"
#if !defined(LIBSS7_ABI_COMPATIBILITY)
#error "Upgrade your libss7"
#elif LIBSS7_ABI_COMPATIBILITY != 2
#error "Your installed libss7 is not compatible"
#endif
#endif /* defined(HAVE_SS7) */
#if defined(HAVE_OPENR2)
/* put this here until sig_mfcr2 comes along */
#define SIG_MFCR2_MAX_CHANNELS 672 /*!< No more than a DS3 per trunk group */
#endif /* defined(HAVE_OPENR2) */
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/file.h"
#include "asterisk/ulaw.h"
#include "asterisk/alaw.h"
#include "asterisk/callerid.h"
#include "asterisk/adsi.h"
#include "asterisk/cli.h"
#include "asterisk/pickup.h"
#include "asterisk/features.h"
#include "asterisk/musiconhold.h"
#include "asterisk/say.h"
#include "asterisk/tdd.h"
#include "asterisk/app.h"
#include "asterisk/dsp.h"
#include "asterisk/astdb.h"
#include "asterisk/manager.h"
#include "asterisk/causes.h"
#include "asterisk/term.h"
#include "asterisk/utils.h"
#include "asterisk/transcap.h"
#include "asterisk/stringfields.h"
#include "asterisk/abstract_jb.h"
#include "asterisk/smdi.h"
#include "asterisk/devicestate.h"
#include "asterisk/paths.h"
#include "asterisk/ccss.h"
#include "asterisk/data.h"
#include "asterisk/features_config.h"
#include "asterisk/bridge.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/parking.h"
#include "asterisk/format_cache.h"
#include "chan_dahdi.h"
#include "dahdi/bridge_native_dahdi.h"
/*** DOCUMENTATION
<application name="DAHDISendKeypadFacility" language="en_US">
<synopsis>
Send digits out of band over a PRI.
</synopsis>
<syntax>
<parameter name="digits" required="true" />
</syntax>
<description>
<para>This application will send the given string of digits in a Keypad
Facility IE over the current channel.</para>
</description>
</application>
<application name="DAHDISendCallreroutingFacility" language="en_US">
<synopsis>
Send an ISDN call rerouting/deflection facility message.
</synopsis>
<syntax argsep=",">
<parameter name="destination" required="true">
<para>Destination number.</para>
</parameter>
<parameter name="original">
<para>Original called number.</para>
</parameter>
<parameter name="reason">
<para>Diversion reason, if not specified defaults to <literal>unknown</literal></para>
</parameter>
</syntax>
<description>
<para>This application will send an ISDN switch specific call
rerouting/deflection facility message over the current channel.
Supported switches depend upon the version of libpri in use.</para>
</description>
</application>
<application name="DAHDIAcceptR2Call" language="en_US">
<synopsis>
Accept an R2 call if its not already accepted (you still need to answer it)
</synopsis>
<syntax>
<parameter name="charge" required="true">
<para>Yes or No.</para>
<para>Whether you want to accept the call with charge or without charge.</para>
</parameter>
</syntax>
<description>
<para>This application will Accept the R2 call either with charge or no charge.</para>
</description>
</application>
<info name="CHANNEL" language="en_US" tech="DAHDI">
<enumlist>
<enum name="dahdi_channel">
<para>R/O DAHDI channel related to this channel.</para>
</enum>
<enum name="dahdi_span">
<para>R/O DAHDI span related to this channel.</para>
</enum>
<enum name="dahdi_type">
<para>R/O DAHDI channel type, one of:</para>
<enumlist>
<enum name="analog" />
<enum name="mfc/r2" />
<enum name="pri" />
<enum name="pseudo" />
<enum name="ss7" />
</enumlist>
</enum>
<enum name="keypad_digits">
<para>R/O PRI Keypad digits that came in with the SETUP message.</para>
</enum>
<enum name="reversecharge">
<para>R/O PRI Reverse Charging Indication, one of:</para>
<enumlist>
<enum name="-1"> <para>None</para></enum>
<enum name=" 1"> <para>Reverse Charging Requested</para></enum>
</enumlist>
</enum>
<enum name="no_media_path">
<para>R/O PRI Nonzero if the channel has no B channel.
The channel is either on hold or a call waiting call.</para>
</enum>
<enum name="buffers">
<para>W/O Change the channel's buffer policy (for the current call only)</para>
<para>This option takes two arguments:</para>
<para> Number of buffers,</para>
<para> Buffer policy being one of:</para>
<para> <literal>full</literal></para>
<para> <literal>immediate</literal></para>
<para> <literal>half</literal></para>
</enum>
<enum name="echocan_mode">
<para>W/O Change the configuration of the active echo
canceller on the channel (if any), for the current call
only.</para>
<para>Possible values are:</para>
<para> <literal>on</literal> Normal mode (the echo canceller is actually reinitalized)</para>
<para> <literal>off</literal> Disabled</para>
<para> <literal>fax</literal> FAX/data mode (NLP disabled if possible, otherwise
completely disabled)</para>
<para> <literal>voice</literal> Voice mode (returns from FAX mode, reverting the changes that were made)</para>
</enum>
</enumlist>
</info>
<manager name="DAHDITransfer" language="en_US">
<synopsis>
Transfer DAHDI Channel.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="DAHDIChannel" required="true">
<para>DAHDI channel number to transfer.</para>
</parameter>
</syntax>
<description>
<para>Simulate a flash hook event by the user connected to the channel.</para>
<note><para>Valid only for analog channels.</para></note>
</description>
</manager>
<manager name="DAHDIHangup" language="en_US">
<synopsis>
Hangup DAHDI Channel.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="DAHDIChannel" required="true">
<para>DAHDI channel number to hangup.</para>
</parameter>
</syntax>
<description>
<para>Simulate an on-hook event by the user connected to the channel.</para>
<note><para>Valid only for analog channels.</para></note>
</description>
</manager>
<manager name="DAHDIDialOffhook" language="en_US">
<synopsis>
Dial over DAHDI channel while offhook.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="DAHDIChannel" required="true">
<para>DAHDI channel number to dial digits.</para>
</parameter>
<parameter name="Number" required="true">
<para>Digits to dial.</para>
</parameter>
</syntax>
<description>
<para>Generate DTMF control frames to the bridged peer.</para>
</description>
</manager>
<manager name="DAHDIDNDon" language="en_US">
<synopsis>
Toggle DAHDI channel Do Not Disturb status ON.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="DAHDIChannel" required="true">
<para>DAHDI channel number to set DND on.</para>
</parameter>
</syntax>
<description>
<para>Equivalent to the CLI command "dahdi set dnd <variable>channel</variable> on".</para>
<note><para>Feature only supported by analog channels.</para></note>
</description>
</manager>
<manager name="DAHDIDNDoff" language="en_US">
<synopsis>
Toggle DAHDI channel Do Not Disturb status OFF.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="DAHDIChannel" required="true">
<para>DAHDI channel number to set DND off.</para>
</parameter>
</syntax>
<description>
<para>Equivalent to the CLI command "dahdi set dnd <variable>channel</variable> off".</para>
<note><para>Feature only supported by analog channels.</para></note>
</description>
</manager>
<manager name="DAHDIShowChannels" language="en_US">
<synopsis>
Show status of DAHDI channels.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="DAHDIChannel">
<para>Specify the specific channel number to show. Show all channels if zero or not present.</para>
</parameter>
</syntax>
<description>
<para>Similar to the CLI command "dahdi show channels".</para>
</description>
</manager>
<manager name="DAHDIRestart" language="en_US">
<synopsis>
Fully Restart DAHDI channels (terminates calls).
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
</syntax>
<description>
<para>Equivalent to the CLI command "dahdi restart".</para>
</description>
</manager>
<manager name="PRIShowSpans" language="en_US">
<synopsis>
Show status of PRI spans.
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="Span">
<para>Specify the specific span to show. Show all spans if zero or not present.</para>
</parameter>
</syntax>
<description>
<para>Similar to the CLI command "pri show spans".</para>
</description>
</manager>
<manager name="PRIDebugSet" language="en_US">
<synopsis>
Set PRI debug levels for a span
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="Span" required="true">
<para>Which span to affect.</para>
</parameter>
<parameter name="Level" required="true">
<para>What debug level to set. May be a numerical value or a text value from the list below</para>
<enumlist>
<enum name="off" />
<enum name="on" />
<enum name="hex" />
<enum name="intense" />
</enumlist>
</parameter>
</syntax>
<description>
<para>Equivalent to the CLI command "pri set debug <level> span <span>".</para>
</description>
</manager>
<manager name="PRIDebugFileSet" language="en_US">
<synopsis>
Set the file used for PRI debug message output
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
<parameter name="File" required="true">
<para>Path of file to write debug output.</para>
</parameter>
</syntax>
<description>
<para>Equivalent to the CLI command "pri set debug file <output-file>"</para>
</description>
</manager>
<manager name="PRIDebugFileUnset" language="en_US">
<synopsis>
Disables file output for PRI debug messages
</synopsis>
<syntax>
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
</syntax>
</manager>
<managerEvent language="en_US" name="AlarmClear">
<managerEventInstance class="EVENT_FLAG_SYSTEM">
<synopsis>Raised when an alarm is cleared on a DAHDI channel.</synopsis>
<syntax>
<parameter name="DAHDIChannel">
<para>The DAHDI channel on which the alarm was cleared.</para>
<note><para>This is not an Asterisk channel identifier.</para></note>
</parameter>
</syntax>
</managerEventInstance>
</managerEvent>
<managerEvent language="en_US" name="SpanAlarmClear">
<managerEventInstance class="EVENT_FLAG_SYSTEM">
<synopsis>Raised when an alarm is cleared on a DAHDI span.</synopsis>
<syntax>
<parameter name="Span">
<para>The span on which the alarm was cleared.</para>
</parameter>
</syntax>
</managerEventInstance>
</managerEvent>
<managerEvent language="en_US" name="DNDState">
<managerEventInstance class="EVENT_FLAG_SYSTEM">
<synopsis>Raised when the Do Not Disturb state is changed on a DAHDI channel.</synopsis>
<syntax>
<parameter name="DAHDIChannel">
<para>The DAHDI channel on which DND status changed.</para>
<note><para>This is not an Asterisk channel identifier.</para></note>
</parameter>
<parameter name="Status">
<enumlist>
<enum name="enabled"/>
<enum name="disabled"/>
</enumlist>
</parameter>
</syntax>
</managerEventInstance>
</managerEvent>
<managerEvent language="en_US" name="Alarm">
<managerEventInstance class="EVENT_FLAG_SYSTEM">
<synopsis>Raised when an alarm is set on a DAHDI channel.</synopsis>
<syntax>
<parameter name="DAHDIChannel">
<para>The channel on which the alarm occurred.</para>
<note><para>This is not an Asterisk channel identifier.</para></note>
</parameter>
<parameter name="Alarm">
<para>A textual description of the alarm that occurred.</para>
</parameter>
</syntax>
</managerEventInstance>
</managerEvent>
<managerEvent language="en_US" name="SpanAlarm">
<managerEventInstance class="EVENT_FLAG_SYSTEM">
<synopsis>Raised when an alarm is set on a DAHDI span.</synopsis>
<syntax>
<parameter name="Span">
<para>The span on which the alarm occurred.</para>
</parameter>
<parameter name="Alarm">
<para>A textual description of the alarm that occurred.</para>
</parameter>
</syntax>
</managerEventInstance>
</managerEvent>
<managerEvent language="en_US" name="DAHDIChannel">
<managerEventInstance class="EVENT_FLAG_CALL">
<synopsis>Raised when a DAHDI channel is created or an underlying technology is associated with a DAHDI channel.</synopsis>
<syntax>
<channel_snapshot/>
<parameter name="DAHDISpan">
<para>The DAHDI span associated with this channel.</para>
</parameter>
<parameter name="DAHDIChannel">
<para>The DAHDI channel associated with this channel.</para>
</parameter>
</syntax>
</managerEventInstance>
</managerEvent>
***/
#define SMDI_MD_WAIT_TIMEOUT 1500 /* 1.5 seconds */
static const char * const lbostr[] = {
"0 db (CSU)/0-133 feet (DSX-1)",
"133-266 feet (DSX-1)",
"266-399 feet (DSX-1)",
"399-533 feet (DSX-1)",
"533-655 feet (DSX-1)",
"-7.5db (CSU)",
"-15db (CSU)",
"-22.5db (CSU)"
};
/*! Global jitterbuffer configuration - by default, jb is disabled
* \note Values shown here match the defaults shown in chan_dahdi.conf.sample */
static struct ast_jb_conf default_jbconf =
{
.flags = 0,
.max_size = 200,
.resync_threshold = 1000,
.impl = "fixed",
.target_extra = 40,
};
static struct ast_jb_conf global_jbconf;
/*!
* \note Define ZHONE_HACK to cause us to go off hook and then back on hook when
* the user hangs up to reset the state machine so ring works properly.
* This is used to be able to support kewlstart by putting the zhone in
* groundstart mode since their forward disconnect supervision is entirely
* broken even though their documentation says it isn't and their support
* is entirely unwilling to provide any assistance with their channel banks
* even though their web site says they support their products for life.
*/
/* #define ZHONE_HACK */
/*! \brief Typically, how many rings before we should send Caller*ID */
#define DEFAULT_CIDRINGS 1
#define AST_LAW(p) (((p)->law == DAHDI_LAW_ALAW) ? ast_format_alaw : ast_format_ulaw)
/*! \brief Signaling types that need to use MF detection should be placed in this macro */
#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))
static const char tdesc[] = "DAHDI Telephony"
#if defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2)
" w/"
#if defined(HAVE_PRI)
"PRI"
#endif /* defined(HAVE_PRI) */
#if defined(HAVE_SS7)
#if defined(HAVE_PRI)
" & "
#endif /* defined(HAVE_PRI) */
"SS7"
#endif /* defined(HAVE_SS7) */
#if defined(HAVE_OPENR2)
#if defined(HAVE_PRI) || defined(HAVE_SS7)
" & "
#endif /* defined(HAVE_PRI) || defined(HAVE_SS7) */
"MFC/R2"
#endif /* defined(HAVE_OPENR2) */
#endif /* defined(HAVE_PRI) || defined(HAVE_SS7) || defined(HAVE_OPENR2) */
;
static const char config[] = "chan_dahdi.conf";
#ifdef LOTS_OF_SPANS
#define NUM_SPANS DAHDI_MAX_SPANS
#else
#define NUM_SPANS 32
#endif
#define CHAN_PSEUDO -2
#define CALLPROGRESS_PROGRESS 1
#define CALLPROGRESS_FAX_OUTGOING 2
#define CALLPROGRESS_FAX_INCOMING 4
#define CALLPROGRESS_FAX (CALLPROGRESS_FAX_INCOMING | CALLPROGRESS_FAX_OUTGOING)
#define NUM_CADENCE_MAX 25
static int num_cadence = 4;
static int user_has_defined_cadences = 0;
static int has_pseudo;
static struct dahdi_ring_cadence cadences[NUM_CADENCE_MAX] = {
{ { 125, 125, 2000, 4000 } }, /*!< Quick chirp followed by normal ring */
{ { 250, 250, 500, 1000, 250, 250, 500, 4000 } }, /*!< British style ring */
{ { 125, 125, 125, 125, 125, 4000 } }, /*!< Three short bursts */
{ { 1000, 500, 2500, 5000 } }, /*!< Long ring */
};
/*! \brief cidrings says in which pause to transmit the cid information, where the first pause
* is 1, the second pause is 2 and so on.
*/
static int cidrings[NUM_CADENCE_MAX] = {
2, /*!< Right after first long ring */
4, /*!< Right after long part */
3, /*!< After third chirp */
2, /*!< Second spell */
};
/* ETSI EN300 659-1 specifies the ring pulse between 200 and 300 mS */
static struct dahdi_ring_cadence AS_RP_cadence = {{250, 10000}};
#define ISTRUNK(p) ((p->sig == SIG_FXSLS) || (p->sig == SIG_FXSKS) || \
(p->sig == SIG_FXSGS) || (p->sig == SIG_PRI))
#define CANBUSYDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
#define CANPROGRESSDETECT(p) (ISTRUNK(p) || (p->sig & (SIG_EM | SIG_EM_E1 | SIG_SF)) /* || (p->sig & __DAHDI_SIG_FXO) */)
static char defaultcic[64] = "";
static char defaultozz[64] = "";
/*! Run this script when the MWI state changes on an FXO line, if mwimonitor is enabled */
static char mwimonitornotify[PATH_MAX] = "";
#ifndef HAVE_DAHDI_LINEREVERSE_VMWI
static int mwisend_rpas = 0;
#endif
static char progzone[10] = "";
static int usedistinctiveringdetection = 0;
static int distinctiveringaftercid = 0;
static int numbufs = 4;
static int mwilevel = 512;
static int dtmfcid_level = 256;
#define REPORT_CHANNEL_ALARMS 1
#define REPORT_SPAN_ALARMS 2
static int report_alarms = REPORT_CHANNEL_ALARMS;
#ifdef HAVE_PRI
static int pridebugfd = -1;
static char pridebugfilename[1024] = "";
#endif
/*! \brief Wait up to 16 seconds for first digit (FXO logic) */
static int firstdigittimeout = 16000;
/*! \brief How long to wait for following digits (FXO logic) */
static int gendigittimeout = 8000;
/*! \brief How long to wait for an extra digit, if there is an ambiguous match */
static int matchdigittimeout = 3000;
/*! \brief Protect the interface list (of dahdi_pvt's) */
AST_MUTEX_DEFINE_STATIC(iflock);
static int ifcount = 0;
#ifdef HAVE_PRI
AST_MUTEX_DEFINE_STATIC(pridebugfdlock);
#endif
/*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
when it's doing something critical. */
AST_MUTEX_DEFINE_STATIC(monlock);
/*! \brief This is the thread for the monitor which checks for input on the channels
which are not currently in use. */
static pthread_t monitor_thread = AST_PTHREADT_NULL;
static ast_cond_t ss_thread_complete;
AST_MUTEX_DEFINE_STATIC(ss_thread_lock);
AST_MUTEX_DEFINE_STATIC(restart_lock);
static int ss_thread_count = 0;
static int num_restart_pending = 0;
static int restart_monitor(void);
static int dahdi_sendtext(struct ast_channel *c, const char *text);
/*! \brief Avoid the silly dahdi_getevent which ignores a bunch of events */
static inline int dahdi_get_event(int fd)
{
int j;
if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
return -1;
return j;
}
/*! \brief Avoid the silly dahdi_waitevent which ignores a bunch of events */
static inline int dahdi_wait_event(int fd)
{
int i, j = 0;
i = DAHDI_IOMUX_SIGEVENT;
if (ioctl(fd, DAHDI_IOMUX, &i) == -1)
return -1;
if (ioctl(fd, DAHDI_GETEVENT, &j) == -1)
return -1;
return j;
}
/*! Chunk size to read -- we use 20ms chunks to make things happy. */
#define READ_SIZE 160
#define MASK_AVAIL (1 << 0) /*!< Channel available for PRI use */
#define MASK_INUSE (1 << 1) /*!< Channel currently in use */
#define CALLWAITING_SILENT_SAMPLES ((300 * 8) / READ_SIZE) /*!< 300 ms */
#define CALLWAITING_REPEAT_SAMPLES ((10000 * 8) / READ_SIZE) /*!< 10,000 ms */
#define CALLWAITING_SUPPRESS_SAMPLES ((100 * 8) / READ_SIZE) /*!< 100 ms */
#define CIDCW_EXPIRE_SAMPLES ((500 * 8) / READ_SIZE) /*!< 500 ms */
#define MIN_MS_SINCE_FLASH ((2000) ) /*!< 2000 ms */
#define DEFAULT_RINGT ((8000 * 8) / READ_SIZE) /*!< 8,000 ms */
#define DEFAULT_DIALTONE_DETECT_TIMEOUT ((10000 * 8) / READ_SIZE) /*!< 10,000 ms */
/*!
* \brief Configured ring timeout base.
* \note Value computed from "ringtimeout" read in from chan_dahdi.conf if it exists.
*/
static int ringt_base = DEFAULT_RINGT;
#if defined(HAVE_SS7)
struct dahdi_ss7 {
struct sig_ss7_linkset ss7;
};
static struct dahdi_ss7 linksets[NUM_SPANS];
static int cur_ss7type = -1;
static int cur_slc = -1;
static int cur_linkset = -1;
static int cur_pointcode = -1;
static int cur_cicbeginswith = -1;
static int cur_adjpointcode = -1;
static int cur_networkindicator = -1;
static int cur_defaultdpc = -1;
#endif /* defined(HAVE_SS7) */
#ifdef HAVE_OPENR2
struct dahdi_mfcr2_conf {
openr2_variant_t variant;
int mfback_timeout;
int metering_pulse_timeout;
int max_ani;
int max_dnis;
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
int dtmf_time_on;
int dtmf_time_off;
#endif
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 3
int dtmf_end_timeout;
#endif
signed int get_ani_first:2;
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
signed int skip_category_request:2;
#endif
unsigned int call_files:1;
unsigned int allow_collect_calls:1;
unsigned int charge_calls:1;
unsigned int accept_on_offer:1;
unsigned int forced_release:1;
unsigned int double_answer:1;
signed int immediate_accept:2;
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
signed int dtmf_dialing:2;
signed int dtmf_detection:2;
#endif
char logdir[OR2_MAX_PATH];
char r2proto_file[OR2_MAX_PATH];
openr2_log_level_t loglevel;
openr2_calling_party_category_t category;
};
/* MFC-R2 pseudo-link structure */
struct dahdi_mfcr2 {
pthread_t r2master; /*!< Thread of master */
openr2_context_t *protocol_context; /*!< OpenR2 context handle */
struct dahdi_pvt *pvts[SIG_MFCR2_MAX_CHANNELS]; /*!< Member channel pvt structs */
int numchans; /*!< Number of channels in this R2 block */
struct dahdi_mfcr2_conf conf; /*!< Configuration used to setup this pseudo-link */
};
/* malloc'd array of malloc'd r2links */
static struct dahdi_mfcr2 **r2links;
/* how many r2links have been malloc'd */
static int r2links_count = 0;
#endif /* HAVE_OPENR2 */
#ifdef HAVE_PRI
struct dahdi_pri {
int dchannels[SIG_PRI_NUM_DCHANS]; /*!< What channel are the dchannels on */
int mastertrunkgroup; /*!< What trunk group is our master */
int prilogicalspan; /*!< Logical span number within trunk group */
struct sig_pri_span pri;
};
static struct dahdi_pri pris[NUM_SPANS];
#if defined(HAVE_PRI_CCSS)
/*! DAHDI PRI CCSS agent and monitor type name. */
static const char dahdi_pri_cc_type[] = "DAHDI/PRI";
#endif /* defined(HAVE_PRI_CCSS) */
#else
/*! Shut up the compiler */
struct dahdi_pri;
#endif
/* Polarity states */
#define POLARITY_IDLE 0
#define POLARITY_REV 1
const char * const subnames[] = {
"Real",
"Callwait",
"Threeway"
};
#define DATA_EXPORT_DAHDI_PVT(MEMBER) \
MEMBER(dahdi_pvt, cid_rxgain, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, rxgain, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, txgain, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, txdrc, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, rxdrc, AST_DATA_DOUBLE) \
MEMBER(dahdi_pvt, adsi, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, answeronpolarityswitch, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, busydetect, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, callreturn, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, callwaiting, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, callwaitingcallerid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, cancallforward, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, canpark, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, confirmanswer, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, destroy, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, didtdd, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, dialednone, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, dialing, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, digital, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, dnd, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, echobreak, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, echocanbridged, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, echocanon, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, faxhandled, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, usefaxbuffers, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, bufferoverrideinuse, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, firstradio, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, hanguponpolarityswitch, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, hardwaredtmf, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, hidecallerid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, hidecalleridname, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, ignoredtmf, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, immediate, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, inalarm, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mate, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, outgoing, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, permcallwaiting, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, priindication_oob, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, priexclusive, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, pulse, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, pulsedial, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, restartpending, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, restrictcid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, threewaycalling, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, transfer, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, use_callerid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, use_callingpres, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, usedistinctiveringdetection, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, dahditrcallerid, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, transfertobusy, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwimonitor_neon, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwimonitor_fsk, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwimonitor_rpas, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwimonitoractive, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, mwisendactive, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, inservice, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, locallyblocked, AST_DATA_UNSIGNED_INTEGER) \
MEMBER(dahdi_pvt, remotelyblocked, AST_DATA_UNSIGNED_INTEGER) \
MEMBER(dahdi_pvt, manages_span_alarms, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, use_smdi, AST_DATA_BOOLEAN) \
MEMBER(dahdi_pvt, context, AST_DATA_STRING) \
MEMBER(dahdi_pvt, defcontext, AST_DATA_STRING) \
MEMBER(dahdi_pvt, description, AST_DATA_STRING) \
MEMBER(dahdi_pvt, exten, AST_DATA_STRING) \
MEMBER(dahdi_pvt, language, AST_DATA_STRING) \
MEMBER(dahdi_pvt, mohinterpret, AST_DATA_STRING) \
MEMBER(dahdi_pvt, mohsuggest, AST_DATA_STRING) \
MEMBER(dahdi_pvt, parkinglot, AST_DATA_STRING)
AST_DATA_STRUCTURE(dahdi_pvt, DATA_EXPORT_DAHDI_PVT);
static struct dahdi_pvt *iflist = NULL; /*!< Main interface list start */
static struct dahdi_pvt *ifend = NULL; /*!< Main interface list end */
#if defined(HAVE_PRI)
struct doomed_pri {
struct sig_pri_span *pri;
AST_LIST_ENTRY(doomed_pri) list;
};
static AST_LIST_HEAD_STATIC(doomed_pris, doomed_pri);
static void pri_destroy_span(struct sig_pri_span *pri);
static struct dahdi_parms_pseudo {
int buf_no; /*!< Number of buffers */
int buf_policy; /*!< Buffer policy */
int faxbuf_no; /*!< Number of Fax buffers */
int faxbuf_policy; /*!< Fax buffer policy */
} dahdi_pseudo_parms;
#endif /* defined(HAVE_PRI) */
/*! \brief Channel configuration from chan_dahdi.conf .
* This struct is used for parsing the [channels] section of chan_dahdi.conf.
* Generally there is a field here for every possible configuration item.
*
* The state of fields is saved along the parsing and whenever a 'channel'
* statement is reached, the current dahdi_chan_conf is used to configure the
* channel (struct dahdi_pvt)
*
* \see dahdi_chan_init for the default values.
*/
struct dahdi_chan_conf {
struct dahdi_pvt chan;
#ifdef HAVE_PRI
struct dahdi_pri pri;
#endif
#if defined(HAVE_SS7)
struct dahdi_ss7 ss7;
#endif /* defined(HAVE_SS7) */
#ifdef HAVE_OPENR2
struct dahdi_mfcr2_conf mfcr2;
#endif
struct dahdi_params timing;
int is_sig_auto; /*!< Use channel signalling from DAHDI? */
/*! Continue configuration even if a channel is not there. */
int ignore_failed_channels;
/*!
* \brief The serial port to listen for SMDI data on
* \note Set from the "smdiport" string read in from chan_dahdi.conf
*/
char smdi_port[SMDI_MAX_FILENAME_LEN];
/*!
* \brief Don't create channels below this number
* \note by default is 0 (no limit)
*/
int wanted_channels_start;
/*!
* \brief Don't create channels above this number (infinity by default)
* \note by default is 0 (special value that means "no limit").
*/
int wanted_channels_end;
};
/*! returns a new dahdi_chan_conf with default values (by-value) */
static struct dahdi_chan_conf dahdi_chan_conf_default(void)
{
/* recall that if a field is not included here it is initialized
* to 0 or equivalent
*/
struct dahdi_chan_conf conf = {
#ifdef HAVE_PRI
.pri.pri = {
.nsf = PRI_NSF_NONE,
.switchtype = PRI_SWITCH_NI2,
.dialplan = PRI_UNKNOWN + 1,
.localdialplan = PRI_NATIONAL_ISDN + 1,
.nodetype = PRI_CPE,
.qsigchannelmapping = DAHDI_CHAN_MAPPING_PHYSICAL,
#if defined(HAVE_PRI_CCSS)
.cc_ptmp_recall_mode = 1,/* specificRecall */
.cc_qsig_signaling_link_req = 1,/* retain */
.cc_qsig_signaling_link_rsp = 1,/* retain */
#endif /* defined(HAVE_PRI_CCSS) */
.minunused = 2,
.idleext = "",
.idledial = "",
.internationalprefix = "",
.nationalprefix = "",
.localprefix = "",
.privateprefix = "",
.unknownprefix = "",
.colp_send = SIG_PRI_COLP_UPDATE,
.resetinterval = -1,
},
#endif
#if defined(HAVE_SS7)
.ss7.ss7 = {
.called_nai = SS7_NAI_NATIONAL,
.calling_nai = SS7_NAI_NATIONAL,
.internationalprefix = "",
.nationalprefix = "",
.subscriberprefix = "",
.unknownprefix = "",
.networkroutedprefix = ""
},
#endif /* defined(HAVE_SS7) */
#ifdef HAVE_OPENR2
.mfcr2 = {
.variant = OR2_VAR_ITU,
.mfback_timeout = -1,
.metering_pulse_timeout = -1,
.max_ani = 10,
.max_dnis = 4,
.get_ani_first = -1,
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 1
.skip_category_request = -1,
#endif
.call_files = 0,
.allow_collect_calls = 0,
.charge_calls = 1,
.accept_on_offer = 1,
.forced_release = 0,
.double_answer = 0,
.immediate_accept = -1,
#if defined(OR2_LIB_INTERFACE) && OR2_LIB_INTERFACE > 2
.dtmf_dialing = -1,
.dtmf_detection = -1,
.dtmf_time_on = OR2_DEFAULT_DTMF_ON,
.dtmf_time_off = OR2_DEFAULT_DTMF_OFF,