Asterisk - The Open Source Telephony Project GIT-master-a63eec2
Loading...
Searching...
No Matches
sig_analog.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2009, Digium, Inc.
5 *
6 * Mark Spencer <markster@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*! \file
20 *
21 * \brief Analog signaling module
22 *
23 * \author Matthew Fredrickson <creslin@digium.com>
24 */
25
26/*** MODULEINFO
27 <support_level>core</support_level>
28 ***/
29
30#include "asterisk.h"
31
32#include <errno.h>
33#include <ctype.h>
34
35#include "asterisk/utils.h"
36#include "asterisk/options.h"
37#include "asterisk/pickup.h"
38#include "asterisk/pbx.h"
39#include "asterisk/file.h"
40#include "asterisk/callerid.h"
41#include "asterisk/say.h"
42#include "asterisk/manager.h"
43#include "asterisk/astdb.h"
44#include "asterisk/features.h"
45#include "asterisk/causes.h"
47#include "asterisk/bridge.h"
48#include "asterisk/parking.h"
49
50#include "sig_analog.h"
51
52/*** DOCUMENTATION
53 ***/
54
55/*! \note
56 * Define if you want to check the hook state for an FXO (FXS signalled) interface
57 * before dialing on it. Certain FXO interfaces always think they're out of
58 * service with this method however.
59 */
60/* #define DAHDI_CHECK_HOOKSTATE */
61
62#define POLARITY_IDLE 0
63#define POLARITY_REV 1
64#define MIN_MS_SINCE_FLASH ( (2000) ) /*!< 2000 ms */
65static char analog_defaultcic[64] = "";
66static char analog_defaultozz[64] = "";
67
68static const struct {
70 const char *name;
71} sigtypes[] = {
72 { ANALOG_SIG_FXOLS, "fxo_ls" },
73 { ANALOG_SIG_FXOKS, "fxo_ks" },
74 { ANALOG_SIG_FXOGS, "fxo_gs" },
75 { ANALOG_SIG_FXSLS, "fxs_ls" },
76 { ANALOG_SIG_FXSKS, "fxs_ks" },
77 { ANALOG_SIG_FXSGS, "fxs_gs" },
78 { ANALOG_SIG_EMWINK, "em_w" },
79 { ANALOG_SIG_EM, "em" },
80 { ANALOG_SIG_EM_E1, "em_e1" },
81 { ANALOG_SIG_FEATD, "featd" },
82 { ANALOG_SIG_FEATDMF, "featdmf" },
83 { ANALOG_SIG_FEATDMF_TA, "featdmf_ta" },
84 { ANALOG_SIG_FEATB, "featb" },
85 { ANALOG_SIG_FGC_CAMA, "fgccama" },
86 { ANALOG_SIG_FGC_CAMAMF, "fgccamamf" },
87 { ANALOG_SIG_SF, "sf" },
88 { ANALOG_SIG_SFWINK, "sf_w" },
89 { ANALOG_SIG_SF_FEATD, "sf_featd" },
90 { ANALOG_SIG_SF_FEATDMF, "sf_featdmf" },
91 { ANALOG_SIG_SF_FEATB, "sf_featb" },
92 { ANALOG_SIG_E911, "e911" },
93};
94
95static const struct {
96 unsigned int cid_type;
97 const char *name;
98} cidtypes[] = {
99 { CID_SIG_BELL, "bell" },
100 { CID_SIG_V23, "v23" },
101 { CID_SIG_V23_JP, "v23_jp" },
102 { CID_SIG_DTMF, "dtmf" },
103 /* "smdi" is intentionally not supported here, as there is a much better
104 * way to do this in the dialplan now. */
106
107#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
565
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
635
636#if 0
637static void analog_set_polarity(struct analog_pvt *p, int value)
638{
641 }
642}
643#endif
644
657
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
957
959{
962 }
963
964 return 0;
965}
966
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
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
1885
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
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 int is_lastnumredial = 0;
2425 int is_endofdialing = 0;
2426
2427 /* Read digit unless it's supposed to be immediate, in which case the
2428 only answer is 's' */
2429 if (p->immediate) {
2430 res = 's';
2431 } else {
2432 res = ast_waitfordigit(chan, timeout);
2433 }
2434 timeout = 0;
2435 if (res < 0) {
2436 ast_debug(1, "waitfordigit returned < 0...\n");
2437 res = analog_play_tone(p, idx, -1);
2438 ast_hangup(chan);
2439 goto quit;
2440 } else if (res) {
2441 ast_debug(1,"waitfordigit returned '%c' (%d), timeout = %d\n", res, res, timeout);
2442 exten[len++] = res;
2443 exten[len] = '\0';
2444 if (len > 1 && res == '#' && !ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) {
2445 /* The user was dialing something that matched, but as soon as he dialed #, we no longer have a match.
2446 * Check if what was dialed immediately prior to the # is an extension that exists.
2447 * If so, we can treat "#" as the end of dialing terminator to allow user to complete the call without a timeout.
2448 * This is fully compatible with the user's dialplan, since we only do this if there isn't a dialplan match. */
2449 exten[--len] = '\0'; /* Remove '#' from the buffer to test the extension without it */
2450 if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) {
2451 /* The number dialed prior to the # exists as a valid extension.
2452 * Since the number with # does not exist, treat # as end of dialing. */
2453 ast_debug(1, "Interpreting '#' as end of dialing\n");
2454 is_endofdialing = 1;
2455 } else {
2456 /* Even without the #, the number in the buffer is not a valid extension.
2457 * In this case, it's still invalid; do nothing special.
2458 * We simply reverse the removal of '#' from the buffer, i.e. we append it again. */
2459 exten[len++] = res;
2460 exten[len ] = '\0';
2461 }
2462 }
2463 }
2464 if (!ast_ignore_pattern(ast_channel_context(chan), exten)) {
2465 analog_play_tone(p, idx, -1);
2466 } else {
2468 }
2470 is_exten_parking = ast_parking_is_exten_park(ast_channel_context(chan), exten);
2471 }
2472 if (p->lastnumredial && !strcmp(exten, "##") && !ast_exists_extension(chan, ast_channel_context(chan), "##", 1, p->cid_num)) {
2473 /* Last Number Redial */
2474 if (!ast_strlen_zero(p->lastexten)) {
2475 ast_verb(4, "Redialing last number dialed on channel %d\n", p->channel);
2477 ast_copy_string(exten, p->lastexten, sizeof(exten));
2479 /* If Last Number Redial was used, even if the user might normally be able to dial further
2480 * digits for the digits dialed, we should complete the call immediately without delay. */
2481 is_lastnumredial = 1;
2482 } else {
2483 ast_verb(3, "Last Number Redial not possible on channel %d (no saved number)\n", p->channel);
2486 ast_hangup(chan);
2487 goto quit;
2488 }
2489 }
2490 if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num) && !is_exten_parking) {
2491 if (!res || is_lastnumredial || is_endofdialing || !ast_matchmore_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) {
2492 if (getforward) {
2493 /* Record this as the forwarding extension */
2495 ast_copy_string(p->call_forward, exten, sizeof(p->call_forward));
2497 ast_verb(3, "Setting call forward to '%s' on channel %d\n", exten, p->channel);
2499 if (res) {
2500 break;
2501 }
2502 usleep(500000);
2503 res = analog_play_tone(p, idx, -1);
2504 sleep(1);
2505 memset(exten, 0, sizeof(exten));
2507 len = 0;
2508 getforward = 0;
2509 } else {
2510 res = analog_play_tone(p, idx, -1);
2511 ast_channel_lock(chan);
2512 ast_channel_exten_set(chan, exten);
2513
2514 /* Save the last number dialed, for Last Number Redial. */
2515 if (!p->immediate) {
2516 ast_copy_string(p->lastexten, exten, sizeof(p->lastexten));
2517 }
2518
2519 /* Properly set the presentation.
2520 * We need to do this here as well, because p->hidecallerid might be set
2521 * due to permanent blocking, not star-67/star-82 usage. */
2522 if (p->hidecallerid) {
2525 } else {
2528 }
2529
2531 ast_channel_unlock(chan);
2533 res = ast_pbx_run(chan);
2534 if (res) {
2535 ast_log(LOG_WARNING, "PBX exited non-zero\n");
2537 }
2538 goto quit;
2539 }
2540 } else {
2541 /* It's a match, but they just typed a digit, and there is an ambiguous match,
2542 so just set the timeout to analog_matchdigittimeout and wait some more */
2543 timeout = analog_get_matchdigit_timeout(p);
2544 }
2545 } else if (res == 0) {
2546 ast_debug(1, "not enough digits (and no ambiguous match)...\n");
2547 if (p->threewaysilenthold) {
2548 ast_debug(1, "Nothing dialed at three-way dial tone, timed out to silent hold\n");
2549 } else {
2551 }
2553 ast_hangup(chan);
2554 goto quit;
2555 } else if (p->callwaiting && !strcmp(exten, "*70")) {
2556 ast_verb(3, "Disabling call waiting on %s\n", ast_channel_name(chan));
2557 /* Disable call waiting if enabled */
2560 if (res) {
2561 ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2562 ast_channel_name(chan), strerror(errno));
2563 }
2564 len = 0;
2565 memset(exten, 0, sizeof(exten));
2566 timeout = analog_get_firstdigit_timeout(p);
2567
2568 } else if (!strcmp(exten, pickupexten)) {
2569 /* Scan all channels and see if there are any
2570 * ringing channels that have call groups
2571 * that equal this channel's pickup group
2572 */
2573 if (idx == ANALOG_SUB_REAL) {
2574 /* Switch us from Third call to Call Wait */
2575 if (p->subs[ANALOG_SUB_THREEWAY].owner) {
2576 /* If you make a threeway call and then *8# a call, it should actually
2577 look like a callwait */
2581 }
2583 if (ast_pickup_call(chan)) {
2584 ast_debug(1, "No call pickup possible...\n");
2587 }
2588 ast_hangup(chan);
2589 goto quit;
2590 } else {
2591 ast_log(LOG_WARNING, "Huh? Got *8# on call not on real\n");
2592 ast_hangup(chan);
2593 goto quit;
2594 }
2595 /* While the DMS-100 allows dialing as many *67s and *82s in succession as one's heart may desire,
2596 * the 5ESS does not, it only allows pure toggling (and only once!). So, it's not incorrect
2597 * to prevent people from dialing *67 if that won't actually do anything. */
2598 } else if (!p->hidecallerid && !strcmp(exten, "*67")) {
2599 ast_verb(3, "Blocking Caller*ID on %s\n", ast_channel_name(chan));
2600 /* Disable Caller*ID if enabled */
2601 p->hidecallerid = 1;
2605 if (res) {
2606 ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2607 ast_channel_name(chan), strerror(errno));
2608 }
2609 len = 0;
2610 memset(exten, 0, sizeof(exten));
2611 timeout = analog_get_firstdigit_timeout(p);
2612 } else if (p->callreturn && !strcmp(exten, "*69")) {
2613 res = 0;
2614 if (!ast_strlen_zero(p->lastcid_num)) {
2615 res = ast_say_digit_str(chan, p->lastcid_num, "", ast_channel_language(chan));
2616 }
2617 if (!res) {
2619 }
2620 break;
2621 } else if (!strcmp(exten, "*78")) {
2622 /* Do not disturb enabled */
2623 analog_dnd(p, 1);
2625 getforward = 0;
2626 memset(exten, 0, sizeof(exten));
2627 len = 0;
2628 } else if (!strcmp(exten, "*79")) {
2629 /* Do not disturb disabled */
2630 analog_dnd(p, 0);
2632 getforward = 0;
2633 memset(exten, 0, sizeof(exten));
2634 len = 0;
2635 } else if (p->cancallforward && !strcmp(exten, "*72")) {
2637 getforward = 1;
2638 memset(exten, 0, sizeof(exten));
2639 len = 0;
2640 } else if (p->cancallforward && !strcmp(exten, "*73")) {
2641 ast_verb(3, "Cancelling call forwarding on channel %d\n", p->channel);
2643 memset(p->call_forward, 0, sizeof(p->call_forward));
2644 getforward = 0;
2645 memset(exten, 0, sizeof(exten));
2646 len = 0;
2647 } else if ((p->transfer || p->canpark) && is_exten_parking
2649 struct ast_bridge_channel *bridge_channel;
2650
2651 /*
2652 * This is a three way call, the main call being a real channel,
2653 * and we're parking the first call.
2654 */
2658 if (bridge_channel) {
2659 if (!ast_parking_blind_transfer_park(bridge_channel, ast_channel_context(chan), exten, NULL, NULL)) {
2660 /*
2661 * Swap things around between the three-way and real call so we
2662 * can hear where the channel got parked.
2663 */
2668
2669 ast_verb(3, "%s: Parked call\n", ast_channel_name(chan));
2671 ao2_ref(bridge_channel, -1);
2672 goto quit;
2673 }
2674 ao2_ref(bridge_channel, -1);
2675 }
2676 break;
2677 } else if (!ast_strlen_zero(p->lastcid_num) && !strcmp(exten, "*60")) {
2678 ast_verb(3, "Blacklisting number %s\n", p->lastcid_num);
2679 res = ast_db_put("blacklist", p->lastcid_num, "1");
2680 if (!res) {
2682 memset(exten, 0, sizeof(exten));
2683 len = 0;
2684 }
2685 } else if (p->hidecallerid && !strcmp(exten, "*82")) {
2686 ast_verb(3, "Allowing Caller*ID on %s\n", ast_channel_name(chan));
2687 /* Enable Caller*ID if enabled */
2688 p->hidecallerid = 0;
2692 if (res) {
2693 ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2694 ast_channel_name(chan), strerror(errno));
2695 }
2696 len = 0;
2697 memset(exten, 0, sizeof(exten));
2698 timeout = analog_get_firstdigit_timeout(p);
2699 } else if (!strcmp(exten, "*0")) {
2700 struct ast_channel *nbridge = p->subs[ANALOG_SUB_THREEWAY].owner;
2701 struct analog_pvt *pbridge = NULL;
2702 /* set up the private struct of the bridged one, if any */
2703 if (nbridge) {
2704 pbridge = analog_get_bridged_channel(nbridge);
2705 }
2706 if (pbridge && ISTRUNK(pbridge)) {
2707 /* Clear out the dial buffer */
2708 p->dop.dialstr[0] = '\0';
2709 /* flash hookswitch */
2710 if ((analog_flash(pbridge) == -1) && (errno != EINPROGRESS)) {
2712 "Unable to flash-hook bridged trunk from channel %s: %s\n",
2713 ast_channel_name(nbridge), strerror(errno));
2714 }
2719 ast_hangup(chan);
2720 goto quit;
2721 } else {
2724 analog_play_tone(p, idx, -1);
2728 ast_hangup(chan);
2729 goto quit;
2730 }
2731 } else if (!ast_canmatch_extension(chan, ast_channel_context(chan), exten, 1,
2732 ast_channel_caller(chan)->id.number.valid ? ast_channel_caller(chan)->id.number.str : NULL)
2733 && !analog_canmatch_featurecode(pickupexten, exten)) {
2734 ast_debug(1, "Can't match %s from '%s' in context %s\n", exten,
2735 ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str
2736 ? ast_channel_caller(chan)->id.number.str : "<Unknown Caller>",
2737 ast_channel_context(chan));
2738 break;
2739 }
2740 if (!timeout) {
2741 timeout = analog_get_interdigit_timeout(p);
2742 }
2743 if (len && !ast_ignore_pattern(ast_channel_context(chan), exten)) {
2744 analog_play_tone(p, idx, -1);
2745 }
2746 }
2747 break;
2748 case ANALOG_SIG_FXSLS:
2749 case ANALOG_SIG_FXSGS:
2750 case ANALOG_SIG_FXSKS:
2751 /* check for SMDI messages */
2752 if (p->use_smdi && p->smdi_iface) {
2754 if (smdi_msg != NULL) {
2755 ast_channel_exten_set(chan, smdi_msg->fwd_st);
2756
2757 if (smdi_msg->type == 'B')
2758 pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "b");
2759 else if (smdi_msg->type == 'N')
2760 pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "u");
2761
2762 ast_debug(1, "Received SMDI message on %s\n", ast_channel_name(chan));
2763 } else {
2764 ast_log(LOG_WARNING, "SMDI enabled but no SMDI message present\n");
2765 }
2766 }
2767
2768 if (p->use_callerid && (p->cid_signalling == CID_SIG_SMDI && smdi_msg)) {
2769 number = smdi_msg->calling_st;
2770
2771 /* If we want caller id, we're in a prering state due to a polarity reversal
2772 * and we're set to use a polarity reversal to trigger the start of caller id,
2773 * grab the caller id and wait for ringing to start... */
2774 } else if (p->use_callerid && (ast_channel_state(chan) == AST_STATE_PRERING
2778 /* If set to use DTMF CID signalling, listen for DTMF */
2779 if (p->cid_signalling == CID_SIG_DTMF) {
2780 int k = 0;
2781 int oldlinearity;
2782 int timeout_ms;
2783 int ms;
2784 struct timeval start = ast_tvnow();
2785 ast_debug(1, "Receiving DTMF cid on channel %s\n", ast_channel_name(chan));
2786
2787 oldlinearity = analog_set_linear_mode(p, idx, 0);
2788
2789 /*
2790 * We are the only party interested in the Rx stream since
2791 * we have not answered yet. We don't need or even want DTMF
2792 * emulation. The DTMF digits can come so fast that emulation
2793 * can drop some of them.
2794 */
2795 ast_channel_lock(chan);
2797 ast_channel_unlock(chan);
2798 timeout_ms = 4000;/* This is a typical OFF time between rings. */
2799 for (;;) {
2800 struct ast_frame *f;
2801
2802 ms = ast_remaining_ms(start, timeout_ms);
2803 res = ast_waitfor(chan, ms);
2804 if (res <= 0) {
2805 /*
2806 * We do not need to restore the analog_set_linear_mode()
2807 * or AST_FLAG_END_DTMF_ONLY flag settings since we
2808 * are hanging up the channel.
2809 */
2811 "DTMFCID timed out waiting for ring. Exiting simple switch\n");
2812 ast_hangup(chan);
2813 goto quit;
2814 }
2815 f = ast_read(chan);
2816 if (!f) {
2817 break;
2818 }
2819 if (f->frametype == AST_FRAME_DTMF) {
2820 if (k < ARRAY_LEN(dtmfbuf) - 1) {
2821 dtmfbuf[k++] = f->subclass.integer;
2822 }
2823 ast_debug(1, "CID got digit '%c'\n", f->subclass.integer);
2824 start = ast_tvnow();
2825 }
2826 ast_frfree(f);
2827 if (ast_channel_state(chan) == AST_STATE_RING ||
2829 break; /* Got ring */
2830 }
2831 }
2832 ast_channel_lock(chan);
2834 ast_channel_unlock(chan);
2835 dtmfbuf[k] = '\0';
2836
2837 analog_set_linear_mode(p, idx, oldlinearity);
2838
2839 /* Got cid and ring. */
2840 ast_debug(1, "CID got string '%s'\n", dtmfbuf);
2841 callerid_get_dtmf(dtmfbuf, dtmfcid, &flags);
2842 ast_debug(1, "CID is '%s', flags %d\n", dtmfcid, flags);
2843 /* If first byte is NULL, we have no cid */
2844 if (!ast_strlen_zero(dtmfcid)) {
2845 number = dtmfcid;
2846 } else {
2847 number = NULL;
2848 }
2849
2850 /* If set to use V23 Signalling, launch our FSK gubbins and listen for it */
2851 } else if ((p->cid_signalling == CID_SIG_V23) || (p->cid_signalling == CID_SIG_V23_JP)) {
2852 namebuf[0] = 0;
2853 numbuf[0] = 0;
2854
2856 int timeout = 10000; /* Ten seconds */
2857 struct timeval start = ast_tvnow();
2858 enum analog_event ev;
2859 int off_ms;
2860 int ms;
2861 struct timeval off_start;
2862
2864 /* Disable distinctive ring timeout count */
2866 }
2867 while ((ms = ast_remaining_ms(start, timeout))) {
2868 res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2869 if (res < 0) {
2871 "CallerID returned with error on channel '%s'\n",
2872 ast_channel_name(chan));
2873 break;
2874 }
2875 if (res == 0) {
2876 break;
2877 }
2878 if (res != 1) {
2879 continue;
2880 }
2881 if (ev == ANALOG_EVENT_NOALARM) {
2882 analog_set_alarm(p, 0);
2883 }
2884 if (p->cid_signalling == CID_SIG_V23_JP) {
2885 if (ev == ANALOG_EVENT_RINGBEGIN) {
2886 analog_off_hook(p);
2887 usleep(1);
2888 }
2889 } else {
2890 break;
2891 }
2892 }
2893
2894 name = namebuf;
2895 number = numbuf;
2896
2897 if (p->cid_signalling == CID_SIG_V23_JP) {
2898 analog_on_hook(p);
2899 usleep(1);
2900 }
2901
2902 /* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
2903 off_start = ast_tvnow();
2904 off_ms = 4000;/* This is a typical OFF time between rings. */
2905 while ((ms = ast_remaining_ms(off_start, off_ms))) {
2906 struct ast_frame *f;
2907
2908 res = ast_waitfor(chan, ms);
2909 if (res <= 0) {
2911 "CID timed out waiting for ring. Exiting simple switch\n");
2913 ast_hangup(chan);
2914 goto quit;
2915 }
2916 if (!(f = ast_read(chan))) {
2917 ast_log(LOG_WARNING, "Hangup received waiting for ring. Exiting simple switch\n");
2919 ast_hangup(chan);
2920 goto quit;
2921 }
2922 ast_frfree(f);
2923 if (ast_channel_state(chan) == AST_STATE_RING ||
2925 break; /* Got ring */
2926 }
2927
2928 res = analog_distinctive_ring(chan, p, idx, NULL);
2930 if (res) {
2931 goto quit;
2932 }
2933 } else {
2934 ast_log(LOG_WARNING, "Unable to get caller ID space\n");
2935 }
2936 } else {
2938 "Channel %s in prering state, but I have nothing to do. Terminating simple switch, should be restarted by the actual ring.\n",
2939 ast_channel_name(chan));
2940 ast_hangup(chan);
2941 goto quit;
2942 }
2943 } else if (p->use_callerid && p->cid_start == ANALOG_CID_START_RING) {
2944 namebuf[0] = 0;
2945 numbuf[0] = 0;
2946
2948 int timeout = 10000; /* Ten seconds */
2949 struct timeval start = ast_tvnow();
2950 enum analog_event ev;
2951 int ring_data[RING_PATTERNS] = { 0 };
2952 int ring_data_idx = 0;
2953 int ms;
2954
2956 /* Disable distinctive ring timeout count */
2958 }
2959 while ((ms = ast_remaining_ms(start, timeout))) {
2960 res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2961 if (res < 0) {
2963 "CallerID returned with error on channel '%s'\n",
2964 ast_channel_name(chan));
2965 break;
2966 }
2967 if (res == 0) {
2968 break;
2969 }
2970 if (res != 1) {
2971 continue;
2972 }
2973 if (ev == ANALOG_EVENT_NOALARM) {
2974 analog_set_alarm(p, 0);
2975 } else if (ev == ANALOG_EVENT_POLARITY
2977 && p->polarity == POLARITY_REV) {
2978 ast_debug(1,
2979 "Hanging up due to polarity reversal on channel %d while detecting callerid\n",
2980 p->channel);
2983 ast_hangup(chan);
2984 goto quit;
2985 } else if (ev == ANALOG_EVENT_RINGOFFHOOK
2987 && ring_data_idx < RING_PATTERNS) {
2988 /*
2989 * Detect callerid while collecting possible
2990 * distinctive ring pattern.
2991 */
2992 ring_data[ring_data_idx] = p->ringt;
2993 ++ring_data_idx;
2994 }
2995 }
2996
2997 name = namebuf;
2998 number = numbuf;
2999
3000 res = analog_distinctive_ring(chan, p, idx, ring_data);
3002 if (res) {
3003 goto quit;
3004 }
3005 } else {
3006 ast_log(LOG_WARNING, "Unable to get caller ID space\n");
3007 }
3008 }
3009
3010 if (number) {
3012 }
3014
3015 analog_handle_notify_message(chan, p, flags, -1);
3016
3017 ast_channel_lock(chan);
3019 ast_channel_rings_set(chan, 1);
3020 ast_channel_unlock(chan);
3022 res = ast_pbx_run(chan);
3023 if (res) {
3024 ast_hangup(chan);
3025 ast_log(LOG_WARNING, "PBX exited non-zero\n");
3026 }
3027 goto quit;
3028 default:
3029 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);
3030 break;
3031 }
3033 if (res < 0) {
3034 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
3035 }
3036 ast_hangup(chan);
3037quit:
3038 ao2_cleanup(smdi_msg);
3040 return NULL;
3041}
3042
3044{
3045 pthread_t threadid;
3046
3047 p->ss_astchan = chan;
3049}
3050
3052{
3053 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
3054
3055 ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", channel);
3056 body = ast_json_pack("{s: i}", "Channel", channel);
3057 if (!body) {
3058 return;
3059 }
3060
3061 ast_manager_publish_event("AlarmClear", EVENT_FLAG_SYSTEM, body);
3062}
3063
3064static struct ast_frame *__analog_handle_event(struct analog_pvt *p, struct ast_channel *ast)
3065{
3066 int res, x;
3067 int mysig;
3068 int idx;
3069 char *c;
3070 pthread_t threadid;
3071 struct ast_channel *chan;
3072 struct ast_frame *f;
3073 struct ast_control_pvt_cause_code *cause_code = NULL;
3074 int data_size = sizeof(*cause_code);
3075 char *subclass = NULL;
3076
3077 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
3078
3079 idx = analog_get_index(ast, p, 0);
3080 if (idx < 0) {
3081 return &ast_null_frame;
3082 }
3083 if (idx != ANALOG_SUB_REAL) {
3084 ast_log(LOG_ERROR, "We got an event on a non real sub. Fix it!\n");
3085 }
3086
3087 mysig = p->sig;
3088 if (p->outsigmod > -1) {
3089 mysig = p->outsigmod;
3090 }
3091
3092 p->subs[idx].f.frametype = AST_FRAME_NULL;
3093 p->subs[idx].f.subclass.integer = 0;
3094 p->subs[idx].f.datalen = 0;
3095 p->subs[idx].f.samples = 0;
3096 p->subs[idx].f.mallocd = 0;
3097 p->subs[idx].f.offset = 0;
3098 p->subs[idx].f.src = "dahdi_handle_event";
3099 p->subs[idx].f.data.ptr = NULL;
3100 f = &p->subs[idx].f;
3101
3102 res = analog_get_event(p);
3103
3104 ast_debug(1, "Got event %s(%d) on channel %d (index %u)\n", analog_event2str(res), res, p->channel, idx);
3105
3108 ast_debug(1, "Detected %sdigit '%c'\n", (res & ANALOG_EVENT_PULSEDIGIT) ? "pulse ": "", res & 0xff);
3109 analog_confmute(p, 0);
3112 p->subs[idx].f.subclass.integer = res & 0xff;
3113 analog_handle_dtmf(p, ast, idx, &f);
3114 } else {
3115 ast_debug(1, "Dropping pulse digit '%c' because pulse dialing disabled on channel %d\n", res & 0xff, p->channel);
3116 }
3117 return f;
3118 }
3119
3120 if (res & ANALOG_EVENT_DTMFDOWN) {
3121 ast_debug(1, "DTMF Down '%c'\n", res & 0xff);
3122 /* Mute conference */
3123 analog_confmute(p, 1);
3125 p->subs[idx].f.subclass.integer = res & 0xff;
3126 analog_handle_dtmf(p, ast, idx, &f);
3127 return f;
3128 }
3129
3130 switch (res) {
3131 case ANALOG_EVENT_ALARM:
3134 /* add length of "ANALOG " */
3135 data_size += 7;
3136 subclass = analog_event2str(res);
3137 data_size += strlen(subclass);
3138 cause_code = ast_alloca(data_size);
3139 memset(cause_code, 0, data_size);
3142 snprintf(cause_code->code, data_size - sizeof(*cause_code) + 1, "ANALOG %s", subclass);
3143 break;
3144 default:
3145 break;
3146 }
3147
3148 switch (res) {
3150 ast_verb(3, "Channel %d echo canceller disabled due to CED detection\n", p->channel);
3152 break;
3153#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
3155 ast_verb(3, "Channel %d detected a CED tone towards the network.\n", p->channel);
3156 break;
3158 ast_verb(3, "Channel %d detected a CED tone from the network.\n", p->channel);
3159 break;
3161 ast_verb(3, "Channel %d echo canceller disabled its NLP.\n", p->channel);
3162 break;
3164 ast_verb(3, "Channel %d echo canceller enabled its NLP.\n", p->channel);
3165 break;
3166#endif
3168 /* Stop tone if there's a pulse start and the PBX isn't started */
3169 if (!ast_channel_pbx(ast))
3171 break;
3173 if (p->inalarm) {
3174 break;
3175 }
3176 x = analog_is_dialing(p, idx);
3177 if (!x) { /* if not still dialing in driver */
3179 if (p->echobreak) {
3181 ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr));
3184 p->echobreak = 0;
3185 } else {
3186 analog_set_dialing(p, 0);
3187 if ((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) {
3188 /* if thru with dialing after offhook */
3193 break;
3194 } else { /* if to state wait for offhook to dial rest */
3195 /* we now wait for off hook */
3197 }
3198 }
3201 ast_debug(1, "Done dialing, but waiting for progress detection before doing more...\n");
3202 } else if (analog_check_confirmanswer(p) || (!p->dialednone
3203 && ((mysig == ANALOG_SIG_EM) || (mysig == ANALOG_SIG_EM_E1)
3204 || (mysig == ANALOG_SIG_EMWINK) || (mysig == ANALOG_SIG_FEATD)
3205 || (mysig == ANALOG_SIG_FEATDMF_TA) || (mysig == ANALOG_SIG_FEATDMF)
3206 || (mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA)
3207 || (mysig == ANALOG_SIG_FGC_CAMAMF) || (mysig == ANALOG_SIG_FEATB)
3208 || (mysig == ANALOG_SIG_SF) || (mysig == ANALOG_SIG_SFWINK)
3209 || (mysig == ANALOG_SIG_SF_FEATD) || (mysig == ANALOG_SIG_SF_FEATDMF)
3210 || (mysig == ANALOG_SIG_SF_FEATB)))) {
3212 } else if (!p->answeronpolarityswitch) {
3216 /* If aops=0 and hops=1, this is necessary */
3218 } else {
3219 /* Start clean, so we can catch the change to REV polarity when party answers */
3221 }
3222 }
3223 }
3224 }
3225 break;
3226 case ANALOG_EVENT_ALARM:
3227 analog_set_alarm(p, 1);
3231 if (p->calledsubscriberheld && (p->sig == ANALOG_SIG_FXOLS || p->sig == ANALOG_SIG_FXOGS || p->sig == ANALOG_SIG_FXOKS) && idx == ANALOG_SUB_REAL) {
3232 ast_debug(4, "Channel state on %s is %d\n", ast_channel_name(ast), ast_channel_state(ast));
3233 /* Called Subscriber Held: don't let the called party hang up on an incoming call immediately (if it's the only call). */
3235 ast_debug(2, "Letting this call hang up normally, since it's not the only call\n");
3236 } else if (!p->owner || !p->subs[ANALOG_SUB_REAL].owner || ast_channel_state(ast) != AST_STATE_UP) {
3237 ast_debug(2, "Called Subscriber Held does not apply: channel state is %d\n", ast_channel_state(ast));
3239 /* If the channel application is empty, it is likely a masquerade has occured, in which case don't hold any calls.
3240 * This conditional matches only executions that would have reached the strcmp below. */
3241 ast_debug(1, "Skipping Called Subscriber Held; channel has no application\n");
3242 } else if (!p->owner || !p->subs[ANALOG_SUB_REAL].owner || strcmp(ast_channel_appl(p->subs[ANALOG_SUB_REAL].owner), "AppDial")) {
3243 /* Called Subscriber held only applies to incoming calls, not outgoing calls.
3244 * We can't use p->outgoing because that is always true, for both incoming and outgoing calls, so it's not accurate.
3245 * We can check the channel application/data instead.
3246 * For incoming calls to the channel, it will look like: AppDial / (Outgoing Line)
3247 * We only want this behavior for regular calls anyways (and not, say, Queue),
3248 * so this would actually work great. But accessing ast_channel_appl can cause a crash if there are no calls left,
3249 * so this check must occur AFTER we confirm the channel state *is* still UP.
3250 */
3251 ast_debug(2, "Called Subscriber Held does not apply: not an incoming call\n");
3252 } else if (analog_is_off_hook(p)) {
3253 ast_log(LOG_WARNING, "Got ONHOOK but channel %d is off hook?\n", p->channel); /* Shouldn't happen */
3254 } else {
3255 ast_verb(3, "Holding incoming call %s for channel %d\n", ast_channel_name(ast), p->channel);
3256 /* Inhibit dahdi_hangup from getting called, and do nothing else now.
3257 * When the DAHDI channel goes off hook again, it'll just get reconnected with the incoming call,
3258 * to which, as far as its concerned, nothing has happened. */
3259 p->cshactive = 1; /* Keep track that this DAHDI channel is currently being held by an incoming call. */
3260 break;
3261 }
3262 }
3264 ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
3265 ast_channel_hangupcause_hash_set(ast, cause_code, data_size);
3266 switch (p->sig) {
3267 case ANALOG_SIG_FXOLS:
3268 case ANALOG_SIG_FXOGS:
3269 case ANALOG_SIG_FXOKS:
3271 p->fxsoffhookstate = 0;
3272 p->onhooktime = time(NULL);
3273 p->msgstate = -1;
3274 /* Check for some special conditions regarding call waiting */
3275 if (idx == ANALOG_SUB_REAL) {
3276 /* The normal line was hung up */
3277 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
3278 /* Need to hold the lock for real-call, private, and call-waiting call */
3280 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
3281 /*
3282 * The call waiting call disappeared.
3283 * This is now a normal hangup.
3284 */
3286 return NULL;
3287 }
3288
3289 /* There's a call waiting call, so ring the phone, but make it unowned in the meantime */
3291 ast_verb(3, "Channel %d still has (callwait) call, ringing phone\n", p->channel);
3295 /* Don't start streaming audio yet if the incoming call isn't up yet */
3297 analog_set_dialing(p, 1);
3298 }
3299 /* Unlock the call-waiting call that we swapped to real-call. */
3301 analog_ring(p);
3302 } else if (p->subs[ANALOG_SUB_THREEWAY].owner) {
3303 unsigned int mssinceflash;
3304
3305 /* Need to hold the lock for real-call, private, and 3-way call */
3307 if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3308 ast_log(LOG_NOTICE, "Whoa, threeway disappeared kinda randomly.\n");
3309 /* Just hangup */
3310 return NULL;
3311 }
3312 if (p->owner != ast) {
3314 ast_log(LOG_WARNING, "This isn't good...\n");
3315 /* Just hangup */
3316 return NULL;
3317 }
3318
3319 mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
3320 ast_debug(1, "Last flash was %u ms ago\n", mssinceflash);
3321 if (mssinceflash < MIN_MS_SINCE_FLASH) {
3322 /* It hasn't been long enough since the last flashook. This is probably a bounce on
3323 hanging up. Hangup both channels now */
3324 ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel);
3328 } else if ((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) {
3329 if (p->transfer) {
3330 /* In any case this isn't a threeway call anymore */
3333
3334 /* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */
3335 if (!p->transfertobusy && ast_channel_state(ast) == AST_STATE_BUSY) {
3336 /* Swap subs and dis-own channel */
3338 /* Unlock the 3-way call that we swapped to real-call. */
3341 /* Ring the phone */
3342 analog_ring(p);
3343 } else if (!analog_attempt_transfer(p)) {
3344 /*
3345 * Transfer successful. Don't actually hang up at this point.
3346 * Let our channel legs of the calls die off as the transfer
3347 * percolates through the core.
3348 */
3349 break;
3350 }
3351 } else {
3354 }
3355 } else {
3356 /* Swap subs and dis-own channel */
3358 /* Unlock the 3-way call that we swapped to real-call. */
3361 /* Ring the phone */
3362 analog_ring(p);
3363 }
3364 }
3365 } else {
3366 ast_log(LOG_WARNING, "Got a hangup and my index is %u?\n", idx);
3367 }
3368 /* Fall through */
3369 default:
3371 return NULL;
3372 }
3373 break;
3375 if (p->inalarm) {
3376 break;
3377 }
3378 /* for E911, its supposed to wait for offhook then dial
3379 the second half of the dial string */
3380 if (((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) && (ast_channel_state(ast) == AST_STATE_DIALING_OFFHOOK)) {
3381 c = strchr(p->dialdest, '/');
3382 if (c) {
3383 c++;
3384 } else {
3385 c = p->dialdest;
3386 }
3387
3388 if (*c) {
3389 int numchars = snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
3390 if (numchars >= sizeof(p->dop.dialstr)) {
3391 ast_log(LOG_WARNING, "Dial string '%s' truncated\n", c);
3392 }
3393 } else {
3394 ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
3395 }
3396
3397 if (strlen(p->dop.dialstr) > 4) {
3398 memset(p->echorest, 'w', sizeof(p->echorest) - 1);
3399 strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
3400 p->echorest[sizeof(p->echorest) - 1] = '\0';
3401 p->echobreak = 1;
3402 p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
3403 } else {
3404 p->echobreak = 0;
3405 }
3406 if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
3407 analog_on_hook(p);
3408 return NULL;
3409 }
3410 analog_set_dialing(p, 1);
3411 return &p->subs[idx].f;
3412 }
3413 switch (p->sig) {
3414 case ANALOG_SIG_FXOLS:
3415 case ANALOG_SIG_FXOGS:
3416 case ANALOG_SIG_FXOKS:
3417 p->fxsoffhookstate = 1;
3418 switch (ast_channel_state(ast)) {
3419 case AST_STATE_RINGING:
3424 /* Make sure it stops ringing */
3426 analog_off_hook(p);
3427 ast_debug(1, "channel %d answered\n", p->channel);
3428
3429 /* Cancel any running CallerID spill */
3431
3432 analog_set_dialing(p, 0);
3433 p->callwaitcas = 0;
3435 /* Ignore answer if "confirm answer" is enabled */
3436 p->subs[idx].f.frametype = AST_FRAME_NULL;
3437 p->subs[idx].f.subclass.integer = 0;
3438 } else if (!ast_strlen_zero(p->dop.dialstr)) {
3439 /* nick@dccinc.com 4/3/03 - fxo should be able to do deferred dialing */
3440 res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3441 if (res) {
3442 p->dop.dialstr[0] = '\0';
3443 return NULL;
3444 } else {
3445 ast_debug(1, "Sent FXO deferred digit string: %s\n", p->dop.dialstr);
3446 p->subs[idx].f.frametype = AST_FRAME_NULL;
3447 p->subs[idx].f.subclass.integer = 0;
3448 analog_set_dialing(p, 1);
3449 }
3450 p->dop.dialstr[0] = '\0';
3452 } else {
3455 }
3456 return &p->subs[idx].f;
3457 case AST_STATE_DOWN:
3459 ast_channel_rings_set(ast, 1);
3462 ast_debug(1, "channel %d picked up\n", p->channel);
3463 return &p->subs[idx].f;
3464 case AST_STATE_UP:
3465 /* Make sure it stops ringing */
3466 analog_off_hook(p);
3467 /* Okay -- probably call waiting */
3469 break;
3470 case AST_STATE_RESERVED:
3471 /* Start up dialtone */
3472 if (analog_has_voicemail(p)) {
3474 } else {
3476 }
3477 break;
3478 default:
3479 ast_log(LOG_WARNING, "FXO phone off hook in weird state %u??\n", ast_channel_state(ast));
3480 }
3481 break;
3482 case ANALOG_SIG_FXSLS:
3483 case ANALOG_SIG_FXSGS:
3484 case ANALOG_SIG_FXSKS:
3485 if (ast_channel_state(ast) == AST_STATE_RING) {
3487 }
3488
3489 /* Fall through */
3490 case ANALOG_SIG_EM:
3491 case ANALOG_SIG_EM_E1:
3492 case ANALOG_SIG_EMWINK:
3493 case ANALOG_SIG_FEATD:
3494 case ANALOG_SIG_FEATDMF:
3496 case ANALOG_SIG_E911:
3499 case ANALOG_SIG_FEATB:
3500 case ANALOG_SIG_SF:
3501 case ANALOG_SIG_SFWINK:
3505 switch (ast_channel_state(ast)) {
3506 case AST_STATE_PRERING:
3508 /* Fall through */
3509 case AST_STATE_DOWN:
3510 case AST_STATE_RING:
3511 ast_debug(1, "Ring detected\n");
3514 break;
3515 case AST_STATE_RINGING:
3516 case AST_STATE_DIALING:
3517 if (p->outgoing) {
3518 ast_debug(1, "Line answered\n");
3520 p->subs[idx].f.frametype = AST_FRAME_NULL;
3521 p->subs[idx].f.subclass.integer = 0;
3522 } else {
3526 }
3527 break;
3528 }
3529 /* Fall through */
3530 default:
3531 ast_log(LOG_WARNING, "Ring/Off-hook in strange state %u on channel %d\n", ast_channel_state(ast), p->channel);
3532 break;
3533 }
3534 break;
3535 default:
3536 ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3537 break;
3538 }
3539 break;
3541 switch (p->sig) {
3542 case ANALOG_SIG_FXSLS:
3543 case ANALOG_SIG_FXSGS:
3544 case ANALOG_SIG_FXSKS:
3545 if (ast_channel_state(ast) == AST_STATE_RING) {
3547 }
3548 break;
3549 default:
3550 break;
3551 }
3552 break;
3554 if (p->inalarm) break;
3556 if (ast_channel_rings(ast) == p->cidrings) {
3557 analog_send_callerid(p, 0, &p->caller);
3558 }
3559
3560 if (ast_channel_rings(ast) > p->cidrings) {
3562 p->callwaitcas = 0;
3563 }
3566 break;
3568 break;
3570 analog_set_alarm(p, 0);
3572 break;
3574 if (p->inalarm) {
3575 break;
3576 }
3577 /* Remember last time we got a flash-hook */
3578 gettimeofday(&p->flashtime, NULL);
3580 switch (mysig) {
3581 case ANALOG_SIG_FXOLS:
3582 case ANALOG_SIG_FXOGS:
3583 case ANALOG_SIG_FXOKS:
3584 ast_debug(1, "Winkflash, index: %u, normal: %d, callwait: %d, thirdcall: %d\n",
3586
3587 /* Cancel any running CallerID spill */
3589 p->callwaitcas = 0;
3590
3591 if (idx != ANALOG_SUB_REAL) {
3592 ast_log(LOG_WARNING, "Got flash hook with index %u on channel %d?!?\n", idx, p->channel);
3593 goto winkflashdone;
3594 }
3595
3596 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
3597 /* Need to hold the lock for real-call, private, and call-waiting call */
3599 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
3600 /*
3601 * The call waiting call disappeared.
3602 * Let's just ignore this flash-hook.
3603 */
3604 ast_log(LOG_NOTICE, "Whoa, the call-waiting call disappeared.\n");
3605 goto winkflashdone;
3606 }
3607
3608 /* If line has Call Waiting Deluxe, see what the user wants to do.
3609 * Only do this if this is an as yet unanswered call waiting, not an existing, answered SUB_CALLWAIT. */
3611 if (p->callwaitingdeluxe) {
3612 /* This thread cannot block, so just set the flag that we need
3613 * to wait for a Call Waiting Deluxe option (or let it time out),
3614 * and then we're done for now. */
3617 ast_debug(1, "Deferring call waiting manipulation, waiting for Call Waiting Deluxe option from user\n");
3618 goto winkflashdone;
3619 }
3620 }
3621
3622 /* Swap to call-wait */
3626 ast_debug(1, "Making %s the new owner\n", ast_channel_name(p->owner));
3630 }
3632
3633 /* Start music on hold if appropriate */
3636 }
3639
3640 /* Unlock the call-waiting call that we swapped to real-call. */
3642 } else if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3643 if (!p->threewaycalling) {
3644 /* Just send a flash if no 3-way calling */
3646 goto winkflashdone;
3647 } else if (!analog_check_for_conference(p)) {
3648 ast_callid callid = 0;
3649 int callid_created;
3650 char cid_num[256];
3651 char cid_name[256];
3652
3653 cid_num[0] = '\0';
3654 cid_name[0] = '\0';
3655 if (p->dahditrcallerid && p->owner) {
3659 sizeof(cid_num));
3660 }
3664 sizeof(cid_name));
3665 }
3666 }
3667 /* XXX This section needs much more error checking!!! XXX */
3668 /* Start a 3-way call if feasible */
3669 if (!((ast_channel_pbx(ast)) ||
3670 (ast_channel_state(ast) == AST_STATE_UP) ||
3671 (ast_channel_state(ast) == AST_STATE_RING))) {
3672 ast_debug(1, "Flash when call not up or ringing\n");
3673 goto winkflashdone;
3674 }
3676 ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n");
3677 goto winkflashdone;
3678 }
3679
3680 callid_created = ast_callid_threadstorage_auto(&callid);
3681
3682 /*
3683 * Make new channel
3684 *
3685 * We cannot hold the p or ast locks while creating a new
3686 * channel.
3687 */
3689 ast_channel_unlock(ast);
3691 ast_channel_lock(ast);
3693 if (!chan) {
3695 "Cannot allocate new call structure on channel %d\n",
3696 p->channel);
3698 ast_callid_threadstorage_auto_clean(callid, callid_created);
3699 goto winkflashdone;
3700 }
3701 if (p->dahditrcallerid) {
3702 if (!p->origcid_num) {
3704 }
3705 if (!p->origcid_name) {
3707 }
3708 ast_copy_string(p->cid_num, cid_num, sizeof(p->cid_num));
3709 ast_copy_string(p->cid_name, cid_name, sizeof(p->cid_name));
3710 }
3711 /* Swap things around between the three-way and real call */
3713 /* Disable echo canceller for better dialing */
3716 if (res) {
3717 ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel);
3718 }
3719 analog_set_new_owner(p, chan);
3720 p->ss_astchan = chan;
3722 ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel);
3725 ast_hangup(chan);
3726 } else {
3727 ast_verb(3, "Started three way call on channel %d\n", p->channel);
3728
3729 /* Start music on hold */
3731 }
3732 ast_callid_threadstorage_auto_clean(callid, callid_created);
3733 }
3734 } else {
3735 /* Already have a 3 way call */
3736 enum analog_sub orig_3way_sub;
3737
3738 /* Need to hold the lock for real-call, private, and 3-way call */
3740 if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3741 /*
3742 * The 3-way call disappeared.
3743 * Let's just ignore this flash-hook.
3744 */
3745 ast_log(LOG_NOTICE, "Whoa, the 3-way call disappeared.\n");
3746 goto winkflashdone;
3747 }
3748 orig_3way_sub = ANALOG_SUB_THREEWAY;
3749
3751 /* Call is already up, drop the last person */
3752 ast_debug(1, "Got flash with three way call up, dropping last call on %d\n", p->channel);
3753 /* If the primary call isn't answered yet, use it */
3756 /* Swap back -- we're dropping the real 3-way that isn't finished yet*/
3758 orig_3way_sub = ANALOG_SUB_REAL;
3760 }
3761 /* Drop the last call and stop the conference */
3762 ast_verb(3, "Dropping three-way call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner));
3766 } else {
3767 /* Lets see what we're up to */
3768 if (((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) &&
3770 ast_verb(3, "Building conference call with %s and %s\n",
3773 /* Put them in the threeway, and flip */
3777 orig_3way_sub = ANALOG_SUB_REAL;
3778 ast_queue_unhold(p->subs[orig_3way_sub].owner);
3780 } else {
3781 ast_verb(3, "Dumping incomplete call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner));
3783 orig_3way_sub = ANALOG_SUB_REAL;
3788 }
3789 }
3790 ast_channel_unlock(p->subs[orig_3way_sub].owner);
3791 }
3792winkflashdone:
3794 break;
3795 case ANALOG_SIG_EM:
3796 case ANALOG_SIG_EM_E1:
3797 case ANALOG_SIG_FEATD:
3798 case ANALOG_SIG_SF:
3799 case ANALOG_SIG_SFWINK:
3801 case ANALOG_SIG_FXSLS:
3802 case ANALOG_SIG_FXSGS:
3803 if (p->dialing) {
3804 ast_debug(1, "Ignoring wink on channel %d\n", p->channel);
3805 } else {
3806 ast_debug(1, "Got wink in weird state %u on channel %d\n", ast_channel_state(ast), p->channel);
3807 }
3808 break;
3810 switch (p->whichwink) {
3811 case 0:
3812 ast_debug(1, "ANI2 set to '%d' and ANI is '%s'\n", ast_channel_caller(p->owner)->ani2,
3815 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%d%s#",
3819 break;
3820 case 1:
3821 ast_copy_string(p->dop.dialstr, p->finaldial, sizeof(p->dop.dialstr));
3822 break;
3823 case 2:
3824 ast_log(LOG_WARNING, "Received unexpected wink on channel of type ANALOG_SIG_FEATDMF_TA\n");
3825 return NULL;
3826 }
3827 p->whichwink++;
3828 /* Fall through */
3829 case ANALOG_SIG_FEATDMF:
3830 case ANALOG_SIG_E911:
3833 case ANALOG_SIG_FEATB:
3836 case ANALOG_SIG_EMWINK:
3837 /* FGD MF and EMWINK *Must* wait for wink */
3838 if (!ast_strlen_zero(p->dop.dialstr)) {
3839 res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3840 if (res) {
3841 p->dop.dialstr[0] = '\0';
3842 return NULL;
3843 } else {
3844 ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3845 }
3846 }
3847 p->dop.dialstr[0] = '\0';
3848 break;
3849 default:
3850 ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3851 }
3852 break;
3854 if (p->inalarm) break;
3856 break;
3857 }
3858 switch (mysig) {
3859 case ANALOG_SIG_FXSLS: /* only interesting for FXS */
3860 case ANALOG_SIG_FXSGS:
3861 case ANALOG_SIG_FXSKS:
3862 case ANALOG_SIG_EM:
3863 case ANALOG_SIG_EM_E1:
3864 case ANALOG_SIG_EMWINK:
3865 case ANALOG_SIG_FEATD:
3866 case ANALOG_SIG_SF:
3867 case ANALOG_SIG_SFWINK:
3869 if (!ast_strlen_zero(p->dop.dialstr)) {
3870 res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3871 if (res) {
3872 p->dop.dialstr[0] = '\0';
3873 return NULL;
3874 } else {
3875 ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3876 }
3877 }
3878 p->dop.dialstr[0] = '\0';
3880 break;
3881 case ANALOG_SIG_FEATDMF:
3883 case ANALOG_SIG_E911:
3886 case ANALOG_SIG_FEATB:
3889 ast_debug(1, "Got hook complete in MF FGD, waiting for wink now on channel %d\n",p->channel);
3890 break;
3891 default:
3892 break;
3893 }
3894 break;
3896 /*
3897 * If we get a Polarity Switch event, this could be
3898 * due to line seizure, remote end connect or remote end disconnect.
3899 *
3900 * Check to see if we should change the polarity state and
3901 * mark the channel as UP or if this is an indication
3902 * of remote end disconnect.
3903 */
3904
3905 if (p->polarityonanswerdelay > 0) {
3906 /* check if event is not too soon after OffHook or Answer */
3908 switch (ast_channel_state(ast)) {
3909 case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3910 case AST_STATE_RINGING: /*!< Remote end is ringing */
3911 if (p->answeronpolarityswitch) {
3912 ast_debug(1, "Answering on polarity switch! channel %d\n", p->channel);
3915 if (p->hanguponpolarityswitch) {
3917 }
3918 } else {
3919 ast_debug(1, "Ignore Answer on polarity switch, channel %d\n", p->channel);
3920 }
3921 break;
3922
3923 case AST_STATE_UP: /*!< Line is up */
3924 case AST_STATE_RING: /*!< Line is ringing */
3925 if (p->hanguponpolarityswitch) {
3926 ast_debug(1, "HangingUp on polarity switch! channel %d\n", p->channel);
3927 ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
3928 ast_channel_hangupcause_hash_set(ast, cause_code, data_size);
3931 } else {
3932 ast_debug(1, "Ignore Hangup on polarity switch, channel %d\n", p->channel);
3933 }
3934 break;
3935
3936 case AST_STATE_DOWN: /*!< Channel is down and available */
3937 case AST_STATE_RESERVED: /*!< Channel is down, but reserved */
3938 case AST_STATE_OFFHOOK: /*!< Channel is off hook */
3939 case AST_STATE_BUSY: /*!< Line is busy */
3940 case AST_STATE_DIALING_OFFHOOK: /*!< Digits (or equivalent) have been dialed while offhook */
3941 case AST_STATE_PRERING: /*!< Channel has detected an incoming call and is waiting for ring */
3942 default:
3944 ast_debug(1, "Ignoring Polarity switch on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3945 }
3946 break;
3947 }
3948
3949 } else {
3950 /* event is too soon after OffHook or Answer */
3951 switch (ast_channel_state(ast)) {
3952 case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3953 case AST_STATE_RINGING: /*!< Remote end is ringing */
3954 if (p->answeronpolarityswitch) {
3955 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));
3956 }
3957 break;
3958
3959 case AST_STATE_UP: /*!< Line is up */
3960 case AST_STATE_RING: /*!< Line is ringing */
3961 if (p->hanguponpolarityswitch) {
3962 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));
3963 }
3964 break;
3965
3966 default:
3968 ast_debug(1, "Polarity switch detected (too close to previous event) on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3969 }
3970 break;
3971 }
3972 }
3973 }
3974
3975 /* Added more log_debug information below to provide a better indication of what is going on */
3976 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) );
3977 break;
3978 default:
3979 ast_debug(1, "Dunno what to do with event %d on channel %d\n", res, p->channel);
3980 }
3981 return &p->subs[idx].f;
3982}
3983
3984struct ast_frame *analog_exception(struct analog_pvt *p, struct ast_channel *ast)
3985{
3986 int res;
3987 int idx;
3988 struct ast_frame *f;
3989
3990 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
3991
3992 idx = analog_get_index(ast, p, 1);
3993 if (idx < 0) {
3994 idx = ANALOG_SUB_REAL;
3995 }
3996
3997 p->subs[idx].f.frametype = AST_FRAME_NULL;
3998 p->subs[idx].f.datalen = 0;
3999 p->subs[idx].f.samples = 0;
4000 p->subs[idx].f.mallocd = 0;
4001 p->subs[idx].f.offset = 0;
4002 p->subs[idx].f.subclass.integer = 0;
4003 p->subs[idx].f.delivery = ast_tv(0,0);
4004 p->subs[idx].f.src = "dahdi_exception";
4005 p->subs[idx].f.data.ptr = NULL;
4006
4007 if (!p->owner) {
4008 /* If nobody owns us, absorb the event appropriately, otherwise
4009 we loop indefinitely. This occurs when, during call waiting, the
4010 other end hangs up our channel so that it no longer exists, but we
4011 have neither FLASH'd nor ONHOOK'd to signify our desire to
4012 change to the other channel. */
4013 res = analog_get_event(p);
4014
4015 /* Switch to real if there is one and this isn't something really silly... */
4016 if ((res != ANALOG_EVENT_RINGEROFF) && (res != ANALOG_EVENT_RINGERON) &&
4017 (res != ANALOG_EVENT_HOOKCOMPLETE)) {
4018 ast_debug(1, "Restoring owner of channel %d on event %d\n", p->channel, res);
4020 if (p->owner && ast != p->owner) {
4021 /*
4022 * Could this even happen?
4023 * Possible deadlock because we do not have the real-call lock.
4024 */
4025 ast_log(LOG_WARNING, "Event %s on %s is not restored owner %s\n",
4027 }
4028 if (p->owner) {
4030 }
4031 }
4032 switch (res) {
4035 if (p->owner) {
4036 ast_verb(3, "Channel %s still has call, ringing phone\n", ast_channel_name(p->owner));
4037 analog_ring(p);
4039 } else {
4040 ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
4041 analog_event2str(res));
4042 }
4044 break;
4047 analog_off_hook(p);
4048 if (p->owner && (ast_channel_state(p->owner) == AST_STATE_RINGING)) {
4050 analog_set_dialing(p, 0);
4051 }
4052 break;
4056 /* Do nothing */
4057 break;
4059 gettimeofday(&p->flashtime, NULL);
4060 if (p->owner) {
4061 ast_verb(3, "Channel %d flashed to other channel %s\n", p->channel, ast_channel_name(p->owner));
4063 /* Answer if necessary */
4066 }
4069 } else {
4070 ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
4071 analog_event2str(res));
4072 }
4074 break;
4075 default:
4076 ast_log(LOG_WARNING, "Don't know how to absorb event %s\n", analog_event2str(res));
4077 break;
4078 }
4079 f = &p->subs[idx].f;
4080 return f;
4081 }
4082 ast_debug(1, "Exception on %d, channel %d\n", ast_channel_fd(ast, 0), p->channel);
4083 /* If it's not us, return NULL immediately */
4084 if (ast != p->owner) {
4085 ast_log(LOG_WARNING, "We're %s, not %s\n", ast_channel_name(ast), ast_channel_name(p->owner));
4086 f = &p->subs[idx].f;
4087 return f;
4088 }
4089
4090 f = __analog_handle_event(p, ast);
4091 if (!f) {
4092 const char *name = ast_strdupa(ast_channel_name(ast));
4093
4094 /* Tell the CDR this DAHDI device hung up */
4096 ast_channel_unlock(ast);
4097 ast_set_hangupsource(ast, name, 0);
4098 ast_channel_lock(ast);
4100 }
4101 return f;
4102}
4103
4105{
4106 int res;
4107 pthread_t threadid;
4108 struct ast_channel *chan;
4109 ast_callid callid = 0;
4110 int callid_created;
4111
4112 ast_debug(1, "channel (%d) - signaling (%d) - event (%s)\n",
4114
4115 /* Handle an event on a given channel for the monitor thread. */
4116 switch (event) {
4119 switch (i->sig) {
4120 case ANALOG_SIG_FXSLS:
4121 case ANALOG_SIG_FXSGS:
4122 case ANALOG_SIG_FXSKS:
4123 if (i->immediate) {
4125 ast_log(LOG_WARNING, "Can't start PBX immediately, must wait for Caller ID / distinctive ring\n");
4126 } else {
4127 /* If we don't care about Caller ID or Distinctive Ring, then there's
4128 * no need to wait for anything before accepting the call, as
4129 * waiting will buy us nothing.
4130 * So if the channel is configured for immediate, actually start immediately
4131 * and get the show on the road as soon as possible. */
4132 ast_debug(1, "Disabling ring timeout (previously %d) to begin handling immediately\n", i->ringt_base);
4134 }
4135 }
4136 break;
4137 default:
4138 break;
4139 }
4140 /* Fall through */
4141 if (!(ISTRUNK(i) && i->immediate && !i->use_callerid && !i->usedistinctiveringdetection)) {
4142 break;
4143 }
4145 if (i->inalarm) {
4146 break;
4147 }
4148 /* Got a ring/answer. What kind of channel are we? */
4149 switch (i->sig) {
4150 case ANALOG_SIG_FXOLS:
4151 case ANALOG_SIG_FXOGS:
4152 case ANALOG_SIG_FXOKS:
4153 res = analog_off_hook(i);
4154 i->fxsoffhookstate = 1;
4155 i->cshactive = 0;
4157 if (res && (errno == EBUSY)) {
4158 break;
4159 }
4160 callid_created = ast_callid_threadstorage_auto(&callid);
4161
4162 /* Cancel VMWI spill */
4164
4165 if (i->immediate) {
4167 /* The channel is immediately up. Start right away */
4168 if (i->immediatering) {
4169 /* Play fake ringing, if we've been told to... */
4171 }
4173 if (!chan) {
4174 ast_log(LOG_WARNING, "Unable to start PBX on channel %d\n", i->channel);
4176 if (res < 0) {
4177 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4178 }
4179 }
4180 } else {
4181 /* Check for callerid, digits, etc */
4183 i->ss_astchan = chan;
4184 if (chan) {
4185 if (analog_has_voicemail(i)) {
4187 } else {
4189 }
4190 if (res < 0)
4191 ast_log(LOG_WARNING, "Unable to play dialtone on channel %d, do you have defaultzone and loadzone defined?\n", i->channel);
4192
4194 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4196 if (res < 0) {
4197 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4198 }
4199 ast_hangup(chan);
4200 }
4201 } else
4202 ast_log(LOG_WARNING, "Unable to create channel\n");
4203 }
4205 break;
4206 case ANALOG_SIG_FXSLS:
4207 case ANALOG_SIG_FXSGS:
4208 case ANALOG_SIG_FXSKS:
4210 /* Fall through */
4211 case ANALOG_SIG_EMWINK:
4212 case ANALOG_SIG_FEATD:
4213 case ANALOG_SIG_FEATDMF:
4215 case ANALOG_SIG_E911:
4218 case ANALOG_SIG_FEATB:
4219 case ANALOG_SIG_EM:
4220 case ANALOG_SIG_EM_E1:
4221 case ANALOG_SIG_SFWINK:
4225 case ANALOG_SIG_SF:
4226 callid_created = ast_callid_threadstorage_auto(&callid);
4227 /* Check for callerid, digits, etc */
4230 } else {
4232 }
4233 i->ss_astchan = chan;
4234 if (!chan) {
4235 ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
4236 } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4237 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4239 if (res < 0) {
4240 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4241 }
4242 ast_hangup(chan);
4243 }
4245 break;
4246 default:
4247 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);
4249 if (res < 0) {
4250 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4251 }
4252 return NULL;
4253 }
4254 break;
4256 analog_set_alarm(i, 0);
4258 break;
4259 case ANALOG_EVENT_ALARM:
4260 analog_set_alarm(i, 1);
4262 /* fall thru intentionally */
4264 /* Back on hook. Hang up. */
4265 switch (i->sig) {
4266 case ANALOG_SIG_FXOLS:
4267 case ANALOG_SIG_FXOGS:
4268 i->fxsoffhookstate = 0;
4270 /* Fall through */
4271 case ANALOG_SIG_FEATD:
4272 case ANALOG_SIG_FEATDMF:
4274 case ANALOG_SIG_E911:
4277 case ANALOG_SIG_FEATB:
4278 case ANALOG_SIG_EM:
4279 case ANALOG_SIG_EM_E1:
4280 case ANALOG_SIG_EMWINK:
4284 case ANALOG_SIG_SF:
4285 case ANALOG_SIG_SFWINK:
4286 case ANALOG_SIG_FXSLS:
4287 case ANALOG_SIG_FXSGS:
4288 case ANALOG_SIG_FXSKS:
4290 res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
4291 analog_on_hook(i);
4292 break;
4293 case ANALOG_SIG_FXOKS:
4294 i->fxsoffhookstate = 0;
4297 /* Diddle the battery for the zhone */
4298#ifdef ZHONE_HACK
4299 analog_off_hook(i);
4300 usleep(1);
4301#endif
4302 res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
4303 analog_on_hook(i);
4304 break;
4305 default:
4306 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);
4307 res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
4308 return NULL;
4309 }
4310 break;
4312 switch (i->sig) {
4313 case ANALOG_SIG_FXSLS:
4314 case ANALOG_SIG_FXSKS:
4315 case ANALOG_SIG_FXSGS:
4316 callid_created = ast_callid_threadstorage_auto(&callid);
4317 /* We have already got a PR before the channel was
4318 created, but it wasn't handled. We need polarity
4319 to be REV for remote hangup detection to work.
4320 At least in Spain */
4321 if (i->hanguponpolarityswitch) {
4323 }
4326 ast_verb(2, "Starting post polarity CID detection on channel %d\n",
4327 i->channel);
4329 i->ss_astchan = chan;
4330 if (!chan) {
4331 ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
4332 } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4333 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4334 ast_hangup(chan);
4335 }
4336 }
4338 break;
4339 default:
4341 "handle_init_event detected polarity reversal on non-FXO (ANALOG_SIG_FXS) interface %d\n",
4342 i->channel);
4343 break;
4344 }
4345 break;
4347 switch (i->sig) {
4348 case ANALOG_SIG_FXSLS:
4349 case ANALOG_SIG_FXSKS:
4350 case ANALOG_SIG_FXSGS:
4351 callid_created = ast_callid_threadstorage_auto(&callid);
4353 ast_verb(2, "Starting DTMF CID detection on channel %d\n",
4354 i->channel);
4356 i->ss_astchan = chan;
4357 if (!chan) {
4358 ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
4359 } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4360 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4361 ast_hangup(chan);
4362 }
4363 }
4365 break;
4366 default:
4368 "handle_init_event detected dtmfcid generation event on non-FXO (ANALOG_SIG_FXS) interface %d\n",
4369 i->channel);
4370 break;
4371 }
4372 break;
4373 case ANALOG_EVENT_REMOVED: /* destroy channel, will actually do so in do_monitor */
4374 ast_log(LOG_NOTICE, "Got ANALOG_EVENT_REMOVED. Destroying channel %d\n",
4375 i->channel);
4376 return i->chan_pvt;
4379 break;
4382 break;
4383 }
4384 return NULL;
4385}
4386
4387
4388struct analog_pvt *analog_new(enum analog_sigtype signallingtype, void *private_data)
4389{
4390 struct analog_pvt *p;
4391
4392 p = ast_calloc(1, sizeof(*p));
4393 if (!p) {
4394 return p;
4395 }
4396
4398 p->sig = signallingtype;
4399 p->chan_pvt = private_data;
4400
4401 /* Some defaults for values */
4404 /* Sub real is assumed to always be alloc'd */
4405 p->subs[ANALOG_SUB_REAL].allocd = 1;
4406
4407 return p;
4408}
4409
4410/*!
4411 * \brief Delete the analog private structure.
4412 * \since 1.8
4413 *
4414 * \param doomed Analog private structure to delete.
4415 */
4416void analog_delete(struct analog_pvt *doomed)
4417{
4418 ast_free(doomed);
4419}
4420
4422{
4423 /* No call waiting on non FXS channels */
4424 if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) {
4425 p->permcallwaiting = 0;
4426 }
4427
4429
4430 return 0;
4431}
4432
4434{
4435 ast_free(p);
4436}
4437
4438/* called while dahdi_pvt is locked in dahdi_fixup */
4439int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp)
4440{
4441 struct analog_pvt *new_pvt = newp;
4442 int x;
4443 ast_debug(1, "New owner for channel %d is %s\n", new_pvt->channel, ast_channel_name(newchan));
4444 if (new_pvt->owner == oldchan) {
4445 analog_set_new_owner(new_pvt, newchan);
4446 }
4447 for (x = 0; x < 3; x++) {
4448 if (new_pvt->subs[x].owner == oldchan) {
4449 new_pvt->subs[x].owner = newchan;
4450 }
4451 }
4452
4453 analog_update_conf(new_pvt);
4454 return 0;
4455}
4456
4457static void analog_publish_dnd_state(int channel, const char *status)
4458{
4459 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
4460 RAII_VAR(struct ast_str *, dahdichan, ast_str_create(32), ast_free);
4461 if (!dahdichan) {
4462 return;
4463 }
4464
4465 ast_str_set(&dahdichan, 0, "DAHDI/%d", channel);
4466
4467 body = ast_json_pack("{s: s, s: s}",
4468 "Channel", ast_str_buffer(dahdichan),
4469 "Status", status);
4470 if (!body) {
4471 return;
4472 }
4473
4475}
4476
4477int analog_dnd(struct analog_pvt *p, int flag)
4478{
4479 if (flag == -1) {
4480 return p->dnd;
4481 }
4482
4483 p->dnd = flag;
4484
4485 ast_verb(3, "%s DND on channel %d\n",
4486 flag ? "Enabled" : "Disabled",
4487 p->channel);
4488 analog_publish_dnd_state(p->channel, flag ? "enabled" : "disabled");
4489
4490 return 0;
4491}
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
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_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
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)
@ AST_FLAG_END_DTMF_ONLY
Definition channel.h:1027
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition channel.c:1542
@ AST_SOFTHANGUP_EXPLICIT
Definition channel.h:1168
@ AST_SOFTHANGUP_DEV
Definition channel.h:1141
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
@ AST_STATE_RING
@ AST_STATE_DIALING_OFFHOOK
@ AST_STATE_RINGING
@ AST_STATE_PRERING
@ AST_STATE_DOWN
@ AST_STATE_OFFHOOK
@ AST_STATE_BUSY
@ AST_STATE_DIALING
@ AST_STATE_UP
@ AST_STATE_RESERVED
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition channel.c: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_DTMF_END
@ AST_FRAME_DTMF_BEGIN
@ AST_FRAME_CONTROL
@ AST_CONTROL_OFFHOOK
@ AST_CONTROL_PLAYBACK_BEGIN
@ AST_CONTROL_ANSWER
@ AST_CONTROL_RINGING
@ AST_CONTROL_FLASH
@ AST_CONTROL_PVT_CAUSE_CODE
struct ast_frame ast_null_frame
Definition main/frame.c:79
void ast_callid_threadstorage_auto_clean(ast_callid callid, int callid_created)
Use in conjunction with ast_callid_threadstorage_auto. Cleans up the references and if the callid was...
Definition logger.c: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
static struct stasis_subscription * sub
Statsd channel stats. Exmaple of how to subscribe to Stasis events.
#define NULL
Definition resample.c:96
Say numbers and dates (maybe words one day too)
int ast_say_digit_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang)
says digits of a string
Definition channel.c: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)
static int analog_my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms)
static void analog_set_alarm(struct analog_pvt *p, int in_alarm)
Definition sig_analog.c: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 const struct @151 cidtypes[]
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)
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
@ CWD_DROP
@ CWD_FORWARD
@ CWD_HOLD
@ CWD_CONFERENCE
@ CWD_ANNOUNCEMENT
static int analog_dsp_reset_and_flush_digits(struct analog_pvt *p)
Definition sig_analog.c: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)
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)
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)
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)
struct ast_frame * analog_exception(struct analog_pvt *p, struct ast_channel *ast)
#define gen_analog_field_callback(type, callback_name, def_value)
Definition sig_analog.c: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)
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)
static void * __analog_ss_thread(void *data)
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)
static void analog_hangup_polarityswitch(struct analog_pvt *p)
Definition sig_analog.c:658
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)
int analog_config_complete(struct analog_pvt *p)
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)
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)
void analog_delete(struct analog_pvt *doomed)
Delete the analog private structure.
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)
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)
void analog_free(struct analog_pvt *p)
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)
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)
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)
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)
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)
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 const struct @150 sigtypes[]
static void analog_cancel_cidspill(struct analog_pvt *p)
Definition sig_analog.c:967
static const char * callwaiting_deluxe_optname(int option)
static int analog_start_cid_detect(struct analog_pvt *p, int cid_signalling)
Definition sig_analog.c: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)
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)
enum analog_cid_start analog_str_to_cidstart(const char *value)
Definition sig_analog.c:234
#define ANALOG_NEED_MFDETECT(p)
static int analog_get_sub_fd(struct analog_pvt *p, enum analog_sub sub)
static void analog_start_polarityswitch(struct analog_pvt *p)
Definition sig_analog.c: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_OPTIONAL_API_NAME() ast_smdi_md_message_wait(struct ast_smdi_interface *iface, int timeout)
Get the next SMDI message from the queue.
Definition res_smdi.c:545
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition strings.h:80
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition utils.c: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
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425
int(*const stop_cid_detect)(void *pvt)
Definition sig_analog.h:194
int(*const set_echocanceller)(void *pvt, int enable)
Definition sig_analog.h:184
void(*const deadlock_avoidance_private)(void *pvt)
Definition sig_analog.h:149
int(*const unallocate_sub)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:203
int(*const distinctive_ring)(struct ast_channel *chan, void *pvt, int idx, int *ringdata)
Definition sig_analog.h:230
int(*const stop_callwait)(void *pvt)
Definition sig_analog.h:199
void(*const set_confirmanswer)(void *pvt, int flag)
Definition sig_analog.h:244
void(*const set_callwaiting)(void *pvt, int callwaiting_enable)
Definition sig_analog.h:246
void(*const unlock_private)(void *pvt)
Definition sig_analog.h:145
int(*const check_confirmanswer)(void *pvt)
Definition sig_analog.h:245
const char *(*const get_orig_dialstring)(void *pvt)
Definition sig_analog.h:252
void(*const set_cadence)(void *pvt, int *cidrings, struct ast_channel *chan)
Definition sig_analog.h:237
int(*const have_progressdetect)(void *pvt)
Definition sig_analog.h:253
void(*const hangup_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch and hanguponpolarityswitch.
Definition sig_analog.h:176
int(*const is_off_hook)(void *pvt)
Definition sig_analog.h:158
void(*const decrease_ss_count)(void)
Definition sig_analog.h:228
int(*const is_dialing)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:159
int(*const train_echocanceller)(void *pvt)
Definition sig_analog.h:185
void(*const set_pulsedial)(void *pvt, int flag)
Definition sig_analog.h:249
int(*const check_waitingfordt)(void *pvt)
Definition sig_analog.h:243
int(*const get_callerid)(void *pvt, char *name, char *num, enum analog_event *ev, size_t timeout)
Definition sig_analog.h:190
int(*const conf_add)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:210
int(*const ring)(void *pvt)
Definition sig_analog.h:162
void(*const handle_dtmf)(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
Definition sig_analog.h:154
int(*const flash)(void *pvt)
Definition sig_analog.h:163
int(*const start_cid_detect)(void *pvt, int cid_signalling)
Definition sig_analog.h:192
void(*const swap_subs)(void *pvt, enum analog_sub a, struct ast_channel *new_a_owner, enum analog_sub b, struct ast_channel *new_b_owner)
Definition sig_analog.h:206
int(*const confmute)(void *pvt, int mute)
Definition sig_analog.h:248
void(*const handle_notify_message)(struct ast_channel *chan, void *pvt, int cid_flags, int neon_mwievent)
Definition sig_analog.h:224
int(*const set_linear_mode)(void *pvt, enum analog_sub sub, int linear_mode)
Definition sig_analog.h:232
int(*const complete_conference_update)(void *pvt, int needconf)
Definition sig_analog.h:216
void(*const set_outgoing)(void *pvt, int is_outgoing)
Definition sig_analog.h:240
int(*const on_hook)(void *pvt)
Set channel on hook.
Definition sig_analog.h:165
void(*const set_dialing)(void *pvt, int is_dialing)
Definition sig_analog.h:239
void(*const answer_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch=yes.
Definition sig_analog.h:174
int(*const dsp_set_digitmode)(void *pvt, enum analog_dsp_digitmode mode)
Definition sig_analog.h:186
void(*const set_alarm)(void *pvt, int in_alarm)
Definition sig_analog.h:238
void(*const set_new_owner)(void *pvt, struct ast_channel *new_owner)
Definition sig_analog.h:250
int(*const send_callerid)(void *pvt, int cwcid, struct ast_party_caller *caller)
Definition sig_analog.h:188
void(*const set_inthreeway)(void *pvt, enum analog_sub sub, int inthreeway)
Definition sig_analog.h:233
void(*const increase_ss_count)(void)
Definition sig_analog.h:227
void(*const cancel_cidspill)(void *pvt)
Definition sig_analog.h:247
int(*const dial_digits)(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop)
Definition sig_analog.h:180
int(*const conf_del)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:212
int(*const has_voicemail)(void *pvt)
Definition sig_analog.h:222
int(*const check_for_conference)(void *pvt)
Definition sig_analog.h:223
int(*const allocate_sub)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:202
int(*const wink)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:179
int(*const off_hook)(void *pvt)
Set channel off hook.
Definition sig_analog.h:167
int(*const dsp_reset_and_flush_digits)(void *pvt)
Definition sig_analog.h:187
void(*const set_ringtimeout)(void *pvt, int ringt)
Definition sig_analog.h:241
void(*const lock_private)(void *pvt)
Definition sig_analog.h:147
void(*const all_subchannels_hungup)(void *pvt)
Definition sig_analog.h:220
int(*const play_tone)(void *pvt, enum analog_sub sub, enum analog_tone tone)
Definition sig_analog.h:182
void(*const get_and_handle_alarms)(void *pvt)
Definition sig_analog.h:234
int(*const start)(void *pvt)
Definition sig_analog.h:161
int(*const callwait)(void *pvt)
Definition sig_analog.h:197
void(*const set_waitingfordt)(void *pvt, struct ast_channel *ast)
Definition sig_analog.h:242
void(*const start_polarityswitch)(void *pvt)
Reset FXS line polarity to IDLE, based on answeronpolarityswitch and hanguponpolarityswitch.
Definition sig_analog.h:172
struct ast_channel *(*const new_ast_channel)(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
Definition sig_analog.h:207
int(*const get_event)(void *pvt)
Definition sig_analog.h:156
void(*const set_needringing)(void *pvt, int value)
Definition sig_analog.h:168
void *(*const get_sigpvt_bridged_channel)(struct ast_channel *chan)
Definition sig_analog.h:235
void(*const set_polarity)(void *pvt, int value)
Set FXS line polarity to 0=IDLE NZ=REVERSED.
Definition sig_analog.h:170
int(*const get_sub_fd)(void *pvt, enum analog_sub sub)
Definition sig_analog.h:236
int(*const wait_event)(void *pvt)
Definition sig_analog.h:157
char dialdest[256]
Definition sig_analog.h:372
unsigned int immediate
Definition sig_analog.h:298
unsigned int immediatering
Definition sig_analog.h:299
unsigned int threewaysilenthold
Definition sig_analog.h:307
unsigned int permcallwaiting
Definition sig_analog.h:301
unsigned int callwaitingdeluxepending
TRUE if a Call Waiting Deluxe action is currently pending.
Definition sig_analog.h:356
unsigned int canpark
Definition sig_analog.h:295
void * chan_pvt
Definition sig_analog.h:275
unsigned int dnd
Definition sig_analog.h:340
unsigned int dahditrcallerid
Definition sig_analog.h:296
struct analog_dialoperation dop
Definition sig_analog.h:280
char lastexten[AST_MAX_EXTENSION]
Definition sig_analog.h:364
int polarityonanswerdelay
Definition sig_analog.h:327
char cid_num[AST_MAX_EXTENSION]
Definition sig_analog.h:331
int redirecting_reason
Definition sig_analog.h:366
unsigned int permhidecallerid
Definition sig_analog.h:303
char * origcid_name
Definition sig_analog.h:378
struct timeval flashtime
Definition sig_analog.h:374
unsigned int outgoing
Definition sig_analog.h:343
unsigned int callwaitingcallerid
Definition sig_analog.h:312
char * origcid_num
Definition sig_analog.h:377
unsigned int ani_wink_time
Definition sig_analog.h:289
enum analog_sigtype outsigmod
Definition sig_analog.h:323
unsigned int usedistinctiveringdetection
Definition sig_analog.h:311
unsigned int answeronpolarityswitch
Definition sig_analog.h:291
unsigned int threewaycalling
Definition sig_analog.h:306
unsigned int pulse
Definition sig_analog.h:305
int echotraining
Definition sig_analog.h:325
char callwait_num[AST_MAX_EXTENSION]
Definition sig_analog.h:360
int msgstate
-1 = unknown, 0 = no messages, 1 = new messages available
Definition sig_analog.h:284
unsigned int callwaiting
Definition sig_analog.h:336
time_t guardtime
Definition sig_analog.h:373
struct timeval polaritydelaytv
Definition sig_analog.h:371
unsigned int hanguponpolarityswitch
Definition sig_analog.h:297
enum analog_dialmode permdialmode
Definition sig_analog.h:304
unsigned int callwaitingdeluxe
Definition sig_analog.h:302
char call_forward[AST_MAX_EXTENSION]
Definition sig_analog.h:379
enum analog_cid_start cid_start
Definition sig_analog.h:329
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
Definition sig_analog.h:351
unsigned int hidecallerid
Definition sig_analog.h:342
unsigned int echobreak
Definition sig_analog.h:341
unsigned int cshactive
Definition sig_analog.h:337
unsigned int callreturn
Definition sig_analog.h:293
struct ast_channel * owner
Definition sig_analog.h:277
unsigned int use_smdi
TRUE if SMDI (Simplified Message Desk Interface) is enabled.
Definition sig_analog.h:316
char lastcid_name[AST_MAX_EXTENSION]
Definition sig_analog.h:363
enum analog_sigtype sig
Definition sig_analog.h:273
unsigned int dialednone
Definition sig_analog.h:338
unsigned int call_qualifier
Definition sig_analog.h:358
char echorest[20]
Definition sig_analog.h:369
unsigned int ani_timeout
Definition sig_analog.h:288
unsigned int lastnumredial
Definition sig_analog.h:300
int fxsoffhookstate
Definition sig_analog.h:282
unsigned int ani_info_digits
Definition sig_analog.h:287
enum analog_dialmode dialmode
Definition sig_analog.h:324
unsigned int cancallforward
Definition sig_analog.h:294
char lastcid_num[AST_MAX_EXTENSION]
Definition sig_analog.h:362
struct analog_subchannel subs[3]
Definition sig_analog.h:279
int cid_signalling
Definition sig_analog.h:326
char finaldial[64]
Definition sig_analog.h:376
unsigned int transfer
Definition sig_analog.h:308
unsigned int transfertobusy
Definition sig_analog.h:309
unsigned int inalarm
Definition sig_analog.h:344
char cid_name[AST_MAX_EXTENSION]
Definition sig_analog.h:332
unsigned int calledsubscriberheld
Definition sig_analog.h:292
char mohsuggest[MAX_MUSICCLASS]
Definition sig_analog.h:330
unsigned int use_callerid
Definition sig_analog.h:310
struct ast_channel * ss_astchan
Definition sig_analog.h:382
unsigned int dialing
Definition sig_analog.h:339
char callwait_name[AST_MAX_EXTENSION]
Definition sig_analog.h:361
struct ast_smdi_interface * smdi_iface
The SMDI interface to get SMDI messages from.
Definition sig_analog.h:318
struct ast_party_caller caller
Definition sig_analog.h:365
unsigned int allocd
Definition sig_analog.h:268
struct ast_frame f
Definition sig_analog.h:265
unsigned int inthreeway
Definition sig_analog.h:266
struct ast_channel * owner
Definition sig_analog.h:264
Structure that contains information regarding a channel in a bridge.
struct ast_channel * chan
Main Channel structure associated with a channel.
ast_callid callid
char exten[AST_MAX_EXTENSION]
struct ast_flags flags
struct ast_party_caller caller
Channel Caller ID information.
Configuration relating to call pickup.
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
struct timeval delivery
enum ast_frame_type frametype
union ast_frame::@239 data
Abstract JSON element (object, array, string, int, ...).
Caller Party information.
Definition channel.h:420
struct ast_party_id id
Caller party ID.
Definition channel.h:422
int ani2
Automatic Number Identification 2 (Info Digits)
Definition channel.h:435
struct ast_party_id ani
Automatic Number Identification (ANI)
Definition channel.h:429
struct ast_party_id id
Connected party ID.
Definition channel.h:460
struct ast_party_name name
Subscriber name.
Definition channel.h:342
struct ast_party_number number
Subscriber phone number.
Definition channel.h:344
int presentation
Q.931 encoded presentation-indicator encoded field.
Definition channel.h:279
unsigned char valid
TRUE if the name information is valid/present.
Definition channel.h:281
char * str
Subscriber name (Malloced)
Definition channel.h:266
int presentation
Q.931 presentation-indicator and screening-indicator encoded fields.
Definition channel.h:297
unsigned char valid
TRUE if the number information is valid/present.
Definition channel.h:299
char * str
Subscriber phone number (Malloced)
Definition channel.h:293
int code
enum AST_REDIRECTING_REASON value for redirection
Definition channel.h:512
struct ast_party_redirecting_reason reason
Reason for the redirection.
Definition channel.h:544
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
Definition channel.h:529
An SMDI message desk message.
Definition smdi.h:65
char calling_st[SMDI_MAX_STATION_NUM_LEN+1]
Definition smdi.h:70
char fwd_st[SMDI_MAX_STATION_NUM_LEN+1]
Definition smdi.h:69
Support for dynamic strings.
Definition strings.h:623
Number structure.
int value
Definition syslog.c:37
static struct test_val b
static struct test_val a
static struct test_val c
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition utils.c: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