Asterisk - The Open Source Telephony Project GIT-master-43bf8a4
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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 ast_debug(1, "Sending callerid. CID_NAME: '%s' CID_NUM: '%s'\n",
394 caller->id.name.str,
396
397 if (cwcid) {
398 p->callwaitcas = 0;
399 }
400
403 }
404 return 0;
405}
406
407#define analog_get_index(ast, p, nullok) _analog_get_index(ast, p, nullok, __PRETTY_FUNCTION__, __LINE__)
408static int _analog_get_index(struct ast_channel *ast, struct analog_pvt *p, int nullok, const char *fname, unsigned long line)
409{
410 int res;
411 if (p->subs[ANALOG_SUB_REAL].owner == ast) {
412 res = ANALOG_SUB_REAL;
413 } else if (p->subs[ANALOG_SUB_CALLWAIT].owner == ast) {
415 } else if (p->subs[ANALOG_SUB_THREEWAY].owner == ast) {
417 } else {
418 res = -1;
419 if (!nullok) {
421 "Unable to get index for '%s' on channel %d (%s(), line %lu)\n",
422 ast ? ast_channel_name(ast) : "", p->channel, fname, line);
423 }
424 }
425 return res;
426}
427
429{
432 }
433
434 /* Return 0 since I think this is unnecessary to do in most cases it is used. Mostly only for ast_dsp */
435 return 0;
436}
437
438static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
439{
441 return analog_callbacks.play_tone(p->chan_pvt, sub, tone);
442 }
443 return -1;
444}
445
446static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
447{
448 p->owner = new_owner;
451 }
452}
453
454static struct ast_channel * analog_new_ast_channel(struct analog_pvt *p, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
455{
456 struct ast_channel *c;
457
459 return NULL;
460 }
461
462 c = analog_callbacks.new_ast_channel(p->chan_pvt, state, startpbx, sub, requestor);
463 if (c) {
464 ast_channel_call_forward_set(c, p->call_forward);
465 }
466 p->subs[sub].owner = c;
467 if (!p->owner) {
469 }
470 return c;
471}
472
473static int analog_set_echocanceller(struct analog_pvt *p, int enable)
474{
477 }
478 return -1;
479}
480
482{
485 }
486 return -1;
487}
488
489static int analog_is_off_hook(struct analog_pvt *p)
490{
493 }
494 return -1;
495}
496
497static int analog_ring(struct analog_pvt *p)
498{
500 return analog_callbacks.ring(p->chan_pvt);
501 }
502 return -1;
503}
504
505static int analog_flash(struct analog_pvt *p)
506{
509 }
510 return -1;
511}
512
513static int analog_start(struct analog_pvt *p)
514{
517 }
518 return -1;
519}
520
521static int analog_dial_digits(struct analog_pvt *p, enum analog_sub sub, struct analog_dialoperation *dop)
522{
524 return analog_callbacks.dial_digits(p->chan_pvt, sub, dop);
525 }
526 return -1;
527}
528
529static int analog_on_hook(struct analog_pvt *p)
530{
533 }
534 return -1;
535}
536
537static void analog_set_outgoing(struct analog_pvt *p, int is_outgoing)
538{
539 p->outgoing = is_outgoing;
541 analog_callbacks.set_outgoing(p->chan_pvt, is_outgoing);
542 }
543}
544
546{
549 }
550 return -1;
551}
552
554{
557 }
558}
559
560static void analog_unlock_private(struct analog_pvt *p)
561{
564 }
565}
566
567static void analog_lock_private(struct analog_pvt *p)
568{
571 }
572}
573
575{
578 } else {
579 /* Fallback to manual avoidance if callback not present. */
581 usleep(1);
583 }
584}
585
586/*!
587 * \internal
588 * \brief Obtain the specified subchannel owner lock if the owner exists.
589 *
590 * \param pvt Analog private struct.
591 * \param sub_idx Subchannel owner to lock.
592 *
593 * \note Assumes the analog_lock_private(pvt->chan_pvt) is already obtained.
594 *
595 * \note
596 * Because deadlock avoidance may have been necessary, you need to confirm
597 * the state of things before continuing.
598 */
599static void analog_lock_sub_owner(struct analog_pvt *pvt, enum analog_sub sub_idx)
600{
601 for (;;) {
602 if (!pvt->subs[sub_idx].owner) {
603 /* No subchannel owner pointer */
604 break;
605 }
606 if (!ast_channel_trylock(pvt->subs[sub_idx].owner)) {
607 /* Got subchannel owner lock */
608 break;
609 }
610 /* We must unlock the private to avoid the possibility of a deadlock */
612 }
613}
614
615static int analog_off_hook(struct analog_pvt *p)
616{
619 }
620 return -1;
621}
622
623static void analog_set_needringing(struct analog_pvt *p, int value)
624{
627 }
628}
629
630#if 0
631static void analog_set_polarity(struct analog_pvt *p, int value)
632{
635 }
636}
637#endif
638
640{
643 }
644}
646{
649 }
650}
651
653{
656 }
657}
658
660{
663 }
664 return -1;
665}
666
667static void analog_cb_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
668{
670 analog_callbacks.handle_dtmf(p->chan_pvt, ast, analog_index, dest);
671 }
672}
673
674static int analog_wink(struct analog_pvt *p, enum analog_sub index)
675{
677 return analog_callbacks.wink(p->chan_pvt, index);
678 }
679 return -1;
680}
681
682static int analog_has_voicemail(struct analog_pvt *p)
683{
686 }
687 return -1;
688}
689
690static int analog_is_dialing(struct analog_pvt *p, enum analog_sub index)
691{
693 return analog_callbacks.is_dialing(p->chan_pvt, index);
694 }
695 return -1;
696}
697
698/*!
699 * \internal
700 * \brief Attempt to transfer 3-way call.
701 *
702 * \param p Analog private structure.
703 *
704 * \note On entry these locks are held: real-call, private, 3-way call.
705 * \note On exit these locks are held: real-call, private.
706 *
707 * \retval 0 on success.
708 * \retval -1 on error.
709 */
711{
712 struct ast_channel *owner_real;
713 struct ast_channel *owner_3way;
714 enum ast_transfer_result xfer_res;
715 int res = 0;
716
717 owner_real = ast_channel_ref(p->subs[ANALOG_SUB_REAL].owner);
719
720 ast_verb(3, "TRANSFERRING %s to %s\n",
721 ast_channel_name(owner_3way), ast_channel_name(owner_real));
722
723 ast_channel_unlock(owner_real);
724 ast_channel_unlock(owner_3way);
726
727 xfer_res = ast_bridge_transfer_attended(owner_3way, owner_real);
728 if (xfer_res != AST_BRIDGE_TRANSFER_SUCCESS) {
730 res = -1;
731 }
732
733 /* Must leave with these locked. */
734 ast_channel_lock(owner_real);
736
737 ast_channel_unref(owner_real);
738 ast_channel_unref(owner_3way);
739
740 return res;
741}
742
743static int analog_update_conf(struct analog_pvt *p)
744{
745 int x;
746 int needconf = 0;
747
748 /* Start with the obvious, general stuff */
749 for (x = 0; x < 3; x++) {
750 /* Look for three way calls */
751 if ((p->subs[x].allocd) && p->subs[x].inthreeway) {
754 }
755 needconf++;
756 } else {
759 }
760 }
761 }
762 ast_debug(1, "Updated conferencing on %d, with %d conference users\n", p->channel, needconf);
763
766 }
767 return 0;
768}
769
770struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor)
771{
772 struct ast_channel *ast;
773
774 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
775 *callwait = (p->owner != NULL);
776
777 if (p->owner) {
779 ast_log(LOG_ERROR, "Unable to alloc subchannel\n");
780 return NULL;
781 }
782 }
783
786 p->owner ? ANALOG_SUB_CALLWAIT : ANALOG_SUB_REAL, requestor);
787 if (!ast) {
789 }
790 return ast;
791}
792
794{
795 int offhook;
796
797 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
798
799 /* If do not disturb, definitely not */
800 if (p->dnd) {
801 return 0;
802 }
803 /* If guard time, definitely not */
804 if (p->guardtime && (time(NULL) < p->guardtime)) {
805 return 0;
806 }
807
808 /* If line is being held, definitely not (don't allow call waitings to an on-hook phone) */
809 if (p->cshactive) {
810 return 0;
811 }
812
813 /* If no owner definitely available */
814 if (!p->owner) {
815 offhook = analog_is_off_hook(p);
816
817 /* TDM FXO card, "onhook" means out of service (no battery on the line) */
818 if ((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || (p->sig == ANALOG_SIG_FXSGS)) {
819#ifdef DAHDI_CHECK_HOOKSTATE
820 if (offhook) {
821 return 1;
822 }
823 return 0;
824#endif
825 /* TDM FXS card, "offhook" means someone took the hook off so it's unavailable! */
826 } else if (offhook) {
827 ast_debug(1, "Channel %d off hook, can't use\n", p->channel);
828 /* Not available when the other end is off hook */
829 return 0;
830 }
831 return 1;
832 }
833
834 /* If it's not an FXO, forget about call wait */
835 if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) {
836 return 0;
837 }
838
839 if (!p->callwaiting) {
840 /* If they don't have call waiting enabled, then for sure they're unavailable at this point */
841 return 0;
842 }
843
845 /* If there is already a call waiting call, then we can't take a second one */
846 return 0;
847 }
848
849 if ((ast_channel_state(p->owner) != AST_STATE_UP) &&
851 /* If the current call is not up, then don't allow the call */
852 return 0;
853 }
855 /* Can't take a call wait when the three way calling hasn't been merged yet. */
856 return 0;
857 }
858 /* We're cool */
859 return 1;
860}
861
862static int analog_stop_callwait(struct analog_pvt *p)
863{
864 p->callwaitcas = 0;
867 }
868 return 0;
869}
870
871static int analog_callwait(struct analog_pvt *p)
872{
876 }
877 return 0;
878}
879
880static void analog_set_callwaiting(struct analog_pvt *p, int callwaiting_enable)
881{
882 p->callwaiting = callwaiting_enable;
884 analog_callbacks.set_callwaiting(p->chan_pvt, callwaiting_enable);
885 }
886}
887
888static void analog_set_cadence(struct analog_pvt *p, struct ast_channel *chan)
889{
892 }
893}
894
895static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
896{
897 p->dialing = is_dialing;
899 analog_callbacks.set_dialing(p->chan_pvt, is_dialing);
900 }
901}
902
903static void analog_set_alarm(struct analog_pvt *p, int in_alarm)
904{
905 p->inalarm = in_alarm;
907 analog_callbacks.set_alarm(p->chan_pvt, in_alarm);
908 }
909}
910
911static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
912{
913 p->ringt = ringt;
916 }
917}
918
919static void analog_set_waitingfordt(struct analog_pvt *p, struct ast_channel *ast)
920{
923 }
924}
925
927{
930 }
931
932 return 0;
933}
934
935static void analog_set_confirmanswer(struct analog_pvt *p, int flag)
936{
939 }
940}
941
943{
946 }
947
948 return 0;
949}
950
951static void analog_cancel_cidspill(struct analog_pvt *p)
952{
955 }
956}
957
958static int analog_confmute(struct analog_pvt *p, int mute)
959{
961 return analog_callbacks.confmute(p->chan_pvt, mute);
962 }
963 return 0;
964}
965
966static void analog_set_pulsedial(struct analog_pvt *p, int flag)
967{
970 }
971}
972
973static int analog_set_linear_mode(struct analog_pvt *p, enum analog_sub sub, int linear_mode)
974{
976 /* Return provides old linear_mode setting or error indication */
977 return analog_callbacks.set_linear_mode(p->chan_pvt, sub, linear_mode);
978 }
979 return -1;
980}
981
982static void analog_set_inthreeway(struct analog_pvt *p, enum analog_sub sub, int inthreeway)
983{
984 p->subs[sub].inthreeway = inthreeway;
987 }
988}
989
990int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout)
991{
992 int res, idx, mysig;
993 char *c, *n, *l;
994 char dest[256]; /* must be same length as p->dialdest */
995
996 ast_debug(1, "CALLING CID_NAME: %s CID_NUM:: %s\n",
997 S_COR(ast_channel_connected(ast)->id.name.valid, ast_channel_connected(ast)->id.name.str, ""),
998 S_COR(ast_channel_connected(ast)->id.number.valid, ast_channel_connected(ast)->id.number.str, ""));
999
1000 ast_copy_string(dest, rdest, sizeof(dest));
1001 ast_copy_string(p->dialdest, rdest, sizeof(p->dialdest));
1002
1003 if ((ast_channel_state(ast) == AST_STATE_BUSY)) {
1005 return 0;
1006 }
1007
1009 ast_log(LOG_WARNING, "analog_call called on %s, neither down nor reserved\n", ast_channel_name(ast));
1010 return -1;
1011 }
1012
1013 p->dialednone = 0;
1014 analog_set_outgoing(p, 1);
1015
1016 mysig = p->sig;
1017 if (p->outsigmod > -1) {
1018 mysig = p->outsigmod;
1019 }
1020
1021 switch (mysig) {
1022 case ANALOG_SIG_FXOLS:
1023 case ANALOG_SIG_FXOGS:
1024 case ANALOG_SIG_FXOKS:
1025 if (p->owner == ast) {
1026 /* Normal ring, on hook */
1027
1028 /* Don't send audio while on hook, until the call is answered */
1029 analog_set_dialing(p, 1);
1030 analog_set_cadence(p, ast); /* and set p->cidrings */
1031
1032 /* nick@dccinc.com 4/3/03 mods to allow for deferred dialing */
1033 c = strchr(dest, '/');
1034 if (c) {
1035 c++;
1036 }
1037 if (c && (strlen(c) < p->stripmsd)) {
1038 ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1039 c = NULL;
1040 }
1041 if (c && (strlen(c) > sizeof(p->dop.dialstr) - 3 /* "Tw\0" */)) {
1042 ast_log(LOG_WARNING, "Number '%s' is longer than %d bytes\n", c, (int)sizeof(p->dop.dialstr) - 2);
1043 c = NULL;
1044 }
1045 if (c) {
1047 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "Tw%s", c);
1048 ast_debug(1, "FXO: setup deferred dialstring: %s\n", c);
1049 } else {
1050 p->dop.dialstr[0] = '\0';
1051 }
1052
1053 if (analog_ring(p)) {
1054 ast_log(LOG_WARNING, "Unable to ring phone: %s\n", strerror(errno));
1055 return -1;
1056 }
1057 analog_set_dialing(p, 1);
1058 } else {
1059 /* Call waiting call */
1060 if (ast_channel_connected(ast)->id.number.valid && ast_channel_connected(ast)->id.number.str) {
1062 } else {
1063 p->callwait_num[0] = '\0';
1064 }
1065 if (ast_channel_connected(ast)->id.name.valid && ast_channel_connected(ast)->id.name.str) {
1067 } else {
1068 p->callwait_name[0] = '\0';
1069 }
1070
1071 /* Call waiting tone instead */
1072 if (analog_callwait(p)) {
1073 return -1;
1074 }
1075 /* Make ring-back */
1077 ast_log(LOG_WARNING, "Unable to generate call-wait ring-back on channel %s\n", ast_channel_name(ast));
1078 }
1079
1080 }
1081
1082 /* Name and Number */
1085 if (l) {
1086 ast_copy_string(p->lastcid_num, l, sizeof(p->lastcid_num));
1087 } else {
1088 p->lastcid_num[0] = '\0';
1089 }
1090 if (n) {
1091 ast_copy_string(p->lastcid_name, n, sizeof(p->lastcid_name));
1092 } else {
1093 p->lastcid_name[0] = '\0';
1094 }
1095
1096 if (p->use_callerid) {
1097 const char *qual_var;
1098
1099 /* Caller ID Name and Number */
1100 p->caller.id.name.str = p->lastcid_name;
1101 p->caller.id.number.str = p->lastcid_num;
1106
1107 /* Redirecting Reason */
1109
1110 /* Call Qualifier */
1111 ast_channel_lock(ast);
1112 /* XXX In the future, we may want to make this a CALLERID or CHANNEL property and fetch it from there. */
1113 qual_var = pbx_builtin_getvar_helper(ast, "CALL_QUALIFIER");
1114 p->call_qualifier = ast_true(qual_var) ? 1 : 0;
1115 ast_channel_unlock(ast);
1116 }
1117
1119 idx = analog_get_index(ast, p, 0);
1120 if (idx > -1) {
1121 struct ast_cc_config_params *cc_params;
1122
1123 /* This is where the initial ringing frame is queued for an analog call.
1124 * As such, this is a great time to offer CCNR to the caller if it's available.
1125 */
1126 cc_params = ast_channel_get_cc_config_params(p->subs[idx].owner);
1127 if (cc_params) {
1128 switch (ast_get_cc_monitor_policy(cc_params)) {
1130 break;
1136 break;
1137 }
1138 }
1140 }
1141 break;
1142 case ANALOG_SIG_FXSLS:
1143 case ANALOG_SIG_FXSGS:
1144 case ANALOG_SIG_FXSKS:
1146 ast_debug(1, "Ignore possible polarity reversal on line seizure\n");
1148 }
1149 /* fall through */
1150 case ANALOG_SIG_EMWINK:
1151 case ANALOG_SIG_EM:
1152 case ANALOG_SIG_EM_E1:
1153 case ANALOG_SIG_FEATD:
1154 case ANALOG_SIG_FEATDMF:
1155 case ANALOG_SIG_E911:
1158 case ANALOG_SIG_FEATB:
1159 case ANALOG_SIG_SFWINK:
1160 case ANALOG_SIG_SF:
1165 c = strchr(dest, '/');
1166 if (c) {
1167 c++;
1168 } else {
1169 c = "";
1170 }
1171 if (strlen(c) < p->stripmsd) {
1172 ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1173 return -1;
1174 }
1175 res = analog_start(p);
1176 if (res < 0) {
1177 if (errno != EINPROGRESS) {
1178 return -1;
1179 }
1180 }
1181 ast_debug(1, "Dialing '%s'\n", c);
1183
1184 c += p->stripmsd;
1185
1186 switch (mysig) {
1187 case ANALOG_SIG_FEATD:
1189 if (l) {
1190 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T*%s*%s*", l, c);
1191 } else {
1192 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T**%s*", c);
1193 }
1194 break;
1195 case ANALOG_SIG_FEATDMF:
1197 if (l) {
1198 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*00%s#*%s#", l, c);
1199 } else {
1200 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*02#*%s#", c);
1201 }
1202 break;
1204 {
1205 const char *cic = "", *ozz = "";
1206
1207 /* If you have to go through a Tandem Access point you need to use this */
1208#ifndef STANDALONE
1209 ozz = pbx_builtin_getvar_helper(p->owner, "FEATDMF_OZZ");
1210 if (!ozz) {
1211 ozz = analog_defaultozz;
1212 }
1213 cic = pbx_builtin_getvar_helper(p->owner, "FEATDMF_CIC");
1214 if (!cic) {
1215 cic = analog_defaultcic;
1216 }
1217#endif
1218 if (!ozz || !cic) {
1219 ast_log(LOG_WARNING, "Unable to dial channel of type feature group D MF tandem access without CIC or OZZ set\n");
1220 return -1;
1221 }
1222 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s%s#", ozz, cic);
1223 snprintf(p->finaldial, sizeof(p->finaldial), "M*%s#", c);
1224 p->whichwink = 0;
1225 }
1226 break;
1227 case ANALOG_SIG_E911:
1228 ast_copy_string(p->dop.dialstr, "M*911#", sizeof(p->dop.dialstr));
1229 break;
1231 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%s", c);
1232 break;
1234 case ANALOG_SIG_FEATB:
1235 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s#", c);
1236 break;
1237 default:
1238 if (p->pulse) {
1239 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%sw", c);
1240 } else {
1241 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T%sw", c);
1242 }
1243 break;
1244 }
1245
1246 if (p->echotraining && (strlen(p->dop.dialstr) > 4)) {
1247 memset(p->echorest, 'w', sizeof(p->echorest) - 1);
1248 strcpy(p->echorest + (p->echotraining / 400) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
1249 p->echorest[sizeof(p->echorest) - 1] = '\0';
1250 p->echobreak = 1;
1251 p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
1252 } else {
1253 p->echobreak = 0;
1254 }
1256 if (!res) {
1257 if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
1258 analog_on_hook(p);
1259 return -1;
1260 }
1261 } else {
1262 ast_debug(1, "Deferring dialing...\n");
1263 }
1264 analog_set_dialing(p, 1);
1265 if (ast_strlen_zero(c)) {
1266 p->dialednone = 1;
1267 }
1269 break;
1270 default:
1271 ast_debug(1, "not yet implemented\n");
1272 return -1;
1273 }
1274 return 0;
1275}
1276
1277int analog_hangup(struct analog_pvt *p, struct ast_channel *ast)
1278{
1279 int res;
1280 int idx, x;
1281
1282 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1283 if (!ast_channel_tech_pvt(ast)) {
1284 ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
1285 return 0;
1286 }
1287
1288 idx = analog_get_index(ast, p, 1);
1289
1290 x = 0;
1291 if (p->origcid_num) {
1292 ast_copy_string(p->cid_num, p->origcid_num, sizeof(p->cid_num));
1294 p->origcid_num = NULL;
1295 }
1296 if (p->origcid_name) {
1297 ast_copy_string(p->cid_name, p->origcid_name, sizeof(p->cid_name));
1299 p->origcid_name = NULL;
1300 }
1301
1303
1304 ast_debug(1, "Hangup: channel: %d index = %d, normal = %d, callwait = %d, thirdcall = %d\n",
1306 if (idx > -1) {
1307 /* Real channel, do some fixup */
1308 p->cshactive = 0;
1309 p->subs[idx].owner = NULL;
1311 analog_set_linear_mode(p, idx, 0);
1312 switch (idx) {
1313 case ANALOG_SUB_REAL:
1315 ast_debug(1, "Normal call hung up with both three way call and a call waiting call in place?\n");
1317 /* We had flipped over to answer a callwait and now it's gone */
1318 ast_debug(1, "We were flipped over to the callwait, moving back and not owning.\n");
1319 /* Move to the call-wait, but un-own us until they flip back. */
1323 } else {
1324 /* The three way hung up, but we still have a call wait */
1325 ast_debug(1, "We were in the threeway and have a callwait still. Ditching the threeway.\n");
1329 /* This was part of a three way call. Immediately make way for
1330 another call */
1331 ast_debug(1, "Call was complete, setting owner to former third call\n");
1334 } else {
1335 /* This call hasn't been completed yet... Set owner to NULL */
1336 ast_debug(1, "Call was incomplete, setting owner to NULL\n");
1338 }
1339 }
1340 } else if (p->subs[ANALOG_SUB_CALLWAIT].allocd) {
1341 /* Need to hold the lock for real-call, private, and call-waiting call */
1343 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
1344 /* The call waiting call disappeared. */
1346 break;
1347 }
1348
1349 /* Move to the call-wait and switch back to them. */
1355 }
1357 /* Unlock the call-waiting call that we swapped to real-call. */
1359 } else if (p->subs[ANALOG_SUB_THREEWAY].allocd) {
1363 /* This was part of a three way call. Immediately make way for
1364 another call */
1365 ast_debug(1, "Call was complete, setting owner to former third call\n");
1368 } else {
1369 /* This call hasn't been completed yet... Set owner to NULL */
1370 ast_debug(1, "Call was incomplete, setting owner to NULL\n");
1372 }
1373 }
1374 break;
1376 /* Ditch the holding callwait call, and immediately make it available */
1378 /* Need to hold the lock for call-waiting call, private, and 3-way call */
1380
1381 /* This is actually part of a three way, placed on hold. Place the third part
1382 on music on hold now */
1383 if (p->subs[ANALOG_SUB_THREEWAY].owner) {
1385 }
1387 /* Make it the call wait now */
1390 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1391 /* Unlock the 3-way call that we swapped to call-waiting call. */
1393 }
1394 } else {
1396 }
1397 break;
1399 /* Need to hold the lock for 3-way call, private, and call-waiting call */
1402 /* The other party of the three way call is currently in a call-wait state.
1403 Start music on hold for them, and take the main guy out of the third call */
1405 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1407 }
1408 }
1409 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1411 }
1413 /* If this was part of a three way call index, let us make
1414 another three way call */
1416 break;
1417 default:
1418 /*
1419 * Should never happen.
1420 * This wasn't any sort of call, so how are we an index?
1421 */
1422 ast_log(LOG_ERROR, "Index found but not any type of call?\n");
1423 break;
1424 }
1425 }
1426
1432 analog_set_outgoing(p, 0);
1433 p->onhooktime = time(NULL);
1434 p->cidrings = 1;
1435
1436 /* Perform low level hangup if no owner left */
1437 res = analog_on_hook(p);
1438 if (res < 0) {
1439 ast_log(LOG_WARNING, "Unable to hangup line %s\n", ast_channel_name(ast));
1440 }
1441 switch (p->sig) {
1442 case ANALOG_SIG_FXOGS:
1443 case ANALOG_SIG_FXOLS:
1444 case ANALOG_SIG_FXOKS:
1445 /* If they're off hook, try playing congestion */
1446 if (analog_is_off_hook(p)) {
1449 } else {
1451 }
1452 break;
1453 case ANALOG_SIG_FXSGS:
1454 case ANALOG_SIG_FXSLS:
1455 case ANALOG_SIG_FXSKS:
1456 /* Make sure we're not made available for at least two seconds assuming
1457 we were actually used for an inbound or outbound call. */
1459 time(&p->guardtime);
1460 p->guardtime += 2;
1461 }
1462 break;
1463 default:
1465 break;
1466 }
1467
1469
1470 x = 0;
1471 ast_channel_setoption(ast,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0);
1472 ast_channel_setoption(ast,AST_OPTION_TDD,&x,sizeof(char),0);
1473 p->callwaitcas = 0;
1475 /* In theory, the below is not necessary since we set hidecallerid = permhidecaller when calls start,
1476 * but this ensures the setting is defaulted properly when channels are idle, too. */
1478 analog_set_dialing(p, 0);
1481 }
1482
1484
1485 ast_verb(3, "Hanging up on '%s'\n", ast_channel_name(ast));
1486
1487 return 0;
1488}
1489
1490int analog_answer(struct analog_pvt *p, struct ast_channel *ast)
1491{
1492 int res = 0;
1493 int idx;
1494 int oldstate = ast_channel_state(ast);
1495
1496 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1498 idx = analog_get_index(ast, p, 1);
1499 if (idx < 0) {
1500 idx = ANALOG_SUB_REAL;
1501 }
1502 switch (p->sig) {
1503 case ANALOG_SIG_FXSLS:
1504 case ANALOG_SIG_FXSGS:
1505 case ANALOG_SIG_FXSKS:
1507 /* Fall through */
1508 case ANALOG_SIG_EM:
1509 case ANALOG_SIG_EM_E1:
1510 case ANALOG_SIG_EMWINK:
1511 case ANALOG_SIG_FEATD:
1512 case ANALOG_SIG_FEATDMF:
1514 case ANALOG_SIG_E911:
1517 case ANALOG_SIG_FEATB:
1518 case ANALOG_SIG_SF:
1519 case ANALOG_SIG_SFWINK:
1523 case ANALOG_SIG_FXOLS:
1524 case ANALOG_SIG_FXOGS:
1525 case ANALOG_SIG_FXOKS:
1526 /* Pick up the line */
1527 ast_debug(1, "Took %s off hook\n", ast_channel_name(ast));
1528 if (p->hanguponpolarityswitch) {
1529 gettimeofday(&p->polaritydelaytv, NULL);
1530 }
1531 res = analog_off_hook(p);
1532 analog_play_tone(p, idx, -1);
1533 analog_set_dialing(p, 0);
1534 if ((idx == ANALOG_SUB_REAL) && p->subs[ANALOG_SUB_THREEWAY].inthreeway) {
1535 if (oldstate == AST_STATE_RINGING) {
1536 ast_debug(1, "Finally swapping real and threeway\n");
1540 }
1541 }
1542
1543 switch (p->sig) {
1544 case ANALOG_SIG_FXSLS:
1545 case ANALOG_SIG_FXSKS:
1546 case ANALOG_SIG_FXSGS:
1549 break;
1550 case ANALOG_SIG_FXOLS:
1551 case ANALOG_SIG_FXOKS:
1552 case ANALOG_SIG_FXOGS:
1554 break;
1555 default:
1556 break;
1557 }
1558 break;
1559 default:
1560 ast_log(LOG_WARNING, "Don't know how to answer signalling %d (channel %d)\n", p->sig, p->channel);
1561 res = -1;
1562 break;
1563 }
1565 return res;
1566}
1567
1568static int analog_handles_digit(struct ast_frame *f)
1569{
1570 char subclass = toupper(f->subclass.integer);
1571
1572 switch (subclass) {
1573 case '1':
1574 case '2':
1575 case '3':
1576 case '4':
1577 case '5':
1578 case '6':
1579 case '7':
1580 case '9':
1581 case 'A':
1582 case 'B':
1583 case 'C':
1584 case 'D':
1585 case 'E':
1586 case 'F':
1587 return 1;
1588 default:
1589 return 0;
1590 }
1591}
1592
1599};
1600
1601static const char *callwaiting_deluxe_optname(int option)
1602{
1603 switch (option) {
1604 case CWD_CONFERENCE:
1605 return "CONFERENCE";
1606 case CWD_HOLD:
1607 return "HOLD";
1608 case CWD_DROP:
1609 return "DROP";
1610 case CWD_ANNOUNCEMENT:
1611 return "ANNOUNCEMENT";
1612 case CWD_FORWARD:
1613 return "FORWARD";
1614 default:
1615 return "DEFAULT";
1616 }
1617}
1618
1619int analog_callwaiting_deluxe(struct analog_pvt *p, int option)
1620{
1621 const char *announce_var;
1622 char announcement[PATH_MAX];
1623
1624 ast_debug(1, "Handling Call Waiting on channel %d with option %c: treatment %s\n", p->channel, option, callwaiting_deluxe_optname(option));
1625
1626 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
1627 /* This can happen if the caller hook flashes and the call waiting hangs up before the CWD timer expires (1 second) */
1628 ast_debug(1, "Call waiting call disappeared before it could be handled?\n");
1629 return -1;
1630 }
1631
1633 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
1634 ast_log(LOG_WARNING, "Whoa, the call-waiting call disappeared.\n");
1635 return -1;
1636 }
1637
1638 /* Note that when p->callwaitingdeluxepending, dahdi_write will drop incoming frames to the channel,
1639 * since the user shouldn't hear anything after flashing until either a DTMF has been received
1640 * or it's been a second and the decision is made automatically. */
1641
1642 switch (option) {
1643 case CWD_CONFERENCE:
1644 /* We should never have a call waiting if we have a 3-way anyways, but check just in case,
1645 * there better be no existing SUB_THREEWAY since we're going to make one (and then swap the call wait to it) */
1646 if (p->subs[ANALOG_SUB_THREEWAY].owner) {
1648 ast_log(LOG_ERROR, "Already have a 3-way call on channel %d, can't conference!\n", p->channel);
1649 return -1;
1650 }
1651
1652 /* To conference the incoming call, swap it from SUB_CALLWAIT to SUB_THREEWAY,
1653 * and then the existing 3-way logic will ensure that flashing again will drop the call waiting */
1657
1658 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));
1661
1665 /* Stop the ringing on the call wait channel (yeah, apparently this is how it's done) */
1668 }
1670
1671 ast_channel_unlock(p->subs[ANALOG_SUB_THREEWAY].owner); /* Unlock what was originally SUB_CALLWAIT */
1672 break;
1673 case CWD_HOLD: /* The CI-7112 Visual Director sends "HOLD" for "Play hold message" rather than "ANNOUNCEMENT". For default behavior, nothing is actually sent. */
1674 case CWD_ANNOUNCEMENT:
1675 /* We can't just call ast_streamfile here, this thread isn't responsible for media on the call waiting channel.
1676 * Indicate to the dialing channel in app_dial that it needs to play media.
1677 *
1678 * This is a lot easier than other ways of trying to send early media to the channel
1679 * (such as every call from the core to dahdi_read, sending the channel one frame of the audio file, etc.)
1680 */
1681
1682 /* There's not a particularly good stock audio prompt to use here. The Pat Fleet library has some better
1683 * ones but we want one that is also in the default Allison Smith library. "One moment please" works okay.
1684 * Check if a variable containing the prompt to use was specified on the call waiting channel, and
1685 * fall back to a reasonable default if not. */
1686
1687 /* The SUB_CALLWAIT channel is already locked here, no need to lock and unlock to get the variable. */
1688 announce_var = pbx_builtin_getvar_helper(p->subs[ANALOG_SUB_CALLWAIT].owner, "CALLWAITDELUXEANNOUNCEMENT");
1689 ast_copy_string(announcement, S_OR(announce_var, "one-moment-please"), sizeof(announcement));
1690 ast_debug(2, "Call Waiting Deluxe announcement for %s: %s\n", ast_channel_name(p->subs[ANALOG_SUB_CALLWAIT].owner), announcement);
1692 /* Tell app_dial what file to play. */
1693 ast_queue_control_data(p->subs[ANALOG_SUB_CALLWAIT].owner, AST_CONTROL_PLAYBACK_BEGIN, announcement, strlen(announcement) + 1);
1694 /* Unlike all the other options, the call waiting is still active with this option,
1695 * so we don't call analog_stop_callwait(p)
1696 * The call waiting will continue to be here, and at some later point the user can flash again and choose a finalizing option
1697 * (or even queue the announcement again... and again... and again...)
1698 */
1699 break;
1700 case CWD_FORWARD:
1701 /* Go away, call waiting, call again some other day... */
1703 /* Can't use p->call_forward exten because that's for *72 forwarding, and sig_analog doesn't
1704 * have a Busy/Don't Answer call forwarding exten internally, so let the dialplan deal with it.
1705 * by sending the call to the 'f' extension.
1706 */
1707 ast_channel_call_forward_set(p->subs[ANALOG_SUB_CALLWAIT].owner, "f");
1709 /* app_dial already has a verbose message for forwarding, so we don't really need one here also since that does the job */
1710 break;
1711 case CWD_DROP:
1712 /* Fall through: logic is identical to hold, except we drop the original call right after we swap. */
1713 default:
1714 /* Swap to call-wait, same as with the non-deluxe call waiting handling. */
1718 ast_debug(1, "Making %s the new owner\n", ast_channel_name(p->owner));
1722 }
1724
1725 if (option == CWD_DROP) {
1726 /* Disconnect the previous call (the original call is now the SUB_CALLWAIT since we swapped above) */
1728 ast_verb(3, "Dropping original call and swapping to call waiting on %s\n", ast_channel_name(p->subs[ANALOG_SUB_REAL].owner));
1729 } else {
1730 /* Start music on hold if appropriate */
1733 }
1734 ast_verb(3, "Holding original call and swapping to call waiting on %s\n", ast_channel_name(p->subs[ANALOG_SUB_REAL].owner));
1735 }
1736
1737 /* Stop ringing on the incoming call */
1740
1741 /* Unlock the call-waiting call that we swapped to real-call. */
1743 }
1745 return 0;
1746}
1747
1748void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub idx, struct ast_frame **dest)
1749{
1750 struct ast_frame *f = *dest;
1751
1752 ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n",
1753 f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End",
1754 (unsigned)f->subclass.integer, f->subclass.integer, ast_channel_name(ast));
1755
1757 if (f->frametype == AST_FRAME_DTMF_END) {
1758 ast_debug(1, "Confirm answer on %s!\n", ast_channel_name(ast));
1759 /* Upon receiving a DTMF digit, consider this an answer confirmation instead
1760 of a DTMF digit */
1763 /* Reset confirmanswer so DTMF's will behave properly for the duration of the call */
1765 } else {
1766 p->subs[idx].f.frametype = AST_FRAME_NULL;
1767 p->subs[idx].f.subclass.integer = 0;
1768 }
1769 *dest = &p->subs[idx].f;
1770 } else if (p->callwaitcas) {
1771 if (f->frametype == AST_FRAME_DTMF_END) {
1772 if ((f->subclass.integer == 'A') || (f->subclass.integer == 'D')) {
1773 ast_debug(1, "Got some DTMF, but it's for the CAS\n");
1774 p->caller.id.name.str = p->callwait_name;
1776 analog_send_callerid(p, 1, &p->caller);
1777 }
1778 if (analog_handles_digit(f)) {
1779 p->callwaitcas = 0;
1780 }
1781 }
1782 p->subs[idx].f.frametype = AST_FRAME_NULL;
1783 p->subs[idx].f.subclass.integer = 0;
1784 *dest = &p->subs[idx].f;
1785 } else if (p->callwaitingdeluxepending) {
1786 if (f->frametype == AST_FRAME_DTMF_END) {
1787 unsigned int mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
1789
1790 /* This is the case where a user explicitly took action (made a decision)
1791 * for Call Waiting Deluxe.
1792 * Because we already handled the hook flash, if the user doesn't do
1793 * anything within a second, then we still need to eventually take
1794 * the default action (swap) for the call waiting.
1795 *
1796 * dahdi_write will also drop audio if callwaitingdeluxepending is set HIGH,
1797 * and also check if flashtime hits 1000, in which case it will set the flag LOW and then take the
1798 * default action, e.g. analog_callwaiting_deluxe(p, 0);
1799 */
1800
1801 /* Slightly less than 1000, so there's no chance of a race condition
1802 * between do_monitor when it sees flashtime hitting 1000 and us. */
1803 if (mssinceflash > 990) {
1804 /* This was more than a second ago, clear the flag and process normally. */
1805 /* Because another thread has to monitor channels with pending CWDs,
1806 * in theory, we shouldn't need to check this here. */
1807 ast_debug(1, "It's been %u ms since the last flash, this is not a Call Waiting Deluxe DTMF\n", mssinceflash);
1808 analog_cb_handle_dtmf(p, ast, idx, dest);
1809 return;
1810 }
1811 /* Okay, actually do something now. */
1812 switch (f->subclass.integer) {
1813 case CWD_CONFERENCE:
1814 case CWD_HOLD:
1815 case CWD_DROP:
1816 case CWD_ANNOUNCEMENT:
1817 case CWD_FORWARD:
1818 ast_debug(1, "Got some DTMF, but it's for Call Waiting Deluxe: %c\n", f->subclass.integer);
1820 break;
1821 default:
1822 ast_log(LOG_WARNING, "Invalid Call Waiting Deluxe option (%c), using default\n", f->subclass.integer);
1824 }
1825 }
1826 p->subs[idx].f.frametype = AST_FRAME_NULL;
1827 p->subs[idx].f.subclass.integer = 0;
1828 *dest = &p->subs[idx].f;
1829 } else {
1830 analog_cb_handle_dtmf(p, ast, idx, dest);
1831 }
1832}
1833
1834static int analog_my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms)
1835{
1836 char c;
1837
1838 *str = 0; /* start with empty output buffer */
1839 for (;;) {
1840 /* Wait for the first digit (up to specified ms). */
1841 c = ast_waitfordigit(chan, ms);
1842 /* if timeout, hangup or error, return as such */
1843 if (c < 1) {
1844 return c;
1845 }
1846 *str++ = c;
1847 *str = 0;
1848 if (strchr(term, c)) {
1849 return 1;
1850 }
1851 }
1852}
1853
1854static int analog_handle_notify_message(struct ast_channel *chan, struct analog_pvt *p, int cid_flags, int neon_mwievent)
1855{
1857 analog_callbacks.handle_notify_message(chan, p->chan_pvt, cid_flags, neon_mwievent);
1858 return 0;
1859 }
1860 return -1;
1861}
1862
1864{
1867 }
1868}
1869
1871{
1874 }
1875}
1876
1877static int analog_distinctive_ring(struct ast_channel *chan, struct analog_pvt *p, int idx, int *ringdata)
1878{
1880 return 0;
1881 }
1883 return analog_callbacks.distinctive_ring(chan, p->chan_pvt, idx, ringdata);
1884 }
1885 return -1;
1886
1887}
1888
1890{
1893 }
1894}
1895
1896static void *analog_get_bridged_channel(struct ast_channel *chan)
1897{
1900 }
1901 return NULL;
1902}
1903
1904static int analog_get_sub_fd(struct analog_pvt *p, enum analog_sub sub)
1905{
1908 }
1909 return -1;
1910}
1911
1912#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))
1913
1914static int analog_canmatch_featurecode(const char *pickupexten, const char *exten)
1915{
1916 int extlen = strlen(exten);
1917 if (!extlen) {
1918 return 1;
1919 }
1920 if (extlen < strlen(pickupexten) && !strncmp(pickupexten, exten, extlen)) {
1921 return 1;
1922 }
1923 if (exten[0] == '#' && extlen < 2) {
1924 return 1; /* Could match ## */
1925 }
1926 /* hardcoded features are *60, *67, *69, *70, *72, *73, *78, *79, *82, *0 */
1927 if (exten[0] == '*' && extlen < 3) {
1928 if (extlen == 1) {
1929 return 1;
1930 }
1931 /* "*0" should be processed before it gets here */
1932 switch (exten[1]) {
1933 case '6':
1934 case '7':
1935 case '8':
1936 return 1;
1937 }
1938 }
1939 return 0;
1940}
1941
1942static void *__analog_ss_thread(void *data)
1943{
1944 struct analog_pvt *p = data;
1945 struct ast_channel *chan = p->ss_astchan;
1946 char exten[AST_MAX_EXTENSION] = "";
1947 char exten2[AST_MAX_EXTENSION] = "";
1948 char dtmfcid[300];
1949 char dtmfbuf[300];
1950 char namebuf[ANALOG_MAX_CID];
1951 char numbuf[ANALOG_MAX_CID];
1952 char *name = NULL, *number = NULL;
1953 int flags = 0;
1954 struct ast_smdi_md_message *smdi_msg = NULL;
1955 int timeout;
1956 int getforward = 0;
1957 char *s1, *s2;
1958 int len = 0;
1959 int res;
1960 int idx;
1961 ast_callid callid;
1962 RAII_VAR(struct ast_features_pickup_config *, pickup_cfg, NULL, ao2_cleanup);
1963 const char *pickupexten;
1964
1966
1967 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1968
1969 ast_assert(chan != NULL);
1970
1971 if ((callid = ast_channel_callid(chan))) {
1973 }
1974
1975 /* in the bizarre case where the channel has become a zombie before we
1976 even get started here, abort safely
1977 */
1978 if (!ast_channel_tech_pvt(chan)) {
1979 ast_log(LOG_WARNING, "Channel became a zombie before simple switch could be started (%s)\n", ast_channel_name(chan));
1980 ast_hangup(chan);
1981 goto quit;
1982 }
1983
1984 ast_verb(3, "Starting simple switch on '%s'\n", ast_channel_name(chan));
1985 idx = analog_get_index(chan, p, 0);
1986 if (idx < 0) {
1987 ast_hangup(chan);
1988 goto quit;
1989 }
1990
1991 ast_channel_lock(chan);
1992 pickup_cfg = ast_get_chan_features_pickup_config(chan);
1993 if (!pickup_cfg) {
1994 ast_log(LOG_ERROR, "Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n");
1995 pickupexten = "";
1996 } else {
1997 pickupexten = ast_strdupa(pickup_cfg->pickupexten);
1998 }
1999 ast_channel_unlock(chan);
2000
2002 switch (p->sig) {
2003 case ANALOG_SIG_FEATD:
2004 case ANALOG_SIG_FEATDMF:
2006 case ANALOG_SIG_E911:
2008 case ANALOG_SIG_FEATB:
2009 case ANALOG_SIG_EMWINK:
2013 case ANALOG_SIG_SFWINK:
2014 if (analog_wink(p, idx))
2015 goto quit;
2016 /* Fall through */
2017 case ANALOG_SIG_EM:
2018 case ANALOG_SIG_EM_E1:
2019 case ANALOG_SIG_SF:
2021 res = analog_play_tone(p, idx, -1);
2022
2024
2025 /* set digit mode appropriately */
2026 if (ANALOG_NEED_MFDETECT(p)) {
2028 } else {
2030 }
2031
2032 memset(dtmfbuf, 0, sizeof(dtmfbuf));
2033 /* Wait for the first digit only if immediate=no */
2034 if (!p->immediate) {
2035 /* Wait for the first digit (up to 5 seconds). */
2036 res = ast_waitfordigit(chan, 5000);
2037 } else {
2038 res = 0;
2039 }
2040 if (res > 0) {
2041 /* save first char */
2042 dtmfbuf[0] = res;
2043 switch (p->sig) {
2044 case ANALOG_SIG_FEATD:
2046 res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
2047 if (res > 0) {
2048 res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
2049 }
2050 if (res < 1) {
2052 }
2053 break;
2055 res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
2056 if (res < 1) {
2058 }
2059 if (analog_wink(p, idx)) {
2060 goto quit;
2061 }
2062 dtmfbuf[0] = 0;
2063 /* Wait for the first digit (up to 5 seconds). */
2064 res = ast_waitfordigit(chan, 5000);
2065 if (res <= 0) {
2066 break;
2067 }
2068 dtmfbuf[0] = res;
2069 /* fall through intentionally */
2070 case ANALOG_SIG_FEATDMF:
2071 case ANALOG_SIG_E911:
2074 res = analog_my_getsigstr(chan, dtmfbuf + 1, "#ABC", 3000);
2075 /* if international CAC, do it again to get real ANI */
2076 if ((p->sig == ANALOG_SIG_FEATDMF) && (dtmfbuf[1] != '0')
2077 && (strlen(dtmfbuf) != 14)) {
2078 if (analog_wink(p, idx)) {
2079 goto quit;
2080 }
2081 dtmfbuf[0] = 0;
2082 /* Wait for the first digit (up to 5 seconds). */
2083 res = ast_waitfordigit(chan, 5000);
2084 if (res <= 0) {
2085 break;
2086 }
2087 dtmfbuf[0] = res;
2088 res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
2089 }
2090 if (res > 0) {
2091 /* if E911, take off hook */
2092 if (p->sig == ANALOG_SIG_E911) {
2093 analog_off_hook(p);
2094 }
2095 if (p->sig != ANALOG_SIG_FGC_CAMAMF) {
2096 /* CAMA signaling (CAMA and CAMAMF) are handled in an if block below.
2097 * Everything else, process here. */
2098 res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "#", 3000);
2099 }
2100 }
2101 if (res < 1) {
2103 }
2104 break;
2105 case ANALOG_SIG_FEATB:
2107 res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
2108 if (res < 1) {
2110 }
2111 break;
2112 case ANALOG_SIG_EMWINK:
2113 /* if we received a '*', we are actually receiving Feature Group D
2114 dial syntax, so use that mode; otherwise, fall through to normal
2115 mode
2116 */
2117 if (res == '*') {
2118 res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
2119 if (res > 0) {
2120 res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
2121 }
2122 if (res < 1) {
2124 }
2125 break;
2126 }
2127 default:
2128 /* If we got the first digit, get the rest */
2129 len = 1;
2130 dtmfbuf[len] = '\0';
2131 while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
2132 if (ast_exists_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
2133 timeout = analog_get_matchdigit_timeout(p);
2134 } else {
2135 timeout = analog_get_interdigit_timeout(p);
2136 }
2137 res = ast_waitfordigit(chan, timeout);
2138 if (res < 0) {
2139 ast_debug(1, "waitfordigit returned < 0...\n");
2140 ast_hangup(chan);
2141 goto quit;
2142 } else if (res) {
2143 dtmfbuf[len++] = res;
2144 dtmfbuf[len] = '\0';
2145 } else {
2146 break;
2147 }
2148 }
2149 break;
2150 }
2151 }
2152 if (res == -1) {
2153 ast_log(LOG_WARNING, "getdtmf on channel %d: %s\n", p->channel, strerror(errno));
2154 ast_hangup(chan);
2155 goto quit;
2156 } else if (res < 0) {
2157 ast_debug(1, "Got hung up before digits finished\n");
2158 ast_hangup(chan);
2159 goto quit;
2160 }
2161
2162 if (p->sig == ANALOG_SIG_FGC_CAMA || p->sig == ANALOG_SIG_FGC_CAMAMF) {
2163 /* This if block is where we process ANI for CAMA */
2164
2165 char anibuf[100];
2166 struct ast_party_caller *caller;
2167
2168 /* cnoffset is the point at which we pull the calling number out
2169 * of anibuf. Must be the number of ani_info_digits + 1 to account
2170 * for the KP, which is considered a digit. */
2171
2172 /* The 1XB with ANI-B will send a full 10 digits
2173 * or 2 digits in case of ANI failure.
2174 * (CD-95811-01 Section II, page 10)
2175 * 10 digit string example: *08320123#
2176 * 2 digit string example: *2
2177 * KP (*) and ST (#) are considered to be digits */
2178
2179 int cnoffset = p->ani_info_digits + 1;
2180
2181 /* This is how long to wait before the wink to start ANI spill
2182 * Pulled from chan_dahdi.conf, default is 1000ms */
2183 if (ast_safe_sleep(chan,p->ani_wink_time) == -1) {
2184 ast_hangup(chan);
2185 goto quit;
2186 }
2187 analog_off_hook(p);
2188 ast_debug(1, "Went off-hook to signal ANI start\n");
2190
2191 /* ani_timeout is configured in chan_dahdi.conf. default is 10000ms.
2192 * ST, STP, ST2P, ST3P can all signal transmission complete, regardless of timeout */
2193 res = analog_my_getsigstr(chan, anibuf, "#ABC", p->ani_timeout);
2194
2195 /* so we can work with the ani buffer */
2196 pbx_builtin_setvar_helper(chan, "ANIBUF", anibuf);
2197
2198 /* as long as we get a terminating pulse OR the length of ANI buffer is at least >=2, we can treat
2199 * this as a complete spill for the purposes of setting anistart */
2200 if ((res > 0) || (strlen(anibuf) >= 2)) {
2201 char anistart[2] = "X";
2202 char f[101] = {0};
2203 if (strchr("#ABC", anibuf[strlen(anibuf) - 1])) {
2204 anistart[0] = anibuf[strlen(anibuf) - 1];
2205 anibuf[strlen(anibuf) - 1] = 0;
2206 }
2207 ast_set_callerid(chan, anibuf + cnoffset, NULL, anibuf + cnoffset);
2208
2209 caller = ast_channel_caller(chan);
2210 strncpy(f, &(anibuf[1]), MIN((int)(p->ani_info_digits), sizeof(f)-1));
2211 caller->ani2 = atoi(f);
2212
2213 anibuf[cnoffset] = 0;
2214
2215 /* so we can work with the different start pulses as used in ANI-D */
2216 pbx_builtin_setvar_helper(chan, "ANISTART", anistart);
2217 /* so we can use our ANI INFO digits in our dialplan */
2218 pbx_builtin_setvar_helper(chan, "ANI2", anibuf + 1);
2219 }
2221 }
2222
2223 ast_copy_string(exten, dtmfbuf, sizeof(exten));
2224 if (ast_strlen_zero(exten)) {
2225 ast_copy_string(exten, "s", sizeof(exten));
2226 }
2227 if (p->sig == ANALOG_SIG_FEATD || p->sig == ANALOG_SIG_EMWINK) {
2228 /* Look for Feature Group D on all E&M Wink and Feature Group D trunks */
2229 if (exten[0] == '*') {
2230 char *stringp=NULL;
2231 ast_copy_string(exten2, exten, sizeof(exten2));
2232 /* Parse out extension and callerid */
2233 stringp=exten2 +1;
2234 s1 = strsep(&stringp, "*");
2235 s2 = strsep(&stringp, "*");
2236 if (s2) {
2237 if (!ast_strlen_zero(p->cid_num)) {
2238 ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
2239 } else {
2240 ast_set_callerid(chan, s1, NULL, s1);
2241 }
2242 ast_copy_string(exten, s2, sizeof(exten));
2243 } else {
2244 ast_copy_string(exten, s1, sizeof(exten));
2245 }
2246 } else if (p->sig == ANALOG_SIG_FEATD) {
2247 ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
2248 }
2249 }
2250 if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
2251 if (exten[0] == '*') {
2252 char *stringp=NULL;
2253 struct ast_party_caller *caller;
2254
2255 ast_copy_string(exten2, exten, sizeof(exten2));
2256 /* Parse out extension and callerid */
2257 stringp=exten2 +1;
2258 s1 = strsep(&stringp, "#");
2259 s2 = strsep(&stringp, "#");
2260 if (s2) {
2261 if (!ast_strlen_zero(p->cid_num)) {
2262 ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
2263 } else {
2264 if (*(s1 + 2)) {
2265 ast_set_callerid(chan, s1 + 2, NULL, s1 + 2);
2266 }
2267 }
2268 ast_copy_string(exten, s2 + 1, sizeof(exten));
2269 } else {
2270 ast_copy_string(exten, s1 + 2, sizeof(exten));
2271 }
2272
2273 /* The first two digits are ani2 information. */
2274 caller = ast_channel_caller(chan);
2275 s1[2] = '\0';
2276 caller->ani2 = atoi(s1);
2277 } else {
2278 ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
2279 }
2280 }
2281 if ((p->sig == ANALOG_SIG_E911) || (p->sig == ANALOG_SIG_FGC_CAMAMF)) {
2282 if (exten[0] == '*') {
2283 char *stringp=NULL;
2284 ast_copy_string(exten2, exten, sizeof(exten2));
2285 /* Parse out extension and callerid */
2286 stringp=exten2 +1;
2287 s1 = strsep(&stringp, "#ABC");
2288 s2 = strsep(&stringp, "#ABC");
2289 if (s2 && (*(s2 + 1) == '0')) {
2290 if (*(s2 + 2)) {
2291 ast_set_callerid(chan, s2 + 2, NULL, s2 + 2);
2292 }
2293 }
2294 if (s1) {
2295 ast_copy_string(exten, s1, sizeof(exten));
2296 } else {
2297 ast_copy_string(exten, "911", sizeof(exten));
2298 }
2299 } else {
2300 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);
2301 }
2302 }
2303 if (p->sig == ANALOG_SIG_FEATB) {
2304 if (exten[0] == '*') {
2305 char *stringp=NULL;
2306 ast_copy_string(exten2, exten, sizeof(exten2));
2307 /* Parse out extension and callerid */
2308 stringp=exten2 +1;
2309 s1 = strsep(&stringp, "#");
2310 ast_copy_string(exten, exten2 + 1, sizeof(exten));
2311 } else {
2312 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);
2313 }
2314 }
2315 if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
2316 analog_wink(p, idx);
2317 /*
2318 * Some switches require a minimum guard time between the last
2319 * FGD wink and something that answers immediately. This
2320 * ensures it.
2321 */
2322 if (ast_safe_sleep(chan, 100)) {
2323 ast_hangup(chan);
2324 goto quit;
2325 }
2326 }
2328
2330
2331 if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1,
2332 ast_channel_caller(chan)->id.number.valid ? ast_channel_caller(chan)->id.number.str : NULL)) {
2333 ast_channel_exten_set(chan, exten);
2335 res = ast_pbx_run(chan);
2336 if (res) {
2337 ast_log(LOG_WARNING, "PBX exited non-zero\n");
2339 }
2340 goto quit;
2341 } else {
2342 ast_verb(3, "Unknown extension '%s' in context '%s' requested\n", exten, ast_channel_context(chan));
2343 sleep(2);
2344 res = analog_play_tone(p, idx, ANALOG_TONE_INFO);
2345 if (res < 0) {
2346 ast_log(LOG_WARNING, "Unable to start special tone on %d\n", p->channel);
2347 } else {
2348 sleep(1);
2349 }
2350 res = ast_streamfile(chan, "ss-noservice", ast_channel_language(chan));
2351 if (res >= 0) {
2352 ast_waitstream(chan, "");
2353 }
2355 ast_hangup(chan);
2356 goto quit;
2357 }
2358 break;
2359 case ANALOG_SIG_FXOLS:
2360 case ANALOG_SIG_FXOGS:
2361 case ANALOG_SIG_FXOKS:
2362 /* Set our default presentation.
2363 * This is necessary because the presentation for each call is independent
2364 * (though the default may be the same).
2365 * For example, if hidecallerid=yes and somebody makes a call with *82,
2366 * then makes a 3-way call, the presentation for the 2nd call should still
2367 * be blocked, unless that also had a *82.
2368 * For this reason, setting hidecallerid = permhidecallerid on hangup
2369 * is NOT sufficient, as the *82 from the first call could "leak" into
2370 * subsequent ones made before a hangup, improperly leaking a number
2371 * that should have been hidden.
2372 */
2374
2375 /* Read the first digit */
2376 timeout = analog_get_firstdigit_timeout(p);
2377 /* If starting a threeway call, never timeout on the first digit so someone
2378 * can use flash-hook as a "hold" feature...
2379 * ...Unless three-way dial tone should time out to silence, in which case the default suffices. */
2381 timeout = INT_MAX;
2382 }
2383 while (len < AST_MAX_EXTENSION-1) {
2384 int is_exten_parking = 0;
2385
2386 /* Read digit unless it's supposed to be immediate, in which case the
2387 only answer is 's' */
2388 if (p->immediate) {
2389 res = 's';
2390 } else {
2391 res = ast_waitfordigit(chan, timeout);
2392 }
2393 timeout = 0;
2394 if (res < 0) {
2395 ast_debug(1, "waitfordigit returned < 0...\n");
2396 res = analog_play_tone(p, idx, -1);
2397 ast_hangup(chan);
2398 goto quit;
2399 } else if (res) {
2400 ast_debug(1,"waitfordigit returned '%c' (%d), timeout = %d\n", res, res, timeout);
2401 exten[len++]=res;
2402 exten[len] = '\0';
2403 }
2404 if (!ast_ignore_pattern(ast_channel_context(chan), exten)) {
2405 analog_play_tone(p, idx, -1);
2406 } else {
2408 }
2410 is_exten_parking = ast_parking_is_exten_park(ast_channel_context(chan), exten);
2411 }
2412 if (p->lastnumredial && !strcmp(exten, "##") && !ast_exists_extension(chan, ast_channel_context(chan), "##", 1, p->cid_num)) {
2413 /* Last Number Redial */
2414 if (!ast_strlen_zero(p->lastexten)) {
2415 ast_verb(4, "Redialing last number dialed on channel %d\n", p->channel);
2416 ast_copy_string(exten, p->lastexten, sizeof(exten));
2417 } else {
2418 ast_verb(3, "Last Number Redial not possible on channel %d (no saved number)\n", p->channel);
2421 ast_hangup(chan);
2422 goto quit;
2423 }
2424 }
2425 if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num) && !is_exten_parking) {
2426 if (!res || !ast_matchmore_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) {
2427 if (getforward) {
2428 /* Record this as the forwarding extension */
2429 ast_copy_string(p->call_forward, exten, sizeof(p->call_forward));
2430 ast_verb(3, "Setting call forward to '%s' on channel %d\n", p->call_forward, p->channel);
2432 if (res) {
2433 break;
2434 }
2435 usleep(500000);
2436 res = analog_play_tone(p, idx, -1);
2437 sleep(1);
2438 memset(exten, 0, sizeof(exten));
2440 len = 0;
2441 getforward = 0;
2442 } else {
2443 res = analog_play_tone(p, idx, -1);
2444 ast_channel_lock(chan);
2445 ast_channel_exten_set(chan, exten);
2446
2447 /* Save the last number dialed, for Last Number Redial. */
2448 if (!p->immediate) {
2449 ast_copy_string(p->lastexten, exten, sizeof(p->lastexten));
2450 }
2451
2452 /* Properly set the presentation.
2453 * We need to do this here as well, because p->hidecallerid might be set
2454 * due to permanent blocking, not star-67/star-82 usage. */
2455 if (p->hidecallerid) {
2458 } else {
2461 }
2462
2464 ast_channel_unlock(chan);
2466 res = ast_pbx_run(chan);
2467 if (res) {
2468 ast_log(LOG_WARNING, "PBX exited non-zero\n");
2470 }
2471 goto quit;
2472 }
2473 } else {
2474 /* It's a match, but they just typed a digit, and there is an ambiguous match,
2475 so just set the timeout to analog_matchdigittimeout and wait some more */
2476 timeout = analog_get_matchdigit_timeout(p);
2477 }
2478 } else if (res == 0) {
2479 ast_debug(1, "not enough digits (and no ambiguous match)...\n");
2480 if (p->threewaysilenthold) {
2481 ast_debug(1, "Nothing dialed at three-way dial tone, timed out to silent hold\n");
2482 } else {
2484 }
2486 ast_hangup(chan);
2487 goto quit;
2488 } else if (p->callwaiting && !strcmp(exten, "*70")) {
2489 ast_verb(3, "Disabling call waiting on %s\n", ast_channel_name(chan));
2490 /* Disable call waiting if enabled */
2493 if (res) {
2494 ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2495 ast_channel_name(chan), strerror(errno));
2496 }
2497 len = 0;
2498 memset(exten, 0, sizeof(exten));
2499 timeout = analog_get_firstdigit_timeout(p);
2500
2501 } else if (!strcmp(exten, pickupexten)) {
2502 /* Scan all channels and see if there are any
2503 * ringing channels that have call groups
2504 * that equal this channel's pickup group
2505 */
2506 if (idx == ANALOG_SUB_REAL) {
2507 /* Switch us from Third call to Call Wait */
2508 if (p->subs[ANALOG_SUB_THREEWAY].owner) {
2509 /* If you make a threeway call and then *8# a call, it should actually
2510 look like a callwait */
2514 }
2516 if (ast_pickup_call(chan)) {
2517 ast_debug(1, "No call pickup possible...\n");
2520 }
2521 ast_hangup(chan);
2522 goto quit;
2523 } else {
2524 ast_log(LOG_WARNING, "Huh? Got *8# on call not on real\n");
2525 ast_hangup(chan);
2526 goto quit;
2527 }
2528 /* While the DMS-100 allows dialing as many *67s and *82s in succession as one's heart may desire,
2529 * the 5ESS does not, it only allows pure toggling (and only once!). So, it's not incorrect
2530 * to prevent people from dialing *67 if that won't actually do anything. */
2531 } else if (!p->hidecallerid && !strcmp(exten, "*67")) {
2532 ast_verb(3, "Blocking Caller*ID on %s\n", ast_channel_name(chan));
2533 /* Disable Caller*ID if enabled */
2534 p->hidecallerid = 1;
2538 if (res) {
2539 ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2540 ast_channel_name(chan), strerror(errno));
2541 }
2542 len = 0;
2543 memset(exten, 0, sizeof(exten));
2544 timeout = analog_get_firstdigit_timeout(p);
2545 } else if (p->callreturn && !strcmp(exten, "*69")) {
2546 res = 0;
2547 if (!ast_strlen_zero(p->lastcid_num)) {
2548 res = ast_say_digit_str(chan, p->lastcid_num, "", ast_channel_language(chan));
2549 }
2550 if (!res) {
2552 }
2553 break;
2554 } else if (!strcmp(exten, "*78")) {
2555 /* Do not disturb enabled */
2556 analog_dnd(p, 1);
2558 getforward = 0;
2559 memset(exten, 0, sizeof(exten));
2560 len = 0;
2561 } else if (!strcmp(exten, "*79")) {
2562 /* Do not disturb disabled */
2563 analog_dnd(p, 0);
2565 getforward = 0;
2566 memset(exten, 0, sizeof(exten));
2567 len = 0;
2568 } else if (p->cancallforward && !strcmp(exten, "*72")) {
2570 getforward = 1;
2571 memset(exten, 0, sizeof(exten));
2572 len = 0;
2573 } else if (p->cancallforward && !strcmp(exten, "*73")) {
2574 ast_verb(3, "Cancelling call forwarding on channel %d\n", p->channel);
2576 memset(p->call_forward, 0, sizeof(p->call_forward));
2577 getforward = 0;
2578 memset(exten, 0, sizeof(exten));
2579 len = 0;
2580 } else if ((p->transfer || p->canpark) && is_exten_parking
2582 struct ast_bridge_channel *bridge_channel;
2583
2584 /*
2585 * This is a three way call, the main call being a real channel,
2586 * and we're parking the first call.
2587 */
2591 if (bridge_channel) {
2592 if (!ast_parking_blind_transfer_park(bridge_channel, ast_channel_context(chan), exten, NULL, NULL)) {
2593 /*
2594 * Swap things around between the three-way and real call so we
2595 * can hear where the channel got parked.
2596 */
2601
2602 ast_verb(3, "%s: Parked call\n", ast_channel_name(chan));
2604 ao2_ref(bridge_channel, -1);
2605 goto quit;
2606 }
2607 ao2_ref(bridge_channel, -1);
2608 }
2609 break;
2610 } else if (!ast_strlen_zero(p->lastcid_num) && !strcmp(exten, "*60")) {
2611 ast_verb(3, "Blacklisting number %s\n", p->lastcid_num);
2612 res = ast_db_put("blacklist", p->lastcid_num, "1");
2613 if (!res) {
2615 memset(exten, 0, sizeof(exten));
2616 len = 0;
2617 }
2618 } else if (p->hidecallerid && !strcmp(exten, "*82")) {
2619 ast_verb(3, "Allowing Caller*ID on %s\n", ast_channel_name(chan));
2620 /* Enable Caller*ID if enabled */
2621 p->hidecallerid = 0;
2625 if (res) {
2626 ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2627 ast_channel_name(chan), strerror(errno));
2628 }
2629 len = 0;
2630 memset(exten, 0, sizeof(exten));
2631 timeout = analog_get_firstdigit_timeout(p);
2632 } else if (!strcmp(exten, "*0")) {
2633 struct ast_channel *nbridge = p->subs[ANALOG_SUB_THREEWAY].owner;
2634 struct analog_pvt *pbridge = NULL;
2635 /* set up the private struct of the bridged one, if any */
2636 if (nbridge) {
2637 pbridge = analog_get_bridged_channel(nbridge);
2638 }
2639 if (pbridge && ISTRUNK(pbridge)) {
2640 /* Clear out the dial buffer */
2641 p->dop.dialstr[0] = '\0';
2642 /* flash hookswitch */
2643 if ((analog_flash(pbridge) == -1) && (errno != EINPROGRESS)) {
2645 "Unable to flash-hook bridged trunk from channel %s: %s\n",
2646 ast_channel_name(nbridge), strerror(errno));
2647 }
2652 ast_hangup(chan);
2653 goto quit;
2654 } else {
2657 analog_play_tone(p, idx, -1);
2661 ast_hangup(chan);
2662 goto quit;
2663 }
2664 } else if (!ast_canmatch_extension(chan, ast_channel_context(chan), exten, 1,
2665 ast_channel_caller(chan)->id.number.valid ? ast_channel_caller(chan)->id.number.str : NULL)
2666 && !analog_canmatch_featurecode(pickupexten, exten)) {
2667 ast_debug(1, "Can't match %s from '%s' in context %s\n", exten,
2668 ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str
2669 ? ast_channel_caller(chan)->id.number.str : "<Unknown Caller>",
2670 ast_channel_context(chan));
2671 break;
2672 }
2673 if (!timeout) {
2674 timeout = analog_get_interdigit_timeout(p);
2675 }
2676 if (len && !ast_ignore_pattern(ast_channel_context(chan), exten)) {
2677 analog_play_tone(p, idx, -1);
2678 }
2679 }
2680 break;
2681 case ANALOG_SIG_FXSLS:
2682 case ANALOG_SIG_FXSGS:
2683 case ANALOG_SIG_FXSKS:
2684 /* check for SMDI messages */
2685 if (p->use_smdi && p->smdi_iface) {
2687 if (smdi_msg != NULL) {
2688 ast_channel_exten_set(chan, smdi_msg->fwd_st);
2689
2690 if (smdi_msg->type == 'B')
2691 pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "b");
2692 else if (smdi_msg->type == 'N')
2693 pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "u");
2694
2695 ast_debug(1, "Received SMDI message on %s\n", ast_channel_name(chan));
2696 } else {
2697 ast_log(LOG_WARNING, "SMDI enabled but no SMDI message present\n");
2698 }
2699 }
2700
2701 if (p->use_callerid && (p->cid_signalling == CID_SIG_SMDI && smdi_msg)) {
2702 number = smdi_msg->calling_st;
2703
2704 /* If we want caller id, we're in a prering state due to a polarity reversal
2705 * and we're set to use a polarity reversal to trigger the start of caller id,
2706 * grab the caller id and wait for ringing to start... */
2707 } else if (p->use_callerid && (ast_channel_state(chan) == AST_STATE_PRERING
2711 /* If set to use DTMF CID signalling, listen for DTMF */
2712 if (p->cid_signalling == CID_SIG_DTMF) {
2713 int k = 0;
2714 int oldlinearity;
2715 int timeout_ms;
2716 int ms;
2717 struct timeval start = ast_tvnow();
2718 ast_debug(1, "Receiving DTMF cid on channel %s\n", ast_channel_name(chan));
2719
2720 oldlinearity = analog_set_linear_mode(p, idx, 0);
2721
2722 /*
2723 * We are the only party interested in the Rx stream since
2724 * we have not answered yet. We don't need or even want DTMF
2725 * emulation. The DTMF digits can come so fast that emulation
2726 * can drop some of them.
2727 */
2728 ast_channel_lock(chan);
2730 ast_channel_unlock(chan);
2731 timeout_ms = 4000;/* This is a typical OFF time between rings. */
2732 for (;;) {
2733 struct ast_frame *f;
2734
2735 ms = ast_remaining_ms(start, timeout_ms);
2736 res = ast_waitfor(chan, ms);
2737 if (res <= 0) {
2738 /*
2739 * We do not need to restore the analog_set_linear_mode()
2740 * or AST_FLAG_END_DTMF_ONLY flag settings since we
2741 * are hanging up the channel.
2742 */
2744 "DTMFCID timed out waiting for ring. Exiting simple switch\n");
2745 ast_hangup(chan);
2746 goto quit;
2747 }
2748 f = ast_read(chan);
2749 if (!f) {
2750 break;
2751 }
2752 if (f->frametype == AST_FRAME_DTMF) {
2753 if (k < ARRAY_LEN(dtmfbuf) - 1) {
2754 dtmfbuf[k++] = f->subclass.integer;
2755 }
2756 ast_debug(1, "CID got digit '%c'\n", f->subclass.integer);
2757 start = ast_tvnow();
2758 }
2759 ast_frfree(f);
2760 if (ast_channel_state(chan) == AST_STATE_RING ||
2762 break; /* Got ring */
2763 }
2764 }
2765 ast_channel_lock(chan);
2767 ast_channel_unlock(chan);
2768 dtmfbuf[k] = '\0';
2769
2770 analog_set_linear_mode(p, idx, oldlinearity);
2771
2772 /* Got cid and ring. */
2773 ast_debug(1, "CID got string '%s'\n", dtmfbuf);
2774 callerid_get_dtmf(dtmfbuf, dtmfcid, &flags);
2775 ast_debug(1, "CID is '%s', flags %d\n", dtmfcid, flags);
2776 /* If first byte is NULL, we have no cid */
2777 if (!ast_strlen_zero(dtmfcid)) {
2778 number = dtmfcid;
2779 } else {
2780 number = NULL;
2781 }
2782
2783 /* If set to use V23 Signalling, launch our FSK gubbins and listen for it */
2784 } else if ((p->cid_signalling == CID_SIG_V23) || (p->cid_signalling == CID_SIG_V23_JP)) {
2785 namebuf[0] = 0;
2786 numbuf[0] = 0;
2787
2789 int timeout = 10000; /* Ten seconds */
2790 struct timeval start = ast_tvnow();
2791 enum analog_event ev;
2792 int off_ms;
2793 int ms;
2794 struct timeval off_start;
2795
2797 /* Disable distinctive ring timeout count */
2799 }
2800 while ((ms = ast_remaining_ms(start, timeout))) {
2801 res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2802 if (res < 0) {
2804 "CallerID returned with error on channel '%s'\n",
2805 ast_channel_name(chan));
2806 break;
2807 }
2808 if (res == 0) {
2809 break;
2810 }
2811 if (res != 1) {
2812 continue;
2813 }
2814 if (ev == ANALOG_EVENT_NOALARM) {
2815 analog_set_alarm(p, 0);
2816 }
2817 if (p->cid_signalling == CID_SIG_V23_JP) {
2818 if (ev == ANALOG_EVENT_RINGBEGIN) {
2819 analog_off_hook(p);
2820 usleep(1);
2821 }
2822 } else {
2823 break;
2824 }
2825 }
2826
2827 name = namebuf;
2828 number = numbuf;
2829
2830 if (p->cid_signalling == CID_SIG_V23_JP) {
2831 analog_on_hook(p);
2832 usleep(1);
2833 }
2834
2835 /* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
2836 off_start = ast_tvnow();
2837 off_ms = 4000;/* This is a typical OFF time between rings. */
2838 while ((ms = ast_remaining_ms(off_start, off_ms))) {
2839 struct ast_frame *f;
2840
2841 res = ast_waitfor(chan, ms);
2842 if (res <= 0) {
2844 "CID timed out waiting for ring. Exiting simple switch\n");
2846 ast_hangup(chan);
2847 goto quit;
2848 }
2849 if (!(f = ast_read(chan))) {
2850 ast_log(LOG_WARNING, "Hangup received waiting for ring. Exiting simple switch\n");
2852 ast_hangup(chan);
2853 goto quit;
2854 }
2855 ast_frfree(f);
2856 if (ast_channel_state(chan) == AST_STATE_RING ||
2858 break; /* Got ring */
2859 }
2860
2861 res = analog_distinctive_ring(chan, p, idx, NULL);
2863 if (res) {
2864 goto quit;
2865 }
2866 } else {
2867 ast_log(LOG_WARNING, "Unable to get caller ID space\n");
2868 }
2869 } else {
2871 "Channel %s in prering state, but I have nothing to do. Terminating simple switch, should be restarted by the actual ring.\n",
2872 ast_channel_name(chan));
2873 ast_hangup(chan);
2874 goto quit;
2875 }
2876 } else if (p->use_callerid && p->cid_start == ANALOG_CID_START_RING) {
2877 namebuf[0] = 0;
2878 numbuf[0] = 0;
2879
2881 int timeout = 10000; /* Ten seconds */
2882 struct timeval start = ast_tvnow();
2883 enum analog_event ev;
2884 int ring_data[RING_PATTERNS] = { 0 };
2885 int ring_data_idx = 0;
2886 int ms;
2887
2889 /* Disable distinctive ring timeout count */
2891 }
2892 while ((ms = ast_remaining_ms(start, timeout))) {
2893 res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2894 if (res < 0) {
2896 "CallerID returned with error on channel '%s'\n",
2897 ast_channel_name(chan));
2898 break;
2899 }
2900 if (res == 0) {
2901 break;
2902 }
2903 if (res != 1) {
2904 continue;
2905 }
2906 if (ev == ANALOG_EVENT_NOALARM) {
2907 analog_set_alarm(p, 0);
2908 } else if (ev == ANALOG_EVENT_POLARITY
2910 && p->polarity == POLARITY_REV) {
2911 ast_debug(1,
2912 "Hanging up due to polarity reversal on channel %d while detecting callerid\n",
2913 p->channel);
2916 ast_hangup(chan);
2917 goto quit;
2918 } else if (ev == ANALOG_EVENT_RINGOFFHOOK
2920 && ring_data_idx < RING_PATTERNS) {
2921 /*
2922 * Detect callerid while collecting possible
2923 * distinctive ring pattern.
2924 */
2925 ring_data[ring_data_idx] = p->ringt;
2926 ++ring_data_idx;
2927 }
2928 }
2929
2930 name = namebuf;
2931 number = numbuf;
2932
2933 res = analog_distinctive_ring(chan, p, idx, ring_data);
2935 if (res) {
2936 goto quit;
2937 }
2938 } else {
2939 ast_log(LOG_WARNING, "Unable to get caller ID space\n");
2940 }
2941 }
2942
2943 if (number) {
2945 }
2947
2948 analog_handle_notify_message(chan, p, flags, -1);
2949
2950 ast_channel_lock(chan);
2952 ast_channel_rings_set(chan, 1);
2953 ast_channel_unlock(chan);
2955 res = ast_pbx_run(chan);
2956 if (res) {
2957 ast_hangup(chan);
2958 ast_log(LOG_WARNING, "PBX exited non-zero\n");
2959 }
2960 goto quit;
2961 default:
2962 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);
2963 break;
2964 }
2966 if (res < 0) {
2967 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
2968 }
2969 ast_hangup(chan);
2970quit:
2971 ao2_cleanup(smdi_msg);
2973 return NULL;
2974}
2975
2977{
2978 pthread_t threadid;
2979
2980 p->ss_astchan = chan;
2982}
2983
2985{
2986 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
2987
2988 ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", channel);
2989 body = ast_json_pack("{s: i}", "Channel", channel);
2990 if (!body) {
2991 return;
2992 }
2993
2994 ast_manager_publish_event("AlarmClear", EVENT_FLAG_SYSTEM, body);
2995}
2996
2997static struct ast_frame *__analog_handle_event(struct analog_pvt *p, struct ast_channel *ast)
2998{
2999 int res, x;
3000 int mysig;
3001 int idx;
3002 char *c;
3003 pthread_t threadid;
3004 struct ast_channel *chan;
3005 struct ast_frame *f;
3006 struct ast_control_pvt_cause_code *cause_code = NULL;
3007 int data_size = sizeof(*cause_code);
3008 char *subclass = NULL;
3009
3010 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
3011
3012 idx = analog_get_index(ast, p, 0);
3013 if (idx < 0) {
3014 return &ast_null_frame;
3015 }
3016 if (idx != ANALOG_SUB_REAL) {
3017 ast_log(LOG_ERROR, "We got an event on a non real sub. Fix it!\n");
3018 }
3019
3020 mysig = p->sig;
3021 if (p->outsigmod > -1) {
3022 mysig = p->outsigmod;
3023 }
3024
3025 p->subs[idx].f.frametype = AST_FRAME_NULL;
3026 p->subs[idx].f.subclass.integer = 0;
3027 p->subs[idx].f.datalen = 0;
3028 p->subs[idx].f.samples = 0;
3029 p->subs[idx].f.mallocd = 0;
3030 p->subs[idx].f.offset = 0;
3031 p->subs[idx].f.src = "dahdi_handle_event";
3032 p->subs[idx].f.data.ptr = NULL;
3033 f = &p->subs[idx].f;
3034
3035 res = analog_get_event(p);
3036
3037 ast_debug(1, "Got event %s(%d) on channel %d (index %u)\n", analog_event2str(res), res, p->channel, idx);
3038
3041 ast_debug(1, "Detected %sdigit '%c'\n", (res & ANALOG_EVENT_PULSEDIGIT) ? "pulse ": "", res & 0xff);
3042 analog_confmute(p, 0);
3045 p->subs[idx].f.subclass.integer = res & 0xff;
3046 analog_handle_dtmf(p, ast, idx, &f);
3047 } else {
3048 ast_debug(1, "Dropping pulse digit '%c' because pulse dialing disabled on channel %d\n", res & 0xff, p->channel);
3049 }
3050 return f;
3051 }
3052
3053 if (res & ANALOG_EVENT_DTMFDOWN) {
3054 ast_debug(1, "DTMF Down '%c'\n", res & 0xff);
3055 /* Mute conference */
3056 analog_confmute(p, 1);
3058 p->subs[idx].f.subclass.integer = res & 0xff;
3059 analog_handle_dtmf(p, ast, idx, &f);
3060 return f;
3061 }
3062
3063 switch (res) {
3064 case ANALOG_EVENT_ALARM:
3067 /* add length of "ANALOG " */
3068 data_size += 7;
3069 subclass = analog_event2str(res);
3070 data_size += strlen(subclass);
3071 cause_code = ast_alloca(data_size);
3072 memset(cause_code, 0, data_size);
3075 snprintf(cause_code->code, data_size - sizeof(*cause_code) + 1, "ANALOG %s", subclass);
3076 break;
3077 default:
3078 break;
3079 }
3080
3081 switch (res) {
3083 ast_verb(3, "Channel %d echo canceller disabled due to CED detection\n", p->channel);
3085 break;
3086#ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
3088 ast_verb(3, "Channel %d detected a CED tone towards the network.\n", p->channel);
3089 break;
3091 ast_verb(3, "Channel %d detected a CED tone from the network.\n", p->channel);
3092 break;
3094 ast_verb(3, "Channel %d echo canceller disabled its NLP.\n", p->channel);
3095 break;
3097 ast_verb(3, "Channel %d echo canceller enabled its NLP.\n", p->channel);
3098 break;
3099#endif
3101 /* Stop tone if there's a pulse start and the PBX isn't started */
3102 if (!ast_channel_pbx(ast))
3104 break;
3106 if (p->inalarm) {
3107 break;
3108 }
3109 x = analog_is_dialing(p, idx);
3110 if (!x) { /* if not still dialing in driver */
3112 if (p->echobreak) {
3114 ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr));
3117 p->echobreak = 0;
3118 } else {
3119 analog_set_dialing(p, 0);
3120 if ((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) {
3121 /* if thru with dialing after offhook */
3126 break;
3127 } else { /* if to state wait for offhook to dial rest */
3128 /* we now wait for off hook */
3130 }
3131 }
3134 ast_debug(1, "Done dialing, but waiting for progress detection before doing more...\n");
3135 } else if (analog_check_confirmanswer(p) || (!p->dialednone
3136 && ((mysig == ANALOG_SIG_EM) || (mysig == ANALOG_SIG_EM_E1)
3137 || (mysig == ANALOG_SIG_EMWINK) || (mysig == ANALOG_SIG_FEATD)
3138 || (mysig == ANALOG_SIG_FEATDMF_TA) || (mysig == ANALOG_SIG_FEATDMF)
3139 || (mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA)
3140 || (mysig == ANALOG_SIG_FGC_CAMAMF) || (mysig == ANALOG_SIG_FEATB)
3141 || (mysig == ANALOG_SIG_SF) || (mysig == ANALOG_SIG_SFWINK)
3142 || (mysig == ANALOG_SIG_SF_FEATD) || (mysig == ANALOG_SIG_SF_FEATDMF)
3143 || (mysig == ANALOG_SIG_SF_FEATB)))) {
3145 } else if (!p->answeronpolarityswitch) {
3149 /* If aops=0 and hops=1, this is necessary */
3151 } else {
3152 /* Start clean, so we can catch the change to REV polarity when party answers */
3154 }
3155 }
3156 }
3157 }
3158 break;
3159 case ANALOG_EVENT_ALARM:
3160 analog_set_alarm(p, 1);
3164 if (p->calledsubscriberheld && (p->sig == ANALOG_SIG_FXOLS || p->sig == ANALOG_SIG_FXOGS || p->sig == ANALOG_SIG_FXOKS) && idx == ANALOG_SUB_REAL) {
3165 ast_debug(4, "Channel state on %s is %d\n", ast_channel_name(ast), ast_channel_state(ast));
3166 /* Called Subscriber Held: don't let the called party hang up on an incoming call immediately (if it's the only call). */
3168 ast_debug(2, "Letting this call hang up normally, since it's not the only call\n");
3169 } else if (!p->owner || !p->subs[ANALOG_SUB_REAL].owner || ast_channel_state(ast) != AST_STATE_UP) {
3170 ast_debug(2, "Called Subscriber Held does not apply: channel state is %d\n", ast_channel_state(ast));
3171 } else if (!p->owner || !p->subs[ANALOG_SUB_REAL].owner || strcmp(ast_channel_appl(p->subs[ANALOG_SUB_REAL].owner), "AppDial")) {
3172 /* Called Subscriber held only applies to incoming calls, not outgoing calls.
3173 * We can't use p->outgoing because that is always true, for both incoming and outgoing calls, so it's not accurate.
3174 * We can check the channel application/data instead.
3175 * For incoming calls to the channel, it will look like: AppDial / (Outgoing Line)
3176 * We only want this behavior for regular calls anyways (and not, say, Queue),
3177 * so this would actually work great. But accessing ast_channel_appl can cause a crash if there are no calls left,
3178 * so this check must occur AFTER we confirm the channel state *is* still UP.
3179 */
3180 ast_debug(2, "Called Subscriber Held does not apply: not an incoming call\n");
3181 } else if (analog_is_off_hook(p)) {
3182 ast_log(LOG_WARNING, "Got ONHOOK but channel %d is off hook?\n", p->channel); /* Shouldn't happen */
3183 } else {
3184 ast_verb(3, "Holding incoming call %s for channel %d\n", ast_channel_name(ast), p->channel);
3185 /* Inhibit dahdi_hangup from getting called, and do nothing else now.
3186 * When the DAHDI channel goes off hook again, it'll just get reconnected with the incoming call,
3187 * to which, as far as its concerned, nothing has happened. */
3188 p->cshactive = 1; /* Keep track that this DAHDI channel is currently being held by an incoming call. */
3189 break;
3190 }
3191 }
3193 ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
3194 ast_channel_hangupcause_hash_set(ast, cause_code, data_size);
3195 switch (p->sig) {
3196 case ANALOG_SIG_FXOLS:
3197 case ANALOG_SIG_FXOGS:
3198 case ANALOG_SIG_FXOKS:
3200 p->fxsoffhookstate = 0;
3201 p->onhooktime = time(NULL);
3202 p->msgstate = -1;
3203 /* Check for some special conditions regarding call waiting */
3204 if (idx == ANALOG_SUB_REAL) {
3205 /* The normal line was hung up */
3206 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
3207 /* Need to hold the lock for real-call, private, and call-waiting call */
3209 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
3210 /*
3211 * The call waiting call disappeared.
3212 * This is now a normal hangup.
3213 */
3215 return NULL;
3216 }
3217
3218 /* There's a call waiting call, so ring the phone, but make it unowned in the meantime */
3220 ast_verb(3, "Channel %d still has (callwait) call, ringing phone\n", p->channel);
3224 /* Don't start streaming audio yet if the incoming call isn't up yet */
3226 analog_set_dialing(p, 1);
3227 }
3228 /* Unlock the call-waiting call that we swapped to real-call. */
3230 analog_ring(p);
3231 } else if (p->subs[ANALOG_SUB_THREEWAY].owner) {
3232 unsigned int mssinceflash;
3233
3234 /* Need to hold the lock for real-call, private, and 3-way call */
3236 if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3237 ast_log(LOG_NOTICE, "Whoa, threeway disappeared kinda randomly.\n");
3238 /* Just hangup */
3239 return NULL;
3240 }
3241 if (p->owner != ast) {
3243 ast_log(LOG_WARNING, "This isn't good...\n");
3244 /* Just hangup */
3245 return NULL;
3246 }
3247
3248 mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
3249 ast_debug(1, "Last flash was %u ms ago\n", mssinceflash);
3250 if (mssinceflash < MIN_MS_SINCE_FLASH) {
3251 /* It hasn't been long enough since the last flashook. This is probably a bounce on
3252 hanging up. Hangup both channels now */
3253 ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel);
3257 } else if ((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) {
3258 if (p->transfer) {
3259 /* In any case this isn't a threeway call anymore */
3262
3263 /* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */
3264 if (!p->transfertobusy && ast_channel_state(ast) == AST_STATE_BUSY) {
3265 /* Swap subs and dis-own channel */
3267 /* Unlock the 3-way call that we swapped to real-call. */
3270 /* Ring the phone */
3271 analog_ring(p);
3272 } else if (!analog_attempt_transfer(p)) {
3273 /*
3274 * Transfer successful. Don't actually hang up at this point.
3275 * Let our channel legs of the calls die off as the transfer
3276 * percolates through the core.
3277 */
3278 break;
3279 }
3280 } else {
3283 }
3284 } else {
3285 /* Swap subs and dis-own channel */
3287 /* Unlock the 3-way call that we swapped to real-call. */
3290 /* Ring the phone */
3291 analog_ring(p);
3292 }
3293 }
3294 } else {
3295 ast_log(LOG_WARNING, "Got a hangup and my index is %u?\n", idx);
3296 }
3297 /* Fall through */
3298 default:
3300 return NULL;
3301 }
3302 break;
3304 if (p->inalarm) {
3305 break;
3306 }
3307 /* for E911, its supposed to wait for offhook then dial
3308 the second half of the dial string */
3309 if (((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) && (ast_channel_state(ast) == AST_STATE_DIALING_OFFHOOK)) {
3310 c = strchr(p->dialdest, '/');
3311 if (c) {
3312 c++;
3313 } else {
3314 c = p->dialdest;
3315 }
3316
3317 if (*c) {
3318 int numchars = snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
3319 if (numchars >= sizeof(p->dop.dialstr)) {
3320 ast_log(LOG_WARNING, "Dial string '%s' truncated\n", c);
3321 }
3322 } else {
3323 ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
3324 }
3325
3326 if (strlen(p->dop.dialstr) > 4) {
3327 memset(p->echorest, 'w', sizeof(p->echorest) - 1);
3328 strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
3329 p->echorest[sizeof(p->echorest) - 1] = '\0';
3330 p->echobreak = 1;
3331 p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
3332 } else {
3333 p->echobreak = 0;
3334 }
3335 if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
3336 analog_on_hook(p);
3337 return NULL;
3338 }
3339 analog_set_dialing(p, 1);
3340 return &p->subs[idx].f;
3341 }
3342 switch (p->sig) {
3343 case ANALOG_SIG_FXOLS:
3344 case ANALOG_SIG_FXOGS:
3345 case ANALOG_SIG_FXOKS:
3346 p->fxsoffhookstate = 1;
3347 switch (ast_channel_state(ast)) {
3348 case AST_STATE_RINGING:
3353 /* Make sure it stops ringing */
3355 analog_off_hook(p);
3356 ast_debug(1, "channel %d answered\n", p->channel);
3357
3358 /* Cancel any running CallerID spill */
3360
3361 analog_set_dialing(p, 0);
3362 p->callwaitcas = 0;
3364 /* Ignore answer if "confirm answer" is enabled */
3365 p->subs[idx].f.frametype = AST_FRAME_NULL;
3366 p->subs[idx].f.subclass.integer = 0;
3367 } else if (!ast_strlen_zero(p->dop.dialstr)) {
3368 /* nick@dccinc.com 4/3/03 - fxo should be able to do deferred dialing */
3369 res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3370 if (res) {
3371 p->dop.dialstr[0] = '\0';
3372 return NULL;
3373 } else {
3374 ast_debug(1, "Sent FXO deferred digit string: %s\n", p->dop.dialstr);
3375 p->subs[idx].f.frametype = AST_FRAME_NULL;
3376 p->subs[idx].f.subclass.integer = 0;
3377 analog_set_dialing(p, 1);
3378 }
3379 p->dop.dialstr[0] = '\0';
3381 } else {
3384 }
3385 return &p->subs[idx].f;
3386 case AST_STATE_DOWN:
3388 ast_channel_rings_set(ast, 1);
3391 ast_debug(1, "channel %d picked up\n", p->channel);
3392 return &p->subs[idx].f;
3393 case AST_STATE_UP:
3394 /* Make sure it stops ringing */
3395 analog_off_hook(p);
3396 /* Okay -- probably call waiting */
3398 break;
3399 case AST_STATE_RESERVED:
3400 /* Start up dialtone */
3401 if (analog_has_voicemail(p)) {
3403 } else {
3405 }
3406 break;
3407 default:
3408 ast_log(LOG_WARNING, "FXO phone off hook in weird state %u??\n", ast_channel_state(ast));
3409 }
3410 break;
3411 case ANALOG_SIG_FXSLS:
3412 case ANALOG_SIG_FXSGS:
3413 case ANALOG_SIG_FXSKS:
3414 if (ast_channel_state(ast) == AST_STATE_RING) {
3416 }
3417
3418 /* Fall through */
3419 case ANALOG_SIG_EM:
3420 case ANALOG_SIG_EM_E1:
3421 case ANALOG_SIG_EMWINK:
3422 case ANALOG_SIG_FEATD:
3423 case ANALOG_SIG_FEATDMF:
3425 case ANALOG_SIG_E911:
3428 case ANALOG_SIG_FEATB:
3429 case ANALOG_SIG_SF:
3430 case ANALOG_SIG_SFWINK:
3434 switch (ast_channel_state(ast)) {
3435 case AST_STATE_PRERING:
3437 /* Fall through */
3438 case AST_STATE_DOWN:
3439 case AST_STATE_RING:
3440 ast_debug(1, "Ring detected\n");
3443 break;
3444 case AST_STATE_RINGING:
3445 case AST_STATE_DIALING:
3446 if (p->outgoing) {
3447 ast_debug(1, "Line answered\n");
3449 p->subs[idx].f.frametype = AST_FRAME_NULL;
3450 p->subs[idx].f.subclass.integer = 0;
3451 } else {
3455 }
3456 break;
3457 }
3458 /* Fall through */
3459 default:
3460 ast_log(LOG_WARNING, "Ring/Off-hook in strange state %u on channel %d\n", ast_channel_state(ast), p->channel);
3461 break;
3462 }
3463 break;
3464 default:
3465 ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3466 break;
3467 }
3468 break;
3470 switch (p->sig) {
3471 case ANALOG_SIG_FXSLS:
3472 case ANALOG_SIG_FXSGS:
3473 case ANALOG_SIG_FXSKS:
3474 if (ast_channel_state(ast) == AST_STATE_RING) {
3476 }
3477 break;
3478 default:
3479 break;
3480 }
3481 break;
3483 if (p->inalarm) break;
3485 if (ast_channel_rings(ast) == p->cidrings) {
3486 analog_send_callerid(p, 0, &p->caller);
3487 }
3488
3489 if (ast_channel_rings(ast) > p->cidrings) {
3491 p->callwaitcas = 0;
3492 }
3495 break;
3497 break;
3499 analog_set_alarm(p, 0);
3501 break;
3503 if (p->inalarm) {
3504 break;
3505 }
3506 /* Remember last time we got a flash-hook */
3507 gettimeofday(&p->flashtime, NULL);
3509 switch (mysig) {
3510 case ANALOG_SIG_FXOLS:
3511 case ANALOG_SIG_FXOGS:
3512 case ANALOG_SIG_FXOKS:
3513 ast_debug(1, "Winkflash, index: %u, normal: %d, callwait: %d, thirdcall: %d\n",
3515
3516 /* Cancel any running CallerID spill */
3518 p->callwaitcas = 0;
3519
3520 if (idx != ANALOG_SUB_REAL) {
3521 ast_log(LOG_WARNING, "Got flash hook with index %u on channel %d?!?\n", idx, p->channel);
3522 goto winkflashdone;
3523 }
3524
3525 if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
3526 /* Need to hold the lock for real-call, private, and call-waiting call */
3528 if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
3529 /*
3530 * The call waiting call disappeared.
3531 * Let's just ignore this flash-hook.
3532 */
3533 ast_log(LOG_NOTICE, "Whoa, the call-waiting call disappeared.\n");
3534 goto winkflashdone;
3535 }
3536
3537 /* If line has Call Waiting Deluxe, see what the user wants to do.
3538 * Only do this if this is an as yet unanswered call waiting, not an existing, answered SUB_CALLWAIT. */
3540 if (p->callwaitingdeluxe) {
3541 /* This thread cannot block, so just set the flag that we need
3542 * to wait for a Call Waiting Deluxe option (or let it time out),
3543 * and then we're done for now. */
3546 ast_debug(1, "Deferring call waiting manipulation, waiting for Call Waiting Deluxe option from user\n");
3547 goto winkflashdone;
3548 }
3549 }
3550
3551 /* Swap to call-wait */
3555 ast_debug(1, "Making %s the new owner\n", ast_channel_name(p->owner));
3559 }
3561
3562 /* Start music on hold if appropriate */
3565 }
3568
3569 /* Unlock the call-waiting call that we swapped to real-call. */
3571 } else if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3572 if (!p->threewaycalling) {
3573 /* Just send a flash if no 3-way calling */
3575 goto winkflashdone;
3576 } else if (!analog_check_for_conference(p)) {
3577 ast_callid callid = 0;
3578 int callid_created;
3579 char cid_num[256];
3580 char cid_name[256];
3581
3582 cid_num[0] = '\0';
3583 cid_name[0] = '\0';
3584 if (p->dahditrcallerid && p->owner) {
3588 sizeof(cid_num));
3589 }
3593 sizeof(cid_name));
3594 }
3595 }
3596 /* XXX This section needs much more error checking!!! XXX */
3597 /* Start a 3-way call if feasible */
3598 if (!((ast_channel_pbx(ast)) ||
3599 (ast_channel_state(ast) == AST_STATE_UP) ||
3600 (ast_channel_state(ast) == AST_STATE_RING))) {
3601 ast_debug(1, "Flash when call not up or ringing\n");
3602 goto winkflashdone;
3603 }
3605 ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n");
3606 goto winkflashdone;
3607 }
3608
3609 callid_created = ast_callid_threadstorage_auto(&callid);
3610
3611 /*
3612 * Make new channel
3613 *
3614 * We cannot hold the p or ast locks while creating a new
3615 * channel.
3616 */
3618 ast_channel_unlock(ast);
3620 ast_channel_lock(ast);
3622 if (!chan) {
3624 "Cannot allocate new call structure on channel %d\n",
3625 p->channel);
3627 ast_callid_threadstorage_auto_clean(callid, callid_created);
3628 goto winkflashdone;
3629 }
3630 if (p->dahditrcallerid) {
3631 if (!p->origcid_num) {
3633 }
3634 if (!p->origcid_name) {
3636 }
3637 ast_copy_string(p->cid_num, cid_num, sizeof(p->cid_num));
3638 ast_copy_string(p->cid_name, cid_name, sizeof(p->cid_name));
3639 }
3640 /* Swap things around between the three-way and real call */
3642 /* Disable echo canceller for better dialing */
3645 if (res) {
3646 ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel);
3647 }
3648 analog_set_new_owner(p, chan);
3649 p->ss_astchan = chan;
3651 ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel);
3654 ast_hangup(chan);
3655 } else {
3656 ast_verb(3, "Started three way call on channel %d\n", p->channel);
3657
3658 /* Start music on hold */
3660 }
3661 ast_callid_threadstorage_auto_clean(callid, callid_created);
3662 }
3663 } else {
3664 /* Already have a 3 way call */
3665 enum analog_sub orig_3way_sub;
3666
3667 /* Need to hold the lock for real-call, private, and 3-way call */
3669 if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3670 /*
3671 * The 3-way call disappeared.
3672 * Let's just ignore this flash-hook.
3673 */
3674 ast_log(LOG_NOTICE, "Whoa, the 3-way call disappeared.\n");
3675 goto winkflashdone;
3676 }
3677 orig_3way_sub = ANALOG_SUB_THREEWAY;
3678
3680 /* Call is already up, drop the last person */
3681 ast_debug(1, "Got flash with three way call up, dropping last call on %d\n", p->channel);
3682 /* If the primary call isn't answered yet, use it */
3685 /* Swap back -- we're dropping the real 3-way that isn't finished yet*/
3687 orig_3way_sub = ANALOG_SUB_REAL;
3689 }
3690 /* Drop the last call and stop the conference */
3691 ast_verb(3, "Dropping three-way call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner));
3695 } else {
3696 /* Lets see what we're up to */
3697 if (((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) &&
3699 ast_verb(3, "Building conference call with %s and %s\n",
3702 /* Put them in the threeway, and flip */
3706 orig_3way_sub = ANALOG_SUB_REAL;
3707 ast_queue_unhold(p->subs[orig_3way_sub].owner);
3709 } else {
3710 ast_verb(3, "Dumping incomplete call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner));
3712 orig_3way_sub = ANALOG_SUB_REAL;
3717 }
3718 }
3719 ast_channel_unlock(p->subs[orig_3way_sub].owner);
3720 }
3721winkflashdone:
3723 break;
3724 case ANALOG_SIG_EM:
3725 case ANALOG_SIG_EM_E1:
3726 case ANALOG_SIG_FEATD:
3727 case ANALOG_SIG_SF:
3728 case ANALOG_SIG_SFWINK:
3730 case ANALOG_SIG_FXSLS:
3731 case ANALOG_SIG_FXSGS:
3732 if (p->dialing) {
3733 ast_debug(1, "Ignoring wink on channel %d\n", p->channel);
3734 } else {
3735 ast_debug(1, "Got wink in weird state %u on channel %d\n", ast_channel_state(ast), p->channel);
3736 }
3737 break;
3739 switch (p->whichwink) {
3740 case 0:
3741 ast_debug(1, "ANI2 set to '%d' and ANI is '%s'\n", ast_channel_caller(p->owner)->ani2,
3744 snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%d%s#",
3748 break;
3749 case 1:
3750 ast_copy_string(p->dop.dialstr, p->finaldial, sizeof(p->dop.dialstr));
3751 break;
3752 case 2:
3753 ast_log(LOG_WARNING, "Received unexpected wink on channel of type ANALOG_SIG_FEATDMF_TA\n");
3754 return NULL;
3755 }
3756 p->whichwink++;
3757 /* Fall through */
3758 case ANALOG_SIG_FEATDMF:
3759 case ANALOG_SIG_E911:
3762 case ANALOG_SIG_FEATB:
3765 case ANALOG_SIG_EMWINK:
3766 /* FGD MF and EMWINK *Must* wait for wink */
3767 if (!ast_strlen_zero(p->dop.dialstr)) {
3768 res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3769 if (res) {
3770 p->dop.dialstr[0] = '\0';
3771 return NULL;
3772 } else {
3773 ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3774 }
3775 }
3776 p->dop.dialstr[0] = '\0';
3777 break;
3778 default:
3779 ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3780 }
3781 break;
3783 if (p->inalarm) break;
3785 break;
3786 }
3787 switch (mysig) {
3788 case ANALOG_SIG_FXSLS: /* only interesting for FXS */
3789 case ANALOG_SIG_FXSGS:
3790 case ANALOG_SIG_FXSKS:
3791 case ANALOG_SIG_EM:
3792 case ANALOG_SIG_EM_E1:
3793 case ANALOG_SIG_EMWINK:
3794 case ANALOG_SIG_FEATD:
3795 case ANALOG_SIG_SF:
3796 case ANALOG_SIG_SFWINK:
3798 if (!ast_strlen_zero(p->dop.dialstr)) {
3799 res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3800 if (res) {
3801 p->dop.dialstr[0] = '\0';
3802 return NULL;
3803 } else {
3804 ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3805 }
3806 }
3807 p->dop.dialstr[0] = '\0';
3809 break;
3810 case ANALOG_SIG_FEATDMF:
3812 case ANALOG_SIG_E911:
3815 case ANALOG_SIG_FEATB:
3818 ast_debug(1, "Got hook complete in MF FGD, waiting for wink now on channel %d\n",p->channel);
3819 break;
3820 default:
3821 break;
3822 }
3823 break;
3825 /*
3826 * If we get a Polarity Switch event, this could be
3827 * due to line seizure, remote end connect or remote end disconnect.
3828 *
3829 * Check to see if we should change the polarity state and
3830 * mark the channel as UP or if this is an indication
3831 * of remote end disconnect.
3832 */
3833
3834 if (p->polarityonanswerdelay > 0) {
3835 /* check if event is not too soon after OffHook or Answer */
3837 switch (ast_channel_state(ast)) {
3838 case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3839 case AST_STATE_RINGING: /*!< Remote end is ringing */
3840 if (p->answeronpolarityswitch) {
3841 ast_debug(1, "Answering on polarity switch! channel %d\n", p->channel);
3844 if (p->hanguponpolarityswitch) {
3846 }
3847 } else {
3848 ast_debug(1, "Ignore Answer on polarity switch, channel %d\n", p->channel);
3849 }
3850 break;
3851
3852 case AST_STATE_UP: /*!< Line is up */
3853 case AST_STATE_RING: /*!< Line is ringing */
3854 if (p->hanguponpolarityswitch) {
3855 ast_debug(1, "HangingUp on polarity switch! channel %d\n", p->channel);
3856 ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
3857 ast_channel_hangupcause_hash_set(ast, cause_code, data_size);
3860 } else {
3861 ast_debug(1, "Ignore Hangup on polarity switch, channel %d\n", p->channel);
3862 }
3863 break;
3864
3865 case AST_STATE_DOWN: /*!< Channel is down and available */
3866 case AST_STATE_RESERVED: /*!< Channel is down, but reserved */
3867 case AST_STATE_OFFHOOK: /*!< Channel is off hook */
3868 case AST_STATE_BUSY: /*!< Line is busy */
3869 case AST_STATE_DIALING_OFFHOOK: /*!< Digits (or equivalent) have been dialed while offhook */
3870 case AST_STATE_PRERING: /*!< Channel has detected an incoming call and is waiting for ring */
3871 default:
3873 ast_debug(1, "Ignoring Polarity switch on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3874 }
3875 break;
3876 }
3877
3878 } else {
3879 /* event is too soon after OffHook or Answer */
3880 switch (ast_channel_state(ast)) {
3881 case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3882 case AST_STATE_RINGING: /*!< Remote end is ringing */
3883 if (p->answeronpolarityswitch) {
3884 ast_debug(1, "Polarity switch detected but NOT answering (too close to OffHook event) on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3885 }
3886 break;
3887
3888 case AST_STATE_UP: /*!< Line is up */
3889 case AST_STATE_RING: /*!< Line is ringing */
3890 if (p->hanguponpolarityswitch) {
3891 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));
3892 }
3893 break;
3894
3895 default:
3897 ast_debug(1, "Polarity switch detected (too close to previous event) on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3898 }
3899 break;
3900 }
3901 }
3902 }
3903
3904 /* Added more log_debug information below to provide a better indication of what is going on */
3905 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) );
3906 break;
3907 default:
3908 ast_debug(1, "Dunno what to do with event %d on channel %d\n", res, p->channel);
3909 }
3910 return &p->subs[idx].f;
3911}
3912
3913struct ast_frame *analog_exception(struct analog_pvt *p, struct ast_channel *ast)
3914{
3915 int res;
3916 int idx;
3917 struct ast_frame *f;
3918
3919 ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
3920
3921 idx = analog_get_index(ast, p, 1);
3922 if (idx < 0) {
3923 idx = ANALOG_SUB_REAL;
3924 }
3925
3926 p->subs[idx].f.frametype = AST_FRAME_NULL;
3927 p->subs[idx].f.datalen = 0;
3928 p->subs[idx].f.samples = 0;
3929 p->subs[idx].f.mallocd = 0;
3930 p->subs[idx].f.offset = 0;
3931 p->subs[idx].f.subclass.integer = 0;
3932 p->subs[idx].f.delivery = ast_tv(0,0);
3933 p->subs[idx].f.src = "dahdi_exception";
3934 p->subs[idx].f.data.ptr = NULL;
3935
3936 if (!p->owner) {
3937 /* If nobody owns us, absorb the event appropriately, otherwise
3938 we loop indefinitely. This occurs when, during call waiting, the
3939 other end hangs up our channel so that it no longer exists, but we
3940 have neither FLASH'd nor ONHOOK'd to signify our desire to
3941 change to the other channel. */
3942 res = analog_get_event(p);
3943
3944 /* Switch to real if there is one and this isn't something really silly... */
3945 if ((res != ANALOG_EVENT_RINGEROFF) && (res != ANALOG_EVENT_RINGERON) &&
3946 (res != ANALOG_EVENT_HOOKCOMPLETE)) {
3947 ast_debug(1, "Restoring owner of channel %d on event %d\n", p->channel, res);
3949 if (p->owner && ast != p->owner) {
3950 /*
3951 * Could this even happen?
3952 * Possible deadlock because we do not have the real-call lock.
3953 */
3954 ast_log(LOG_WARNING, "Event %s on %s is not restored owner %s\n",
3956 }
3957 if (p->owner) {
3959 }
3960 }
3961 switch (res) {
3964 if (p->owner) {
3965 ast_verb(3, "Channel %s still has call, ringing phone\n", ast_channel_name(p->owner));
3966 analog_ring(p);
3968 } else {
3969 ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
3970 analog_event2str(res));
3971 }
3973 break;
3976 analog_off_hook(p);
3977 if (p->owner && (ast_channel_state(p->owner) == AST_STATE_RINGING)) {
3979 analog_set_dialing(p, 0);
3980 }
3981 break;
3985 /* Do nothing */
3986 break;
3988 gettimeofday(&p->flashtime, NULL);
3989 if (p->owner) {
3990 ast_verb(3, "Channel %d flashed to other channel %s\n", p->channel, ast_channel_name(p->owner));
3992 /* Answer if necessary */
3995 }
3998 } else {
3999 ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
4000 analog_event2str(res));
4001 }
4003 break;
4004 default:
4005 ast_log(LOG_WARNING, "Don't know how to absorb event %s\n", analog_event2str(res));
4006 break;
4007 }
4008 f = &p->subs[idx].f;
4009 return f;
4010 }
4011 ast_debug(1, "Exception on %d, channel %d\n", ast_channel_fd(ast, 0), p->channel);
4012 /* If it's not us, return NULL immediately */
4013 if (ast != p->owner) {
4014 ast_log(LOG_WARNING, "We're %s, not %s\n", ast_channel_name(ast), ast_channel_name(p->owner));
4015 f = &p->subs[idx].f;
4016 return f;
4017 }
4018
4019 f = __analog_handle_event(p, ast);
4020 if (!f) {
4021 const char *name = ast_strdupa(ast_channel_name(ast));
4022
4023 /* Tell the CDR this DAHDI device hung up */
4025 ast_channel_unlock(ast);
4026 ast_set_hangupsource(ast, name, 0);
4027 ast_channel_lock(ast);
4029 }
4030 return f;
4031}
4032
4034{
4035 int res;
4036 pthread_t threadid;
4037 struct ast_channel *chan;
4038 ast_callid callid = 0;
4039 int callid_created;
4040
4041 ast_debug(1, "channel (%d) - signaling (%d) - event (%s)\n",
4043
4044 /* Handle an event on a given channel for the monitor thread. */
4045 switch (event) {
4048 switch (i->sig) {
4049 case ANALOG_SIG_FXSLS:
4050 case ANALOG_SIG_FXSGS:
4051 case ANALOG_SIG_FXSKS:
4052 if (i->immediate) {
4054 ast_log(LOG_WARNING, "Can't start PBX immediately, must wait for Caller ID / distinctive ring\n");
4055 } else {
4056 /* If we don't care about Caller ID or Distinctive Ring, then there's
4057 * no need to wait for anything before accepting the call, as
4058 * waiting will buy us nothing.
4059 * So if the channel is configured for immediate, actually start immediately
4060 * and get the show on the road as soon as possible. */
4061 ast_debug(1, "Disabling ring timeout (previously %d) to begin handling immediately\n", i->ringt_base);
4063 }
4064 }
4065 break;
4066 default:
4067 break;
4068 }
4069 /* Fall through */
4070 if (!(ISTRUNK(i) && i->immediate && !i->use_callerid && !i->usedistinctiveringdetection)) {
4071 break;
4072 }
4074 if (i->inalarm) {
4075 break;
4076 }
4077 /* Got a ring/answer. What kind of channel are we? */
4078 switch (i->sig) {
4079 case ANALOG_SIG_FXOLS:
4080 case ANALOG_SIG_FXOGS:
4081 case ANALOG_SIG_FXOKS:
4082 res = analog_off_hook(i);
4083 i->fxsoffhookstate = 1;
4084 i->cshactive = 0;
4086 if (res && (errno == EBUSY)) {
4087 break;
4088 }
4089 callid_created = ast_callid_threadstorage_auto(&callid);
4090
4091 /* Cancel VMWI spill */
4093
4094 if (i->immediate) {
4096 /* The channel is immediately up. Start right away */
4097 if (i->immediatering) {
4098 /* Play fake ringing, if we've been told to... */
4100 }
4102 if (!chan) {
4103 ast_log(LOG_WARNING, "Unable to start PBX on channel %d\n", i->channel);
4105 if (res < 0) {
4106 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4107 }
4108 }
4109 } else {
4110 /* Check for callerid, digits, etc */
4112 i->ss_astchan = chan;
4113 if (chan) {
4114 if (analog_has_voicemail(i)) {
4116 } else {
4118 }
4119 if (res < 0)
4120 ast_log(LOG_WARNING, "Unable to play dialtone on channel %d, do you have defaultzone and loadzone defined?\n", i->channel);
4121
4123 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4125 if (res < 0) {
4126 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4127 }
4128 ast_hangup(chan);
4129 }
4130 } else
4131 ast_log(LOG_WARNING, "Unable to create channel\n");
4132 }
4134 break;
4135 case ANALOG_SIG_FXSLS:
4136 case ANALOG_SIG_FXSGS:
4137 case ANALOG_SIG_FXSKS:
4139 /* Fall through */
4140 case ANALOG_SIG_EMWINK:
4141 case ANALOG_SIG_FEATD:
4142 case ANALOG_SIG_FEATDMF:
4144 case ANALOG_SIG_E911:
4147 case ANALOG_SIG_FEATB:
4148 case ANALOG_SIG_EM:
4149 case ANALOG_SIG_EM_E1:
4150 case ANALOG_SIG_SFWINK:
4154 case ANALOG_SIG_SF:
4155 callid_created = ast_callid_threadstorage_auto(&callid);
4156 /* Check for callerid, digits, etc */
4159 } else {
4161 }
4162 i->ss_astchan = chan;
4163 if (!chan) {
4164 ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
4165 } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4166 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4168 if (res < 0) {
4169 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4170 }
4171 ast_hangup(chan);
4172 }
4174 break;
4175 default:
4176 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);
4178 if (res < 0) {
4179 ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
4180 }
4181 return NULL;
4182 }
4183 break;
4185 analog_set_alarm(i, 0);
4187 break;
4188 case ANALOG_EVENT_ALARM:
4189 analog_set_alarm(i, 1);
4191 /* fall thru intentionally */
4193 /* Back on hook. Hang up. */
4194 switch (i->sig) {
4195 case ANALOG_SIG_FXOLS:
4196 case ANALOG_SIG_FXOGS:
4197 i->fxsoffhookstate = 0;
4199 /* Fall through */
4200 case ANALOG_SIG_FEATD:
4201 case ANALOG_SIG_FEATDMF:
4203 case ANALOG_SIG_E911:
4206 case ANALOG_SIG_FEATB:
4207 case ANALOG_SIG_EM:
4208 case ANALOG_SIG_EM_E1:
4209 case ANALOG_SIG_EMWINK:
4213 case ANALOG_SIG_SF:
4214 case ANALOG_SIG_SFWINK:
4215 case ANALOG_SIG_FXSLS:
4216 case ANALOG_SIG_FXSGS:
4217 case ANALOG_SIG_FXSKS:
4219 res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
4220 analog_on_hook(i);
4221 break;
4222 case ANALOG_SIG_FXOKS:
4223 i->fxsoffhookstate = 0;
4226 /* Diddle the battery for the zhone */
4227#ifdef ZHONE_HACK
4228 analog_off_hook(i);
4229 usleep(1);
4230#endif
4231 res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
4232 analog_on_hook(i);
4233 break;
4234 default:
4235 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);
4236 res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
4237 return NULL;
4238 }
4239 break;
4241 switch (i->sig) {
4242 case ANALOG_SIG_FXSLS:
4243 case ANALOG_SIG_FXSKS:
4244 case ANALOG_SIG_FXSGS:
4245 callid_created = ast_callid_threadstorage_auto(&callid);
4246 /* We have already got a PR before the channel was
4247 created, but it wasn't handled. We need polarity
4248 to be REV for remote hangup detection to work.
4249 At least in Spain */
4250 if (i->hanguponpolarityswitch) {
4252 }
4255 ast_verb(2, "Starting post polarity CID detection on channel %d\n",
4256 i->channel);
4258 i->ss_astchan = chan;
4259 if (!chan) {
4260 ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
4261 } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4262 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4263 ast_hangup(chan);
4264 }
4265 }
4267 break;
4268 default:
4270 "handle_init_event detected polarity reversal on non-FXO (ANALOG_SIG_FXS) interface %d\n",
4271 i->channel);
4272 break;
4273 }
4274 break;
4276 switch (i->sig) {
4277 case ANALOG_SIG_FXSLS:
4278 case ANALOG_SIG_FXSKS:
4279 case ANALOG_SIG_FXSGS:
4280 callid_created = ast_callid_threadstorage_auto(&callid);
4282 ast_verb(2, "Starting DTMF CID detection on channel %d\n",
4283 i->channel);
4285 i->ss_astchan = chan;
4286 if (!chan) {
4287 ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
4288 } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
4289 ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
4290 ast_hangup(chan);
4291 }
4292 }
4294 break;
4295 default:
4297 "handle_init_event detected dtmfcid generation event on non-FXO (ANALOG_SIG_FXS) interface %d\n",
4298 i->channel);
4299 break;
4300 }
4301 break;
4302 case ANALOG_EVENT_REMOVED: /* destroy channel, will actually do so in do_monitor */
4303 ast_log(LOG_NOTICE, "Got ANALOG_EVENT_REMOVED. Destroying channel %d\n",
4304 i->channel);
4305 return i->chan_pvt;
4308 break;
4311 break;
4312 }
4313 return NULL;
4314}
4315
4316
4317struct analog_pvt *analog_new(enum analog_sigtype signallingtype, void *private_data)
4318{
4319 struct analog_pvt *p;
4320
4321 p = ast_calloc(1, sizeof(*p));
4322 if (!p) {
4323 return p;
4324 }
4325
4327 p->sig = signallingtype;
4328 p->chan_pvt = private_data;
4329
4330 /* Some defaults for values */
4333 /* Sub real is assumed to always be alloc'd */
4334 p->subs[ANALOG_SUB_REAL].allocd = 1;
4335
4336 return p;
4337}
4338
4339/*!
4340 * \brief Delete the analog private structure.
4341 * \since 1.8
4342 *
4343 * \param doomed Analog private structure to delete.
4344 */
4345void analog_delete(struct analog_pvt *doomed)
4346{
4347 ast_free(doomed);
4348}
4349
4351{
4352 /* No call waiting on non FXS channels */
4353 if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) {
4354 p->permcallwaiting = 0;
4355 }
4356
4358
4359 return 0;
4360}
4361
4363{
4364 ast_free(p);
4365}
4366
4367/* called while dahdi_pvt is locked in dahdi_fixup */
4368int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp)
4369{
4370 struct analog_pvt *new_pvt = newp;
4371 int x;
4372 ast_debug(1, "New owner for channel %d is %s\n", new_pvt->channel, ast_channel_name(newchan));
4373 if (new_pvt->owner == oldchan) {
4374 analog_set_new_owner(new_pvt, newchan);
4375 }
4376 for (x = 0; x < 3; x++) {
4377 if (new_pvt->subs[x].owner == oldchan) {
4378 new_pvt->subs[x].owner = newchan;
4379 }
4380 }
4381
4382 analog_update_conf(new_pvt);
4383 return 0;
4384}
4385
4386static void analog_publish_dnd_state(int channel, const char *status)
4387{
4388 RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
4389 RAII_VAR(struct ast_str *, dahdichan, ast_str_create(32), ast_free);
4390 if (!dahdichan) {
4391 return;
4392 }
4393
4394 ast_str_set(&dahdichan, 0, "DAHDI/%d", channel);
4395
4396 body = ast_json_pack("{s: s, s: s}",
4397 "Channel", ast_str_buffer(dahdichan),
4398 "Status", status);
4399 if (!body) {
4400 return;
4401 }
4402
4404}
4405
4406int analog_dnd(struct analog_pvt *p, int flag)
4407{
4408 if (flag == -1) {
4409 return p->dnd;
4410 }
4411
4412 p->dnd = flag;
4413
4414 ast_verb(3, "%s DND on channel %d\n",
4415 flag ? "Enabled" : "Disabled",
4416 p->channel);
4417 analog_publish_dnd_state(p->channel, flag ? "enabled" : "disabled");
4418
4419 return 0;
4420}
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:4746
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
#define CID_SIG_V23_JP
Definition: callerid.h:63
#define AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED
Definition: callerid.h:449
#define CID_SIG_SMDI
Definition: callerid.h:64
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()'s,...
Definition: callerid.c:1101
#define CID_SIG_DTMF
Definition: callerid.h:62
#define CID_SIG_V23
Definition: callerid.h:61
void callerid_get_dtmf(char *cidstring, char *number, int *flags)
Get and parse DTMF-based callerid.
Definition: callerid.c:211
#define CID_SIG_BELL
Definition: callerid.h:60
#define AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED
Definition: callerid.h:437
Internal Asterisk hangup causes.
#define AST_CAUSE_NETWORK_OUT_OF_ORDER
Definition: causes.h:121
#define AST_CAUSE_NO_ANSWER
Definition: causes.h:109
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:106
#define AST_CC_GENERIC_MONITOR_TYPE
Definition: ccss.h:455
@ AST_CC_CCNR
Definition: ccss.h:38
@ AST_CC_MONITOR_NEVER
Definition: ccss.h:76
@ AST_CC_MONITOR_ALWAYS
Definition: ccss.h:87
@ AST_CC_MONITOR_NATIVE
Definition: ccss.h:78
@ AST_CC_MONITOR_GENERIC
Definition: ccss.h:83
enum ast_cc_monitor_policies ast_get_cc_monitor_policy(struct ast_cc_config_params *config)
Get the cc_monitor_policy.
Definition: ccss.c:882
int ast_queue_cc_frame(struct ast_channel *chan, const char *const monitor_type, const char *const dialstring, enum ast_cc_service_type service, void *private_data)
Queue an AST_CONTROL_CC frame.
Definition: ccss.c:4120
struct analog_callback analog_callbacks
Definition: chan_dahdi.c:3686
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:3143
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:2510
int ast_channel_rings(const struct ast_channel *chan)
int ast_queue_hangup(struct ast_channel *chan)
Queue a hangup frame.
Definition: channel.c:1180
#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:3130
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
Definition: channel.c:1269
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2997
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
@ AST_FLAG_END_DTMF_ONLY
Definition: channel.h:1027
ast_callid ast_channel_callid(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4210
#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:1276
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:7303
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:1204
@ AST_SOFTHANGUP_EXPLICIT
Definition: channel.h:1168
@ AST_SOFTHANGUP_DEV
Definition: channel.h:1141
void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
Set the source of the hangup in this channel and it's bridge.
Definition: channel.c:2468
int ast_softhangup(struct ast_channel *chan, int cause)
Softly hangup up a channel.
Definition: channel.c:2440
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:4300
int ast_queue_unhold(struct ast_channel *chan)
Queue an unhold frame.
Definition: channel.c:1254
int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
Queue a hold frame.
Definition: channel.c:1229
#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:10583
int ast_softhangup_nolock(struct ast_channel *chan, int cause)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2427
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:7391
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1541
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:10475
#define ast_channel_unlock(chan)
Definition: channel.h:2973
#define AST_MAX_EXTENSION
Definition: channel.h:134
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_RING
Definition: channelstate.h:40
@ AST_STATE_DIALING_OFFHOOK
Definition: channelstate.h:44
@ AST_STATE_RINGING
Definition: channelstate.h:41
@ AST_STATE_PRERING
Definition: channelstate.h:45
@ AST_STATE_DOWN
Definition: channelstate.h:36
@ AST_STATE_OFFHOOK
Definition: channelstate.h:38
@ AST_STATE_BUSY
Definition: channelstate.h:43
@ AST_STATE_DIALING
Definition: channelstate.h:39
@ AST_STATE_UP
Definition: channelstate.h:42
@ AST_STATE_RESERVED
Definition: channelstate.h:37
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7355
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:1301
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1848
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_manager_publish_event(const char *type, int class_type, struct ast_json *obj)
Publish an event to AMI.
Definition: manager.c:634
struct ast_features_pickup_config * ast_get_chan_features_pickup_config(struct ast_channel *chan)
Get the pickup configuration options for a channel.
#define AST_FRAME_DTMF
#define AST_OPTION_TONE_VERIFY
#define ast_frfree(fr)
#define AST_OPTION_TDD
@ AST_FRAME_NULL
@ AST_FRAME_DTMF_END
@ AST_FRAME_DTMF_BEGIN
@ AST_FRAME_CONTROL
@ AST_CONTROL_RING
@ AST_CONTROL_OFFHOOK
@ AST_CONTROL_BUSY
@ AST_CONTROL_PLAYBACK_BEGIN
@ AST_CONTROL_ANSWER
@ AST_CONTROL_RINGING
@ AST_CONTROL_FLASH
@ AST_CONTROL_PVT_CAUSE_CODE
struct ast_frame ast_null_frame
Definition: main/frame.c:79
void ast_callid_threadstorage_auto_clean(ast_callid callid, int callid_created)
Use in conjunction with ast_callid_threadstorage_auto. Cleans up the references and if the callid was...
Definition: logger.c:2353
#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:2295
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:2331
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_NOTICE
#define LOG_WARNING
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
int errno
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
#define EVENT_FLAG_SYSTEM
Definition: manager.h:75
Options provided by main asterisk program.
Call Parking API.
int ast_parking_blind_transfer_park(struct ast_bridge_channel *parker, const char *context, const char *exten, transfer_channel_cb parked_channel_cb, struct transfer_channel_data *parked_channel_data)
Perform a blind transfer to a parking extension.
Definition: parking.c:143
int ast_parking_is_exten_park(const char *context, const char *exten)
Determine if the context/exten is a "parking" extension.
Definition: parking.c:179
int ast_parking_provider_registered(void)
Check whether a parking provider is registered.
Definition: parking.c:241
Core PBX routines and definitions.
enum ast_pbx_result ast_pbx_run(struct ast_channel *c)
Execute the PBX in the current thread.
Definition: pbx.c:4776
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:4196
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks for a valid matching extension.
Definition: pbx.c:4211
int ast_ignore_pattern(const char *context, const char *pattern)
Checks to see if a number should be ignored.
Definition: pbx.c:6900
int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks to see if adding anything to this extension might match something. (exists ^ canmatch)
Definition: pbx.c:4216
Call Pickup API.
int ast_pickup_call(struct ast_channel *chan)
Pickup a call.
Definition: pickup.c:202
struct stasis_forward * sub
Definition: res_corosync.c:240
#define NULL
Definition: resample.c:96
Say numbers and dates (maybe words one day too)
int ast_say_digit_str(struct ast_channel *chan, const char *num, const char *ints, const char *lang)
says digits of a string
Definition: channel.c:8260
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:880
static void analog_publish_channel_alarm_clear(int channel)
Definition: sig_analog.c:2984
static int analog_my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms)
Definition: sig_analog.c:1834
static const struct @144 sigtypes[]
static void analog_set_alarm(struct analog_pvt *p, int in_alarm)
Definition: sig_analog.c:903
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:408
static int analog_stop_cid_detect(struct analog_pvt *p)
Definition: sig_analog.c:170
static char analog_defaultozz[64]
Definition: sig_analog.c:66
static int analog_alloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition: sig_analog.c:368
int analog_hangup(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:1277
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:935
static int analog_update_conf(struct analog_pvt *p)
Definition: sig_analog.c:743
static void analog_unlock_private(struct analog_pvt *p)
Definition: sig_analog.c:560
static int analog_callwait(struct analog_pvt *p)
Definition: sig_analog.c:871
static void analog_set_outgoing(struct analog_pvt *p, int is_outgoing)
Definition: sig_analog.c:537
callwaiting_deluxe_option
Definition: sig_analog.c:1593
@ CWD_DROP
Definition: sig_analog.c:1596
@ CWD_FORWARD
Definition: sig_analog.c:1598
@ CWD_HOLD
Definition: sig_analog.c:1595
@ CWD_CONFERENCE
Definition: sig_analog.c:1594
@ CWD_ANNOUNCEMENT
Definition: sig_analog.c:1597
static int analog_dsp_reset_and_flush_digits(struct analog_pvt *p)
Definition: sig_analog.c:428
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:667
static void analog_increase_ss_count(void)
Definition: sig_analog.c:1863
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:793
static char analog_defaultcic[64]
Definition: sig_analog.c:65
static void analog_publish_dnd_state(int channel, const char *status)
Definition: sig_analog.c:4386
static int analog_is_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:489
static void * analog_get_bridged_channel(struct ast_channel *chan)
Definition: sig_analog.c:1896
static int analog_dial_digits(struct analog_pvt *p, enum analog_sub sub, struct analog_dialoperation *dop)
Definition: sig_analog.c:521
static int analog_handle_notify_message(struct ast_channel *chan, struct analog_pvt *p, int cid_flags, int neon_mwievent)
Definition: sig_analog.c:1854
struct ast_frame * analog_exception(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:3913
#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:446
static struct ast_frame * __analog_handle_event(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:2997
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:454
static int analog_canmatch_featurecode(const char *pickupexten, const char *exten)
Definition: sig_analog.c:1914
static void * __analog_ss_thread(void *data)
Definition: sig_analog.c:1942
static int analog_flash(struct analog_pvt *p)
Definition: sig_analog.c:505
static int analog_attempt_transfer(struct analog_pvt *p)
Definition: sig_analog.c:710
static void analog_set_needringing(struct analog_pvt *p, int value)
Definition: sig_analog.c:623
static int analog_set_linear_mode(struct analog_pvt *p, enum analog_sub sub, int linear_mode)
Definition: sig_analog.c:973
int analog_dnd(struct analog_pvt *p, int flag)
Definition: sig_analog.c:4406
static void analog_hangup_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:652
static const struct @145 cidtypes[]
static int analog_check_waitingfordt(struct analog_pvt *p)
Definition: sig_analog.c:926
static int analog_train_echocanceller(struct analog_pvt *p)
Definition: sig_analog.c:481
static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
Definition: sig_analog.c:895
int analog_callwaiting_deluxe(struct analog_pvt *p, int option)
Definition: sig_analog.c:1619
int analog_config_complete(struct analog_pvt *p)
Definition: sig_analog.c:4350
static int analog_ring(struct analog_pvt *p)
Definition: sig_analog.c:497
static int analog_check_for_conference(struct analog_pvt *p)
Definition: sig_analog.c:545
void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub idx, struct ast_frame **dest)
Definition: sig_analog.c:1748
static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
Definition: sig_analog.c:911
int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout)
Definition: sig_analog.c:990
void analog_delete(struct analog_pvt *doomed)
Delete the analog private structure.
Definition: sig_analog.c:4345
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:888
struct analog_pvt * analog_new(enum analog_sigtype signallingtype, void *private_data)
Definition: sig_analog.c:4317
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:599
static int analog_handles_digit(struct ast_frame *f)
Definition: sig_analog.c:1568
void analog_free(struct analog_pvt *p)
Definition: sig_analog.c:4362
static void analog_lock_private(struct analog_pvt *p)
Definition: sig_analog.c:567
int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp)
Definition: sig_analog.c:4368
static int analog_dsp_set_digitmode(struct analog_pvt *p, enum analog_dsp_digitmode mode)
Definition: sig_analog.c:659
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:407
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:958
static void analog_answer_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:645
static int analog_on_hook(struct analog_pvt *p)
Definition: sig_analog.c:529
static void analog_get_and_handle_alarms(struct analog_pvt *p)
Definition: sig_analog.c:1889
static int analog_stop_callwait(struct analog_pvt *p)
Definition: sig_analog.c:862
static void analog_set_pulsedial(struct analog_pvt *p, int flag)
Definition: sig_analog.c:966
static int analog_start(struct analog_pvt *p)
Definition: sig_analog.c:513
static int analog_has_voicemail(struct analog_pvt *p)
Definition: sig_analog.c:682
static int analog_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:615
static void analog_decrease_ss_count(void)
Definition: sig_analog.c:1870
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:770
void * analog_handle_init_event(struct analog_pvt *i, int event)
Definition: sig_analog.c:4033
static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
Definition: sig_analog.c:438
#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:574
static int analog_set_echocanceller(struct analog_pvt *p, int enable)
Definition: sig_analog.c:473
static void analog_set_inthreeway(struct analog_pvt *p, enum analog_sub sub, int inthreeway)
Definition: sig_analog.c:982
#define POLARITY_IDLE
Definition: sig_analog.c:62
int analog_answer(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:1490
static int analog_check_confirmanswer(struct analog_pvt *p)
Definition: sig_analog.c:942
static int analog_wink(struct analog_pvt *p, enum analog_sub index)
Definition: sig_analog.c:674
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:690
static void analog_cancel_cidspill(struct analog_pvt *p)
Definition: sig_analog.c:951
static const char * callwaiting_deluxe_optname(int option)
Definition: sig_analog.c:1601
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:919
static int analog_distinctive_ring(struct ast_channel *chan, struct analog_pvt *p, int idx, int *ringdata)
Definition: sig_analog.c:1877
static void analog_all_subchannels_hungup(struct analog_pvt *p)
Definition: sig_analog.c:553
#define POLARITY_REV
Definition: sig_analog.c:63
enum analog_sigtype analog_str_to_sigtype(const char *name)
Definition: sig_analog.c:110
int analog_ss_thread_start(struct analog_pvt *p, struct ast_channel *chan)
Definition: sig_analog.c:2976
enum analog_cid_start analog_str_to_cidstart(const char *value)
Definition: sig_analog.c:234
#define ANALOG_NEED_MFDETECT(p)
Definition: sig_analog.c:1912
static int analog_get_sub_fd(struct analog_pvt *p, enum analog_sub sub)
Definition: sig_analog.c:1904
static void analog_start_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:639
Interface header for analog signaling module.
#define ANALOG_MAX_CID
Definition: sig_analog.h:33
analog_dsp_digitmode
Definition: sig_analog.h:114
@ ANALOG_DIGITMODE_DTMF
Definition: sig_analog.h:115
@ ANALOG_DIGITMODE_MF
Definition: sig_analog.h:116
#define ANALOG_INTER_DIGIT_TIMEOUT
Default time (ms) to detect following digits.
Definition: sig_analog.h:40
#define ANALOG_MATCH_DIGIT_TIMEOUT
Default time (ms) to wait, in case of ambiguous match.
Definition: sig_analog.h:42
@ ANALOG_DIALMODE_PULSE
Definition: sig_analog.h:121
@ ANALOG_DIALMODE_BOTH
Definition: sig_analog.h:120
#define ANALOG_SMDI_MD_WAIT_TIMEOUT
Definition: sig_analog.h:32
#define RING_PATTERNS
Definition: sig_analog.h:35
analog_event
Definition: sig_analog.h:79
@ ANALOG_EVENT_HOOKCOMPLETE
Definition: sig_analog.h:89
@ ANALOG_EVENT_DTMFDOWN
Definition: sig_analog.h:104
@ ANALOG_EVENT_RINGEROFF
Definition: sig_analog.h:88
@ ANALOG_EVENT_PULSE_START
Definition: sig_analog.h:90
@ ANALOG_EVENT_DTMFCID
Definition: sig_analog.h:102
@ ANALOG_EVENT_TX_CED_DETECTED
Definition: sig_analog.h:97
@ ANALOG_EVENT_NEONMWI_ACTIVE
Definition: sig_analog.h:95
@ ANALOG_EVENT_RINGBEGIN
Definition: sig_analog.h:92
@ ANALOG_EVENT_ONHOOK
Definition: sig_analog.h:81
@ ANALOG_EVENT_EC_DISABLED
Definition: sig_analog.h:93
@ ANALOG_EVENT_WINKFLASH
Definition: sig_analog.h:83
@ ANALOG_EVENT_PULSEDIGIT
Definition: sig_analog.h:103
@ ANALOG_EVENT_RINGERON
Definition: sig_analog.h:87
@ ANALOG_EVENT_RX_CED_DETECTED
Definition: sig_analog.h:98
@ ANALOG_EVENT_ALARM
Definition: sig_analog.h:84
@ ANALOG_EVENT_DIALCOMPLETE
Definition: sig_analog.h:86
@ ANALOG_EVENT_EC_NLP_ENABLED
Definition: sig_analog.h:100
@ ANALOG_EVENT_POLARITY
Definition: sig_analog.h:91
@ ANALOG_EVENT_NEONMWI_INACTIVE
Definition: sig_analog.h:96
@ ANALOG_EVENT_DTMFUP
Definition: sig_analog.h:105
@ ANALOG_EVENT_EC_NLP_DISABLED
Definition: sig_analog.h:99
@ ANALOG_EVENT_RINGOFFHOOK
Definition: sig_analog.h:82
@ ANALOG_EVENT_REMOVED
Definition: sig_analog.h:94
@ ANALOG_EVENT_NOALARM
Definition: sig_analog.h:85
@ ANALOG_DIAL_OP_REPLACE
Definition: sig_analog.h:134
analog_sub
Definition: sig_analog.h:108
@ ANALOG_SUB_THREEWAY
Definition: sig_analog.h:111
@ ANALOG_SUB_REAL
Definition: sig_analog.h:109
@ ANALOG_SUB_CALLWAIT
Definition: sig_analog.h:110
#define ANALOG_FIRST_DIGIT_TIMEOUT
Default time (ms) to detect first digit.
Definition: sig_analog.h:38
analog_sigtype
Definition: sig_analog.h:45
@ ANALOG_SIG_FEATD
Definition: sig_analog.h:56
@ ANALOG_SIG_FEATDMF_TA
Definition: sig_analog.h:66
@ ANALOG_SIG_FGC_CAMAMF
Definition: sig_analog.h:60
@ ANALOG_SIG_FXOLS
Definition: sig_analog.h:47
@ ANALOG_SIG_FEATDMF
Definition: sig_analog.h:57
@ ANALOG_SIG_EM_E1
Definition: sig_analog.h:55
@ ANALOG_SIG_EMWINK
Definition: sig_analog.h:53
@ ANALOG_SIG_FXOKS
Definition: sig_analog.h:48
@ ANALOG_SIG_SF
Definition: sig_analog.h:63
@ ANALOG_SIG_FGC_CAMA
Definition: sig_analog.h:59
@ ANALOG_SIG_FXSLS
Definition: sig_analog.h:50
@ ANALOG_SIG_EM
Definition: sig_analog.h:54
@ ANALOG_SIG_FXOGS
Definition: sig_analog.h:49
@ ANALOG_SIG_SF_FEATB
Definition: sig_analog.h:67
@ ANALOG_SIG_NONE
Definition: sig_analog.h:46
@ ANALOG_SIG_FXSGS
Definition: sig_analog.h:52
@ ANALOG_SIG_SF_FEATDMF
Definition: sig_analog.h:65
@ ANALOG_SIG_SFWINK
Definition: sig_analog.h:62
@ ANALOG_SIG_E911
Definition: sig_analog.h:58
@ ANALOG_SIG_FEATB
Definition: sig_analog.h:61
@ ANALOG_SIG_SF_FEATD
Definition: sig_analog.h:64
@ ANALOG_SIG_FXSKS
Definition: sig_analog.h:51
analog_tone
Definition: sig_analog.h:70
@ ANALOG_TONE_CONGESTION
Definition: sig_analog.h:73
@ ANALOG_TONE_INFO
Definition: sig_analog.h:76
@ ANALOG_TONE_DIALTONE
Definition: sig_analog.h:74
@ ANALOG_TONE_DIALRECALL
Definition: sig_analog.h:75
@ ANALOG_TONE_STUTTER
Definition: sig_analog.h:72
@ ANALOG_TONE_RINGTONE
Definition: sig_analog.h:71
analog_cid_start
Definition: sig_analog.h:126
@ ANALOG_CID_START_RING
Definition: sig_analog.h:129
@ ANALOG_CID_START_DTMF_NOALERT
Definition: sig_analog.h:130
@ ANALOG_CID_START_POLARITY
Definition: sig_analog.h:127
@ ANALOG_CID_START_POLARITY_IN
Definition: sig_analog.h:128
struct ast_smdi_md_message * ast_smdi_md_message_wait(struct ast_smdi_interface *iface, int timeout)
Get the next SMDI message from the queue.
Definition: res_smdi.c:545
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
int(*const stop_cid_detect)(void *pvt)
Definition: sig_analog.h:194
int(*const set_echocanceller)(void *pvt, int enable)
Definition: sig_analog.h:184
void(*const deadlock_avoidance_private)(void *pvt)
Definition: sig_analog.h:149
int(*const unallocate_sub)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:203
int(*const distinctive_ring)(struct ast_channel *chan, void *pvt, int idx, int *ringdata)
Definition: sig_analog.h:230
int(*const stop_callwait)(void *pvt)
Definition: sig_analog.h:199
void(*const set_confirmanswer)(void *pvt, int flag)
Definition: sig_analog.h:244
void(*const set_callwaiting)(void *pvt, int callwaiting_enable)
Definition: sig_analog.h:246
void(*const unlock_private)(void *pvt)
Definition: sig_analog.h:145
int(*const check_confirmanswer)(void *pvt)
Definition: sig_analog.h:245
const char *(*const get_orig_dialstring)(void *pvt)
Definition: sig_analog.h:252
void(*const set_cadence)(void *pvt, int *cidrings, struct ast_channel *chan)
Definition: sig_analog.h:237
int(*const have_progressdetect)(void *pvt)
Definition: sig_analog.h:253
void(*const hangup_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch and hanguponpolarityswitch.
Definition: sig_analog.h:176
int(*const is_off_hook)(void *pvt)
Definition: sig_analog.h:158
void(*const decrease_ss_count)(void)
Definition: sig_analog.h:228
int(*const is_dialing)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:159
int(*const train_echocanceller)(void *pvt)
Definition: sig_analog.h:185
void(*const set_pulsedial)(void *pvt, int flag)
Definition: sig_analog.h:249
int(*const check_waitingfordt)(void *pvt)
Definition: sig_analog.h:243
int(*const get_callerid)(void *pvt, char *name, char *num, enum analog_event *ev, size_t timeout)
Definition: sig_analog.h:190
int(*const conf_add)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:210
int(*const ring)(void *pvt)
Definition: sig_analog.h:162
void(*const handle_dtmf)(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
Definition: sig_analog.h:154
int(*const flash)(void *pvt)
Definition: sig_analog.h:163
int(*const start_cid_detect)(void *pvt, int cid_signalling)
Definition: sig_analog.h:192
void(*const swap_subs)(void *pvt, enum analog_sub a, struct ast_channel *new_a_owner, enum analog_sub b, struct ast_channel *new_b_owner)
Definition: sig_analog.h:206
int(*const confmute)(void *pvt, int mute)
Definition: sig_analog.h:248
void(*const handle_notify_message)(struct ast_channel *chan, void *pvt, int cid_flags, int neon_mwievent)
Definition: sig_analog.h:224
int(*const set_linear_mode)(void *pvt, enum analog_sub sub, int linear_mode)
Definition: sig_analog.h:232
int(*const complete_conference_update)(void *pvt, int needconf)
Definition: sig_analog.h:216
void(*const set_outgoing)(void *pvt, int is_outgoing)
Definition: sig_analog.h:240
int(*const on_hook)(void *pvt)
Set channel on hook.
Definition: sig_analog.h:165
void(*const set_dialing)(void *pvt, int is_dialing)
Definition: sig_analog.h:239
void(*const answer_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch=yes.
Definition: sig_analog.h:174
int(*const dsp_set_digitmode)(void *pvt, enum analog_dsp_digitmode mode)
Definition: sig_analog.h:186
void(*const set_alarm)(void *pvt, int in_alarm)
Definition: sig_analog.h:238
void(*const set_new_owner)(void *pvt, struct ast_channel *new_owner)
Definition: sig_analog.h:250
int(*const send_callerid)(void *pvt, int cwcid, struct ast_party_caller *caller)
Definition: sig_analog.h:188
void(*const set_inthreeway)(void *pvt, enum analog_sub sub, int inthreeway)
Definition: sig_analog.h:233
void(*const increase_ss_count)(void)
Definition: sig_analog.h:227
void(*const cancel_cidspill)(void *pvt)
Definition: sig_analog.h:247
int(*const dial_digits)(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop)
Definition: sig_analog.h:180
int(*const conf_del)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:212
int(*const has_voicemail)(void *pvt)
Definition: sig_analog.h:222
int(*const check_for_conference)(void *pvt)
Definition: sig_analog.h:223
int(*const allocate_sub)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:202
int(*const wink)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:179
int(*const off_hook)(void *pvt)
Set channel off hook.
Definition: sig_analog.h:167
int(*const dsp_reset_and_flush_digits)(void *pvt)
Definition: sig_analog.h:187
void(*const set_ringtimeout)(void *pvt, int ringt)
Definition: sig_analog.h:241
void(*const lock_private)(void *pvt)
Definition: sig_analog.h:147
void(*const all_subchannels_hungup)(void *pvt)
Definition: sig_analog.h:220
int(*const play_tone)(void *pvt, enum analog_sub sub, enum analog_tone tone)
Definition: sig_analog.h:182
void(*const get_and_handle_alarms)(void *pvt)
Definition: sig_analog.h:234
int(*const start)(void *pvt)
Definition: sig_analog.h:161
int(*const callwait)(void *pvt)
Definition: sig_analog.h:197
void(*const set_waitingfordt)(void *pvt, struct ast_channel *ast)
Definition: sig_analog.h:242
void(*const start_polarityswitch)(void *pvt)
Reset FXS line polarity to IDLE, based on answeronpolarityswitch and hanguponpolarityswitch.
Definition: sig_analog.h:172
struct ast_channel *(*const new_ast_channel)(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
Definition: sig_analog.h:207
int(*const get_event)(void *pvt)
Definition: sig_analog.h:156
void(*const set_needringing)(void *pvt, int value)
Definition: sig_analog.h:168
void *(*const get_sigpvt_bridged_channel)(struct ast_channel *chan)
Definition: sig_analog.h:235
void(*const set_polarity)(void *pvt, int value)
Set FXS line polarity to 0=IDLE NZ=REVERSED.
Definition: sig_analog.h:170
int(*const get_sub_fd)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:236
int(*const wait_event)(void *pvt)
Definition: sig_analog.h:157
char dialdest[256]
Definition: sig_analog.h:371
unsigned int immediate
Definition: sig_analog.h:298
unsigned int immediatering
Definition: sig_analog.h:299
unsigned int threewaysilenthold
Definition: sig_analog.h:306
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:355
unsigned int canpark
Definition: sig_analog.h:295
void * chan_pvt
Definition: sig_analog.h:275
unsigned int dnd
Definition: sig_analog.h:339
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:363
int polarityonanswerdelay
Definition: sig_analog.h:326
char cid_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:330
int redirecting_reason
Definition: sig_analog.h:365
unsigned int permhidecallerid
Definition: sig_analog.h:303
char * origcid_name
Definition: sig_analog.h:377
struct timeval flashtime
Definition: sig_analog.h:373
unsigned int outgoing
Definition: sig_analog.h:342
int whichwink
Definition: sig_analog.h:374
unsigned int callwaitingcallerid
Definition: sig_analog.h:311
char * origcid_num
Definition: sig_analog.h:376
unsigned int ani_wink_time
Definition: sig_analog.h:289
enum analog_sigtype outsigmod
Definition: sig_analog.h:322
unsigned int usedistinctiveringdetection
Definition: sig_analog.h:310
unsigned int answeronpolarityswitch
Definition: sig_analog.h:291
unsigned int threewaycalling
Definition: sig_analog.h:305
unsigned int pulse
Definition: sig_analog.h:304
int echotraining
Definition: sig_analog.h:324
char callwait_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:359
int msgstate
-1 = unknown, 0 = no messages, 1 = new messages available
Definition: sig_analog.h:284
int onhooktime
Definition: sig_analog.h:281
unsigned int callwaiting
Definition: sig_analog.h:335
time_t guardtime
Definition: sig_analog.h:372
struct timeval polaritydelaytv
Definition: sig_analog.h:370
unsigned int hanguponpolarityswitch
Definition: sig_analog.h:297
int cidrings
Definition: sig_analog.h:367
unsigned int callwaitingdeluxe
Definition: sig_analog.h:302
char call_forward[AST_MAX_EXTENSION]
Definition: sig_analog.h:378
enum analog_cid_start cid_start
Definition: sig_analog.h:328
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
Definition: sig_analog.h:350
unsigned int hidecallerid
Definition: sig_analog.h:341
unsigned int echobreak
Definition: sig_analog.h:340
unsigned int cshactive
Definition: sig_analog.h:336
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:315
char lastcid_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:362
enum analog_sigtype sig
Definition: sig_analog.h:273
unsigned int dialednone
Definition: sig_analog.h:337
unsigned int call_qualifier
Definition: sig_analog.h:357
char echorest[20]
Definition: sig_analog.h:368
unsigned int ani_timeout
Definition: sig_analog.h:288
unsigned int lastnumredial
Definition: sig_analog.h:300
int ringt_base
Definition: sig_analog.h:385
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:323
unsigned int cancallforward
Definition: sig_analog.h:294
char lastcid_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:361
struct analog_subchannel subs[3]
Definition: sig_analog.h:279
int cid_signalling
Definition: sig_analog.h:325
char finaldial[64]
Definition: sig_analog.h:375
unsigned int transfer
Definition: sig_analog.h:307
unsigned int transfertobusy
Definition: sig_analog.h:308
unsigned int inalarm
Definition: sig_analog.h:343
char cid_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:331
int stripmsd
Definition: sig_analog.h:327
unsigned int calledsubscriberheld
Definition: sig_analog.h:292
char mohsuggest[MAX_MUSICCLASS]
Definition: sig_analog.h:329
unsigned int use_callerid
Definition: sig_analog.h:309
int polarity
Definition: sig_analog.h:369
struct ast_channel * ss_astchan
Definition: sig_analog.h:381
unsigned int dialing
Definition: sig_analog.h:338
char callwait_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:360
struct ast_smdi_interface * smdi_iface
The SMDI interface to get SMDI messages from.
Definition: sig_analog.h:317
struct ast_party_caller caller
Definition: sig_analog.h:364
unsigned int allocd
Definition: sig_analog.h:268
struct ast_frame f
Definition: sig_analog.h:265
unsigned int inthreeway
Definition: sig_analog.h:266
struct ast_channel * owner
Definition: sig_analog.h:264
Structure that contains information regarding a channel in a bridge.
struct ast_channel * chan
Main Channel structure associated with a channel.
ast_callid callid
char exten[AST_MAX_EXTENSION]
char x
Definition: extconf.c:81
struct ast_flags flags
struct ast_party_caller caller
Channel Caller ID information.
char chan_name[AST_CHANNEL_NAME]
Configuration relating to call pickup.
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
struct timeval delivery
enum ast_frame_type frametype
unsigned int flags
union ast_frame::@231 data
const char * src
Abstract JSON element (object, array, string, int, ...).
Caller Party information.
Definition: channel.h:420
struct ast_party_id id
Caller party ID.
Definition: channel.h:422
int ani2
Automatic Number Identification 2 (Info Digits)
Definition: channel.h:435
struct ast_party_id ani
Automatic Number Identification (ANI)
Definition: channel.h:429
struct ast_party_id id
Connected party ID.
Definition: channel.h:460
struct ast_party_name name
Subscriber name.
Definition: channel.h:342
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:344
int presentation
Q.931 encoded presentation-indicator encoded field.
Definition: channel.h:279
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:281
char * str
Subscriber name (Malloced)
Definition: channel.h:266
int presentation
Q.931 presentation-indicator and screening-indicator encoded fields.
Definition: channel.h:297
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:299
char * str
Subscriber phone number (Malloced)
Definition: channel.h:293
int code
enum AST_REDIRECTING_REASON value for redirection
Definition: channel.h:512
struct ast_party_redirecting_reason reason
Reason for the redirection.
Definition: channel.h:544
struct ast_party_id from
Who is redirecting the call (Sent to the party the call is redirected toward)
Definition: channel.h:529
An SMDI message desk message.
Definition: smdi.h:65
char calling_st[SMDI_MAX_STATION_NUM_LEN+1]
Definition: smdi.h:70
char fwd_st[SMDI_MAX_STATION_NUM_LEN+1]
Definition: smdi.h:69
Support for dynamic strings.
Definition: strings.h:623
Definition: astman.c:222
Number structure.
Definition: app_followme.c:157
int value
Definition: syslog.c:37
static struct test_val b
static struct test_val a
static struct test_val c
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition: utils.c:2281
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:965
#define ast_assert(a)
Definition: utils.h:763
#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:612
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define ARRAY_LEN(a)
Definition: utils.h:690