Asterisk - The Open Source Telephony Project GIT-master-77d630f
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#define ISTRUNK(p) ((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || \
108 (p->sig == ANALOG_SIG_FXSGS))
109
111{
112 int i;
113
114 for (i = 0; i < ARRAY_LEN(sigtypes); i++) {
115 if (!strcasecmp(sigtypes[i].name, name)) {
116 return sigtypes[i].sigtype;
117 }
118 }
119
120 return 0;
121}
122
124{
125 int i;
126
127 for (i = 0; i < ARRAY_LEN(sigtypes); i++) {
128 if (sigtype == sigtypes[i].sigtype) {
129 return sigtypes[i].name;
130 }
131 }
132
133 return "Unknown";
134}
135
136unsigned int analog_str_to_cidtype(const char *name)
137{
138 int i;
139
140 for (i = 0; i < ARRAY_LEN(cidtypes); i++) {
141 if (!strcasecmp(cidtypes[i].name, name)) {
142 return cidtypes[i].cid_type;
143 }
144 }
145
146 return 0;
147}
148
149const char *analog_cidtype_to_str(unsigned int cid_type)
150{
151 int i;
152
153 for (i = 0; i < ARRAY_LEN(cidtypes); i++) {
154 if (cid_type == cidtypes[i].cid_type) {
155 return cidtypes[i].name;
156 }
157 }
158
159 return "Unknown";
160}
161
162static int analog_start_cid_detect(struct analog_pvt *p, int cid_signalling)
163{
165 return analog_callbacks.start_cid_detect(p->chan_pvt, cid_signalling);
166 }
167 return -1;
168}
169
171{
174 }
175 return -1;
176}
177
178static int analog_get_callerid(struct analog_pvt *p, char *name, char *number, enum analog_event *ev, size_t timeout)
179{
181 return analog_callbacks.get_callerid(p->chan_pvt, name, number, ev, timeout);
182 }
183 return -1;
184}
185
186static const char *analog_get_orig_dialstring(struct analog_pvt *p)
187{
190 }
191 return "";
192}
193
194static int analog_get_event(struct analog_pvt *p)
195{
198 }
199 return -1;
200}
201
202static int analog_wait_event(struct analog_pvt *p)
203{
206 }
207 return -1;
208}
209
211{
214 }
215 /* Don't have progress detection. */
216 return 0;
217}
218
219#define gen_analog_field_callback(type, callback_name, def_value) \
220 static type analog_get_##callback_name(struct analog_pvt *p) \
221 { \
222 if (!analog_callbacks.get_##callback_name) { \
223 return def_value; \
224 } \
225 return analog_callbacks.get_##callback_name(p->chan_pvt); \
226 }
227
231
232#undef gen_analog_field_callback
233
235{
236 if (!strcasecmp(value, "ring")) {
238 } else if (!strcasecmp(value, "polarity")) {
240 } else if (!strcasecmp(value, "polarity_in")) {
242 } else if (!strcasecmp(value, "dtmf")) {
244 }
245
246 return 0;
247}
248
249const char *analog_cidstart_to_str(enum analog_cid_start cid_start)
250{
251 switch (cid_start) {
253 return "Ring";
255 return "Polarity";
257 return "Polarity_In";
259 return "DTMF";
260 }
261
262 return "Unknown";
263}
264
266{
267 char *res;
268 switch (event) {
270 res = "ANALOG_EVENT_ONHOOK";
271 break;
273 res = "ANALOG_EVENT_RINGOFFHOOK";
274 break;
276 res = "ANALOG_EVENT_WINKFLASH";
277 break;
279 res = "ANALOG_EVENT_ALARM";
280 break;
282 res = "ANALOG_EVENT_NOALARM";
283 break;
285 res = "ANALOG_EVENT_DIALCOMPLETE";
286 break;
288 res = "ANALOG_EVENT_HOOKCOMPLETE";
289 break;
291 res = "ANALOG_EVENT_PULSE_START";
292 break;
294 res = "ANALOG_EVENT_POLARITY";
295 break;
297 res = "ANALOG_EVENT_RINGBEGIN";
298 break;
300 res = "ANALOG_EVENT_EC_DISABLED";
301 break;
303 res = "ANALOG_EVENT_RINGERON";
304 break;
306 res = "ANALOG_EVENT_RINGEROFF";
307 break;
309 res = "ANALOG_EVENT_REMOVED";
310 break;
312 res = "ANALOG_EVENT_NEONMWI_ACTIVE";
313 break;
315 res = "ANALOG_EVENT_NEONMWI_INACTIVE";
316 break;
317#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
319 res = "ANALOG_EVENT_TX_CED_DETECTED";
320 break;
322 res = "ANALOG_EVENT_RX_CED_DETECTED";
323 break;
325 res = "ANALOG_EVENT_EC_NLP_DISABLED";
326 break;
328 res = "ANALOG_EVENT_EC_NLP_ENABLED";
329 break;
330#endif
332 res = "ANALOG_EVENT_PULSEDIGIT";
333 break;
335 res = "ANALOG_EVENT_DTMFDOWN";
336 break;
338 res = "ANALOG_EVENT_DTMFUP";
339 break;
340 default:
341 res = "UNKNOWN/OTHER";
342 break;
343 }
344
345 return res;
346}
347
348static void analog_swap_subs(struct analog_pvt *p, enum analog_sub a, enum analog_sub b)
349{
350 int tinthreeway;
351 struct ast_channel *towner;
352
353 ast_debug(1, "Swapping %u and %u\n", a, b);
354
355 towner = p->subs[a].owner;
356 p->subs[a].owner = p->subs[b].owner;
357 p->subs[b].owner = towner;
358
359 tinthreeway = p->subs[a].inthreeway;
360 p->subs[a].inthreeway = p->subs[b].inthreeway;
361 p->subs[b].inthreeway = tinthreeway;
362
365 }
366}
367
368static int analog_alloc_sub(struct analog_pvt *p, enum analog_sub x)
369{
371 int res;
373 if (!res) {
374 p->subs[x].allocd = 1;
375 }
376 return res;
377 }
378 return 0;
379}
380
381static int analog_unalloc_sub(struct analog_pvt *p, enum analog_sub x)
382{
383 p->subs[x].allocd = 0;
384 p->subs[x].owner = NULL;
387 }
388 return 0;
389}
390
391static int analog_send_callerid(struct analog_pvt *p, int cwcid, struct ast_party_caller *caller)
392{
393 /* If Caller ID is disabled for the line, that means we do not send ANY spill whatsoever. */
394 if (!p->use_callerid) {
395 ast_debug(1, "Caller ID is disabled for channel %d, skipping spill\n", p->channel);
396 return 0;
397 }
398
399 ast_debug(1, "Sending callerid. CID_NAME: '%s' CID_NUM: '%s'\n",
400 caller->id.name.str,
402
403 if (cwcid) {
404 p->callwaitcas = 0;
405 }
406
409 }
410 return 0;
411}
412
413#define analog_get_index(ast, p, nullok) _analog_get_index(ast, p, nullok, __PRETTY_FUNCTION__, __LINE__)
414static int _analog_get_index(struct ast_channel *ast, struct analog_pvt *p, int nullok, const char *fname, unsigned long line)
415{
416 int res;
417 if (p->subs[ANALOG_SUB_REAL].owner == ast) {
418 res = ANALOG_SUB_REAL;
419 } else if (p->subs[ANALOG_SUB_CALLWAIT].owner == ast) {
421 } else if (p->subs[ANALOG_SUB_THREEWAY].owner == ast) {
423 } else {
424 res = -1;
425 if (!nullok) {
427 "Unable to get index for '%s' on channel %d (%s(), line %lu)\n",
428 ast ? ast_channel_name(ast) : "", p->channel, fname, line);
429 }
430 }
431 return res;
432}
433
435{
438 }
439
440 /* Return 0 since I think this is unnecessary to do in most cases it is used. Mostly only for ast_dsp */
441 return 0;
442}
443
444static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
445{
447 return analog_callbacks.play_tone(p->chan_pvt, sub, tone);
448 }
449 return -1;
450}
451
452static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
453{
454 p->owner = new_owner;
457 }
458}
459
460static struct ast_channel * analog_new_ast_channel(struct analog_pvt *p, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
461{
462 struct ast_channel *c;
463
465 return NULL;
466 }
467
468 c = analog_callbacks.new_ast_channel(p->chan_pvt, state, startpbx, sub, requestor);
469 if (c) {
470 ast_channel_call_forward_set(c, p->call_forward);
471 }
472 p->subs[sub].owner = c;
473 if (!p->owner) {
475 }
476 return c;
477}
478
479static int analog_set_echocanceller(struct analog_pvt *p, int enable)
480{
483 }
484 return -1;
485}
486
488{
491 }
492 return -1;
493}
494
495static int analog_is_off_hook(struct analog_pvt *p)
496{
499 }
500 return -1;
501}
502
503static int analog_ring(struct analog_pvt *p)
504{
506 return analog_callbacks.ring(p->chan_pvt);
507 }
508 return -1;
509}
510
511static int analog_flash(struct analog_pvt *p)
512{
515 }
516 return -1;
517}
518
519static int analog_start(struct analog_pvt *p)
520{
523 }
524 return -1;
525}
526
527static int analog_dial_digits(struct analog_pvt *p, enum analog_sub sub, struct analog_dialoperation *dop)
528{
530 return analog_callbacks.dial_digits(p->chan_pvt, sub, dop);
531 }
532 return -1;
533}
534
535static int analog_on_hook(struct analog_pvt *p)
536{
539 }
540 return -1;
541}
542
543static void analog_set_outgoing(struct analog_pvt *p, int is_outgoing)
544{
545 p->outgoing = is_outgoing;
547 analog_callbacks.set_outgoing(p->chan_pvt, is_outgoing);
548 }
549}
550
552{
555 }
556 return -1;
557}
558
560{
563 }
564}
565
566static void analog_unlock_private(struct analog_pvt *p)
567{
570 }
571}
572
573static void analog_lock_private(struct analog_pvt *p)
574{
577 }
578}
579
581{
584 } else {
585 /* Fallback to manual avoidance if callback not present. */
587 usleep(1);
589 }
590}
591
592/*!
593 * \internal
594 * \brief Obtain the specified subchannel owner lock if the owner exists.
595 *
596 * \param pvt Analog private struct.
597 * \param sub_idx Subchannel owner to lock.
598 *
599 * \note Assumes the analog_lock_private(pvt->chan_pvt) is already obtained.
600 *
601 * \note
602 * Because deadlock avoidance may have been necessary, you need to confirm
603 * the state of things before continuing.
604 */
605static void analog_lock_sub_owner(struct analog_pvt *pvt, enum analog_sub sub_idx)
606{
607 for (;;) {
608 if (!pvt->subs[sub_idx].owner) {
609 /* No subchannel owner pointer */
610 break;
611 }
612 if (!ast_channel_trylock(pvt->subs[sub_idx].owner)) {
613 /* Got subchannel owner lock */
614 break;
615 }
616 /* We must unlock the private to avoid the possibility of a deadlock */
618 }
619}
620
621static int analog_off_hook(struct analog_pvt *p)
622{
625 }
626 return -1;
627}
628
629static void analog_set_needringing(struct analog_pvt *p, int value)
630{
633 }
634}
635
636#if 0
637static void analog_set_polarity(struct analog_pvt *p, int value)
638{
641 }
642}
643#endif
644
646{
649 }
650}
652{
655 }
656}
657
659{
662 }
663}
664
666{
669 }
670 return -1;
671}
672
673static void analog_cb_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
674{
676 analog_callbacks.handle_dtmf(p->chan_pvt, ast, analog_index, dest);
677 }
678}
679
680static int analog_wink(struct analog_pvt *p, enum analog_sub index)
681{
683 return analog_callbacks.wink(p->chan_pvt, index);
684 }
685 return -1;
686}
687
688static int analog_has_voicemail(struct analog_pvt *p)
689{
692 }
693 return -1;
694}
695
696static int analog_is_dialing(struct analog_pvt *p, enum analog_sub index)
697{
699 return analog_callbacks.is_dialing(p->chan_pvt, index);
700 }
701 return -1;
702}
703
704/*!
705 * \internal
706 * \brief Attempt to transfer 3-way call.
707 *
708 * \param p Analog private structure.
709 *
710 * \note On entry these locks are held: real-call, private, 3-way call.
711 * \note On exit these locks are held: real-call, private.
712 *
713 * \retval 0 on success.
714 * \retval -1 on error.
715 */
717{
718 struct ast_channel *owner_real;
719 struct ast_channel *owner_3way;
720 enum ast_transfer_result xfer_res;
721 int res = 0;
722
723 owner_real = ast_channel_ref(p->subs[ANALOG_SUB_REAL].owner);
725
726 ast_verb(3, "TRANSFERRING %s to %s\n",
727 ast_channel_name(owner_3way), ast_channel_name(owner_real));
728
729 ast_channel_unlock(owner_real);
730 ast_channel_unlock(owner_3way);
732
733 xfer_res = ast_bridge_transfer_attended(owner_3way, owner_real);
734 if (xfer_res != AST_BRIDGE_TRANSFER_SUCCESS) {
736 res = -1;
737 }
738
739 /* Must leave with these locked. */
740 ast_channel_lock(owner_real);
742
743 ast_channel_unref(owner_real);
744 ast_channel_unref(owner_3way);
745
746 return res;
747}
748
749static int analog_update_conf(struct analog_pvt *p)
750{
751 int x;
752 int needconf = 0;
753
754 /* Start with the obvious, general stuff */
755 for (x = 0; x < 3; x++) {
756 /* Look for three way calls */
757 if ((p->subs[x].allocd) && p->subs[x].inthreeway) {
760 }
761 needconf++;
762 } else {
765 }
766 }
767 }
768 ast_debug(1, "Updated conferencing on %d, with %d conference users\n", p->channel, needconf);
769
772 }
773 return 0;
774}
775
776struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor)
777{
778 struct ast_channel *ast;
779
780 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
781 *callwait = (p->owner != NULL);
782
783 if (p->owner) {
785 ast_log(LOG_ERROR, "Unable to alloc subchannel\n");
786 return NULL;
787 }
788 }
789
792 p->owner ? ANALOG_SUB_CALLWAIT : ANALOG_SUB_REAL, requestor);
793 if (!ast) {
795 }
796 return ast;
797}
798
800{
801 int offhook;
802
803 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
804
805 /* If do not disturb, definitely not */
806 if (p->dnd) {
807 return 0;
808 }
809 /* If guard time, definitely not */
810 if (p->guardtime && (time(NULL) < p->guardtime)) {
811 return 0;
812 }
813
814 /* If line is being held, definitely not (don't allow call waitings to an on-hook phone) */
815 if (p->cshactive) {
816 return 0;
817 }
818
819 /* If no owner definitely available */
820 if (!p->owner) {
821 offhook = analog_is_off_hook(p);
822
823 /* TDM FXO card, "onhook" means out of service (no battery on the line) */
824 if ((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || (p->sig == ANALOG_SIG_FXSGS)) {
825#ifdef DAHDI_CHECK_HOOKSTATE
826 if (offhook) {
827 return 1;
828 }
829 return 0;
830#endif
831 /* TDM FXS card, "offhook" means someone took the hook off so it's unavailable! */
832 } else if (offhook) {
833 ast_debug(1, "Channel %d off hook, can't use\n", p->channel);
834 /* Not available when the other end is off hook */
835 return 0;
836 }
837 return 1;
838 }
839
840 /* If it's not an FXO, forget about call wait */
841 if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) {
842 return 0;
843 }
844
845 if (!p->callwaiting) {
846 /* If they don't have call waiting enabled, then for sure they're unavailable at this point */
847 return 0;
848 }
849
851 /* If there is already a call waiting call, then we can't take a second one */
852 return 0;
853 }
854
855 if ((ast_channel_state(p->owner) != AST_STATE_UP) &&
857 /* If the current call is not up, then don't allow the call */
858 return 0;
859 }
861 /* Can't take a call wait when the three way calling hasn't been merged yet. */
862 return 0;
863 }
864 /* We're cool */
865 return 1;
866}
867
868static int analog_stop_callwait(struct analog_pvt *p)
869{
870 p->callwaitcas = 0;
871
872 /* There are 3 scenarios in which we need to reset the dialmode to permdialmode.
873 * 1) When placing a new outgoing call (either the first or a three-way)
874 * 2) When receiving a new incoming call
875 * 2A) If it's the first incoming call (not a call waiting), we reset
876 * in dahdi_hangup.
877 * 2B ) If it's a call waiting we've answered, either by swapping calls
878 * or having it ring through, we call analog_stop_callwait. That's this! */
879 p->dialmode = p->permdialmode;
880
883 }
884 return 0;
885}
886
887static int analog_callwait(struct analog_pvt *p)
888{
892 }
893 return 0;
894}
895
896static void analog_set_callwaiting(struct analog_pvt *p, int callwaiting_enable)
897{
898 p->callwaiting = callwaiting_enable;
900 analog_callbacks.set_callwaiting(p->chan_pvt, callwaiting_enable);
901 }
902}
903
904static void analog_set_cadence(struct analog_pvt *p, struct ast_channel *chan)
905{
908 }
909}
910
911static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
912{
913 p->dialing = is_dialing;
915 analog_callbacks.set_dialing(p->chan_pvt, is_dialing);
916 }
917}
918
919static void analog_set_alarm(struct analog_pvt *p, int in_alarm)
920{
921 p->inalarm = in_alarm;
923 analog_callbacks.set_alarm(p->chan_pvt, in_alarm);
924 }
925}
926
927static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
928{
929 p->ringt = ringt;
932 }
933}
934
935static void analog_set_waitingfordt(struct analog_pvt *p, struct ast_channel *ast)
936{
939 }
940}
941
943{
946 }
947
948 return 0;
949}
950
951static void analog_set_confirmanswer(struct analog_pvt *p, int flag)
952{
955 }
956}
957
959{
962 }
963
964 return 0;
965}
966
967static void analog_cancel_cidspill(struct analog_pvt *p)
968{
971 }
972}
973
974static int analog_confmute(struct analog_pvt *p, int mute)
975{
977 return analog_callbacks.confmute(p->chan_pvt, mute);
978 }
979 return 0;
980}
981
982static void analog_set_pulsedial(struct analog_pvt *p, int flag)
983{
986 }
987}
988
989static int analog_set_linear_mode(struct analog_pvt *p, enum analog_sub sub, int linear_mode)
990{
992 /* Return provides old linear_mode setting or error indication */
993 return analog_callbacks.set_linear_mode(p->chan_pvt, sub, linear_mode);
994 }
995 return -1;
996}
997
998static void analog_set_inthreeway(struct analog_pvt *p, enum analog_sub sub, int inthreeway)
999{
1000 p->subs[sub].inthreeway = inthreeway;
1003 }
1004}
1005
1006int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout)
1007{
1008 int res, idx, mysig;
1009 char *c, *n, *l;
1010 char dest[256]; /* must be same length as p->dialdest */
1011
1012 ast_debug(1, "CALLING CID_NAME: %s CID_NUM:: %s\n",
1013 S_COR(ast_channel_connected(ast)->id.name.valid, ast_channel_connected(ast)->id.name.str, ""),
1014 S_COR(ast_channel_connected(ast)->id.number.valid, ast_channel_connected(ast)->id.number.str, ""));
1015
1016 ast_copy_string(dest, rdest, sizeof(dest));
1017 ast_copy_string(p->dialdest, rdest, sizeof(p->dialdest));
1018
1019 if ((ast_channel_state(ast) == AST_STATE_BUSY)) {
1021 return 0;
1022 }
1023
1025 ast_log(LOG_WARNING, "analog_call called on %s, neither down nor reserved\n", ast_channel_name(ast));
1026 return -1;
1027 }
1028
1029 p->dialednone = 0;
1030 analog_set_outgoing(p, 1);
1031
1032 mysig = p->sig;
1033 if (p->outsigmod > -1) {
1034 mysig = p->outsigmod;
1035 }
1036
1037 switch (mysig) {
1038 case ANALOG_SIG_FXOLS:
1039 case ANALOG_SIG_FXOGS:
1040 case ANALOG_SIG_FXOKS:
1041 if (p->owner == ast) {
1042 /* Normal ring, on hook */
1043
1044 /* Don't send audio while on hook, until the call is answered */
1045 analog_set_dialing(p, 1);
1046 analog_set_cadence(p, ast); /* and set p->cidrings */
1047
1048 /* nick@dccinc.com 4/3/03 mods to allow for deferred dialing */
1049 c = strchr(dest, '/');
1050 if (c) {
1051 c++;
1052 }
1053 if (c && (strlen(c) < p->stripmsd)) {
1054 ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1055 c = NULL;
1056 }
1057 if (c && (strlen(c) > sizeof(p->dop.dialstr) - 3 /* "Tw\0" */)) {
1058 ast_log(LOG_WARNING, "Number '%s' is longer than %d bytes\n", c, (int)sizeof(p->dop.dialstr) - 2);
1059 c = NULL;
1060 }
1061 if (c) {
1063 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "Tw%s", c);
1064 ast_debug(1, "FXO: setup deferred dialstring: %s\n", c);
1065 } else {
1066 p->dop.dialstr[0] = '\0';
1067 }
1068
1069 if (analog_ring(p)) {
1070 ast_log(LOG_WARNING, "Unable to ring phone: %s\n", strerror(errno));
1071 return -1;
1072 }
1073 analog_set_dialing(p, 1);
1074 } else {
1075 /* Call waiting call */
1076 if (ast_channel_connected(ast)->id.number.valid && ast_channel_connected(ast)->id.number.str) {
1078 } else {
1079 p->callwait_num[0] = '\0';
1080 }
1081 if (ast_channel_connected(ast)->id.name.valid && ast_channel_connected(ast)->id.name.str) {
1083 } else {
1084 p->callwait_name[0] = '\0';
1085 }
1086
1087 /* Call waiting tone instead */
1088 if (analog_callwait(p)) {
1089 return -1;
1090 }
1091 /* Make ring-back */
1093 ast_log(LOG_WARNING, "Unable to generate call-wait ring-back on channel %s\n", ast_channel_name(ast));
1094 }
1095
1096 }
1097
1098 /* Name and Number */
1101 if (l) {
1102 ast_copy_string(p->lastcid_num, l, sizeof(p->lastcid_num));
1103 } else {
1104 p->lastcid_num[0] = '\0';
1105 }
1106 if (n) {
1107 ast_copy_string(p->lastcid_name, n, sizeof(p->lastcid_name));
1108 } else {
1109 p->lastcid_name[0] = '\0';
1110 }
1111
1112 if (p->use_callerid) {
1113 const char *qual_var;
1114
1115 /* Caller ID Name and Number */
1116 p->caller.id.name.str = p->lastcid_name;
1117 p->caller.id.number.str = p->lastcid_num;
1122
1123 /* Redirecting Reason */
1125
1126 /* Call Qualifier */
1127 ast_channel_lock(ast);
1128 /* XXX In the future, we may want to make this a CALLERID or CHANNEL property and fetch it from there. */
1129 qual_var = pbx_builtin_getvar_helper(ast, "CALL_QUALIFIER");
1130 p->call_qualifier = ast_true(qual_var) ? 1 : 0;
1131 ast_channel_unlock(ast);
1132 }
1133
1135 idx = analog_get_index(ast, p, 0);
1136 if (idx > -1) {
1137 struct ast_cc_config_params *cc_params;
1138
1139 /* This is where the initial ringing frame is queued for an analog call.
1140 * As such, this is a great time to offer CCNR to the caller if it's available.
1141 */
1142 cc_params = ast_channel_get_cc_config_params(p->subs[idx].owner);
1143 if (cc_params) {
1144 switch (ast_get_cc_monitor_policy(cc_params)) {
1146 break;
1152 break;
1153 }
1154 }
1156 }
1157 break;
1158 case ANALOG_SIG_FXSLS:
1159 case ANALOG_SIG_FXSGS:
1160 case ANALOG_SIG_FXSKS:
1162 ast_debug(1, "Ignore possible polarity reversal on line seizure\n");
1164 }
1165 /* fall through */
1166 case ANALOG_SIG_EMWINK:
1167 case ANALOG_SIG_EM:
1168 case ANALOG_SIG_EM_E1:
1169 case ANALOG_SIG_FEATD:
1170 case ANALOG_SIG_FEATDMF:
1171 case ANALOG_SIG_E911:
1174 case ANALOG_SIG_FEATB:
1175 case ANALOG_SIG_SFWINK:
1176 case ANALOG_SIG_SF:
1181 c = strchr(dest, '/');
1182 if (c) {
1183 c++;
1184 } else {
1185 c = "";
1186 }
1187 if (strlen(c) < p->stripmsd) {
1188 ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1189 return -1;
1190 }
1191 res = analog_start(p);
1192 if (res < 0) {
1193 if (errno != EINPROGRESS) {
1194 return -1;
1195 }
1196 }
1197 ast_debug(1, "Dialing '%s'\n", c);
1199
1200 c += p->stripmsd;
1201
1202 switch (mysig) {
1203 case ANALOG_SIG_FEATD:
1205 if (l) {
1206 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T*%s*%s*", l, c);
1207 } else {
1208 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T**%s*", c);
1209 }
1210 break;
1211 case ANALOG_SIG_FEATDMF:
1213 if (l) {
1214 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*00%s#*%s#", l, c);
1215 } else {
1216 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*02#*%s#", c);
1217 }
1218 break;
1220 {
1221 const char *cic = "", *ozz = "";
1222
1223 /* If you have to go through a Tandem Access point you need to use this */
1224#ifndef STANDALONE
1225 ozz = pbx_builtin_getvar_helper(p->owner, "FEATDMF_OZZ");
1226 if (!ozz) {
1227 ozz = analog_defaultozz;
1228 }
1229 cic = pbx_builtin_getvar_helper(p->owner, "FEATDMF_CIC");
1230 if (!cic) {
1231 cic = analog_defaultcic;
1232 }
1233#endif
1234 if (!ozz || !cic) {
1235 ast_log(LOG_WARNING, "Unable to dial channel of type feature group D MF tandem access without CIC or OZZ set\n");
1236 return -1;
1237 }
1238 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s%s#", ozz, cic);
1239 snprintf(p->finaldial, sizeof(p->finaldial), "M*%s#", c);
1240 p->whichwink = 0;
1241 }
1242 break;
1243 case ANALOG_SIG_E911:
1244 ast_copy_string(p->dop.dialstr, "M*911#", sizeof(p->dop.dialstr));
1245 break;
1247 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%s", c);
1248 break;
1250 case ANALOG_SIG_FEATB:
1251 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s#", c);
1252 break;
1253 default:
1254 if (p->pulse) {
1255 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%sw", c);
1256 } else {
1257 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T%sw", c);
1258 }
1259 break;
1260 }
1261
1262 if (p->echotraining && (strlen(p->dop.dialstr) > 4)) {
1263 memset(p->echorest, 'w', sizeof(p->echorest) - 1);
1264 strcpy(p->echorest + (p->echotraining / 400) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
1265 p->echorest[sizeof(p->echorest) - 1] = '\0';
1266 p->echobreak = 1;
1267 p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
1268 } else {
1269 p->echobreak = 0;
1270 }
1272 if (!res) {
1273 if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
1274 analog_on_hook(p);
1275 return -1;
1276 }
1277 } else {
1278 ast_debug(1, "Deferring dialing...\n");
1279 }
1280 analog_set_dialing(p, 1);
1281 if (ast_strlen_zero(c)) {
1282 p->dialednone = 1;
1283 }
1285 break;
1286 default:
1287 ast_debug(1, "not yet implemented\n");
1288 return -1;
1289 }
1290 return 0;
1291}
1292
1293int analog_hangup(struct analog_pvt *p, struct ast_channel *ast)
1294{
1295 int res;
1296 int idx, x;
1297
1298 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1299 if (!ast_channel_tech_pvt(ast)) {
1300 ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
1301 return 0;
1302 }
1303
1304 idx = analog_get_index(ast, p, 1);
1305
1306 x = 0;
1307 if (p->origcid_num) {
1308 ast_copy_string(p->cid_num, p->origcid_num, sizeof(p->cid_num));
1310 p->origcid_num = NULL;
1311 }
1312 if (p->origcid_name) {
1313 ast_copy_string(p->cid_name, p->origcid_name, sizeof(p->cid_name));
1315 p->origcid_name = NULL;
1316 }
1317
1319
1320 ast_debug(1, "Hangup: channel: %d index = %d, normal = %d, callwait = %d, thirdcall = %d\n",
1322 if (idx > -1) {
1323 /* Real channel, do some fixup */
1324 p->cshactive = 0;
1325 p->subs[idx].owner = NULL;
1327 analog_set_linear_mode(p, idx, 0);
1328 switch (idx) {
1329 case ANALOG_SUB_REAL:
1331 ast_debug(1, "Normal call hung up with both three way call and a call waiting call in place?\n");
1333 /* We had flipped over to answer a callwait and now it's gone */
1334 ast_debug(1, "We were flipped over to the callwait, moving back and not owning.\n");
1335 /* Move to the call-wait, but un-own us until they flip back. */
1339 } else {
1340 /* The three way hung up, but we still have a call wait */
1341 ast_debug(1, "We were in the threeway and have a callwait still. Ditching the threeway.\n");
1345 /* This was part of a three way call. Immediately make way for
1346 another call */
1347 ast_debug(1, "Call was complete, setting owner to former third call\n");
1350 } else {
1351 /* This call hasn't been completed yet... Set owner to NULL */
1352 ast_debug(1, "Call was incomplete, setting owner to NULL\n");
1354 }
1355 }
1356 } else if (p->subs[ANALOG_SUB_CALLWAIT].allocd) {
1357 /* Need to hold the lock for real-call, private, and call-waiting call */
1359 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
1360 /* The call waiting call disappeared. */
1362 break;
1363 }
1364
1365 /* Move to the call-wait and switch back to them. */
1371 }
1373 /* Unlock the call-waiting call that we swapped to real-call. */
1375 } else if (p->subs[ANALOG_SUB_THREEWAY].allocd) {
1379 /* This was part of a three way call. Immediately make way for
1380 another call */
1381 ast_debug(1, "Call was complete, setting owner to former third call\n");
1384 } else {
1385 /* This call hasn't been completed yet... Set owner to NULL */
1386 ast_debug(1, "Call was incomplete, setting owner to NULL\n");
1388 }
1389 }
1390 break;
1392 /* Ditch the holding callwait call, and immediately make it available */
1394 /* Need to hold the lock for call-waiting call, private, and 3-way call */
1396
1397 /* This is actually part of a three way, placed on hold. Place the third part
1398 on music on hold now */
1399 if (p->subs[ANALOG_SUB_THREEWAY].owner) {
1401 }
1403 /* Make it the call wait now */
1406 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1407 /* Unlock the 3-way call that we swapped to call-waiting call. */
1409 }
1410 } else {
1412 }
1413 break;
1415 /* Need to hold the lock for 3-way call, private, and call-waiting call */
1418 /* The other party of the three way call is currently in a call-wait state.
1419 Start music on hold for them, and take the main guy out of the third call */
1421 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1423 }
1424 }
1425 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1427 }
1429 /* If this was part of a three way call index, let us make
1430 another three way call */
1432 break;
1433 default:
1434 /*
1435 * Should never happen.
1436 * This wasn't any sort of call, so how are we an index?
1437 */
1438 ast_log(LOG_ERROR, "Index found but not any type of call?\n");
1439 break;
1440 }
1441 }
1442
1448 analog_set_outgoing(p, 0);
1449 p->onhooktime = time(NULL);
1450 p->cidrings = 1;
1451
1452 /* Perform low level hangup if no owner left */
1453 res = analog_on_hook(p);
1454 if (res < 0) {
1455 ast_log(LOG_WARNING, "Unable to hangup line %s\n", ast_channel_name(ast));
1456 }
1457 switch (p->sig) {
1458 case ANALOG_SIG_FXOGS:
1459 case ANALOG_SIG_FXOLS:
1460 case ANALOG_SIG_FXOKS:
1461 /* If they're off hook, try playing congestion */
1462 if (analog_is_off_hook(p)) {
1465 } else {
1467 }
1468 break;
1469 case ANALOG_SIG_FXSGS:
1470 case ANALOG_SIG_FXSLS:
1471 case ANALOG_SIG_FXSKS:
1472 /* Make sure we're not made available for at least two seconds assuming
1473 we were actually used for an inbound or outbound call. */
1475 time(&p->guardtime);
1476 p->guardtime += 2;
1477 }
1478 break;
1479 default:
1481 break;
1482 }
1483
1485
1486 x = 0;
1487 ast_channel_setoption(ast,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0);
1488 ast_channel_setoption(ast,AST_OPTION_TDD,&x,sizeof(char),0);
1489 p->callwaitcas = 0;
1491 /* In theory, the below is not necessary since we set hidecallerid = permhidecaller when calls start,
1492 * but this ensures the setting is defaulted properly when channels are idle, too. */
1494 analog_set_dialing(p, 0);
1497 }
1498
1500
1501 ast_verb(3, "Hanging up on '%s'\n", ast_channel_name(ast));
1502
1503 return 0;
1504}
1505
1506int analog_answer(struct analog_pvt *p, struct ast_channel *ast)
1507{
1508 int res = 0;
1509 int idx;
1510 int oldstate = ast_channel_state(ast);
1511
1512 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1514 idx = analog_get_index(ast, p, 1);
1515 if (idx < 0) {
1516 idx = ANALOG_SUB_REAL;
1517 }
1518 switch (p->sig) {
1519 case ANALOG_SIG_FXSLS:
1520 case ANALOG_SIG_FXSGS:
1521 case ANALOG_SIG_FXSKS:
1523 /* Fall through */
1524 case ANALOG_SIG_EM:
1525 case ANALOG_SIG_EM_E1:
1526 case ANALOG_SIG_EMWINK:
1527 case ANALOG_SIG_FEATD:
1528 case ANALOG_SIG_FEATDMF:
1530 case ANALOG_SIG_E911:
1533 case ANALOG_SIG_FEATB:
1534 case ANALOG_SIG_SF:
1535 case ANALOG_SIG_SFWINK:
1539 case ANALOG_SIG_FXOLS:
1540 case ANALOG_SIG_FXOGS:
1541 case ANALOG_SIG_FXOKS:
1542 /* Pick up the line */
1543 ast_debug(1, "Took %s off hook\n", ast_channel_name(ast));
1544 if (p->hanguponpolarityswitch) {
1545 gettimeofday(&p->polaritydelaytv, NULL);
1546 }
1547 res = analog_off_hook(p);
1548 analog_play_tone(p, idx, -1);
1549 analog_set_dialing(p, 0);
1550 if ((idx == ANALOG_SUB_REAL) && p->subs[ANALOG_SUB_THREEWAY].inthreeway) {
1551 if (oldstate == AST_STATE_RINGING) {
1552 ast_debug(1, "Finally swapping real and threeway\n");
1556 }
1557 }
1558
1559 switch (p->sig) {
1560 case ANALOG_SIG_FXSLS:
1561 case ANALOG_SIG_FXSKS:
1562 case ANALOG_SIG_FXSGS:
1565 break;
1566 case ANALOG_SIG_FXOLS:
1567 case ANALOG_SIG_FXOKS:
1568 case ANALOG_SIG_FXOGS:
1570 break;
1571 default:
1572 break;
1573 }
1574 break;
1575 default:
1576 ast_log(LOG_WARNING, "Don't know how to answer signalling %d (channel %d)\n", p->sig, p->channel);
1577 res = -1;
1578 break;
1579 }
1581 return res;
1582}
1583
1584static int analog_handles_digit(struct ast_frame *f)
1585{
1586 char subclass = toupper(f->subclass.integer);
1587
1588 switch (subclass) {
1589 case '1':
1590 case '2':
1591 case '3':
1592 case '4':
1593 case '5':
1594 case '6':
1595 case '7':
1596 case '9':
1597 case 'A':
1598 case 'B':
1599 case 'C':
1600 case 'D':
1601 case 'E':
1602 case 'F':
1603 return 1;
1604 default:
1605 return 0;
1606 }
1607}
1608
1615};
1616
1617static const char *callwaiting_deluxe_optname(int option)
1618{
1619 switch (option) {
1620 case CWD_CONFERENCE:
1621 return "CONFERENCE";
1622 case CWD_HOLD:
1623 return "HOLD";
1624 case CWD_DROP:
1625 return "DROP";
1626 case CWD_ANNOUNCEMENT:
1627 return "ANNOUNCEMENT";
1628 case CWD_FORWARD:
1629 return "FORWARD";
1630 default:
1631 return "DEFAULT";
1632 }
1633}
1634
1635int analog_callwaiting_deluxe(struct analog_pvt *p, int option)
1636{
1637 const char *announce_var;
1638 char announcement[PATH_MAX];
1639
1640 ast_debug(1, "Handling Call Waiting on channel %d with option %c: treatment %s\n", p->channel, option, callwaiting_deluxe_optname(option));
1641
1642 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
1643 /* This can happen if the caller hook flashes and the call waiting hangs up before the CWD timer expires (1 second) */
1644 ast_debug(1, "Call waiting call disappeared before it could be handled?\n");
1645 return -1;
1646 }
1647
1649 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
1650 ast_log(LOG_WARNING, "Whoa, the call-waiting call disappeared.\n");
1651 return -1;
1652 }
1653
1654 /* Note that when p->callwaitingdeluxepending, dahdi_write will drop incoming frames to the channel,
1655 * since the user shouldn't hear anything after flashing until either a DTMF has been received
1656 * or it's been a second and the decision is made automatically. */
1657
1658 switch (option) {
1659 case CWD_CONFERENCE:
1660 /* We should never have a call waiting if we have a 3-way anyways, but check just in case,
1661 * there better be no existing SUB_THREEWAY since we're going to make one (and then swap the call wait to it) */
1662 if (p->subs[ANALOG_SUB_THREEWAY].owner) {
1664 ast_log(LOG_ERROR, "Already have a 3-way call on channel %d, can't conference!\n", p->channel);
1665 return -1;
1666 }
1667
1668 /* To conference the incoming call, swap it from SUB_CALLWAIT to SUB_THREEWAY,
1669 * and then the existing 3-way logic will ensure that flashing again will drop the call waiting */
1673
1674 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));
1677
1681 /* Stop the ringing on the call wait channel (yeah, apparently this is how it's done) */
1684 }
1686
1687 ast_channel_unlock(p->subs[ANALOG_SUB_THREEWAY].owner); /* Unlock what was originally SUB_CALLWAIT */
1688 break;
1689 case CWD_HOLD: /* The CI-7112 Visual Director sends "HOLD" for "Play hold message" rather than "ANNOUNCEMENT". For default behavior, nothing is actually sent. */
1690 case CWD_ANNOUNCEMENT:
1691 /* We can't just call ast_streamfile here, this thread isn't responsible for media on the call waiting channel.
1692 * Indicate to the dialing channel in app_dial that it needs to play media.
1693 *
1694 * This is a lot easier than other ways of trying to send early media to the channel
1695 * (such as every call from the core to dahdi_read, sending the channel one frame of the audio file, etc.)
1696 */
1697
1698 /* There's not a particularly good stock audio prompt to use here. The Pat Fleet library has some better
1699 * ones but we want one that is also in the default Allison Smith library. "One moment please" works okay.
1700 * Check if a variable containing the prompt to use was specified on the call waiting channel, and
1701 * fall back to a reasonable default if not. */
1702
1703 /* The SUB_CALLWAIT channel is already locked here, no need to lock and unlock to get the variable. */
1704 announce_var = pbx_builtin_getvar_helper(p->subs[ANALOG_SUB_CALLWAIT].owner, "CALLWAITDELUXEANNOUNCEMENT");
1705 ast_copy_string(announcement, S_OR(announce_var, "one-moment-please"), sizeof(announcement));
1706 ast_debug(2, "Call Waiting Deluxe announcement for %s: %s\n", ast_channel_name(p->subs[ANALOG_SUB_CALLWAIT].owner), announcement);
1708 /* Tell app_dial what file to play. */
1709 ast_queue_control_data(p->subs[ANALOG_SUB_CALLWAIT].owner, AST_CONTROL_PLAYBACK_BEGIN, announcement, strlen(announcement) + 1);
1710 /* Unlike all the other options, the call waiting is still active with this option,
1711 * so we don't call analog_stop_callwait(p)
1712 * The call waiting will continue to be here, and at some later point the user can flash again and choose a finalizing option
1713 * (or even queue the announcement again... and again... and again...)
1714 */
1715 break;
1716 case CWD_FORWARD:
1717 /* Go away, call waiting, call again some other day... */
1719 /* Can't use p->call_forward exten because that's for *72 forwarding, and sig_analog doesn't
1720 * have a Busy/Don't Answer call forwarding exten internally, so let the dialplan deal with it.
1721 * by sending the call to the 'f' extension.
1722 */
1723 ast_channel_call_forward_set(p->subs[ANALOG_SUB_CALLWAIT].owner, "f");
1725 /* app_dial already has a verbose message for forwarding, so we don't really need one here also since that does the job */
1726 break;
1727 case CWD_DROP:
1728 /* Fall through: logic is identical to hold, except we drop the original call right after we swap. */
1729 default:
1730 /* Swap to call-wait, same as with the non-deluxe call waiting handling. */
1734 ast_debug(1, "Making %s the new owner\n", ast_channel_name(p->owner));
1738 }
1740
1741 if (option == CWD_DROP) {
1742 /* Disconnect the previous call (the original call is now the SUB_CALLWAIT since we swapped above) */
1744 ast_verb(3, "Dropping original call and swapping to call waiting on %s\n", ast_channel_name(p->subs[ANALOG_SUB_REAL].owner));
1745 } else {
1746 /* Start music on hold if appropriate */
1749 }
1750 ast_verb(3, "Holding original call and swapping to call waiting on %s\n", ast_channel_name(p->subs[ANALOG_SUB_REAL].owner));
1751 }
1752
1753 /* Stop ringing on the incoming call */
1756
1757 /* Unlock the call-waiting call that we swapped to real-call. */
1759 }
1761 return 0;
1762}
1763
1764void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub idx, struct ast_frame **dest)
1765{
1766 struct ast_frame *f = *dest;
1767
1768 ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n",
1769 f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End",
1770 (unsigned)f->subclass.integer, f->subclass.integer, ast_channel_name(ast));
1771
1773 if (f->frametype == AST_FRAME_DTMF_END) {
1774 ast_debug(1, "Confirm answer on %s!\n", ast_channel_name(ast));
1775 /* Upon receiving a DTMF digit, consider this an answer confirmation instead
1776 of a DTMF digit */
1779 /* Reset confirmanswer so DTMF's will behave properly for the duration of the call */
1781 } else {
1782 p->subs[idx].f.frametype = AST_FRAME_NULL;
1783 p->subs[idx].f.subclass.integer = 0;
1784 }
1785 *dest = &p->subs[idx].f;
1786 } else if (p->callwaitcas) {
1787 if (f->frametype == AST_FRAME_DTMF_END) {
1788 if ((f->subclass.integer == 'A') || (f->subclass.integer == 'D')) {
1789 ast_debug(1, "Got some DTMF, but it's for the CAS\n");
1790 p->caller.id.name.str = p->callwait_name;
1792 analog_send_callerid(p, 1, &p->caller);
1793 }
1794 if (analog_handles_digit(f)) {
1795 p->callwaitcas = 0;
1796 }
1797 }
1798 p->subs[idx].f.frametype = AST_FRAME_NULL;
1799 p->subs[idx].f.subclass.integer = 0;
1800 *dest = &p->subs[idx].f;
1801 } else if (p->callwaitingdeluxepending) {
1802 if (f->frametype == AST_FRAME_DTMF_END) {
1803 unsigned int mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
1805
1806 /* This is the case where a user explicitly took action (made a decision)
1807 * for Call Waiting Deluxe.
1808 * Because we already handled the hook flash, if the user doesn't do
1809 * anything within a second, then we still need to eventually take
1810 * the default action (swap) for the call waiting.
1811 *
1812 * dahdi_write will also drop audio if callwaitingdeluxepending is set HIGH,
1813 * and also check if flashtime hits 1000, in which case it will set the flag LOW and then take the
1814 * default action, e.g. analog_callwaiting_deluxe(p, 0);
1815 */
1816
1817 /* Slightly less than 1000, so there's no chance of a race condition
1818 * between do_monitor when it sees flashtime hitting 1000 and us. */
1819 if (mssinceflash > 990) {
1820 /* This was more than a second ago, clear the flag and process normally. */
1821 /* Because another thread has to monitor channels with pending CWDs,
1822 * in theory, we shouldn't need to check this here. */
1823 ast_debug(1, "It's been %u ms since the last flash, this is not a Call Waiting Deluxe DTMF\n", mssinceflash);
1824 analog_cb_handle_dtmf(p, ast, idx, dest);
1825 return;
1826 }
1827 /* Okay, actually do something now. */
1828 switch (f->subclass.integer) {
1829 case CWD_CONFERENCE:
1830 case CWD_HOLD:
1831 case CWD_DROP:
1832 case CWD_ANNOUNCEMENT:
1833 case CWD_FORWARD:
1834 ast_debug(1, "Got some DTMF, but it's for Call Waiting Deluxe: %c\n", f->subclass.integer);
1836 break;
1837 default:
1838 ast_log(LOG_WARNING, "Invalid Call Waiting Deluxe option (%c), using default\n", f->subclass.integer);
1840 }
1841 }
1842 p->subs[idx].f.frametype = AST_FRAME_NULL;
1843 p->subs[idx].f.subclass.integer = 0;
1844 *dest = &p->subs[idx].f;
1845 } else {
1846 analog_cb_handle_dtmf(p, ast, idx, dest);
1847 }
1848}
1849
1850static int analog_my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms)
1851{
1852 char c;
1853
1854 *str = 0; /* start with empty output buffer */
1855 for (;;) {
1856 /* Wait for the first digit (up to specified ms). */
1857 c = ast_waitfordigit(chan, ms);
1858 /* if timeout, hangup or error, return as such */
1859 if (c < 1) {
1860 return c;
1861 }
1862 *str++ = c;
1863 *str = 0;
1864 if (strchr(term, c)) {
1865 return 1;
1866 }
1867 }
1868}
1869
1870static int analog_handle_notify_message(struct ast_channel *chan, struct analog_pvt *p, int cid_flags, int neon_mwievent)
1871{
1873 analog_callbacks.handle_notify_message(chan, p->chan_pvt, cid_flags, neon_mwievent);
1874 return 0;
1875 }
1876 return -1;
1877}
1878
1880{
1883 }
1884}
1885
1887{
1890 }
1891}
1892
1893static int analog_distinctive_ring(struct ast_channel *chan, struct analog_pvt *p, int idx, int *ringdata)
1894{
1896 return 0;
1897 }
1899 return analog_callbacks.distinctive_ring(chan, p->chan_pvt, idx, ringdata);
1900 }
1901 return -1;
1902
1903}
1904
1906{
1909 }
1910}
1911
1912static void *analog_get_bridged_channel(struct ast_channel *chan)
1913{
1916 }
1917 return NULL;
1918}
1919
1920static int analog_get_sub_fd(struct analog_pvt *p, enum analog_sub sub)
1921{
1924 }
1925 return -1;
1926}
1927
1928#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))
1929
1930static int analog_canmatch_featurecode(const char *pickupexten, const char *exten)
1931{
1932 int extlen = strlen(exten);
1933 if (!extlen) {
1934 return 1;
1935 }
1936 if (extlen < strlen(pickupexten) && !strncmp(pickupexten, exten, extlen)) {
1937 return 1;
1938 }
1939 if (exten[0] == '#' && extlen < 2) {
1940 return 1; /* Could match ## */
1941 }
1942 /* hardcoded features are *60, *67, *69, *70, *72, *73, *78, *79, *82, *0 */
1943 if (exten[0] == '*' && extlen < 3) {
1944 if (extlen == 1) {
1945 return 1;
1946 }
1947 /* "*0" should be processed before it gets here */
1948 switch (exten[1]) {
1949 case '6':
1950 case '7':
1951 case '8':
1952 return 1;
1953 }
1954 }
1955 return 0;
1956}
1957
1958static void *__analog_ss_thread(void *data)
1959{
1960 struct analog_pvt *p = data;
1961 struct ast_channel *chan = p->ss_astchan;
1962 char exten[AST_MAX_EXTENSION] = "";
1963 char exten2[AST_MAX_EXTENSION] = "";
1964 char dtmfcid[300];
1965 char dtmfbuf[300];
1966 char namebuf[ANALOG_MAX_CID];
1967 char numbuf[ANALOG_MAX_CID];
1968 char *name = NULL, *number = NULL;
1969 int flags = 0;
1970 struct ast_smdi_md_message *smdi_msg = NULL;
1971 int timeout;
1972 int getforward = 0;
1973 char *s1, *s2;
1974 int len = 0;
1975 int res;
1976 int idx;
1977 ast_callid callid;
1978 RAII_VAR(struct ast_features_pickup_config *, pickup_cfg, NULL, ao2_cleanup);
1979 const char *pickupexten;
1980
1982
1983 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1984
1985 ast_assert(chan != NULL);
1986
1987 if ((callid = ast_channel_callid(chan))) {
1989 }
1990
1991 /* in the bizarre case where the channel has become a zombie before we
1992 even get started here, abort safely
1993 */
1994 if (!ast_channel_tech_pvt(chan)) {
1995 ast_log(LOG_WARNING, "Channel became a zombie before simple switch could be started (%s)\n", ast_channel_name(chan));
1996 ast_hangup(chan);
1997 goto quit;
1998 }
1999
2000 ast_verb(3, "Starting simple switch on '%s'\n", ast_channel_name(chan));
2001 idx = analog_get_index(chan, p, 0);
2002 if (idx < 0) {
2003 ast_hangup(chan);
2004 goto quit;
2005 }
2006
2007 ast_channel_lock(chan);
2008 pickup_cfg = ast_get_chan_features_pickup_config(chan);
2009 if (!pickup_cfg) {
2010 ast_log(LOG_ERROR, "Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n");
2011 pickupexten = "";
2012 } else {
2013 pickupexten = ast_strdupa(pickup_cfg->pickupexten);
2014 }
2015 ast_channel_unlock(chan);
2016
2018 switch (p->sig) {
2019 case ANALOG_SIG_FEATD:
2020 case ANALOG_SIG_FEATDMF:
2022 case ANALOG_SIG_E911:
2024 case ANALOG_SIG_FEATB:
2025 case ANALOG_SIG_EMWINK:
2029 case ANALOG_SIG_SFWINK:
2030 if (analog_wink(p, idx))
2031 goto quit;
2032 /* Fall through */
2033 case ANALOG_SIG_EM:
2034 case ANALOG_SIG_EM_E1:
2035 case ANALOG_SIG_SF:
2037 res = analog_play_tone(p, idx, -1);
2038
2040
2041 /* set digit mode appropriately */
2042 if (ANALOG_NEED_MFDETECT(p)) {
2044 } else {
2046 }
2047
2048 memset(dtmfbuf, 0, sizeof(dtmfbuf));
2049 /* Wait for the first digit only if immediate=no */
2050 if (!p->immediate) {
2051 /* Wait for the first digit (up to 5 seconds). */
2052 res = ast_waitfordigit(chan, 5000);
2053 } else {
2054 res = 0;
2055 }
2056 if (res > 0) {
2057 /* save first char */
2058 dtmfbuf[0] = res;
2059 switch (p->sig) {
2060 case ANALOG_SIG_FEATD:
2062 res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
2063 if (res > 0) {
2064 res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
2065 }
2066 if (res < 1) {
2068 }
2069 break;
2071 res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
2072 if (res < 1) {
2074 }
2075 if (analog_wink(p, idx)) {
2076 goto quit;
2077 }
2078 dtmfbuf[0] = 0;
2079 /* Wait for the first digit (up to 5 seconds). */
2080 res = ast_waitfordigit(chan, 5000);
2081 if (res <= 0) {
2082 break;
2083 }
2084 dtmfbuf[0] = res;
2085 /* fall through intentionally */
2086 case ANALOG_SIG_FEATDMF:
2087 case ANALOG_SIG_E911:
2090 res = analog_my_getsigstr(chan, dtmfbuf + 1, "#ABC", 3000);
2091 /* if international CAC, do it again to get real ANI */
2092 if ((p->sig == ANALOG_SIG_FEATDMF) && (dtmfbuf[1] != '0')
2093 && (strlen(dtmfbuf) != 14)) {
2094 if (analog_wink(p, idx)) {
2095 goto quit;
2096 }
2097 dtmfbuf[0] = 0;
2098 /* Wait for the first digit (up to 5 seconds). */
2099 res = ast_waitfordigit(chan, 5000);
2100 if (res <= 0) {
2101 break;
2102 }
2103 dtmfbuf[0] = res;
2104 res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
2105 }
2106 if (res > 0) {
2107 /* if E911, take off hook */
2108 if (p->sig == ANALOG_SIG_E911) {
2109 analog_off_hook(p);
2110 }
2111 if (p->sig != ANALOG_SIG_FGC_CAMAMF) {
2112 /* CAMA signaling (CAMA and CAMAMF) are handled in an if block below.
2113 * Everything else, process here. */
2114 res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "#", 3000);
2115 }
2116 }
2117 if (res < 1) {
2119 }
2120 break;
2121 case ANALOG_SIG_FEATB:
2123 res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
2124 if (res < 1) {
2126 }
2127 break;
2128 case ANALOG_SIG_EMWINK:
2129 /* if we received a '*', we are actually receiving Feature Group D
2130 dial syntax, so use that mode; otherwise, fall through to normal
2131 mode
2132 */
2133 if (res == '*') {
2134 res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
2135 if (res > 0) {
2136 res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
2137 }
2138 if (res < 1) {
2140 }
2141 break;
2142 }
2143 default:
2144 /* If we got the first digit, get the rest */
2145 len = 1;
2146 dtmfbuf[len] = '\0';
2147 while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
2148 if (ast_exists_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
2149 timeout = analog_get_matchdigit_timeout(p);
2150 } else {
2151 timeout = analog_get_interdigit_timeout(p);
2152 }
2153 res = ast_waitfordigit(chan, timeout);
2154 if (res < 0) {
2155 ast_debug(1, "waitfordigit returned < 0...\n");
2156 ast_hangup(chan);
2157 goto quit;
2158 } else if (res) {
2159 dtmfbuf[len++] = res;
2160 dtmfbuf[len] = '\0';
2161 } else {
2162 break;
2163 }
2164 }
2165 break;
2166 }
2167 }
2168 if (res == -1) {
2169 ast_log(LOG_WARNING, "getdtmf on channel %d: %s\n", p->channel, strerror(errno));
2170 ast_hangup(chan);
2171 goto quit;
2172 } else if (res < 0) {
2173 ast_debug(1, "Got hung up before digits finished\n");
2174 ast_hangup(chan);
2175 goto quit;
2176 }
2177
2178 if (p->sig == ANALOG_SIG_FGC_CAMA || p->sig == ANALOG_SIG_FGC_CAMAMF) {
2179 /* This if block is where we process ANI for CAMA */
2180
2181 char anibuf[100];
2182 struct ast_party_caller *caller;
2183
2184 /* cnoffset is the point at which we pull the calling number out
2185 * of anibuf. Must be the number of ani_info_digits + 1 to account
2186 * for the KP, which is considered a digit. */
2187
2188 /* The 1XB with ANI-B will send a full 10 digits
2189 * or 2 digits in case of ANI failure.
2190 * (CD-95811-01 Section II, page 10)
2191 * 10 digit string example: *08320123#
2192 * 2 digit string example: *2
2193 * KP (*) and ST (#) are considered to be digits */
2194
2195 int cnoffset = p->ani_info_digits + 1;
2196
2197 /* This is how long to wait before the wink to start ANI spill
2198 * Pulled from chan_dahdi.conf, default is 1000ms */
2199 if (ast_safe_sleep(chan,p->ani_wink_time) == -1) {
2200 ast_hangup(chan);
2201 goto quit;
2202 }
2203 analog_off_hook(p);
2204 ast_debug(1, "Went off-hook to signal ANI start\n");
2206
2207 /* ani_timeout is configured in chan_dahdi.conf. default is 10000ms.
2208 * ST, STP, ST2P, ST3P can all signal transmission complete, regardless of timeout */
2209 res = analog_my_getsigstr(chan, anibuf, "#ABC", p->ani_timeout);
2210
2211 /* so we can work with the ani buffer */
2212 pbx_builtin_setvar_helper(chan, "ANIBUF", anibuf);
2213
2214 /* as long as we get a terminating pulse OR the length of ANI buffer is at least >=2, we can treat
2215 * this as a complete spill for the purposes of setting anistart */
2216 if ((res > 0) || (strlen(anibuf) >= 2)) {
2217 char anistart[2] = "X";
2218 char f[101] = {0};
2219 if (strchr("#ABC", anibuf[strlen(anibuf) - 1])) {
2220 anistart[0] = anibuf[strlen(anibuf) - 1];
2221 anibuf[strlen(anibuf) - 1] = 0;
2222 }
2223 ast_set_callerid(chan, anibuf + cnoffset, NULL, anibuf + cnoffset);
2224
2225 caller = ast_channel_caller(chan);
2226 strncpy(f, &(anibuf[1]), MIN((int)(p->ani_info_digits), sizeof(f)-1));
2227 caller->ani2 = atoi(f);
2228
2229 anibuf[cnoffset] = 0;
2230
2231 /* so we can work with the different start pulses as used in ANI-D */
2232 pbx_builtin_setvar_helper(chan, "ANISTART", anistart);
2233 /* so we can use our ANI INFO digits in our dialplan */
2234 pbx_builtin_setvar_helper(chan, "ANI2", anibuf + 1);
2235 }
2237 }
2238
2239 ast_copy_string(exten, dtmfbuf, sizeof(exten));
2240 if (ast_strlen_zero(exten)) {
2241 ast_copy_string(exten, "s", sizeof(exten));
2242 }
2243 if (p->sig == ANALOG_SIG_FEATD || p->sig == ANALOG_SIG_EMWINK) {
2244 /* Look for Feature Group D on all E&M Wink and Feature Group D trunks */
2245 if (exten[0] == '*') {
2246 char *stringp=NULL;
2247 ast_copy_string(exten2, exten, sizeof(exten2));
2248 /* Parse out extension and callerid */
2249 stringp=exten2 +1;
2250 s1 = strsep(&stringp, "*");
2251 s2 = strsep(&stringp, "*");
2252 if (s2) {
2253 if (!ast_strlen_zero(p->cid_num)) {
2254 ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
2255 } else {
2256 ast_set_callerid(chan, s1, NULL, s1);
2257 }
2258 ast_copy_string(exten, s2, sizeof(exten));
2259 } else {
2260 ast_copy_string(exten, s1, sizeof(exten));
2261 }
2262 } else if (p->sig == ANALOG_SIG_FEATD) {
2263 ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
2264 }
2265 }
2266 if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
2267 if (exten[0] == '*') {
2268 char *stringp=NULL;
2269 struct ast_party_caller *caller;
2270
2271 ast_copy_string(exten2, exten, sizeof(exten2));
2272 /* Parse out extension and callerid */
2273 stringp=exten2 +1;
2274 s1 = strsep(&stringp, "#");
2275 s2 = strsep(&stringp, "#");
2276 if (s2) {
2277 if (!ast_strlen_zero(p->cid_num)) {
2278 ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
2279 } else {
2280 if (*(s1 + 2)) {
2281 ast_set_callerid(chan, s1 + 2, NULL, s1 + 2);
2282 }
2283 }
2284 ast_copy_string(exten, s2 + 1, sizeof(exten));
2285 } else {
2286 ast_copy_string(exten, s1 + 2, sizeof(exten));
2287 }
2288
2289 /* The first two digits are ani2 information. */
2290 caller = ast_channel_caller(chan);
2291 s1[2] = '\0';
2292 caller->ani2 = atoi(s1);
2293 } else {
2294 ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
2295 }
2296 }
2297 if ((p->sig == ANALOG_SIG_E911) || (p->sig == ANALOG_SIG_FGC_CAMAMF)) {
2298 if (exten[0] == '*') {
2299 char *stringp=NULL;
2300 ast_copy_string(exten2, exten, sizeof(exten2));
2301 /* Parse out extension and callerid */
2302 stringp=exten2 +1;
2303 s1 = strsep(&stringp, "#ABC");
2304 s2 = strsep(&stringp, "#ABC");
2305 if (s2 && (*(s2 + 1) == '0')) {
2306 if (*(s2 + 2)) {
2307 ast_set_callerid(chan, s2 + 2, NULL, s2 + 2);
2308 }
2309 }
2310 if (s1) {
2311 ast_copy_string(exten, s1, sizeof(exten));
2312 } else {
2313 ast_copy_string(exten, "911", sizeof(exten));
2314 }
2315 } else {
2316 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);
2317 }
2318 }
2319 if (p->sig == ANALOG_SIG_FEATB) {
2320 if (exten[0] == '*') {
2321 char *stringp=NULL;
2322 ast_copy_string(exten2, exten, sizeof(exten2));
2323 /* Parse out extension and callerid */
2324 stringp=exten2 +1;
2325 s1 = strsep(&stringp, "#");
2326 ast_copy_string(exten, exten2 + 1, sizeof(exten));
2327 } else {
2328 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);
2329 }
2330 }
2331 if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
2332 analog_wink(p, idx);
2333 /*
2334 * Some switches require a minimum guard time between the last
2335 * FGD wink and something that answers immediately. This
2336 * ensures it.
2337 */
2338 if (ast_safe_sleep(chan, 100)) {
2339 ast_hangup(chan);
2340 goto quit;
2341 }
2342 }
2344
2346
2347 if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1,
2348 ast_channel_caller(chan)->id.number.valid ? ast_channel_caller(chan)->id.number.str : NULL)) {
2349 ast_channel_exten_set(chan, exten);
2351 res = ast_pbx_run(chan);
2352 if (res) {
2353 ast_log(LOG_WARNING, "PBX exited non-zero\n");
2355 }
2356 goto quit;
2357 } else {
2358 ast_verb(3, "Unknown extension '%s' in context '%s' requested\n", exten, ast_channel_context(chan));
2359 sleep(2);
2360 res = analog_play_tone(p, idx, ANALOG_TONE_INFO);
2361 if (res < 0) {
2362 ast_log(LOG_WARNING, "Unable to start special tone on %d\n", p->channel);
2363 } else {
2364 sleep(1);
2365 }
2366 res = ast_streamfile(chan, "ss-noservice", ast_channel_language(chan));
2367 if (res >= 0) {
2368 ast_waitstream(chan, "");
2369 }
2371 ast_hangup(chan);
2372 goto quit;
2373 }
2374 break;
2375 case ANALOG_SIG_FXOLS:
2376 case ANALOG_SIG_FXOGS:
2377 case ANALOG_SIG_FXOKS:
2378 /* Set our default presentation.
2379 * This is necessary because the presentation for each call is independent
2380 * (though the default may be the same).
2381 * For example, if hidecallerid=yes and somebody makes a call with *82,
2382 * then makes a 3-way call, the presentation for the 2nd call should still
2383 * be blocked, unless that also had a *82.
2384 * For this reason, setting hidecallerid = permhidecallerid on hangup
2385 * is NOT sufficient, as the *82 from the first call could "leak" into
2386 * subsequent ones made before a hangup, improperly leaking a number
2387 * that should have been hidden.
2388 */
2390
2391 /* Set the default dial mode.
2392 * As with Caller ID, this is independent for each call,
2393 * and changes made using the CHANNEL function are only temporary.
2394 * This reset ensures temporary changes are discarded when a new call is originated.
2395 *
2396 * XXX There is a slight edge case in that because the dialmode is reset to permdialmode,
2397 * assuming permdialmode=both, if a user disables dtmf during call 1, then flashes and
2398 * starts call 2, this will set dialmode back to permcallmode on the private,
2399 * allowing tone dialing to (correctly) work on call 2.
2400 * If the user flashes back to call 1, however, tone dialing will again work on call 1.
2401 *
2402 * This problem does not exist with the other settings that involve a "permanent"
2403 * and "transient" settings (e.g. hidecallerid, callwaiting), because hidecallerid
2404 * only matters when originating a call, so as soon as it's been placed, it doesn't
2405 * matter if it gets reset. For callwaiting, the setting is supposed to be common
2406 * to the entire channel private (all subchannels), which is NOT the case with this setting.
2407 *
2408 * The correct and probably only fix for this edge case is to move dialmode out of the channel private
2409 * (which is shared by all subchannels), and into the Asterisk channel structure. Just using an array for
2410 * each chan_dahdi subchannel won't work because the indices change as calls flip around.
2411 */
2412 p->dialmode = p->permdialmode;
2413
2414 /* Read the first digit */
2415 timeout = analog_get_firstdigit_timeout(p);
2416 /* If starting a threeway call, never timeout on the first digit so someone
2417 * can use flash-hook as a "hold" feature...
2418 * ...Unless three-way dial tone should time out to silence, in which case the default suffices. */
2420 timeout = INT_MAX;
2421 }
2422 while (len < AST_MAX_EXTENSION-1) {
2423 int is_exten_parking = 0;
2424
2425 /* Read digit unless it's supposed to be immediate, in which case the
2426 only answer is 's' */
2427 if (p->immediate) {
2428 res = 's';
2429 } else {
2430 res = ast_waitfordigit(chan, timeout);
2431 }
2432 timeout = 0;
2433 if (res < 0) {
2434 ast_debug(1, "waitfordigit returned < 0...\n");
2435 res = analog_play_tone(p, idx, -1);
2436 ast_hangup(chan);
2437 goto quit;
2438 } else if (res) {
2439 ast_debug(1,"waitfordigit returned '%c' (%d), timeout = %d\n", res, res, timeout);
2440 exten[len++]=res;
2441 exten[len] = '\0';
2442 }
2443 if (!ast_ignore_pattern(ast_channel_context(chan), exten)) {
2444 analog_play_tone(p, idx, -1);
2445 } else {
2447 }
2449 is_exten_parking = ast_parking_is_exten_park(ast_channel_context(chan), exten);
2450 }
2451 if (p->lastnumredial && !strcmp(exten, "##") && !ast_exists_extension(chan, ast_channel_context(chan), "##", 1, p->cid_num)) {
2452 /* Last Number Redial */
2453 if (!ast_strlen_zero(p->lastexten)) {
2454 ast_verb(4, "Redialing last number dialed on channel %d\n", p->channel);
2455 ast_copy_string(exten, p->lastexten, sizeof(exten));
2456 } else {
2457 ast_verb(3, "Last Number Redial not possible on channel %d (no saved number)\n", p->channel);
2460 ast_hangup(chan);
2461 goto quit;
2462 }
2463 }
2464 if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num) && !is_exten_parking) {
2465 if (!res || !ast_matchmore_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) {
2466 if (getforward) {
2467 /* Record this as the forwarding extension */
2468 ast_copy_string(p->call_forward, exten, sizeof(p->call_forward));
2469 ast_verb(3, "Setting call forward to '%s' on channel %d\n", p->call_forward, p->channel);
2471 if (res) {
2472 break;
2473 }
2474 usleep(500000);
2475 res = analog_play_tone(p, idx, -1);
2476 sleep(1);
2477 memset(exten, 0, sizeof(exten));
2479 len = 0;
2480 getforward = 0;
2481 } else {
2482 res = analog_play_tone(p, idx, -1);
2483 ast_channel_lock(chan);
2484 ast_channel_exten_set(chan, exten);
2485
2486 /* Save the last number dialed, for Last Number Redial. */
2487 if (!p->immediate) {
2488 ast_copy_string(p->lastexten, exten, sizeof(p->lastexten));
2489 }
2490
2491 /* Properly set the presentation.
2492 * We need to do this here as well, because p->hidecallerid might be set
2493 * due to permanent blocking, not star-67/star-82 usage. */
2494 if (p->hidecallerid) {
2497 } else {
2500 }
2501
2503 ast_channel_unlock(chan);
2505 res = ast_pbx_run(chan);
2506 if (res) {
2507 ast_log(LOG_WARNING, "PBX exited non-zero\n");
2509 }
2510 goto quit;
2511 }
2512 } else {
2513 /* It's a match, but they just typed a digit, and there is an ambiguous match,
2514 so just set the timeout to analog_matchdigittimeout and wait some more */
2515 timeout = analog_get_matchdigit_timeout(p);
2516 }
2517 } else if (res == 0) {
2518 ast_debug(1, "not enough digits (and no ambiguous match)...\n");
2519 if (p->threewaysilenthold) {
2520 ast_debug(1, "Nothing dialed at three-way dial tone, timed out to silent hold\n");
2521 } else {
2523 }
2525 ast_hangup(chan);
2526 goto quit;
2527 } else if (p->callwaiting && !strcmp(exten, "*70")) {
2528 ast_verb(3, "Disabling call waiting on %s\n", ast_channel_name(chan));
2529 /* Disable call waiting if enabled */
2532 if (res) {
2533 ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2534 ast_channel_name(chan), strerror(errno));
2535 }
2536 len = 0;
2537 memset(exten, 0, sizeof(exten));
2538 timeout = analog_get_firstdigit_timeout(p);
2539
2540 } else if (!strcmp(exten, pickupexten)) {
2541 /* Scan all channels and see if there are any
2542 * ringing channels that have call groups
2543 * that equal this channel's pickup group
2544 */
2545 if (idx == ANALOG_SUB_REAL) {
2546 /* Switch us from Third call to Call Wait */
2547 if (p->subs[ANALOG_SUB_THREEWAY].owner) {
2548 /* If you make a threeway call and then *8# a call, it should actually
2549 look like a callwait */
2553 }
2555 if (ast_pickup_call(chan)) {
2556 ast_debug(1, "No call pickup possible...\n");
2559 }
2560 ast_hangup(chan);
2561 goto quit;
2562 } else {
2563 ast_log(LOG_WARNING, "Huh? Got *8# on call not on real\n");
2564 ast_hangup(chan);
2565 goto quit;
2566 }
2567 /* While the DMS-100 allows dialing as many *67s and *82s in succession as one's heart may desire,
2568 * the 5ESS does not, it only allows pure toggling (and only once!). So, it's not incorrect
2569 * to prevent people from dialing *67 if that won't actually do anything. */
2570 } else if (!p->hidecallerid && !strcmp(exten, "*67")) {
2571 ast_verb(3, "Blocking Caller*ID on %s\n", ast_channel_name(chan));
2572 /* Disable Caller*ID if enabled */
2573 p->hidecallerid = 1;
2577 if (res) {
2578 ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2579 ast_channel_name(chan), strerror(errno));
2580 }
2581 len = 0;
2582 memset(exten, 0, sizeof(exten));
2583 timeout = analog_get_firstdigit_timeout(p);
2584 } else if (p->callreturn && !strcmp(exten, "*69")) {
2585 res = 0;
2586 if (!ast_strlen_zero(p->lastcid_num)) {
2587 res = ast_say_digit_str(chan, p->lastcid_num, "", ast_channel_language(chan));
2588 }
2589 if (!res) {
2591 }
2592 break;
2593 } else if (!strcmp(exten, "*78")) {
2594 /* Do not disturb enabled */
2595 analog_dnd(p, 1);
2597 getforward = 0;
2598 memset(exten, 0, sizeof(exten));
2599 len = 0;
2600 } else if (!strcmp(exten, "*79")) {
2601 /* Do not disturb disabled */
2602 analog_dnd(p, 0);
2604 getforward = 0;
2605 memset(exten, 0, sizeof(exten));
2606 len = 0;
2607 } else if (p->cancallforward && !strcmp(exten, "*72")) {
2609 getforward = 1;
2610 memset(exten, 0, sizeof(exten));
2611 len = 0;
2612 } else if (p->cancallforward && !strcmp(exten, "*73")) {
2613 ast_verb(3, "Cancelling call forwarding on channel %d\n", p->channel);
2615 memset(p->call_forward, 0, sizeof(p->call_forward));
2616 getforward = 0;
2617 memset(exten, 0, sizeof(exten));
2618 len = 0;
2619 } else if ((p->transfer || p->canpark) && is_exten_parking
2621 struct ast_bridge_channel *bridge_channel;
2622
2623 /*
2624 * This is a three way call, the main call being a real channel,
2625 * and we're parking the first call.
2626 */
2630 if (bridge_channel) {
2631 if (!ast_parking_blind_transfer_park(bridge_channel, ast_channel_context(chan), exten, NULL, NULL)) {
2632 /*
2633 * Swap things around between the three-way and real call so we
2634 * can hear where the channel got parked.
2635 */
2640
2641 ast_verb(3, "%s: Parked call\n", ast_channel_name(chan));
2643 ao2_ref(bridge_channel, -1);
2644 goto quit;
2645 }
2646 ao2_ref(bridge_channel, -1);
2647 }
2648 break;
2649 } else if (!ast_strlen_zero(p->lastcid_num) && !strcmp(exten, "*60")) {
2650 ast_verb(3, "Blacklisting number %s\n", p->lastcid_num);
2651 res = ast_db_put("blacklist", p->lastcid_num, "1");
2652 if (!res) {
2654 memset(exten, 0, sizeof(exten));
2655 len = 0;
2656 }
2657 } else if (p->hidecallerid && !strcmp(exten, "*82")) {
2658 ast_verb(3, "Allowing Caller*ID on %s\n", ast_channel_name(chan));
2659 /* Enable Caller*ID if enabled */
2660 p->hidecallerid = 0;
2664 if (res) {
2665 ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2666 ast_channel_name(chan), strerror(errno));
2667 }
2668 len = 0;
2669 memset(exten, 0, sizeof(exten));
2670 timeout = analog_get_firstdigit_timeout(p);
2671 } else if (!strcmp(exten, "*0")) {
2672 struct ast_channel *nbridge = p->subs[ANALOG_SUB_THREEWAY].owner;
2673 struct analog_pvt *pbridge = NULL;
2674 /* set up the private struct of the bridged one, if any */
2675 if (nbridge) {
2676 pbridge = analog_get_bridged_channel(nbridge);
2677 }
2678 if (pbridge && ISTRUNK(pbridge)) {
2679 /* Clear out the dial buffer */
2680 p->dop.dialstr[0] = '\0';
2681 /* flash hookswitch */
2682 if ((analog_flash(pbridge) == -1) && (errno != EINPROGRESS)) {
2684 "Unable to flash-hook bridged trunk from channel %s: %s\n",
2685 ast_channel_name(nbridge), strerror(errno));
2686 }
2691 ast_hangup(chan);
2692 goto quit;
2693 } else {
2696 analog_play_tone(p, idx, -1);
2700 ast_hangup(chan);
2701 goto quit;
2702 }
2703 } else if (!ast_canmatch_extension(chan, ast_channel_context(chan), exten, 1,
2704 ast_channel_caller(chan)->id.number.valid ? ast_channel_caller(chan)->id.number.str : NULL)
2705 && !analog_canmatch_featurecode(pickupexten, exten)) {
2706 ast_debug(1, "Can't match %s from '%s' in context %s\n", exten,
2707 ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str
2708 ? ast_channel_caller(chan)->id.number.str : "<Unknown Caller>",
2709 ast_channel_context(chan));
2710 break;
2711 }
2712 if (!timeout) {
2713 timeout = analog_get_interdigit_timeout(p);
2714 }
2715 if (len && !ast_ignore_pattern(ast_channel_context(chan), exten)) {
2716 analog_play_tone(p, idx, -1);
2717 }
2718 }
2719 break;
2720 case ANALOG_SIG_FXSLS:
2721 case ANALOG_SIG_FXSGS:
2722 case ANALOG_SIG_FXSKS:
2723 /* check for SMDI messages */
2724 if (p->use_smdi && p->smdi_iface) {
2726 if (smdi_msg != NULL) {
2727 ast_channel_exten_set(chan, smdi_msg->fwd_st);
2728
2729 if (smdi_msg->type == 'B')
2730 pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "b");
2731 else if (smdi_msg->type == 'N')
2732 pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "u");
2733
2734 ast_debug(1, "Received SMDI message on %s\n", ast_channel_name(chan));
2735 } else {
2736 ast_log(LOG_WARNING, "SMDI enabled but no SMDI message present\n");
2737 }
2738 }
2739
2740 if (p->use_callerid && (p->cid_signalling == CID_SIG_SMDI && smdi_msg)) {
2741 number = smdi_msg->calling_st;
2742
2743 /* If we want caller id, we're in a prering state due to a polarity reversal
2744 * and we're set to use a polarity reversal to trigger the start of caller id,
2745 * grab the caller id and wait for ringing to start... */
2746 } else if (p->use_callerid && (ast_channel_state(chan) == AST_STATE_PRERING
2750 /* If set to use DTMF CID signalling, listen for DTMF */
2751 if (p->cid_signalling == CID_SIG_DTMF) {
2752 int k = 0;
2753 int oldlinearity;
2754 int timeout_ms;
2755 int ms;
2756 struct timeval start = ast_tvnow();
2757 ast_debug(1, "Receiving DTMF cid on channel %s\n", ast_channel_name(chan));
2758
2759 oldlinearity = analog_set_linear_mode(p, idx, 0);
2760
2761 /*
2762 * We are the only party interested in the Rx stream since
2763 * we have not answered yet. We don't need or even want DTMF
2764 * emulation. The DTMF digits can come so fast that emulation
2765 * can drop some of them.
2766 */
2767 ast_channel_lock(chan);
2769 ast_channel_unlock(chan);
2770 timeout_ms = 4000;/* This is a typical OFF time between rings. */
2771 for (;;) {
2772 struct ast_frame *f;
2773
2774 ms = ast_remaining_ms(start, timeout_ms);
2775 res = ast_waitfor(chan, ms);
2776 if (res <= 0) {
2777 /*
2778 * We do not need to restore the analog_set_linear_mode()
2779 * or AST_FLAG_END_DTMF_ONLY flag settings since we
2780 * are hanging up the channel.
2781 */
2783 "DTMFCID timed out waiting for ring. Exiting simple switch\n");
2784 ast_hangup(chan);
2785 goto quit;
2786 }
2787 f = ast_read(chan);
2788 if (!f) {
2789 break;
2790 }
2791 if (f->frametype == AST_FRAME_DTMF) {
2792 if (k < ARRAY_LEN(dtmfbuf) - 1) {
2793 dtmfbuf[k++] = f->subclass.integer;
2794 }
2795 ast_debug(1, "CID got digit '%c'\n", f->subclass.integer);
2796 start = ast_tvnow();
2797 }
2798 ast_frfree(f);
2799 if (ast_channel_state(chan) == AST_STATE_RING ||
2801 break; /* Got ring */
2802 }
2803 }
2804 ast_channel_lock(chan);
2806 ast_channel_unlock(chan);
2807 dtmfbuf[k] = '\0';
2808
2809 analog_set_linear_mode(p, idx, oldlinearity);
2810
2811 /* Got cid and ring. */
2812 ast_debug(1, "CID got string '%s'\n", dtmfbuf);
2813 callerid_get_dtmf(dtmfbuf, dtmfcid, &flags);
2814 ast_debug(1, "CID is '%s', flags %d\n", dtmfcid, flags);
2815 /* If first byte is NULL, we have no cid */
2816 if (!ast_strlen_zero(dtmfcid)) {
2817 number = dtmfcid;
2818 } else {
2819 number = NULL;
2820 }
2821
2822 /* If set to use V23 Signalling, launch our FSK gubbins and listen for it */
2823 } else if ((p->cid_signalling == CID_SIG_V23) || (p->cid_signalling == CID_SIG_V23_JP)) {
2824 namebuf[0] = 0;
2825 numbuf[0] = 0;
2826
2828 int timeout = 10000; /* Ten seconds */
2829 struct timeval start = ast_tvnow();
2830 enum analog_event ev;
2831 int off_ms;
2832 int ms;
2833 struct timeval off_start;
2834
2836 /* Disable distinctive ring timeout count */
2838 }
2839 while ((ms = ast_remaining_ms(start, timeout))) {
2840 res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2841 if (res < 0) {
2843 "CallerID returned with error on channel '%s'\n",
2844 ast_channel_name(chan));
2845 break;
2846 }
2847 if (res == 0) {
2848 break;
2849 }
2850 if (res != 1) {
2851 continue;
2852 }
2853 if (ev == ANALOG_EVENT_NOALARM) {
2854 analog_set_alarm(p, 0);
2855 }
2856 if (p->cid_signalling == CID_SIG_V23_JP) {
2857 if (ev == ANALOG_EVENT_RINGBEGIN) {
2858 analog_off_hook(p);
2859 usleep(1);
2860 }
2861 } else {
2862 break;
2863 }
2864 }
2865
2866 name = namebuf;
2867 number = numbuf;
2868
2869 if (p->cid_signalling == CID_SIG_V23_JP) {
2870 analog_on_hook(p);
2871 usleep(1);
2872 }
2873
2874 /* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
2875 off_start = ast_tvnow();
2876 off_ms = 4000;/* This is a typical OFF time between rings. */
2877 while ((ms = ast_remaining_ms(off_start, off_ms))) {
2878 struct ast_frame *f;
2879
2880 res = ast_waitfor(chan, ms);
2881 if (res <= 0) {
2883 "CID timed out waiting for ring. Exiting simple switch\n");
2885 ast_hangup(chan);
2886 goto quit;
2887 }
2888 if (!(f = ast_read(chan))) {
2889 ast_log(LOG_WARNING, "Hangup received waiting for ring. Exiting simple switch\n");
2891 ast_hangup(chan);
2892 goto quit;
2893 }
2894 ast_frfree(f);
2895 if (ast_channel_state(chan) == AST_STATE_RING ||
2897 break; /* Got ring */
2898 }
2899
2900 res = analog_distinctive_ring(chan, p, idx, NULL);
2902 if (res) {
2903 goto quit;
2904 }
2905 } else {
2906 ast_log(LOG_WARNING, "Unable to get caller ID space\n");
2907 }
2908 } else {
2910 "Channel %s in prering state, but I have nothing to do. Terminating simple switch, should be restarted by the actual ring.\n",
2911 ast_channel_name(chan));
2912 ast_hangup(chan);
2913 goto quit;
2914 }
2915 } else if (p->use_callerid && p->cid_start == ANALOG_CID_START_RING) {
2916 namebuf[0] = 0;
2917 numbuf[0] = 0;
2918
2920 int timeout = 10000; /* Ten seconds */
2921 struct timeval start = ast_tvnow();
2922 enum analog_event ev;
2923 int ring_data[RING_PATTERNS] = { 0 };
2924 int ring_data_idx = 0;
2925 int ms;
2926
2928 /* Disable distinctive ring timeout count */
2930 }
2931 while ((ms = ast_remaining_ms(start, timeout))) {
2932 res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2933 if (res < 0) {
2935 "CallerID returned with error on channel '%s'\n",
2936 ast_channel_name(chan));
2937 break;
2938 }
2939 if (res == 0) {
2940 break;
2941 }
2942 if (res != 1) {
2943 continue;
2944 }
2945 if (ev == ANALOG_EVENT_NOALARM) {
2946 analog_set_alarm(p, 0);
2947 } else if (ev == ANALOG_EVENT_POLARITY
2949 && p->polarity == POLARITY_REV) {
2950 ast_debug(1,
2951 "Hanging up due to polarity reversal on channel %d while detecting callerid\n",
2952 p->channel);
2955 ast_hangup(chan);
2956 goto quit;
2957 } else if (ev == ANALOG_EVENT_RINGOFFHOOK
2959 && ring_data_idx < RING_PATTERNS) {
2960 /*
2961 * Detect callerid while collecting possible
2962 * distinctive ring pattern.
2963 */
2964 ring_data[ring_data_idx] = p->ringt;
2965 ++ring_data_idx;
2966 }
2967 }
2968
2969 name = namebuf;
2970 number = numbuf;
2971
2972 res = analog_distinctive_ring(chan, p, idx, ring_data);
2974 if (res) {
2975 goto quit;
2976 }
2977 } else {
2978 ast_log(LOG_WARNING, "Unable to get caller ID space\n");
2979 }
2980 }
2981
2982 if (number) {
2984 }
2986
2987 analog_handle_notify_message(chan, p, flags, -1);
2988
2989 ast_channel_lock(chan);
2991 ast_channel_rings_set(chan, 1);
2992 ast_channel_unlock(chan);
2994 res = ast_pbx_run(chan);
2995 if (res) {
2996 ast_hangup(chan);
2997 ast_log(LOG_WARNING, "PBX exited non-zero\n");
2998 }
2999 goto quit;
3000 default:
3001 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);
3002 break;
3003 }
3005 if (res < 0) {
3006 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
3007 }
3008 ast_hangup(chan);
3009quit:
3010 ao2_cleanup(smdi_msg);
3012 return NULL;
3013}
3014
3016{
3017 pthread_t threadid;
3018
3019 p->ss_astchan = chan;
3021}
3022
3024{
3025 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
3026
3027 ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", channel);
3028 body = ast_json_pack("{s: i}", "Channel", channel);
3029 if (!body) {
3030 return;
3031 }
3032
3033 ast_manager_publish_event("AlarmClear", EVENT_FLAG_SYSTEM, body);
3034}
3035
3036static struct ast_frame *__analog_handle_event(struct analog_pvt *p, struct ast_channel *ast)
3037{
3038 int res, x;
3039 int mysig;
3040 int idx;
3041 char *c;
3042 pthread_t threadid;
3043 struct ast_channel *chan;
3044 struct ast_frame *f;
3045 struct ast_control_pvt_cause_code *cause_code = NULL;
3046 int data_size = sizeof(*cause_code);
3047 char *subclass = NULL;
3048
3049 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
3050
3051 idx = analog_get_index(ast, p, 0);
3052 if (idx < 0) {
3053 return &ast_null_frame;
3054 }
3055 if (idx != ANALOG_SUB_REAL) {
3056 ast_log(LOG_ERROR, "We got an event on a non real sub. Fix it!\n");
3057 }
3058
3059 mysig = p->sig;
3060 if (p->outsigmod > -1) {
3061 mysig = p->outsigmod;
3062 }
3063
3064 p->subs[idx].f.frametype = AST_FRAME_NULL;
3065 p->subs[idx].f.subclass.integer = 0;
3066 p->subs[idx].f.datalen = 0;
3067 p->subs[idx].f.samples = 0;
3068 p->subs[idx].f.mallocd = 0;
3069 p->subs[idx].f.offset = 0;
3070 p->subs[idx].f.src = "dahdi_handle_event";
3071 p->subs[idx].f.data.ptr = NULL;
3072 f = &p->subs[idx].f;
3073
3074 res = analog_get_event(p);
3075
3076 ast_debug(1, "Got event %s(%d) on channel %d (index %u)\n", analog_event2str(res), res, p->channel, idx);
3077
3080 ast_debug(1, "Detected %sdigit '%c'\n", (res & ANALOG_EVENT_PULSEDIGIT) ? "pulse ": "", res & 0xff);
3081 analog_confmute(p, 0);
3084 p->subs[idx].f.subclass.integer = res & 0xff;
3085 analog_handle_dtmf(p, ast, idx, &f);
3086 } else {
3087 ast_debug(1, "Dropping pulse digit '%c' because pulse dialing disabled on channel %d\n", res & 0xff, p->channel);
3088 }
3089 return f;
3090 }
3091
3092 if (res & ANALOG_EVENT_DTMFDOWN) {
3093 ast_debug(1, "DTMF Down '%c'\n", res & 0xff);
3094 /* Mute conference */
3095 analog_confmute(p, 1);
3097 p->subs[idx].f.subclass.integer = res & 0xff;
3098 analog_handle_dtmf(p, ast, idx, &f);
3099 return f;
3100 }
3101
3102 switch (res) {
3103 case ANALOG_EVENT_ALARM:
3106 /* add length of "ANALOG " */
3107 data_size += 7;
3108 subclass = analog_event2str(res);
3109 data_size += strlen(subclass);
3110 cause_code = ast_alloca(data_size);
3111 memset(cause_code, 0, data_size);
3114 snprintf(cause_code->code, data_size - sizeof(*cause_code) + 1, "ANALOG %s", subclass);
3115 break;
3116 default:
3117 break;
3118 }
3119
3120 switch (res) {
3122 ast_verb(3, "Channel %d echo canceller disabled due to CED detection\n", p->channel);
3124 break;
3125#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
3127 ast_verb(3, "Channel %d detected a CED tone towards the network.\n", p->channel);
3128 break;
3130 ast_verb(3, "Channel %d detected a CED tone from the network.\n", p->channel);
3131 break;
3133 ast_verb(3, "Channel %d echo canceller disabled its NLP.\n", p->channel);
3134 break;
3136 ast_verb(3, "Channel %d echo canceller enabled its NLP.\n", p->channel);
3137 break;
3138#endif
3140 /* Stop tone if there's a pulse start and the PBX isn't started */
3141 if (!ast_channel_pbx(ast))
3143 break;
3145 if (p->inalarm) {
3146 break;
3147 }
3148 x = analog_is_dialing(p, idx);
3149 if (!x) { /* if not still dialing in driver */
3151 if (p->echobreak) {
3153 ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr));
3156 p->echobreak = 0;
3157 } else {
3158 analog_set_dialing(p, 0);
3159 if ((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) {
3160 /* if thru with dialing after offhook */
3165 break;
3166 } else { /* if to state wait for offhook to dial rest */
3167 /* we now wait for off hook */
3169 }
3170 }
3173 ast_debug(1, "Done dialing, but waiting for progress detection before doing more...\n");
3174 } else if (analog_check_confirmanswer(p) || (!p->dialednone
3175 && ((mysig == ANALOG_SIG_EM) || (mysig == ANALOG_SIG_EM_E1)
3176 || (mysig == ANALOG_SIG_EMWINK) || (mysig == ANALOG_SIG_FEATD)
3177 || (mysig == ANALOG_SIG_FEATDMF_TA) || (mysig == ANALOG_SIG_FEATDMF)
3178 || (mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA)
3179 || (mysig == ANALOG_SIG_FGC_CAMAMF) || (mysig == ANALOG_SIG_FEATB)
3180 || (mysig == ANALOG_SIG_SF) || (mysig == ANALOG_SIG_SFWINK)
3181 || (mysig == ANALOG_SIG_SF_FEATD) || (mysig == ANALOG_SIG_SF_FEATDMF)
3182 || (mysig == ANALOG_SIG_SF_FEATB)))) {
3184 } else if (!p->answeronpolarityswitch) {
3188 /* If aops=0 and hops=1, this is necessary */
3190 } else {
3191 /* Start clean, so we can catch the change to REV polarity when party answers */
3193 }
3194 }
3195 }
3196 }
3197 break;
3198 case ANALOG_EVENT_ALARM:
3199 analog_set_alarm(p, 1);
3203 if (p->calledsubscriberheld && (p->sig == ANALOG_SIG_FXOLS || p->sig == ANALOG_SIG_FXOGS || p->sig == ANALOG_SIG_FXOKS) && idx == ANALOG_SUB_REAL) {
3204 ast_debug(4, "Channel state on %s is %d\n", ast_channel_name(ast), ast_channel_state(ast));
3205 /* Called Subscriber Held: don't let the called party hang up on an incoming call immediately (if it's the only call). */
3207 ast_debug(2, "Letting this call hang up normally, since it's not the only call\n");
3208 } else if (!p->owner || !p->subs[ANALOG_SUB_REAL].owner || ast_channel_state(ast) != AST_STATE_UP) {
3209 ast_debug(2, "Called Subscriber Held does not apply: channel state is %d\n", ast_channel_state(ast));
3211 /* If the channel application is empty, it is likely a masquerade has occured, in which case don't hold any calls.
3212 * This conditional matches only executions that would have reached the strcmp below. */
3213 ast_debug(1, "Skipping Called Subscriber Held; channel has no application\n");
3214 } else if (!p->owner || !p->subs[ANALOG_SUB_REAL].owner || strcmp(ast_channel_appl(p->subs[ANALOG_SUB_REAL].owner), "AppDial")) {
3215 /* Called Subscriber held only applies to incoming calls, not outgoing calls.
3216 * We can't use p->outgoing because that is always true, for both incoming and outgoing calls, so it's not accurate.
3217 * We can check the channel application/data instead.
3218 * For incoming calls to the channel, it will look like: AppDial / (Outgoing Line)
3219 * We only want this behavior for regular calls anyways (and not, say, Queue),
3220 * so this would actually work great. But accessing ast_channel_appl can cause a crash if there are no calls left,
3221 * so this check must occur AFTER we confirm the channel state *is* still UP.
3222 */
3223 ast_debug(2, "Called Subscriber Held does not apply: not an incoming call\n");
3224 } else if (analog_is_off_hook(p)) {
3225 ast_log(LOG_WARNING, "Got ONHOOK but channel %d is off hook?\n", p->channel); /* Shouldn't happen */
3226 } else {
3227 ast_verb(3, "Holding incoming call %s for channel %d\n", ast_channel_name(ast), p->channel);
3228 /* Inhibit dahdi_hangup from getting called, and do nothing else now.
3229 * When the DAHDI channel goes off hook again, it'll just get reconnected with the incoming call,
3230 * to which, as far as its concerned, nothing has happened. */
3231 p->cshactive = 1; /* Keep track that this DAHDI channel is currently being held by an incoming call. */
3232 break;
3233 }
3234 }
3236 ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
3237 ast_channel_hangupcause_hash_set(ast, cause_code, data_size);
3238 switch (p->sig) {
3239 case ANALOG_SIG_FXOLS:
3240 case ANALOG_SIG_FXOGS:
3241 case ANALOG_SIG_FXOKS:
3243 p->fxsoffhookstate = 0;
3244 p->onhooktime = time(NULL);
3245 p->msgstate = -1;
3246 /* Check for some special conditions regarding call waiting */
3247 if (idx == ANALOG_SUB_REAL) {
3248 /* The normal line was hung up */
3249 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
3250 /* Need to hold the lock for real-call, private, and call-waiting call */
3252 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
3253 /*
3254 * The call waiting call disappeared.
3255 * This is now a normal hangup.
3256 */
3258 return NULL;
3259 }
3260
3261 /* There's a call waiting call, so ring the phone, but make it unowned in the meantime */
3263 ast_verb(3, "Channel %d still has (callwait) call, ringing phone\n", p->channel);
3267 /* Don't start streaming audio yet if the incoming call isn't up yet */
3269 analog_set_dialing(p, 1);
3270 }
3271 /* Unlock the call-waiting call that we swapped to real-call. */
3273 analog_ring(p);
3274 } else if (p->subs[ANALOG_SUB_THREEWAY].owner) {
3275 unsigned int mssinceflash;
3276
3277 /* Need to hold the lock for real-call, private, and 3-way call */
3279 if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3280 ast_log(LOG_NOTICE, "Whoa, threeway disappeared kinda randomly.\n");
3281 /* Just hangup */
3282 return NULL;
3283 }
3284 if (p->owner != ast) {
3286 ast_log(LOG_WARNING, "This isn't good...\n");
3287 /* Just hangup */
3288 return NULL;
3289 }
3290
3291 mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
3292 ast_debug(1, "Last flash was %u ms ago\n", mssinceflash);
3293 if (mssinceflash < MIN_MS_SINCE_FLASH) {
3294 /* It hasn't been long enough since the last flashook. This is probably a bounce on
3295 hanging up. Hangup both channels now */
3296 ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel);
3300 } else if ((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) {
3301 if (p->transfer) {
3302 /* In any case this isn't a threeway call anymore */
3305
3306 /* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */
3307 if (!p->transfertobusy && ast_channel_state(ast) == AST_STATE_BUSY) {
3308 /* Swap subs and dis-own channel */
3310 /* Unlock the 3-way call that we swapped to real-call. */
3313 /* Ring the phone */
3314 analog_ring(p);
3315 } else if (!analog_attempt_transfer(p)) {
3316 /*
3317 * Transfer successful. Don't actually hang up at this point.
3318 * Let our channel legs of the calls die off as the transfer
3319 * percolates through the core.
3320 */
3321 break;
3322 }
3323 } else {
3326 }
3327 } else {
3328 /* Swap subs and dis-own channel */
3330 /* Unlock the 3-way call that we swapped to real-call. */
3333 /* Ring the phone */
3334 analog_ring(p);
3335 }
3336 }
3337 } else {
3338 ast_log(LOG_WARNING, "Got a hangup and my index is %u?\n", idx);
3339 }
3340 /* Fall through */
3341 default:
3343 return NULL;
3344 }
3345 break;
3347 if (p->inalarm) {
3348 break;
3349 }
3350 /* for E911, its supposed to wait for offhook then dial
3351 the second half of the dial string */
3352 if (((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) && (ast_channel_state(ast) == AST_STATE_DIALING_OFFHOOK)) {
3353 c = strchr(p->dialdest, '/');
3354 if (c) {
3355 c++;
3356 } else {
3357 c = p->dialdest;
3358 }
3359
3360 if (*c) {
3361 int numchars = snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
3362 if (numchars >= sizeof(p->dop.dialstr)) {
3363 ast_log(LOG_WARNING, "Dial string '%s' truncated\n", c);
3364 }
3365 } else {
3366 ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
3367 }
3368
3369 if (strlen(p->dop.dialstr) > 4) {
3370 memset(p->echorest, 'w', sizeof(p->echorest) - 1);
3371 strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
3372 p->echorest[sizeof(p->echorest) - 1] = '\0';
3373 p->echobreak = 1;
3374 p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
3375 } else {
3376 p->echobreak = 0;
3377 }
3378 if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
3379 analog_on_hook(p);
3380 return NULL;
3381 }
3382 analog_set_dialing(p, 1);
3383 return &p->subs[idx].f;
3384 }
3385 switch (p->sig) {
3386 case ANALOG_SIG_FXOLS:
3387 case ANALOG_SIG_FXOGS:
3388 case ANALOG_SIG_FXOKS:
3389 p->fxsoffhookstate = 1;
3390 switch (ast_channel_state(ast)) {
3391 case AST_STATE_RINGING:
3396 /* Make sure it stops ringing */
3398 analog_off_hook(p);
3399 ast_debug(1, "channel %d answered\n", p->channel);
3400
3401 /* Cancel any running CallerID spill */
3403
3404 analog_set_dialing(p, 0);
3405 p->callwaitcas = 0;
3407 /* Ignore answer if "confirm answer" is enabled */
3408 p->subs[idx].f.frametype = AST_FRAME_NULL;
3409 p->subs[idx].f.subclass.integer = 0;
3410 } else if (!ast_strlen_zero(p->dop.dialstr)) {
3411 /* nick@dccinc.com 4/3/03 - fxo should be able to do deferred dialing */
3412 res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3413 if (res) {
3414 p->dop.dialstr[0] = '\0';
3415 return NULL;
3416 } else {
3417 ast_debug(1, "Sent FXO deferred digit string: %s\n", p->dop.dialstr);
3418 p->subs[idx].f.frametype = AST_FRAME_NULL;
3419 p->subs[idx].f.subclass.integer = 0;
3420 analog_set_dialing(p, 1);
3421 }
3422 p->dop.dialstr[0] = '\0';
3424 } else {
3427 }
3428 return &p->subs[idx].f;
3429 case AST_STATE_DOWN:
3431 ast_channel_rings_set(ast, 1);
3434 ast_debug(1, "channel %d picked up\n", p->channel);
3435 return &p->subs[idx].f;
3436 case AST_STATE_UP:
3437 /* Make sure it stops ringing */
3438 analog_off_hook(p);
3439 /* Okay -- probably call waiting */
3441 break;
3442 case AST_STATE_RESERVED:
3443 /* Start up dialtone */
3444 if (analog_has_voicemail(p)) {
3446 } else {
3448 }
3449 break;
3450 default:
3451 ast_log(LOG_WARNING, "FXO phone off hook in weird state %u??\n", ast_channel_state(ast));
3452 }
3453 break;
3454 case ANALOG_SIG_FXSLS:
3455 case ANALOG_SIG_FXSGS:
3456 case ANALOG_SIG_FXSKS:
3457 if (ast_channel_state(ast) == AST_STATE_RING) {
3459 }
3460
3461 /* Fall through */
3462 case ANALOG_SIG_EM:
3463 case ANALOG_SIG_EM_E1:
3464 case ANALOG_SIG_EMWINK:
3465 case ANALOG_SIG_FEATD:
3466 case ANALOG_SIG_FEATDMF:
3468 case ANALOG_SIG_E911:
3471 case ANALOG_SIG_FEATB:
3472 case ANALOG_SIG_SF:
3473 case ANALOG_SIG_SFWINK:
3477 switch (ast_channel_state(ast)) {
3478 case AST_STATE_PRERING:
3480 /* Fall through */
3481 case AST_STATE_DOWN:
3482 case AST_STATE_RING:
3483 ast_debug(1, "Ring detected\n");
3486 break;
3487 case AST_STATE_RINGING:
3488 case AST_STATE_DIALING:
3489 if (p->outgoing) {
3490 ast_debug(1, "Line answered\n");
3492 p->subs[idx].f.frametype = AST_FRAME_NULL;
3493 p->subs[idx].f.subclass.integer = 0;
3494 } else {
3498 }
3499 break;
3500 }
3501 /* Fall through */
3502 default:
3503 ast_log(LOG_WARNING, "Ring/Off-hook in strange state %u on channel %d\n", ast_channel_state(ast), p->channel);
3504 break;
3505 }
3506 break;
3507 default:
3508 ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3509 break;
3510 }
3511 break;
3513 switch (p->sig) {
3514 case ANALOG_SIG_FXSLS:
3515 case ANALOG_SIG_FXSGS:
3516 case ANALOG_SIG_FXSKS:
3517 if (ast_channel_state(ast) == AST_STATE_RING) {
3519 }
3520 break;
3521 default:
3522 break;
3523 }
3524 break;
3526 if (p->inalarm) break;
3528 if (ast_channel_rings(ast) == p->cidrings) {
3529 analog_send_callerid(p, 0, &p->caller);
3530 }
3531
3532 if (ast_channel_rings(ast) > p->cidrings) {
3534 p->callwaitcas = 0;
3535 }
3538 break;
3540 break;
3542 analog_set_alarm(p, 0);
3544 break;
3546 if (p->inalarm) {
3547 break;
3548 }
3549 /* Remember last time we got a flash-hook */
3550 gettimeofday(&p->flashtime, NULL);
3552 switch (mysig) {
3553 case ANALOG_SIG_FXOLS:
3554 case ANALOG_SIG_FXOGS:
3555 case ANALOG_SIG_FXOKS:
3556 ast_debug(1, "Winkflash, index: %u, normal: %d, callwait: %d, thirdcall: %d\n",
3558
3559 /* Cancel any running CallerID spill */
3561 p->callwaitcas = 0;
3562
3563 if (idx != ANALOG_SUB_REAL) {
3564 ast_log(LOG_WARNING, "Got flash hook with index %u on channel %d?!?\n", idx, p->channel);
3565 goto winkflashdone;
3566 }
3567
3568 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
3569 /* Need to hold the lock for real-call, private, and call-waiting call */
3571 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
3572 /*
3573 * The call waiting call disappeared.
3574 * Let's just ignore this flash-hook.
3575 */
3576 ast_log(LOG_NOTICE, "Whoa, the call-waiting call disappeared.\n");
3577 goto winkflashdone;
3578 }
3579
3580 /* If line has Call Waiting Deluxe, see what the user wants to do.
3581 * Only do this if this is an as yet unanswered call waiting, not an existing, answered SUB_CALLWAIT. */
3583 if (p->callwaitingdeluxe) {
3584 /* This thread cannot block, so just set the flag that we need
3585 * to wait for a Call Waiting Deluxe option (or let it time out),
3586 * and then we're done for now. */
3589 ast_debug(1, "Deferring call waiting manipulation, waiting for Call Waiting Deluxe option from user\n");
3590 goto winkflashdone;
3591 }
3592 }
3593
3594 /* Swap to call-wait */
3598 ast_debug(1, "Making %s the new owner\n", ast_channel_name(p->owner));
3602 }
3604
3605 /* Start music on hold if appropriate */
3608 }
3611
3612 /* Unlock the call-waiting call that we swapped to real-call. */
3614 } else if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3615 if (!p->threewaycalling) {
3616 /* Just send a flash if no 3-way calling */
3618 goto winkflashdone;
3619 } else if (!analog_check_for_conference(p)) {
3620 ast_callid callid = 0;
3621 int callid_created;
3622 char cid_num[256];
3623 char cid_name[256];
3624
3625 cid_num[0] = '\0';
3626 cid_name[0] = '\0';
3627 if (p->dahditrcallerid && p->owner) {
3631 sizeof(cid_num));
3632 }
3636 sizeof(cid_name));
3637 }
3638 }
3639 /* XXX This section needs much more error checking!!! XXX */
3640 /* Start a 3-way call if feasible */
3641 if (!((ast_channel_pbx(ast)) ||
3642 (ast_channel_state(ast) == AST_STATE_UP) ||
3643 (ast_channel_state(ast) == AST_STATE_RING))) {
3644 ast_debug(1, "Flash when call not up or ringing\n");
3645 goto winkflashdone;
3646 }
3648 ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n");
3649 goto winkflashdone;
3650 }
3651
3652 callid_created = ast_callid_threadstorage_auto(&callid);
3653
3654 /*
3655 * Make new channel
3656 *
3657 * We cannot hold the p or ast locks while creating a new
3658 * channel.
3659 */
3661 ast_channel_unlock(ast);
3663 ast_channel_lock(ast);
3665 if (!chan) {
3667 "Cannot allocate new call structure on channel %d\n",
3668 p->channel);
3670 ast_callid_threadstorage_auto_clean(callid, callid_created);
3671 goto winkflashdone;
3672 }
3673 if (p->dahditrcallerid) {
3674 if (!p->origcid_num) {
3676 }
3677 if (!p->origcid_name) {
3679 }
3680 ast_copy_string(p->cid_num, cid_num, sizeof(p->cid_num));
3681 ast_copy_string(p->cid_name, cid_name, sizeof(p->cid_name));
3682 }
3683 /* Swap things around between the three-way and real call */
3685 /* Disable echo canceller for better dialing */
3688 if (res) {
3689 ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel);
3690 }
3691 analog_set_new_owner(p, chan);
3692 p->ss_astchan = chan;
3694 ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel);
3697 ast_hangup(chan);
3698 } else {
3699 ast_verb(3, "Started three way call on channel %d\n", p->channel);
3700
3701 /* Start music on hold */
3703 }
3704 ast_callid_threadstorage_auto_clean(callid, callid_created);
3705 }
3706 } else {
3707 /* Already have a 3 way call */
3708 enum analog_sub orig_3way_sub;
3709
3710 /* Need to hold the lock for real-call, private, and 3-way call */
3712 if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3713 /*
3714 * The 3-way call disappeared.
3715 * Let's just ignore this flash-hook.
3716 */
3717 ast_log(LOG_NOTICE, "Whoa, the 3-way call disappeared.\n");
3718 goto winkflashdone;
3719 }
3720 orig_3way_sub = ANALOG_SUB_THREEWAY;
3721
3723 /* Call is already up, drop the last person */
3724 ast_debug(1, "Got flash with three way call up, dropping last call on %d\n", p->channel);
3725 /* If the primary call isn't answered yet, use it */
3728 /* Swap back -- we're dropping the real 3-way that isn't finished yet*/
3730 orig_3way_sub = ANALOG_SUB_REAL;
3732 }
3733 /* Drop the last call and stop the conference */
3734 ast_verb(3, "Dropping three-way call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner));
3738 } else {
3739 /* Lets see what we're up to */
3740 if (((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) &&
3742 ast_verb(3, "Building conference call with %s and %s\n",
3745 /* Put them in the threeway, and flip */
3749 orig_3way_sub = ANALOG_SUB_REAL;
3750 ast_queue_unhold(p->subs[orig_3way_sub].owner);
3752 } else {
3753 ast_verb(3, "Dumping incomplete call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner));
3755 orig_3way_sub = ANALOG_SUB_REAL;
3760 }
3761 }
3762 ast_channel_unlock(p->subs[orig_3way_sub].owner);
3763 }
3764winkflashdone:
3766 break;
3767 case ANALOG_SIG_EM:
3768 case ANALOG_SIG_EM_E1:
3769 case ANALOG_SIG_FEATD:
3770 case ANALOG_SIG_SF:
3771 case ANALOG_SIG_SFWINK:
3773 case ANALOG_SIG_FXSLS:
3774 case ANALOG_SIG_FXSGS:
3775 if (p->dialing) {
3776 ast_debug(1, "Ignoring wink on channel %d\n", p->channel);
3777 } else {
3778 ast_debug(1, "Got wink in weird state %u on channel %d\n", ast_channel_state(ast), p->channel);
3779 }
3780 break;
3782 switch (p->whichwink) {
3783 case 0:
3784 ast_debug(1, "ANI2 set to '%d' and ANI is '%s'\n", ast_channel_caller(p->owner)->ani2,
3787 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%d%s#",
3791 break;
3792 case 1:
3793 ast_copy_string(p->dop.dialstr, p->finaldial, sizeof(p->dop.dialstr));
3794 break;
3795 case 2:
3796 ast_log(LOG_WARNING, "Received unexpected wink on channel of type ANALOG_SIG_FEATDMF_TA\n");
3797 return NULL;
3798 }
3799 p->whichwink++;
3800 /* Fall through */
3801 case ANALOG_SIG_FEATDMF:
3802 case ANALOG_SIG_E911:
3805 case ANALOG_SIG_FEATB:
3808 case ANALOG_SIG_EMWINK:
3809 /* FGD MF and EMWINK *Must* wait for wink */
3810 if (!ast_strlen_zero(p->dop.dialstr)) {
3811 res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3812 if (res) {
3813 p->dop.dialstr[0] = '\0';
3814 return NULL;
3815 } else {
3816 ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3817 }
3818 }
3819 p->dop.dialstr[0] = '\0';
3820 break;
3821 default:
3822 ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3823 }
3824 break;
3826 if (p->inalarm) break;
3828 break;
3829 }
3830 switch (mysig) {
3831 case ANALOG_SIG_FXSLS: /* only interesting for FXS */
3832 case ANALOG_SIG_FXSGS:
3833 case ANALOG_SIG_FXSKS:
3834 case ANALOG_SIG_EM:
3835 case ANALOG_SIG_EM_E1:
3836 case ANALOG_SIG_EMWINK:
3837 case ANALOG_SIG_FEATD:
3838 case ANALOG_SIG_SF:
3839 case ANALOG_SIG_SFWINK:
3841 if (!ast_strlen_zero(p->dop.dialstr)) {
3842 res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3843 if (res) {
3844 p->dop.dialstr[0] = '\0';
3845 return NULL;
3846 } else {
3847 ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3848 }
3849 }
3850 p->dop.dialstr[0] = '\0';
3852 break;
3853 case ANALOG_SIG_FEATDMF:
3855 case ANALOG_SIG_E911:
3858 case ANALOG_SIG_FEATB:
3861 ast_debug(1, "Got hook complete in MF FGD, waiting for wink now on channel %d\n",p->channel);
3862 break;
3863 default:
3864 break;
3865 }
3866 break;
3868 /*
3869 * If we get a Polarity Switch event, this could be
3870 * due to line seizure, remote end connect or remote end disconnect.
3871 *
3872 * Check to see if we should change the polarity state and
3873 * mark the channel as UP or if this is an indication
3874 * of remote end disconnect.
3875 */
3876
3877 if (p->polarityonanswerdelay > 0) {
3878 /* check if event is not too soon after OffHook or Answer */
3880 switch (ast_channel_state(ast)) {
3881 case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3882 case AST_STATE_RINGING: /*!< Remote end is ringing */
3883 if (p->answeronpolarityswitch) {
3884 ast_debug(1, "Answering on polarity switch! channel %d\n", p->channel);
3887 if (p->hanguponpolarityswitch) {
3889 }
3890 } else {
3891 ast_debug(1, "Ignore Answer on polarity switch, channel %d\n", p->channel);
3892 }
3893 break;
3894
3895 case AST_STATE_UP: /*!< Line is up */
3896 case AST_STATE_RING: /*!< Line is ringing */
3897 if (p->hanguponpolarityswitch) {
3898 ast_debug(1, "HangingUp on polarity switch! channel %d\n", p->channel);
3899 ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
3900 ast_channel_hangupcause_hash_set(ast, cause_code, data_size);
3903 } else {
3904 ast_debug(1, "Ignore Hangup on polarity switch, channel %d\n", p->channel);
3905 }
3906 break;
3907
3908 case AST_STATE_DOWN: /*!< Channel is down and available */
3909 case AST_STATE_RESERVED: /*!< Channel is down, but reserved */
3910 case AST_STATE_OFFHOOK: /*!< Channel is off hook */
3911 case AST_STATE_BUSY: /*!< Line is busy */
3912 case AST_STATE_DIALING_OFFHOOK: /*!< Digits (or equivalent) have been dialed while offhook */
3913 case AST_STATE_PRERING: /*!< Channel has detected an incoming call and is waiting for ring */
3914 default:
3916 ast_debug(1, "Ignoring Polarity switch on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3917 }
3918 break;
3919 }
3920
3921 } else {
3922 /* event is too soon after OffHook or Answer */
3923 switch (ast_channel_state(ast)) {
3924 case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3925 case AST_STATE_RINGING: /*!< Remote end is ringing */
3926 if (p->answeronpolarityswitch) {
3927 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));
3928 }
3929 break;
3930
3931 case AST_STATE_UP: /*!< Line is up */
3932 case AST_STATE_RING: /*!< Line is ringing */
3933 if (p->hanguponpolarityswitch) {
3934 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));
3935 }
3936 break;
3937
3938 default:
3940 ast_debug(1, "Polarity switch detected (too close to previous event) on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3941 }
3942 break;
3943 }
3944 }
3945 }
3946
3947 /* Added more log_debug information below to provide a better indication of what is going on */
3948 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) );
3949 break;
3950 default:
3951 ast_debug(1, "Dunno what to do with event %d on channel %d\n", res, p->channel);
3952 }
3953 return &p->subs[idx].f;
3954}
3955
3956struct ast_frame *analog_exception(struct analog_pvt *p, struct ast_channel *ast)
3957{
3958 int res;
3959 int idx;
3960 struct ast_frame *f;
3961
3962 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
3963
3964 idx = analog_get_index(ast, p, 1);
3965 if (idx < 0) {
3966 idx = ANALOG_SUB_REAL;
3967 }
3968
3969 p->subs[idx].f.frametype = AST_FRAME_NULL;
3970 p->subs[idx].f.datalen = 0;
3971 p->subs[idx].f.samples = 0;
3972 p->subs[idx].f.mallocd = 0;
3973 p->subs[idx].f.offset = 0;
3974 p->subs[idx].f.subclass.integer = 0;
3975 p->subs[idx].f.delivery = ast_tv(0,0);
3976 p->subs[idx].f.src = "dahdi_exception";
3977 p->subs[idx].f.data.ptr = NULL;
3978
3979 if (!p->owner) {
3980 /* If nobody owns us, absorb the event appropriately, otherwise
3981 we loop indefinitely. This occurs when, during call waiting, the
3982 other end hangs up our channel so that it no longer exists, but we
3983 have neither FLASH'd nor ONHOOK'd to signify our desire to
3984 change to the other channel. */
3985 res = analog_get_event(p);
3986
3987 /* Switch to real if there is one and this isn't something really silly... */
3988 if ((res != ANALOG_EVENT_RINGEROFF) && (res != ANALOG_EVENT_RINGERON) &&
3989 (res != ANALOG_EVENT_HOOKCOMPLETE)) {
3990 ast_debug(1, "Restoring owner of channel %d on event %d\n", p->channel, res);
3992 if (p->owner && ast != p->owner) {
3993 /*
3994 * Could this even happen?
3995 * Possible deadlock because we do not have the real-call lock.
3996 */
3997 ast_log(LOG_WARNING, "Event %s on %s is not restored owner %s\n",
3999 }
4000 if (p->owner) {
4002 }
4003 }
4004 switch (res) {
4007 if (p->owner) {
4008 ast_verb(3, "Channel %s still has call, ringing phone\n", ast_channel_name(p->owner));
4009 analog_ring(p);
4011 } else {
4012 ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
4013 analog_event2str(res));
4014 }
4016 break;
4019 analog_off_hook(p);
4020 if (p->owner && (ast_channel_state(p->owner) == AST_STATE_RINGING)) {
4022 analog_set_dialing(p, 0);
4023 }
4024 break;
4028 /* Do nothing */
4029 break;
4031 gettimeofday(&p->flashtime, NULL);
4032 if (p->owner) {
4033 ast_verb(3, "Channel %d flashed to other channel %s\n", p->channel, ast_channel_name(p->owner));
4035 /* Answer if necessary */
4038 }
4041 } else {
4042 ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
4043 analog_event2str(res));
4044 }
4046 break;
4047 default:
4048 ast_log(LOG_WARNING, "Don't know how to absorb event %s\n", analog_event2str(res));
4049 break;
4050 }
4051 f = &p->subs[idx].f;
4052 return f;
4053 }
4054 ast_debug(1, "Exception on %d, channel %d\n", ast_channel_fd(ast, 0), p->channel);
4055 /* If it's not us, return NULL immediately */
4056 if (ast != p->owner) {
4057 ast_log(LOG_WARNING, "We're %s, not %s\n", ast_channel_name(ast), ast_channel_name(p->owner));
4058 f = &p->subs[idx].f;
4059 return f;
4060 }
4061
4062 f = __analog_handle_event(p, ast);
4063 if (!f) {
4064 const char *name = ast_strdupa(ast_channel_name(ast));
4065
4066 /* Tell the CDR this DAHDI device hung up */
4068 ast_channel_unlock(ast);
4069 ast_set_hangupsource(ast, name, 0);
4070 ast_channel_lock(ast);
4072 }
4073 return f;
4074}
4075
4077{
4078 int res;
4079 pthread_t threadid;
4080 struct ast_channel *chan;
4081 ast_callid callid = 0;
4082 int callid_created;
4083
4084 ast_debug(1, "channel (%d) - signaling (%d) - event (%s)\n",
4086
4087 /* Handle an event on a given channel for the monitor thread. */
4088 switch (event) {
4091 switch (i->sig) {
4092 case ANALOG_SIG_FXSLS:
4093 case ANALOG_SIG_FXSGS:
4094 case ANALOG_SIG_FXSKS:
4095 if (i->immediate) {
4097 ast_log(LOG_WARNING, "Can't start PBX immediately, must wait for Caller ID / distinctive ring\n");
4098 } else {
4099 /* If we don't care about Caller ID or Distinctive Ring, then there's
4100 * no need to wait for anything before accepting the call, as
4101 * waiting will buy us nothing.
4102 * So if the channel is configured for immediate, actually start immediately
4103 * and get the show on the road as soon as possible. */
4104 ast_debug(1, "Disabling ring timeout (previously %d) to begin handling immediately\n", i->ringt_base);
4106 }
4107 }
4108 break;
4109 default:
4110 break;
4111 }
4112 /* Fall through */
4113 if (!(ISTRUNK(i) && i->immediate && !i->use_callerid && !i->usedistinctiveringdetection)) {
4114 break;
4115 }
4117 if (i->inalarm) {
4118 break;
4119 }
4120 /* Got a ring/answer. What kind of channel are we? */
4121 switch (i->sig) {
4122 case ANALOG_SIG_FXOLS:
4123 case ANALOG_SIG_FXOGS:
4124 case ANALOG_SIG_FXOKS:
4125 res = analog_off_hook(i);
4126 i->fxsoffhookstate = 1;
4127 i->cshactive = 0;
4129 if (res && (errno == EBUSY)) {
4130 break;
4131 }
4132 callid_created = ast_callid_threadstorage_auto(&callid);
4133
4134 /* Cancel VMWI spill */
4136
4137 if (i->immediate) {
4139 /* The channel is immediately up. Start right away */
4140 if (i->immediatering) {
4141 /* Play fake ringing, if we've been told to... */
4143 }
4145 if (!chan) {
4146 ast_log(LOG_WARNING, "Unable to start PBX on channel %d\n", i->channel);
4148 if (res < 0) {
4149 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4150 }
4151 }
4152 } else {
4153 /* Check for callerid, digits, etc */
4155 i->ss_astchan = chan;
4156 if (chan) {
4157 if (analog_has_voicemail(i)) {
4159 } else {
4161 }
4162 if (res < 0)
4163 ast_log(LOG_WARNING, "Unable to play dialtone on channel %d, do you have defaultzone and loadzone defined?\n", i->channel);
4164
4166 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4168 if (res < 0) {
4169 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4170 }
4171 ast_hangup(chan);
4172 }
4173 } else
4174 ast_log(LOG_WARNING, "Unable to create channel\n");
4175 }
4177 break;
4178 case ANALOG_SIG_FXSLS:
4179 case ANALOG_SIG_FXSGS:
4180 case ANALOG_SIG_FXSKS:
4182 /* Fall through */
4183 case ANALOG_SIG_EMWINK:
4184 case ANALOG_SIG_FEATD:
4185 case ANALOG_SIG_FEATDMF:
4187 case ANALOG_SIG_E911:
4190 case ANALOG_SIG_FEATB:
4191 case ANALOG_SIG_EM:
4192 case ANALOG_SIG_EM_E1:
4193 case ANALOG_SIG_SFWINK:
4197 case ANALOG_SIG_SF:
4198 callid_created = ast_callid_threadstorage_auto(&callid);
4199 /* Check for callerid, digits, etc */
4202 } else {
4204 }
4205 i->ss_astchan = chan;
4206 if (!chan) {
4207 ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
4208 } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4209 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4211 if (res < 0) {
4212 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4213 }
4214 ast_hangup(chan);
4215 }
4217 break;
4218 default:
4219 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);
4221 if (res < 0) {
4222 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4223 }
4224 return NULL;
4225 }
4226 break;
4228 analog_set_alarm(i, 0);
4230 break;
4231 case ANALOG_EVENT_ALARM:
4232 analog_set_alarm(i, 1);
4234 /* fall thru intentionally */
4236 /* Back on hook. Hang up. */
4237 switch (i->sig) {
4238 case ANALOG_SIG_FXOLS:
4239 case ANALOG_SIG_FXOGS:
4240 i->fxsoffhookstate = 0;
4242 /* Fall through */
4243 case ANALOG_SIG_FEATD:
4244 case ANALOG_SIG_FEATDMF:
4246 case ANALOG_SIG_E911:
4249 case ANALOG_SIG_FEATB:
4250 case ANALOG_SIG_EM:
4251 case ANALOG_SIG_EM_E1:
4252 case ANALOG_SIG_EMWINK:
4256 case ANALOG_SIG_SF:
4257 case ANALOG_SIG_SFWINK:
4258 case ANALOG_SIG_FXSLS:
4259 case ANALOG_SIG_FXSGS:
4260 case ANALOG_SIG_FXSKS:
4262 res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
4263 analog_on_hook(i);
4264 break;
4265 case ANALOG_SIG_FXOKS:
4266 i->fxsoffhookstate = 0;
4269 /* Diddle the battery for the zhone */
4270#ifdef ZHONE_HACK
4271 analog_off_hook(i);
4272 usleep(1);
4273#endif
4274 res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
4275 analog_on_hook(i);
4276 break;
4277 default:
4278 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);
4279 res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
4280 return NULL;
4281 }
4282 break;
4284 switch (i->sig) {
4285 case ANALOG_SIG_FXSLS:
4286 case ANALOG_SIG_FXSKS:
4287 case ANALOG_SIG_FXSGS:
4288 callid_created = ast_callid_threadstorage_auto(&callid);
4289 /* We have already got a PR before the channel was
4290 created, but it wasn't handled. We need polarity
4291 to be REV for remote hangup detection to work.
4292 At least in Spain */
4293 if (i->hanguponpolarityswitch) {
4295 }
4298 ast_verb(2, "Starting post polarity CID detection on channel %d\n",
4299 i->channel);
4301 i->ss_astchan = chan;
4302 if (!chan) {
4303 ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
4304 } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4305 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4306 ast_hangup(chan);
4307 }
4308 }
4310 break;
4311 default:
4313 "handle_init_event detected polarity reversal on non-FXO (ANALOG_SIG_FXS) interface %d\n",
4314 i->channel);
4315 break;
4316 }
4317 break;
4319 switch (i->sig) {
4320 case ANALOG_SIG_FXSLS:
4321 case ANALOG_SIG_FXSKS:
4322 case ANALOG_SIG_FXSGS:
4323 callid_created = ast_callid_threadstorage_auto(&callid);
4325 ast_verb(2, "Starting DTMF CID detection on channel %d\n",
4326 i->channel);
4328 i->ss_astchan = chan;
4329 if (!chan) {
4330 ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
4331 } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4332 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4333 ast_hangup(chan);
4334 }
4335 }
4337 break;
4338 default:
4340 "handle_init_event detected dtmfcid generation event on non-FXO (ANALOG_SIG_FXS) interface %d\n",
4341 i->channel);
4342 break;
4343 }
4344 break;
4345 case ANALOG_EVENT_REMOVED: /* destroy channel, will actually do so in do_monitor */
4346 ast_log(LOG_NOTICE, "Got ANALOG_EVENT_REMOVED. Destroying channel %d\n",
4347 i->channel);
4348 return i->chan_pvt;
4351 break;
4354 break;
4355 }
4356 return NULL;
4357}
4358
4359
4360struct analog_pvt *analog_new(enum analog_sigtype signallingtype, void *private_data)
4361{
4362 struct analog_pvt *p;
4363
4364 p = ast_calloc(1, sizeof(*p));
4365 if (!p) {
4366 return p;
4367 }
4368
4370 p->sig = signallingtype;
4371 p->chan_pvt = private_data;
4372
4373 /* Some defaults for values */
4376 /* Sub real is assumed to always be alloc'd */
4377 p->subs[ANALOG_SUB_REAL].allocd = 1;
4378
4379 return p;
4380}
4381
4382/*!
4383 * \brief Delete the analog private structure.
4384 * \since 1.8
4385 *
4386 * \param doomed Analog private structure to delete.
4387 */
4388void analog_delete(struct analog_pvt *doomed)
4389{
4390 ast_free(doomed);
4391}
4392
4394{
4395 /* No call waiting on non FXS channels */
4396 if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) {
4397 p->permcallwaiting = 0;
4398 }
4399
4401
4402 return 0;
4403}
4404
4406{
4407 ast_free(p);
4408}
4409
4410/* called while dahdi_pvt is locked in dahdi_fixup */
4411int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp)
4412{
4413 struct analog_pvt *new_pvt = newp;
4414 int x;
4415 ast_debug(1, "New owner for channel %d is %s\n", new_pvt->channel, ast_channel_name(newchan));
4416 if (new_pvt->owner == oldchan) {
4417 analog_set_new_owner(new_pvt, newchan);
4418 }
4419 for (x = 0; x < 3; x++) {
4420 if (new_pvt->subs[x].owner == oldchan) {
4421 new_pvt->subs[x].owner = newchan;
4422 }
4423 }
4424
4425 analog_update_conf(new_pvt);
4426 return 0;
4427}
4428
4429static void analog_publish_dnd_state(int channel, const char *status)
4430{
4431 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
4432 RAII_VAR(struct ast_str *, dahdichan, ast_str_create(32), ast_free);
4433 if (!dahdichan) {
4434 return;
4435 }
4436
4437 ast_str_set(&dahdichan, 0, "DAHDI/%d", channel);
4438
4439 body = ast_json_pack("{s: s, s: s}",
4440 "Channel", ast_str_buffer(dahdichan),
4441 "Status", status);
4442 if (!body) {
4443 return;
4444 }
4445
4447}
4448
4449int analog_dnd(struct analog_pvt *p, int flag)
4450{
4451 if (flag == -1) {
4452 return p->dnd;
4453 }
4454
4455 p->dnd = flag;
4456
4457 ast_verb(3, "%s DND on channel %d\n",
4458 flag ? "Enabled" : "Disabled",
4459 p->channel);
4460 analog_publish_dnd_state(p->channel, flag ? "enabled" : "disabled");
4461
4462 return 0;
4463}
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:1102
@ AST_BRIDGE_TRANSFER_SUCCESS
Definition: bridge.h:1104
enum ast_transfer_result ast_bridge_transfer_attended(struct ast_channel *to_transferee, struct ast_channel *to_transfer_target)
Attended transfer.
Definition: bridge.c:4756
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:882
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:4120
struct analog_callback analog_callbacks
Definition: chan_dahdi.c:3691
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:3145
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:2511
int ast_channel_rings(const struct ast_channel *chan)
int ast_queue_hangup(struct ast_channel *chan)
Queue a hangup frame.
Definition: channel.c:1181
#define ast_channel_lock(chan)
Definition: channel.h:2972
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:3132
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
Definition: channel.c:1270
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2997
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
@ AST_FLAG_END_DTMF_ONLY
Definition: channel.h:1027
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:4223
#define ast_channel_trylock(chan)
Definition: channel.h:2974
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:1277
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:7316
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:1205
@ AST_SOFTHANGUP_EXPLICIT
Definition: channel.h:1168
@ AST_SOFTHANGUP_DEV
Definition: channel.h:1141
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:2469
int ast_softhangup(struct ast_channel *chan, int cause)
Softly hangup up a channel.
Definition: channel.c:2441
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:4313
int ast_queue_unhold(struct ast_channel *chan)
Queue an unhold frame.
Definition: channel.c:1255
int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
Queue a hold frame.
Definition: channel.c:1230
#define AST_CHANNEL_NAME
Definition: channel.h:173
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:3008
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:10596
int ast_softhangup_nolock(struct ast_channel *chan, int cause)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2428
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:7404
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:1542
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:10488
#define ast_channel_unlock(chan)
Definition: channel.h:2973
#define AST_MAX_EXTENSION
Definition: channel.h:134
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_RING
Definition: channelstate.h:40
@ AST_STATE_DIALING_OFFHOOK
Definition: channelstate.h:44
@ AST_STATE_RINGING
Definition: channelstate.h:41
@ AST_STATE_PRERING
Definition: channelstate.h:45
@ AST_STATE_DOWN
Definition: channelstate.h:36
@ AST_STATE_OFFHOOK
Definition: channelstate.h:38
@ AST_STATE_BUSY
Definition: channelstate.h:43
@ AST_STATE_DIALING
Definition: channelstate.h:39
@ AST_STATE_UP
Definition: channelstate.h:42
@ AST_STATE_RESERVED
Definition: channelstate.h:37
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7368
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:1312
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1874
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:634
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_NULL
@ AST_FRAME_DTMF_END
@ AST_FRAME_DTMF_BEGIN
@ AST_FRAME_CONTROL
@ AST_CONTROL_RING
@ AST_CONTROL_OFFHOOK
@ AST_CONTROL_BUSY
@ 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:2348
#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:2290
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:2326
#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:4776
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:4196
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:4211
int ast_ignore_pattern(const char *context, const char *pattern)
Checks to see if a number should be ignored.
Definition: pbx.c:6900
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:4216
Call Pickup API.
int ast_pickup_call(struct ast_channel *chan)
Pickup a call.
Definition: pickup.c:202
struct stasis_forward * sub
Definition: res_corosync.c:240
#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:8273
static const char * analog_get_orig_dialstring(struct analog_pvt *p)
Definition: sig_analog.c:186
static void analog_set_callwaiting(struct analog_pvt *p, int callwaiting_enable)
Definition: sig_analog.c:896
static void analog_publish_channel_alarm_clear(int channel)
Definition: sig_analog.c:3023
static int analog_my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms)
Definition: sig_analog.c:1850
static const struct @144 sigtypes[]
static void analog_set_alarm(struct analog_pvt *p, int in_alarm)
Definition: sig_analog.c:919
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:414
static int analog_stop_cid_detect(struct analog_pvt *p)
Definition: sig_analog.c:170
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:368
int analog_hangup(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:1293
static int analog_send_callerid(struct analog_pvt *p, int cwcid, struct ast_party_caller *caller)
Definition: sig_analog.c:391
static void analog_set_confirmanswer(struct analog_pvt *p, int flag)
Definition: sig_analog.c:951
static int analog_update_conf(struct analog_pvt *p)
Definition: sig_analog.c:749
static void analog_unlock_private(struct analog_pvt *p)
Definition: sig_analog.c:566
static int analog_callwait(struct analog_pvt *p)
Definition: sig_analog.c:887
static void analog_set_outgoing(struct analog_pvt *p, int is_outgoing)
Definition: sig_analog.c:543
callwaiting_deluxe_option
Definition: sig_analog.c:1609
@ CWD_DROP
Definition: sig_analog.c:1612
@ CWD_FORWARD
Definition: sig_analog.c:1614
@ CWD_HOLD
Definition: sig_analog.c:1611
@ CWD_CONFERENCE
Definition: sig_analog.c:1610
@ CWD_ANNOUNCEMENT
Definition: sig_analog.c:1613
static int analog_dsp_reset_and_flush_digits(struct analog_pvt *p)
Definition: sig_analog.c:434
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:673
static void analog_increase_ss_count(void)
Definition: sig_analog.c:1879
static int analog_unalloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition: sig_analog.c:381
int analog_available(struct analog_pvt *p)
Definition: sig_analog.c:799
static char analog_defaultcic[64]
Definition: sig_analog.c:65
static void analog_publish_dnd_state(int channel, const char *status)
Definition: sig_analog.c:4429
static int analog_is_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:495
static void * analog_get_bridged_channel(struct ast_channel *chan)
Definition: sig_analog.c:1912
static int analog_dial_digits(struct analog_pvt *p, enum analog_sub sub, struct analog_dialoperation *dop)
Definition: sig_analog.c:527
static int analog_handle_notify_message(struct ast_channel *chan, struct analog_pvt *p, int cid_flags, int neon_mwievent)
Definition: sig_analog.c:1870
struct ast_frame * analog_exception(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:3956
#define gen_analog_field_callback(type, callback_name, def_value)
Definition: sig_analog.c:219
static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
Definition: sig_analog.c:452
static struct ast_frame * __analog_handle_event(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:3036
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:460
static int analog_canmatch_featurecode(const char *pickupexten, const char *exten)
Definition: sig_analog.c:1930
static void * __analog_ss_thread(void *data)
Definition: sig_analog.c:1958
static int analog_flash(struct analog_pvt *p)
Definition: sig_analog.c:511
static int analog_attempt_transfer(struct analog_pvt *p)
Definition: sig_analog.c:716
static void analog_set_needringing(struct analog_pvt *p, int value)
Definition: sig_analog.c:629
static int analog_set_linear_mode(struct analog_pvt *p, enum analog_sub sub, int linear_mode)
Definition: sig_analog.c:989
int analog_dnd(struct analog_pvt *p, int flag)
Definition: sig_analog.c:4449
static void analog_hangup_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:658
static const struct @145 cidtypes[]
static int analog_check_waitingfordt(struct analog_pvt *p)
Definition: sig_analog.c:942
static int analog_train_echocanceller(struct analog_pvt *p)
Definition: sig_analog.c:487
static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
Definition: sig_analog.c:911
int analog_callwaiting_deluxe(struct analog_pvt *p, int option)
Definition: sig_analog.c:1635
int analog_config_complete(struct analog_pvt *p)
Definition: sig_analog.c:4393
static int analog_ring(struct analog_pvt *p)
Definition: sig_analog.c:503
static int analog_check_for_conference(struct analog_pvt *p)
Definition: sig_analog.c:551
void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub idx, struct ast_frame **dest)
Definition: sig_analog.c:1764
static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
Definition: sig_analog.c:927
int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout)
Definition: sig_analog.c:1006
void analog_delete(struct analog_pvt *doomed)
Delete the analog private structure.
Definition: sig_analog.c:4388
static char * analog_event2str(enum analog_event event)
Definition: sig_analog.c:265
static void analog_set_cadence(struct analog_pvt *p, struct ast_channel *chan)
Definition: sig_analog.c:904
struct analog_pvt * analog_new(enum analog_sigtype signallingtype, void *private_data)
Definition: sig_analog.c:4360
const char * analog_cidtype_to_str(unsigned int cid_type)
Definition: sig_analog.c:149
static void analog_lock_sub_owner(struct analog_pvt *pvt, enum analog_sub sub_idx)
Definition: sig_analog.c:605
static int analog_handles_digit(struct ast_frame *f)
Definition: sig_analog.c:1584
void analog_free(struct analog_pvt *p)
Definition: sig_analog.c:4405
static void analog_lock_private(struct analog_pvt *p)
Definition: sig_analog.c:573
int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp)
Definition: sig_analog.c:4411
static int analog_dsp_set_digitmode(struct analog_pvt *p, enum analog_dsp_digitmode mode)
Definition: sig_analog.c:665
static int analog_have_progressdetect(struct analog_pvt *p)
Definition: sig_analog.c:210
#define analog_get_index(ast, p, nullok)
Definition: sig_analog.c:413
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:974
static void analog_answer_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:651
static int analog_on_hook(struct analog_pvt *p)
Definition: sig_analog.c:535
static void analog_get_and_handle_alarms(struct analog_pvt *p)
Definition: sig_analog.c:1905
static int analog_stop_callwait(struct analog_pvt *p)
Definition: sig_analog.c:868
static void analog_set_pulsedial(struct analog_pvt *p, int flag)
Definition: sig_analog.c:982
static int analog_start(struct analog_pvt *p)
Definition: sig_analog.c:519
static int analog_has_voicemail(struct analog_pvt *p)
Definition: sig_analog.c:688
static int analog_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:621
static void analog_decrease_ss_count(void)
Definition: sig_analog.c:1886
unsigned int cid_type
Definition: sig_analog.c:96
static int analog_wait_event(struct analog_pvt *p)
Definition: sig_analog.c:202
#define ISTRUNK(p)
Definition: sig_analog.c:107
const char * analog_cidstart_to_str(enum analog_cid_start cid_start)
Definition: sig_analog.c:249
static int analog_get_callerid(struct analog_pvt *p, char *name, char *number, enum analog_event *ev, size_t timeout)
Definition: sig_analog.c:178
struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor)
Definition: sig_analog.c:776
void * analog_handle_init_event(struct analog_pvt *i, int event)
Definition: sig_analog.c:4076
static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
Definition: sig_analog.c:444
#define MIN_MS_SINCE_FLASH
Definition: sig_analog.c:64
static int analog_get_event(struct analog_pvt *p)
Definition: sig_analog.c:194
unsigned int analog_str_to_cidtype(const char *name)
Definition: sig_analog.c:136
static void analog_deadlock_avoidance_private(struct analog_pvt *p)
Definition: sig_analog.c:580
static int analog_set_echocanceller(struct analog_pvt *p, int enable)
Definition: sig_analog.c:479
static void analog_set_inthreeway(struct analog_pvt *p, enum analog_sub sub, int inthreeway)
Definition: sig_analog.c:998
#define POLARITY_IDLE
Definition: sig_analog.c:62
int analog_answer(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:1506
static int analog_check_confirmanswer(struct analog_pvt *p)
Definition: sig_analog.c:958
static int analog_wink(struct analog_pvt *p, enum analog_sub index)
Definition: sig_analog.c:680
const char * analog_sigtype_to_str(enum analog_sigtype sigtype)
Definition: sig_analog.c:123
static int analog_is_dialing(struct analog_pvt *p, enum analog_sub index)
Definition: sig_analog.c:696
static void analog_cancel_cidspill(struct analog_pvt *p)
Definition: sig_analog.c:967
static const char * callwaiting_deluxe_optname(int option)
Definition: sig_analog.c:1617
static int analog_start_cid_detect(struct analog_pvt *p, int cid_signalling)
Definition: sig_analog.c:162
static void analog_swap_subs(struct analog_pvt *p, enum analog_sub a, enum analog_sub b)
Definition: sig_analog.c:348
static void analog_set_waitingfordt(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:935
static int analog_distinctive_ring(struct ast_channel *chan, struct analog_pvt *p, int idx, int *ringdata)
Definition: sig_analog.c:1893
static void analog_all_subchannels_hungup(struct analog_pvt *p)
Definition: sig_analog.c:559
#define POLARITY_REV
Definition: sig_analog.c:63
enum analog_sigtype analog_str_to_sigtype(const char *name)
Definition: sig_analog.c:110
int analog_ss_thread_start(struct analog_pvt *p, struct ast_channel *chan)
Definition: sig_analog.c:3015
enum analog_cid_start analog_str_to_cidstart(const char *value)
Definition: sig_analog.c:234
#define ANALOG_NEED_MFDETECT(p)
Definition: sig_analog.c:1928
static int analog_get_sub_fd(struct analog_pvt *p, enum analog_sub sub)
Definition: sig_analog.c:1920
static void analog_start_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:645
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_smdi_md_message_wait(struct ast_smdi_interface *iface, int timeout)
Get the next SMDI message from the queue.
Definition: res_smdi.c:545
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#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:2235
#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
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
int whichwink
Definition: sig_analog.h:375
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
int onhooktime
Definition: sig_analog.h:281
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
int cidrings
Definition: sig_analog.h:368
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 ringt_base
Definition: sig_analog.h:386
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
int stripmsd
Definition: sig_analog.h:328
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
int polarity
Definition: sig_analog.h:370
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]
char x
Definition: extconf.c:81
struct ast_flags flags
struct ast_party_caller caller
Channel Caller ID information.
char chan_name[AST_CHANNEL_NAME]
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
unsigned int flags
union ast_frame::@231 data
const char * src
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
Definition: astman.c:222
Number structure.
Definition: app_followme.c:157
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:2317
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:978
#define ast_assert(a)
Definition: utils.h:776
#define MIN(a, b)
Definition: utils.h:249
#define ast_clear_flag(p, flag)
Definition: utils.h:77
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:625
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define ARRAY_LEN(a)
Definition: utils.h:703