Asterisk - The Open Source Telephony Project  18.5.0
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 <[email protected]>
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 <[email protected]>
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 */
65 static char analog_defaultcic[64] = "";
66 static char analog_defaultozz[64] = "";
67 
68 static 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 
95 static 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. */
105 };
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 
136 unsigned 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 
149 const 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 
162 static 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 
170 static int analog_stop_cid_detect(struct analog_pvt *p)
171 {
174  }
175  return -1;
176 }
177 
178 static 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 
186 static const char *analog_get_orig_dialstring(struct analog_pvt *p)
187 {
190  }
191  return "";
192 }
193 
194 static int analog_get_event(struct analog_pvt *p)
195 {
198  }
199  return -1;
200 }
201 
202 static 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 
228 gen_analog_field_callback(int, firstdigit_timeout, ANALOG_FIRST_DIGIT_TIMEOUT);
229 gen_analog_field_callback(int, interdigit_timeout, ANALOG_INTER_DIGIT_TIMEOUT);
230 gen_analog_field_callback(int, matchdigit_timeout, ANALOG_MATCH_DIGIT_TIMEOUT);
231 
232 #undef gen_analog_field_callback
233 
235 {
236  if (!strcasecmp(value, "ring")) {
237  return ANALOG_CID_START_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 
249 const 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) {
269  case ANALOG_EVENT_ONHOOK:
270  res = "ANALOG_EVENT_ONHOOK";
271  break;
273  res = "ANALOG_EVENT_RINGOFFHOOK";
274  break;
276  res = "ANALOG_EVENT_WINKFLASH";
277  break;
278  case ANALOG_EVENT_ALARM:
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;
337  case ANALOG_EVENT_DTMFUP:
338  res = "ANALOG_EVENT_DTMFUP";
339  break;
340  default:
341  res = "UNKNOWN/OTHER";
342  break;
343  }
344 
345  return res;
346 }
347 
348 static 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 
364  analog_callbacks.swap_subs(p->chan_pvt, a, p->subs[a].owner, b, p->subs[b].owner);
365  }
366 }
367 
368 static 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 
381 static 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 
391 static 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,
395  caller->id.number.str);
396 
397  if (cwcid) {
398  p->callwaitcas = 0;
399  }
400 
402  return analog_callbacks.send_callerid(p->chan_pvt, cwcid, caller);
403  }
404  return 0;
405 }
406 
407 #define analog_get_index(ast, p, nullok) _analog_get_index(ast, p, nullok, __PRETTY_FUNCTION__, __LINE__)
408 static 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) {
414  res = ANALOG_SUB_CALLWAIT;
415  } else if (p->subs[ANALOG_SUB_THREEWAY].owner == ast) {
416  res = ANALOG_SUB_THREEWAY;
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 
438 static 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 
446 static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
447 {
448  p->owner = new_owner;
450  analog_callbacks.set_new_owner(p->chan_pvt, new_owner);
451  }
452 }
453 
454 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)
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) {
468  analog_set_new_owner(p, c);
469  }
470  return c;
471 }
472 
473 static int analog_set_echocanceller(struct analog_pvt *p, int enable)
474 {
476  return analog_callbacks.set_echocanceller(p->chan_pvt, enable);
477  }
478  return -1;
479 }
480 
482 {
485  }
486  return -1;
487 }
488 
489 static int analog_is_off_hook(struct analog_pvt *p)
490 {
493  }
494  return -1;
495 }
496 
497 static int analog_ring(struct analog_pvt *p)
498 {
499  if (analog_callbacks.ring) {
500  return analog_callbacks.ring(p->chan_pvt);
501  }
502  return -1;
503 }
504 
505 static int analog_flash(struct analog_pvt *p)
506 {
507  if (analog_callbacks.flash) {
508  return analog_callbacks.flash(p->chan_pvt);
509  }
510  return -1;
511 }
512 
513 static int analog_start(struct analog_pvt *p)
514 {
515  if (analog_callbacks.start) {
516  return analog_callbacks.start(p->chan_pvt);
517  }
518  return -1;
519 }
520 
521 static 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 
529 static int analog_on_hook(struct analog_pvt *p)
530 {
532  return analog_callbacks.on_hook(p->chan_pvt);
533  }
534  return -1;
535 }
536 
537 static 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 
560 static void analog_unlock_private(struct analog_pvt *p)
561 {
564  }
565 }
566 
567 static 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  *
599  * \return Nothing
600  */
601 static void analog_lock_sub_owner(struct analog_pvt *pvt, enum analog_sub sub_idx)
602 {
603  for (;;) {
604  if (!pvt->subs[sub_idx].owner) {
605  /* No subchannel owner pointer */
606  break;
607  }
608  if (!ast_channel_trylock(pvt->subs[sub_idx].owner)) {
609  /* Got subchannel owner lock */
610  break;
611  }
612  /* We must unlock the private to avoid the possibility of a deadlock */
614  }
615 }
616 
617 static int analog_off_hook(struct analog_pvt *p)
618 {
621  }
622  return -1;
623 }
624 
625 static void analog_set_needringing(struct analog_pvt *p, int value)
626 {
629  }
630 }
631 
632 #if 0
633 static void analog_set_polarity(struct analog_pvt *p, int value)
634 {
637  }
638 }
639 #endif
640 
642 {
645  }
646 }
648 {
651  }
652 }
653 
655 {
658  }
659 }
660 
662 {
665  }
666  return -1;
667 }
668 
669 static void analog_cb_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
670 {
672  analog_callbacks.handle_dtmf(p->chan_pvt, ast, analog_index, dest);
673  }
674 }
675 
676 static int analog_wink(struct analog_pvt *p, enum analog_sub index)
677 {
678  if (analog_callbacks.wink) {
679  return analog_callbacks.wink(p->chan_pvt, index);
680  }
681  return -1;
682 }
683 
684 static int analog_has_voicemail(struct analog_pvt *p)
685 {
688  }
689  return -1;
690 }
691 
692 static int analog_is_dialing(struct analog_pvt *p, enum analog_sub index)
693 {
695  return analog_callbacks.is_dialing(p->chan_pvt, index);
696  }
697  return -1;
698 }
699 
700 /*!
701  * \internal
702  * \brief Attempt to transfer 3-way call.
703  *
704  * \param p Analog private structure.
705  *
706  * \note On entry these locks are held: real-call, private, 3-way call.
707  * \note On exit these locks are held: real-call, private.
708  *
709  * \retval 0 on success.
710  * \retval -1 on error.
711  */
712 static int analog_attempt_transfer(struct analog_pvt *p)
713 {
714  struct ast_channel *owner_real;
715  struct ast_channel *owner_3way;
716  enum ast_transfer_result xfer_res;
717  int res = 0;
718 
719  owner_real = ast_channel_ref(p->subs[ANALOG_SUB_REAL].owner);
720  owner_3way = ast_channel_ref(p->subs[ANALOG_SUB_THREEWAY].owner);
721 
722  ast_verb(3, "TRANSFERRING %s to %s\n",
723  ast_channel_name(owner_3way), ast_channel_name(owner_real));
724 
725  ast_channel_unlock(owner_real);
726  ast_channel_unlock(owner_3way);
728 
729  xfer_res = ast_bridge_transfer_attended(owner_3way, owner_real);
730  if (xfer_res != AST_BRIDGE_TRANSFER_SUCCESS) {
731  ast_softhangup(owner_3way, AST_SOFTHANGUP_DEV);
732  res = -1;
733  }
734 
735  /* Must leave with these locked. */
736  ast_channel_lock(owner_real);
738 
739  ast_channel_unref(owner_real);
740  ast_channel_unref(owner_3way);
741 
742  return res;
743 }
744 
745 static int analog_update_conf(struct analog_pvt *p)
746 {
747  int x;
748  int needconf = 0;
749 
750  /* Start with the obvious, general stuff */
751  for (x = 0; x < 3; x++) {
752  /* Look for three way calls */
753  if ((p->subs[x].allocd) && p->subs[x].inthreeway) {
756  }
757  needconf++;
758  } else {
761  }
762  }
763  }
764  ast_debug(1, "Updated conferencing on %d, with %d conference users\n", p->channel, needconf);
765 
768  }
769  return 0;
770 }
771 
772 struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor)
773 {
774  struct ast_channel *ast;
775 
776  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
777  *callwait = (p->owner != NULL);
778 
779  if (p->owner) {
781  ast_log(LOG_ERROR, "Unable to alloc subchannel\n");
782  return NULL;
783  }
784  }
785 
786  analog_set_outgoing(p, 1);
788  p->owner ? ANALOG_SUB_CALLWAIT : ANALOG_SUB_REAL, requestor);
789  if (!ast) {
790  analog_set_outgoing(p, 0);
791  }
792  return ast;
793 }
794 
796 {
797  int offhook;
798 
799  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
800 
801  /* If do not disturb, definitely not */
802  if (p->dnd) {
803  return 0;
804  }
805  /* If guard time, definitely not */
806  if (p->guardtime && (time(NULL) < p->guardtime)) {
807  return 0;
808  }
809 
810  /* If no owner definitely available */
811  if (!p->owner) {
812  offhook = analog_is_off_hook(p);
813 
814  /* TDM FXO card, "onhook" means out of service (no battery on the line) */
815  if ((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || (p->sig == ANALOG_SIG_FXSGS)) {
816 #ifdef DAHDI_CHECK_HOOKSTATE
817  if (offhook) {
818  return 1;
819  }
820  return 0;
821 #endif
822  /* TDM FXS card, "offhook" means someone took the hook off so it's unavailable! */
823  } else if (offhook) {
824  ast_debug(1, "Channel %d off hook, can't use\n", p->channel);
825  /* Not available when the other end is off hook */
826  return 0;
827  }
828  return 1;
829  }
830 
831  /* If it's not an FXO, forget about call wait */
832  if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) {
833  return 0;
834  }
835 
836  if (!p->callwaiting) {
837  /* If they don't have call waiting enabled, then for sure they're unavailable at this point */
838  return 0;
839  }
840 
841  if (p->subs[ANALOG_SUB_CALLWAIT].allocd) {
842  /* If there is already a call waiting call, then we can't take a second one */
843  return 0;
844  }
845 
846  if ((ast_channel_state(p->owner) != AST_STATE_UP) &&
848  /* If the current call is not up, then don't allow the call */
849  return 0;
850  }
852  /* Can't take a call wait when the three way calling hasn't been merged yet. */
853  return 0;
854  }
855  /* We're cool */
856  return 1;
857 }
858 
859 static int analog_stop_callwait(struct analog_pvt *p)
860 {
861  p->callwaitcas = 0;
864  }
865  return 0;
866 }
867 
868 static int analog_callwait(struct analog_pvt *p)
869 {
873  }
874  return 0;
875 }
876 
877 static void analog_set_callwaiting(struct analog_pvt *p, int callwaiting_enable)
878 {
879  p->callwaiting = callwaiting_enable;
881  analog_callbacks.set_callwaiting(p->chan_pvt, callwaiting_enable);
882  }
883 }
884 
885 static void analog_set_cadence(struct analog_pvt *p, struct ast_channel *chan)
886 {
889  }
890 }
891 
892 static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
893 {
894  p->dialing = is_dialing;
896  analog_callbacks.set_dialing(p->chan_pvt, is_dialing);
897  }
898 }
899 
900 static void analog_set_alarm(struct analog_pvt *p, int in_alarm)
901 {
902  p->inalarm = in_alarm;
904  analog_callbacks.set_alarm(p->chan_pvt, in_alarm);
905  }
906 }
907 
908 static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
909 {
910  p->ringt = ringt;
913  }
914 }
915 
916 static void analog_set_waitingfordt(struct analog_pvt *p, struct ast_channel *ast)
917 {
920  }
921 }
922 
924 {
927  }
928 
929  return 0;
930 }
931 
932 static void analog_set_confirmanswer(struct analog_pvt *p, int flag)
933 {
936  }
937 }
938 
940 {
943  }
944 
945  return 0;
946 }
947 
948 static void analog_cancel_cidspill(struct analog_pvt *p)
949 {
952  }
953 }
954 
955 static int analog_confmute(struct analog_pvt *p, int mute)
956 {
958  return analog_callbacks.confmute(p->chan_pvt, mute);
959  }
960  return 0;
961 }
962 
963 static void analog_set_pulsedial(struct analog_pvt *p, int flag)
964 {
967  }
968 }
969 
970 static int analog_set_linear_mode(struct analog_pvt *p, enum analog_sub sub, int linear_mode)
971 {
973  /* Return provides old linear_mode setting or error indication */
974  return analog_callbacks.set_linear_mode(p->chan_pvt, sub, linear_mode);
975  }
976  return -1;
977 }
978 
979 static void analog_set_inthreeway(struct analog_pvt *p, enum analog_sub sub, int inthreeway)
980 {
981  p->subs[sub].inthreeway = inthreeway;
983  analog_callbacks.set_inthreeway(p->chan_pvt, sub, inthreeway);
984  }
985 }
986 
987 int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout)
988 {
989  int res, idx, mysig;
990  char *c, *n, *l;
991  char dest[256]; /* must be same length as p->dialdest */
992 
993  ast_debug(1, "CALLING CID_NAME: %s CID_NUM:: %s\n",
994  S_COR(ast_channel_connected(ast)->id.name.valid, ast_channel_connected(ast)->id.name.str, ""),
995  S_COR(ast_channel_connected(ast)->id.number.valid, ast_channel_connected(ast)->id.number.str, ""));
996 
997  ast_copy_string(dest, rdest, sizeof(dest));
998  ast_copy_string(p->dialdest, rdest, sizeof(p->dialdest));
999 
1000  if ((ast_channel_state(ast) == AST_STATE_BUSY)) {
1002  return 0;
1003  }
1004 
1006  ast_log(LOG_WARNING, "analog_call called on %s, neither down nor reserved\n", ast_channel_name(ast));
1007  return -1;
1008  }
1009 
1010  p->dialednone = 0;
1011  analog_set_outgoing(p, 1);
1012 
1013  mysig = p->sig;
1014  if (p->outsigmod > -1) {
1015  mysig = p->outsigmod;
1016  }
1017 
1018  switch (mysig) {
1019  case ANALOG_SIG_FXOLS:
1020  case ANALOG_SIG_FXOGS:
1021  case ANALOG_SIG_FXOKS:
1022  if (p->owner == ast) {
1023  /* Normal ring, on hook */
1024 
1025  /* Don't send audio while on hook, until the call is answered */
1026  analog_set_dialing(p, 1);
1027  analog_set_cadence(p, ast); /* and set p->cidrings */
1028 
1029  /* [email protected] 4/3/03 mods to allow for deferred dialing */
1030  c = strchr(dest, '/');
1031  if (c) {
1032  c++;
1033  }
1034  if (c && (strlen(c) < p->stripmsd)) {
1035  ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1036  c = NULL;
1037  }
1038  if (c) {
1040  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "Tw%s", c);
1041  ast_debug(1, "FXO: setup deferred dialstring: %s\n", c);
1042  } else {
1043  p->dop.dialstr[0] = '\0';
1044  }
1045 
1046  if (analog_ring(p)) {
1047  ast_log(LOG_WARNING, "Unable to ring phone: %s\n", strerror(errno));
1048  return -1;
1049  }
1050  analog_set_dialing(p, 1);
1051  } else {
1052  /* Call waiting call */
1053  if (ast_channel_connected(ast)->id.number.valid && ast_channel_connected(ast)->id.number.str) {
1055  } else {
1056  p->callwait_num[0] = '\0';
1057  }
1058  if (ast_channel_connected(ast)->id.name.valid && ast_channel_connected(ast)->id.name.str) {
1060  } else {
1061  p->callwait_name[0] = '\0';
1062  }
1063 
1064  /* Call waiting tone instead */
1065  if (analog_callwait(p)) {
1066  return -1;
1067  }
1068  /* Make ring-back */
1070  ast_log(LOG_WARNING, "Unable to generate call-wait ring-back on channel %s\n", ast_channel_name(ast));
1071  }
1072 
1073  }
1076  if (l) {
1077  ast_copy_string(p->lastcid_num, l, sizeof(p->lastcid_num));
1078  } else {
1079  p->lastcid_num[0] = '\0';
1080  }
1081  if (n) {
1082  ast_copy_string(p->lastcid_name, n, sizeof(p->lastcid_name));
1083  } else {
1084  p->lastcid_name[0] = '\0';
1085  }
1086 
1087  if (p->use_callerid) {
1088  p->caller.id.name.str = p->lastcid_name;
1089  p->caller.id.number.str = p->lastcid_num;
1090  }
1091 
1093  idx = analog_get_index(ast, p, 0);
1094  if (idx > -1) {
1095  struct ast_cc_config_params *cc_params;
1096 
1097  /* This is where the initial ringing frame is queued for an analog call.
1098  * As such, this is a great time to offer CCNR to the caller if it's available.
1099  */
1100  cc_params = ast_channel_get_cc_config_params(p->subs[idx].owner);
1101  if (cc_params) {
1102  switch (ast_get_cc_monitor_policy(cc_params)) {
1103  case AST_CC_MONITOR_NEVER:
1104  break;
1105  case AST_CC_MONITOR_NATIVE:
1106  case AST_CC_MONITOR_ALWAYS:
1110  break;
1111  }
1112  }
1114  }
1115  break;
1116  case ANALOG_SIG_FXSLS:
1117  case ANALOG_SIG_FXSGS:
1118  case ANALOG_SIG_FXSKS:
1120  ast_debug(1, "Ignore possible polarity reversal on line seizure\n");
1121  p->polaritydelaytv = ast_tvnow();
1122  }
1123  /* fall through */
1124  case ANALOG_SIG_EMWINK:
1125  case ANALOG_SIG_EM:
1126  case ANALOG_SIG_EM_E1:
1127  case ANALOG_SIG_FEATD:
1128  case ANALOG_SIG_FEATDMF:
1129  case ANALOG_SIG_E911:
1130  case ANALOG_SIG_FGC_CAMA:
1131  case ANALOG_SIG_FGC_CAMAMF:
1132  case ANALOG_SIG_FEATB:
1133  case ANALOG_SIG_SFWINK:
1134  case ANALOG_SIG_SF:
1135  case ANALOG_SIG_SF_FEATD:
1136  case ANALOG_SIG_SF_FEATDMF:
1137  case ANALOG_SIG_FEATDMF_TA:
1138  case ANALOG_SIG_SF_FEATB:
1139  c = strchr(dest, '/');
1140  if (c) {
1141  c++;
1142  } else {
1143  c = "";
1144  }
1145  if (strlen(c) < p->stripmsd) {
1146  ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1147  return -1;
1148  }
1149  res = analog_start(p);
1150  if (res < 0) {
1151  if (errno != EINPROGRESS) {
1152  return -1;
1153  }
1154  }
1155  ast_debug(1, "Dialing '%s'\n", c);
1157 
1158  c += p->stripmsd;
1159 
1160  switch (mysig) {
1161  case ANALOG_SIG_FEATD:
1163  if (l) {
1164  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T*%s*%s*", l, c);
1165  } else {
1166  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T**%s*", c);
1167  }
1168  break;
1169  case ANALOG_SIG_FEATDMF:
1171  if (l) {
1172  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*00%s#*%s#", l, c);
1173  } else {
1174  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*02#*%s#", c);
1175  }
1176  break;
1177  case ANALOG_SIG_FEATDMF_TA:
1178  {
1179  const char *cic = "", *ozz = "";
1180 
1181  /* If you have to go through a Tandem Access point you need to use this */
1182 #ifndef STANDALONE
1183  ozz = pbx_builtin_getvar_helper(p->owner, "FEATDMF_OZZ");
1184  if (!ozz) {
1185  ozz = analog_defaultozz;
1186  }
1187  cic = pbx_builtin_getvar_helper(p->owner, "FEATDMF_CIC");
1188  if (!cic) {
1189  cic = analog_defaultcic;
1190  }
1191 #endif
1192  if (!ozz || !cic) {
1193  ast_log(LOG_WARNING, "Unable to dial channel of type feature group D MF tandem access without CIC or OZZ set\n");
1194  return -1;
1195  }
1196  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s%s#", ozz, cic);
1197  snprintf(p->finaldial, sizeof(p->finaldial), "M*%s#", c);
1198  p->whichwink = 0;
1199  }
1200  break;
1201  case ANALOG_SIG_E911:
1202  ast_copy_string(p->dop.dialstr, "M*911#", sizeof(p->dop.dialstr));
1203  break;
1204  case ANALOG_SIG_FGC_CAMA:
1205  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%s", c);
1206  break;
1207  case ANALOG_SIG_FGC_CAMAMF:
1208  case ANALOG_SIG_FEATB:
1209  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s#", c);
1210  break;
1211  default:
1212  if (p->pulse) {
1213  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%sw", c);
1214  } else {
1215  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T%sw", c);
1216  }
1217  break;
1218  }
1219 
1220  if (p->echotraining && (strlen(p->dop.dialstr) > 4)) {
1221  memset(p->echorest, 'w', sizeof(p->echorest) - 1);
1222  strcpy(p->echorest + (p->echotraining / 400) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
1223  p->echorest[sizeof(p->echorest) - 1] = '\0';
1224  p->echobreak = 1;
1225  p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
1226  } else {
1227  p->echobreak = 0;
1228  }
1229  analog_set_waitingfordt(p, ast);
1230  if (!res) {
1231  if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
1232  analog_on_hook(p);
1233  return -1;
1234  }
1235  } else {
1236  ast_debug(1, "Deferring dialing...\n");
1237  }
1238  analog_set_dialing(p, 1);
1239  if (ast_strlen_zero(c)) {
1240  p->dialednone = 1;
1241  }
1243  break;
1244  default:
1245  ast_debug(1, "not yet implemented\n");
1246  return -1;
1247  }
1248  return 0;
1249 }
1250 
1251 int analog_hangup(struct analog_pvt *p, struct ast_channel *ast)
1252 {
1253  int res;
1254  int idx, x;
1255 
1256  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1257  if (!ast_channel_tech_pvt(ast)) {
1258  ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
1259  return 0;
1260  }
1261 
1262  idx = analog_get_index(ast, p, 1);
1263 
1264  x = 0;
1265  if (p->origcid_num) {
1266  ast_copy_string(p->cid_num, p->origcid_num, sizeof(p->cid_num));
1267  ast_free(p->origcid_num);
1268  p->origcid_num = NULL;
1269  }
1270  if (p->origcid_name) {
1271  ast_copy_string(p->cid_name, p->origcid_name, sizeof(p->cid_name));
1272  ast_free(p->origcid_name);
1273  p->origcid_name = NULL;
1274  }
1275 
1277 
1278  ast_debug(1, "Hangup: channel: %d index = %d, normal = %d, callwait = %d, thirdcall = %d\n",
1280  if (idx > -1) {
1281  /* Real channel, do some fixup */
1282  p->subs[idx].owner = NULL;
1283  p->polarity = POLARITY_IDLE;
1284  analog_set_linear_mode(p, idx, 0);
1285  switch (idx) {
1286  case ANALOG_SUB_REAL:
1288  ast_debug(1, "Normal call hung up with both three way call and a call waiting call in place?\n");
1290  /* We had flipped over to answer a callwait and now it's gone */
1291  ast_debug(1, "We were flipped over to the callwait, moving back and unowning.\n");
1292  /* Move to the call-wait, but un-own us until they flip back. */
1296  } else {
1297  /* The three way hung up, but we still have a call wait */
1298  ast_debug(1, "We were in the threeway and have a callwait still. Ditching the threeway.\n");
1301  if (p->subs[ANALOG_SUB_REAL].inthreeway) {
1302  /* This was part of a three way call. Immediately make way for
1303  another call */
1304  ast_debug(1, "Call was complete, setting owner to former third call\n");
1307  } else {
1308  /* This call hasn't been completed yet... Set owner to NULL */
1309  ast_debug(1, "Call was incomplete, setting owner to NULL\n");
1311  }
1312  }
1313  } else if (p->subs[ANALOG_SUB_CALLWAIT].allocd) {
1314  /* Need to hold the lock for real-call, private, and call-waiting call */
1316  if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
1317  /* The call waiting call dissappeared. */
1319  break;
1320  }
1321 
1322  /* Move to the call-wait and switch back to them. */
1326  if (ast_channel_state(p->owner) != AST_STATE_UP) {
1328  }
1330  /* Unlock the call-waiting call that we swapped to real-call. */
1332  } else if (p->subs[ANALOG_SUB_THREEWAY].allocd) {
1335  if (p->subs[ANALOG_SUB_REAL].inthreeway) {
1336  /* This was part of a three way call. Immediately make way for
1337  another call */
1338  ast_debug(1, "Call was complete, setting owner to former third call\n");
1341  } else {
1342  /* This call hasn't been completed yet... Set owner to NULL */
1343  ast_debug(1, "Call was incomplete, setting owner to NULL\n");
1345  }
1346  }
1347  break;
1348  case ANALOG_SUB_CALLWAIT:
1349  /* Ditch the holding callwait call, and immediately make it available */
1351  /* Need to hold the lock for call-waiting call, private, and 3-way call */
1353 
1354  /* This is actually part of a three way, placed on hold. Place the third part
1355  on music on hold now */
1356  if (p->subs[ANALOG_SUB_THREEWAY].owner) {
1358  }
1360  /* Make it the call wait now */
1363  if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1364  /* Unlock the 3-way call that we swapped to call-waiting call. */
1366  }
1367  } else {
1369  }
1370  break;
1371  case ANALOG_SUB_THREEWAY:
1372  /* Need to hold the lock for 3-way call, private, and call-waiting call */
1375  /* The other party of the three way call is currently in a call-wait state.
1376  Start music on hold for them, and take the main guy out of the third call */
1378  if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1380  }
1381  }
1382  if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1384  }
1386  /* If this was part of a three way call index, let us make
1387  another three way call */
1389  break;
1390  default:
1391  /*
1392  * Should never happen.
1393  * This wasn't any sort of call, so how are we an index?
1394  */
1395  ast_log(LOG_ERROR, "Index found but not any type of call?\n");
1396  break;
1397  }
1398  }
1399 
1402  analog_set_ringtimeout(p, 0);
1404  analog_set_pulsedial(p, 0);
1405  analog_set_outgoing(p, 0);
1406  p->onhooktime = time(NULL);
1407  p->cidrings = 1;
1408 
1409  /* Perform low level hangup if no owner left */
1410  res = analog_on_hook(p);
1411  if (res < 0) {
1412  ast_log(LOG_WARNING, "Unable to hangup line %s\n", ast_channel_name(ast));
1413  }
1414  switch (p->sig) {
1415  case ANALOG_SIG_FXOGS:
1416  case ANALOG_SIG_FXOLS:
1417  case ANALOG_SIG_FXOKS:
1418  /* If they're off hook, try playing congestion */
1419  if (analog_is_off_hook(p)) {
1422  } else {
1424  }
1425  break;
1426  case ANALOG_SIG_FXSGS:
1427  case ANALOG_SIG_FXSLS:
1428  case ANALOG_SIG_FXSKS:
1429  /* Make sure we're not made available for at least two seconds assuming
1430  we were actually used for an inbound or outbound call. */
1431  if (ast_channel_state(ast) != AST_STATE_RESERVED) {
1432  time(&p->guardtime);
1433  p->guardtime += 2;
1434  }
1435  break;
1436  default:
1438  break;
1439  }
1440 
1442 
1443  x = 0;
1444  ast_channel_setoption(ast,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0);
1445  ast_channel_setoption(ast,AST_OPTION_TDD,&x,sizeof(char),0);
1446  p->callwaitcas = 0;
1449  analog_set_dialing(p, 0);
1450  analog_update_conf(p);
1452  }
1453 
1455 
1456  ast_verb(3, "Hanging up on '%s'\n", ast_channel_name(ast));
1457 
1458  return 0;
1459 }
1460 
1461 int analog_answer(struct analog_pvt *p, struct ast_channel *ast)
1462 {
1463  int res = 0;
1464  int idx;
1465  int oldstate = ast_channel_state(ast);
1466 
1467  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1468  ast_setstate(ast, AST_STATE_UP);
1469  idx = analog_get_index(ast, p, 1);
1470  if (idx < 0) {
1471  idx = ANALOG_SUB_REAL;
1472  }
1473  switch (p->sig) {
1474  case ANALOG_SIG_FXSLS:
1475  case ANALOG_SIG_FXSGS:
1476  case ANALOG_SIG_FXSKS:
1477  analog_set_ringtimeout(p, 0);
1478  /* Fall through */
1479  case ANALOG_SIG_EM:
1480  case ANALOG_SIG_EM_E1:
1481  case ANALOG_SIG_EMWINK:
1482  case ANALOG_SIG_FEATD:
1483  case ANALOG_SIG_FEATDMF:
1484  case ANALOG_SIG_FEATDMF_TA:
1485  case ANALOG_SIG_E911:
1486  case ANALOG_SIG_FGC_CAMA:
1487  case ANALOG_SIG_FGC_CAMAMF:
1488  case ANALOG_SIG_FEATB:
1489  case ANALOG_SIG_SF:
1490  case ANALOG_SIG_SFWINK:
1491  case ANALOG_SIG_SF_FEATD:
1492  case ANALOG_SIG_SF_FEATDMF:
1493  case ANALOG_SIG_SF_FEATB:
1494  case ANALOG_SIG_FXOLS:
1495  case ANALOG_SIG_FXOGS:
1496  case ANALOG_SIG_FXOKS:
1497  /* Pick up the line */
1498  ast_debug(1, "Took %s off hook\n", ast_channel_name(ast));
1499  if (p->hanguponpolarityswitch) {
1500  gettimeofday(&p->polaritydelaytv, NULL);
1501  }
1502  res = analog_off_hook(p);
1503  analog_play_tone(p, idx, -1);
1504  analog_set_dialing(p, 0);
1505  if ((idx == ANALOG_SUB_REAL) && p->subs[ANALOG_SUB_THREEWAY].inthreeway) {
1506  if (oldstate == AST_STATE_RINGING) {
1507  ast_debug(1, "Finally swapping real and threeway\n");
1511  }
1512  }
1513 
1514  switch (p->sig) {
1515  case ANALOG_SIG_FXSLS:
1516  case ANALOG_SIG_FXSKS:
1517  case ANALOG_SIG_FXSGS:
1520  break;
1521  case ANALOG_SIG_FXOLS:
1522  case ANALOG_SIG_FXOKS:
1523  case ANALOG_SIG_FXOGS:
1525  break;
1526  default:
1527  break;
1528  }
1529  break;
1530  default:
1531  ast_log(LOG_WARNING, "Don't know how to answer signalling %d (channel %d)\n", p->sig, p->channel);
1532  res = -1;
1533  break;
1534  }
1535  ast_setstate(ast, AST_STATE_UP);
1536  return res;
1537 }
1538 
1539 static int analog_handles_digit(struct ast_frame *f)
1540 {
1541  char subclass = toupper(f->subclass.integer);
1542 
1543  switch (subclass) {
1544  case '1':
1545  case '2':
1546  case '3':
1547  case '4':
1548  case '5':
1549  case '6':
1550  case '7':
1551  case '9':
1552  case 'A':
1553  case 'B':
1554  case 'C':
1555  case 'D':
1556  case 'E':
1557  case 'F':
1558  return 1;
1559  default:
1560  return 0;
1561  }
1562 }
1563 
1564 void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub idx, struct ast_frame **dest)
1565 {
1566  struct ast_frame *f = *dest;
1567 
1568  ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n",
1569  f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End",
1570  (unsigned)f->subclass.integer, f->subclass.integer, ast_channel_name(ast));
1571 
1572  if (analog_check_confirmanswer(p)) {
1573  if (f->frametype == AST_FRAME_DTMF_END) {
1574  ast_debug(1, "Confirm answer on %s!\n", ast_channel_name(ast));
1575  /* Upon receiving a DTMF digit, consider this an answer confirmation instead
1576  of a DTMF digit */
1577  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
1579  /* Reset confirmanswer so DTMF's will behave properly for the duration of the call */
1581  } else {
1582  p->subs[idx].f.frametype = AST_FRAME_NULL;
1583  p->subs[idx].f.subclass.integer = 0;
1584  }
1585  *dest = &p->subs[idx].f;
1586  } else if (p->callwaitcas) {
1587  if (f->frametype == AST_FRAME_DTMF_END) {
1588  if ((f->subclass.integer == 'A') || (f->subclass.integer == 'D')) {
1589  ast_debug(1, "Got some DTMF, but it's for the CAS\n");
1590  p->caller.id.name.str = p->callwait_name;
1591  p->caller.id.number.str = p->callwait_num;
1592  analog_send_callerid(p, 1, &p->caller);
1593  }
1594  if (analog_handles_digit(f)) {
1595  p->callwaitcas = 0;
1596  }
1597  }
1598  p->subs[idx].f.frametype = AST_FRAME_NULL;
1599  p->subs[idx].f.subclass.integer = 0;
1600  *dest = &p->subs[idx].f;
1601  } else {
1602  analog_cb_handle_dtmf(p, ast, idx, dest);
1603  }
1604 }
1605 
1606 static int analog_my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms)
1607 {
1608  char c;
1609 
1610  *str = 0; /* start with empty output buffer */
1611  for (;;) {
1612  /* Wait for the first digit (up to specified ms). */
1613  c = ast_waitfordigit(chan, ms);
1614  /* if timeout, hangup or error, return as such */
1615  if (c < 1) {
1616  return c;
1617  }
1618  *str++ = c;
1619  *str = 0;
1620  if (strchr(term, c)) {
1621  return 1;
1622  }
1623  }
1624 }
1625 
1626 static int analog_handle_notify_message(struct ast_channel *chan, struct analog_pvt *p, int cid_flags, int neon_mwievent)
1627 {
1629  analog_callbacks.handle_notify_message(chan, p->chan_pvt, cid_flags, neon_mwievent);
1630  return 0;
1631  }
1632  return -1;
1633 }
1634 
1635 static void analog_increase_ss_count(void)
1636 {
1639  }
1640 }
1641 
1642 static void analog_decrease_ss_count(void)
1643 {
1646  }
1647 }
1648 
1649 static int analog_distinctive_ring(struct ast_channel *chan, struct analog_pvt *p, int idx, int *ringdata)
1650 {
1651  if (!p->usedistinctiveringdetection) {
1652  return 0;
1653  }
1655  return analog_callbacks.distinctive_ring(chan, p->chan_pvt, idx, ringdata);
1656  }
1657  return -1;
1658 
1659 }
1660 
1662 {
1665  }
1666 }
1667 
1668 static void *analog_get_bridged_channel(struct ast_channel *chan)
1669 {
1672  }
1673  return NULL;
1674 }
1675 
1676 static int analog_get_sub_fd(struct analog_pvt *p, enum analog_sub sub)
1677 {
1679  return analog_callbacks.get_sub_fd(p->chan_pvt, sub);
1680  }
1681  return -1;
1682 }
1683 
1684 #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))
1685 
1686 static int analog_canmatch_featurecode(const char *pickupexten, const char *exten)
1687 {
1688  int extlen = strlen(exten);
1689  if (!extlen) {
1690  return 1;
1691  }
1692  if (extlen < strlen(pickupexten) && !strncmp(pickupexten, exten, extlen)) {
1693  return 1;
1694  }
1695  /* hardcoded features are *60, *67, *69, *70, *72, *73, *78, *79, *82, *0 */
1696  if (exten[0] == '*' && extlen < 3) {
1697  if (extlen == 1) {
1698  return 1;
1699  }
1700  /* "*0" should be processed before it gets here */
1701  switch (exten[1]) {
1702  case '6':
1703  case '7':
1704  case '8':
1705  return 1;
1706  }
1707  }
1708  return 0;
1709 }
1710 
1711 static void *__analog_ss_thread(void *data)
1712 {
1713  struct analog_pvt *p = data;
1714  struct ast_channel *chan = p->ss_astchan;
1715  char exten[AST_MAX_EXTENSION] = "";
1716  char exten2[AST_MAX_EXTENSION] = "";
1717  char dtmfcid[300];
1718  char dtmfbuf[300];
1719  char namebuf[ANALOG_MAX_CID];
1720  char numbuf[ANALOG_MAX_CID];
1721  char *name = NULL, *number = NULL;
1722  int flags = 0;
1723  struct ast_smdi_md_message *smdi_msg = NULL;
1724  int timeout;
1725  int getforward = 0;
1726  char *s1, *s2;
1727  int len = 0;
1728  int res;
1729  int idx;
1730  ast_callid callid;
1731  RAII_VAR(struct ast_features_pickup_config *, pickup_cfg, NULL, ao2_cleanup);
1732  const char *pickupexten;
1733 
1735 
1736  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1737 
1738  if (!chan) {
1739  /* What happened to the channel? */
1740  goto quit;
1741  }
1742 
1743  if ((callid = ast_channel_callid(chan))) {
1745  }
1746 
1747  /* in the bizarre case where the channel has become a zombie before we
1748  even get started here, abort safely
1749  */
1750  if (!ast_channel_tech_pvt(chan)) {
1751  ast_log(LOG_WARNING, "Channel became a zombie before simple switch could be started (%s)\n", ast_channel_name(chan));
1752  ast_hangup(chan);
1753  goto quit;
1754  }
1755 
1756  ast_verb(3, "Starting simple switch on '%s'\n", ast_channel_name(chan));
1757  idx = analog_get_index(chan, p, 0);
1758  if (idx < 0) {
1759  ast_hangup(chan);
1760  goto quit;
1761  }
1762 
1763  ast_channel_lock(chan);
1764  pickup_cfg = ast_get_chan_features_pickup_config(chan);
1765  if (!pickup_cfg) {
1766  ast_log(LOG_ERROR, "Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n");
1767  pickupexten = "";
1768  } else {
1769  pickupexten = ast_strdupa(pickup_cfg->pickupexten);
1770  }
1771  ast_channel_unlock(chan);
1772 
1774  switch (p->sig) {
1775  case ANALOG_SIG_FEATD:
1776  case ANALOG_SIG_FEATDMF:
1777  case ANALOG_SIG_FEATDMF_TA:
1778  case ANALOG_SIG_E911:
1779  case ANALOG_SIG_FGC_CAMAMF:
1780  case ANALOG_SIG_FEATB:
1781  case ANALOG_SIG_EMWINK:
1782  case ANALOG_SIG_SF_FEATD:
1783  case ANALOG_SIG_SF_FEATDMF:
1784  case ANALOG_SIG_SF_FEATB:
1785  case ANALOG_SIG_SFWINK:
1786  if (analog_wink(p, idx))
1787  goto quit;
1788  /* Fall through */
1789  case ANALOG_SIG_EM:
1790  case ANALOG_SIG_EM_E1:
1791  case ANALOG_SIG_SF:
1792  case ANALOG_SIG_FGC_CAMA:
1793  res = analog_play_tone(p, idx, -1);
1794 
1796 
1797  /* set digit mode appropriately */
1798  if (ANALOG_NEED_MFDETECT(p)) {
1800  } else {
1802  }
1803 
1804  memset(dtmfbuf, 0, sizeof(dtmfbuf));
1805  /* Wait for the first digit only if immediate=no */
1806  if (!p->immediate) {
1807  /* Wait for the first digit (up to 5 seconds). */
1808  res = ast_waitfordigit(chan, 5000);
1809  } else {
1810  res = 0;
1811  }
1812  if (res > 0) {
1813  /* save first char */
1814  dtmfbuf[0] = res;
1815  switch (p->sig) {
1816  case ANALOG_SIG_FEATD:
1817  case ANALOG_SIG_SF_FEATD:
1818  res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
1819  if (res > 0) {
1820  res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
1821  }
1822  if (res < 1) {
1824  }
1825  break;
1826  case ANALOG_SIG_FEATDMF_TA:
1827  res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
1828  if (res < 1) {
1830  }
1831  if (analog_wink(p, idx)) {
1832  goto quit;
1833  }
1834  dtmfbuf[0] = 0;
1835  /* Wait for the first digit (up to 5 seconds). */
1836  res = ast_waitfordigit(chan, 5000);
1837  if (res <= 0) {
1838  break;
1839  }
1840  dtmfbuf[0] = res;
1841  /* fall through intentionally */
1842  case ANALOG_SIG_FEATDMF:
1843  case ANALOG_SIG_E911:
1844  case ANALOG_SIG_FGC_CAMAMF:
1845  case ANALOG_SIG_SF_FEATDMF:
1846  res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
1847  /* if international caca, do it again to get real ANO */
1848  if ((p->sig == ANALOG_SIG_FEATDMF) && (dtmfbuf[1] != '0')
1849  && (strlen(dtmfbuf) != 14)) {
1850  if (analog_wink(p, idx)) {
1851  goto quit;
1852  }
1853  dtmfbuf[0] = 0;
1854  /* Wait for the first digit (up to 5 seconds). */
1855  res = ast_waitfordigit(chan, 5000);
1856  if (res <= 0) {
1857  break;
1858  }
1859  dtmfbuf[0] = res;
1860  res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
1861  }
1862  if (res > 0) {
1863  /* if E911, take off hook */
1864  if (p->sig == ANALOG_SIG_E911) {
1865  analog_off_hook(p);
1866  }
1867  res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "#", 3000);
1868  }
1869  if (res < 1) {
1871  }
1872  break;
1873  case ANALOG_SIG_FEATB:
1874  case ANALOG_SIG_SF_FEATB:
1875  res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
1876  if (res < 1) {
1878  }
1879  break;
1880  case ANALOG_SIG_EMWINK:
1881  /* if we received a '*', we are actually receiving Feature Group D
1882  dial syntax, so use that mode; otherwise, fall through to normal
1883  mode
1884  */
1885  if (res == '*') {
1886  res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
1887  if (res > 0) {
1888  res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
1889  }
1890  if (res < 1) {
1892  }
1893  break;
1894  }
1895  default:
1896  /* If we got the first digit, get the rest */
1897  len = 1;
1898  dtmfbuf[len] = '\0';
1899  while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
1900  if (ast_exists_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
1901  timeout = analog_get_matchdigit_timeout(p);
1902  } else {
1903  timeout = analog_get_interdigit_timeout(p);
1904  }
1905  res = ast_waitfordigit(chan, timeout);
1906  if (res < 0) {
1907  ast_debug(1, "waitfordigit returned < 0...\n");
1908  ast_hangup(chan);
1909  goto quit;
1910  } else if (res) {
1911  dtmfbuf[len++] = res;
1912  dtmfbuf[len] = '\0';
1913  } else {
1914  break;
1915  }
1916  }
1917  break;
1918  }
1919  }
1920  if (res == -1) {
1921  ast_log(LOG_WARNING, "getdtmf on channel %d: %s\n", p->channel, strerror(errno));
1922  ast_hangup(chan);
1923  goto quit;
1924  } else if (res < 0) {
1925  ast_debug(1, "Got hung up before digits finished\n");
1926  ast_hangup(chan);
1927  goto quit;
1928  }
1929 
1930  if (p->sig == ANALOG_SIG_FGC_CAMA) {
1931  char anibuf[100];
1932 
1933  if (ast_safe_sleep(chan,1000) == -1) {
1934  ast_hangup(chan);
1935  goto quit;
1936  }
1937  analog_off_hook(p);
1939  res = analog_my_getsigstr(chan, anibuf, "#", 10000);
1940  if ((res > 0) && (strlen(anibuf) > 2)) {
1941  if (anibuf[strlen(anibuf) - 1] == '#') {
1942  anibuf[strlen(anibuf) - 1] = 0;
1943  }
1944  ast_set_callerid(chan, anibuf + 2, NULL, anibuf + 2);
1945  }
1947  }
1948 
1949  ast_copy_string(exten, dtmfbuf, sizeof(exten));
1950  if (ast_strlen_zero(exten)) {
1951  ast_copy_string(exten, "s", sizeof(exten));
1952  }
1953  if (p->sig == ANALOG_SIG_FEATD || p->sig == ANALOG_SIG_EMWINK) {
1954  /* Look for Feature Group D on all E&M Wink and Feature Group D trunks */
1955  if (exten[0] == '*') {
1956  char *stringp=NULL;
1957  ast_copy_string(exten2, exten, sizeof(exten2));
1958  /* Parse out extension and callerid */
1959  stringp=exten2 +1;
1960  s1 = strsep(&stringp, "*");
1961  s2 = strsep(&stringp, "*");
1962  if (s2) {
1963  if (!ast_strlen_zero(p->cid_num)) {
1964  ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
1965  } else {
1966  ast_set_callerid(chan, s1, NULL, s1);
1967  }
1968  ast_copy_string(exten, s2, sizeof(exten));
1969  } else {
1970  ast_copy_string(exten, s1, sizeof(exten));
1971  }
1972  } else if (p->sig == ANALOG_SIG_FEATD) {
1973  ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
1974  }
1975  }
1976  if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
1977  if (exten[0] == '*') {
1978  char *stringp=NULL;
1979  struct ast_party_caller *caller;
1980 
1981  ast_copy_string(exten2, exten, sizeof(exten2));
1982  /* Parse out extension and callerid */
1983  stringp=exten2 +1;
1984  s1 = strsep(&stringp, "#");
1985  s2 = strsep(&stringp, "#");
1986  if (s2) {
1987  if (!ast_strlen_zero(p->cid_num)) {
1988  ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
1989  } else {
1990  if (*(s1 + 2)) {
1991  ast_set_callerid(chan, s1 + 2, NULL, s1 + 2);
1992  }
1993  }
1994  ast_copy_string(exten, s2 + 1, sizeof(exten));
1995  } else {
1996  ast_copy_string(exten, s1 + 2, sizeof(exten));
1997  }
1998 
1999  /* The first two digits are ani2 information. */
2000  caller = ast_channel_caller(chan);
2001  s1[2] = '\0';
2002  caller->ani2 = atoi(s1);
2003  } else {
2004  ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
2005  }
2006  }
2007  if ((p->sig == ANALOG_SIG_E911) || (p->sig == ANALOG_SIG_FGC_CAMAMF)) {
2008  if (exten[0] == '*') {
2009  char *stringp=NULL;
2010  ast_copy_string(exten2, exten, sizeof(exten2));
2011  /* Parse out extension and callerid */
2012  stringp=exten2 +1;
2013  s1 = strsep(&stringp, "#");
2014  s2 = strsep(&stringp, "#");
2015  if (s2 && (*(s2 + 1) == '0')) {
2016  if (*(s2 + 2)) {
2017  ast_set_callerid(chan, s2 + 2, NULL, s2 + 2);
2018  }
2019  }
2020  if (s1) {
2021  ast_copy_string(exten, s1, sizeof(exten));
2022  } else {
2023  ast_copy_string(exten, "911", sizeof(exten));
2024  }
2025  } else {
2026  ast_log(LOG_WARNING, "Got a non-E911/FGC CAMA input on channel %d. Assuming E&M Wink instead\n", p->channel);
2027  }
2028  }
2029  if (p->sig == ANALOG_SIG_FEATB) {
2030  if (exten[0] == '*') {
2031  char *stringp=NULL;
2032  ast_copy_string(exten2, exten, sizeof(exten2));
2033  /* Parse out extension and callerid */
2034  stringp=exten2 +1;
2035  s1 = strsep(&stringp, "#");
2036  ast_copy_string(exten, exten2 + 1, sizeof(exten));
2037  } else {
2038  ast_log(LOG_WARNING, "Got a non-Feature Group B input on channel %d. Assuming E&M Wink instead\n", p->channel);
2039  }
2040  }
2041  if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
2042  analog_wink(p, idx);
2043  /*
2044  * Some switches require a minimum guard time between the last
2045  * FGD wink and something that answers immediately. This
2046  * ensures it.
2047  */
2048  if (ast_safe_sleep(chan, 100)) {
2049  ast_hangup(chan);
2050  goto quit;
2051  }
2052  }
2054 
2056 
2057  if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1,
2058  ast_channel_caller(chan)->id.number.valid ? ast_channel_caller(chan)->id.number.str : NULL)) {
2059  ast_channel_exten_set(chan, exten);
2061  res = ast_pbx_run(chan);
2062  if (res) {
2063  ast_log(LOG_WARNING, "PBX exited non-zero\n");
2065  }
2066  goto quit;
2067  } else {
2068  ast_verb(3, "Unknown extension '%s' in context '%s' requested\n", exten, ast_channel_context(chan));
2069  sleep(2);
2070  res = analog_play_tone(p, idx, ANALOG_TONE_INFO);
2071  if (res < 0) {
2072  ast_log(LOG_WARNING, "Unable to start special tone on %d\n", p->channel);
2073  } else {
2074  sleep(1);
2075  }
2076  res = ast_streamfile(chan, "ss-noservice", ast_channel_language(chan));
2077  if (res >= 0) {
2078  ast_waitstream(chan, "");
2079  }
2081  ast_hangup(chan);
2082  goto quit;
2083  }
2084  break;
2085  case ANALOG_SIG_FXOLS:
2086  case ANALOG_SIG_FXOGS:
2087  case ANALOG_SIG_FXOKS:
2088  /* Read the first digit */
2089  timeout = analog_get_firstdigit_timeout(p);
2090  /* If starting a threeway call, never timeout on the first digit so someone
2091  can use flash-hook as a "hold" feature */
2092  if (p->subs[ANALOG_SUB_THREEWAY].owner) {
2093  timeout = 999999;
2094  }
2095  while (len < AST_MAX_EXTENSION-1) {
2096  int is_exten_parking = 0;
2097 
2098  /* Read digit unless it's supposed to be immediate, in which case the
2099  only answer is 's' */
2100  if (p->immediate) {
2101  res = 's';
2102  } else {
2103  res = ast_waitfordigit(chan, timeout);
2104  }
2105  timeout = 0;
2106  if (res < 0) {
2107  ast_debug(1, "waitfordigit returned < 0...\n");
2108  res = analog_play_tone(p, idx, -1);
2109  ast_hangup(chan);
2110  goto quit;
2111  } else if (res) {
2112  ast_debug(1,"waitfordigit returned '%c' (%d), timeout = %d\n", res, res, timeout);
2113  exten[len++]=res;
2114  exten[len] = '\0';
2115  }
2116  if (!ast_ignore_pattern(ast_channel_context(chan), exten)) {
2117  analog_play_tone(p, idx, -1);
2118  } else {
2120  }
2122  is_exten_parking = ast_parking_is_exten_park(ast_channel_context(chan), exten);
2123  }
2124  if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num) && !is_exten_parking) {
2125  if (!res || !ast_matchmore_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) {
2126  if (getforward) {
2127  /* Record this as the forwarding extension */
2128  ast_copy_string(p->call_forward, exten, sizeof(p->call_forward));
2129  ast_verb(3, "Setting call forward to '%s' on channel %d\n", p->call_forward, p->channel);
2131  if (res) {
2132  break;
2133  }
2134  usleep(500000);
2135  res = analog_play_tone(p, idx, -1);
2136  sleep(1);
2137  memset(exten, 0, sizeof(exten));
2138  res = analog_play_tone(p, idx, ANALOG_TONE_DIALTONE);
2139  len = 0;
2140  getforward = 0;
2141  } else {
2142  res = analog_play_tone(p, idx, -1);
2143  ast_channel_lock(chan);
2144  ast_channel_exten_set(chan, exten);
2145  if (!ast_strlen_zero(p->cid_num)) {
2146  if (!p->hidecallerid) {
2147  ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
2148  } else {
2149  ast_set_callerid(chan, NULL, NULL, p->cid_num);
2150  }
2151  }
2152  if (!ast_strlen_zero(p->cid_name)) {
2153  if (!p->hidecallerid) {
2154  ast_set_callerid(chan, NULL, p->cid_name, NULL);
2155  }
2156  }
2158  ast_channel_unlock(chan);
2160  res = ast_pbx_run(chan);
2161  if (res) {
2162  ast_log(LOG_WARNING, "PBX exited non-zero\n");
2164  }
2165  goto quit;
2166  }
2167  } else {
2168  /* It's a match, but they just typed a digit, and there is an ambiguous match,
2169  so just set the timeout to analog_matchdigittimeout and wait some more */
2170  timeout = analog_get_matchdigit_timeout(p);
2171  }
2172  } else if (res == 0) {
2173  ast_debug(1, "not enough digits (and no ambiguous match)...\n");
2175  analog_wait_event(p);
2176  ast_hangup(chan);
2177  goto quit;
2178  } else if (p->callwaiting && !strcmp(exten, "*70")) {
2179  ast_verb(3, "Disabling call waiting on %s\n", ast_channel_name(chan));
2180  /* Disable call waiting if enabled */
2181  analog_set_callwaiting(p, 0);
2183  if (res) {
2184  ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2185  ast_channel_name(chan), strerror(errno));
2186  }
2187  len = 0;
2188  memset(exten, 0, sizeof(exten));
2189  timeout = analog_get_firstdigit_timeout(p);
2190 
2191  } else if (!strcmp(exten, pickupexten)) {
2192  /* Scan all channels and see if there are any
2193  * ringing channels that have call groups
2194  * that equal this channels pickup group
2195  */
2196  if (idx == ANALOG_SUB_REAL) {
2197  /* Switch us from Third call to Call Wait */
2198  if (p->subs[ANALOG_SUB_THREEWAY].owner) {
2199  /* If you make a threeway call and the *8# a call, it should actually
2200  look like a callwait */
2204  }
2206  if (ast_pickup_call(chan)) {
2207  ast_debug(1, "No call pickup possible...\n");
2209  analog_wait_event(p);
2210  }
2211  ast_hangup(chan);
2212  goto quit;
2213  } else {
2214  ast_log(LOG_WARNING, "Huh? Got *8# on call not on real\n");
2215  ast_hangup(chan);
2216  goto quit;
2217  }
2218 
2219  } else if (!p->hidecallerid && !strcmp(exten, "*67")) {
2220  ast_verb(3, "Disabling Caller*ID on %s\n", ast_channel_name(chan));
2221  /* Disable Caller*ID if enabled */
2222  p->hidecallerid = 1;
2223  ast_party_number_free(&ast_channel_caller(chan)->id.number);
2224  ast_party_number_init(&ast_channel_caller(chan)->id.number);
2225  ast_party_name_free(&ast_channel_caller(chan)->id.name);
2226  ast_party_name_init(&ast_channel_caller(chan)->id.name);
2228  if (res) {
2229  ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2230  ast_channel_name(chan), strerror(errno));
2231  }
2232  len = 0;
2233  memset(exten, 0, sizeof(exten));
2234  timeout = analog_get_firstdigit_timeout(p);
2235  } else if (p->callreturn && !strcmp(exten, "*69")) {
2236  res = 0;
2237  if (!ast_strlen_zero(p->lastcid_num)) {
2238  res = ast_say_digit_str(chan, p->lastcid_num, "", ast_channel_language(chan));
2239  }
2240  if (!res) {
2242  }
2243  break;
2244  } else if (!strcmp(exten, "*78")) {
2245  /* Do not disturb enabled */
2246  analog_dnd(p, 1);
2248  getforward = 0;
2249  memset(exten, 0, sizeof(exten));
2250  len = 0;
2251  } else if (!strcmp(exten, "*79")) {
2252  /* Do not disturb disabled */
2253  analog_dnd(p, 0);
2255  getforward = 0;
2256  memset(exten, 0, sizeof(exten));
2257  len = 0;
2258  } else if (p->cancallforward && !strcmp(exten, "*72")) {
2260  getforward = 1;
2261  memset(exten, 0, sizeof(exten));
2262  len = 0;
2263  } else if (p->cancallforward && !strcmp(exten, "*73")) {
2264  ast_verb(3, "Cancelling call forwarding on channel %d\n", p->channel);
2266  memset(p->call_forward, 0, sizeof(p->call_forward));
2267  getforward = 0;
2268  memset(exten, 0, sizeof(exten));
2269  len = 0;
2270  } else if ((p->transfer || p->canpark) && is_exten_parking
2271  && p->subs[ANALOG_SUB_THREEWAY].owner) {
2272  struct ast_bridge_channel *bridge_channel;
2273 
2274  /*
2275  * This is a three way call, the main call being a real channel,
2276  * and we're parking the first call.
2277  */
2281  if (bridge_channel) {
2282  if (!ast_parking_blind_transfer_park(bridge_channel, ast_channel_context(chan), exten, NULL, NULL)) {
2283  /*
2284  * Swap things around between the three-way and real call so we
2285  * can hear where the channel got parked.
2286  */
2291 
2292  ast_verb(3, "%s: Parked call\n", ast_channel_name(chan));
2293  ast_hangup(chan);
2294  ao2_ref(bridge_channel, -1);
2295  goto quit;
2296  }
2297  ao2_ref(bridge_channel, -1);
2298  }
2299  break;
2300  } else if (!ast_strlen_zero(p->lastcid_num) && !strcmp(exten, "*60")) {
2301  ast_verb(3, "Blacklisting number %s\n", p->lastcid_num);
2302  res = ast_db_put("blacklist", p->lastcid_num, "1");
2303  if (!res) {
2305  memset(exten, 0, sizeof(exten));
2306  len = 0;
2307  }
2308  } else if (p->hidecallerid && !strcmp(exten, "*82")) {
2309  ast_verb(3, "Enabling Caller*ID on %s\n", ast_channel_name(chan));
2310  /* Enable Caller*ID if enabled */
2311  p->hidecallerid = 0;
2312  ast_set_callerid(chan, p->cid_num, p->cid_name, NULL);
2314  if (res) {
2315  ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2316  ast_channel_name(chan), strerror(errno));
2317  }
2318  len = 0;
2319  memset(exten, 0, sizeof(exten));
2320  timeout = analog_get_firstdigit_timeout(p);
2321  } else if (!strcmp(exten, "*0")) {
2322  struct ast_channel *nbridge = p->subs[ANALOG_SUB_THREEWAY].owner;
2323  struct analog_pvt *pbridge = NULL;
2324  /* set up the private struct of the bridged one, if any */
2325  if (nbridge) {
2326  pbridge = analog_get_bridged_channel(nbridge);
2327  }
2328  if (pbridge && ISTRUNK(pbridge)) {
2329  /* Clear out the dial buffer */
2330  p->dop.dialstr[0] = '\0';
2331  /* flash hookswitch */
2332  if ((analog_flash(pbridge) == -1) && (errno != EINPROGRESS)) {
2334  "Unable to flash-hook bridged trunk from channel %s: %s\n",
2335  ast_channel_name(nbridge), strerror(errno));
2336  }
2341  ast_hangup(chan);
2342  goto quit;
2343  } else {
2345  analog_wait_event(p);
2346  analog_play_tone(p, idx, -1);
2350  ast_hangup(chan);
2351  goto quit;
2352  }
2353  } else if (!ast_canmatch_extension(chan, ast_channel_context(chan), exten, 1,
2354  ast_channel_caller(chan)->id.number.valid ? ast_channel_caller(chan)->id.number.str : NULL)
2355  && !analog_canmatch_featurecode(pickupexten, exten)) {
2356  ast_debug(1, "Can't match %s from '%s' in context %s\n", exten,
2357  ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str
2358  ? ast_channel_caller(chan)->id.number.str : "<Unknown Caller>",
2359  ast_channel_context(chan));
2360  break;
2361  }
2362  if (!timeout) {
2363  timeout = analog_get_interdigit_timeout(p);
2364  }
2365  if (len && !ast_ignore_pattern(ast_channel_context(chan), exten)) {
2366  analog_play_tone(p, idx, -1);
2367  }
2368  }
2369  break;
2370  case ANALOG_SIG_FXSLS:
2371  case ANALOG_SIG_FXSGS:
2372  case ANALOG_SIG_FXSKS:
2373  /* check for SMDI messages */
2374  if (p->use_smdi && p->smdi_iface) {
2376  if (smdi_msg != NULL) {
2377  ast_channel_exten_set(chan, smdi_msg->fwd_st);
2378 
2379  if (smdi_msg->type == 'B')
2380  pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "b");
2381  else if (smdi_msg->type == 'N')
2382  pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "u");
2383 
2384  ast_debug(1, "Received SMDI message on %s\n", ast_channel_name(chan));
2385  } else {
2386  ast_log(LOG_WARNING, "SMDI enabled but no SMDI message present\n");
2387  }
2388  }
2389 
2390  if (p->use_callerid && (p->cid_signalling == CID_SIG_SMDI && smdi_msg)) {
2391  number = smdi_msg->calling_st;
2392 
2393  /* If we want caller id, we're in a prering state due to a polarity reversal
2394  * and we're set to use a polarity reversal to trigger the start of caller id,
2395  * grab the caller id and wait for ringing to start... */
2396  } else if (p->use_callerid && (ast_channel_state(chan) == AST_STATE_PRERING
2400  /* If set to use DTMF CID signalling, listen for DTMF */
2401  if (p->cid_signalling == CID_SIG_DTMF) {
2402  int k = 0;
2403  int oldlinearity;
2404  int timeout_ms;
2405  int ms;
2406  struct timeval start = ast_tvnow();
2407  ast_debug(1, "Receiving DTMF cid on channel %s\n", ast_channel_name(chan));
2408 
2409  oldlinearity = analog_set_linear_mode(p, idx, 0);
2410 
2411  /*
2412  * We are the only party interested in the Rx stream since
2413  * we have not answered yet. We don't need or even want DTMF
2414  * emulation. The DTMF digits can come so fast that emulation
2415  * can drop some of them.
2416  */
2417  ast_channel_lock(chan);
2419  ast_channel_unlock(chan);
2420  timeout_ms = 4000;/* This is a typical OFF time between rings. */
2421  for (;;) {
2422  struct ast_frame *f;
2423 
2424  ms = ast_remaining_ms(start, timeout_ms);
2425  res = ast_waitfor(chan, ms);
2426  if (res <= 0) {
2427  /*
2428  * We do not need to restore the analog_set_linear_mode()
2429  * or AST_FLAG_END_DTMF_ONLY flag settings since we
2430  * are hanging up the channel.
2431  */
2433  "DTMFCID timed out waiting for ring. Exiting simple switch\n");
2434  ast_hangup(chan);
2435  goto quit;
2436  }
2437  f = ast_read(chan);
2438  if (!f) {
2439  break;
2440  }
2441  if (f->frametype == AST_FRAME_DTMF) {
2442  if (k < ARRAY_LEN(dtmfbuf) - 1) {
2443  dtmfbuf[k++] = f->subclass.integer;
2444  }
2445  ast_debug(1, "CID got digit '%c'\n", f->subclass.integer);
2446  start = ast_tvnow();
2447  }
2448  ast_frfree(f);
2449  if (ast_channel_state(chan) == AST_STATE_RING ||
2451  break; /* Got ring */
2452  }
2453  }
2454  ast_channel_lock(chan);
2456  ast_channel_unlock(chan);
2457  dtmfbuf[k] = '\0';
2458 
2459  analog_set_linear_mode(p, idx, oldlinearity);
2460 
2461  /* Got cid and ring. */
2462  ast_debug(1, "CID got string '%s'\n", dtmfbuf);
2463  callerid_get_dtmf(dtmfbuf, dtmfcid, &flags);
2464  ast_debug(1, "CID is '%s', flags %d\n", dtmfcid, flags);
2465  /* If first byte is NULL, we have no cid */
2466  if (!ast_strlen_zero(dtmfcid)) {
2467  number = dtmfcid;
2468  } else {
2469  number = NULL;
2470  }
2471 
2472  /* If set to use V23 Signalling, launch our FSK gubbins and listen for it */
2473  } else if ((p->cid_signalling == CID_SIG_V23) || (p->cid_signalling == CID_SIG_V23_JP)) {
2474  namebuf[0] = 0;
2475  numbuf[0] = 0;
2476 
2478  int timeout = 10000; /* Ten seconds */
2479  struct timeval start = ast_tvnow();
2480  enum analog_event ev;
2481  int off_ms;
2482  int ms;
2483  struct timeval off_start;
2484 
2485  if (!p->usedistinctiveringdetection) {
2486  /* Disable distinctive ring timeout count */
2487  analog_set_ringtimeout(p, 0);
2488  }
2489  while ((ms = ast_remaining_ms(start, timeout))) {
2490  res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2491  if (res < 0) {
2493  "CallerID returned with error on channel '%s'\n",
2494  ast_channel_name(chan));
2495  break;
2496  }
2497  if (res == 0) {
2498  break;
2499  }
2500  if (res != 1) {
2501  continue;
2502  }
2503  if (ev == ANALOG_EVENT_NOALARM) {
2504  analog_set_alarm(p, 0);
2505  }
2506  if (p->cid_signalling == CID_SIG_V23_JP) {
2507  if (ev == ANALOG_EVENT_RINGBEGIN) {
2508  analog_off_hook(p);
2509  usleep(1);
2510  }
2511  } else {
2512  break;
2513  }
2514  }
2515 
2516  name = namebuf;
2517  number = numbuf;
2518 
2519  if (p->cid_signalling == CID_SIG_V23_JP) {
2520  analog_on_hook(p);
2521  usleep(1);
2522  }
2523 
2524  /* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
2525  off_start = ast_tvnow();
2526  off_ms = 4000;/* This is a typical OFF time between rings. */
2527  while ((ms = ast_remaining_ms(off_start, off_ms))) {
2528  struct ast_frame *f;
2529 
2530  res = ast_waitfor(chan, ms);
2531  if (res <= 0) {
2533  "CID timed out waiting for ring. Exiting simple switch\n");
2535  ast_hangup(chan);
2536  goto quit;
2537  }
2538  if (!(f = ast_read(chan))) {
2539  ast_log(LOG_WARNING, "Hangup received waiting for ring. Exiting simple switch\n");
2541  ast_hangup(chan);
2542  goto quit;
2543  }
2544  ast_frfree(f);
2545  if (ast_channel_state(chan) == AST_STATE_RING ||
2547  break; /* Got ring */
2548  }
2549 
2550  res = analog_distinctive_ring(chan, p, idx, NULL);
2552  if (res) {
2553  goto quit;
2554  }
2555  } else {
2556  ast_log(LOG_WARNING, "Unable to get caller ID space\n");
2557  }
2558  } else {
2560  "Channel %s in prering state, but I have nothing to do. Terminating simple switch, should be restarted by the actual ring.\n",
2561  ast_channel_name(chan));
2562  ast_hangup(chan);
2563  goto quit;
2564  }
2565  } else if (p->use_callerid && p->cid_start == ANALOG_CID_START_RING) {
2566  namebuf[0] = 0;
2567  numbuf[0] = 0;
2568 
2570  int timeout = 10000; /* Ten seconds */
2571  struct timeval start = ast_tvnow();
2572  enum analog_event ev;
2573  int ring_data[RING_PATTERNS] = { 0 };
2574  int ring_data_idx = 0;
2575  int ms;
2576 
2577  if (!p->usedistinctiveringdetection) {
2578  /* Disable distinctive ring timeout count */
2579  analog_set_ringtimeout(p, 0);
2580  }
2581  while ((ms = ast_remaining_ms(start, timeout))) {
2582  res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2583  if (res < 0) {
2585  "CallerID returned with error on channel '%s'\n",
2586  ast_channel_name(chan));
2587  break;
2588  }
2589  if (res == 0) {
2590  break;
2591  }
2592  if (res != 1) {
2593  continue;
2594  }
2595  if (ev == ANALOG_EVENT_NOALARM) {
2596  analog_set_alarm(p, 0);
2597  } else if (ev == ANALOG_EVENT_POLARITY
2599  && p->polarity == POLARITY_REV) {
2600  ast_debug(1,
2601  "Hanging up due to polarity reversal on channel %d while detecting callerid\n",
2602  p->channel);
2603  p->polarity = POLARITY_IDLE;
2605  ast_hangup(chan);
2606  goto quit;
2607  } else if (ev == ANALOG_EVENT_RINGOFFHOOK
2609  && ring_data_idx < RING_PATTERNS) {
2610  /*
2611  * Detect callerid while collecting possible
2612  * distinctive ring pattern.
2613  */
2614  ring_data[ring_data_idx] = p->ringt;
2615  ++ring_data_idx;
2616  }
2617  }
2618 
2619  name = namebuf;
2620  number = numbuf;
2621 
2622  res = analog_distinctive_ring(chan, p, idx, ring_data);
2624  if (res) {
2625  goto quit;
2626  }
2627  } else {
2628  ast_log(LOG_WARNING, "Unable to get caller ID space\n");
2629  }
2630  }
2631 
2632  if (number) {
2633  ast_shrink_phone_number(number);
2634  }
2635  ast_set_callerid(chan, number, name, number);
2636 
2637  analog_handle_notify_message(chan, p, flags, -1);
2638 
2639  ast_channel_lock(chan);
2641  ast_channel_rings_set(chan, 1);
2642  ast_channel_unlock(chan);
2644  res = ast_pbx_run(chan);
2645  if (res) {
2646  ast_hangup(chan);
2647  ast_log(LOG_WARNING, "PBX exited non-zero\n");
2648  }
2649  goto quit;
2650  default:
2651  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);
2652  break;
2653  }
2655  if (res < 0) {
2656  ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
2657  }
2658  ast_hangup(chan);
2659 quit:
2660  ao2_cleanup(smdi_msg);
2662  return NULL;
2663 }
2664 
2665 int analog_ss_thread_start(struct analog_pvt *p, struct ast_channel *chan)
2666 {
2667  pthread_t threadid;
2668 
2669  return ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, p);
2670 }
2671 
2673 {
2674  RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
2675 
2676  ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", channel);
2677  body = ast_json_pack("{s: i}", "Channel", channel);
2678  if (!body) {
2679  return;
2680  }
2681 
2682  ast_manager_publish_event("AlarmClear", EVENT_FLAG_SYSTEM, body);
2683 }
2684 
2685 static struct ast_frame *__analog_handle_event(struct analog_pvt *p, struct ast_channel *ast)
2686 {
2687  int res, x;
2688  int mysig;
2689  int idx;
2690  char *c;
2691  pthread_t threadid;
2692  struct ast_channel *chan;
2693  struct ast_frame *f;
2694  struct ast_control_pvt_cause_code *cause_code = NULL;
2695  int data_size = sizeof(*cause_code);
2696  char *subclass = NULL;
2697 
2698  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
2699 
2700  idx = analog_get_index(ast, p, 0);
2701  if (idx < 0) {
2702  return &ast_null_frame;
2703  }
2704  if (idx != ANALOG_SUB_REAL) {
2705  ast_log(LOG_ERROR, "We got an event on a non real sub. Fix it!\n");
2706  }
2707 
2708  mysig = p->sig;
2709  if (p->outsigmod > -1) {
2710  mysig = p->outsigmod;
2711  }
2712 
2713  p->subs[idx].f.frametype = AST_FRAME_NULL;
2714  p->subs[idx].f.subclass.integer = 0;
2715  p->subs[idx].f.datalen = 0;
2716  p->subs[idx].f.samples = 0;
2717  p->subs[idx].f.mallocd = 0;
2718  p->subs[idx].f.offset = 0;
2719  p->subs[idx].f.src = "dahdi_handle_event";
2720  p->subs[idx].f.data.ptr = NULL;
2721  f = &p->subs[idx].f;
2722 
2723  res = analog_get_event(p);
2724 
2725  ast_debug(1, "Got event %s(%d) on channel %d (index %u)\n", analog_event2str(res), res, p->channel, idx);
2726 
2728  analog_set_pulsedial(p, (res & ANALOG_EVENT_PULSEDIGIT) ? 1 : 0);
2729  ast_debug(1, "Detected %sdigit '%c'\n", (res & ANALOG_EVENT_PULSEDIGIT) ? "pulse ": "", res & 0xff);
2730  analog_confmute(p, 0);
2731  p->subs[idx].f.frametype = AST_FRAME_DTMF_END;
2732  p->subs[idx].f.subclass.integer = res & 0xff;
2733  analog_handle_dtmf(p, ast, idx, &f);
2734  return f;
2735  }
2736 
2737  if (res & ANALOG_EVENT_DTMFDOWN) {
2738  ast_debug(1, "DTMF Down '%c'\n", res & 0xff);
2739  /* Mute conference */
2740  analog_confmute(p, 1);
2742  p->subs[idx].f.subclass.integer = res & 0xff;
2743  analog_handle_dtmf(p, ast, idx, &f);
2744  return f;
2745  }
2746 
2747  switch (res) {
2748  case ANALOG_EVENT_ALARM:
2749  case ANALOG_EVENT_POLARITY:
2750  case ANALOG_EVENT_ONHOOK:
2751  /* add length of "ANALOG " */
2752  data_size += 7;
2753  subclass = analog_event2str(res);
2754  data_size += strlen(subclass);
2755  cause_code = ast_alloca(data_size);
2756  memset(cause_code, 0, data_size);
2757  cause_code->ast_cause = AST_CAUSE_NORMAL_CLEARING;
2759  snprintf(cause_code->code, data_size - sizeof(*cause_code) + 1, "ANALOG %s", subclass);
2760  break;
2761  default:
2762  break;
2763  }
2764 
2765  switch (res) {
2767  ast_verb(3, "Channel %d echo canceler disabled due to CED detection\n", p->channel);
2769  break;
2770 #ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
2772  ast_verb(3, "Channel %d detected a CED tone towards the network.\n", p->channel);
2773  break;
2775  ast_verb(3, "Channel %d detected a CED tone from the network.\n", p->channel);
2776  break;
2778  ast_verb(3, "Channel %d echo canceler disabled its NLP.\n", p->channel);
2779  break;
2781  ast_verb(3, "Channel %d echo canceler enabled its NLP.\n", p->channel);
2782  break;
2783 #endif
2785  /* Stop tone if there's a pulse start and the PBX isn't started */
2786  if (!ast_channel_pbx(ast))
2788  break;
2790  if (p->inalarm) {
2791  break;
2792  }
2793  x = analog_is_dialing(p, idx);
2794  if (!x) { /* if not still dialing in driver */
2796  if (p->echobreak) {
2798  ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr));
2801  p->echobreak = 0;
2802  } else {
2803  analog_set_dialing(p, 0);
2804  if ((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) {
2805  /* if thru with dialing after offhook */
2807  ast_setstate(ast, AST_STATE_UP);
2808  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
2810  break;
2811  } else { /* if to state wait for offhook to dial rest */
2812  /* we now wait for off hook */
2814  }
2815  }
2816  if (ast_channel_state(ast) == AST_STATE_DIALING) {
2817  if (analog_have_progressdetect(p)) {
2818  ast_debug(1, "Done dialing, but waiting for progress detection before doing more...\n");
2819  } else if (analog_check_confirmanswer(p) || (!p->dialednone
2820  && ((mysig == ANALOG_SIG_EM) || (mysig == ANALOG_SIG_EM_E1)
2821  || (mysig == ANALOG_SIG_EMWINK) || (mysig == ANALOG_SIG_FEATD)
2822  || (mysig == ANALOG_SIG_FEATDMF_TA) || (mysig == ANALOG_SIG_FEATDMF)
2823  || (mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA)
2824  || (mysig == ANALOG_SIG_FGC_CAMAMF) || (mysig == ANALOG_SIG_FEATB)
2825  || (mysig == ANALOG_SIG_SF) || (mysig == ANALOG_SIG_SFWINK)
2826  || (mysig == ANALOG_SIG_SF_FEATD) || (mysig == ANALOG_SIG_SF_FEATDMF)
2827  || (mysig == ANALOG_SIG_SF_FEATB)))) {
2829  } else if (!p->answeronpolarityswitch) {
2830  ast_setstate(ast, AST_STATE_UP);
2831  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
2833  /* If aops=0 and hops=1, this is necessary */
2834  p->polarity = POLARITY_REV;
2835  } else {
2836  /* Start clean, so we can catch the change to REV polarity when party answers */
2837  p->polarity = POLARITY_IDLE;
2838  }
2839  }
2840  }
2841  }
2842  break;
2843  case ANALOG_EVENT_ALARM:
2844  analog_set_alarm(p, 1);
2847  case ANALOG_EVENT_ONHOOK:
2848  ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
2849  ast_channel_hangupcause_hash_set(ast, cause_code, data_size);
2850  switch (p->sig) {
2851  case ANALOG_SIG_FXOLS:
2852  case ANALOG_SIG_FXOGS:
2853  case ANALOG_SIG_FXOKS:
2855  p->fxsoffhookstate = 0;
2856  p->onhooktime = time(NULL);
2857  p->msgstate = -1;
2858  /* Check for some special conditions regarding call waiting */
2859  if (idx == ANALOG_SUB_REAL) {
2860  /* The normal line was hung up */
2861  if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
2862  /* Need to hold the lock for real-call, private, and call-waiting call */
2864  if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
2865  /*
2866  * The call waiting call dissappeared.
2867  * This is now a normal hangup.
2868  */
2870  return NULL;
2871  }
2872 
2873  /* There's a call waiting call, so ring the phone, but make it unowned in the mean time */
2875  ast_verb(3, "Channel %d still has (callwait) call, ringing phone\n", p->channel);
2879  /* Don't start streaming audio yet if the incoming call isn't up yet */
2881  analog_set_dialing(p, 1);
2882  }
2883  /* Unlock the call-waiting call that we swapped to real-call. */
2885  analog_ring(p);
2886  } else if (p->subs[ANALOG_SUB_THREEWAY].owner) {
2887  unsigned int mssinceflash;
2888 
2889  /* Need to hold the lock for real-call, private, and 3-way call */
2891  if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
2892  ast_log(LOG_NOTICE, "Whoa, threeway disappeared kinda randomly.\n");
2893  /* Just hangup */
2894  return NULL;
2895  }
2896  if (p->owner != ast) {
2898  ast_log(LOG_WARNING, "This isn't good...\n");
2899  /* Just hangup */
2900  return NULL;
2901  }
2902 
2903  mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
2904  ast_debug(1, "Last flash was %u ms ago\n", mssinceflash);
2905  if (mssinceflash < MIN_MS_SINCE_FLASH) {
2906  /* It hasn't been long enough since the last flashook. This is probably a bounce on
2907  hanging up. Hangup both channels now */
2908  ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel);
2912  } else if ((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) {
2913  if (p->transfer) {
2914  /* In any case this isn't a threeway call anymore */
2917 
2918  /* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */
2919  if (!p->transfertobusy && ast_channel_state(ast) == AST_STATE_BUSY) {
2920  /* Swap subs and dis-own channel */
2922  /* Unlock the 3-way call that we swapped to real-call. */
2925  /* Ring the phone */
2926  analog_ring(p);
2927  } else if (!analog_attempt_transfer(p)) {
2928  /*
2929  * Transfer successful. Don't actually hang up at this point.
2930  * Let our channel legs of the calls die off as the transfer
2931  * percolates through the core.
2932  */
2933  break;
2934  }
2935  } else {
2938  }
2939  } else {
2940  /* Swap subs and dis-own channel */
2942  /* Unlock the 3-way call that we swapped to real-call. */
2945  /* Ring the phone */
2946  analog_ring(p);
2947  }
2948  }
2949  } else {
2950  ast_log(LOG_WARNING, "Got a hangup and my index is %u?\n", idx);
2951  }
2952  /* Fall through */
2953  default:
2955  return NULL;
2956  }
2957  break;
2959  if (p->inalarm) {
2960  break;
2961  }
2962  /* for E911, its supposed to wait for offhook then dial
2963  the second half of the dial string */
2964  if (((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) && (ast_channel_state(ast) == AST_STATE_DIALING_OFFHOOK)) {
2965  c = strchr(p->dialdest, '/');
2966  if (c) {
2967  c++;
2968  } else {
2969  c = p->dialdest;
2970  }
2971 
2972  if (*c) {
2973  int numchars = snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
2974  if (numchars >= sizeof(p->dop.dialstr)) {
2975  ast_log(LOG_WARNING, "Dial string '%s' truncated\n", c);
2976  }
2977  } else {
2978  ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
2979  }
2980 
2981  if (strlen(p->dop.dialstr) > 4) {
2982  memset(p->echorest, 'w', sizeof(p->echorest) - 1);
2983  strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
2984  p->echorest[sizeof(p->echorest) - 1] = '\0';
2985  p->echobreak = 1;
2986  p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
2987  } else {
2988  p->echobreak = 0;
2989  }
2990  if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
2991  analog_on_hook(p);
2992  return NULL;
2993  }
2994  analog_set_dialing(p, 1);
2995  return &p->subs[idx].f;
2996  }
2997  switch (p->sig) {
2998  case ANALOG_SIG_FXOLS:
2999  case ANALOG_SIG_FXOGS:
3000  case ANALOG_SIG_FXOKS:
3001  p->fxsoffhookstate = 1;
3002  switch (ast_channel_state(ast)) {
3003  case AST_STATE_RINGING:
3006  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
3008  /* Make sure it stops ringing */
3009  analog_set_needringing(p, 0);
3010  analog_off_hook(p);
3011  ast_debug(1, "channel %d answered\n", p->channel);
3012 
3013  /* Cancel any running CallerID spill */
3015 
3016  analog_set_dialing(p, 0);
3017  p->callwaitcas = 0;
3018  if (analog_check_confirmanswer(p)) {
3019  /* Ignore answer if "confirm answer" is enabled */
3020  p->subs[idx].f.frametype = AST_FRAME_NULL;
3021  p->subs[idx].f.subclass.integer = 0;
3022  } else if (!ast_strlen_zero(p->dop.dialstr)) {
3023  /* [email protected] 4/3/03 - fxo should be able to do deferred dialing */
3024  res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3025  if (res) {
3026  p->dop.dialstr[0] = '\0';
3027  return NULL;
3028  } else {
3029  ast_debug(1, "Sent FXO deferred digit string: %s\n", p->dop.dialstr);
3030  p->subs[idx].f.frametype = AST_FRAME_NULL;
3031  p->subs[idx].f.subclass.integer = 0;
3032  analog_set_dialing(p, 1);
3033  }
3034  p->dop.dialstr[0] = '\0';
3036  } else {
3037  ast_setstate(ast, AST_STATE_UP);
3039  }
3040  return &p->subs[idx].f;
3041  case AST_STATE_DOWN:
3043  ast_channel_rings_set(ast, 1);
3044  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
3046  ast_debug(1, "channel %d picked up\n", p->channel);
3047  return &p->subs[idx].f;
3048  case AST_STATE_UP:
3049  /* Make sure it stops ringing */
3050  analog_off_hook(p);
3051  /* Okay -- probably call waiting */
3052  ast_queue_unhold(p->owner);
3053  break;
3054  case AST_STATE_RESERVED:
3055  /* Start up dialtone */
3056  if (analog_has_voicemail(p)) {
3058  } else {
3060  }
3061  break;
3062  default:
3063  ast_log(LOG_WARNING, "FXO phone off hook in weird state %u??\n", ast_channel_state(ast));
3064  }
3065  break;
3066  case ANALOG_SIG_FXSLS:
3067  case ANALOG_SIG_FXSGS:
3068  case ANALOG_SIG_FXSKS:
3069  if (ast_channel_state(ast) == AST_STATE_RING) {
3071  }
3072 
3073  /* Fall through */
3074  case ANALOG_SIG_EM:
3075  case ANALOG_SIG_EM_E1:
3076  case ANALOG_SIG_EMWINK:
3077  case ANALOG_SIG_FEATD:
3078  case ANALOG_SIG_FEATDMF:
3079  case ANALOG_SIG_FEATDMF_TA:
3080  case ANALOG_SIG_E911:
3081  case ANALOG_SIG_FGC_CAMA:
3082  case ANALOG_SIG_FGC_CAMAMF:
3083  case ANALOG_SIG_FEATB:
3084  case ANALOG_SIG_SF:
3085  case ANALOG_SIG_SFWINK:
3086  case ANALOG_SIG_SF_FEATD:
3087  case ANALOG_SIG_SF_FEATDMF:
3088  case ANALOG_SIG_SF_FEATB:
3089  switch (ast_channel_state(ast)) {
3090  case AST_STATE_PRERING:
3092  /* Fall through */
3093  case AST_STATE_DOWN:
3094  case AST_STATE_RING:
3095  ast_debug(1, "Ring detected\n");
3096  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
3098  break;
3099  case AST_STATE_RINGING:
3100  case AST_STATE_DIALING:
3101  if (p->outgoing) {
3102  ast_debug(1, "Line answered\n");
3103  if (analog_check_confirmanswer(p)) {
3104  p->subs[idx].f.frametype = AST_FRAME_NULL;
3105  p->subs[idx].f.subclass.integer = 0;
3106  } else {
3107  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
3109  ast_setstate(ast, AST_STATE_UP);
3110  }
3111  break;
3112  }
3113  /* Fall through */
3114  default:
3115  ast_log(LOG_WARNING, "Ring/Off-hook in strange state %u on channel %d\n", ast_channel_state(ast), p->channel);
3116  break;
3117  }
3118  break;
3119  default:
3120  ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3121  break;
3122  }
3123  break;
3125  switch (p->sig) {
3126  case ANALOG_SIG_FXSLS:
3127  case ANALOG_SIG_FXSGS:
3128  case ANALOG_SIG_FXSKS:
3129  if (ast_channel_state(ast) == AST_STATE_RING) {
3131  }
3132  break;
3133  default:
3134  break;
3135  }
3136  break;
3138  if (p->inalarm) break;
3140  if (ast_channel_rings(ast) == p->cidrings) {
3141  analog_send_callerid(p, 0, &p->caller);
3142  }
3143 
3144  if (ast_channel_rings(ast) > p->cidrings) {
3146  p->callwaitcas = 0;
3147  }
3148  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
3150  break;
3151  case ANALOG_EVENT_RINGERON:
3152  break;
3153  case ANALOG_EVENT_NOALARM:
3154  analog_set_alarm(p, 0);
3156  break;
3158  if (p->inalarm) {
3159  break;
3160  }
3161  /* Remember last time we got a flash-hook */
3162  gettimeofday(&p->flashtime, NULL);
3163  switch (mysig) {
3164  case ANALOG_SIG_FXOLS:
3165  case ANALOG_SIG_FXOGS:
3166  case ANALOG_SIG_FXOKS:
3167  ast_debug(1, "Winkflash, index: %u, normal: %d, callwait: %d, thirdcall: %d\n",
3169 
3170  /* Cancel any running CallerID spill */
3172  p->callwaitcas = 0;
3173 
3174  if (idx != ANALOG_SUB_REAL) {
3175  ast_log(LOG_WARNING, "Got flash hook with index %u on channel %d?!?\n", idx, p->channel);
3176  goto winkflashdone;
3177  }
3178 
3179  if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
3180  /* Need to hold the lock for real-call, private, and call-waiting call */
3182  if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
3183  /*
3184  * The call waiting call dissappeared.
3185  * Let's just ignore this flash-hook.
3186  */
3187  ast_log(LOG_NOTICE, "Whoa, the call-waiting call disappeared.\n");
3188  goto winkflashdone;
3189  }
3190 
3191  /* Swap to call-wait */
3195  ast_debug(1, "Making %s the new owner\n", ast_channel_name(p->owner));
3199  }
3201 
3202  /* Start music on hold if appropriate */
3203  if (!p->subs[ANALOG_SUB_CALLWAIT].inthreeway) {
3205  }
3208 
3209  /* Unlock the call-waiting call that we swapped to real-call. */
3211  } else if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3212  if (!p->threewaycalling) {
3213  /* Just send a flash if no 3-way calling */
3215  goto winkflashdone;
3216  } else if (!analog_check_for_conference(p)) {
3217  ast_callid callid = 0;
3218  int callid_created;
3219  char cid_num[256];
3220  char cid_name[256];
3221 
3222  cid_num[0] = '\0';
3223  cid_name[0] = '\0';
3224  if (p->dahditrcallerid && p->owner) {
3226  && ast_channel_caller(p->owner)->id.number.str) {
3228  sizeof(cid_num));
3229  }
3231  && ast_channel_caller(p->owner)->id.name.str) {
3233  sizeof(cid_name));
3234  }
3235  }
3236  /* XXX This section needs much more error checking!!! XXX */
3237  /* Start a 3-way call if feasible */
3238  if (!((ast_channel_pbx(ast)) ||
3239  (ast_channel_state(ast) == AST_STATE_UP) ||
3240  (ast_channel_state(ast) == AST_STATE_RING))) {
3241  ast_debug(1, "Flash when call not up or ringing\n");
3242  goto winkflashdone;
3243  }
3245  ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n");
3246  goto winkflashdone;
3247  }
3248 
3249  callid_created = ast_callid_threadstorage_auto(&callid);
3250 
3251  /*
3252  * Make new channel
3253  *
3254  * We cannot hold the p or ast locks while creating a new
3255  * channel.
3256  */
3258  ast_channel_unlock(ast);
3260  ast_channel_lock(ast);
3262  if (!chan) {
3264  "Cannot allocate new call structure on channel %d\n",
3265  p->channel);
3267  ast_callid_threadstorage_auto_clean(callid, callid_created);
3268  goto winkflashdone;
3269  }
3270  if (p->dahditrcallerid) {
3271  if (!p->origcid_num) {
3272  p->origcid_num = ast_strdup(p->cid_num);
3273  }
3274  if (!p->origcid_name) {
3275  p->origcid_name = ast_strdup(p->cid_name);
3276  }
3277  ast_copy_string(p->cid_num, cid_num, sizeof(p->cid_num));
3278  ast_copy_string(p->cid_name, cid_name, sizeof(p->cid_name));
3279  }
3280  /* Swap things around between the three-way and real call */
3282  /* Disable echo canceller for better dialing */
3285  if (res) {
3286  ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel);
3287  }
3288  analog_set_new_owner(p, chan);
3289  p->ss_astchan = chan;
3290  if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, p)) {
3291  ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel);
3294  ast_hangup(chan);
3295  } else {
3296  ast_verb(3, "Started three way call on channel %d\n", p->channel);
3297 
3298  /* Start music on hold */
3300  }
3301  ast_callid_threadstorage_auto_clean(callid, callid_created);
3302  }
3303  } else {
3304  /* Already have a 3 way call */
3305  enum analog_sub orig_3way_sub;
3306 
3307  /* Need to hold the lock for real-call, private, and 3-way call */
3309  if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3310  /*
3311  * The 3-way call dissappeared.
3312  * Let's just ignore this flash-hook.
3313  */
3314  ast_log(LOG_NOTICE, "Whoa, the 3-way call disappeared.\n");
3315  goto winkflashdone;
3316  }
3317  orig_3way_sub = ANALOG_SUB_THREEWAY;
3318 
3320  /* Call is already up, drop the last person */
3321  ast_debug(1, "Got flash with three way call up, dropping last call on %d\n", p->channel);
3322  /* If the primary call isn't answered yet, use it */
3325  /* Swap back -- we're dropping the real 3-way that isn't finished yet*/
3327  orig_3way_sub = ANALOG_SUB_REAL;
3329  }
3330  /* Drop the last call and stop the conference */
3331  ast_verb(3, "Dropping three-way call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner));
3335  } else {
3336  /* Lets see what we're up to */
3337  if (((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) &&
3338  (p->transfertobusy || (ast_channel_state(ast) != AST_STATE_BUSY))) {
3339  ast_verb(3, "Building conference call with %s and %s\n",
3342  /* Put them in the threeway, and flip */
3345  if (ast_channel_state(ast) == AST_STATE_UP) {
3347  orig_3way_sub = ANALOG_SUB_REAL;
3348  }
3349  ast_queue_unhold(p->subs[orig_3way_sub].owner);
3351  } else {
3352  ast_verb(3, "Dumping incomplete call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner));
3354  orig_3way_sub = ANALOG_SUB_REAL;
3359  }
3360  }
3361  ast_channel_unlock(p->subs[orig_3way_sub].owner);
3362  }
3363 winkflashdone:
3364  analog_update_conf(p);
3365  break;
3366  case ANALOG_SIG_EM:
3367  case ANALOG_SIG_EM_E1:
3368  case ANALOG_SIG_FEATD:
3369  case ANALOG_SIG_SF:
3370  case ANALOG_SIG_SFWINK:
3371  case ANALOG_SIG_SF_FEATD:
3372  case ANALOG_SIG_FXSLS:
3373  case ANALOG_SIG_FXSGS:
3374  if (p->dialing) {
3375  ast_debug(1, "Ignoring wink on channel %d\n", p->channel);
3376  } else {
3377  ast_debug(1, "Got wink in weird state %u on channel %d\n", ast_channel_state(ast), p->channel);
3378  }
3379  break;
3380  case ANALOG_SIG_FEATDMF_TA:
3381  switch (p->whichwink) {
3382  case 0:
3383  ast_debug(1, "ANI2 set to '%d' and ANI is '%s'\n", ast_channel_caller(p->owner)->ani2,
3385  ast_channel_caller(p->owner)->ani.number.str, ""));
3386  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%d%s#",
3389  ast_channel_caller(p->owner)->ani.number.str, ""));
3390  break;
3391  case 1:
3392  ast_copy_string(p->dop.dialstr, p->finaldial, sizeof(p->dop.dialstr));
3393  break;
3394  case 2:
3395  ast_log(LOG_WARNING, "Received unexpected wink on channel of type ANALOG_SIG_FEATDMF_TA\n");
3396  return NULL;
3397  }
3398  p->whichwink++;
3399  /* Fall through */
3400  case ANALOG_SIG_FEATDMF:
3401  case ANALOG_SIG_E911:
3402  case ANALOG_SIG_FGC_CAMAMF:
3403  case ANALOG_SIG_FGC_CAMA:
3404  case ANALOG_SIG_FEATB:
3405  case ANALOG_SIG_SF_FEATDMF:
3406  case ANALOG_SIG_SF_FEATB:
3407  case ANALOG_SIG_EMWINK:
3408  /* FGD MF and EMWINK *Must* wait for wink */
3409  if (!ast_strlen_zero(p->dop.dialstr)) {
3410  res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3411  if (res) {
3412  p->dop.dialstr[0] = '\0';
3413  return NULL;
3414  } else {
3415  ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3416  }
3417  }
3418  p->dop.dialstr[0] = '\0';
3419  break;
3420  default:
3421  ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3422  }
3423  break;
3425  if (p->inalarm) break;
3426  if (analog_check_waitingfordt(p)) {
3427  break;
3428  }
3429  switch (mysig) {
3430  case ANALOG_SIG_FXSLS: /* only interesting for FXS */
3431  case ANALOG_SIG_FXSGS:
3432  case ANALOG_SIG_FXSKS:
3433  case ANALOG_SIG_EM:
3434  case ANALOG_SIG_EM_E1:
3435  case ANALOG_SIG_EMWINK:
3436  case ANALOG_SIG_FEATD:
3437  case ANALOG_SIG_SF:
3438  case ANALOG_SIG_SFWINK:
3439  case ANALOG_SIG_SF_FEATD:
3440  if (!ast_strlen_zero(p->dop.dialstr)) {
3441  res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3442  if (res) {
3443  p->dop.dialstr[0] = '\0';
3444  return NULL;
3445  } else {
3446  ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3447  }
3448  }
3449  p->dop.dialstr[0] = '\0';
3451  break;
3452  case ANALOG_SIG_FEATDMF:
3453  case ANALOG_SIG_FEATDMF_TA:
3454  case ANALOG_SIG_E911:
3455  case ANALOG_SIG_FGC_CAMA:
3456  case ANALOG_SIG_FGC_CAMAMF:
3457  case ANALOG_SIG_FEATB:
3458  case ANALOG_SIG_SF_FEATDMF:
3459  case ANALOG_SIG_SF_FEATB:
3460  ast_debug(1, "Got hook complete in MF FGD, waiting for wink now on channel %d\n",p->channel);
3461  break;
3462  default:
3463  break;
3464  }
3465  break;
3466  case ANALOG_EVENT_POLARITY:
3467  /*
3468  * If we get a Polarity Switch event, this could be
3469  * due to line seizure, remote end connect or remote end disconnect.
3470  *
3471  * Check to see if we should change the polarity state and
3472  * mark the channel as UP or if this is an indication
3473  * of remote end disconnect.
3474  */
3475 
3476  if (p->polarityonanswerdelay > 0) {
3477  /* check if event is not too soon after OffHook or Answer */
3479  switch (ast_channel_state(ast)) {
3480  case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3481  case AST_STATE_RINGING: /*!< Remote end is ringing */
3482  if (p->answeronpolarityswitch) {
3483  ast_debug(1, "Answering on polarity switch! channel %d\n", p->channel);
3485  p->polarity = POLARITY_REV;
3486  if (p->hanguponpolarityswitch) {
3487  p->polaritydelaytv = ast_tvnow();
3488  }
3489  } else {
3490  ast_debug(1, "Ignore Answer on polarity switch, channel %d\n", p->channel);
3491  }
3492  break;
3493 
3494  case AST_STATE_UP: /*!< Line is up */
3495  case AST_STATE_RING: /*!< Line is ringing */
3496  if (p->hanguponpolarityswitch) {
3497  ast_debug(1, "HangingUp on polarity switch! channel %d\n", p->channel);
3498  ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
3499  ast_channel_hangupcause_hash_set(ast, cause_code, data_size);
3501  p->polarity = POLARITY_IDLE;
3502  } else {
3503  ast_debug(1, "Ignore Hangup on polarity switch, channel %d\n", p->channel);
3504  }
3505  break;
3506 
3507  case AST_STATE_DOWN: /*!< Channel is down and available */
3508  case AST_STATE_RESERVED: /*!< Channel is down, but reserved */
3509  case AST_STATE_OFFHOOK: /*!< Channel is off hook */
3510  case AST_STATE_BUSY: /*!< Line is busy */
3511  case AST_STATE_DIALING_OFFHOOK: /*!< Digits (or equivalent) have been dialed while offhook */
3512  case AST_STATE_PRERING: /*!< Channel has detected an incoming call and is waiting for ring */
3513  default:
3515  ast_debug(1, "Ignoring Polarity switch on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3516  }
3517  break;
3518  }
3519 
3520  } else {
3521  /* event is too soon after OffHook or Answer */
3522  switch (ast_channel_state(ast)) {
3523  case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3524  case AST_STATE_RINGING: /*!< Remote end is ringing */
3525  if (p->answeronpolarityswitch) {
3526  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));
3527  }
3528  break;
3529 
3530  case AST_STATE_UP: /*!< Line is up */
3531  case AST_STATE_RING: /*!< Line is ringing */
3532  if (p->hanguponpolarityswitch) {
3533  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));
3534  }
3535  break;
3536 
3537  default:
3539  ast_debug(1, "Polarity switch detected (too close to previous event) on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3540  }
3541  break;
3542  }
3543  }
3544  }
3545 
3546  /* Added more log_debug information below to provide a better indication of what is going on */
3547  ast_debug(1, "Polarity Reversal event occured - 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) );
3548  break;
3549  default:
3550  ast_debug(1, "Dunno what to do with event %d on channel %d\n", res, p->channel);
3551  }
3552  return &p->subs[idx].f;
3553 }
3554 
3555 struct ast_frame *analog_exception(struct analog_pvt *p, struct ast_channel *ast)
3556 {
3557  int res;
3558  int idx;
3559  struct ast_frame *f;
3560 
3561  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
3562 
3563  idx = analog_get_index(ast, p, 1);
3564  if (idx < 0) {
3565  idx = ANALOG_SUB_REAL;
3566  }
3567 
3568  p->subs[idx].f.frametype = AST_FRAME_NULL;
3569  p->subs[idx].f.datalen = 0;
3570  p->subs[idx].f.samples = 0;
3571  p->subs[idx].f.mallocd = 0;
3572  p->subs[idx].f.offset = 0;
3573  p->subs[idx].f.subclass.integer = 0;
3574  p->subs[idx].f.delivery = ast_tv(0,0);
3575  p->subs[idx].f.src = "dahdi_exception";
3576  p->subs[idx].f.data.ptr = NULL;
3577 
3578  if (!p->owner) {
3579  /* If nobody owns us, absorb the event appropriately, otherwise
3580  we loop indefinitely. This occurs when, during call waiting, the
3581  other end hangs up our channel so that it no longer exists, but we
3582  have neither FLASH'd nor ONHOOK'd to signify our desire to
3583  change to the other channel. */
3584  res = analog_get_event(p);
3585 
3586  /* Switch to real if there is one and this isn't something really silly... */
3587  if ((res != ANALOG_EVENT_RINGEROFF) && (res != ANALOG_EVENT_RINGERON) &&
3588  (res != ANALOG_EVENT_HOOKCOMPLETE)) {
3589  ast_debug(1, "Restoring owner of channel %d on event %d\n", p->channel, res);
3591  if (p->owner && ast != p->owner) {
3592  /*
3593  * Could this even happen?
3594  * Possible deadlock because we do not have the real-call lock.
3595  */
3596  ast_log(LOG_WARNING, "Event %s on %s is not restored owner %s\n",
3598  }
3599  if (p->owner) {
3600  ast_queue_unhold(p->owner);
3601  }
3602  }
3603  switch (res) {
3604  case ANALOG_EVENT_ONHOOK:
3606  if (p->owner) {
3607  ast_verb(3, "Channel %s still has call, ringing phone\n", ast_channel_name(p->owner));
3608  analog_ring(p);
3610  } else {
3611  ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
3612  analog_event2str(res));
3613  }
3614  analog_update_conf(p);
3615  break;
3618  analog_off_hook(p);
3619  if (p->owner && (ast_channel_state(p->owner) == AST_STATE_RINGING)) {
3621  analog_set_dialing(p, 0);
3622  }
3623  break;
3625  case ANALOG_EVENT_RINGERON:
3627  /* Do nothing */
3628  break;
3630  gettimeofday(&p->flashtime, NULL);
3631  if (p->owner) {
3632  ast_verb(3, "Channel %d flashed to other channel %s\n", p->channel, ast_channel_name(p->owner));
3633  if (ast_channel_state(p->owner) != AST_STATE_UP) {
3634  /* Answer if necessary */
3637  }
3639  ast_queue_unhold(p->owner);
3640  } else {
3641  ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
3642  analog_event2str(res));
3643  }
3644  analog_update_conf(p);
3645  break;
3646  default:
3647  ast_log(LOG_WARNING, "Don't know how to absorb event %s\n", analog_event2str(res));
3648  break;
3649  }
3650  f = &p->subs[idx].f;
3651  return f;
3652  }
3653  ast_debug(1, "Exception on %d, channel %d\n", ast_channel_fd(ast, 0), p->channel);
3654  /* If it's not us, return NULL immediately */
3655  if (ast != p->owner) {
3656  ast_log(LOG_WARNING, "We're %s, not %s\n", ast_channel_name(ast), ast_channel_name(p->owner));
3657  f = &p->subs[idx].f;
3658  return f;
3659  }
3660 
3661  f = __analog_handle_event(p, ast);
3662  if (!f) {
3663  const char *name = ast_strdupa(ast_channel_name(ast));
3664 
3665  /* Tell the CDR this DAHDI device hung up */
3667  ast_channel_unlock(ast);
3668  ast_set_hangupsource(ast, name, 0);
3669  ast_channel_lock(ast);
3671  }
3672  return f;
3673 }
3674 
3676 {
3677  int res;
3678  pthread_t threadid;
3679  struct ast_channel *chan;
3680  ast_callid callid = 0;
3681  int callid_created;
3682 
3683  ast_debug(1, "channel (%d) - signaling (%d) - event (%s)\n",
3684  i->channel, i->sig, analog_event2str(event));
3685 
3686  /* Handle an event on a given channel for the monitor thread. */
3687  switch (event) {
3690  if (i->inalarm) {
3691  break;
3692  }
3693  /* Got a ring/answer. What kind of channel are we? */
3694  switch (i->sig) {
3695  case ANALOG_SIG_FXOLS:
3696  case ANALOG_SIG_FXOGS:
3697  case ANALOG_SIG_FXOKS:
3698  res = analog_off_hook(i);
3699  i->fxsoffhookstate = 1;
3700  if (res && (errno == EBUSY)) {
3701  break;
3702  }
3703  callid_created = ast_callid_threadstorage_auto(&callid);
3704 
3705  /* Cancel VMWI spill */
3707 
3708  if (i->immediate) {
3710  /* The channel is immediately up. Start right away */
3713  if (!chan) {
3714  ast_log(LOG_WARNING, "Unable to start PBX on channel %d\n", i->channel);
3716  if (res < 0) {
3717  ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
3718  }
3719  }
3720  } else {
3721  /* Check for callerid, digits, etc */
3723  i->ss_astchan = chan;
3724  if (chan) {
3725  if (analog_has_voicemail(i)) {
3727  } else {
3729  }
3730  if (res < 0)
3731  ast_log(LOG_WARNING, "Unable to play dialtone on channel %d, do you have defaultzone and loadzone defined?\n", i->channel);
3732 
3733  if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
3734  ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
3736  if (res < 0) {
3737  ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
3738  }
3739  ast_hangup(chan);
3740  }
3741  } else
3742  ast_log(LOG_WARNING, "Unable to create channel\n");
3743  }
3744  ast_callid_threadstorage_auto_clean(callid, callid_created);
3745  break;
3746  case ANALOG_SIG_FXSLS:
3747  case ANALOG_SIG_FXSGS:
3748  case ANALOG_SIG_FXSKS:
3750  /* Fall through */
3751  case ANALOG_SIG_EMWINK:
3752  case ANALOG_SIG_FEATD:
3753  case ANALOG_SIG_FEATDMF:
3754  case ANALOG_SIG_FEATDMF_TA:
3755  case ANALOG_SIG_E911:
3756  case ANALOG_SIG_FGC_CAMA:
3757  case ANALOG_SIG_FGC_CAMAMF:
3758  case ANALOG_SIG_FEATB:
3759  case ANALOG_SIG_EM:
3760  case ANALOG_SIG_EM_E1:
3761  case ANALOG_SIG_SFWINK:
3762  case ANALOG_SIG_SF_FEATD:
3763  case ANALOG_SIG_SF_FEATDMF:
3764  case ANALOG_SIG_SF_FEATB:
3765  case ANALOG_SIG_SF:
3766  callid_created = ast_callid_threadstorage_auto(&callid);
3767  /* Check for callerid, digits, etc */
3770  } else {
3772  }
3773  i->ss_astchan = chan;
3774  if (!chan) {
3775  ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
3776  } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
3777  ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
3779  if (res < 0) {
3780  ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
3781  }
3782  ast_hangup(chan);
3783  }
3784  ast_callid_threadstorage_auto_clean(callid, callid_created);
3785  break;
3786  default:
3787  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);
3789  if (res < 0) {
3790  ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
3791  }
3792  return NULL;
3793  }
3794  break;
3795  case ANALOG_EVENT_NOALARM:
3796  analog_set_alarm(i, 0);
3798  break;
3799  case ANALOG_EVENT_ALARM:
3800  analog_set_alarm(i, 1);
3802  /* fall thru intentionally */
3803  case ANALOG_EVENT_ONHOOK:
3804  /* Back on hook. Hang up. */
3805  switch (i->sig) {
3806  case ANALOG_SIG_FXOLS:
3807  case ANALOG_SIG_FXOGS:
3808  i->fxsoffhookstate = 0;
3810  /* Fall through */
3811  case ANALOG_SIG_FEATD:
3812  case ANALOG_SIG_FEATDMF:
3813  case ANALOG_SIG_FEATDMF_TA:
3814  case ANALOG_SIG_E911:
3815  case ANALOG_SIG_FGC_CAMA:
3816  case ANALOG_SIG_FGC_CAMAMF:
3817  case ANALOG_SIG_FEATB:
3818  case ANALOG_SIG_EM:
3819  case ANALOG_SIG_EM_E1:
3820  case ANALOG_SIG_EMWINK:
3821  case ANALOG_SIG_SF_FEATD:
3822  case ANALOG_SIG_SF_FEATDMF:
3823  case ANALOG_SIG_SF_FEATB:
3824  case ANALOG_SIG_SF:
3825  case ANALOG_SIG_SFWINK:
3826  case ANALOG_SIG_FXSLS:
3827  case ANALOG_SIG_FXSGS:
3828  case ANALOG_SIG_FXSKS:
3830  res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
3831  analog_on_hook(i);
3832  break;
3833  case ANALOG_SIG_FXOKS:
3834  i->fxsoffhookstate = 0;
3837  /* Diddle the battery for the zhone */
3838 #ifdef ZHONE_HACK
3839  analog_off_hook(i);
3840  usleep(1);
3841 #endif
3842  res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
3843  analog_on_hook(i);
3844  break;
3845  default:
3846  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);
3847  res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
3848  return NULL;
3849  }
3850  break;
3851  case ANALOG_EVENT_POLARITY:
3852  switch (i->sig) {
3853  case ANALOG_SIG_FXSLS:
3854  case ANALOG_SIG_FXSKS:
3855  case ANALOG_SIG_FXSGS:
3856  callid_created = ast_callid_threadstorage_auto(&callid);
3857  /* We have already got a PR before the channel was
3858  created, but it wasn't handled. We need polarity
3859  to be REV for remote hangup detection to work.
3860  At least in Spain */
3861  if (i->hanguponpolarityswitch) {
3862  i->polarity = POLARITY_REV;
3863  }
3865  i->polarity = POLARITY_REV;
3866  ast_verb(2, "Starting post polarity CID detection on channel %d\n",
3867  i->channel);
3869  i->ss_astchan = chan;
3870  if (!chan) {
3871  ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
3872  } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
3873  ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
3874  ast_hangup(chan);
3875  }
3876  }
3877  ast_callid_threadstorage_auto_clean(callid, callid_created);
3878  break;
3879  default:
3881  "handle_init_event detected polarity reversal on non-FXO (ANALOG_SIG_FXS) interface %d\n",
3882  i->channel);
3883  break;
3884  }
3885  break;
3886  case ANALOG_EVENT_DTMFCID:
3887  switch (i->sig) {
3888  case ANALOG_SIG_FXSLS:
3889  case ANALOG_SIG_FXSKS:
3890  case ANALOG_SIG_FXSGS:
3891  callid_created = ast_callid_threadstorage_auto(&callid);
3893  ast_verb(2, "Starting DTMF CID detection on channel %d\n",
3894  i->channel);
3896  i->ss_astchan = chan;
3897  if (!chan) {
3898  ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
3899  } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
3900  ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
3901  ast_hangup(chan);
3902  }
3903  }
3904  ast_callid_threadstorage_auto_clean(callid, callid_created);
3905  break;
3906  default:
3908  "handle_init_event detected dtmfcid generation event on non-FXO (ANALOG_SIG_FXS) interface %d\n",
3909  i->channel);
3910  break;
3911  }
3912  break;
3913  case ANALOG_EVENT_REMOVED: /* destroy channel, will actually do so in do_monitor */
3914  ast_log(LOG_NOTICE, "Got ANALOG_EVENT_REMOVED. Destroying channel %d\n",
3915  i->channel);
3916  return i->chan_pvt;
3919  break;
3922  break;
3923  }
3924  return NULL;
3925 }
3926 
3927 
3928 struct analog_pvt *analog_new(enum analog_sigtype signallingtype, void *private_data)
3929 {
3930  struct analog_pvt *p;
3931 
3932  p = ast_calloc(1, sizeof(*p));
3933  if (!p) {
3934  return p;
3935  }
3936 
3938  p->sig = signallingtype;
3939  p->chan_pvt = private_data;
3940 
3941  /* Some defaults for values */
3944  /* Sub real is assumed to always be alloc'd */
3945  p->subs[ANALOG_SUB_REAL].allocd = 1;
3946 
3947  return p;
3948 }
3949 
3950 /*!
3951  * \brief Delete the analog private structure.
3952  * \since 1.8
3953  *
3954  * \param doomed Analog private structure to delete.
3955  *
3956  * \return Nothing
3957  */
3958 void analog_delete(struct analog_pvt *doomed)
3959 {
3960  ast_free(doomed);
3961 }
3962 
3964 {
3965  /* No call waiting on non FXS channels */
3966  if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) {
3967  p->permcallwaiting = 0;
3968  }
3969 
3971 
3972  return 0;
3973 }
3974 
3975 void analog_free(struct analog_pvt *p)
3976 {
3977  ast_free(p);
3978 }
3979 
3980 /* called while dahdi_pvt is locked in dahdi_fixup */
3981 int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp)
3982 {
3983  struct analog_pvt *new_pvt = newp;
3984  int x;
3985  ast_debug(1, "New owner for channel %d is %s\n", new_pvt->channel, ast_channel_name(newchan));
3986  if (new_pvt->owner == oldchan) {
3987  analog_set_new_owner(new_pvt, newchan);
3988  }
3989  for (x = 0; x < 3; x++) {
3990  if (new_pvt->subs[x].owner == oldchan) {
3991  new_pvt->subs[x].owner = newchan;
3992  }
3993  }
3994 
3995  analog_update_conf(new_pvt);
3996  return 0;
3997 }
3998 
3999 static void analog_publish_dnd_state(int channel, const char *status)
4000 {
4001  RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
4002  RAII_VAR(struct ast_str *, dahdichan, ast_str_create(32), ast_free);
4003  if (!dahdichan) {
4004  return;
4005  }
4006 
4007  ast_str_set(&dahdichan, 0, "DAHDI/%d", channel);
4008 
4009  body = ast_json_pack("{s: s, s: s}",
4010  "Channel", ast_str_buffer(dahdichan),
4011  "Status", status);
4012  if (!body) {
4013  return;
4014  }
4015 
4016  ast_manager_publish_event("DNDState", EVENT_FLAG_SYSTEM, body);
4017 }
4018 
4019 int analog_dnd(struct analog_pvt *p, int flag)
4020 {
4021  if (flag == -1) {
4022  return p->dnd;
4023  }
4024 
4025  p->dnd = flag;
4026 
4027  ast_verb(3, "%s DND on channel %d\n",
4028  flag ? "Enabled" : "Disabled",
4029  p->channel);
4030  analog_publish_dnd_state(p->channel, flag ? "enabled" : "disabled");
4031 
4032  return 0;
4033 }
static int analog_send_callerid(struct analog_pvt *p, int cwcid, struct ast_party_caller *caller)
Definition: sig_analog.c:391
int(*const conf_add)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:203
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
void(*const get_and_handle_alarms)(void *pvt)
Definition: sig_analog.h:227
#define ANALOG_SMDI_MD_WAIT_TIMEOUT
Definition: sig_analog.h:32
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1574
static int analog_handles_digit(struct ast_frame *f)
Definition: sig_analog.c:1539
analog_sigtype
Definition: sig_analog.h:45
int(*const on_hook)(void *pvt)
Set channel on hook.
Definition: sig_analog.h:158
char cid_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:314
#define POLARITY_IDLE
Definition: sig_analog.c:62
#define analog_get_index(ast, p, nullok)
Definition: sig_analog.c:407
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:7434
unsigned int threewaycalling
Definition: sig_analog.h:290
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:4199
#define ast_channel_lock(chan)
Definition: channel.h:2945
analog_event
Definition: sig_analog.h:79
unsigned int use_callerid
Definition: sig_analog.h:293
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
#define POLARITY_REV
Definition: sig_analog.c:63
struct ast_smdi_interface * smdi_iface
The SMDI interface to get SMDI messages from.
Definition: sig_analog.h:301
char * str
Subscriber phone number (Malloced)
Definition: channel.h:292
int(*const wink)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:172
static int analog_unalloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition: sig_analog.c:381
char fwd_st[SMDI_MAX_STATION_NUM_LEN+1]
Definition: smdi.h:69
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:1250
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
void(*const answer_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch=yes.
Definition: sig_analog.h:167
void(*const start_polarityswitch)(void *pvt)
Reset FXS line polarity to IDLE, based on answeronpolarityswitch and hanguponpolarityswitch.
Definition: sig_analog.h:165
Asterisk main include file. File version handling, generic pbx functions.
enum ast_transfer_result ast_bridge_transfer_attended(struct ast_channel *to_transferee, struct ast_channel *to_transfer_target)
Attended transfer.
Definition: bridge.c:4729
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
struct ast_features_pickup_config * ast_get_chan_features_pickup_config(struct ast_channel *chan)
Get the pickup configuration options for a channel.
char chan_name[AST_CHANNEL_NAME]
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
Definition: channel.c:1231
struct ast_party_caller caller
Definition: sig_analog.h:338
struct ast_party_caller caller
Channel Caller ID information.
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
struct timeval polaritydelaytv
Definition: sig_analog.h:342
static int analog_check_for_conference(struct analog_pvt *p)
Definition: sig_analog.c:545
unsigned int immediate
Definition: sig_analog.h:286
int(*const start_cid_detect)(void *pvt, int cid_signalling)
Definition: sig_analog.h:185
analog_tone
Definition: sig_analog.h:70
CallerID (and other GR30) management and generation Includes code and algorithms from the Zapata libr...
int(*const is_off_hook)(void *pvt)
Definition: sig_analog.h:151
void * analog_handle_init_event(struct analog_pvt *i, int event)
Definition: sig_analog.c:3675
Call Parking API.
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:563
static int analog_stop_cid_detect(struct analog_pvt *p)
Definition: sig_analog.c:170
static const struct @163 cidtypes[]
struct ast_party_id id
Connected party ID.
Definition: channel.h:459
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
int(*const is_dialing)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:152
int polarity
Definition: sig_analog.h:341
static struct ast_frame * __analog_handle_event(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:2685
static int analog_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:617
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_party_name name
Subscriber name.
Definition: channel.h:341
static int analog_start(struct analog_pvt *p)
Definition: sig_analog.c:513
int analog_hangup(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:1251
static int analog_set_linear_mode(struct analog_pvt *p, enum analog_sub sub, int linear_mode)
Definition: sig_analog.c:970
#define CID_SIG_SMDI
Definition: callerid.h:63
void(*const handle_dtmf)(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
Definition: sig_analog.h:147
int ast_queue_unhold(struct ast_channel *chan)
Queue an unhold frame.
Definition: channel.c:1216
char mohsuggest[MAX_MUSICCLASS]
Definition: sig_analog.h:312
#define AST_CAUSE_NETWORK_OUT_OF_ORDER
Definition: causes.h:120
#define ast_set_flag(p, flag)
Definition: utils.h:70
static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
Definition: sig_analog.c:438
Call Pickup API.
int echotraining
Definition: sig_analog.h:307
int ringt_base
Definition: sig_analog.h:357
char calling_st[SMDI_MAX_STATION_NUM_LEN+1]
Definition: smdi.h:70
#define LOG_WARNING
Definition: logger.h:274
static void analog_lock_sub_owner(struct analog_pvt *pvt, enum analog_sub sub_idx)
Definition: sig_analog.c:601
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:2042
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
static int analog_train_echocanceller(struct analog_pvt *p)
Definition: sig_analog.c:481
char dialdest[256]
Definition: sig_analog.h:343
int(*const dial_digits)(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop)
Definition: sig_analog.h:173
char finaldial[64]
Definition: sig_analog.h:347
void(*const hangup_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch and hanguponpolarityswitch.
Definition: sig_analog.h:169
int(*const check_confirmanswer)(void *pvt)
Definition: sig_analog.h:238
char callwait_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:335
static int timeout
Definition: cdr_mysql.c:86
unsigned int callreturn
Definition: sig_analog.h:281
struct ast_channel * owner
Definition: sig_analog.h:257
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
static int analog_get_event(struct analog_pvt *p)
Definition: sig_analog.c:194
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4302
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:8355
static int analog_handle_notify_message(struct ast_channel *chan, struct analog_pvt *p, int cid_flags, int neon_mwievent)
Definition: sig_analog.c:1626
struct analog_callback analog_callbacks
Definition: chan_dahdi.c:3355
static int analog_start_cid_detect(struct analog_pvt *p, int cid_signalling)
Definition: sig_analog.c:162
int ast_ignore_pattern(const char *context, const char *pattern)
Checks to see if a number should be ignored.
Definition: pbx.c:6921
int cid_signalling
Definition: sig_analog.h:308
static void analog_start_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:641
time_t guardtime
Definition: sig_analog.h:344
ast_channel_state
ast_channel states
Definition: channelstate.h:35
int(*const send_callerid)(void *pvt, int cwcid, struct ast_party_caller *caller)
Definition: sig_analog.h:181
void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub idx, struct ast_frame **dest)
Definition: sig_analog.c:1564
const char * analog_cidstart_to_str(enum analog_cid_start cid_start)
Definition: sig_analog.c:249
char * str
Subscriber name (Malloced)
Definition: channel.h:265
Definition: astman.c:222
const char *(*const get_orig_dialstring)(void *pvt)
Definition: sig_analog.h:245
#define ANALOG_MATCH_DIGIT_TIMEOUT
Default time (ms) to wait, in case of ambiguous match.
Definition: sig_analog.h:42
void(*const all_subchannels_hungup)(void *pvt)
Definition: sig_analog.h:213
unsigned int dialing
Definition: sig_analog.h:320
#define CID_SIG_BELL
Definition: callerid.h:59
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
struct ast_channel * ss_astchan
Definition: sig_analog.h:353
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
unsigned int usedistinctiveringdetection
Definition: sig_analog.h:294
unsigned int ast_callid
Definition: logger.h:87
unsigned int transfertobusy
Definition: sig_analog.h:292
static void analog_all_subchannels_hungup(struct analog_pvt *p)
Definition: sig_analog.c:553
#define RING_PATTERNS
Definition: sig_analog.h:35
static struct test_val c
Definition: muted.c:95
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:98
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define AST_OPTION_TDD
struct timeval flashtime
Definition: sig_analog.h:345
unsigned int allocd
Definition: sig_analog.h:261
const char * str
Definition: app_jack.c:147
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
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:4149
static void analog_publish_dnd_state(int channel, const char *status)
Definition: sig_analog.c:3999
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
ast_transfer_result
Definition: bridge.h:1115
unsigned int hidecallerid
Definition: sig_analog.h:323
#define AST_FRAME_DTMF
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:7522
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:164
static void analog_set_outgoing(struct analog_pvt *p, int is_outgoing)
Definition: sig_analog.c:537
int polarityonanswerdelay
Definition: sig_analog.h:309
int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp)
Definition: sig_analog.c:3981
static void analog_hangup_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:654
#define ast_verb(level,...)
Definition: logger.h:463
char echorest[20]
Definition: sig_analog.h:340
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:539
static int analog_wink(struct analog_pvt *p, enum analog_sub index)
Definition: sig_analog.c:676
#define ISTRUNK(p)
Definition: sig_analog.c:107
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:4194
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
struct ast_frame_subclass subclass
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:10675
unsigned int use_smdi
TRUE if SMDI (Simplified Message Desk Interface) is enabled.
Definition: sig_analog.h:299
struct analog_pvt * analog_new(enum analog_sigtype signallingtype, void *private_data)
Definition: sig_analog.c:3928
static int mute
Definition: chan_alsa.c:144
static int analog_get_sub_fd(struct analog_pvt *p, enum analog_sub sub)
Definition: sig_analog.c:1676
static const char * analog_get_orig_dialstring(struct analog_pvt *p)
Definition: sig_analog.c:186
Utility functions.
int(*const play_tone)(void *pvt, enum analog_sub sub, enum analog_tone tone)
Definition: sig_analog.h:175
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
Definition: channel.c:1166
unsigned int cancallforward
Definition: sig_analog.h:282
static void analog_set_waitingfordt(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:916
#define ast_strlen_zero(foo)
Definition: strings.h:52
void(*const set_polarity)(void *pvt, int value)
Set FXS line polarity to 0=IDLE NZ=REVERSED.
Definition: sig_analog.h:163
enum ast_cc_monitor_policies ast_get_cc_monitor_policy(struct ast_cc_config_params *config)
Get the cc_monitor_policy.
Definition: ccss.c:883
struct ast_channel * owner
Definition: sig_analog.h:270
Number structure.
Definition: app_followme.c:154
int(*const confmute)(void *pvt, int mute)
Definition: sig_analog.h:241
int ast_callid_threadassoc_add(ast_callid callid)
Adds a known callid to thread storage of the calling thread.
Definition: logger.c:1984
#define ANALOG_MAX_CID
Definition: sig_analog.h:33
#define gen_analog_field_callback(type, callback_name, def_value)
Definition: sig_analog.c:219
int(*const allocate_sub)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:195
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:1065
struct ast_party_id id
Caller party ID.
Definition: channel.h:421
int stripmsd
Definition: sig_analog.h:310
enum analog_sigtype sigtype
Definition: sig_analog.c:69
static void analog_unlock_private(struct analog_pvt *p)
Definition: sig_analog.c:560
#define EVENT_FLAG_SYSTEM
Definition: manager.h:71
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
int(*const check_for_conference)(void *pvt)
Definition: sig_analog.h:216
void *(*const get_sigpvt_bridged_channel)(struct ast_channel *chan)
Definition: sig_analog.h:228
static int analog_alloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition: sig_analog.c:368
void(*const handle_notify_message)(struct ast_channel *chan, void *pvt, int cid_flags, int neon_mwievent)
Definition: sig_analog.h:217
struct ast_party_id ani
Automatic Number Identification (ANI)
Definition: channel.h:428
int onhooktime
Definition: sig_analog.h:274
static void * __analog_ss_thread(void *data)
Definition: sig_analog.c:1711
void ast_channel_rings_set(struct ast_channel *chan, int value)
static int analog_dial_digits(struct analog_pvt *p, enum analog_sub sub, struct analog_dialoperation *dop)
Definition: sig_analog.c:521
void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
Set the source of the hangup in this channel and it&#39;s bridge.
Definition: channel.c:2504
const char * src
void(*const set_needringing)(void *pvt, int value)
Definition: sig_analog.h:161
int(*const conf_del)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:205
static void * analog_get_bridged_channel(struct ast_channel *chan)
Definition: sig_analog.c:1668
#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:911
int(*const get_sub_fd)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:229
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_publish_channel_alarm_clear(int channel)
Definition: sig_analog.c:2672
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
void(*const set_dialing)(void *pvt, int is_dialing)
Definition: sig_analog.h:232
void(*const deadlock_avoidance_private)(void *pvt)
Definition: sig_analog.h:142
void(*const set_callwaiting)(void *pvt, int callwaiting_enable)
Definition: sig_analog.h:239
struct ast_pbx * ast_channel_pbx(const struct ast_channel *chan)
int(*const start)(void *pvt)
Definition: sig_analog.h:154
#define AST_MAX_EXTENSION
Definition: channel.h:135
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:105
void ast_party_number_init(struct ast_party_number *init)
Initialize the given number structure.
Definition: channel.c:1644
Caller Party information.
Definition: channel.h:419
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#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:85
int ast_softhangup(struct ast_channel *chan, int reason)
Softly hangup up a channel.
Definition: channel.c:2476
static void analog_answer_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:647
static char analog_defaultcic[64]
Definition: sig_analog.c:65
int(*const train_echocanceller)(void *pvt)
Definition: sig_analog.h:178
static int analog_distinctive_ring(struct ast_channel *chan, struct analog_pvt *p, int idx, int *ringdata)
Definition: sig_analog.c:1649
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
int(*const dsp_reset_and_flush_digits)(void *pvt)
Definition: sig_analog.h:180
int analog_available(struct analog_pvt *p)
Definition: sig_analog.c:795
int(*const set_echocanceller)(void *pvt, int enable)
Definition: sig_analog.h:177
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:199
char callwait_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:334
#define AST_CAUSE_NO_ANSWER
Definition: causes.h:108
analog_sub
Definition: sig_analog.h:108
static int analog_stop_callwait(struct analog_pvt *p)
Definition: sig_analog.c:859
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
struct ast_frame * analog_exception(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:3555
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:4179
analog_cid_start
Definition: sig_analog.h:119
analog_dsp_digitmode
Definition: sig_analog.h:114
An SMDI message desk message.
Definition: smdi.h:65
int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
Queue a hold frame.
Definition: channel.c:1191
unsigned int dialednone
Definition: sig_analog.h:319
Core PBX routines and definitions.
void ast_party_number_free(struct ast_party_number *doomed)
Destroy the party number contents.
Definition: channel.c:1691
const char * analog_sigtype_to_str(enum analog_sigtype sigtype)
Definition: sig_analog.c:123
#define AST_CC_GENERIC_MONITOR_TYPE
Definition: ccss.h:489
int(*const have_progressdetect)(void *pvt)
Definition: sig_analog.h:246
char cid_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:313
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
char lastcid_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:337
static void analog_set_inthreeway(struct analog_pvt *p, enum analog_sub sub, int inthreeway)
Definition: sig_analog.c:979
void(*const increase_ss_count)(void)
Definition: sig_analog.h:220
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
static int analog_on_hook(struct analog_pvt *p)
Definition: sig_analog.c:529
#define CID_SIG_V23_JP
Definition: callerid.h:62
struct analog_dialoperation dop
Definition: sig_analog.h:273
int analog_ss_thread_start(struct analog_pvt *p, struct ast_channel *chan)
Definition: sig_analog.c:2665
enum analog_cid_start cid_start
Definition: sig_analog.h:311
#define LOG_ERROR
Definition: logger.h:285
static char * analog_event2str(enum analog_event event)
Definition: sig_analog.c:265
int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout)
Definition: sig_analog.c:987
int ast_pickup_call(struct ast_channel *chan)
Pickup a call.
Definition: pickup.c:200
unsigned int outgoing
Definition: sig_analog.h:324
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
int analog_config_complete(struct analog_pvt *p)
Definition: sig_analog.c:3963
int(*const unallocate_sub)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:196
void(*const set_cadence)(void *pvt, int *cidrings, struct ast_channel *chan)
Definition: sig_analog.h:230
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
enum analog_sigtype analog_str_to_sigtype(const char *name)
Definition: sig_analog.c:110
static char analog_defaultozz[64]
Definition: sig_analog.c:66
static int analog_dsp_reset_and_flush_digits(struct analog_pvt *p)
Definition: sig_analog.c:428
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition: main/utils.c:2033
void(*const set_new_owner)(void *pvt, struct ast_channel *new_owner)
Definition: sig_analog.h:243
static int analog_callwait(struct analog_pvt *p)
Definition: sig_analog.c:868
int(*const distinctive_ring)(struct ast_channel *chan, void *pvt, int idx, int *ringdata)
Definition: sig_analog.h:223
int analog_answer(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:1461
void ast_party_name_init(struct ast_party_name *init)
Initialize the given name structure.
Definition: channel.c:1591
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int ani2
Automatic Number Identification 2 (Info Digits)
Definition: channel.h:434
int errno
unsigned int callwaiting
Definition: sig_analog.h:318
#define CID_SIG_DTMF
Definition: callerid.h:61
void analog_free(struct analog_pvt *p)
Definition: sig_analog.c:3975
void analog_delete(struct analog_pvt *doomed)
Delete the analog private structure.
Definition: sig_analog.c:3958
void ast_party_name_free(struct ast_party_name *doomed)
Destroy the party name contents.
Definition: channel.c:1638
int(*const ring)(void *pvt)
Definition: sig_analog.h:155
int(*const off_hook)(void *pvt)
Set channel off hook.
Definition: sig_analog.h:160
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:669
void(*const unlock_private)(void *pvt)
Definition: sig_analog.h:138
unsigned int inthreeway
Definition: sig_analog.h:259
#define LOG_NOTICE
Definition: logger.h:263
char * origcid_num
Definition: sig_analog.h:348
int ast_softhangup_nolock(struct ast_channel *chan, int reason)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2463
static int analog_check_confirmanswer(struct analog_pvt *p)
Definition: sig_analog.c:939
long int flag
Definition: f2c.h:83
int(*const stop_cid_detect)(void *pvt)
Definition: sig_analog.h:187
int ast_parking_provider_registered(void)
Check whether a parking provider is registered.
Definition: parking.c:241
#define ast_channel_unlock(chan)
Definition: channel.h:2946
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
int whichwink
Definition: sig_analog.h:346
#define AST_CHANNEL_NAME
Definition: channel.h:172
enum analog_cid_start analog_str_to_cidstart(const char *value)
Definition: sig_analog.c:234
unsigned int dahditrcallerid
Definition: sig_analog.h:284
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2548
void(*const set_alarm)(void *pvt, int in_alarm)
Definition: sig_analog.h:231
static void analog_set_cadence(struct analog_pvt *p, struct ast_channel *chan)
Definition: sig_analog.c:885
int(*const set_linear_mode)(void *pvt, enum analog_sub sub, int linear_mode)
Definition: sig_analog.h:225
static int analog_is_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:489
int msgstate
-1 = unknown, 0 = no messages, 1 = new messages available
Definition: sig_analog.h:277
int(*const has_voicemail)(void *pvt)
Definition: sig_analog.h:215
static void analog_set_confirmanswer(struct analog_pvt *p, int flag)
Definition: sig_analog.c:932
char * origcid_name
Definition: sig_analog.h:349
unsigned int permhidecallerid
Definition: sig_analog.h:288
static void analog_set_callwaiting(struct analog_pvt *p, int callwaiting_enable)
Definition: sig_analog.c:877
static int analog_has_voicemail(struct analog_pvt *p)
Definition: sig_analog.c:684
static void analog_deadlock_avoidance_private(struct analog_pvt *p)
Definition: sig_analog.c:574
unsigned int dnd
Definition: sig_analog.h:321
static void analog_set_pulsedial(struct analog_pvt *p, int flag)
Definition: sig_analog.c:963
#define ast_clear_flag(p, flag)
Definition: utils.h:77
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:165
void(*const set_pulsedial)(void *pvt, int flag)
Definition: sig_analog.h:242
struct ast_bridge_channel * ast_channel_get_bridge_channel(struct ast_channel *chan)
Get a reference to the channel&#39;s bridge pointer.
Definition: channel.c:10783
struct timeval delivery
int(*const wait_event)(void *pvt)
Definition: sig_analog.h:150
static int analog_confmute(struct analog_pvt *p, int mute)
Definition: sig_analog.c:955
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
unsigned int analog_str_to_cidtype(const char *name)
Definition: sig_analog.c:136
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...
static int analog_wait_event(struct analog_pvt *p)
Definition: sig_analog.c:202
static int analog_check_waitingfordt(struct analog_pvt *p)
Definition: sig_analog.c:923
#define ANALOG_NEED_MFDETECT(p)
Definition: sig_analog.c:1684
struct ast_frame ast_null_frame
Definition: main/frame.c:79
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3184
void(*const lock_private)(void *pvt)
Definition: sig_analog.h:140
static void analog_set_needringing(struct analog_pvt *p, int value)
Definition: sig_analog.c:625
int ast_channel_fd(const struct ast_channel *chan, int which)
#define ANALOG_FIRST_DIGIT_TIMEOUT
Default time (ms) to detect first digit.
Definition: sig_analog.h:38
char call_forward[AST_MAX_EXTENSION]
Definition: sig_analog.h:350
Structure that contains information regarding a channel in a bridge.
char * strsep(char **str, const char *delims)
int cidrings
Definition: sig_analog.h:339
static void analog_lock_private(struct analog_pvt *p)
Definition: sig_analog.c:567
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2970
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3171
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static int analog_set_echocanceller(struct analog_pvt *p, int enable)
Definition: sig_analog.c:473
void(*const set_confirmanswer)(void *pvt, int flag)
Definition: sig_analog.h:237
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
unsigned int callwaitingcallerid
Definition: sig_analog.h:295
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
Definition: time.h:226
int(*const check_waitingfordt)(void *pvt)
Definition: sig_analog.h:236
static int analog_is_dialing(struct analog_pvt *p, enum analog_sub index)
Definition: sig_analog.c:692
const char * ast_channel_name(const struct ast_channel *chan)
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1776
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:2020
char lastcid_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:336
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7486
#define ast_frfree(fr)
static int analog_my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms)
Definition: sig_analog.c:1606
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:1238
Interface header for analog signaling module.
enum ast_pbx_result ast_pbx_run(struct ast_channel *c)
Execute the PBX in the current thread.
Definition: pbx.c:4759
static int analog_attempt_transfer(struct analog_pvt *p)
Definition: sig_analog.c:712
static void analog_increase_ss_count(void)
Definition: sig_analog.c:1635
static int analog_have_progressdetect(struct analog_pvt *p)
Definition: sig_analog.c:210
struct stasis_forward * sub
Definition: res_corosync.c:240
#define MIN_MS_SINCE_FLASH
Definition: sig_analog.c:64
static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
Definition: sig_analog.c:446
Data structure associated with a single frame of data.
Internal Asterisk hangup causes.
static void analog_decrease_ss_count(void)
Definition: sig_analog.c:1642
const char * ast_channel_language(const struct ast_channel *chan)
#define ANALOG_INTER_DIGIT_TIMEOUT
Default time (ms) to detect following digits.
Definition: sig_analog.h:40
enum analog_sigtype outsigmod
Definition: sig_analog.h:306
unsigned int inalarm
Definition: sig_analog.h:325
Abstract JSON element (object, array, string, int, ...).
static const struct @162 sigtypes[]
int fxsoffhookstate
Definition: sig_analog.h:275
Options provided by main asterisk program.
static void analog_cancel_cidspill(struct analog_pvt *p)
Definition: sig_analog.c:948
#define AST_OPTION_TONE_VERIFY
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
Definition: sig_analog.h:332
struct ast_frame f
Definition: sig_analog.h:258
static struct test_val b
const char * ast_channel_context(const struct ast_channel *chan)
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: main/db.c:327
union ast_frame::@263 data
int(*const get_event)(void *pvt)
Definition: sig_analog.h:149
enum ast_frame_type frametype
static int analog_update_conf(struct analog_pvt *p)
Definition: sig_analog.c:745
unsigned int pulse
Definition: sig_analog.h:289
void(*const set_inthreeway)(void *pvt, enum analog_sub sub, int inthreeway)
Definition: sig_analog.h:226
char x
Definition: extconf.c:81
#define ast_channel_trylock(chan)
Definition: channel.h:2947
int ast_channel_rings(const struct ast_channel *chan)
const char * analog_cidtype_to_str(unsigned int cid_type)
Definition: sig_analog.c:149
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:200
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:280
Call Parking and Pickup API Includes code and algorithms from the Zapata library. ...
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
unsigned int transfer
Definition: sig_analog.h:291
struct analog_subchannel subs[3]
Definition: sig_analog.h:272
const char * name
Definition: sig_analog.c:70
void(*const set_ringtimeout)(void *pvt, int ringt)
Definition: sig_analog.h:234
void callerid_get_dtmf(char *cidstring, char *number, int *flags)
Get and parse DTMF-based callerid.
Definition: callerid.c:201
static void analog_get_and_handle_alarms(struct analog_pvt *p)
Definition: sig_analog.c:1661
unsigned int hanguponpolarityswitch
Definition: sig_analog.h:285
static int analog_canmatch_featurecode(const char *pickupexten, const char *exten)
Definition: sig_analog.c:1686
void(*const set_outgoing)(void *pvt, int is_outgoing)
Definition: sig_analog.h:233
int(*const stop_callwait)(void *pvt)
Definition: sig_analog.h:192
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()&#39;s, .&#39;s, and -&#39;s...
Definition: callerid.c:947
int(*const dsp_set_digitmode)(void *pvt, enum analog_dsp_digitmode mode)
Definition: sig_analog.h:179
static int analog_flash(struct analog_pvt *p)
Definition: sig_analog.c:505
Say numbers and dates (maybe words one day too)
void * chan_pvt
Definition: sig_analog.h:268
static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
Definition: sig_analog.c:908
Bridging API.
static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
Definition: sig_analog.c:892
unsigned int canpark
Definition: sig_analog.h:283
static int analog_dsp_set_digitmode(struct analog_pvt *p, enum analog_dsp_digitmode mode)
Definition: sig_analog.c:661
void(*const cancel_cidspill)(void *pvt)
Definition: sig_analog.h:240
int(*const complete_conference_update)(void *pvt, int needconf)
Definition: sig_analog.h:209
enum analog_sigtype sig
Definition: sig_analog.h:266
Persistant data storage (akin to *doze registry)
unsigned int echobreak
Definition: sig_analog.h:322
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:298
int analog_dnd(struct analog_pvt *p, int flag)
Definition: sig_analog.c:4019
ast_callid ast_channel_callid(const struct ast_channel *chan)
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:4391
static void analog_set_alarm(struct analog_pvt *p, int in_alarm)
Definition: sig_analog.c:900
struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor)
Definition: sig_analog.c:772
int(*const flash)(void *pvt)
Definition: sig_analog.h:156
static int analog_ring(struct analog_pvt *p)
Definition: sig_analog.c:497
unsigned int permcallwaiting
Definition: sig_analog.h:287
void(*const decrease_ss_count)(void)
Definition: sig_analog.h:221
void(*const set_waitingfordt)(void *pvt, struct ast_channel *ast)
Definition: sig_analog.h:235
unsigned int cid_type
Definition: sig_analog.c:96
int(*const callwait)(void *pvt)
Definition: sig_analog.h:190
jack_status_t status
Definition: app_jack.c:146
void ast_manager_publish_event(const char *type, int class_type, struct ast_json *obj)
Publish an event to AMI.
Definition: manager.c:1903
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620
unsigned int answeronpolarityswitch
Definition: sig_analog.h:280
Configuration relating to call pickup.
#define CID_SIG_V23
Definition: callerid.h:60
int(*const get_callerid)(void *pvt, char *name, char *num, enum analog_event *ev, size_t timeout)
Definition: sig_analog.h:183
static struct test_val a
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:343