Asterisk - The Open Source Telephony Project GIT-master-545c459
Loading...
Searching...
No Matches
sig_analog.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2009, Digium, Inc.
5 *
6 * Mark Spencer <markster@digium.com>
7 *
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.
13 *
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.
17 */
18
19/*! \file
20 *
21 * \brief Analog signaling module
22 *
23 * \author Matthew Fredrickson <creslin@digium.com>
24 */
25
26/*** MODULEINFO
27 <support_level>core</support_level>
28 ***/
29
30#include "asterisk.h"
31
32#include <errno.h>
33#include <ctype.h>
34
35#include "asterisk/utils.h"
36#include "asterisk/options.h"
37#include "asterisk/pickup.h"
38#include "asterisk/pbx.h"
39#include "asterisk/file.h"
40#include "asterisk/callerid.h"
41#include "asterisk/say.h"
42#include "asterisk/manager.h"
43#include "asterisk/astdb.h"
44#include "asterisk/features.h"
45#include "asterisk/causes.h"
47#include "asterisk/bridge.h"
48#include "asterisk/parking.h"
49
50#include "sig_analog.h"
51
52/*** DOCUMENTATION
53 ***/
54
55/*! \note
56 * Define if you want to check the hook state for an FXO (FXS signalled) interface
57 * before dialing on it. Certain FXO interfaces always think they're out of
58 * service with this method however.
59 */
60/* #define DAHDI_CHECK_HOOKSTATE */
61
62#define POLARITY_IDLE 0
63#define POLARITY_REV 1
64#define MIN_MS_SINCE_FLASH ( (2000) ) /*!< 2000 ms */
65static char analog_defaultcic[64] = "";
66static char analog_defaultozz[64] = "";
67
68static const struct {
70 const char *name;
71} sigtypes[] = {
72 { ANALOG_SIG_FXOLS, "fxo_ls" },
73 { ANALOG_SIG_FXOKS, "fxo_ks" },
74 { ANALOG_SIG_FXOGS, "fxo_gs" },
75 { ANALOG_SIG_FXSLS, "fxs_ls" },
76 { ANALOG_SIG_FXSKS, "fxs_ks" },
77 { ANALOG_SIG_FXSGS, "fxs_gs" },
78 { ANALOG_SIG_EMWINK, "em_w" },
79 { ANALOG_SIG_EM, "em" },
80 { ANALOG_SIG_EM_E1, "em_e1" },
81 { ANALOG_SIG_FEATD, "featd" },
82 { ANALOG_SIG_FEATDMF, "featdmf" },
83 { ANALOG_SIG_FEATDMF_TA, "featdmf_ta" },
84 { ANALOG_SIG_FEATB, "featb" },
85 { ANALOG_SIG_FGC_CAMA, "fgccama" },
86 { ANALOG_SIG_FGC_CAMAMF, "fgccamamf" },
87 { ANALOG_SIG_SF, "sf" },
88 { ANALOG_SIG_SFWINK, "sf_w" },
89 { ANALOG_SIG_SF_FEATD, "sf_featd" },
90 { ANALOG_SIG_SF_FEATDMF, "sf_featdmf" },
91 { ANALOG_SIG_SF_FEATB, "sf_featb" },
92 { ANALOG_SIG_E911, "e911" },
93};
94
95static const struct {
96 unsigned int cid_type;
97 const char *name;
98} cidtypes[] = {
99 { CID_SIG_BELL, "bell" },
100 { CID_SIG_V23, "v23" },
101 { CID_SIG_V23_JP, "v23_jp" },
102 { CID_SIG_DTMF, "dtmf" },
103 /* "smdi" is intentionally not supported here, as there is a much better
104 * way to do this in the dialplan now. */
106
107/*! \brief Whether a channel is FXS signaled */
108#define ISTRUNK(p) ((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || \
109 (p->sig == ANALOG_SIG_FXSGS))
110
111/*! \brief Whether a channel is FXO signaled */
112#define IS_FXO_SIG(p) (((p)->sig == ANALOG_SIG_FXOKS) || ((p)->sig == ANALOG_SIG_FXOLS) || ((p)->sig == ANALOG_SIG_FXOGS))
113
115{
116 int i;
117
118 for (i = 0; i < ARRAY_LEN(sigtypes); i++) {
119 if (!strcasecmp(sigtypes[i].name, name)) {
120 return sigtypes[i].sigtype;
121 }
122 }
123
124 return 0;
125}
126
128{
129 int i;
130
131 for (i = 0; i < ARRAY_LEN(sigtypes); i++) {
132 if (sigtype == sigtypes[i].sigtype) {
133 return sigtypes[i].name;
134 }
135 }
136
137 return "Unknown";
138}
139
140unsigned int analog_str_to_cidtype(const char *name)
141{
142 int i;
143
144 for (i = 0; i < ARRAY_LEN(cidtypes); i++) {
145 if (!strcasecmp(cidtypes[i].name, name)) {
146 return cidtypes[i].cid_type;
147 }
148 }
149
150 return 0;
151}
152
153const char *analog_cidtype_to_str(unsigned int cid_type)
154{
155 int i;
156
157 for (i = 0; i < ARRAY_LEN(cidtypes); i++) {
158 if (cid_type == cidtypes[i].cid_type) {
159 return cidtypes[i].name;
160 }
161 }
162
163 return "Unknown";
164}
165
166static int analog_start_cid_detect(struct analog_pvt *p, int cid_signalling)
167{
169 return analog_callbacks.start_cid_detect(p->chan_pvt, cid_signalling);
170 }
171 return -1;
172}
173
175{
178 }
179 return -1;
180}
181
182static int analog_get_callerid(struct analog_pvt *p, char *name, char *number, enum analog_event *ev, size_t timeout)
183{
185 return analog_callbacks.get_callerid(p->chan_pvt, name, number, ev, timeout);
186 }
187 return -1;
188}
189
190static const char *analog_get_orig_dialstring(struct analog_pvt *p)
191{
194 }
195 return "";
196}
197
198static int analog_get_event(struct analog_pvt *p)
199{
202 }
203 return -1;
204}
205
206static int analog_wait_event(struct analog_pvt *p)
207{
210 }
211 return -1;
212}
213
215{
218 }
219 /* Don't have progress detection. */
220 return 0;
221}
222
223#define gen_analog_field_callback(type, callback_name, def_value) \
224 static type analog_get_##callback_name(struct analog_pvt *p) \
225 { \
226 if (!analog_callbacks.get_##callback_name) { \
227 return def_value; \
228 } \
229 return analog_callbacks.get_##callback_name(p->chan_pvt); \
230 }
231
235
236#undef gen_analog_field_callback
237
239{
240 if (!strcasecmp(value, "ring")) {
242 } else if (!strcasecmp(value, "polarity")) {
244 } else if (!strcasecmp(value, "polarity_in")) {
246 } else if (!strcasecmp(value, "dtmf")) {
248 }
249
250 return 0;
251}
252
253const char *analog_cidstart_to_str(enum analog_cid_start cid_start)
254{
255 switch (cid_start) {
257 return "Ring";
259 return "Polarity";
261 return "Polarity_In";
263 return "DTMF";
264 }
265
266 return "Unknown";
267}
268
270{
271 char *res;
272 switch (event) {
274 res = "ANALOG_EVENT_ONHOOK";
275 break;
277 res = "ANALOG_EVENT_RINGOFFHOOK";
278 break;
280 res = "ANALOG_EVENT_WINKFLASH";
281 break;
283 res = "ANALOG_EVENT_ALARM";
284 break;
286 res = "ANALOG_EVENT_NOALARM";
287 break;
289 res = "ANALOG_EVENT_DIALCOMPLETE";
290 break;
292 res = "ANALOG_EVENT_HOOKCOMPLETE";
293 break;
295 res = "ANALOG_EVENT_PULSE_START";
296 break;
298 res = "ANALOG_EVENT_POLARITY";
299 break;
301 res = "ANALOG_EVENT_RINGBEGIN";
302 break;
304 res = "ANALOG_EVENT_EC_DISABLED";
305 break;
307 res = "ANALOG_EVENT_RINGERON";
308 break;
310 res = "ANALOG_EVENT_RINGEROFF";
311 break;
313 res = "ANALOG_EVENT_REMOVED";
314 break;
316 res = "ANALOG_EVENT_NEONMWI_ACTIVE";
317 break;
319 res = "ANALOG_EVENT_NEONMWI_INACTIVE";
320 break;
321#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
323 res = "ANALOG_EVENT_TX_CED_DETECTED";
324 break;
326 res = "ANALOG_EVENT_RX_CED_DETECTED";
327 break;
329 res = "ANALOG_EVENT_EC_NLP_DISABLED";
330 break;
332 res = "ANALOG_EVENT_EC_NLP_ENABLED";
333 break;
334#endif
336 res = "ANALOG_EVENT_PULSEDIGIT";
337 break;
339 res = "ANALOG_EVENT_DTMFDOWN";
340 break;
342 res = "ANALOG_EVENT_DTMFUP";
343 break;
344 default:
345 res = "UNKNOWN/OTHER";
346 break;
347 }
348
349 return res;
350}
351
352static void analog_swap_subs(struct analog_pvt *p, enum analog_sub a, enum analog_sub b)
353{
354 int tinthreeway;
355 struct ast_channel *towner;
356
357 ast_debug(1, "Swapping %u and %u\n", a, b);
358
359 towner = p->subs[a].owner;
360 p->subs[a].owner = p->subs[b].owner;
361 p->subs[b].owner = towner;
362
363 tinthreeway = p->subs[a].inthreeway;
364 p->subs[a].inthreeway = p->subs[b].inthreeway;
365 p->subs[b].inthreeway = tinthreeway;
366
369 }
370}
371
372static int analog_alloc_sub(struct analog_pvt *p, enum analog_sub x)
373{
375 int res;
377 if (!res) {
378 p->subs[x].allocd = 1;
379 }
380 return res;
381 }
382 return 0;
383}
384
385static int analog_unalloc_sub(struct analog_pvt *p, enum analog_sub x)
386{
387 p->subs[x].allocd = 0;
388 p->subs[x].owner = NULL;
391 }
392 return 0;
393}
394
395static int analog_send_callerid(struct analog_pvt *p, int cwcid, struct ast_party_caller *caller)
396{
397 /* If Caller ID is disabled for the line, that means we do not send ANY spill whatsoever. */
398 if (!p->use_callerid) {
399 ast_debug(1, "Caller ID is disabled for channel %d, skipping spill\n", p->channel);
400 return 0;
401 }
402
403 ast_debug(1, "Sending callerid. CID_NAME: '%s' CID_NUM: '%s'\n",
404 caller->id.name.str,
406
407 if (cwcid) {
408 p->callwaitcas = 0;
409 }
410
413 }
414 return 0;
415}
416
417#define analog_get_index(ast, p, nullok) _analog_get_index(ast, p, nullok, __PRETTY_FUNCTION__, __LINE__)
418static int _analog_get_index(struct ast_channel *ast, struct analog_pvt *p, int nullok, const char *fname, unsigned long line)
419{
420 int res;
421 if (p->subs[ANALOG_SUB_REAL].owner == ast) {
422 res = ANALOG_SUB_REAL;
423 } else if (p->subs[ANALOG_SUB_CALLWAIT].owner == ast) {
425 } else if (p->subs[ANALOG_SUB_THREEWAY].owner == ast) {
427 } else {
428 res = -1;
429 if (!nullok) {
431 "Unable to get index for '%s' on channel %d (%s(), line %lu)\n",
432 ast ? ast_channel_name(ast) : "", p->channel, fname, line);
433 }
434 }
435 return res;
436}
437
439{
442 }
443
444 /* Return 0 since I think this is unnecessary to do in most cases it is used. Mostly only for ast_dsp */
445 return 0;
446}
447
448static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
449{
451 return analog_callbacks.play_tone(p->chan_pvt, sub, tone);
452 }
453 return -1;
454}
455
456static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
457{
458 p->owner = new_owner;
461 }
462}
463
464static struct ast_channel * analog_new_ast_channel(struct analog_pvt *p, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
465{
466 struct ast_channel *c;
467
469 return NULL;
470 }
471
472 c = analog_callbacks.new_ast_channel(p->chan_pvt, state, startpbx, sub, requestor);
473 if (c) {
474 ast_channel_call_forward_set(c, p->call_forward);
475 }
476 p->subs[sub].owner = c;
477 if (!p->owner) {
479 }
480 return c;
481}
482
483static int analog_set_echocanceller(struct analog_pvt *p, int enable)
484{
487 }
488 return -1;
489}
490
492{
495 }
496 return -1;
497}
498
499static int analog_is_off_hook(struct analog_pvt *p)
500{
503 }
504 return -1;
505}
506
507static int analog_ring(struct analog_pvt *p)
508{
510 return analog_callbacks.ring(p->chan_pvt);
511 }
512 return -1;
513}
514
515static int analog_flash(struct analog_pvt *p)
516{
519 }
520 return -1;
521}
522
523static int analog_start(struct analog_pvt *p)
524{
527 }
528 return -1;
529}
530
531static int analog_dial_digits(struct analog_pvt *p, enum analog_sub sub, struct analog_dialoperation *dop)
532{
534 return analog_callbacks.dial_digits(p->chan_pvt, sub, dop);
535 }
536 return -1;
537}
538
539static int analog_on_hook(struct analog_pvt *p)
540{
543 }
544 return -1;
545}
546
547static void analog_set_outgoing(struct analog_pvt *p, int is_outgoing)
548{
549 p->outgoing = is_outgoing;
551 analog_callbacks.set_outgoing(p->chan_pvt, is_outgoing);
552 }
553}
554
556{
559 }
560 return -1;
561}
562
569
576
577static void analog_lock_private(struct analog_pvt *p)
578{
581 }
582}
583
585{
588 } else {
589 /* Fallback to manual avoidance if callback not present. */
591 usleep(1);
593 }
594}
595
596/*!
597 * \internal
598 * \brief Obtain the specified subchannel owner lock if the owner exists.
599 *
600 * \param pvt Analog private struct.
601 * \param sub_idx Subchannel owner to lock.
602 *
603 * \note Assumes the analog_lock_private(pvt->chan_pvt) is already obtained.
604 *
605 * \note
606 * Because deadlock avoidance may have been necessary, you need to confirm
607 * the state of things before continuing.
608 */
609static void analog_lock_sub_owner(struct analog_pvt *pvt, enum analog_sub sub_idx)
610{
611 for (;;) {
612 if (!pvt->subs[sub_idx].owner) {
613 /* No subchannel owner pointer */
614 break;
615 }
616 if (!ast_channel_trylock(pvt->subs[sub_idx].owner)) {
617 /* Got subchannel owner lock */
618 break;
619 }
620 /* We must unlock the private to avoid the possibility of a deadlock */
622 }
623}
624
625static int analog_off_hook(struct analog_pvt *p)
626{
629 }
630 return -1;
631}
632
639
640#if 0
641static void analog_set_polarity(struct analog_pvt *p, int value)
642{
645 }
646}
647#endif
648
661
668
670{
673 }
674 return -1;
675}
676
677static void analog_cb_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
678{
680 analog_callbacks.handle_dtmf(p->chan_pvt, ast, analog_index, dest);
681 }
682}
683
684static int analog_wink(struct analog_pvt *p, enum analog_sub index)
685{
687 return analog_callbacks.wink(p->chan_pvt, index);
688 }
689 return -1;
690}
691
692static int analog_has_voicemail(struct analog_pvt *p)
693{
696 }
697 return -1;
698}
699
700static int analog_is_dialing(struct analog_pvt *p, enum analog_sub index)
701{
703 return analog_callbacks.is_dialing(p->chan_pvt, index);
704 }
705 return -1;
706}
707
708/*!
709 * \internal
710 * \brief Attempt to transfer 3-way call.
711 *
712 * \param p Analog private structure.
713 *
714 * \note On entry these locks are held: real-call, private, 3-way call.
715 * \note On exit these locks are held: real-call, private.
716 *
717 * \retval 0 on success.
718 * \retval -1 on error.
719 */
721{
722 struct ast_channel *owner_real;
723 struct ast_channel *owner_3way;
724 enum ast_transfer_result xfer_res;
725 int res = 0;
726
727 owner_real = ast_channel_ref(p->subs[ANALOG_SUB_REAL].owner);
729
730 ast_verb(3, "TRANSFERRING %s to %s\n",
731 ast_channel_name(owner_3way), ast_channel_name(owner_real));
732
733 ast_channel_unlock(owner_real);
734 ast_channel_unlock(owner_3way);
736
737 xfer_res = ast_bridge_transfer_attended(owner_3way, owner_real);
738 if (xfer_res != AST_BRIDGE_TRANSFER_SUCCESS) {
740 res = -1;
741 }
742
743 /* Must leave with these locked. */
744 ast_channel_lock(owner_real);
746
747 ast_channel_unref(owner_real);
748 ast_channel_unref(owner_3way);
749
750 return res;
751}
752
753static int analog_update_conf(struct analog_pvt *p)
754{
755 int x;
756 int needconf = 0;
757
758 /* Start with the obvious, general stuff */
759 for (x = 0; x < 3; x++) {
760 /* Look for three way calls */
761 if ((p->subs[x].allocd) && p->subs[x].inthreeway) {
764 }
765 needconf++;
766 } else {
769 }
770 }
771 }
772 ast_debug(1, "Updated conferencing on %d, with %d conference users\n", p->channel, needconf);
773
776 }
777 return 0;
778}
779
780struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor)
781{
782 struct ast_channel *ast;
783
784 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
785 *callwait = (p->owner != NULL);
786
787 if (p->owner) {
789 ast_log(LOG_ERROR, "Unable to alloc subchannel\n");
790 return NULL;
791 }
792 }
793
796 p->owner ? ANALOG_SUB_CALLWAIT : ANALOG_SUB_REAL, requestor);
797 if (!ast) {
799 }
800 return ast;
801}
802
804{
805 int offhook;
806
807 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
808
809 /* If do not disturb, definitely not */
810 if (p->dnd) {
811 return 0;
812 }
813 /* If guard time, definitely not */
814 if (p->guardtime && (time(NULL) < p->guardtime)) {
815 return 0;
816 }
817
818 /* If line is being held, definitely not (don't allow call waitings to an on-hook phone) */
819 if (p->cshactive) {
820 return 0;
821 }
822
823 /* If no owner definitely available */
824 if (!p->owner) {
825 offhook = analog_is_off_hook(p);
826
827 /* TDM FXO card, "onhook" means out of service (no battery on the line) */
828 if ((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || (p->sig == ANALOG_SIG_FXSGS)) {
829#ifdef DAHDI_CHECK_HOOKSTATE
830 if (offhook) {
831 return 1;
832 }
833 return 0;
834#endif
835 /* TDM FXS card, "offhook" means someone took the hook off so it's unavailable! */
836 } else if (offhook) {
837 ast_debug(1, "Channel %d off hook, can't use\n", p->channel);
838 /* Not available when the other end is off hook */
839 return 0;
840 }
841 return 1;
842 }
843
844 /* If it's not an FXO, forget about call wait */
845 if (!IS_FXO_SIG(p)) {
846 return 0;
847 }
848
849 if (!p->callwaiting) {
850 /* If they don't have call waiting enabled, then for sure they're unavailable at this point */
851 return 0;
852 }
853
855 /* If there is already a call waiting call, then we can't take a second one */
856 return 0;
857 }
858
859 if ((ast_channel_state(p->owner) != AST_STATE_UP) &&
861 /* If the current call is not up, then don't allow the call */
862 return 0;
863 }
865 /* Can't take a call wait when the three way calling hasn't been merged yet. */
866 return 0;
867 }
868 /* We're cool */
869 return 1;
870}
871
872static int analog_stop_callwait(struct analog_pvt *p)
873{
874 p->callwaitcas = 0;
875
876 /* There are 3 scenarios in which we need to reset the dialmode to permdialmode.
877 * 1) When placing a new outgoing call (either the first or a three-way)
878 * 2) When receiving a new incoming call
879 * 2A) If it's the first incoming call (not a call waiting), we reset
880 * in dahdi_hangup.
881 * 2B ) If it's a call waiting we've answered, either by swapping calls
882 * or having it ring through, we call analog_stop_callwait. That's this! */
883 p->dialmode = p->permdialmode;
884
887 }
888 return 0;
889}
890
891static int analog_callwait(struct analog_pvt *p)
892{
896 }
897 return 0;
898}
899
900static void analog_set_callwaiting(struct analog_pvt *p, int callwaiting_enable)
901{
902 p->callwaiting = callwaiting_enable;
904 analog_callbacks.set_callwaiting(p->chan_pvt, callwaiting_enable);
905 }
906}
907
908static void analog_set_cadence(struct analog_pvt *p, struct ast_channel *chan)
909{
912 }
913}
914
915static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
916{
917 p->dialing = is_dialing;
919 analog_callbacks.set_dialing(p->chan_pvt, is_dialing);
920 }
921}
922
923static void analog_set_alarm(struct analog_pvt *p, int in_alarm)
924{
925 p->inalarm = in_alarm;
927 analog_callbacks.set_alarm(p->chan_pvt, in_alarm);
928 }
929}
930
931static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
932{
933 p->ringt = ringt;
936 }
937}
938
939static void analog_set_waitingfordt(struct analog_pvt *p, struct ast_channel *ast)
940{
943 }
944}
945
947{
950 }
951
952 return 0;
953}
954
961
963{
966 }
967
968 return 0;
969}
970
977
978static int analog_confmute(struct analog_pvt *p, int mute)
979{
981 return analog_callbacks.confmute(p->chan_pvt, mute);
982 }
983 return 0;
984}
985
986static void analog_set_pulsedial(struct analog_pvt *p, int flag)
987{
990 }
991}
992
993static int analog_set_linear_mode(struct analog_pvt *p, enum analog_sub sub, int linear_mode)
994{
996 /* Return provides old linear_mode setting or error indication */
997 return analog_callbacks.set_linear_mode(p->chan_pvt, sub, linear_mode);
998 }
999 return -1;
1000}
1001
1002static void analog_set_inthreeway(struct analog_pvt *p, enum analog_sub sub, int inthreeway)
1003{
1004 p->subs[sub].inthreeway = inthreeway;
1007 }
1008}
1009
1010int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout)
1011{
1012 int res, idx, mysig;
1013 char *c, *n, *l;
1014 char dest[256]; /* must be same length as p->dialdest */
1015
1016 ast_debug(1, "CALLING CID_NAME: %s CID_NUM:: %s\n",
1017 S_COR(ast_channel_connected(ast)->id.name.valid, ast_channel_connected(ast)->id.name.str, ""),
1018 S_COR(ast_channel_connected(ast)->id.number.valid, ast_channel_connected(ast)->id.number.str, ""));
1019
1020 ast_copy_string(dest, rdest, sizeof(dest));
1021 ast_copy_string(p->dialdest, rdest, sizeof(p->dialdest));
1022
1023 if ((ast_channel_state(ast) == AST_STATE_BUSY)) {
1025 return 0;
1026 }
1027
1029 ast_log(LOG_WARNING, "analog_call called on %s, neither down nor reserved\n", ast_channel_name(ast));
1030 return -1;
1031 }
1032
1033 p->dialednone = 0;
1034 analog_set_outgoing(p, 1);
1035
1036 mysig = p->sig;
1037 if (p->outsigmod > -1) {
1038 mysig = p->outsigmod;
1039 }
1040
1041 switch (mysig) {
1042 case ANALOG_SIG_FXOLS:
1043 case ANALOG_SIG_FXOGS:
1044 case ANALOG_SIG_FXOKS:
1045 if (p->owner == ast) {
1046 /* Normal ring, on hook */
1047
1048 /* Don't send audio while on hook, until the call is answered */
1049 analog_set_dialing(p, 1);
1050 analog_set_cadence(p, ast); /* and set p->cidrings */
1051
1052 /* nick@dccinc.com 4/3/03 mods to allow for deferred dialing */
1053 c = strchr(dest, '/');
1054 if (c) {
1055 c++;
1056 }
1057 if (c && (strlen(c) < p->stripmsd)) {
1058 ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1059 c = NULL;
1060 }
1061 if (c && (strlen(c) > sizeof(p->dop.dialstr) - 3 /* "Tw\0" */)) {
1062 ast_log(LOG_WARNING, "Number '%s' is longer than %d bytes\n", c, (int)sizeof(p->dop.dialstr) - 2);
1063 c = NULL;
1064 }
1065 if (c) {
1067 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "Tw%s", c);
1068 ast_debug(1, "FXO: setup deferred dialstring: %s\n", c);
1069 } else {
1070 p->dop.dialstr[0] = '\0';
1071 }
1072
1073 if (analog_ring(p)) {
1074 ast_log(LOG_WARNING, "Unable to ring phone: %s\n", strerror(errno));
1075 return -1;
1076 }
1077 analog_set_dialing(p, 1);
1078 } else {
1079 /* Call waiting call */
1080 if (ast_channel_connected(ast)->id.number.valid && ast_channel_connected(ast)->id.number.str) {
1082 } else {
1083 p->callwait_num[0] = '\0';
1084 }
1085 if (ast_channel_connected(ast)->id.name.valid && ast_channel_connected(ast)->id.name.str) {
1087 } else {
1088 p->callwait_name[0] = '\0';
1089 }
1090
1091 /* Call waiting tone instead */
1092 if (analog_callwait(p)) {
1093 return -1;
1094 }
1095 /* Make ring-back */
1097 ast_log(LOG_WARNING, "Unable to generate call-wait ring-back on channel %s\n", ast_channel_name(ast));
1098 }
1099
1100 }
1101
1102 /* Name and Number */
1105 if (l) {
1106 ast_copy_string(p->lastcid_num, l, sizeof(p->lastcid_num));
1107 } else {
1108 p->lastcid_num[0] = '\0';
1109 }
1110 if (n) {
1111 ast_copy_string(p->lastcid_name, n, sizeof(p->lastcid_name));
1112 } else {
1113 p->lastcid_name[0] = '\0';
1114 }
1115
1116 if (p->use_callerid) {
1117 const char *qual_var;
1118
1119 /* Caller ID Name and Number */
1120 p->caller.id.name.str = p->lastcid_name;
1121 p->caller.id.number.str = p->lastcid_num;
1126
1127 /* Redirecting Reason */
1129
1130 /* Call Qualifier */
1131 ast_channel_lock(ast);
1132 /* XXX In the future, we may want to make this a CALLERID or CHANNEL property and fetch it from there. */
1133 qual_var = pbx_builtin_getvar_helper(ast, "CALL_QUALIFIER");
1134 p->call_qualifier = ast_true(qual_var) ? 1 : 0;
1135 ast_channel_unlock(ast);
1136 }
1137
1139 idx = analog_get_index(ast, p, 0);
1140 if (idx > -1) {
1141 struct ast_cc_config_params *cc_params;
1142
1143 /* This is where the initial ringing frame is queued for an analog call.
1144 * As such, this is a great time to offer CCNR to the caller if it's available.
1145 */
1146 cc_params = ast_channel_get_cc_config_params(p->subs[idx].owner);
1147 if (cc_params) {
1148 switch (ast_get_cc_monitor_policy(cc_params)) {
1150 break;
1156 break;
1157 }
1158 }
1160 }
1161 break;
1162 case ANALOG_SIG_FXSLS:
1163 case ANALOG_SIG_FXSGS:
1164 case ANALOG_SIG_FXSKS:
1166 ast_debug(1, "Ignore possible polarity reversal on line seizure\n");
1168 }
1169 /* fall through */
1170 case ANALOG_SIG_EMWINK:
1171 case ANALOG_SIG_EM:
1172 case ANALOG_SIG_EM_E1:
1173 case ANALOG_SIG_FEATD:
1174 case ANALOG_SIG_FEATDMF:
1175 case ANALOG_SIG_E911:
1178 case ANALOG_SIG_FEATB:
1179 case ANALOG_SIG_SFWINK:
1180 case ANALOG_SIG_SF:
1185 c = strchr(dest, '/');
1186 if (c) {
1187 c++;
1188 } else {
1189 c = "";
1190 }
1191 if (strlen(c) < p->stripmsd) {
1192 ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1193 return -1;
1194 }
1195 res = analog_start(p);
1196 if (res < 0) {
1197 if (errno != EINPROGRESS) {
1198 return -1;
1199 }
1200 }
1201 ast_debug(1, "Dialing '%s'\n", c);
1203
1204 c += p->stripmsd;
1205
1206 switch (mysig) {
1207 case ANALOG_SIG_FEATD:
1209 if (l) {
1210 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T*%s*%s*", l, c);
1211 } else {
1212 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T**%s*", c);
1213 }
1214 break;
1215 case ANALOG_SIG_FEATDMF:
1217 if (l) {
1218 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*00%s#*%s#", l, c);
1219 } else {
1220 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*02#*%s#", c);
1221 }
1222 break;
1224 {
1225 const char *cic = "", *ozz = "";
1226
1227 /* If you have to go through a Tandem Access point you need to use this */
1228#ifndef STANDALONE
1229 ozz = pbx_builtin_getvar_helper(p->owner, "FEATDMF_OZZ");
1230 if (!ozz) {
1231 ozz = analog_defaultozz;
1232 }
1233 cic = pbx_builtin_getvar_helper(p->owner, "FEATDMF_CIC");
1234 if (!cic) {
1235 cic = analog_defaultcic;
1236 }
1237#endif
1238 if (!ozz || !cic) {
1239 ast_log(LOG_WARNING, "Unable to dial channel of type feature group D MF tandem access without CIC or OZZ set\n");
1240 return -1;
1241 }
1242 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s%s#", ozz, cic);
1243 snprintf(p->finaldial, sizeof(p->finaldial), "M*%s#", c);
1244 p->whichwink = 0;
1245 }
1246 break;
1247 case ANALOG_SIG_E911:
1248 ast_copy_string(p->dop.dialstr, "M*911#", sizeof(p->dop.dialstr));
1249 break;
1251 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%s", c);
1252 break;
1254 case ANALOG_SIG_FEATB:
1255 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s#", c);
1256 break;
1257 default:
1258 if (p->pulse) {
1259 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%sw", c);
1260 } else {
1261 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T%sw", c);
1262 }
1263 break;
1264 }
1265
1266 if (p->echotraining && (strlen(p->dop.dialstr) > 4)) {
1267 memset(p->echorest, 'w', sizeof(p->echorest) - 1);
1268 strcpy(p->echorest + (p->echotraining / 400) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
1269 p->echorest[sizeof(p->echorest) - 1] = '\0';
1270 p->echobreak = 1;
1271 p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
1272 } else {
1273 p->echobreak = 0;
1274 }
1276 if (!res) {
1277 if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
1278 analog_on_hook(p);
1279 return -1;
1280 }
1281 } else {
1282 ast_debug(1, "Deferring dialing...\n");
1283 }
1284 analog_set_dialing(p, 1);
1285 if (ast_strlen_zero(c)) {
1286 p->dialednone = 1;
1287 }
1289 break;
1290 default:
1291 ast_debug(1, "not yet implemented\n");
1292 return -1;
1293 }
1294 return 0;
1295}
1296
1297int analog_hangup(struct analog_pvt *p, struct ast_channel *ast)
1298{
1299 int res;
1300 int idx, x;
1301
1302 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1303 if (!ast_channel_tech_pvt(ast)) {
1304 ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
1305 return 0;
1306 }
1307
1308 idx = analog_get_index(ast, p, 1);
1309
1310 x = 0;
1311 if (p->origcid_num) {
1312 ast_copy_string(p->cid_num, p->origcid_num, sizeof(p->cid_num));
1314 p->origcid_num = NULL;
1315 }
1316 if (p->origcid_name) {
1317 ast_copy_string(p->cid_name, p->origcid_name, sizeof(p->cid_name));
1319 p->origcid_name = NULL;
1320 }
1321
1323
1324 ast_debug(1, "Hangup: channel: %d index = %d, normal = %d, callwait = %d, thirdcall = %d\n",
1326 if (idx > -1) {
1327 /* Real channel, do some fixup */
1328 p->cshactive = 0;
1329 p->subs[idx].owner = NULL;
1331 analog_set_linear_mode(p, idx, 0);
1332 switch (idx) {
1333 case ANALOG_SUB_REAL:
1335 ast_debug(1, "Normal call hung up with both three way call and a call waiting call in place?\n");
1337 /* We had flipped over to answer a callwait and now it's gone */
1338 ast_debug(1, "We were flipped over to the callwait, moving back and not owning.\n");
1339 /* Move to the call-wait, but un-own us until they flip back. */
1343 } else {
1344 /* The three way hung up, but we still have a call wait */
1345 ast_debug(1, "We were in the threeway and have a callwait still. Ditching the threeway.\n");
1349 /* This was part of a three way call. Immediately make way for
1350 another call */
1351 ast_debug(1, "Call was complete, setting owner to former third call\n");
1354 } else {
1355 /* This call hasn't been completed yet... Set owner to NULL */
1356 ast_debug(1, "Call was incomplete, setting owner to NULL\n");
1358 }
1359 }
1360 } else if (p->subs[ANALOG_SUB_CALLWAIT].allocd) {
1361 /* Need to hold the lock for real-call, private, and call-waiting call */
1363 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
1364 /* The call waiting call disappeared. */
1366 break;
1367 }
1368
1369 /* Move to the call-wait and switch back to them. */
1375 }
1377 /* Unlock the call-waiting call that we swapped to real-call. */
1379 } else if (p->subs[ANALOG_SUB_THREEWAY].allocd) {
1383 /* This was part of a three way call. Immediately make way for
1384 another call */
1385 ast_debug(1, "Call was complete, setting owner to former third call\n");
1388 } else {
1389 /* This call hasn't been completed yet... Set owner to NULL */
1390 ast_debug(1, "Call was incomplete, setting owner to NULL\n");
1392 }
1393 }
1394 break;
1396 /* Ditch the holding callwait call, and immediately make it available */
1398 /* Need to hold the lock for call-waiting call, private, and 3-way call */
1400
1401 /* This is actually part of a three way, placed on hold. Place the third part
1402 on music on hold now */
1403 if (p->subs[ANALOG_SUB_THREEWAY].owner) {
1405 }
1407 /* Make it the call wait now */
1410 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1411 /* Unlock the 3-way call that we swapped to call-waiting call. */
1413 }
1414 } else {
1416 }
1417 break;
1419 /* Need to hold the lock for 3-way call, private, and call-waiting call */
1422 /* The other party of the three way call is currently in a call-wait state.
1423 Start music on hold for them, and take the main guy out of the third call */
1425 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1427 }
1428 }
1429 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1431 }
1433 /* If this was part of a three way call index, let us make
1434 another three way call */
1436 break;
1437 default:
1438 /*
1439 * Should never happen.
1440 * This wasn't any sort of call, so how are we an index?
1441 */
1442 ast_log(LOG_ERROR, "Index found but not any type of call?\n");
1443 break;
1444 }
1445 }
1446
1452 analog_set_outgoing(p, 0);
1453 p->onhooktime = time(NULL);
1454 p->cidrings = 1;
1455
1456 /* Perform low level hangup if no owner left */
1457 res = analog_on_hook(p);
1458 if (res < 0) {
1459 ast_log(LOG_WARNING, "Unable to hangup line %s\n", ast_channel_name(ast));
1460 }
1461 switch (p->sig) {
1462 case ANALOG_SIG_FXOGS:
1463 case ANALOG_SIG_FXOLS:
1464 case ANALOG_SIG_FXOKS:
1465 /* If they're off hook, try playing congestion */
1466 if (analog_is_off_hook(p)) {
1469 } else {
1471 }
1472 break;
1473 case ANALOG_SIG_FXSGS:
1474 case ANALOG_SIG_FXSLS:
1475 case ANALOG_SIG_FXSKS:
1476 /* Make sure we're not made available for at least two seconds assuming
1477 we were actually used for an inbound or outbound call. */
1479 time(&p->guardtime);
1480 p->guardtime += 2;
1481 }
1482 break;
1483 default:
1485 break;
1486 }
1487
1489
1490 x = 0;
1491 ast_channel_setoption(ast,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0);
1492 ast_channel_setoption(ast,AST_OPTION_TDD,&x,sizeof(char),0);
1493 p->callwaitcas = 0;
1495 /* In theory, the below is not necessary since we set hidecallerid = permhidecaller when calls start,
1496 * but this ensures the setting is defaulted properly when channels are idle, too. */
1498 analog_set_dialing(p, 0);
1501 }
1502
1504
1505 ast_verb(3, "Hanging up on '%s'\n", ast_channel_name(ast));
1506
1507 return 0;
1508}
1509
1510int analog_answer(struct analog_pvt *p, struct ast_channel *ast)
1511{
1512 int res = 0;
1513 int idx;
1514 int oldstate = ast_channel_state(ast);
1515
1516 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1518 idx = analog_get_index(ast, p, 1);
1519 if (idx < 0) {
1520 idx = ANALOG_SUB_REAL;
1521 }
1522 switch (p->sig) {
1523 case ANALOG_SIG_FXSLS:
1524 case ANALOG_SIG_FXSGS:
1525 case ANALOG_SIG_FXSKS:
1527 /* Fall through */
1528 case ANALOG_SIG_EM:
1529 case ANALOG_SIG_EM_E1:
1530 case ANALOG_SIG_EMWINK:
1531 case ANALOG_SIG_FEATD:
1532 case ANALOG_SIG_FEATDMF:
1534 case ANALOG_SIG_E911:
1537 case ANALOG_SIG_FEATB:
1538 case ANALOG_SIG_SF:
1539 case ANALOG_SIG_SFWINK:
1543 case ANALOG_SIG_FXOLS:
1544 case ANALOG_SIG_FXOGS:
1545 case ANALOG_SIG_FXOKS:
1546 /* Pick up the line */
1547 ast_debug(1, "Took %s off hook\n", ast_channel_name(ast));
1548 if (p->hanguponpolarityswitch) {
1549 gettimeofday(&p->polaritydelaytv, NULL);
1550 }
1551 res = analog_off_hook(p);
1552 analog_play_tone(p, idx, -1);
1553 analog_set_dialing(p, 0);
1554 if ((idx == ANALOG_SUB_REAL) && p->subs[ANALOG_SUB_THREEWAY].inthreeway) {
1555 if (oldstate == AST_STATE_RINGING) {
1556 ast_debug(1, "Finally swapping real and threeway\n");
1560 }
1561 }
1562
1563 switch (p->sig) {
1564 case ANALOG_SIG_FXSLS:
1565 case ANALOG_SIG_FXSKS:
1566 case ANALOG_SIG_FXSGS:
1569 break;
1570 case ANALOG_SIG_FXOLS:
1571 case ANALOG_SIG_FXOKS:
1572 case ANALOG_SIG_FXOGS:
1574 break;
1575 default:
1576 break;
1577 }
1578 break;
1579 default:
1580 ast_log(LOG_WARNING, "Don't know how to answer signalling %d (channel %d)\n", p->sig, p->channel);
1581 res = -1;
1582 break;
1583 }
1585 return res;
1586}
1587
1588static int analog_handles_digit(struct ast_frame *f)
1589{
1590 char subclass = toupper(f->subclass.integer);
1591
1592 switch (subclass) {
1593 case '1':
1594 case '2':
1595 case '3':
1596 case '4':
1597 case '5':
1598 case '6':
1599 case '7':
1600 case '9':
1601 case 'A':
1602 case 'B':
1603 case 'C':
1604 case 'D':
1605 case 'E':
1606 case 'F':
1607 return 1;
1608 default:
1609 return 0;
1610 }
1611}
1612
1620
1621static const char *callwaiting_deluxe_optname(int option)
1622{
1623 switch (option) {
1624 case CWD_CONFERENCE:
1625 return "CONFERENCE";
1626 case CWD_HOLD:
1627 return "HOLD";
1628 case CWD_DROP:
1629 return "DROP";
1630 case CWD_ANNOUNCEMENT:
1631 return "ANNOUNCEMENT";
1632 case CWD_FORWARD:
1633 return "FORWARD";
1634 default:
1635 return "DEFAULT";
1636 }
1637}
1638
1639int analog_callwaiting_deluxe(struct analog_pvt *p, int option)
1640{
1641 const char *announce_var;
1642 char announcement[PATH_MAX];
1643
1644 ast_debug(1, "Handling Call Waiting on channel %d with option %c: treatment %s\n", p->channel, option, callwaiting_deluxe_optname(option));
1645
1646 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
1647 /* This can happen if the caller hook flashes and the call waiting hangs up before the CWD timer expires (1 second) */
1648 ast_debug(1, "Call waiting call disappeared before it could be handled?\n");
1649 return -1;
1650 }
1651
1653 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
1654 ast_log(LOG_WARNING, "Whoa, the call-waiting call disappeared.\n");
1655 return -1;
1656 }
1657
1658 /* Note that when p->callwaitingdeluxepending, dahdi_write will drop incoming frames to the channel,
1659 * since the user shouldn't hear anything after flashing until either a DTMF has been received
1660 * or it's been a second and the decision is made automatically. */
1661
1662 switch (option) {
1663 case CWD_CONFERENCE:
1664 /* We should never have a call waiting if we have a 3-way anyways, but check just in case,
1665 * there better be no existing SUB_THREEWAY since we're going to make one (and then swap the call wait to it) */
1666 if (p->subs[ANALOG_SUB_THREEWAY].owner) {
1668 ast_log(LOG_ERROR, "Already have a 3-way call on channel %d, can't conference!\n", p->channel);
1669 return -1;
1670 }
1671
1672 /* To conference the incoming call, swap it from SUB_CALLWAIT to SUB_THREEWAY,
1673 * and then the existing 3-way logic will ensure that flashing again will drop the call waiting */
1677
1678 ast_verb(3, "Building conference call with %s and %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner), ast_channel_name(p->subs[ANALOG_SUB_REAL].owner));
1681
1685 /* Stop the ringing on the call wait channel (yeah, apparently this is how it's done) */
1688 }
1690
1691 ast_channel_unlock(p->subs[ANALOG_SUB_THREEWAY].owner); /* Unlock what was originally SUB_CALLWAIT */
1692 break;
1693 case CWD_HOLD: /* The CI-7112 Visual Director sends "HOLD" for "Play hold message" rather than "ANNOUNCEMENT". For default behavior, nothing is actually sent. */
1694 case CWD_ANNOUNCEMENT:
1695 /* We can't just call ast_streamfile here, this thread isn't responsible for media on the call waiting channel.
1696 * Indicate to the dialing channel in app_dial that it needs to play media.
1697 *
1698 * This is a lot easier than other ways of trying to send early media to the channel
1699 * (such as every call from the core to dahdi_read, sending the channel one frame of the audio file, etc.)
1700 */
1701
1702 /* There's not a particularly good stock audio prompt to use here. The Pat Fleet library has some better
1703 * ones but we want one that is also in the default Allison Smith library. "One moment please" works okay.
1704 * Check if a variable containing the prompt to use was specified on the call waiting channel, and
1705 * fall back to a reasonable default if not. */
1706
1707 /* The SUB_CALLWAIT channel is already locked here, no need to lock and unlock to get the variable. */
1708 announce_var = pbx_builtin_getvar_helper(p->subs[ANALOG_SUB_CALLWAIT].owner, "CALLWAITDELUXEANNOUNCEMENT");
1709 ast_copy_string(announcement, S_OR(announce_var, "one-moment-please"), sizeof(announcement));
1710 ast_debug(2, "Call Waiting Deluxe announcement for %s: %s\n", ast_channel_name(p->subs[ANALOG_SUB_CALLWAIT].owner), announcement);
1712 /* Tell app_dial what file to play. */
1713 ast_queue_control_data(p->subs[ANALOG_SUB_CALLWAIT].owner, AST_CONTROL_PLAYBACK_BEGIN, announcement, strlen(announcement) + 1);
1714 /* Unlike all the other options, the call waiting is still active with this option,
1715 * so we don't call analog_stop_callwait(p)
1716 * The call waiting will continue to be here, and at some later point the user can flash again and choose a finalizing option
1717 * (or even queue the announcement again... and again... and again...)
1718 */
1719 break;
1720 case CWD_FORWARD:
1721 /* Go away, call waiting, call again some other day... */
1723 /* Can't use p->call_forward exten because that's for *72 forwarding, and sig_analog doesn't
1724 * have a Busy/Don't Answer call forwarding exten internally, so let the dialplan deal with it.
1725 * by sending the call to the 'f' extension.
1726 */
1727 ast_channel_call_forward_set(p->subs[ANALOG_SUB_CALLWAIT].owner, "f");
1729 /* app_dial already has a verbose message for forwarding, so we don't really need one here also since that does the job */
1730 break;
1731 case CWD_DROP:
1732 /* Fall through: logic is identical to hold, except we drop the original call right after we swap. */
1733 default:
1734 /* Swap to call-wait, same as with the non-deluxe call waiting handling. */
1738 ast_debug(1, "Making %s the new owner\n", ast_channel_name(p->owner));
1742 }
1744
1745 if (option == CWD_DROP) {
1746 /* Disconnect the previous call (the original call is now the SUB_CALLWAIT since we swapped above) */
1748 ast_verb(3, "Dropping original call and swapping to call waiting on %s\n", ast_channel_name(p->subs[ANALOG_SUB_REAL].owner));
1749 } else {
1750 /* Start music on hold if appropriate */
1753 }
1754 ast_verb(3, "Holding original call and swapping to call waiting on %s\n", ast_channel_name(p->subs[ANALOG_SUB_REAL].owner));
1755 }
1756
1757 /* Stop ringing on the incoming call */
1760
1761 /* Unlock the call-waiting call that we swapped to real-call. */
1763 }
1765 return 0;
1766}
1767
1768void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub idx, struct ast_frame **dest)
1769{
1770 struct ast_frame *f = *dest;
1771
1772 ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n",
1773 f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End",
1774 (unsigned)f->subclass.integer, f->subclass.integer, ast_channel_name(ast));
1775
1777 if (f->frametype == AST_FRAME_DTMF_END) {
1778 ast_debug(1, "Confirm answer on %s!\n", ast_channel_name(ast));
1779 /* Upon receiving a DTMF digit, consider this an answer confirmation instead
1780 of a DTMF digit */
1783 /* Reset confirmanswer so DTMF's will behave properly for the duration of the call */
1785 } else {
1786 p->subs[idx].f.frametype = AST_FRAME_NULL;
1787 p->subs[idx].f.subclass.integer = 0;
1788 }
1789 *dest = &p->subs[idx].f;
1790 } else if (p->callwaitcas) {
1791 if (f->frametype == AST_FRAME_DTMF_END) {
1792 if ((f->subclass.integer == 'A') || (f->subclass.integer == 'D')) {
1793 ast_debug(1, "Got some DTMF, but it's for the CAS\n");
1794 p->caller.id.name.str = p->callwait_name;
1796 analog_send_callerid(p, 1, &p->caller);
1797 }
1798 if (analog_handles_digit(f)) {
1799 p->callwaitcas = 0;
1800 }
1801 }
1802 p->subs[idx].f.frametype = AST_FRAME_NULL;
1803 p->subs[idx].f.subclass.integer = 0;
1804 *dest = &p->subs[idx].f;
1805 } else if (p->callwaitingdeluxepending) {
1806 if (f->frametype == AST_FRAME_DTMF_END) {
1807 unsigned int mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
1809
1810 /* This is the case where a user explicitly took action (made a decision)
1811 * for Call Waiting Deluxe.
1812 * Because we already handled the hook flash, if the user doesn't do
1813 * anything within a second, then we still need to eventually take
1814 * the default action (swap) for the call waiting.
1815 *
1816 * dahdi_write will also drop audio if callwaitingdeluxepending is set HIGH,
1817 * and also check if flashtime hits 1000, in which case it will set the flag LOW and then take the
1818 * default action, e.g. analog_callwaiting_deluxe(p, 0);
1819 */
1820
1821 /* Slightly less than 1000, so there's no chance of a race condition
1822 * between do_monitor when it sees flashtime hitting 1000 and us. */
1823 if (mssinceflash > 990) {
1824 /* This was more than a second ago, clear the flag and process normally. */
1825 /* Because another thread has to monitor channels with pending CWDs,
1826 * in theory, we shouldn't need to check this here. */
1827 ast_debug(1, "It's been %u ms since the last flash, this is not a Call Waiting Deluxe DTMF\n", mssinceflash);
1828 analog_cb_handle_dtmf(p, ast, idx, dest);
1829 return;
1830 }
1831 /* Okay, actually do something now. */
1832 switch (f->subclass.integer) {
1833 case CWD_CONFERENCE:
1834 case CWD_HOLD:
1835 case CWD_DROP:
1836 case CWD_ANNOUNCEMENT:
1837 case CWD_FORWARD:
1838 ast_debug(1, "Got some DTMF, but it's for Call Waiting Deluxe: %c\n", f->subclass.integer);
1840 break;
1841 default:
1842 ast_log(LOG_WARNING, "Invalid Call Waiting Deluxe option (%c), using default\n", f->subclass.integer);
1844 }
1845 }
1846 p->subs[idx].f.frametype = AST_FRAME_NULL;
1847 p->subs[idx].f.subclass.integer = 0;
1848 *dest = &p->subs[idx].f;
1849 } else {
1850 analog_cb_handle_dtmf(p, ast, idx, dest);
1851 }
1852}
1853
1854static int analog_my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms)
1855{
1856 char c;
1857
1858 *str = 0; /* start with empty output buffer */
1859 for (;;) {
1860 /* Wait for the first digit (up to specified ms). */
1861 c = ast_waitfordigit(chan, ms);
1862 /* if timeout, hangup or error, return as such */
1863 if (c < 1) {
1864 return c;
1865 }
1866 *str++ = c;
1867 *str = 0;
1868 if (strchr(term, c)) {
1869 return 1;
1870 }
1871 }
1872}
1873
1874static int analog_handle_notify_message(struct ast_channel *chan, struct analog_pvt *p, int cid_flags, int neon_mwievent)
1875{
1877 analog_callbacks.handle_notify_message(chan, p->chan_pvt, cid_flags, neon_mwievent);
1878 return 0;
1879 }
1880 return -1;
1881}
1882
1889
1896
1897static int analog_distinctive_ring(struct ast_channel *chan, struct analog_pvt *p, int idx, int *ringdata)
1898{
1900 return 0;
1901 }
1903 return analog_callbacks.distinctive_ring(chan, p->chan_pvt, idx, ringdata);
1904 }
1905 return -1;
1906
1907}
1908
1915
1916static void *analog_get_bridged_channel(struct ast_channel *chan)
1917{
1920 }
1921 return NULL;
1922}
1923
1924static int analog_get_sub_fd(struct analog_pvt *p, enum analog_sub sub)
1925{
1928 }
1929 return -1;
1930}
1931
1932#define ANALOG_NEED_MFDETECT(p) (((p)->sig == ANALOG_SIG_FEATDMF) || ((p)->sig == ANALOG_SIG_FEATDMF_TA) || ((p)->sig == ANALOG_SIG_E911) || ((p)->sig == ANALOG_SIG_FGC_CAMA) || ((p)->sig == ANALOG_SIG_FGC_CAMAMF) || ((p)->sig == ANALOG_SIG_FEATB))
1933
1934static int analog_canmatch_featurecode(const char *pickupexten, const char *exten)
1935{
1936 int extlen = strlen(exten);
1937 if (!extlen) {
1938 return 1;
1939 }
1940 if (extlen < strlen(pickupexten) && !strncmp(pickupexten, exten, extlen)) {
1941 return 1;
1942 }
1943 if (exten[0] == '#' && extlen < 2) {
1944 return 1; /* Could match ## */
1945 }
1946 /* hardcoded features are *60, *67, *69, *70, *72, *73, *78, *79, *82, *0 */
1947 if (exten[0] == '*' && extlen < 3) {
1948 if (extlen == 1) {
1949 return 1;
1950 }
1951 /* "*0" should be processed before it gets here */
1952 switch (exten[1]) {
1953 case '6':
1954 case '7':
1955 case '8':
1956 return 1;
1957 }
1958 }
1959 return 0;
1960}
1961
1962static void *__analog_ss_thread(void *data)
1963{
1964 struct analog_pvt *p = data;
1965 struct ast_channel *chan = p->ss_astchan;
1966 char exten[AST_MAX_EXTENSION] = "";
1967 char exten2[AST_MAX_EXTENSION] = "";
1968 char dtmfcid[300];
1969 char dtmfbuf[300];
1970 char namebuf[ANALOG_MAX_CID];
1971 char numbuf[ANALOG_MAX_CID];
1972 char *name = NULL, *number = NULL;
1973 int flags = 0;
1974 struct ast_smdi_md_message *smdi_msg = NULL;
1975 int timeout;
1976 int getforward = 0;
1977 char *s1, *s2;
1978 int len = 0;
1979 int res;
1980 int idx;
1981 ast_callid callid;
1982 RAII_VAR(struct ast_features_pickup_config *, pickup_cfg, NULL, ao2_cleanup);
1983 const char *pickupexten;
1984
1986
1987 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1988
1989 ast_assert(chan != NULL);
1990
1991 if ((callid = ast_channel_callid(chan))) {
1993 }
1994
1995 /* in the bizarre case where the channel has become a zombie before we
1996 even get started here, abort safely
1997 */
1998 if (!ast_channel_tech_pvt(chan)) {
1999 ast_log(LOG_WARNING, "Channel became a zombie before simple switch could be started (%s)\n", ast_channel_name(chan));
2000 ast_hangup(chan);
2001 goto quit;
2002 }
2003
2004 ast_verb(3, "Starting simple switch on '%s'\n", ast_channel_name(chan));
2005 idx = analog_get_index(chan, p, 0);
2006 if (idx < 0) {
2007 ast_hangup(chan);
2008 goto quit;
2009 }
2010
2011 ast_channel_lock(chan);
2012 pickup_cfg = ast_get_chan_features_pickup_config(chan);
2013 if (!pickup_cfg) {
2014 ast_log(LOG_ERROR, "Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n");
2015 pickupexten = "";
2016 } else {
2017 pickupexten = ast_strdupa(pickup_cfg->pickupexten);
2018 }
2019 ast_channel_unlock(chan);
2020
2022 switch (p->sig) {
2023 case ANALOG_SIG_FEATD:
2024 case ANALOG_SIG_FEATDMF:
2026 case ANALOG_SIG_E911:
2028 case ANALOG_SIG_FEATB:
2029 case ANALOG_SIG_EMWINK:
2033 case ANALOG_SIG_SFWINK:
2034 if (analog_wink(p, idx))
2035 goto quit;
2036 /* Fall through */
2037 case ANALOG_SIG_EM:
2038 case ANALOG_SIG_EM_E1:
2039 case ANALOG_SIG_SF:
2041 res = analog_play_tone(p, idx, -1);
2042
2044
2045 /* set digit mode appropriately */
2046 if (ANALOG_NEED_MFDETECT(p)) {
2048 } else {
2050 }
2051
2052 memset(dtmfbuf, 0, sizeof(dtmfbuf));
2053 /* Wait for the first digit only if immediate=no */
2054 if (!p->immediate) {
2055 /* Wait for the first digit (up to 5 seconds). */
2056 res = ast_waitfordigit(chan, 5000);
2057 } else {
2058 res = 0;
2059 }
2060 if (res > 0) {
2061 /* save first char */
2062 dtmfbuf[0] = res;
2063 switch (p->sig) {
2064 case ANALOG_SIG_FEATD:
2066 res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
2067 if (res > 0) {
2068 res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
2069 }
2070 if (res < 1) {
2072 }
2073 break;
2075 res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
2076 if (res < 1) {
2078 }
2079 if (analog_wink(p, idx)) {
2080 goto quit;
2081 }
2082 dtmfbuf[0] = 0;
2083 /* Wait for the first digit (up to 5 seconds). */
2084 res = ast_waitfordigit(chan, 5000);
2085 if (res <= 0) {
2086 break;
2087 }
2088 dtmfbuf[0] = res;
2089 /* fall through intentionally */
2090 case ANALOG_SIG_FEATDMF:
2091 case ANALOG_SIG_E911:
2094 res = analog_my_getsigstr(chan, dtmfbuf + 1, "#ABC", 3000);
2095 /* if international CAC, do it again to get real ANI */
2096 if ((p->sig == ANALOG_SIG_FEATDMF) && (dtmfbuf[1] != '0')
2097 && (strlen(dtmfbuf) != 14)) {
2098 if (analog_wink(p, idx)) {
2099 goto quit;
2100 }
2101 dtmfbuf[0] = 0;
2102 /* Wait for the first digit (up to 5 seconds). */
2103 res = ast_waitfordigit(chan, 5000);
2104 if (res <= 0) {
2105 break;
2106 }
2107 dtmfbuf[0] = res;
2108 res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
2109 }
2110 if (res > 0) {
2111 /* if E911, take off hook */
2112 if (p->sig == ANALOG_SIG_E911) {
2113 analog_off_hook(p);
2114 }
2115 if (p->sig != ANALOG_SIG_FGC_CAMAMF) {
2116 /* CAMA signaling (CAMA and CAMAMF) are handled in an if block below.
2117 * Everything else, process here. */
2118 res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "#", 3000);
2119 }
2120 }
2121 if (res < 1) {
2123 }
2124 break;
2125 case ANALOG_SIG_FEATB:
2127 res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
2128 if (res < 1) {
2130 }
2131 break;
2132 case ANALOG_SIG_EMWINK:
2133 /* if we received a '*', we are actually receiving Feature Group D
2134 dial syntax, so use that mode; otherwise, fall through to normal
2135 mode
2136 */
2137 if (res == '*') {
2138 res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
2139 if (res > 0) {
2140 res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
2141 }
2142 if (res < 1) {
2144 }
2145 break;
2146 }
2147 default:
2148 /* If we got the first digit, get the rest */
2149 len = 1;
2150 dtmfbuf[len] = '\0';
2151 while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
2152 if (ast_exists_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
2153 timeout = analog_get_matchdigit_timeout(p);
2154 } else {
2155 timeout = analog_get_interdigit_timeout(p);
2156 }
2157 res = ast_waitfordigit(chan, timeout);
2158 if (res < 0) {
2159 ast_debug(1, "waitfordigit returned < 0...\n");
2160 ast_hangup(chan);
2161 goto quit;
2162 } else if (res) {
2163 dtmfbuf[len++] = res;
2164 dtmfbuf[len] = '\0';
2165 } else {
2166 break;
2167 }
2168 }
2169 break;
2170 }
2171 }
2172 if (res == -1) {
2173 ast_log(LOG_WARNING, "getdtmf on channel %d: %s\n", p->channel, strerror(errno));
2174 ast_hangup(chan);
2175 goto quit;
2176 } else if (res < 0) {
2177 ast_debug(1, "Got hung up before digits finished\n");
2178 ast_hangup(chan);
2179 goto quit;
2180 }
2181
2182 if (p->sig == ANALOG_SIG_FGC_CAMA || p->sig == ANALOG_SIG_FGC_CAMAMF) {
2183 /* This if block is where we process ANI for CAMA */
2184
2185 char anibuf[100];
2186 struct ast_party_caller *caller;
2187
2188 /* cnoffset is the point at which we pull the calling number out
2189 * of anibuf. Must be the number of ani_info_digits + 1 to account
2190 * for the KP, which is considered a digit. */
2191
2192 /* The 1XB with ANI-B will send a full 10 digits
2193 * or 2 digits in case of ANI failure.
2194 * (CD-95811-01 Section II, page 10)
2195 * 10 digit string example: *08320123#
2196 * 2 digit string example: *2
2197 * KP (*) and ST (#) are considered to be digits */
2198
2199 int cnoffset = p->ani_info_digits + 1;
2200
2201 /* This is how long to wait before the wink to start ANI spill
2202 * Pulled from chan_dahdi.conf, default is 1000ms */
2203 if (ast_safe_sleep(chan,p->ani_wink_time) == -1) {
2204 ast_hangup(chan);
2205 goto quit;
2206 }
2207 analog_off_hook(p);
2208 ast_debug(1, "Went off-hook to signal ANI start\n");
2210
2211 /* ani_timeout is configured in chan_dahdi.conf. default is 10000ms.
2212 * ST, STP, ST2P, ST3P can all signal transmission complete, regardless of timeout */
2213 res = analog_my_getsigstr(chan, anibuf, "#ABC", p->ani_timeout);
2214
2215 /* so we can work with the ani buffer */
2216 pbx_builtin_setvar_helper(chan, "ANIBUF", anibuf);
2217
2218 /* as long as we get a terminating pulse OR the length of ANI buffer is at least >=2, we can treat
2219 * this as a complete spill for the purposes of setting anistart */
2220 if ((res > 0) || (strlen(anibuf) >= 2)) {
2221 char anistart[2] = "X";
2222 char f[101] = {0};
2223 if (strchr("#ABC", anibuf[strlen(anibuf) - 1])) {
2224 anistart[0] = anibuf[strlen(anibuf) - 1];
2225 anibuf[strlen(anibuf) - 1] = 0;
2226 }
2227 ast_set_callerid(chan, anibuf + cnoffset, NULL, anibuf + cnoffset);
2228
2229 caller = ast_channel_caller(chan);
2230 strncpy(f, &(anibuf[1]), MIN((int)(p->ani_info_digits), sizeof(f)-1));
2231 caller->ani2 = atoi(f);
2232
2233 anibuf[cnoffset] = 0;
2234
2235 /* so we can work with the different start pulses as used in ANI-D */
2236 pbx_builtin_setvar_helper(chan, "ANISTART", anistart);
2237 /* so we can use our ANI INFO digits in our dialplan */
2238 pbx_builtin_setvar_helper(chan, "ANI2", anibuf + 1);
2239 }
2241 }
2242
2243 ast_copy_string(exten, dtmfbuf, sizeof(exten));
2244 if (ast_strlen_zero(exten)) {
2245 ast_copy_string(exten, "s", sizeof(exten));
2246 }
2247 if (p->sig == ANALOG_SIG_FEATD || p->sig == ANALOG_SIG_EMWINK) {
2248 /* Look for Feature Group D on all E&M Wink and Feature Group D trunks */
2249 if (exten[0] == '*') {
2250 char *stringp=NULL;
2251 ast_copy_string(exten2, exten, sizeof(exten2));
2252 /* Parse out extension and callerid */
2253 stringp=exten2 +1;
2254 s1 = strsep(&stringp, "*");
2255 s2 = strsep(&stringp, "*");
2256 if (s2) {
2257 if (!ast_strlen_zero(p->cid_num)) {
2258 ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
2259 } else {
2260 ast_set_callerid(chan, s1, NULL, s1);
2261 }
2262 ast_copy_string(exten, s2, sizeof(exten));
2263 } else {
2264 ast_copy_string(exten, s1, sizeof(exten));
2265 }
2266 } else if (p->sig == ANALOG_SIG_FEATD) {
2267 ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
2268 }
2269 }
2270 if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
2271 if (exten[0] == '*') {
2272 char *stringp=NULL;
2273 struct ast_party_caller *caller;
2274
2275 ast_copy_string(exten2, exten, sizeof(exten2));
2276 /* Parse out extension and callerid */
2277 stringp=exten2 +1;
2278 s1 = strsep(&stringp, "#");
2279 s2 = strsep(&stringp, "#");
2280 if (s2) {
2281 if (!ast_strlen_zero(p->cid_num)) {
2282 ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
2283 } else {
2284 if (*(s1 + 2)) {
2285 ast_set_callerid(chan, s1 + 2, NULL, s1 + 2);
2286 }
2287 }
2288 ast_copy_string(exten, s2 + 1, sizeof(exten));
2289 } else {
2290 ast_copy_string(exten, s1 + 2, sizeof(exten));
2291 }
2292
2293 /* The first two digits are ani2 information. */
2294 caller = ast_channel_caller(chan);
2295 s1[2] = '\0';
2296 caller->ani2 = atoi(s1);
2297 } else {
2298 ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
2299 }
2300 }
2301 if ((p->sig == ANALOG_SIG_E911) || (p->sig == ANALOG_SIG_FGC_CAMAMF)) {
2302 if (exten[0] == '*') {
2303 char *stringp=NULL;
2304 ast_copy_string(exten2, exten, sizeof(exten2));
2305 /* Parse out extension and callerid */
2306 stringp=exten2 +1;
2307 s1 = strsep(&stringp, "#ABC");
2308 s2 = strsep(&stringp, "#ABC");
2309 if (s2 && (*(s2 + 1) == '0')) {
2310 if (*(s2 + 2)) {
2311 ast_set_callerid(chan, s2 + 2, NULL, s2 + 2);
2312 }
2313 }
2314 if (s1) {
2315 ast_copy_string(exten, s1, sizeof(exten));
2316 } else {
2317 ast_copy_string(exten, "911", sizeof(exten));
2318 }
2319 } else {
2320 ast_log(LOG_WARNING, "A KP was expected to start signaling for Feature Group C CAMA-MF, but we got something else. Received: %s on channel %d\n", exten, p->channel);
2321 }
2322 }
2323 if (p->sig == ANALOG_SIG_FEATB) {
2324 if (exten[0] == '*') {
2325 char *stringp=NULL;
2326 ast_copy_string(exten2, exten, sizeof(exten2));
2327 /* Parse out extension and callerid */
2328 stringp=exten2 +1;
2329 s1 = strsep(&stringp, "#");
2330 ast_copy_string(exten, exten2 + 1, sizeof(exten));
2331 } else {
2332 ast_log(LOG_WARNING, "A KP was expected to start signaling for Feature Group B, but we got something else. Received: %s on channel %d\n", exten, p->channel);
2333 }
2334 }
2335 if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
2336 analog_wink(p, idx);
2337 /*
2338 * Some switches require a minimum guard time between the last
2339 * FGD wink and something that answers immediately. This
2340 * ensures it.
2341 */
2342 if (ast_safe_sleep(chan, 100)) {
2343 ast_hangup(chan);
2344 goto quit;
2345 }
2346 }
2348
2350
2351 if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1,
2352 ast_channel_caller(chan)->id.number.valid ? ast_channel_caller(chan)->id.number.str : NULL)) {
2353 ast_channel_exten_set(chan, exten);
2355 res = ast_pbx_run(chan);
2356 if (res) {
2357 ast_log(LOG_WARNING, "PBX exited non-zero\n");
2359 }
2360 goto quit;
2361 } else {
2362 ast_verb(3, "Unknown extension '%s' in context '%s' requested\n", exten, ast_channel_context(chan));
2363 sleep(2);
2364 res = analog_play_tone(p, idx, ANALOG_TONE_INFO);
2365 if (res < 0) {
2366 ast_log(LOG_WARNING, "Unable to start special tone on %d\n", p->channel);
2367 } else {
2368 sleep(1);
2369 }
2370 res = ast_streamfile(chan, "ss-noservice", ast_channel_language(chan));
2371 if (res >= 0) {
2372 ast_waitstream(chan, "");
2373 }
2375 ast_hangup(chan);
2376 goto quit;
2377 }
2378 break;
2379 case ANALOG_SIG_FXOLS:
2380 case ANALOG_SIG_FXOGS:
2381 case ANALOG_SIG_FXOKS:
2382 /* Set our default presentation.
2383 * This is necessary because the presentation for each call is independent
2384 * (though the default may be the same).
2385 * For example, if hidecallerid=yes and somebody makes a call with *82,
2386 * then makes a 3-way call, the presentation for the 2nd call should still
2387 * be blocked, unless that also had a *82.
2388 * For this reason, setting hidecallerid = permhidecallerid on hangup
2389 * is NOT sufficient, as the *82 from the first call could "leak" into
2390 * subsequent ones made before a hangup, improperly leaking a number
2391 * that should have been hidden.
2392 */
2394
2395 /* Set the default dial mode.
2396 * As with Caller ID, this is independent for each call,
2397 * and changes made using the CHANNEL function are only temporary.
2398 * This reset ensures temporary changes are discarded when a new call is originated.
2399 *
2400 * XXX There is a slight edge case in that because the dialmode is reset to permdialmode,
2401 * assuming permdialmode=both, if a user disables dtmf during call 1, then flashes and
2402 * starts call 2, this will set dialmode back to permcallmode on the private,
2403 * allowing tone dialing to (correctly) work on call 2.
2404 * If the user flashes back to call 1, however, tone dialing will again work on call 1.
2405 *
2406 * This problem does not exist with the other settings that involve a "permanent"
2407 * and "transient" settings (e.g. hidecallerid, callwaiting), because hidecallerid
2408 * only matters when originating a call, so as soon as it's been placed, it doesn't
2409 * matter if it gets reset. For callwaiting, the setting is supposed to be common
2410 * to the entire channel private (all subchannels), which is NOT the case with this setting.
2411 *
2412 * The correct and probably only fix for this edge case is to move dialmode out of the channel private
2413 * (which is shared by all subchannels), and into the Asterisk channel structure. Just using an array for
2414 * each chan_dahdi subchannel won't work because the indices change as calls flip around.
2415 */
2416 p->dialmode = p->permdialmode;
2417
2418 /* Read the first digit */
2419 timeout = analog_get_firstdigit_timeout(p);
2420 /* If starting a threeway call, never timeout on the first digit so someone
2421 * can use flash-hook as a "hold" feature...
2422 * ...Unless three-way dial tone should time out to silence, in which case the default suffices. */
2424 timeout = INT_MAX;
2425 }
2426 while (len < AST_MAX_EXTENSION-1) {
2427 int is_exten_parking = 0;
2428 int is_lastnumredial = 0;
2429 int is_endofdialing = 0;
2430
2431 /* Read digit unless it's supposed to be immediate, in which case the
2432 only answer is 's' */
2433 if (p->immediate) {
2434 res = 's';
2435 } else {
2436 res = ast_waitfordigit(chan, timeout);
2437 }
2438 timeout = 0;
2439 if (res < 0) {
2440 ast_debug(1, "waitfordigit returned < 0...\n");
2441 res = analog_play_tone(p, idx, -1);
2442 ast_hangup(chan);
2443 goto quit;
2444 } else if (res) {
2445 ast_debug(1,"waitfordigit returned '%c' (%d), timeout = %d\n", res, res, timeout);
2446 exten[len++] = res;
2447 exten[len] = '\0';
2448 if (len > 1 && res == '#' && !ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) {
2449 /* The user was dialing something that matched, but as soon as he dialed #, we no longer have a match.
2450 * Check if what was dialed immediately prior to the # is an extension that exists.
2451 * If so, we can treat "#" as the end of dialing terminator to allow user to complete the call without a timeout.
2452 * This is fully compatible with the user's dialplan, since we only do this if there isn't a dialplan match. */
2453 exten[--len] = '\0'; /* Remove '#' from the buffer to test the extension without it */
2454 if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) {
2455 /* The number dialed prior to the # exists as a valid extension.
2456 * Since the number with # does not exist, treat # as end of dialing. */
2457 ast_debug(1, "Interpreting '#' as end of dialing\n");
2458 is_endofdialing = 1;
2459 } else {
2460 /* Even without the #, the number in the buffer is not a valid extension.
2461 * In this case, it's still invalid; do nothing special.
2462 * We simply reverse the removal of '#' from the buffer, i.e. we append it again. */
2463 exten[len++] = res;
2464 exten[len ] = '\0';
2465 }
2466 }
2467 }
2468 if (!ast_ignore_pattern(ast_channel_context(chan), exten)) {
2469 analog_play_tone(p, idx, -1);
2470 } else {
2472 }
2474 is_exten_parking = ast_parking_is_exten_park(ast_channel_context(chan), exten);
2475 }
2476 if (p->lastnumredial && !strcmp(exten, "##") && !ast_exists_extension(chan, ast_channel_context(chan), "##", 1, p->cid_num)) {
2477 /* Last Number Redial */
2478 if (!ast_strlen_zero(p->lastexten)) {
2479 ast_verb(4, "Redialing last number dialed on channel %d\n", p->channel);
2481 ast_copy_string(exten, p->lastexten, sizeof(exten));
2483 /* If Last Number Redial was used, even if the user might normally be able to dial further
2484 * digits for the digits dialed, we should complete the call immediately without delay. */
2485 is_lastnumredial = 1;
2486 } else {
2487 ast_verb(3, "Last Number Redial not possible on channel %d (no saved number)\n", p->channel);
2490 ast_hangup(chan);
2491 goto quit;
2492 }
2493 }
2494 if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num) && !is_exten_parking) {
2495 if (!res || is_lastnumredial || is_endofdialing || !ast_matchmore_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) {
2496 if (getforward) {
2497 /* Record this as the forwarding extension */
2499 ast_copy_string(p->call_forward, exten, sizeof(p->call_forward));
2501 ast_verb(3, "Setting call forward to '%s' on channel %d\n", exten, p->channel);
2503 if (res) {
2504 break;
2505 }
2506 usleep(500000);
2507 res = analog_play_tone(p, idx, -1);
2508 sleep(1);
2509 memset(exten, 0, sizeof(exten));
2511 len = 0;
2512 getforward = 0;
2513 } else {
2514 res = analog_play_tone(p, idx, -1);
2515 ast_channel_lock(chan);
2516 ast_channel_exten_set(chan, exten);
2517
2518 /* Save the last number dialed, for Last Number Redial. */
2519 if (!p->immediate) {
2520 ast_copy_string(p->lastexten, exten, sizeof(p->lastexten));
2521 }
2522
2523 /* Properly set the presentation.
2524 * We need to do this here as well, because p->hidecallerid might be set
2525 * due to permanent blocking, not star-67/star-82 usage. */
2526 if (p->hidecallerid) {
2529 } else {
2532 }
2533
2535 ast_channel_unlock(chan);
2537 res = ast_pbx_run(chan);
2538 if (res) {
2539 ast_log(LOG_WARNING, "PBX exited non-zero\n");
2541 }
2542 goto quit;
2543 }
2544 } else {
2545 /* It's a match, but they just typed a digit, and there is an ambiguous match,
2546 so just set the timeout to analog_matchdigittimeout and wait some more */
2547 timeout = analog_get_matchdigit_timeout(p);
2548 }
2549 } else if (res == 0) {
2550 ast_debug(1, "not enough digits (and no ambiguous match)...\n");
2551 if (p->threewaysilenthold) {
2552 ast_debug(1, "Nothing dialed at three-way dial tone, timed out to silent hold\n");
2553 } else {
2555 }
2557 ast_hangup(chan);
2558 goto quit;
2559 } else if (p->callwaiting && !strcmp(exten, "*70")) {
2560 ast_verb(3, "Disabling call waiting on %s\n", ast_channel_name(chan));
2561 /* Disable call waiting if enabled */
2564 if (res) {
2565 ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2566 ast_channel_name(chan), strerror(errno));
2567 }
2568 len = 0;
2569 memset(exten, 0, sizeof(exten));
2570 timeout = analog_get_firstdigit_timeout(p);
2571
2572 } else if (!strcmp(exten, pickupexten)) {
2573 /* Scan all channels and see if there are any
2574 * ringing channels that have call groups
2575 * that equal this channel's pickup group
2576 */
2577 if (idx == ANALOG_SUB_REAL) {
2578 /* Switch us from Third call to Call Wait */
2579 if (p->subs[ANALOG_SUB_THREEWAY].owner) {
2580 /* If you make a threeway call and then *8# a call, it should actually
2581 look like a callwait */
2585 }
2587 if (ast_pickup_call(chan)) {
2588 ast_debug(1, "No call pickup possible...\n");
2591 }
2592 ast_hangup(chan);
2593 goto quit;
2594 } else {
2595 ast_log(LOG_WARNING, "Huh? Got *8# on call not on real\n");
2596 ast_hangup(chan);
2597 goto quit;
2598 }
2599 /* While the DMS-100 allows dialing as many *67s and *82s in succession as one's heart may desire,
2600 * the 5ESS does not, it only allows pure toggling (and only once!). So, it's not incorrect
2601 * to prevent people from dialing *67 if that won't actually do anything. */
2602 } else if (!p->hidecallerid && !strcmp(exten, "*67")) {
2603 ast_verb(3, "Blocking Caller*ID on %s\n", ast_channel_name(chan));
2604 /* Disable Caller*ID if enabled */
2605 p->hidecallerid = 1;
2609 if (res) {
2610 ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2611 ast_channel_name(chan), strerror(errno));
2612 }
2613 len = 0;
2614 memset(exten, 0, sizeof(exten));
2615 timeout = analog_get_firstdigit_timeout(p);
2616 } else if (p->callreturn && !strcmp(exten, "*69")) {
2617 res = 0;
2618 if (!ast_strlen_zero(p->lastcid_num)) {
2619 res = ast_say_digit_str(chan, p->lastcid_num, "", ast_channel_language(chan));
2620 }
2621 if (!res) {
2623 }
2624 break;
2625 } else if (!strcmp(exten, "*78")) {
2626 /* Do not disturb enabled */
2627 analog_dnd(p, 1);
2629 getforward = 0;
2630 memset(exten, 0, sizeof(exten));
2631 len = 0;
2632 } else if (!strcmp(exten, "*79")) {
2633 /* Do not disturb disabled */
2634 analog_dnd(p, 0);
2636 getforward = 0;
2637 memset(exten, 0, sizeof(exten));
2638 len = 0;
2639 } else if (p->cancallforward && !strcmp(exten, "*72")) {
2641 getforward = 1;
2642 memset(exten, 0, sizeof(exten));
2643 len = 0;
2644 } else if (p->cancallforward && !strcmp(exten, "*73")) {
2645 ast_verb(3, "Cancelling call forwarding on channel %d\n", p->channel);
2647 memset(p->call_forward, 0, sizeof(p->call_forward));
2648 getforward = 0;
2649 memset(exten, 0, sizeof(exten));
2650 len = 0;
2651 } else if ((p->transfer || p->canpark) && is_exten_parking
2653 struct ast_bridge_channel *bridge_channel;
2654
2655 /*
2656 * This is a three way call, the main call being a real channel,
2657 * and we're parking the first call.
2658 */
2662 if (bridge_channel) {
2663 if (!ast_parking_blind_transfer_park(bridge_channel, ast_channel_context(chan), exten, NULL, NULL)) {
2664 /*
2665 * Swap things around between the three-way and real call so we
2666 * can hear where the channel got parked.
2667 */
2672
2673 ast_verb(3, "%s: Parked call\n", ast_channel_name(chan));
2675 ao2_ref(bridge_channel, -1);
2676 goto quit;
2677 }
2678 ao2_ref(bridge_channel, -1);
2679 }
2680 break;
2681 } else if (!ast_strlen_zero(p->lastcid_num) && !strcmp(exten, "*60")) {
2682 ast_verb(3, "Blacklisting number %s\n", p->lastcid_num);
2683 res = ast_db_put("blacklist", p->lastcid_num, "1");
2684 if (!res) {
2686 memset(exten, 0, sizeof(exten));
2687 len = 0;
2688 }
2689 } else if (p->hidecallerid && !strcmp(exten, "*82")) {
2690 ast_verb(3, "Allowing Caller*ID on %s\n", ast_channel_name(chan));
2691 /* Enable Caller*ID if enabled */
2692 p->hidecallerid = 0;
2696 if (res) {
2697 ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2698 ast_channel_name(chan), strerror(errno));
2699 }
2700 len = 0;
2701 memset(exten, 0, sizeof(exten));
2702 timeout = analog_get_firstdigit_timeout(p);
2703 } else if (!strcmp(exten, "*0")) {
2704 struct ast_channel *nbridge = p->subs[ANALOG_SUB_THREEWAY].owner;
2705 struct analog_pvt *pbridge = NULL;
2706 /* set up the private struct of the bridged one, if any */
2707 if (nbridge) {
2708 pbridge = analog_get_bridged_channel(nbridge);
2709 }
2710 if (pbridge && ISTRUNK(pbridge)) {
2711 /* Clear out the dial buffer */
2712 p->dop.dialstr[0] = '\0';
2713 /* flash hookswitch */
2714 if ((analog_flash(pbridge) == -1) && (errno != EINPROGRESS)) {
2716 "Unable to flash-hook bridged trunk from channel %s: %s\n",
2717 ast_channel_name(nbridge), strerror(errno));
2718 }
2723 ast_hangup(chan);
2724 goto quit;
2725 } else {
2728 analog_play_tone(p, idx, -1);
2732 ast_hangup(chan);
2733 goto quit;
2734 }
2735 } else if (!ast_canmatch_extension(chan, ast_channel_context(chan), exten, 1,
2736 ast_channel_caller(chan)->id.number.valid ? ast_channel_caller(chan)->id.number.str : NULL)
2737 && !analog_canmatch_featurecode(pickupexten, exten)) {
2738 ast_debug(1, "Can't match %s from '%s' in context %s\n", exten,
2739 ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str
2740 ? ast_channel_caller(chan)->id.number.str : "<Unknown Caller>",
2741 ast_channel_context(chan));
2742 break;
2743 }
2744 if (!timeout) {
2745 timeout = analog_get_interdigit_timeout(p);
2746 }
2747 if (len && !ast_ignore_pattern(ast_channel_context(chan), exten)) {
2748 analog_play_tone(p, idx, -1);
2749 }
2750 }
2751 break;
2752 case ANALOG_SIG_FXSLS:
2753 case ANALOG_SIG_FXSGS:
2754 case ANALOG_SIG_FXSKS:
2755 /* check for SMDI messages */
2756 if (p->use_smdi && p->smdi_iface) {
2758 if (smdi_msg != NULL) {
2759 ast_channel_exten_set(chan, smdi_msg->fwd_st);
2760
2761 if (smdi_msg->type == 'B')
2762 pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "b");
2763 else if (smdi_msg->type == 'N')
2764 pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "u");
2765
2766 ast_debug(1, "Received SMDI message on %s\n", ast_channel_name(chan));
2767 } else {
2768 ast_log(LOG_WARNING, "SMDI enabled but no SMDI message present\n");
2769 }
2770 }
2771
2772 if (p->use_callerid && (p->cid_signalling == CID_SIG_SMDI && smdi_msg)) {
2773 number = smdi_msg->calling_st;
2774
2775 /* If we want caller id, we're in a prering state due to a polarity reversal
2776 * and we're set to use a polarity reversal to trigger the start of caller id,
2777 * grab the caller id and wait for ringing to start... */
2778 } else if (p->use_callerid && (ast_channel_state(chan) == AST_STATE_PRERING
2782 /* If set to use DTMF CID signalling, listen for DTMF */
2783 if (p->cid_signalling == CID_SIG_DTMF) {
2784 int k = 0;
2785 int oldlinearity;
2786 int timeout_ms;
2787 int ms;
2788 struct timeval start = ast_tvnow();
2789 ast_debug(1, "Receiving DTMF cid on channel %s\n", ast_channel_name(chan));
2790
2791 oldlinearity = analog_set_linear_mode(p, idx, 0);
2792
2793 /*
2794 * We are the only party interested in the Rx stream since
2795 * we have not answered yet. We don't need or even want DTMF
2796 * emulation. The DTMF digits can come so fast that emulation
2797 * can drop some of them.
2798 */
2799 ast_channel_lock(chan);
2801 ast_channel_unlock(chan);
2802 timeout_ms = 4000;/* This is a typical OFF time between rings. */
2803 for (;;) {
2804 struct ast_frame *f;
2805
2806 ms = ast_remaining_ms(start, timeout_ms);
2807 res = ast_waitfor(chan, ms);
2808 if (res <= 0) {
2809 /*
2810 * We do not need to restore the analog_set_linear_mode()
2811 * or AST_FLAG_END_DTMF_ONLY flag settings since we
2812 * are hanging up the channel.
2813 */
2815 "DTMFCID timed out waiting for ring. Exiting simple switch\n");
2816 ast_hangup(chan);
2817 goto quit;
2818 }
2819 f = ast_read(chan);
2820 if (!f) {
2821 break;
2822 }
2823 if (f->frametype == AST_FRAME_DTMF) {
2824 if (k < ARRAY_LEN(dtmfbuf) - 1) {
2825 dtmfbuf[k++] = f->subclass.integer;
2826 }
2827 ast_debug(1, "CID got digit '%c'\n", f->subclass.integer);
2828 start = ast_tvnow();
2829 }
2830 ast_frfree(f);
2831 if (ast_channel_state(chan) == AST_STATE_RING ||
2833 break; /* Got ring */
2834 }
2835 }
2836 ast_channel_lock(chan);
2838 ast_channel_unlock(chan);
2839 dtmfbuf[k] = '\0';
2840
2841 analog_set_linear_mode(p, idx, oldlinearity);
2842
2843 /* Got cid and ring. */
2844 ast_debug(1, "CID got string '%s'\n", dtmfbuf);
2845 callerid_get_dtmf(dtmfbuf, dtmfcid, &flags);
2846 ast_debug(1, "CID is '%s', flags %d\n", dtmfcid, flags);
2847 /* If first byte is NULL, we have no cid */
2848 if (!ast_strlen_zero(dtmfcid)) {
2849 number = dtmfcid;
2850 } else {
2851 number = NULL;
2852 }
2853
2854 /* If set to use V23 Signalling, launch our FSK gubbins and listen for it */
2855 } else if ((p->cid_signalling == CID_SIG_V23) || (p->cid_signalling == CID_SIG_V23_JP)) {
2856 namebuf[0] = 0;
2857 numbuf[0] = 0;
2858
2860 int timeout = 10000; /* Ten seconds */
2861 struct timeval start = ast_tvnow();
2862 enum analog_event ev;
2863 int off_ms;
2864 int ms;
2865 struct timeval off_start;
2866
2868 /* Disable distinctive ring timeout count */
2870 }
2871 while ((ms = ast_remaining_ms(start, timeout))) {
2872 res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2873 if (res < 0) {
2875 "CallerID returned with error on channel '%s'\n",
2876 ast_channel_name(chan));
2877 break;
2878 }
2879 if (res == 0) {
2880 break;
2881 }
2882 if (res != 1) {
2883 continue;
2884 }
2885 if (ev == ANALOG_EVENT_NOALARM) {
2886 analog_set_alarm(p, 0);
2887 }
2888 if (p->cid_signalling == CID_SIG_V23_JP) {
2889 if (ev == ANALOG_EVENT_RINGBEGIN) {
2890 analog_off_hook(p);
2891 usleep(1);
2892 }
2893 } else {
2894 break;
2895 }
2896 }
2897
2898 name = namebuf;
2899 number = numbuf;
2900
2901 if (p->cid_signalling == CID_SIG_V23_JP) {
2902 analog_on_hook(p);
2903 usleep(1);
2904 }
2905
2906 /* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
2907 off_start = ast_tvnow();
2908 off_ms = 4000;/* This is a typical OFF time between rings. */
2909 while ((ms = ast_remaining_ms(off_start, off_ms))) {
2910 struct ast_frame *f;
2911
2912 res = ast_waitfor(chan, ms);
2913 if (res <= 0) {
2915 "CID timed out waiting for ring. Exiting simple switch\n");
2917 ast_hangup(chan);
2918 goto quit;
2919 }
2920 if (!(f = ast_read(chan))) {
2921 ast_log(LOG_WARNING, "Hangup received waiting for ring. Exiting simple switch\n");
2923 ast_hangup(chan);
2924 goto quit;
2925 }
2926 ast_frfree(f);
2927 if (ast_channel_state(chan) == AST_STATE_RING ||
2929 break; /* Got ring */
2930 }
2931
2932 res = analog_distinctive_ring(chan, p, idx, NULL);
2934 if (res) {
2935 goto quit;
2936 }
2937 } else {
2938 ast_log(LOG_WARNING, "Unable to get caller ID space\n");
2939 }
2940 } else {
2942 "Channel %s in prering state, but I have nothing to do. Terminating simple switch, should be restarted by the actual ring.\n",
2943 ast_channel_name(chan));
2944 ast_hangup(chan);
2945 goto quit;
2946 }
2947 } else if (p->use_callerid && p->cid_start == ANALOG_CID_START_RING) {
2948 namebuf[0] = 0;
2949 numbuf[0] = 0;
2950
2952 int timeout = 10000; /* Ten seconds */
2953 struct timeval start = ast_tvnow();
2954 enum analog_event ev;
2955 int ring_data[RING_PATTERNS] = { 0 };
2956 int ring_data_idx = 0;
2957 int ms;
2958
2960 /* Disable distinctive ring timeout count */
2962 }
2963 while ((ms = ast_remaining_ms(start, timeout))) {
2964 res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2965 if (res < 0) {
2967 "CallerID returned with error on channel '%s'\n",
2968 ast_channel_name(chan));
2969 break;
2970 }
2971 if (res == 0) {
2972 break;
2973 }
2974 if (res != 1) {
2975 continue;
2976 }
2977 if (ev == ANALOG_EVENT_NOALARM) {
2978 analog_set_alarm(p, 0);
2979 } else if (ev == ANALOG_EVENT_POLARITY
2981 && p->polarity == POLARITY_REV) {
2982 ast_debug(1,
2983 "Hanging up due to polarity reversal on channel %d while detecting callerid\n",
2984 p->channel);
2987 ast_hangup(chan);
2988 goto quit;
2989 } else if (ev == ANALOG_EVENT_RINGOFFHOOK
2991 && ring_data_idx < RING_PATTERNS) {
2992 /*
2993 * Detect callerid while collecting possible
2994 * distinctive ring pattern.
2995 */
2996 ring_data[ring_data_idx] = p->ringt;
2997 ++ring_data_idx;
2998 }
2999 }
3000
3001 name = namebuf;
3002 number = numbuf;
3003
3004 res = analog_distinctive_ring(chan, p, idx, ring_data);
3006 if (res) {
3007 goto quit;
3008 }
3009 } else {
3010 ast_log(LOG_WARNING, "Unable to get caller ID space\n");
3011 }
3012 }
3013
3014 if (number) {
3016 }
3018
3019 analog_handle_notify_message(chan, p, flags, -1);
3020
3021 ast_channel_lock(chan);
3023 ast_channel_rings_set(chan, 1);
3024 ast_channel_unlock(chan);
3026 res = ast_pbx_run(chan);
3027 if (res) {
3028 ast_hangup(chan);
3029 ast_log(LOG_WARNING, "PBX exited non-zero\n");
3030 }
3031 goto quit;
3032 default:
3033 ast_log(LOG_WARNING, "Don't know how to handle simple switch with signalling %s on channel %d\n", analog_sigtype_to_str(p->sig), p->channel);
3034 break;
3035 }
3037 if (res < 0) {
3038 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
3039 }
3040 ast_hangup(chan);
3041quit:
3042 ao2_cleanup(smdi_msg);
3044 return NULL;
3045}
3046
3048{
3049 pthread_t threadid;
3050
3051 p->ss_astchan = chan;
3053}
3054
3056{
3057 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
3058
3059 ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", channel);
3060 body = ast_json_pack("{s: i}", "Channel", channel);
3061 if (!body) {
3062 return;
3063 }
3064
3065 ast_manager_publish_event("AlarmClear", EVENT_FLAG_SYSTEM, body);
3066}
3067
3068static struct ast_frame *__analog_handle_event(struct analog_pvt *p, struct ast_channel *ast)
3069{
3070 int res, x;
3071 int mysig;
3072 int idx;
3073 char *c;
3074 pthread_t threadid;
3075 struct ast_channel *chan;
3076 struct ast_frame *f;
3077 struct ast_control_pvt_cause_code *cause_code = NULL;
3078 int data_size = sizeof(*cause_code);
3079 char *subclass = NULL;
3080
3081 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
3082
3083 idx = analog_get_index(ast, p, 0);
3084 if (idx < 0) {
3085 return &ast_null_frame;
3086 }
3087 if (idx != ANALOG_SUB_REAL) {
3088 ast_log(LOG_ERROR, "We got an event on a non real sub. Fix it!\n");
3089 }
3090
3091 mysig = p->sig;
3092 if (p->outsigmod > -1) {
3093 mysig = p->outsigmod;
3094 }
3095
3096 p->subs[idx].f.frametype = AST_FRAME_NULL;
3097 p->subs[idx].f.subclass.integer = 0;
3098 p->subs[idx].f.datalen = 0;
3099 p->subs[idx].f.samples = 0;
3100 p->subs[idx].f.mallocd = 0;
3101 p->subs[idx].f.offset = 0;
3102 p->subs[idx].f.src = "dahdi_handle_event";
3103 p->subs[idx].f.data.ptr = NULL;
3104 f = &p->subs[idx].f;
3105
3106 res = analog_get_event(p);
3107
3108 ast_debug(1, "Got event %s(%d) on channel %d (index %u)\n", analog_event2str(res), res, p->channel, idx);
3109
3112 ast_debug(1, "Detected %sdigit '%c'\n", (res & ANALOG_EVENT_PULSEDIGIT) ? "pulse ": "", res & 0xff);
3113 analog_confmute(p, 0);
3116 p->subs[idx].f.subclass.integer = res & 0xff;
3117 analog_handle_dtmf(p, ast, idx, &f);
3118 } else {
3119 ast_debug(1, "Dropping pulse digit '%c' because pulse dialing disabled on channel %d\n", res & 0xff, p->channel);
3120 }
3121 return f;
3122 }
3123
3124 if (res & ANALOG_EVENT_DTMFDOWN) {
3125 ast_debug(1, "DTMF Down '%c'\n", res & 0xff);
3126 /* Mute conference */
3127 analog_confmute(p, 1);
3129 p->subs[idx].f.subclass.integer = res & 0xff;
3130 analog_handle_dtmf(p, ast, idx, &f);
3131 return f;
3132 }
3133
3134 switch (res) {
3135 case ANALOG_EVENT_ALARM:
3138 /* add length of "ANALOG " */
3139 data_size += 7;
3140 subclass = analog_event2str(res);
3141 data_size += strlen(subclass);
3142 cause_code = ast_alloca(data_size);
3143 memset(cause_code, 0, data_size);
3146 snprintf(cause_code->code, data_size - sizeof(*cause_code) + 1, "ANALOG %s", subclass);
3147 break;
3148 default:
3149 break;
3150 }
3151
3152 switch (res) {
3154 ast_verb(3, "Channel %d echo canceller disabled due to CED detection\n", p->channel);
3156 break;
3157#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
3159 ast_verb(3, "Channel %d detected a CED tone towards the network.\n", p->channel);
3160 break;
3162 ast_verb(3, "Channel %d detected a CED tone from the network.\n", p->channel);
3163 break;
3165 ast_verb(3, "Channel %d echo canceller disabled its NLP.\n", p->channel);
3166 break;
3168 ast_verb(3, "Channel %d echo canceller enabled its NLP.\n", p->channel);
3169 break;
3170#endif
3172 /* Stop tone if there's a pulse start and the PBX isn't started */
3173 if (!ast_channel_pbx(ast))
3175 break;
3177 if (p->inalarm) {
3178 break;
3179 }
3180 x = analog_is_dialing(p, idx);
3181 if (!x) { /* if not still dialing in driver */
3183 if (p->echobreak) {
3185 ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr));
3188 p->echobreak = 0;
3189 } else {
3190 analog_set_dialing(p, 0);
3191 if ((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) {
3192 /* if thru with dialing after offhook */
3197 break;
3198 } else { /* if to state wait for offhook to dial rest */
3199 /* we now wait for off hook */
3201 }
3202 }
3205 ast_debug(1, "Done dialing, but waiting for progress detection before doing more...\n");
3206 } else if (analog_check_confirmanswer(p) || (!p->dialednone
3207 && ((mysig == ANALOG_SIG_EM) || (mysig == ANALOG_SIG_EM_E1)
3208 || (mysig == ANALOG_SIG_EMWINK) || (mysig == ANALOG_SIG_FEATD)
3209 || (mysig == ANALOG_SIG_FEATDMF_TA) || (mysig == ANALOG_SIG_FEATDMF)
3210 || (mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA)
3211 || (mysig == ANALOG_SIG_FGC_CAMAMF) || (mysig == ANALOG_SIG_FEATB)
3212 || (mysig == ANALOG_SIG_SF) || (mysig == ANALOG_SIG_SFWINK)
3213 || (mysig == ANALOG_SIG_SF_FEATD) || (mysig == ANALOG_SIG_SF_FEATDMF)
3214 || (mysig == ANALOG_SIG_SF_FEATB)))) {
3216 } else if (!p->answeronpolarityswitch) {
3220 /* If aops=0 and hops=1, this is necessary */
3222 } else {
3223 /* Start clean, so we can catch the change to REV polarity when party answers */
3225 }
3226 }
3227 }
3228 }
3229 break;
3230 case ANALOG_EVENT_ALARM:
3231 analog_set_alarm(p, 1);
3235 if (p->calledsubscriberheld && IS_FXO_SIG(p) && idx == ANALOG_SUB_REAL) {
3236 ast_debug(4, "Channel state on %s is %d\n", ast_channel_name(ast), ast_channel_state(ast));
3237 /* Called Subscriber Held: don't let the called party hang up on an incoming call immediately (if it's the only call). */
3239 ast_debug(2, "Letting this call hang up normally, since it's not the only call\n");
3240 } else if (!p->owner || !p->subs[ANALOG_SUB_REAL].owner || ast_channel_state(ast) != AST_STATE_UP) {
3241 ast_debug(2, "Called Subscriber Held does not apply: channel state is %d\n", ast_channel_state(ast));
3243 /* If the channel application is empty, it is likely a masquerade has occured, in which case don't hold any calls.
3244 * This conditional matches only executions that would have reached the strcmp below. */
3245 ast_debug(1, "Skipping Called Subscriber Held; channel has no application\n");
3246 } else if (!p->owner || !p->subs[ANALOG_SUB_REAL].owner || strcmp(ast_channel_appl(p->subs[ANALOG_SUB_REAL].owner), "AppDial")) {
3247 /* Called Subscriber held only applies to incoming calls, not outgoing calls.
3248 * We can't use p->outgoing because that is always true, for both incoming and outgoing calls, so it's not accurate.
3249 * We can check the channel application/data instead.
3250 * For incoming calls to the channel, it will look like: AppDial / (Outgoing Line)
3251 * We only want this behavior for regular calls anyways (and not, say, Queue),
3252 * so this would actually work great. But accessing ast_channel_appl can cause a crash if there are no calls left,
3253 * so this check must occur AFTER we confirm the channel state *is* still UP.
3254 */
3255 ast_debug(2, "Called Subscriber Held does not apply: not an incoming call\n");
3256 } else if (analog_is_off_hook(p)) {
3257 ast_log(LOG_WARNING, "Got ONHOOK but channel %d is off hook?\n", p->channel); /* Shouldn't happen */
3258 } else {
3259 ast_verb(3, "Holding incoming call %s for channel %d\n", ast_channel_name(ast), p->channel);
3260 /* Inhibit dahdi_hangup from getting called, and do nothing else now.
3261 * When the DAHDI channel goes off hook again, it'll just get reconnected with the incoming call,
3262 * to which, as far as its concerned, nothing has happened. */
3263 p->cshactive = 1; /* Keep track that this DAHDI channel is currently being held by an incoming call. */
3264 break;
3265 }
3266 }
3268 ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
3269 ast_channel_hangupcause_hash_set(ast, cause_code, data_size);
3270 switch (p->sig) {
3271 case ANALOG_SIG_FXOLS:
3272 case ANALOG_SIG_FXOGS:
3273 case ANALOG_SIG_FXOKS:
3275 p->fxsoffhookstate = 0;
3276 p->onhooktime = time(NULL);
3277 p->msgstate = -1;
3278 /* Check for some special conditions regarding call waiting */
3279 if (idx == ANALOG_SUB_REAL) {
3280 /* The normal line was hung up */
3281 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
3282 /* Need to hold the lock for real-call, private, and call-waiting call */
3284 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
3285 /*
3286 * The call waiting call disappeared.
3287 * This is now a normal hangup.
3288 */
3290 return NULL;
3291 }
3292
3293 /* There's a call waiting call, so ring the phone, but make it unowned in the meantime */
3295 ast_verb(3, "Channel %d still has (callwait) call, ringing phone\n", p->channel);
3299 /* Don't start streaming audio yet if the incoming call isn't up yet */
3301 analog_set_dialing(p, 1);
3302 }
3303 /* Unlock the call-waiting call that we swapped to real-call. */
3305 analog_ring(p);
3306 } else if (p->subs[ANALOG_SUB_THREEWAY].owner) {
3307 unsigned int mssinceflash;
3308
3309 /* Need to hold the lock for real-call, private, and 3-way call */
3311 if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3312 ast_log(LOG_NOTICE, "Whoa, threeway disappeared kinda randomly.\n");
3313 /* Just hangup */
3314 return NULL;
3315 }
3316 if (p->owner != ast) {
3318 ast_log(LOG_WARNING, "This isn't good...\n");
3319 /* Just hangup */
3320 return NULL;
3321 }
3322
3323 mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
3324 ast_debug(1, "Last flash was %u ms ago\n", mssinceflash);
3325 if (mssinceflash < MIN_MS_SINCE_FLASH) {
3326 /* It hasn't been long enough since the last flashook. This is probably a bounce on
3327 hanging up. Hangup both channels now */
3328 ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel);
3332 } else if ((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) {
3333 if (p->transfer) {
3334 /* In any case this isn't a threeway call anymore */
3337
3338 /* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */
3339 if (!p->transfertobusy && ast_channel_state(ast) == AST_STATE_BUSY) {
3340 /* Swap subs and dis-own channel */
3342 /* Unlock the 3-way call that we swapped to real-call. */
3345 /* Ring the phone */
3346 analog_ring(p);
3347 } else if (!analog_attempt_transfer(p)) {
3348 /*
3349 * Transfer successful. Don't actually hang up at this point.
3350 * Let our channel legs of the calls die off as the transfer
3351 * percolates through the core.
3352 */
3353 break;
3354 }
3355 } else {
3358 }
3359 } else {
3360 /* Swap subs and dis-own channel */
3362 /* Unlock the 3-way call that we swapped to real-call. */
3365 /* Ring the phone */
3366 analog_ring(p);
3367 }
3368 }
3369 } else {
3370 ast_log(LOG_WARNING, "Got a hangup and my index is %u?\n", idx);
3371 }
3372 /* Fall through */
3373 default:
3375 return NULL;
3376 }
3377 break;
3379 if (p->inalarm) {
3380 break;
3381 }
3382 /* for E911, its supposed to wait for offhook then dial
3383 the second half of the dial string */
3384 if (((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) && (ast_channel_state(ast) == AST_STATE_DIALING_OFFHOOK)) {
3385 c = strchr(p->dialdest, '/');
3386 if (c) {
3387 c++;
3388 } else {
3389 c = p->dialdest;
3390 }
3391
3392 if (*c) {
3393 int numchars = snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
3394 if (numchars >= sizeof(p->dop.dialstr)) {
3395 ast_log(LOG_WARNING, "Dial string '%s' truncated\n", c);
3396 }
3397 } else {
3398 ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
3399 }
3400
3401 if (strlen(p->dop.dialstr) > 4) {
3402 memset(p->echorest, 'w', sizeof(p->echorest) - 1);
3403 strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
3404 p->echorest[sizeof(p->echorest) - 1] = '\0';
3405 p->echobreak = 1;
3406 p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
3407 } else {
3408 p->echobreak = 0;
3409 }
3410 if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
3411 analog_on_hook(p);
3412 return NULL;
3413 }
3414 analog_set_dialing(p, 1);
3415 return &p->subs[idx].f;
3416 }
3417 switch (p->sig) {
3418 case ANALOG_SIG_FXOLS:
3419 case ANALOG_SIG_FXOGS:
3420 case ANALOG_SIG_FXOKS:
3421 p->fxsoffhookstate = 1;
3422 switch (ast_channel_state(ast)) {
3423 case AST_STATE_RINGING:
3428 /* Make sure it stops ringing */
3430 analog_off_hook(p);
3431 ast_debug(1, "channel %d answered\n", p->channel);
3432
3433 /* Cancel any running CallerID spill */
3435
3436 analog_set_dialing(p, 0);
3437 p->callwaitcas = 0;
3439 /* Ignore answer if "confirm answer" is enabled */
3440 p->subs[idx].f.frametype = AST_FRAME_NULL;
3441 p->subs[idx].f.subclass.integer = 0;
3442 } else if (!ast_strlen_zero(p->dop.dialstr)) {
3443 /* nick@dccinc.com 4/3/03 - fxo should be able to do deferred dialing */
3444 res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3445 if (res) {
3446 p->dop.dialstr[0] = '\0';
3447 return NULL;
3448 } else {
3449 ast_debug(1, "Sent FXO deferred digit string: %s\n", p->dop.dialstr);
3450 p->subs[idx].f.frametype = AST_FRAME_NULL;
3451 p->subs[idx].f.subclass.integer = 0;
3452 analog_set_dialing(p, 1);
3453 }
3454 p->dop.dialstr[0] = '\0';
3456 } else {
3459 }
3460 return &p->subs[idx].f;
3461 case AST_STATE_DOWN:
3463 ast_channel_rings_set(ast, 1);
3466 ast_debug(1, "channel %d picked up\n", p->channel);
3467 return &p->subs[idx].f;
3468 case AST_STATE_UP:
3469 /* Make sure it stops ringing */
3470 analog_off_hook(p);
3471 /* Okay -- probably call waiting */
3473 break;
3474 case AST_STATE_RESERVED:
3475 /* Start up dialtone */
3476 if (analog_has_voicemail(p)) {
3478 } else {
3480 }
3481 break;
3482 default:
3483 ast_log(LOG_WARNING, "FXO phone off hook in weird state %u??\n", ast_channel_state(ast));
3484 }
3485 break;
3486 case ANALOG_SIG_FXSLS:
3487 case ANALOG_SIG_FXSGS:
3488 case ANALOG_SIG_FXSKS:
3489 if (ast_channel_state(ast) == AST_STATE_RING) {
3491 }
3492
3493 /* Fall through */
3494 case ANALOG_SIG_EM:
3495 case ANALOG_SIG_EM_E1:
3496 case ANALOG_SIG_EMWINK:
3497 case ANALOG_SIG_FEATD:
3498 case ANALOG_SIG_FEATDMF:
3500 case ANALOG_SIG_E911:
3503 case ANALOG_SIG_FEATB:
3504 case ANALOG_SIG_SF:
3505 case ANALOG_SIG_SFWINK:
3509 switch (ast_channel_state(ast)) {
3510 case AST_STATE_PRERING:
3512 /* Fall through */
3513 case AST_STATE_DOWN:
3514 case AST_STATE_RING:
3515 ast_debug(1, "Ring detected\n");
3518 break;
3519 case AST_STATE_RINGING:
3520 case AST_STATE_DIALING:
3521 if (p->outgoing) {
3522 ast_debug(1, "Line answered\n");
3524 p->subs[idx].f.frametype = AST_FRAME_NULL;
3525 p->subs[idx].f.subclass.integer = 0;
3526 } else {
3530 }
3531 break;
3532 }
3533 /* Fall through */
3534 default:
3535 ast_log(LOG_WARNING, "Ring/Off-hook in strange state %u on channel %d\n", ast_channel_state(ast), p->channel);
3536 break;
3537 }
3538 break;
3539 default:
3540 ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3541 break;
3542 }
3543 break;
3545 switch (p->sig) {
3546 case ANALOG_SIG_FXSLS:
3547 case ANALOG_SIG_FXSGS:
3548 case ANALOG_SIG_FXSKS:
3549 if (ast_channel_state(ast) == AST_STATE_RING) {
3551 }
3552 break;
3553 default:
3554 break;
3555 }
3556 break;
3558 if (p->inalarm) break;
3560 if (ast_channel_rings(ast) == p->cidrings) {
3561 analog_send_callerid(p, 0, &p->caller);
3562 }
3563
3564 if (ast_channel_rings(ast) > p->cidrings) {
3566 p->callwaitcas = 0;
3567 }
3570 break;
3572 break;
3574 analog_set_alarm(p, 0);
3576 break;
3578 if (p->inalarm) {
3579 break;
3580 }
3581 /* Remember last time we got a flash-hook */
3582 gettimeofday(&p->flashtime, NULL);
3584 switch (mysig) {
3585 case ANALOG_SIG_FXOLS:
3586 case ANALOG_SIG_FXOGS:
3587 case ANALOG_SIG_FXOKS:
3588 ast_debug(1, "Winkflash, index: %u, normal: %d, callwait: %d, thirdcall: %d\n",
3590
3591 /* Cancel any running CallerID spill */
3593 p->callwaitcas = 0;
3594
3595 if (idx != ANALOG_SUB_REAL) {
3596 ast_log(LOG_WARNING, "Got flash hook with index %u on channel %d?!?\n", idx, p->channel);
3597 goto winkflashdone;
3598 }
3599
3600 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
3601 /* Need to hold the lock for real-call, private, and call-waiting call */
3603 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
3604 /*
3605 * The call waiting call disappeared.
3606 * Let's just ignore this flash-hook.
3607 */
3608 ast_log(LOG_NOTICE, "Whoa, the call-waiting call disappeared.\n");
3609 goto winkflashdone;
3610 }
3611
3612 /* If line has Call Waiting Deluxe, see what the user wants to do.
3613 * Only do this if this is an as yet unanswered call waiting, not an existing, answered SUB_CALLWAIT. */
3615 if (p->callwaitingdeluxe) {
3616 /* This thread cannot block, so just set the flag that we need
3617 * to wait for a Call Waiting Deluxe option (or let it time out),
3618 * and then we're done for now. */
3621 ast_debug(1, "Deferring call waiting manipulation, waiting for Call Waiting Deluxe option from user\n");
3622 goto winkflashdone;
3623 }
3624 }
3625
3626 /* Swap to call-wait */
3630 ast_debug(1, "Making %s the new owner\n", ast_channel_name(p->owner));
3634 }
3636
3637 /* Start music on hold if appropriate */
3640 }
3643
3644 /* Unlock the call-waiting call that we swapped to real-call. */
3646 } else if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3647 if (!p->threewaycalling) {
3648 /* Just send a flash if no 3-way calling */
3650 goto winkflashdone;
3651 } else if (!analog_check_for_conference(p)) {
3652 ast_callid callid = 0;
3653 int callid_created;
3654 char cid_num[256];
3655 char cid_name[256];
3656
3657 cid_num[0] = '\0';
3658 cid_name[0] = '\0';
3659 if (p->dahditrcallerid && p->owner) {
3663 sizeof(cid_num));
3664 }
3668 sizeof(cid_name));
3669 }
3670 }
3671 /* XXX This section needs much more error checking!!! XXX */
3672 /* Start a 3-way call if feasible */
3673 if (!((ast_channel_pbx(ast)) ||
3674 (ast_channel_state(ast) == AST_STATE_UP) ||
3675 (ast_channel_state(ast) == AST_STATE_RING))) {
3676 ast_debug(1, "Flash when call not up or ringing\n");
3677 goto winkflashdone;
3678 }
3680 ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n");
3681 goto winkflashdone;
3682 }
3683
3684 callid_created = ast_callid_threadstorage_auto(&callid);
3685
3686 /*
3687 * Make new channel
3688 *
3689 * We cannot hold the p or ast locks while creating a new
3690 * channel.
3691 */
3693 ast_channel_unlock(ast);
3695 ast_channel_lock(ast);
3697 if (!chan) {
3699 "Cannot allocate new call structure on channel %d\n",
3700 p->channel);
3702 ast_callid_threadstorage_auto_clean(callid, callid_created);
3703 goto winkflashdone;
3704 }
3705 if (p->dahditrcallerid) {
3706 if (!p->origcid_num) {
3708 }
3709 if (!p->origcid_name) {
3711 }
3712 ast_copy_string(p->cid_num, cid_num, sizeof(p->cid_num));
3713 ast_copy_string(p->cid_name, cid_name, sizeof(p->cid_name));
3714 }
3715 /* Swap things around between the three-way and real call */
3717 /* Disable echo canceller for better dialing */
3720 if (res) {
3721 ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel);
3722 }
3723 analog_set_new_owner(p, chan);
3724 p->ss_astchan = chan;
3726 ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel);
3729 ast_hangup(chan);
3730 } else {
3731 ast_verb(3, "Started three way call on channel %d\n", p->channel);
3732
3733 /* Start music on hold */
3735 }
3736 ast_callid_threadstorage_auto_clean(callid, callid_created);
3737 }
3738 } else {
3739 /* Already have a 3 way call */
3740 enum analog_sub orig_3way_sub;
3741
3742 /* Need to hold the lock for real-call, private, and 3-way call */
3744 if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3745 /*
3746 * The 3-way call disappeared.
3747 * Let's just ignore this flash-hook.
3748 */
3749 ast_log(LOG_NOTICE, "Whoa, the 3-way call disappeared.\n");
3750 goto winkflashdone;
3751 }
3752 orig_3way_sub = ANALOG_SUB_THREEWAY;
3753
3755 /* Call is already up, drop the last person */
3756 ast_debug(1, "Got flash with three way call up, dropping last call on %d\n", p->channel);
3757 /* If the primary call isn't answered yet, use it */
3760 /* Swap back -- we're dropping the real 3-way that isn't finished yet*/
3762 orig_3way_sub = ANALOG_SUB_REAL;
3764 }
3765 /* Drop the last call and stop the conference */
3766 ast_verb(3, "Dropping three-way call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner));
3770 } else {
3771 /* Lets see what we're up to */
3772 if (((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) &&
3774 ast_verb(3, "Building conference call with %s and %s\n",
3777 /* Put them in the threeway, and flip */
3781 orig_3way_sub = ANALOG_SUB_REAL;
3782 ast_queue_unhold(p->subs[orig_3way_sub].owner);
3784 } else {
3785 ast_verb(3, "Dumping incomplete call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner));
3787 orig_3way_sub = ANALOG_SUB_REAL;
3792 }
3793 }
3794 ast_channel_unlock(p->subs[orig_3way_sub].owner);
3795 }
3796winkflashdone:
3798 break;
3799 case ANALOG_SIG_EM:
3800 case ANALOG_SIG_EM_E1:
3801 case ANALOG_SIG_FEATD:
3802 case ANALOG_SIG_SF:
3803 case ANALOG_SIG_SFWINK:
3805 case ANALOG_SIG_FXSLS:
3806 case ANALOG_SIG_FXSGS:
3807 if (p->dialing) {
3808 ast_debug(1, "Ignoring wink on channel %d\n", p->channel);
3809 } else {
3810 ast_debug(1, "Got wink in weird state %u on channel %d\n", ast_channel_state(ast), p->channel);
3811 }
3812 break;
3814 switch (p->whichwink) {
3815 case 0:
3816 ast_debug(1, "ANI2 set to '%d' and ANI is '%s'\n", ast_channel_caller(p->owner)->ani2,
3819 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%d%s#",
3823 break;
3824 case 1:
3825 ast_copy_string(p->dop.dialstr, p->finaldial, sizeof(p->dop.dialstr));
3826 break;
3827 case 2:
3828 ast_log(LOG_WARNING, "Received unexpected wink on channel of type ANALOG_SIG_FEATDMF_TA\n");
3829 return NULL;
3830 }
3831 p->whichwink++;
3832 /* Fall through */
3833 case ANALOG_SIG_FEATDMF:
3834 case ANALOG_SIG_E911:
3837 case ANALOG_SIG_FEATB:
3840 case ANALOG_SIG_EMWINK:
3841 /* FGD MF and EMWINK *Must* wait for wink */
3842 if (!ast_strlen_zero(p->dop.dialstr)) {
3843 res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3844 if (res) {
3845 p->dop.dialstr[0] = '\0';
3846 return NULL;
3847 } else {
3848 ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3849 }
3850 }
3851 p->dop.dialstr[0] = '\0';
3852 break;
3853 default:
3854 ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3855 }
3856 break;
3858 if (p->inalarm) break;
3860 break;
3861 }
3862 switch (mysig) {
3863 case ANALOG_SIG_FXSLS: /* only interesting for FXS */
3864 case ANALOG_SIG_FXSGS:
3865 case ANALOG_SIG_FXSKS:
3866 case ANALOG_SIG_EM:
3867 case ANALOG_SIG_EM_E1:
3868 case ANALOG_SIG_EMWINK:
3869 case ANALOG_SIG_FEATD:
3870 case ANALOG_SIG_SF:
3871 case ANALOG_SIG_SFWINK:
3873 if (!ast_strlen_zero(p->dop.dialstr)) {
3874 res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3875 if (res) {
3876 p->dop.dialstr[0] = '\0';
3877 return NULL;
3878 } else {
3879 ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3880 }
3881 }
3882 p->dop.dialstr[0] = '\0';
3884 break;
3885 case ANALOG_SIG_FEATDMF:
3887 case ANALOG_SIG_E911:
3890 case ANALOG_SIG_FEATB:
3893 ast_debug(1, "Got hook complete in MF FGD, waiting for wink now on channel %d\n",p->channel);
3894 break;
3895 default:
3896 break;
3897 }
3898 break;
3900 /*
3901 * If we get a Polarity Switch event, this could be
3902 * due to line seizure, remote end connect or remote end disconnect.
3903 *
3904 * Check to see if we should change the polarity state and
3905 * mark the channel as UP or if this is an indication
3906 * of remote end disconnect.
3907 */
3908
3909 if (p->polarityonanswerdelay > 0) {
3910 /* check if event is not too soon after OffHook or Answer */
3912 switch (ast_channel_state(ast)) {
3913 case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3914 case AST_STATE_RINGING: /*!< Remote end is ringing */
3915 if (p->answeronpolarityswitch) {
3916 ast_debug(1, "Answering on polarity switch! channel %d\n", p->channel);
3919 if (p->hanguponpolarityswitch) {
3921 }
3922 } else {
3923 ast_debug(1, "Ignore Answer on polarity switch, channel %d\n", p->channel);
3924 }
3925 break;
3926
3927 case AST_STATE_UP: /*!< Line is up */
3928 case AST_STATE_RING: /*!< Line is ringing */
3929 if (p->hanguponpolarityswitch) {
3930 ast_debug(1, "HangingUp on polarity switch! channel %d\n", p->channel);
3931 ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
3932 ast_channel_hangupcause_hash_set(ast, cause_code, data_size);
3935 } else {
3936 ast_debug(1, "Ignore Hangup on polarity switch, channel %d\n", p->channel);
3937 }
3938 break;
3939
3940 case AST_STATE_DOWN: /*!< Channel is down and available */
3941 case AST_STATE_RESERVED: /*!< Channel is down, but reserved */
3942 case AST_STATE_OFFHOOK: /*!< Channel is off hook */
3943 case AST_STATE_BUSY: /*!< Line is busy */
3944 case AST_STATE_DIALING_OFFHOOK: /*!< Digits (or equivalent) have been dialed while offhook */
3945 case AST_STATE_PRERING: /*!< Channel has detected an incoming call and is waiting for ring */
3946 default:
3948 ast_debug(1, "Ignoring Polarity switch on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3949 }
3950 break;
3951 }
3952
3953 } else {
3954 /* event is too soon after OffHook or Answer */
3955 switch (ast_channel_state(ast)) {
3956 case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3957 case AST_STATE_RINGING: /*!< Remote end is ringing */
3958 if (p->answeronpolarityswitch) {
3959 ast_debug(1, "Polarity switch detected but NOT answering (too close to OffHook event) on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3960 }
3961 break;
3962
3963 case AST_STATE_UP: /*!< Line is up */
3964 case AST_STATE_RING: /*!< Line is ringing */
3965 if (p->hanguponpolarityswitch) {
3966 ast_debug(1, "Polarity switch detected but NOT hanging up (too close to Answer event) on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3967 }
3968 break;
3969
3970 default:
3972 ast_debug(1, "Polarity switch detected (too close to previous event) on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3973 }
3974 break;
3975 }
3976 }
3977 }
3978
3979 /* Added more log_debug information below to provide a better indication of what is going on */
3980 ast_debug(1, "Polarity Reversal event occurred - DEBUG 2: channel %d, state %u, pol= %d, aonp= %d, honp= %d, pdelay= %d, tv= %" PRIi64 "\n", p->channel, ast_channel_state(ast), p->polarity, p->answeronpolarityswitch, p->hanguponpolarityswitch, p->polarityonanswerdelay, ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) );
3981 break;
3982 default:
3983 ast_debug(1, "Dunno what to do with event %d on channel %d\n", res, p->channel);
3984 }
3985 return &p->subs[idx].f;
3986}
3987
3988struct ast_frame *analog_exception(struct analog_pvt *p, struct ast_channel *ast)
3989{
3990 int res;
3991 int idx;
3992 struct ast_frame *f;
3993
3994 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
3995
3996 idx = analog_get_index(ast, p, 1);
3997 if (idx < 0) {
3998 idx = ANALOG_SUB_REAL;
3999 }
4000
4001 p->subs[idx].f.frametype = AST_FRAME_NULL;
4002 p->subs[idx].f.datalen = 0;
4003 p->subs[idx].f.samples = 0;
4004 p->subs[idx].f.mallocd = 0;
4005 p->subs[idx].f.offset = 0;
4006 p->subs[idx].f.subclass.integer = 0;
4007 p->subs[idx].f.delivery = ast_tv(0,0);
4008 p->subs[idx].f.src = "dahdi_exception";
4009 p->subs[idx].f.data.ptr = NULL;
4010
4011 if (!p->owner) {
4012 /* If nobody owns us, absorb the event appropriately, otherwise
4013 we loop indefinitely. This occurs when, during call waiting, the
4014 other end hangs up our channel so that it no longer exists, but we
4015 have neither FLASH'd nor ONHOOK'd to signify our desire to
4016 change to the other channel. */
4017 res = analog_get_event(p);
4018
4019 /* Switch to real if there is one and this isn't something really silly... */
4020 if ((res != ANALOG_EVENT_RINGEROFF) && (res != ANALOG_EVENT_RINGERON) &&
4021 (res != ANALOG_EVENT_HOOKCOMPLETE)) {
4022 ast_debug(1, "Restoring owner of channel %d on event %d\n", p->channel, res);
4024 if (p->owner && ast != p->owner) {
4025 /*
4026 * Could this even happen?
4027 * Possible deadlock because we do not have the real-call lock.
4028 */
4029 ast_log(LOG_WARNING, "Event %s on %s is not restored owner %s\n",
4031 }
4032 if (p->owner) {
4034 }
4035 }
4036 switch (res) {
4039 if (p->owner) {
4040 ast_verb(3, "Channel %s still has call, ringing phone\n", ast_channel_name(p->owner));
4041 analog_ring(p);
4043 } else {
4044 ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
4045 analog_event2str(res));
4046 }
4048 break;
4051 analog_off_hook(p);
4052 if (p->owner && (ast_channel_state(p->owner) == AST_STATE_RINGING)) {
4054 analog_set_dialing(p, 0);
4055 }
4056 break;
4060 /* Do nothing */
4061 break;
4063 gettimeofday(&p->flashtime, NULL);
4064 if (p->owner) {
4065 ast_verb(3, "Channel %d flashed to other channel %s\n", p->channel, ast_channel_name(p->owner));
4067 /* Answer if necessary */
4070 }
4073 } else {
4074 ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
4075 analog_event2str(res));
4076 }
4078 break;
4079 default:
4080 ast_log(LOG_WARNING, "Don't know how to absorb event %s\n", analog_event2str(res));
4081 break;
4082 }
4083 f = &p->subs[idx].f;
4084 return f;
4085 }
4086 ast_debug(1, "Exception on %d, channel %d\n", ast_channel_fd(ast, 0), p->channel);
4087 /* If it's not us, return NULL immediately */
4088 if (ast != p->owner) {
4089 ast_log(LOG_WARNING, "We're %s, not %s\n", ast_channel_name(ast), ast_channel_name(p->owner));
4090 f = &p->subs[idx].f;
4091 return f;
4092 }
4093
4094 f = __analog_handle_event(p, ast);
4095 if (!f) {
4096 const char *name = ast_strdupa(ast_channel_name(ast));
4097
4098 /* Tell the CDR this DAHDI device hung up */
4100 ast_channel_unlock(ast);
4101 ast_set_hangupsource(ast, name, 0);
4102 ast_channel_lock(ast);
4104 }
4105 return f;
4106}
4107
4109{
4110 int res;
4111 pthread_t threadid;
4112 struct ast_channel *chan;
4113 ast_callid callid = 0;
4114 int callid_created;
4115
4116 ast_debug(1, "channel (%d) - signaling (%d) - event (%s)\n",
4118
4119 /* Handle an event on a given channel for the monitor thread. */
4120 switch (event) {
4123 switch (i->sig) {
4124 case ANALOG_SIG_FXSLS:
4125 case ANALOG_SIG_FXSGS:
4126 case ANALOG_SIG_FXSKS:
4127 if (i->immediate) {
4129 ast_log(LOG_WARNING, "Can't start PBX immediately, must wait for Caller ID / distinctive ring\n");
4130 } else {
4131 /* If we don't care about Caller ID or Distinctive Ring, then there's
4132 * no need to wait for anything before accepting the call, as
4133 * waiting will buy us nothing.
4134 * So if the channel is configured for immediate, actually start immediately
4135 * and get the show on the road as soon as possible. */
4136 ast_debug(1, "Disabling ring timeout (previously %d) to begin handling immediately\n", i->ringt_base);
4138 }
4139 }
4140 break;
4141 default:
4142 break;
4143 }
4144 /* Fall through */
4145 if (!(ISTRUNK(i) && i->immediate && !i->use_callerid && !i->usedistinctiveringdetection)) {
4146 break;
4147 }
4149 if (i->inalarm) {
4150 break;
4151 }
4152 /* Got a ring/answer. What kind of channel are we? */
4153 switch (i->sig) {
4154 case ANALOG_SIG_FXOLS:
4155 case ANALOG_SIG_FXOGS:
4156 case ANALOG_SIG_FXOKS:
4157 res = analog_off_hook(i);
4158 i->fxsoffhookstate = 1;
4159 i->cshactive = 0;
4161 if (res && (errno == EBUSY)) {
4162 break;
4163 }
4164 callid_created = ast_callid_threadstorage_auto(&callid);
4165
4166 /* Cancel VMWI spill */
4168
4169 if (i->immediate) {
4171 /* The channel is immediately up. Start right away */
4172 if (i->immediatering) {
4173 /* Play fake ringing, if we've been told to... */
4175 }
4177 if (!chan) {
4178 ast_log(LOG_WARNING, "Unable to start PBX on channel %d\n", i->channel);
4180 if (res < 0) {
4181 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4182 }
4183 }
4184 } else {
4185 /* Check for callerid, digits, etc */
4187 i->ss_astchan = chan;
4188 if (chan) {
4189 if (analog_has_voicemail(i)) {
4191 } else {
4193 }
4194 if (res < 0)
4195 ast_log(LOG_WARNING, "Unable to play dialtone on channel %d, do you have defaultzone and loadzone defined?\n", i->channel);
4196
4198 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4200 if (res < 0) {
4201 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4202 }
4203 ast_hangup(chan);
4204 }
4205 } else
4206 ast_log(LOG_WARNING, "Unable to create channel\n");
4207 }
4209 break;
4210 case ANALOG_SIG_FXSLS:
4211 case ANALOG_SIG_FXSGS:
4212 case ANALOG_SIG_FXSKS:
4214 /* Fall through */
4215 case ANALOG_SIG_EMWINK:
4216 case ANALOG_SIG_FEATD:
4217 case ANALOG_SIG_FEATDMF:
4219 case ANALOG_SIG_E911:
4222 case ANALOG_SIG_FEATB:
4223 case ANALOG_SIG_EM:
4224 case ANALOG_SIG_EM_E1:
4225 case ANALOG_SIG_SFWINK:
4229 case ANALOG_SIG_SF:
4230 callid_created = ast_callid_threadstorage_auto(&callid);
4231 /* Check for callerid, digits, etc */
4234 } else {
4236 }
4237 i->ss_astchan = chan;
4238 if (!chan) {
4239 ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
4240 } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4241 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4243 if (res < 0) {
4244 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4245 }
4246 ast_hangup(chan);
4247 }
4249 break;
4250 default:
4251 ast_log(LOG_WARNING, "Don't know how to handle ring/answer with signalling %s on channel %d\n", analog_sigtype_to_str(i->sig), i->channel);
4253 if (res < 0) {
4254 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4255 }
4256 return NULL;
4257 }
4258 break;
4260 analog_set_alarm(i, 0);
4262 break;
4263 case ANALOG_EVENT_ALARM:
4264 analog_set_alarm(i, 1);
4266 /* fall thru intentionally */
4268 /* Back on hook. Hang up. */
4269 switch (i->sig) {
4270 case ANALOG_SIG_FXOLS:
4271 case ANALOG_SIG_FXOGS:
4272 i->fxsoffhookstate = 0;
4274 /* Fall through */
4275 case ANALOG_SIG_FEATD:
4276 case ANALOG_SIG_FEATDMF:
4278 case ANALOG_SIG_E911:
4281 case ANALOG_SIG_FEATB:
4282 case ANALOG_SIG_EM:
4283 case ANALOG_SIG_EM_E1:
4284 case ANALOG_SIG_EMWINK:
4288 case ANALOG_SIG_SF:
4289 case ANALOG_SIG_SFWINK:
4290 case ANALOG_SIG_FXSLS:
4291 case ANALOG_SIG_FXSGS:
4292 case ANALOG_SIG_FXSKS:
4294 res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
4295 analog_on_hook(i);
4296 break;
4297 case ANALOG_SIG_FXOKS:
4298 i->fxsoffhookstate = 0;
4301 /* Diddle the battery for the zhone */
4302#ifdef ZHONE_HACK
4303 analog_off_hook(i);
4304 usleep(1);
4305#endif
4306 res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
4307 analog_on_hook(i);
4308 break;
4309 default:
4310 ast_log(LOG_WARNING, "Don't know how to handle on hook with signalling %s on channel %d\n", analog_sigtype_to_str(i->sig), i->channel);
4311 res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
4312 return NULL;
4313 }
4314 break;
4316 switch (i->sig) {
4317 case ANALOG_SIG_FXSLS:
4318 case ANALOG_SIG_FXSKS:
4319 case ANALOG_SIG_FXSGS:
4320 callid_created = ast_callid_threadstorage_auto(&callid);
4321 /* We have already got a PR before the channel was
4322 created, but it wasn't handled. We need polarity
4323 to be REV for remote hangup detection to work.
4324 At least in Spain */
4325 if (i->hanguponpolarityswitch) {
4327 }
4330 ast_verb(2, "Starting post polarity CID detection on channel %d\n",
4331 i->channel);
4333 i->ss_astchan = chan;
4334 if (!chan) {
4335 ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
4336 } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4337 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4338 ast_hangup(chan);
4339 }
4340 }
4342 break;
4343 default:
4345 "handle_init_event detected polarity reversal on non-FXO (ANALOG_SIG_FXS) interface %d\n",
4346 i->channel);
4347 break;
4348 }
4349 break;
4351 switch (i->sig) {
4352 case ANALOG_SIG_FXSLS:
4353 case ANALOG_SIG_FXSKS:
4354 case ANALOG_SIG_FXSGS:
4355 callid_created = ast_callid_threadstorage_auto(&callid);
4357 ast_verb(2, "Starting DTMF CID detection on channel %d\n",
4358 i->channel);
4360 i->ss_astchan = chan;
4361 if (!chan) {
4362 ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
4363 } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4364 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4365 ast_hangup(chan);
4366 }
4367 }
4369 break;
4370 default:
4372 "handle_init_event detected dtmfcid generation event on non-FXO (ANALOG_SIG_FXS) interface %d\n",
4373 i->channel);
4374 break;
4375 }
4376 break;
4377 case ANALOG_EVENT_REMOVED: /* destroy channel, will actually do so in do_monitor */
4378 ast_log(LOG_NOTICE, "Got ANALOG_EVENT_REMOVED. Destroying channel %d\n",
4379 i->channel);
4380 return i->chan_pvt;
4383 break;
4386 break;
4387 }
4388 return NULL;
4389}
4390
4391
4392struct analog_pvt *analog_new(enum analog_sigtype signallingtype, void *private_data)
4393{
4394 struct analog_pvt *p;
4395
4396 p = ast_calloc(1, sizeof(*p));
4397 if (!p) {
4398 return p;
4399 }
4400
4402 p->sig = signallingtype;
4403 p->chan_pvt = private_data;
4404
4405 /* Some defaults for values */
4408 /* Sub real is assumed to always be alloc'd */
4409 p->subs[ANALOG_SUB_REAL].allocd = 1;
4410
4411 return p;
4412}
4413
4414/*!
4415 * \brief Delete the analog private structure.
4416 * \since 1.8
4417 *
4418 * \param doomed Analog private structure to delete.
4419 */
4420void analog_delete(struct analog_pvt *doomed)
4421{
4422 ast_free(doomed);
4423}
4424
4426{
4427 /* No call waiting on non FXS channels */
4428 if (!IS_FXO_SIG(p)) {
4429 p->permcallwaiting = 0;
4430 }
4431
4433
4434 return 0;
4435}
4436
4438{
4439 ast_free(p);
4440}
4441
4442/* called while dahdi_pvt is locked in dahdi_fixup */
4443int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp)
4444{
4445 struct analog_pvt *new_pvt = newp;
4446 int x;
4447 ast_debug(1, "New owner for channel %d is %s\n", new_pvt->channel, ast_channel_name(newchan));
4448 if (new_pvt->owner == oldchan) {
4449 analog_set_new_owner(new_pvt, newchan);
4450 }
4451 for (x = 0; x < 3; x++) {
4452 if (new_pvt->subs[x].owner == oldchan) {
4453 new_pvt->subs[x].owner = newchan;
4454 }
4455 }
4456
4457 analog_update_conf(new_pvt);
4458 return 0;
4459}
4460
4461static void analog_publish_dnd_state(int channel, const char *status)
4462{
4463 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
4464 RAII_VAR(struct ast_str *, dahdichan, ast_str_create(32), ast_free);
4465 if (!dahdichan) {
4466 return;
4467 }
4468
4469 ast_str_set(&dahdichan, 0, "DAHDI/%d", channel);
4470
4471 body = ast_json_pack("{s: s, s: s}",
4472 "Channel", ast_str_buffer(dahdichan),
4473 "Status", status);
4474 if (!body) {
4475 return;
4476 }
4477
4479}
4480
4481int analog_dnd(struct analog_pvt *p, int flag)
4482{
4483 if (flag == -1) {
4484 return p->dnd;
4485 }
4486
4487 p->dnd = flag;
4488
4489 ast_verb(3, "%s DND on channel %d\n",
4490 flag ? "Enabled" : "Disabled",
4491 p->channel);
4492 analog_publish_dnd_state(p->channel, flag ? "enabled" : "disabled");
4493
4494 return 0;
4495}
jack_status_t status
Definition app_jack.c:149
const char * str
Definition app_jack.c:150
Persistent data storage (akin to *doze registry)
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition db.c:335
char * strsep(char **str, const char *delims)
Asterisk main include file. File version handling, generic pbx functions.
#define PATH_MAX
Definition asterisk.h:40
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition astmm.h:288
#define ast_free(a)
Definition astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
#define ast_log
Definition astobj2.c:42
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
Bridging API.
ast_transfer_result
Definition bridge.h:1159
@ AST_BRIDGE_TRANSFER_SUCCESS
Definition bridge.h:1161
enum ast_transfer_result ast_bridge_transfer_attended(struct ast_channel *to_transferee, struct ast_channel *to_transfer_target)
Attended transfer.
Definition bridge.c:4886
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
#define CID_SIG_V23_JP
Definition callerid.h:63
#define AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED
Definition callerid.h:449
#define CID_SIG_SMDI
Definition callerid.h:64
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()'s,...
Definition callerid.c:1101
#define CID_SIG_DTMF
Definition callerid.h:62
#define CID_SIG_V23
Definition callerid.h:61
void callerid_get_dtmf(char *cidstring, char *number, int *flags)
Get and parse DTMF-based callerid.
Definition callerid.c:211
#define CID_SIG_BELL
Definition callerid.h:60
#define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED
Definition callerid.h:437
Internal Asterisk hangup causes.
#define AST_CAUSE_NETWORK_OUT_OF_ORDER
Definition causes.h:121
#define AST_CAUSE_NO_ANSWER
Definition causes.h:109
#define AST_CAUSE_NORMAL_CLEARING
Definition causes.h:106
#define AST_CC_GENERIC_MONITOR_TYPE
Definition ccss.h:455
@ AST_CC_CCNR
Definition ccss.h:38
@ AST_CC_MONITOR_NEVER
Definition ccss.h:76
@ AST_CC_MONITOR_ALWAYS
Definition ccss.h:87
@ AST_CC_MONITOR_NATIVE
Definition ccss.h:78
@ AST_CC_MONITOR_GENERIC
Definition ccss.h:83
enum ast_cc_monitor_policies ast_get_cc_monitor_policy(struct ast_cc_config_params *config)
Get the cc_monitor_policy.
Definition ccss.c:900
int ast_queue_cc_frame(struct ast_channel *chan, const char *const monitor_type, const char *const dialstring, enum ast_cc_service_type service, void *private_data)
Queue an AST_CONTROL_CC frame.
Definition ccss.c:4206
struct analog_callback analog_callbacks
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition channel.c:3179
const char * ast_channel_name(const struct ast_channel *chan)
void ast_channel_rings_set(struct ast_channel *chan, int value)
void * ast_channel_tech_pvt(const struct ast_channel *chan)
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition channel.c:2540
int ast_channel_rings(const struct ast_channel *chan)
int ast_queue_hangup(struct ast_channel *chan)
Queue a hangup frame.
Definition channel.c:1182
#define ast_channel_lock(chan)
Definition channel.h:2983
@ AST_FLAG_END_DTMF_ONLY
Definition channel.h:1027
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition channel.c:3166
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
Definition channel.c:1289
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
#define ast_channel_ref(c)
Increase channel reference count.
Definition channel.h:3008
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
ast_callid ast_channel_callid(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition channel.c:4278
#define ast_channel_trylock(chan)
Definition channel.h:2985
int ast_queue_control_data(struct ast_channel *chan, enum ast_control_frame_type control, const void *data, size_t datalen)
Queue a control frame with payload.
Definition channel.c:1296
const char * ast_channel_appl(const struct ast_channel *chan)
void ast_set_callerid(struct ast_channel *chan, const char *cid_num, const char *cid_name, const char *cid_ani)
Set caller ID number, name and ANI and generate AMI event.
Definition channel.c:7370
int ast_channel_fd(const struct ast_channel *chan, int which)
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
Definition channel.c:1213
void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
Set the source of the hangup in this channel and it's bridge.
Definition channel.c:2498
int ast_softhangup(struct ast_channel *chan, int cause)
Softly hangup up a channel.
Definition channel.c:2462
void ast_channel_hangupcause_hash_set(struct ast_channel *chan, const struct ast_control_pvt_cause_code *cause_code, int datalen)
Sets the HANGUPCAUSE hash and optionally the SIP_CAUSE hash on the given channel.
Definition channel.c:4368
int ast_queue_unhold(struct ast_channel *chan)
Queue an unhold frame.
Definition channel.c:1274
int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
Queue a hold frame.
Definition channel.c:1249
#define AST_CHANNEL_NAME
Definition channel.h:173
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3019
const char * ast_channel_language(const struct ast_channel *chan)
struct ast_bridge_channel * ast_channel_get_bridge_channel(struct ast_channel *chan)
Get a reference to the channel's bridge pointer.
Definition channel.c:10762
@ AST_SOFTHANGUP_EXPLICIT
Definition channel.h:1168
@ AST_SOFTHANGUP_DEV
Definition channel.h:1141
int ast_softhangup_nolock(struct ast_channel *chan, int cause)
Softly hangup up a channel (no channel lock)
Definition channel.c:2449
struct ast_pbx * ast_channel_pbx(const struct ast_channel *chan)
int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block)
Sets an option on a channel.
Definition channel.c:7458
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition channel.c:1561
struct ast_cc_config_params * ast_channel_get_cc_config_params(struct ast_channel *chan)
Get the CCSS parameters from a channel.
Definition channel.c:10650
#define ast_channel_unlock(chan)
Definition channel.h:2984
#define AST_MAX_EXTENSION
Definition channel.h:134
ast_channel_state
ast_channel states
@ AST_STATE_RING
@ AST_STATE_DIALING_OFFHOOK
@ AST_STATE_RINGING
@ AST_STATE_PRERING
@ AST_STATE_DOWN
@ AST_STATE_OFFHOOK
@ AST_STATE_BUSY
@ AST_STATE_DIALING
@ AST_STATE_UP
@ AST_STATE_RESERVED
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition channel.c:7422
long int flag
Definition f2c.h:83
Call Parking and Pickup API Includes code and algorithms from the Zapata library.
Generic File Format Support. Should be included by clients of the file handling routines....
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition file.c:1320
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition file.c:1882
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_manager_publish_event(const char *type, int class_type, struct ast_json *obj)
Publish an event to AMI.
Definition manager.c:637
struct ast_features_pickup_config * ast_get_chan_features_pickup_config(struct ast_channel *chan)
Get the pickup configuration options for a channel.
#define AST_FRAME_DTMF
#define AST_OPTION_TONE_VERIFY
#define ast_frfree(fr)
#define AST_OPTION_TDD
@ AST_FRAME_DTMF_END
@ AST_FRAME_DTMF_BEGIN
@ AST_FRAME_CONTROL
@ AST_CONTROL_OFFHOOK
@ AST_CONTROL_PLAYBACK_BEGIN
@ AST_CONTROL_ANSWER
@ AST_CONTROL_RINGING
@ AST_CONTROL_FLASH
@ AST_CONTROL_PVT_CAUSE_CODE
struct ast_frame ast_null_frame
Definition main/frame.c:79
void ast_callid_threadstorage_auto_clean(ast_callid callid, int callid_created)
Use in conjunction with ast_callid_threadstorage_auto. Cleans up the references and if the callid was...
Definition logger.c:2367
#define ast_debug(level,...)
Log a DEBUG message.
int ast_callid_threadassoc_add(ast_callid callid)
Adds a known callid to thread storage of the calling thread.
Definition logger.c:2309
unsigned int ast_callid
int ast_callid_threadstorage_auto(ast_callid *callid)
Checks thread storage for a callid and stores a reference if it exists. If not, then a new one will b...
Definition logger.c:2345
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_NOTICE
#define LOG_WARNING
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition json.c:73
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition json.c:612
int errno
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
#define EVENT_FLAG_SYSTEM
Definition manager.h:75
Options provided by main asterisk program.
Call Parking API.
int ast_parking_blind_transfer_park(struct ast_bridge_channel *parker, const char *context, const char *exten, transfer_channel_cb parked_channel_cb, struct transfer_channel_data *parked_channel_data)
Perform a blind transfer to a parking extension.
Definition parking.c:143
int ast_parking_is_exten_park(const char *context, const char *exten)
Determine if the context/exten is a "parking" extension.
Definition parking.c:179
int ast_parking_provider_registered(void)
Check whether a parking provider is registered.
Definition parking.c:241
Core PBX routines and definitions.
enum ast_pbx_result ast_pbx_run(struct ast_channel *c)
Execute the PBX in the current thread.
Definition pbx.c:3315
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition pbx.c:2735
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks for a valid matching extension.
Definition pbx.c:2750
int ast_ignore_pattern(const char *context, const char *pattern)
Checks to see if a number should be ignored.
Definition pbx.c:5177
int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks to see if adding anything to this extension might match something. (exists ^ canmatch)
Definition pbx.c:2755
Call Pickup API.
int ast_pickup_call(struct ast_channel *chan)
Pickup a call.
Definition pickup.c:202
static struct stasis_subscription * sub
Statsd channel stats. Exmaple of how to subscribe to Stasis events.
#define NULL
Definition resample.c:96
Say numbers and dates (maybe words one day too)
int ast_say_digit_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang)
says digits of a string
Definition channel.c:8435
static const char * analog_get_orig_dialstring(struct analog_pvt *p)
Definition sig_analog.c:190
static void analog_set_callwaiting(struct analog_pvt *p, int callwaiting_enable)
Definition sig_analog.c:900
static void analog_publish_channel_alarm_clear(int channel)
static int analog_my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms)
static void analog_set_alarm(struct analog_pvt *p, int in_alarm)
Definition sig_analog.c:923
static int _analog_get_index(struct ast_channel *ast, struct analog_pvt *p, int nullok, const char *fname, unsigned long line)
Definition sig_analog.c:418
static int analog_stop_cid_detect(struct analog_pvt *p)
Definition sig_analog.c:174
static char analog_defaultozz[64]
Definition sig_analog.c:66
static int analog_alloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition sig_analog.c:372
int analog_hangup(struct analog_pvt *p, struct ast_channel *ast)
static int analog_send_callerid(struct analog_pvt *p, int cwcid, struct ast_party_caller *caller)
Definition sig_analog.c:395
static void analog_set_confirmanswer(struct analog_pvt *p, int flag)
Definition sig_analog.c:955
static int analog_update_conf(struct analog_pvt *p)
Definition sig_analog.c:753
static void analog_unlock_private(struct analog_pvt *p)
Definition sig_analog.c:570
static int analog_callwait(struct analog_pvt *p)
Definition sig_analog.c:891
static void analog_set_outgoing(struct analog_pvt *p, int is_outgoing)
Definition sig_analog.c:547
callwaiting_deluxe_option
@ CWD_DROP
@ CWD_FORWARD
@ CWD_HOLD
@ CWD_CONFERENCE
@ CWD_ANNOUNCEMENT
static int analog_dsp_reset_and_flush_digits(struct analog_pvt *p)
Definition sig_analog.c:438
static void analog_cb_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
Definition sig_analog.c:677
static void analog_increase_ss_count(void)
static int analog_unalloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition sig_analog.c:385
int analog_available(struct analog_pvt *p)
Definition sig_analog.c:803
static char analog_defaultcic[64]
Definition sig_analog.c:65
static void analog_publish_dnd_state(int channel, const char *status)
static int analog_is_off_hook(struct analog_pvt *p)
Definition sig_analog.c:499
static void * analog_get_bridged_channel(struct ast_channel *chan)
static int analog_dial_digits(struct analog_pvt *p, enum analog_sub sub, struct analog_dialoperation *dop)
Definition sig_analog.c:531
static int analog_handle_notify_message(struct ast_channel *chan, struct analog_pvt *p, int cid_flags, int neon_mwievent)
struct ast_frame * analog_exception(struct analog_pvt *p, struct ast_channel *ast)
#define gen_analog_field_callback(type, callback_name, def_value)
Definition sig_analog.c:223
static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
Definition sig_analog.c:456
static struct ast_frame * __analog_handle_event(struct analog_pvt *p, struct ast_channel *ast)
static struct ast_channel * analog_new_ast_channel(struct analog_pvt *p, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
Definition sig_analog.c:464
static int analog_canmatch_featurecode(const char *pickupexten, const char *exten)
static void * __analog_ss_thread(void *data)
static int analog_flash(struct analog_pvt *p)
Definition sig_analog.c:515
static int analog_attempt_transfer(struct analog_pvt *p)
Definition sig_analog.c:720
static void analog_set_needringing(struct analog_pvt *p, int value)
Definition sig_analog.c:633
static int analog_set_linear_mode(struct analog_pvt *p, enum analog_sub sub, int linear_mode)
Definition sig_analog.c:993
int analog_dnd(struct analog_pvt *p, int flag)
static const struct @146 sigtypes[]
static void analog_hangup_polarityswitch(struct analog_pvt *p)
Definition sig_analog.c:662
static int analog_check_waitingfordt(struct analog_pvt *p)
Definition sig_analog.c:946
static int analog_train_echocanceller(struct analog_pvt *p)
Definition sig_analog.c:491
static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
Definition sig_analog.c:915
int analog_callwaiting_deluxe(struct analog_pvt *p, int option)
int analog_config_complete(struct analog_pvt *p)
static int analog_ring(struct analog_pvt *p)
Definition sig_analog.c:507
static int analog_check_for_conference(struct analog_pvt *p)
Definition sig_analog.c:555
void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub idx, struct ast_frame **dest)
static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
Definition sig_analog.c:931
int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout)
void analog_delete(struct analog_pvt *doomed)
Delete the analog private structure.
static char * analog_event2str(enum analog_event event)
Definition sig_analog.c:269
static void analog_set_cadence(struct analog_pvt *p, struct ast_channel *chan)
Definition sig_analog.c:908
struct analog_pvt * analog_new(enum analog_sigtype signallingtype, void *private_data)
const char * analog_cidtype_to_str(unsigned int cid_type)
Definition sig_analog.c:153
static void analog_lock_sub_owner(struct analog_pvt *pvt, enum analog_sub sub_idx)
Definition sig_analog.c:609
static int analog_handles_digit(struct ast_frame *f)
void analog_free(struct analog_pvt *p)
static void analog_lock_private(struct analog_pvt *p)
Definition sig_analog.c:577
int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp)
static int analog_dsp_set_digitmode(struct analog_pvt *p, enum analog_dsp_digitmode mode)
Definition sig_analog.c:669
static int analog_have_progressdetect(struct analog_pvt *p)
Definition sig_analog.c:214
#define analog_get_index(ast, p, nullok)
Definition sig_analog.c:417
const char * name
Definition sig_analog.c:70
enum analog_sigtype sigtype
Definition sig_analog.c:69
static int analog_confmute(struct analog_pvt *p, int mute)
Definition sig_analog.c:978
static const struct @147 cidtypes[]
static void analog_answer_polarityswitch(struct analog_pvt *p)
Definition sig_analog.c:655
static int analog_on_hook(struct analog_pvt *p)
Definition sig_analog.c:539
static void analog_get_and_handle_alarms(struct analog_pvt *p)
static int analog_stop_callwait(struct analog_pvt *p)
Definition sig_analog.c:872
static void analog_set_pulsedial(struct analog_pvt *p, int flag)
Definition sig_analog.c:986
static int analog_start(struct analog_pvt *p)
Definition sig_analog.c:523
static int analog_has_voicemail(struct analog_pvt *p)
Definition sig_analog.c:692
static int analog_off_hook(struct analog_pvt *p)
Definition sig_analog.c:625
static void analog_decrease_ss_count(void)
unsigned int cid_type
Definition sig_analog.c:96
static int analog_wait_event(struct analog_pvt *p)
Definition sig_analog.c:206
#define ISTRUNK(p)
Whether a channel is FXS signaled.
Definition sig_analog.c:108
const char * analog_cidstart_to_str(enum analog_cid_start cid_start)
Definition sig_analog.c:253
static int analog_get_callerid(struct analog_pvt *p, char *name, char *number, enum analog_event *ev, size_t timeout)
Definition sig_analog.c:182
#define IS_FXO_SIG(p)
Whether a channel is FXO signaled.
Definition sig_analog.c:112
struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor)
Definition sig_analog.c:780
void * analog_handle_init_event(struct analog_pvt *i, int event)
static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
Definition sig_analog.c:448
#define MIN_MS_SINCE_FLASH
Definition sig_analog.c:64
static int analog_get_event(struct analog_pvt *p)
Definition sig_analog.c:198
unsigned int analog_str_to_cidtype(const char *name)
Definition sig_analog.c:140
static void analog_deadlock_avoidance_private(struct analog_pvt *p)
Definition sig_analog.c:584
static int analog_set_echocanceller(struct analog_pvt *p, int enable)
Definition sig_analog.c:483
static void analog_set_inthreeway(struct analog_pvt *p, enum analog_sub sub, int inthreeway)
#define POLARITY_IDLE
Definition sig_analog.c:62
int analog_answer(struct analog_pvt *p, struct ast_channel *ast)
static int analog_check_confirmanswer(struct analog_pvt *p)
Definition sig_analog.c:962
static int analog_wink(struct analog_pvt *p, enum analog_sub index)
Definition sig_analog.c:684
const char * analog_sigtype_to_str(enum analog_sigtype sigtype)
Definition sig_analog.c:127
static int analog_is_dialing(struct analog_pvt *p, enum analog_sub index)
Definition sig_analog.c:700
static void analog_cancel_cidspill(struct analog_pvt *p)
Definition sig_analog.c:971
static const char * callwaiting_deluxe_optname(int option)
static int analog_start_cid_detect(struct analog_pvt *p, int cid_signalling)
Definition sig_analog.c:166
static void analog_swap_subs(struct analog_pvt *p, enum analog_sub a, enum analog_sub b)
Definition sig_analog.c:352
static void analog_set_waitingfordt(struct analog_pvt *p, struct ast_channel *ast)
Definition sig_analog.c:939
static int analog_distinctive_ring(struct ast_channel *chan, struct analog_pvt *p, int idx, int *ringdata)
static void analog_all_subchannels_hungup(struct analog_pvt *p)
Definition sig_analog.c:563
#define POLARITY_REV
Definition sig_analog.c:63
enum analog_sigtype analog_str_to_sigtype(const char *name)
Definition sig_analog.c:114
int analog_ss_thread_start(struct analog_pvt *p, struct ast_channel *chan)
enum analog_cid_start analog_str_to_cidstart(const char *value)
Definition sig_analog.c:238
#define ANALOG_NEED_MFDETECT(p)
static int analog_get_sub_fd(struct analog_pvt *p, enum analog_sub sub)
static void analog_start_polarityswitch(struct analog_pvt *p)
Definition sig_analog.c:649
Interface header for analog signaling module.
#define ANALOG_MAX_CID
Definition sig_analog.h:33
analog_dsp_digitmode
Definition sig_analog.h:114
@ ANALOG_DIGITMODE_DTMF
Definition sig_analog.h:115
@ ANALOG_DIGITMODE_MF
Definition sig_analog.h:116
#define ANALOG_INTER_DIGIT_TIMEOUT
Default time (ms) to detect following digits.
Definition sig_analog.h:40
#define ANALOG_MATCH_DIGIT_TIMEOUT
Default time (ms) to wait, in case of ambiguous match.
Definition sig_analog.h:42
@ ANALOG_DIALMODE_PULSE
Definition sig_analog.h:121
@ ANALOG_DIALMODE_BOTH
Definition sig_analog.h:120
#define ANALOG_SMDI_MD_WAIT_TIMEOUT
Definition sig_analog.h:32
#define RING_PATTERNS
Definition sig_analog.h:35
analog_event
Definition sig_analog.h:79
@ ANALOG_EVENT_HOOKCOMPLETE
Definition sig_analog.h:89
@ ANALOG_EVENT_DTMFDOWN
Definition sig_analog.h:104
@ ANALOG_EVENT_RINGEROFF
Definition sig_analog.h:88
@ ANALOG_EVENT_PULSE_START
Definition sig_analog.h:90
@ ANALOG_EVENT_DTMFCID
Definition sig_analog.h:102
@ ANALOG_EVENT_TX_CED_DETECTED
Definition sig_analog.h:97
@ ANALOG_EVENT_NEONMWI_ACTIVE
Definition sig_analog.h:95
@ ANALOG_EVENT_RINGBEGIN
Definition sig_analog.h:92
@ ANALOG_EVENT_ONHOOK
Definition sig_analog.h:81
@ ANALOG_EVENT_EC_DISABLED
Definition sig_analog.h:93
@ ANALOG_EVENT_WINKFLASH
Definition sig_analog.h:83
@ ANALOG_EVENT_PULSEDIGIT
Definition sig_analog.h:103
@ ANALOG_EVENT_RINGERON
Definition sig_analog.h:87
@ ANALOG_EVENT_RX_CED_DETECTED
Definition sig_analog.h:98
@ ANALOG_EVENT_ALARM
Definition sig_analog.h:84
@ ANALOG_EVENT_DIALCOMPLETE
Definition sig_analog.h:86
@ ANALOG_EVENT_EC_NLP_ENABLED
Definition sig_analog.h:100
@ ANALOG_EVENT_POLARITY
Definition sig_analog.h:91
@ ANALOG_EVENT_NEONMWI_INACTIVE
Definition sig_analog.h:96
@ ANALOG_EVENT_DTMFUP
Definition sig_analog.h:105
@ ANALOG_EVENT_EC_NLP_DISABLED
Definition sig_analog.h:99
@ ANALOG_EVENT_RINGOFFHOOK
Definition sig_analog.h:82
@ ANALOG_EVENT_REMOVED
Definition sig_analog.h:94
@ ANALOG_EVENT_NOALARM
Definition sig_analog.h:85
@ ANALOG_DIAL_OP_REPLACE
Definition sig_analog.h:134
analog_sub
Definition sig_analog.h:108
@ ANALOG_SUB_THREEWAY
Definition sig_analog.h:111
@ ANALOG_SUB_REAL
Definition sig_analog.h:109
@ ANALOG_SUB_CALLWAIT
Definition sig_analog.h:110
#define ANALOG_FIRST_DIGIT_TIMEOUT
Default time (ms) to detect first digit.
Definition sig_analog.h:38
analog_sigtype
Definition sig_analog.h:45
@ ANALOG_SIG_FEATD
Definition sig_analog.h:56
@ ANALOG_SIG_FEATDMF_TA
Definition sig_analog.h:66
@ ANALOG_SIG_FGC_CAMAMF
Definition sig_analog.h:60
@ ANALOG_SIG_FXOLS
Definition sig_analog.h:47
@ ANALOG_SIG_FEATDMF
Definition sig_analog.h:57
@ ANALOG_SIG_EM_E1
Definition sig_analog.h:55
@ ANALOG_SIG_EMWINK
Definition sig_analog.h:53
@ ANALOG_SIG_FXOKS
Definition sig_analog.h:48
@ ANALOG_SIG_SF
Definition sig_analog.h:63
@ ANALOG_SIG_FGC_CAMA
Definition sig_analog.h:59
@ ANALOG_SIG_FXSLS
Definition sig_analog.h:50
@ ANALOG_SIG_EM
Definition sig_analog.h:54
@ ANALOG_SIG_FXOGS
Definition sig_analog.h:49
@ ANALOG_SIG_SF_FEATB
Definition sig_analog.h:67
@ ANALOG_SIG_NONE
Definition sig_analog.h:46
@ ANALOG_SIG_FXSGS
Definition sig_analog.h:52
@ ANALOG_SIG_SF_FEATDMF
Definition sig_analog.h:65
@ ANALOG_SIG_SFWINK
Definition sig_analog.h:62
@ ANALOG_SIG_E911
Definition sig_analog.h:58
@ ANALOG_SIG_FEATB
Definition sig_analog.h:61
@ ANALOG_SIG_SF_FEATD
Definition sig_analog.h:64
@ ANALOG_SIG_FXSKS
Definition sig_analog.h:51
analog_tone
Definition sig_analog.h:70
@ ANALOG_TONE_CONGESTION
Definition sig_analog.h:73
@ ANALOG_TONE_INFO
Definition sig_analog.h:76
@ ANALOG_TONE_DIALTONE
Definition sig_analog.h:74
@ ANALOG_TONE_DIALRECALL
Definition sig_analog.h:75
@ ANALOG_TONE_STUTTER
Definition sig_analog.h:72
@ ANALOG_TONE_RINGTONE
Definition sig_analog.h:71
analog_cid_start
Definition sig_analog.h:126
@ ANALOG_CID_START_RING
Definition sig_analog.h:129
@ ANALOG_CID_START_DTMF_NOALERT
Definition sig_analog.h:130
@ ANALOG_CID_START_POLARITY
Definition sig_analog.h:127
@ ANALOG_CID_START_POLARITY_IN
Definition sig_analog.h:128
struct ast_smdi_md_message *AST_OPTIONAL_API_NAME() ast_smdi_md_message_wait(struct ast_smdi_interface *iface, int timeout)
Get the next SMDI message from the queue.
Definition res_smdi.c:545
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition strings.h:80
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition utils.c:2233
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition strings.h:87
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition strings.h:659
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition strings.h:1113
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425
int(*const stop_cid_detect)(void *pvt)
Definition sig_analog.h:194
int(*const set_echocanceller)(void *pvt, int enable)
Definition sig_analog.h:184
void(*const deadlock_avoidance_private)(void *pvt)
Definition sig_analog.h:149
int(*const unallocate_sub)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:203
int(*const distinctive_ring)(struct ast_channel *chan, void *pvt, int idx, int *ringdata)
Definition sig_analog.h:230
int(*const stop_callwait)(void *pvt)
Definition sig_analog.h:199
void(*const set_confirmanswer)(void *pvt, int flag)
Definition sig_analog.h:244
void(*const set_callwaiting)(void *pvt, int callwaiting_enable)
Definition sig_analog.h:246
void(*const unlock_private)(void *pvt)
Definition sig_analog.h:145
int(*const check_confirmanswer)(void *pvt)
Definition sig_analog.h:245
const char *(*const get_orig_dialstring)(void *pvt)
Definition sig_analog.h:252
void(*const set_cadence)(void *pvt, int *cidrings, struct ast_channel *chan)
Definition sig_analog.h:237
int(*const have_progressdetect)(void *pvt)
Definition sig_analog.h:253
void(*const hangup_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch and hanguponpolarityswitch.
Definition sig_analog.h:176
int(*const is_off_hook)(void *pvt)
Definition sig_analog.h:158
void(*const decrease_ss_count)(void)
Definition sig_analog.h:228
int(*const is_dialing)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:159
int(*const train_echocanceller)(void *pvt)
Definition sig_analog.h:185
void(*const set_pulsedial)(void *pvt, int flag)
Definition sig_analog.h:249
int(*const check_waitingfordt)(void *pvt)
Definition sig_analog.h:243
int(*const get_callerid)(void *pvt, char *name, char *num, enum analog_event *ev, size_t timeout)
Definition sig_analog.h:190
int(*const conf_add)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:210
int(*const ring)(void *pvt)
Definition sig_analog.h:162
void(*const handle_dtmf)(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
Definition sig_analog.h:154
int(*const flash)(void *pvt)
Definition sig_analog.h:163
int(*const start_cid_detect)(void *pvt, int cid_signalling)
Definition sig_analog.h:192
void(*const swap_subs)(void *pvt, enum analog_sub a, struct ast_channel *new_a_owner, enum analog_sub b, struct ast_channel *new_b_owner)
Definition sig_analog.h:206
int(*const confmute)(void *pvt, int mute)
Definition sig_analog.h:248
void(*const handle_notify_message)(struct ast_channel *chan, void *pvt, int cid_flags, int neon_mwievent)
Definition sig_analog.h:224
int(*const set_linear_mode)(void *pvt, enum analog_sub sub, int linear_mode)
Definition sig_analog.h:232
int(*const complete_conference_update)(void *pvt, int needconf)
Definition sig_analog.h:216
void(*const set_outgoing)(void *pvt, int is_outgoing)
Definition sig_analog.h:240
int(*const on_hook)(void *pvt)
Set channel on hook.
Definition sig_analog.h:165
void(*const set_dialing)(void *pvt, int is_dialing)
Definition sig_analog.h:239
void(*const answer_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch=yes.
Definition sig_analog.h:174
int(*const dsp_set_digitmode)(void *pvt, enum analog_dsp_digitmode mode)
Definition sig_analog.h:186
void(*const set_alarm)(void *pvt, int in_alarm)
Definition sig_analog.h:238
void(*const set_new_owner)(void *pvt, struct ast_channel *new_owner)
Definition sig_analog.h:250
int(*const send_callerid)(void *pvt, int cwcid, struct ast_party_caller *caller)
Definition sig_analog.h:188
void(*const set_inthreeway)(void *pvt, enum analog_sub sub, int inthreeway)
Definition sig_analog.h:233
void(*const increase_ss_count)(void)
Definition sig_analog.h:227
void(*const cancel_cidspill)(void *pvt)
Definition sig_analog.h:247
int(*const dial_digits)(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop)
Definition sig_analog.h:180
int(*const conf_del)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:212
int(*const has_voicemail)(void *pvt)
Definition sig_analog.h:222
int(*const check_for_conference)(void *pvt)
Definition sig_analog.h:223
int(*const allocate_sub)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:202
int(*const wink)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:179
int(*const off_hook)(void *pvt)
Set channel off hook.
Definition sig_analog.h:167
int(*const dsp_reset_and_flush_digits)(void *pvt)
Definition sig_analog.h:187
void(*const set_ringtimeout)(void *pvt, int ringt)
Definition sig_analog.h:241
void(*const lock_private)(void *pvt)
Definition sig_analog.h:147
void(*const all_subchannels_hungup)(void *pvt)
Definition sig_analog.h:220
int(*const play_tone)(void *pvt, enum analog_sub sub, enum analog_tone tone)
Definition sig_analog.h:182
void(*const get_and_handle_alarms)(void *pvt)
Definition sig_analog.h:234
int(*const start)(void *pvt)
Definition sig_analog.h:161
int(*const callwait)(void *pvt)
Definition sig_analog.h:197
void(*const set_waitingfordt)(void *pvt, struct ast_channel *ast)
Definition sig_analog.h:242
void(*const start_polarityswitch)(void *pvt)
Reset FXS line polarity to IDLE, based on answeronpolarityswitch and hanguponpolarityswitch.
Definition sig_analog.h:172
struct ast_channel *(*const new_ast_channel)(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
Definition sig_analog.h:207
int(*const get_event)(void *pvt)
Definition sig_analog.h:156
void(*const set_needringing)(void *pvt, int value)
Definition sig_analog.h:168
void *(*const get_sigpvt_bridged_channel)(struct ast_channel *chan)
Definition sig_analog.h:235
void(*const set_polarity)(void *pvt, int value)
Set FXS line polarity to 0=IDLE NZ=REVERSED.
Definition sig_analog.h:170
int(*const get_sub_fd)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:236
int(*const wait_event)(void *pvt)
Definition sig_analog.h:157
char dialdest[256]
Definition sig_analog.h:372
unsigned int immediate
Definition sig_analog.h:298
unsigned int immediatering
Definition sig_analog.h:299
unsigned int threewaysilenthold
Definition sig_analog.h:307
unsigned int permcallwaiting
Definition sig_analog.h:301
unsigned int callwaitingdeluxepending
TRUE if a Call Waiting Deluxe action is currently pending.
Definition sig_analog.h:356
unsigned int canpark
Definition sig_analog.h:295
void * chan_pvt
Definition sig_analog.h:275
unsigned int dnd
Definition sig_analog.h:340
unsigned int dahditrcallerid
Definition sig_analog.h:296
struct analog_dialoperation dop
Definition sig_analog.h:280
char lastexten[AST_MAX_EXTENSION]
Definition sig_analog.h:364
int polarityonanswerdelay
Definition sig_analog.h:327
char cid_num[AST_MAX_EXTENSION]
Definition sig_analog.h:331
int redirecting_reason
Definition sig_analog.h:366
unsigned int permhidecallerid
Definition sig_analog.h:303
char * origcid_name
Definition sig_analog.h:378
struct timeval flashtime
Definition sig_analog.h:374
unsigned int outgoing
Definition sig_analog.h:343
unsigned int callwaitingcallerid
Definition sig_analog.h:312
char * origcid_num
Definition sig_analog.h:377
unsigned int ani_wink_time
Definition sig_analog.h:289
enum analog_sigtype outsigmod
Definition sig_analog.h:323
unsigned int usedistinctiveringdetection
Definition sig_analog.h:311
unsigned int answeronpolarityswitch
Definition sig_analog.h:291
unsigned int threewaycalling
Definition sig_analog.h:306
unsigned int pulse
Definition sig_analog.h:305
int echotraining
Definition sig_analog.h:325
char callwait_num[AST_MAX_EXTENSION]
Definition sig_analog.h:360
int msgstate
-1 = unknown, 0 = no messages, 1 = new messages available
Definition sig_analog.h:284
unsigned int callwaiting
Definition sig_analog.h:336
time_t guardtime
Definition sig_analog.h:373
struct timeval polaritydelaytv
Definition sig_analog.h:371
unsigned int hanguponpolarityswitch
Definition sig_analog.h:297
enum analog_dialmode permdialmode
Definition sig_analog.h:304
unsigned int callwaitingdeluxe
Definition sig_analog.h:302
char call_forward[AST_MAX_EXTENSION]
Definition sig_analog.h:379
enum analog_cid_start cid_start
Definition sig_analog.h:329
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
Definition sig_analog.h:351
unsigned int hidecallerid
Definition sig_analog.h:342
unsigned int echobreak
Definition sig_analog.h:341
unsigned int cshactive
Definition sig_analog.h:337
unsigned int callreturn
Definition sig_analog.h:293
struct ast_channel * owner
Definition sig_analog.h:277
unsigned int use_smdi
TRUE if SMDI (Simplified Message Desk Interface) is enabled.
Definition sig_analog.h:316
char lastcid_name[AST_MAX_EXTENSION]
Definition sig_analog.h:363
enum analog_sigtype sig
Definition sig_analog.h:273
unsigned int dialednone
Definition sig_analog.h:338
unsigned int call_qualifier
Definition sig_analog.h:358
char echorest[20]
Definition sig_analog.h:369
unsigned int ani_timeout
Definition sig_analog.h:288
unsigned int lastnumredial
Definition sig_analog.h:300
int fxsoffhookstate
Definition sig_analog.h:282
unsigned int ani_info_digits
Definition sig_analog.h:287
enum analog_dialmode dialmode
Definition sig_analog.h:324
unsigned int cancallforward
Definition sig_analog.h:294
char lastcid_num[AST_MAX_EXTENSION]
Definition sig_analog.h:362
struct analog_subchannel subs[3]
Definition sig_analog.h:279
int cid_signalling
Definition sig_analog.h:326
char finaldial[64]
Definition sig_analog.h:376
unsigned int transfer
Definition sig_analog.h:308
unsigned int transfertobusy
Definition sig_analog.h:309
unsigned int inalarm
Definition sig_analog.h:344
char cid_name[AST_MAX_EXTENSION]
Definition sig_analog.h:332
unsigned int calledsubscriberheld
Definition sig_analog.h:292
char mohsuggest[MAX_MUSICCLASS]
Definition sig_analog.h:330
unsigned int use_callerid
Definition sig_analog.h:310
struct ast_channel * ss_astchan
Definition sig_analog.h:382
unsigned int dialing
Definition sig_analog.h:339
char callwait_name[AST_MAX_EXTENSION]
Definition sig_analog.h:361
struct ast_smdi_interface * smdi_iface
The SMDI interface to get SMDI messages from.
Definition sig_analog.h:318
struct ast_party_caller caller
Definition sig_analog.h:365
unsigned int allocd
Definition sig_analog.h:268
struct ast_frame f
Definition sig_analog.h:265
unsigned int inthreeway
Definition sig_analog.h:266
struct ast_channel * owner
Definition sig_analog.h:264
Structure that contains information regarding a channel in a bridge.
struct ast_channel * chan
Main Channel structure associated with a channel.
ast_callid callid
char exten[AST_MAX_EXTENSION]
struct ast_flags flags
struct ast_party_caller caller
Channel Caller ID information.
Configuration relating to call pickup.
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
struct timeval delivery
enum ast_frame_type frametype
union ast_frame::@237 data
Abstract JSON element (object, array, string, int, ...).
Caller Party information.
Definition channel.h:420
struct ast_party_id id
Caller party ID.
Definition channel.h:422
int ani2
Automatic Number Identification 2 (Info Digits)
Definition channel.h:435
struct ast_party_id ani
Automatic Number Identification (ANI)
Definition channel.h:429
struct ast_party_id id
Connected party ID.
Definition channel.h:460
struct ast_party_name name
Subscriber name.
Definition channel.h:342
struct ast_party_number number
Subscriber phone number.
Definition channel.h:344
int presentation
Q.931 encoded presentation-indicator encoded field.
Definition channel.h:279
unsigned char valid
TRUE if the name information is valid/present.
Definition channel.h:281
char * str
Subscriber name (Malloced)
Definition channel.h:266
int presentation
Q.931 presentation-indicator and screening-indicator encoded fields.
Definition channel.h:297
unsigned char valid
TRUE if the number information is valid/present.
Definition channel.h:299
char * str
Subscriber phone number (Malloced)
Definition channel.h:293
int code
enum AST_REDIRECTING_REASON value for redirection
Definition channel.h:512
struct ast_party_redirecting_reason reason
Reason for the redirection.
Definition channel.h:544
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
Definition channel.h:529
An SMDI message desk message.
Definition smdi.h:65
char calling_st[SMDI_MAX_STATION_NUM_LEN+1]
Definition smdi.h:70
char fwd_st[SMDI_MAX_STATION_NUM_LEN+1]
Definition smdi.h:69
Support for dynamic strings.
Definition strings.h:623
Number structure.
int value
Definition syslog.c:37
static struct test_val b
static struct test_val a
static struct test_val c
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition utils.c:2315
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition time.h:159
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
Definition time.h:235
Utility functions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:981
#define ast_assert(a)
Definition utils.h:779
#define MIN(a, b)
Definition utils.h:252
#define ast_clear_flag(p, flag)
Definition utils.h:78
#define ast_pthread_create_detached(a, b, c, d)
Definition utils.h:628
#define ast_set_flag(p, flag)
Definition utils.h:71
#define ARRAY_LEN(a)
Definition utils.h:706