Asterisk - The Open Source Telephony Project  GIT-master-a24979a
Macros | Functions | Variables
sig_analog.c File Reference

Analog signaling module. More...

#include "asterisk.h"
#include <errno.h>
#include <ctype.h>
#include "asterisk/utils.h"
#include "asterisk/options.h"
#include "asterisk/pickup.h"
#include "asterisk/pbx.h"
#include "asterisk/file.h"
#include "asterisk/callerid.h"
#include "asterisk/say.h"
#include "asterisk/manager.h"
#include "asterisk/astdb.h"
#include "asterisk/features.h"
#include "asterisk/causes.h"
#include "asterisk/features_config.h"
#include "asterisk/bridge.h"
#include "asterisk/parking.h"
#include "sig_analog.h"
Include dependency graph for sig_analog.c:

Go to the source code of this file.

Macros

#define analog_get_index(ast, p, nullok)   _analog_get_index(ast, p, nullok, __PRETTY_FUNCTION__, __LINE__)
 
#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))
 
#define gen_analog_field_callback(type, callback_name, def_value)
 
#define ISTRUNK(p)
 
#define MIN_MS_SINCE_FLASH   ( (2000) )
 
#define POLARITY_IDLE   0
 
#define POLARITY_REV   1
 

Functions

static struct ast_frame__analog_handle_event (struct analog_pvt *p, struct ast_channel *ast)
 
static void * __analog_ss_thread (void *data)
 
static int _analog_get_index (struct ast_channel *ast, struct analog_pvt *p, int nullok, const char *fname, unsigned long line)
 
static void analog_all_subchannels_hungup (struct analog_pvt *p)
 
static int analog_alloc_sub (struct analog_pvt *p, enum analog_sub x)
 
int analog_answer (struct analog_pvt *p, struct ast_channel *ast)
 
static void analog_answer_polarityswitch (struct analog_pvt *p)
 
static int analog_attempt_transfer (struct analog_pvt *p)
 
int analog_available (struct analog_pvt *p)
 
int analog_call (struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout)
 
static int analog_callwait (struct analog_pvt *p)
 
static void analog_cancel_cidspill (struct analog_pvt *p)
 
static int analog_canmatch_featurecode (const char *pickupexten, const char *exten)
 
static void analog_cb_handle_dtmf (struct analog_pvt *p, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
 
static int analog_check_confirmanswer (struct analog_pvt *p)
 
static int analog_check_for_conference (struct analog_pvt *p)
 
static int analog_check_waitingfordt (struct analog_pvt *p)
 
const char * analog_cidstart_to_str (enum analog_cid_start cid_start)
 
const char * analog_cidtype_to_str (unsigned int cid_type)
 
int analog_config_complete (struct analog_pvt *p)
 
static int analog_confmute (struct analog_pvt *p, int mute)
 
static void analog_deadlock_avoidance_private (struct analog_pvt *p)
 
static void analog_decrease_ss_count (void)
 
void analog_delete (struct analog_pvt *doomed)
 Delete the analog private structure. More...
 
static int analog_dial_digits (struct analog_pvt *p, enum analog_sub sub, struct analog_dialoperation *dop)
 
static int analog_distinctive_ring (struct ast_channel *chan, struct analog_pvt *p, int idx, int *ringdata)
 
int analog_dnd (struct analog_pvt *p, int flag)
 
static int analog_dsp_reset_and_flush_digits (struct analog_pvt *p)
 
static int analog_dsp_set_digitmode (struct analog_pvt *p, enum analog_dsp_digitmode mode)
 
static char * analog_event2str (enum analog_event event)
 
struct ast_frameanalog_exception (struct analog_pvt *p, struct ast_channel *ast)
 
int analog_fixup (struct ast_channel *oldchan, struct ast_channel *newchan, void *newp)
 
static int analog_flash (struct analog_pvt *p)
 
void analog_free (struct analog_pvt *p)
 
static void analog_get_and_handle_alarms (struct analog_pvt *p)
 
static void * analog_get_bridged_channel (struct ast_channel *chan)
 
static int analog_get_callerid (struct analog_pvt *p, char *name, char *number, enum analog_event *ev, size_t timeout)
 
static int analog_get_event (struct analog_pvt *p)
 
static const char * analog_get_orig_dialstring (struct analog_pvt *p)
 
static int analog_get_sub_fd (struct analog_pvt *p, enum analog_sub sub)
 
void analog_handle_dtmf (struct analog_pvt *p, struct ast_channel *ast, enum analog_sub idx, struct ast_frame **dest)
 
void * analog_handle_init_event (struct analog_pvt *i, int event)
 
static int analog_handle_notify_message (struct ast_channel *chan, struct analog_pvt *p, int cid_flags, int neon_mwievent)
 
static int analog_handles_digit (struct ast_frame *f)
 
int analog_hangup (struct analog_pvt *p, struct ast_channel *ast)
 
static void analog_hangup_polarityswitch (struct analog_pvt *p)
 
static int analog_has_voicemail (struct analog_pvt *p)
 
static int analog_have_progressdetect (struct analog_pvt *p)
 
static void analog_increase_ss_count (void)
 
static int analog_is_dialing (struct analog_pvt *p, enum analog_sub index)
 
static int analog_is_off_hook (struct analog_pvt *p)
 
static void analog_lock_private (struct analog_pvt *p)
 
static void analog_lock_sub_owner (struct analog_pvt *pvt, enum analog_sub sub_idx)
 
static int analog_my_getsigstr (struct ast_channel *chan, char *str, const char *term, int ms)
 
struct analog_pvtanalog_new (enum analog_sigtype signallingtype, void *private_data)
 
static struct ast_channelanalog_new_ast_channel (struct analog_pvt *p, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
 
static int analog_off_hook (struct analog_pvt *p)
 
static int analog_on_hook (struct analog_pvt *p)
 
static int analog_play_tone (struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
 
static void analog_publish_channel_alarm_clear (int channel)
 
static void analog_publish_dnd_state (int channel, const char *status)
 
struct ast_channelanalog_request (struct analog_pvt *p, int *callwait, const struct ast_channel *requestor)
 
static int analog_ring (struct analog_pvt *p)
 
static int analog_send_callerid (struct analog_pvt *p, int cwcid, struct ast_party_caller *caller)
 
static void analog_set_alarm (struct analog_pvt *p, int in_alarm)
 
static void analog_set_cadence (struct analog_pvt *p, struct ast_channel *chan)
 
static void analog_set_callwaiting (struct analog_pvt *p, int callwaiting_enable)
 
static void analog_set_confirmanswer (struct analog_pvt *p, int flag)
 
static void analog_set_dialing (struct analog_pvt *p, int is_dialing)
 
static int analog_set_echocanceller (struct analog_pvt *p, int enable)
 
static void analog_set_inthreeway (struct analog_pvt *p, enum analog_sub sub, int inthreeway)
 
static int analog_set_linear_mode (struct analog_pvt *p, enum analog_sub sub, int linear_mode)
 
static void analog_set_needringing (struct analog_pvt *p, int value)
 
static void analog_set_new_owner (struct analog_pvt *p, struct ast_channel *new_owner)
 
static void analog_set_outgoing (struct analog_pvt *p, int is_outgoing)
 
static void analog_set_pulsedial (struct analog_pvt *p, int flag)
 
static void analog_set_ringtimeout (struct analog_pvt *p, int ringt)
 
static void analog_set_waitingfordt (struct analog_pvt *p, struct ast_channel *ast)
 
const char * analog_sigtype_to_str (enum analog_sigtype sigtype)
 
int analog_ss_thread_start (struct analog_pvt *p, struct ast_channel *chan)
 
static int analog_start (struct analog_pvt *p)
 
static int analog_start_cid_detect (struct analog_pvt *p, int cid_signalling)
 
static void analog_start_polarityswitch (struct analog_pvt *p)
 
static int analog_stop_callwait (struct analog_pvt *p)
 
static int analog_stop_cid_detect (struct analog_pvt *p)
 
enum analog_cid_start analog_str_to_cidstart (const char *value)
 
unsigned int analog_str_to_cidtype (const char *name)
 
enum analog_sigtype analog_str_to_sigtype (const char *name)
 
static void analog_swap_subs (struct analog_pvt *p, enum analog_sub a, enum analog_sub b)
 
static int analog_train_echocanceller (struct analog_pvt *p)
 
static int analog_unalloc_sub (struct analog_pvt *p, enum analog_sub x)
 
static void analog_unlock_private (struct analog_pvt *p)
 
static int analog_update_conf (struct analog_pvt *p)
 
static int analog_wait_event (struct analog_pvt *p)
 
static int analog_wink (struct analog_pvt *p, enum analog_sub index)
 
 gen_analog_field_callback (int, firstdigit_timeout, ANALOG_FIRST_DIGIT_TIMEOUT)
 
 gen_analog_field_callback (int, interdigit_timeout, ANALOG_INTER_DIGIT_TIMEOUT)
 
 gen_analog_field_callback (int, matchdigit_timeout, ANALOG_MATCH_DIGIT_TIMEOUT)
 

Variables

static char analog_defaultcic [64] = ""
 
static char analog_defaultozz [64] = ""
 
struct {
   unsigned int   cid_type
 
   const char *   name
 
cidtypes []
 
struct {
   const char *   name
 
   enum analog_sigtype   sigtype
 
sigtypes []
 

Detailed Description

Analog signaling module.

Author
Matthew Fredrickson cresl.nosp@m.in@d.nosp@m.igium.nosp@m..com

Definition in file sig_analog.c.

Macro Definition Documentation

◆ analog_get_index

#define analog_get_index (   ast,
  p,
  nullok 
)    _analog_get_index(ast, p, nullok, __PRETTY_FUNCTION__, __LINE__)

Definition at line 407 of file sig_analog.c.

◆ ANALOG_NEED_MFDETECT

#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))

Definition at line 1686 of file sig_analog.c.

◆ gen_analog_field_callback

#define gen_analog_field_callback (   type,
  callback_name,
  def_value 
)

Definition at line 219 of file sig_analog.c.

◆ ISTRUNK

#define ISTRUNK (   p)
Value:
((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || \
(p->sig == ANALOG_SIG_FXSGS))
@ ANALOG_SIG_FXSLS
Definition: sig_analog.h:50
@ ANALOG_SIG_FXSGS
Definition: sig_analog.h:52
@ ANALOG_SIG_FXSKS
Definition: sig_analog.h:51

Definition at line 107 of file sig_analog.c.

◆ MIN_MS_SINCE_FLASH

#define MIN_MS_SINCE_FLASH   ( (2000) )

2000 ms

Definition at line 64 of file sig_analog.c.

◆ POLARITY_IDLE

#define POLARITY_IDLE   0
Note
Define if you want to check the hook state for an FXO (FXS signalled) interface before dialing on it. Certain FXO interfaces always think they're out of service with this method however.

Definition at line 62 of file sig_analog.c.

◆ POLARITY_REV

#define POLARITY_REV   1

Definition at line 63 of file sig_analog.c.

Function Documentation

◆ __analog_handle_event()

static struct ast_frame* __analog_handle_event ( struct analog_pvt p,
struct ast_channel ast 
)
static

< Digits (or equivalent) have been dialed

< Remote end is ringing

< Line is up

< Line is ringing

< Channel is down and available

< Channel is down, but reserved

< Channel is off hook

< Line is busy

< Digits (or equivalent) have been dialed while offhook

< Channel has detected an incoming call and is waiting for ring

< Digits (or equivalent) have been dialed

< Remote end is ringing

< Line is up

< Line is ringing

Definition at line 2729 of file sig_analog.c.

2730 {
2731  int res, x;
2732  int mysig;
2733  int idx;
2734  char *c;
2735  pthread_t threadid;
2736  struct ast_channel *chan;
2737  struct ast_frame *f;
2738  struct ast_control_pvt_cause_code *cause_code = NULL;
2739  int data_size = sizeof(*cause_code);
2740  char *subclass = NULL;
2741 
2742  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
2743 
2744  idx = analog_get_index(ast, p, 0);
2745  if (idx < 0) {
2746  return &ast_null_frame;
2747  }
2748  if (idx != ANALOG_SUB_REAL) {
2749  ast_log(LOG_ERROR, "We got an event on a non real sub. Fix it!\n");
2750  }
2751 
2752  mysig = p->sig;
2753  if (p->outsigmod > -1) {
2754  mysig = p->outsigmod;
2755  }
2756 
2757  p->subs[idx].f.frametype = AST_FRAME_NULL;
2758  p->subs[idx].f.subclass.integer = 0;
2759  p->subs[idx].f.datalen = 0;
2760  p->subs[idx].f.samples = 0;
2761  p->subs[idx].f.mallocd = 0;
2762  p->subs[idx].f.offset = 0;
2763  p->subs[idx].f.src = "dahdi_handle_event";
2764  p->subs[idx].f.data.ptr = NULL;
2765  f = &p->subs[idx].f;
2766 
2767  res = analog_get_event(p);
2768 
2769  ast_debug(1, "Got event %s(%d) on channel %d (index %u)\n", analog_event2str(res), res, p->channel, idx);
2770 
2772  analog_set_pulsedial(p, (res & ANALOG_EVENT_PULSEDIGIT) ? 1 : 0);
2773  ast_debug(1, "Detected %sdigit '%c'\n", (res & ANALOG_EVENT_PULSEDIGIT) ? "pulse ": "", res & 0xff);
2774  analog_confmute(p, 0);
2775  p->subs[idx].f.frametype = AST_FRAME_DTMF_END;
2776  p->subs[idx].f.subclass.integer = res & 0xff;
2777  analog_handle_dtmf(p, ast, idx, &f);
2778  return f;
2779  }
2780 
2781  if (res & ANALOG_EVENT_DTMFDOWN) {
2782  ast_debug(1, "DTMF Down '%c'\n", res & 0xff);
2783  /* Mute conference */
2784  analog_confmute(p, 1);
2786  p->subs[idx].f.subclass.integer = res & 0xff;
2787  analog_handle_dtmf(p, ast, idx, &f);
2788  return f;
2789  }
2790 
2791  switch (res) {
2792  case ANALOG_EVENT_ALARM:
2793  case ANALOG_EVENT_POLARITY:
2794  case ANALOG_EVENT_ONHOOK:
2795  /* add length of "ANALOG " */
2796  data_size += 7;
2797  subclass = analog_event2str(res);
2798  data_size += strlen(subclass);
2799  cause_code = ast_alloca(data_size);
2800  memset(cause_code, 0, data_size);
2801  cause_code->ast_cause = AST_CAUSE_NORMAL_CLEARING;
2803  snprintf(cause_code->code, data_size - sizeof(*cause_code) + 1, "ANALOG %s", subclass);
2804  break;
2805  default:
2806  break;
2807  }
2808 
2809  switch (res) {
2811  ast_verb(3, "Channel %d echo canceler disabled due to CED detection\n", p->channel);
2813  break;
2814 #ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
2816  ast_verb(3, "Channel %d detected a CED tone towards the network.\n", p->channel);
2817  break;
2819  ast_verb(3, "Channel %d detected a CED tone from the network.\n", p->channel);
2820  break;
2822  ast_verb(3, "Channel %d echo canceler disabled its NLP.\n", p->channel);
2823  break;
2825  ast_verb(3, "Channel %d echo canceler enabled its NLP.\n", p->channel);
2826  break;
2827 #endif
2829  /* Stop tone if there's a pulse start and the PBX isn't started */
2830  if (!ast_channel_pbx(ast))
2832  break;
2834  if (p->inalarm) {
2835  break;
2836  }
2837  x = analog_is_dialing(p, idx);
2838  if (!x) { /* if not still dialing in driver */
2840  if (p->echobreak) {
2842  ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr));
2845  p->echobreak = 0;
2846  } else {
2847  analog_set_dialing(p, 0);
2848  if ((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) {
2849  /* if thru with dialing after offhook */
2851  ast_setstate(ast, AST_STATE_UP);
2852  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
2854  break;
2855  } else { /* if to state wait for offhook to dial rest */
2856  /* we now wait for off hook */
2858  }
2859  }
2860  if (ast_channel_state(ast) == AST_STATE_DIALING) {
2861  if (analog_have_progressdetect(p)) {
2862  ast_debug(1, "Done dialing, but waiting for progress detection before doing more...\n");
2863  } else if (analog_check_confirmanswer(p) || (!p->dialednone
2864  && ((mysig == ANALOG_SIG_EM) || (mysig == ANALOG_SIG_EM_E1)
2865  || (mysig == ANALOG_SIG_EMWINK) || (mysig == ANALOG_SIG_FEATD)
2866  || (mysig == ANALOG_SIG_FEATDMF_TA) || (mysig == ANALOG_SIG_FEATDMF)
2867  || (mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA)
2868  || (mysig == ANALOG_SIG_FGC_CAMAMF) || (mysig == ANALOG_SIG_FEATB)
2869  || (mysig == ANALOG_SIG_SF) || (mysig == ANALOG_SIG_SFWINK)
2870  || (mysig == ANALOG_SIG_SF_FEATD) || (mysig == ANALOG_SIG_SF_FEATDMF)
2871  || (mysig == ANALOG_SIG_SF_FEATB)))) {
2873  } else if (!p->answeronpolarityswitch) {
2874  ast_setstate(ast, AST_STATE_UP);
2875  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
2877  /* If aops=0 and hops=1, this is necessary */
2878  p->polarity = POLARITY_REV;
2879  } else {
2880  /* Start clean, so we can catch the change to REV polarity when party answers */
2881  p->polarity = POLARITY_IDLE;
2882  }
2883  }
2884  }
2885  }
2886  break;
2887  case ANALOG_EVENT_ALARM:
2888  analog_set_alarm(p, 1);
2891  case ANALOG_EVENT_ONHOOK:
2892  ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
2893  ast_channel_hangupcause_hash_set(ast, cause_code, data_size);
2894  switch (p->sig) {
2895  case ANALOG_SIG_FXOLS:
2896  case ANALOG_SIG_FXOGS:
2897  case ANALOG_SIG_FXOKS:
2899  p->fxsoffhookstate = 0;
2900  p->onhooktime = time(NULL);
2901  p->msgstate = -1;
2902  /* Check for some special conditions regarding call waiting */
2903  if (idx == ANALOG_SUB_REAL) {
2904  /* The normal line was hung up */
2905  if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
2906  /* Need to hold the lock for real-call, private, and call-waiting call */
2908  if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
2909  /*
2910  * The call waiting call dissappeared.
2911  * This is now a normal hangup.
2912  */
2914  return NULL;
2915  }
2916 
2917  /* There's a call waiting call, so ring the phone, but make it unowned in the mean time */
2919  ast_verb(3, "Channel %d still has (callwait) call, ringing phone\n", p->channel);
2923  /* Don't start streaming audio yet if the incoming call isn't up yet */
2925  analog_set_dialing(p, 1);
2926  }
2927  /* Unlock the call-waiting call that we swapped to real-call. */
2929  analog_ring(p);
2930  } else if (p->subs[ANALOG_SUB_THREEWAY].owner) {
2931  unsigned int mssinceflash;
2932 
2933  /* Need to hold the lock for real-call, private, and 3-way call */
2935  if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
2936  ast_log(LOG_NOTICE, "Whoa, threeway disappeared kinda randomly.\n");
2937  /* Just hangup */
2938  return NULL;
2939  }
2940  if (p->owner != ast) {
2942  ast_log(LOG_WARNING, "This isn't good...\n");
2943  /* Just hangup */
2944  return NULL;
2945  }
2946 
2947  mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
2948  ast_debug(1, "Last flash was %u ms ago\n", mssinceflash);
2949  if (mssinceflash < MIN_MS_SINCE_FLASH) {
2950  /* It hasn't been long enough since the last flashook. This is probably a bounce on
2951  hanging up. Hangup both channels now */
2952  ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel);
2956  } else if ((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) {
2957  if (p->transfer) {
2958  /* In any case this isn't a threeway call anymore */
2961 
2962  /* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */
2963  if (!p->transfertobusy && ast_channel_state(ast) == AST_STATE_BUSY) {
2964  /* Swap subs and dis-own channel */
2966  /* Unlock the 3-way call that we swapped to real-call. */
2969  /* Ring the phone */
2970  analog_ring(p);
2971  } else if (!analog_attempt_transfer(p)) {
2972  /*
2973  * Transfer successful. Don't actually hang up at this point.
2974  * Let our channel legs of the calls die off as the transfer
2975  * percolates through the core.
2976  */
2977  break;
2978  }
2979  } else {
2982  }
2983  } else {
2984  /* Swap subs and dis-own channel */
2986  /* Unlock the 3-way call that we swapped to real-call. */
2989  /* Ring the phone */
2990  analog_ring(p);
2991  }
2992  }
2993  } else {
2994  ast_log(LOG_WARNING, "Got a hangup and my index is %u?\n", idx);
2995  }
2996  /* Fall through */
2997  default:
2999  return NULL;
3000  }
3001  break;
3003  if (p->inalarm) {
3004  break;
3005  }
3006  /* for E911, its supposed to wait for offhook then dial
3007  the second half of the dial string */
3008  if (((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) && (ast_channel_state(ast) == AST_STATE_DIALING_OFFHOOK)) {
3009  c = strchr(p->dialdest, '/');
3010  if (c) {
3011  c++;
3012  } else {
3013  c = p->dialdest;
3014  }
3015 
3016  if (*c) {
3017  int numchars = snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
3018  if (numchars >= sizeof(p->dop.dialstr)) {
3019  ast_log(LOG_WARNING, "Dial string '%s' truncated\n", c);
3020  }
3021  } else {
3022  ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
3023  }
3024 
3025  if (strlen(p->dop.dialstr) > 4) {
3026  memset(p->echorest, 'w', sizeof(p->echorest) - 1);
3027  strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
3028  p->echorest[sizeof(p->echorest) - 1] = '\0';
3029  p->echobreak = 1;
3030  p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
3031  } else {
3032  p->echobreak = 0;
3033  }
3034  if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
3035  analog_on_hook(p);
3036  return NULL;
3037  }
3038  analog_set_dialing(p, 1);
3039  return &p->subs[idx].f;
3040  }
3041  switch (p->sig) {
3042  case ANALOG_SIG_FXOLS:
3043  case ANALOG_SIG_FXOGS:
3044  case ANALOG_SIG_FXOKS:
3045  p->fxsoffhookstate = 1;
3046  switch (ast_channel_state(ast)) {
3047  case AST_STATE_RINGING:
3050  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
3052  /* Make sure it stops ringing */
3053  analog_set_needringing(p, 0);
3054  analog_off_hook(p);
3055  ast_debug(1, "channel %d answered\n", p->channel);
3056 
3057  /* Cancel any running CallerID spill */
3059 
3060  analog_set_dialing(p, 0);
3061  p->callwaitcas = 0;
3062  if (analog_check_confirmanswer(p)) {
3063  /* Ignore answer if "confirm answer" is enabled */
3064  p->subs[idx].f.frametype = AST_FRAME_NULL;
3065  p->subs[idx].f.subclass.integer = 0;
3066  } else if (!ast_strlen_zero(p->dop.dialstr)) {
3067  /* nick@dccinc.com 4/3/03 - fxo should be able to do deferred dialing */
3068  res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3069  if (res) {
3070  p->dop.dialstr[0] = '\0';
3071  return NULL;
3072  } else {
3073  ast_debug(1, "Sent FXO deferred digit string: %s\n", p->dop.dialstr);
3074  p->subs[idx].f.frametype = AST_FRAME_NULL;
3075  p->subs[idx].f.subclass.integer = 0;
3076  analog_set_dialing(p, 1);
3077  }
3078  p->dop.dialstr[0] = '\0';
3080  } else {
3081  ast_setstate(ast, AST_STATE_UP);
3083  }
3084  return &p->subs[idx].f;
3085  case AST_STATE_DOWN:
3087  ast_channel_rings_set(ast, 1);
3088  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
3090  ast_debug(1, "channel %d picked up\n", p->channel);
3091  return &p->subs[idx].f;
3092  case AST_STATE_UP:
3093  /* Make sure it stops ringing */
3094  analog_off_hook(p);
3095  /* Okay -- probably call waiting */
3096  ast_queue_unhold(p->owner);
3097  break;
3098  case AST_STATE_RESERVED:
3099  /* Start up dialtone */
3100  if (analog_has_voicemail(p)) {
3102  } else {
3104  }
3105  break;
3106  default:
3107  ast_log(LOG_WARNING, "FXO phone off hook in weird state %u??\n", ast_channel_state(ast));
3108  }
3109  break;
3110  case ANALOG_SIG_FXSLS:
3111  case ANALOG_SIG_FXSGS:
3112  case ANALOG_SIG_FXSKS:
3113  if (ast_channel_state(ast) == AST_STATE_RING) {
3115  }
3116 
3117  /* Fall through */
3118  case ANALOG_SIG_EM:
3119  case ANALOG_SIG_EM_E1:
3120  case ANALOG_SIG_EMWINK:
3121  case ANALOG_SIG_FEATD:
3122  case ANALOG_SIG_FEATDMF:
3123  case ANALOG_SIG_FEATDMF_TA:
3124  case ANALOG_SIG_E911:
3125  case ANALOG_SIG_FGC_CAMA:
3126  case ANALOG_SIG_FGC_CAMAMF:
3127  case ANALOG_SIG_FEATB:
3128  case ANALOG_SIG_SF:
3129  case ANALOG_SIG_SFWINK:
3130  case ANALOG_SIG_SF_FEATD:
3131  case ANALOG_SIG_SF_FEATDMF:
3132  case ANALOG_SIG_SF_FEATB:
3133  switch (ast_channel_state(ast)) {
3134  case AST_STATE_PRERING:
3136  /* Fall through */
3137  case AST_STATE_DOWN:
3138  case AST_STATE_RING:
3139  ast_debug(1, "Ring detected\n");
3140  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
3142  break;
3143  case AST_STATE_RINGING:
3144  case AST_STATE_DIALING:
3145  if (p->outgoing) {
3146  ast_debug(1, "Line answered\n");
3147  if (analog_check_confirmanswer(p)) {
3148  p->subs[idx].f.frametype = AST_FRAME_NULL;
3149  p->subs[idx].f.subclass.integer = 0;
3150  } else {
3151  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
3153  ast_setstate(ast, AST_STATE_UP);
3154  }
3155  break;
3156  }
3157  /* Fall through */
3158  default:
3159  ast_log(LOG_WARNING, "Ring/Off-hook in strange state %u on channel %d\n", ast_channel_state(ast), p->channel);
3160  break;
3161  }
3162  break;
3163  default:
3164  ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3165  break;
3166  }
3167  break;
3169  switch (p->sig) {
3170  case ANALOG_SIG_FXSLS:
3171  case ANALOG_SIG_FXSGS:
3172  case ANALOG_SIG_FXSKS:
3173  if (ast_channel_state(ast) == AST_STATE_RING) {
3175  }
3176  break;
3177  default:
3178  break;
3179  }
3180  break;
3182  if (p->inalarm) break;
3184  if (ast_channel_rings(ast) == p->cidrings) {
3185  analog_send_callerid(p, 0, &p->caller);
3186  }
3187 
3188  if (ast_channel_rings(ast) > p->cidrings) {
3190  p->callwaitcas = 0;
3191  }
3192  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
3194  break;
3195  case ANALOG_EVENT_RINGERON:
3196  break;
3197  case ANALOG_EVENT_NOALARM:
3198  analog_set_alarm(p, 0);
3200  break;
3202  if (p->inalarm) {
3203  break;
3204  }
3205  /* Remember last time we got a flash-hook */
3206  gettimeofday(&p->flashtime, NULL);
3207  switch (mysig) {
3208  case ANALOG_SIG_FXOLS:
3209  case ANALOG_SIG_FXOGS:
3210  case ANALOG_SIG_FXOKS:
3211  ast_debug(1, "Winkflash, index: %u, normal: %d, callwait: %d, thirdcall: %d\n",
3213 
3214  /* Cancel any running CallerID spill */
3216  p->callwaitcas = 0;
3217 
3218  if (idx != ANALOG_SUB_REAL) {
3219  ast_log(LOG_WARNING, "Got flash hook with index %u on channel %d?!?\n", idx, p->channel);
3220  goto winkflashdone;
3221  }
3222 
3223  if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
3224  /* Need to hold the lock for real-call, private, and call-waiting call */
3226  if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
3227  /*
3228  * The call waiting call dissappeared.
3229  * Let's just ignore this flash-hook.
3230  */
3231  ast_log(LOG_NOTICE, "Whoa, the call-waiting call disappeared.\n");
3232  goto winkflashdone;
3233  }
3234 
3235  /* Swap to call-wait */
3239  ast_debug(1, "Making %s the new owner\n", ast_channel_name(p->owner));
3243  }
3245 
3246  /* Start music on hold if appropriate */
3247  if (!p->subs[ANALOG_SUB_CALLWAIT].inthreeway) {
3249  }
3252 
3253  /* Unlock the call-waiting call that we swapped to real-call. */
3255  } else if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3256  if (!p->threewaycalling) {
3257  /* Just send a flash if no 3-way calling */
3259  goto winkflashdone;
3260  } else if (!analog_check_for_conference(p)) {
3261  ast_callid callid = 0;
3262  int callid_created;
3263  char cid_num[256];
3264  char cid_name[256];
3265 
3266  cid_num[0] = '\0';
3267  cid_name[0] = '\0';
3268  if (p->dahditrcallerid && p->owner) {
3270  && ast_channel_caller(p->owner)->id.number.str) {
3272  sizeof(cid_num));
3273  }
3275  && ast_channel_caller(p->owner)->id.name.str) {
3277  sizeof(cid_name));
3278  }
3279  }
3280  /* XXX This section needs much more error checking!!! XXX */
3281  /* Start a 3-way call if feasible */
3282  if (!((ast_channel_pbx(ast)) ||
3283  (ast_channel_state(ast) == AST_STATE_UP) ||
3284  (ast_channel_state(ast) == AST_STATE_RING))) {
3285  ast_debug(1, "Flash when call not up or ringing\n");
3286  goto winkflashdone;
3287  }
3289  ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n");
3290  goto winkflashdone;
3291  }
3292 
3293  callid_created = ast_callid_threadstorage_auto(&callid);
3294 
3295  /*
3296  * Make new channel
3297  *
3298  * We cannot hold the p or ast locks while creating a new
3299  * channel.
3300  */
3302  ast_channel_unlock(ast);
3304  ast_channel_lock(ast);
3306  if (!chan) {
3308  "Cannot allocate new call structure on channel %d\n",
3309  p->channel);
3311  ast_callid_threadstorage_auto_clean(callid, callid_created);
3312  goto winkflashdone;
3313  }
3314  if (p->dahditrcallerid) {
3315  if (!p->origcid_num) {
3316  p->origcid_num = ast_strdup(p->cid_num);
3317  }
3318  if (!p->origcid_name) {
3319  p->origcid_name = ast_strdup(p->cid_name);
3320  }
3321  ast_copy_string(p->cid_num, cid_num, sizeof(p->cid_num));
3322  ast_copy_string(p->cid_name, cid_name, sizeof(p->cid_name));
3323  }
3324  /* Swap things around between the three-way and real call */
3326  /* Disable echo canceller for better dialing */
3329  if (res) {
3330  ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel);
3331  }
3332  analog_set_new_owner(p, chan);
3333  p->ss_astchan = chan;
3334  if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, p)) {
3335  ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel);
3338  ast_hangup(chan);
3339  } else {
3340  ast_verb(3, "Started three way call on channel %d\n", p->channel);
3341 
3342  /* Start music on hold */
3344  }
3345  ast_callid_threadstorage_auto_clean(callid, callid_created);
3346  }
3347  } else {
3348  /* Already have a 3 way call */
3349  enum analog_sub orig_3way_sub;
3350 
3351  /* Need to hold the lock for real-call, private, and 3-way call */
3353  if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3354  /*
3355  * The 3-way call dissappeared.
3356  * Let's just ignore this flash-hook.
3357  */
3358  ast_log(LOG_NOTICE, "Whoa, the 3-way call disappeared.\n");
3359  goto winkflashdone;
3360  }
3361  orig_3way_sub = ANALOG_SUB_THREEWAY;
3362 
3364  /* Call is already up, drop the last person */
3365  ast_debug(1, "Got flash with three way call up, dropping last call on %d\n", p->channel);
3366  /* If the primary call isn't answered yet, use it */
3369  /* Swap back -- we're dropping the real 3-way that isn't finished yet*/
3371  orig_3way_sub = ANALOG_SUB_REAL;
3373  }
3374  /* Drop the last call and stop the conference */
3375  ast_verb(3, "Dropping three-way call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner));
3379  } else {
3380  /* Lets see what we're up to */
3381  if (((ast_channel_pbx(ast)) || (ast_channel_state(ast) == AST_STATE_UP)) &&
3382  (p->transfertobusy || (ast_channel_state(ast) != AST_STATE_BUSY))) {
3383  ast_verb(3, "Building conference call with %s and %s\n",
3386  /* Put them in the threeway, and flip */
3389  if (ast_channel_state(ast) == AST_STATE_UP) {
3391  orig_3way_sub = ANALOG_SUB_REAL;
3392  }
3393  ast_queue_unhold(p->subs[orig_3way_sub].owner);
3395  } else {
3396  ast_verb(3, "Dumping incomplete call on %s\n", ast_channel_name(p->subs[ANALOG_SUB_THREEWAY].owner));
3398  orig_3way_sub = ANALOG_SUB_REAL;
3403  }
3404  }
3405  ast_channel_unlock(p->subs[orig_3way_sub].owner);
3406  }
3407 winkflashdone:
3408  analog_update_conf(p);
3409  break;
3410  case ANALOG_SIG_EM:
3411  case ANALOG_SIG_EM_E1:
3412  case ANALOG_SIG_FEATD:
3413  case ANALOG_SIG_SF:
3414  case ANALOG_SIG_SFWINK:
3415  case ANALOG_SIG_SF_FEATD:
3416  case ANALOG_SIG_FXSLS:
3417  case ANALOG_SIG_FXSGS:
3418  if (p->dialing) {
3419  ast_debug(1, "Ignoring wink on channel %d\n", p->channel);
3420  } else {
3421  ast_debug(1, "Got wink in weird state %u on channel %d\n", ast_channel_state(ast), p->channel);
3422  }
3423  break;
3424  case ANALOG_SIG_FEATDMF_TA:
3425  switch (p->whichwink) {
3426  case 0:
3427  ast_debug(1, "ANI2 set to '%d' and ANI is '%s'\n", ast_channel_caller(p->owner)->ani2,
3429  ast_channel_caller(p->owner)->ani.number.str, ""));
3430  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%d%s#",
3433  ast_channel_caller(p->owner)->ani.number.str, ""));
3434  break;
3435  case 1:
3436  ast_copy_string(p->dop.dialstr, p->finaldial, sizeof(p->dop.dialstr));
3437  break;
3438  case 2:
3439  ast_log(LOG_WARNING, "Received unexpected wink on channel of type ANALOG_SIG_FEATDMF_TA\n");
3440  return NULL;
3441  }
3442  p->whichwink++;
3443  /* Fall through */
3444  case ANALOG_SIG_FEATDMF:
3445  case ANALOG_SIG_E911:
3446  case ANALOG_SIG_FGC_CAMAMF:
3447  case ANALOG_SIG_FGC_CAMA:
3448  case ANALOG_SIG_FEATB:
3449  case ANALOG_SIG_SF_FEATDMF:
3450  case ANALOG_SIG_SF_FEATB:
3451  case ANALOG_SIG_EMWINK:
3452  /* FGD MF and EMWINK *Must* wait for wink */
3453  if (!ast_strlen_zero(p->dop.dialstr)) {
3454  res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3455  if (res) {
3456  p->dop.dialstr[0] = '\0';
3457  return NULL;
3458  } else {
3459  ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3460  }
3461  }
3462  p->dop.dialstr[0] = '\0';
3463  break;
3464  default:
3465  ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3466  }
3467  break;
3469  if (p->inalarm) break;
3470  if (analog_check_waitingfordt(p)) {
3471  break;
3472  }
3473  switch (mysig) {
3474  case ANALOG_SIG_FXSLS: /* only interesting for FXS */
3475  case ANALOG_SIG_FXSGS:
3476  case ANALOG_SIG_FXSKS:
3477  case ANALOG_SIG_EM:
3478  case ANALOG_SIG_EM_E1:
3479  case ANALOG_SIG_EMWINK:
3480  case ANALOG_SIG_FEATD:
3481  case ANALOG_SIG_SF:
3482  case ANALOG_SIG_SFWINK:
3483  case ANALOG_SIG_SF_FEATD:
3484  if (!ast_strlen_zero(p->dop.dialstr)) {
3485  res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3486  if (res) {
3487  p->dop.dialstr[0] = '\0';
3488  return NULL;
3489  } else {
3490  ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3491  }
3492  }
3493  p->dop.dialstr[0] = '\0';
3495  break;
3496  case ANALOG_SIG_FEATDMF:
3497  case ANALOG_SIG_FEATDMF_TA:
3498  case ANALOG_SIG_E911:
3499  case ANALOG_SIG_FGC_CAMA:
3500  case ANALOG_SIG_FGC_CAMAMF:
3501  case ANALOG_SIG_FEATB:
3502  case ANALOG_SIG_SF_FEATDMF:
3503  case ANALOG_SIG_SF_FEATB:
3504  ast_debug(1, "Got hook complete in MF FGD, waiting for wink now on channel %d\n",p->channel);
3505  break;
3506  default:
3507  break;
3508  }
3509  break;
3510  case ANALOG_EVENT_POLARITY:
3511  /*
3512  * If we get a Polarity Switch event, this could be
3513  * due to line seizure, remote end connect or remote end disconnect.
3514  *
3515  * Check to see if we should change the polarity state and
3516  * mark the channel as UP or if this is an indication
3517  * of remote end disconnect.
3518  */
3519 
3520  if (p->polarityonanswerdelay > 0) {
3521  /* check if event is not too soon after OffHook or Answer */
3523  switch (ast_channel_state(ast)) {
3524  case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3525  case AST_STATE_RINGING: /*!< Remote end is ringing */
3526  if (p->answeronpolarityswitch) {
3527  ast_debug(1, "Answering on polarity switch! channel %d\n", p->channel);
3529  p->polarity = POLARITY_REV;
3530  if (p->hanguponpolarityswitch) {
3531  p->polaritydelaytv = ast_tvnow();
3532  }
3533  } else {
3534  ast_debug(1, "Ignore Answer on polarity switch, channel %d\n", p->channel);
3535  }
3536  break;
3537 
3538  case AST_STATE_UP: /*!< Line is up */
3539  case AST_STATE_RING: /*!< Line is ringing */
3540  if (p->hanguponpolarityswitch) {
3541  ast_debug(1, "HangingUp on polarity switch! channel %d\n", p->channel);
3542  ast_queue_control_data(ast, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size);
3543  ast_channel_hangupcause_hash_set(ast, cause_code, data_size);
3545  p->polarity = POLARITY_IDLE;
3546  } else {
3547  ast_debug(1, "Ignore Hangup on polarity switch, channel %d\n", p->channel);
3548  }
3549  break;
3550 
3551  case AST_STATE_DOWN: /*!< Channel is down and available */
3552  case AST_STATE_RESERVED: /*!< Channel is down, but reserved */
3553  case AST_STATE_OFFHOOK: /*!< Channel is off hook */
3554  case AST_STATE_BUSY: /*!< Line is busy */
3555  case AST_STATE_DIALING_OFFHOOK: /*!< Digits (or equivalent) have been dialed while offhook */
3556  case AST_STATE_PRERING: /*!< Channel has detected an incoming call and is waiting for ring */
3557  default:
3559  ast_debug(1, "Ignoring Polarity switch on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3560  }
3561  break;
3562  }
3563 
3564  } else {
3565  /* event is too soon after OffHook or Answer */
3566  switch (ast_channel_state(ast)) {
3567  case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3568  case AST_STATE_RINGING: /*!< Remote end is ringing */
3569  if (p->answeronpolarityswitch) {
3570  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));
3571  }
3572  break;
3573 
3574  case AST_STATE_UP: /*!< Line is up */
3575  case AST_STATE_RING: /*!< Line is ringing */
3576  if (p->hanguponpolarityswitch) {
3577  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));
3578  }
3579  break;
3580 
3581  default:
3583  ast_debug(1, "Polarity switch detected (too close to previous event) on channel %d, state %u\n", p->channel, ast_channel_state(ast));
3584  }
3585  break;
3586  }
3587  }
3588  }
3589 
3590  /* Added more log_debug information below to provide a better indication of what is going on */
3591  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) );
3592  break;
3593  default:
3594  ast_debug(1, "Dunno what to do with event %d on channel %d\n", res, p->channel);
3595  }
3596  return &p->subs[idx].f;
3597 }
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_log
Definition: astobj2.c:42
#define AST_CAUSE_NETWORK_OUT_OF_ORDER
Definition: causes.h:121
#define AST_CAUSE_NO_ANSWER
Definition: causes.h:109
#define AST_CAUSE_NORMAL_CLEARING
Definition: causes.h:106
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:167
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:168
void ast_channel_rings_set(struct ast_channel *chan, int value)
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2542
int ast_channel_rings(const struct ast_channel *chan)
@ AST_SOFTHANGUP_EXPLICIT
Definition: channel.h:1148
@ AST_SOFTHANGUP_DEV
Definition: channel.h:1121
struct ast_pbx * ast_channel_pbx(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2922
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
Definition: channel.c:1225
const char * ast_channel_name(const struct ast_channel *chan)
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:1232
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
Definition: channel.c:1160
int ast_softhangup(struct ast_channel *chan, int cause)
Softly hangup up a channel.
Definition: channel.c:2470
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:4381
int ast_queue_unhold(struct ast_channel *chan)
Queue an unhold frame.
Definition: channel.c:1210
int ast_queue_hold(struct ast_channel *chan, const char *musicclass)
Queue a hold frame.
Definition: channel.c:1185
#define AST_CHANNEL_NAME
Definition: channel.h:171
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
int ast_softhangup_nolock(struct ast_channel *chan, int cause)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2457
#define ast_channel_unlock(chan)
Definition: channel.h:2923
ast_channel_state
ast_channel states
Definition: channelstate.h:35
@ AST_STATE_RING
Definition: channelstate.h:40
@ AST_STATE_DIALING_OFFHOOK
Definition: channelstate.h:44
@ AST_STATE_RINGING
Definition: channelstate.h:41
@ AST_STATE_PRERING
Definition: channelstate.h:45
@ AST_STATE_DOWN
Definition: channelstate.h:36
@ AST_STATE_OFFHOOK
Definition: channelstate.h:38
@ AST_STATE_BUSY
Definition: channelstate.h:43
@ AST_STATE_DIALING
Definition: channelstate.h:39
@ AST_STATE_UP
Definition: channelstate.h:42
@ AST_STATE_RESERVED
Definition: channelstate.h:37
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7469
@ AST_FRAME_NULL
@ AST_FRAME_DTMF_END
@ AST_FRAME_DTMF_BEGIN
@ AST_FRAME_CONTROL
@ AST_CONTROL_RING
@ AST_CONTROL_OFFHOOK
@ AST_CONTROL_ANSWER
@ AST_CONTROL_RINGING
@ AST_CONTROL_FLASH
@ AST_CONTROL_PVT_CAUSE_CODE
struct ast_frame ast_null_frame
Definition: main/frame.c:79
void ast_callid_threadstorage_auto_clean(ast_callid callid, int callid_created)
Use in conjunction with ast_callid_threadstorage_auto. Cleans up the references and if the callid was...
Definition: logger.c:2128
#define ast_debug(level,...)
Log a DEBUG message.
unsigned int ast_callid
int ast_callid_threadstorage_auto(ast_callid *callid)
Checks thread storage for a callid and stores a reference if it exists. If not, then a new one will b...
Definition: logger.c:2106
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_NOTICE
#define LOG_WARNING
#define NULL
Definition: resample.c:96
static void analog_publish_channel_alarm_clear(int channel)
Definition: sig_analog.c:2716
static void * __analog_ss_thread(void *data)
Definition: sig_analog.c:1713
static void analog_set_alarm(struct analog_pvt *p, int in_alarm)
Definition: sig_analog.c:898
static int analog_alloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition: sig_analog.c:368
static int analog_send_callerid(struct analog_pvt *p, int cwcid, struct ast_party_caller *caller)
Definition: sig_analog.c:391
static int analog_update_conf(struct analog_pvt *p)
Definition: sig_analog.c:743
static void analog_unlock_private(struct analog_pvt *p)
Definition: sig_analog.c:560
static int analog_unalloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition: sig_analog.c:381
static int analog_dial_digits(struct analog_pvt *p, enum analog_sub sub, struct analog_dialoperation *dop)
Definition: sig_analog.c:521
static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
Definition: sig_analog.c:446
static int analog_attempt_transfer(struct analog_pvt *p)
Definition: sig_analog.c:710
static void analog_set_needringing(struct analog_pvt *p, int value)
Definition: sig_analog.c:623
static int analog_check_waitingfordt(struct analog_pvt *p)
Definition: sig_analog.c:921
static int analog_train_echocanceller(struct analog_pvt *p)
Definition: sig_analog.c:481
static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
Definition: sig_analog.c:890
static struct ast_channel * analog_new_ast_channel(struct analog_pvt *p, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
Definition: sig_analog.c:454
static int analog_ring(struct analog_pvt *p)
Definition: sig_analog.c:497
static int analog_check_for_conference(struct analog_pvt *p)
Definition: sig_analog.c:545
void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub idx, struct ast_frame **dest)
Definition: sig_analog.c:1566
static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
Definition: sig_analog.c:906
static void analog_lock_sub_owner(struct analog_pvt *pvt, enum analog_sub sub_idx)
Definition: sig_analog.c:599
static void analog_lock_private(struct analog_pvt *p)
Definition: sig_analog.c:567
static int analog_have_progressdetect(struct analog_pvt *p)
Definition: sig_analog.c:210
#define analog_get_index(ast, p, nullok)
Definition: sig_analog.c:407
static int analog_confmute(struct analog_pvt *p, int mute)
Definition: sig_analog.c:953
static void analog_answer_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:645
static int analog_on_hook(struct analog_pvt *p)
Definition: sig_analog.c:529
static void analog_get_and_handle_alarms(struct analog_pvt *p)
Definition: sig_analog.c:1663
static int analog_stop_callwait(struct analog_pvt *p)
Definition: sig_analog.c:857
static void analog_set_pulsedial(struct analog_pvt *p, int flag)
Definition: sig_analog.c:961
static int analog_has_voicemail(struct analog_pvt *p)
Definition: sig_analog.c:682
static char * analog_event2str(enum analog_event event)
Definition: sig_analog.c:265
static int analog_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:615
static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
Definition: sig_analog.c:438
#define MIN_MS_SINCE_FLASH
Definition: sig_analog.c:64
static int analog_get_event(struct analog_pvt *p)
Definition: sig_analog.c:194
static int analog_set_echocanceller(struct analog_pvt *p, int enable)
Definition: sig_analog.c:473
static void analog_set_inthreeway(struct analog_pvt *p, enum analog_sub sub, int inthreeway)
Definition: sig_analog.c:977
#define POLARITY_IDLE
Definition: sig_analog.c:62
static int analog_check_confirmanswer(struct analog_pvt *p)
Definition: sig_analog.c:937
static int analog_is_dialing(struct analog_pvt *p, enum analog_sub index)
Definition: sig_analog.c:690
static void analog_cancel_cidspill(struct analog_pvt *p)
Definition: sig_analog.c:946
static void analog_swap_subs(struct analog_pvt *p, enum analog_sub a, enum analog_sub b)
Definition: sig_analog.c:348
#define POLARITY_REV
Definition: sig_analog.c:63
static int analog_get_sub_fd(struct analog_pvt *p, enum analog_sub sub)
Definition: sig_analog.c:1678
static void analog_start_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:639
@ ANALOG_EVENT_HOOKCOMPLETE
Definition: sig_analog.h:89
@ ANALOG_EVENT_DTMFDOWN
Definition: sig_analog.h:104
@ ANALOG_EVENT_RINGEROFF
Definition: sig_analog.h:88
@ ANALOG_EVENT_PULSE_START
Definition: sig_analog.h:90
@ ANALOG_EVENT_TX_CED_DETECTED
Definition: sig_analog.h:97
@ ANALOG_EVENT_RINGBEGIN
Definition: sig_analog.h:92
@ ANALOG_EVENT_ONHOOK
Definition: sig_analog.h:81
@ ANALOG_EVENT_EC_DISABLED
Definition: sig_analog.h:93
@ ANALOG_EVENT_WINKFLASH
Definition: sig_analog.h:83
@ ANALOG_EVENT_PULSEDIGIT
Definition: sig_analog.h:103
@ ANALOG_EVENT_RINGERON
Definition: sig_analog.h:87
@ ANALOG_EVENT_RX_CED_DETECTED
Definition: sig_analog.h:98
@ ANALOG_EVENT_ALARM
Definition: sig_analog.h:84
@ ANALOG_EVENT_DIALCOMPLETE
Definition: sig_analog.h:86
@ ANALOG_EVENT_EC_NLP_ENABLED
Definition: sig_analog.h:100
@ ANALOG_EVENT_POLARITY
Definition: sig_analog.h:91
@ ANALOG_EVENT_DTMFUP
Definition: sig_analog.h:105
@ ANALOG_EVENT_EC_NLP_DISABLED
Definition: sig_analog.h:99
@ ANALOG_EVENT_RINGOFFHOOK
Definition: sig_analog.h:82
@ ANALOG_EVENT_NOALARM
Definition: sig_analog.h:85
@ ANALOG_DIAL_OP_REPLACE
Definition: sig_analog.h:127
analog_sub
Definition: sig_analog.h:108
@ ANALOG_SUB_THREEWAY
Definition: sig_analog.h:111
@ ANALOG_SUB_REAL
Definition: sig_analog.h:109
@ ANALOG_SUB_CALLWAIT
Definition: sig_analog.h:110
@ ANALOG_SIG_FEATD
Definition: sig_analog.h:56
@ ANALOG_SIG_FEATDMF_TA
Definition: sig_analog.h:66
@ ANALOG_SIG_FGC_CAMAMF
Definition: sig_analog.h:60
@ ANALOG_SIG_FXOLS
Definition: sig_analog.h:47
@ ANALOG_SIG_FEATDMF
Definition: sig_analog.h:57
@ ANALOG_SIG_EM_E1
Definition: sig_analog.h:55
@ ANALOG_SIG_EMWINK
Definition: sig_analog.h:53
@ ANALOG_SIG_FXOKS
Definition: sig_analog.h:48
@ ANALOG_SIG_SF
Definition: sig_analog.h:63
@ ANALOG_SIG_FGC_CAMA
Definition: sig_analog.h:59
@ ANALOG_SIG_EM
Definition: sig_analog.h:54
@ ANALOG_SIG_FXOGS
Definition: sig_analog.h:49
@ ANALOG_SIG_SF_FEATB
Definition: sig_analog.h:67
@ ANALOG_SIG_SF_FEATDMF
Definition: sig_analog.h:65
@ ANALOG_SIG_SFWINK
Definition: sig_analog.h:62
@ ANALOG_SIG_E911
Definition: sig_analog.h:58
@ ANALOG_SIG_FEATB
Definition: sig_analog.h:61
@ ANALOG_SIG_SF_FEATD
Definition: sig_analog.h:64
@ ANALOG_TONE_CONGESTION
Definition: sig_analog.h:73
@ ANALOG_TONE_DIALTONE
Definition: sig_analog.h:74
@ ANALOG_TONE_DIALRECALL
Definition: sig_analog.h:75
@ ANALOG_TONE_STUTTER
Definition: sig_analog.h:72
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:406
char dialdest[256]
Definition: sig_analog.h:347
unsigned int dahditrcallerid
Definition: sig_analog.h:288
struct analog_dialoperation dop
Definition: sig_analog.h:273
int polarityonanswerdelay
Definition: sig_analog.h:313
char cid_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:317
char * origcid_name
Definition: sig_analog.h:353
struct timeval flashtime
Definition: sig_analog.h:349
unsigned int outgoing
Definition: sig_analog.h:328
int whichwink
Definition: sig_analog.h:350
char * origcid_num
Definition: sig_analog.h:352
enum analog_sigtype outsigmod
Definition: sig_analog.h:310
unsigned int answeronpolarityswitch
Definition: sig_analog.h:284
unsigned int threewaycalling
Definition: sig_analog.h:294
int echotraining
Definition: sig_analog.h:311
int msgstate
-1 = unknown, 0 = no messages, 1 = new messages available
Definition: sig_analog.h:277
int onhooktime
Definition: sig_analog.h:274
struct timeval polaritydelaytv
Definition: sig_analog.h:346
unsigned int hanguponpolarityswitch
Definition: sig_analog.h:289
int cidrings
Definition: sig_analog.h:343
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
Definition: sig_analog.h:336
unsigned int echobreak
Definition: sig_analog.h:326
struct ast_channel * owner
Definition: sig_analog.h:270
enum analog_sigtype sig
Definition: sig_analog.h:266
unsigned int dialednone
Definition: sig_analog.h:323
char echorest[20]
Definition: sig_analog.h:344
int ringt_base
Definition: sig_analog.h:361
int fxsoffhookstate
Definition: sig_analog.h:275
struct analog_subchannel subs[3]
Definition: sig_analog.h:272
char finaldial[64]
Definition: sig_analog.h:351
unsigned int transfer
Definition: sig_analog.h:295
unsigned int transfertobusy
Definition: sig_analog.h:296
unsigned int inalarm
Definition: sig_analog.h:329
char cid_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:318
char mohsuggest[MAX_MUSICCLASS]
Definition: sig_analog.h:316
int polarity
Definition: sig_analog.h:345
struct ast_channel * ss_astchan
Definition: sig_analog.h:357
unsigned int dialing
Definition: sig_analog.h:324
struct ast_party_caller caller
Definition: sig_analog.h:342
struct ast_frame f
Definition: sig_analog.h:258
unsigned int inthreeway
Definition: sig_analog.h:259
struct ast_channel * owner
Definition: sig_analog.h:257
Main Channel structure associated with a channel.
char chan_name[AST_CHANNEL_NAME]
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
union ast_frame::@254 data
enum ast_frame_type frametype
const char * src
struct ast_party_id id
Caller party ID.
Definition: channel.h:420
int ani2
Automatic Number Identification 2 (Info Digits)
Definition: channel.h:433
struct ast_party_id ani
Automatic Number Identification (ANI)
Definition: channel.h:427
struct ast_party_name name
Subscriber name.
Definition: channel.h:340
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:342
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:279
char * str
Subscriber name (Malloced)
Definition: channel.h:264
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:297
char * str
Subscriber phone number (Malloced)
Definition: channel.h:291
static struct test_val c
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:105
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:157
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:583

References __analog_ss_thread(), analog_alloc_sub(), analog_answer_polarityswitch(), analog_attempt_transfer(), analog_cancel_cidspill(), analog_check_confirmanswer(), analog_check_for_conference(), analog_check_waitingfordt(), analog_confmute(), analog_dial_digits(), ANALOG_DIAL_OP_REPLACE, analog_event2str(), ANALOG_EVENT_ALARM, ANALOG_EVENT_DIALCOMPLETE, ANALOG_EVENT_DTMFDOWN, ANALOG_EVENT_DTMFUP, ANALOG_EVENT_EC_DISABLED, ANALOG_EVENT_EC_NLP_DISABLED, ANALOG_EVENT_EC_NLP_ENABLED, ANALOG_EVENT_HOOKCOMPLETE, ANALOG_EVENT_NOALARM, ANALOG_EVENT_ONHOOK, ANALOG_EVENT_POLARITY, ANALOG_EVENT_PULSE_START, ANALOG_EVENT_PULSEDIGIT, ANALOG_EVENT_RINGBEGIN, ANALOG_EVENT_RINGEROFF, ANALOG_EVENT_RINGERON, ANALOG_EVENT_RINGOFFHOOK, ANALOG_EVENT_RX_CED_DETECTED, ANALOG_EVENT_TX_CED_DETECTED, ANALOG_EVENT_WINKFLASH, analog_get_and_handle_alarms(), analog_get_event(), analog_get_index, analog_get_sub_fd(), analog_handle_dtmf(), analog_has_voicemail(), analog_have_progressdetect(), analog_is_dialing(), analog_lock_private(), analog_lock_sub_owner(), analog_new_ast_channel(), analog_off_hook(), analog_on_hook(), analog_play_tone(), analog_publish_channel_alarm_clear(), analog_ring(), analog_send_callerid(), analog_set_alarm(), analog_set_dialing(), analog_set_echocanceller(), analog_set_inthreeway(), analog_set_needringing(), analog_set_new_owner(), analog_set_pulsedial(), analog_set_ringtimeout(), ANALOG_SIG_E911, ANALOG_SIG_EM, ANALOG_SIG_EM_E1, ANALOG_SIG_EMWINK, ANALOG_SIG_FEATB, ANALOG_SIG_FEATD, ANALOG_SIG_FEATDMF, ANALOG_SIG_FEATDMF_TA, ANALOG_SIG_FGC_CAMA, ANALOG_SIG_FGC_CAMAMF, ANALOG_SIG_FXOGS, ANALOG_SIG_FXOKS, ANALOG_SIG_FXOLS, ANALOG_SIG_FXSGS, ANALOG_SIG_FXSKS, ANALOG_SIG_FXSLS, ANALOG_SIG_SF, ANALOG_SIG_SF_FEATB, ANALOG_SIG_SF_FEATD, ANALOG_SIG_SF_FEATDMF, ANALOG_SIG_SFWINK, analog_start_polarityswitch(), analog_stop_callwait(), ANALOG_SUB_CALLWAIT, ANALOG_SUB_REAL, ANALOG_SUB_THREEWAY, analog_swap_subs(), ANALOG_TONE_CONGESTION, ANALOG_TONE_DIALRECALL, ANALOG_TONE_DIALTONE, ANALOG_TONE_STUTTER, analog_train_echocanceller(), analog_unalloc_sub(), analog_unlock_private(), analog_update_conf(), ast_party_caller::ani, ast_party_caller::ani2, analog_pvt::answeronpolarityswitch, ast_alloca, ast_callid_threadstorage_auto(), ast_callid_threadstorage_auto_clean(), ast_control_pvt_cause_code::ast_cause, AST_CAUSE_NETWORK_OUT_OF_ORDER, AST_CAUSE_NO_ANSWER, AST_CAUSE_NORMAL_CLEARING, ast_channel_caller(), ast_channel_hangupcause_hash_set(), ast_channel_lock, AST_CHANNEL_NAME, ast_channel_name(), ast_channel_pbx(), ast_channel_rings(), ast_channel_rings_set(), ast_channel_unlock, AST_CONTROL_ANSWER, AST_CONTROL_FLASH, AST_CONTROL_OFFHOOK, AST_CONTROL_PVT_CAUSE_CODE, AST_CONTROL_RING, AST_CONTROL_RINGING, ast_copy_string(), ast_debug, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_NULL, ast_hangup(), ast_log, ast_null_frame, ast_pthread_create_detached, ast_queue_control(), ast_queue_control_data(), ast_queue_hangup_with_cause(), ast_queue_hold(), ast_queue_unhold(), ast_setstate(), ast_softhangup(), AST_SOFTHANGUP_DEV, AST_SOFTHANGUP_EXPLICIT, ast_softhangup_nolock(), AST_STATE_BUSY, AST_STATE_DIALING, AST_STATE_DIALING_OFFHOOK, AST_STATE_DOWN, AST_STATE_OFFHOOK, AST_STATE_PRERING, AST_STATE_RESERVED, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_strdup, ast_strlen_zero(), ast_tvdiff_ms(), ast_tvnow(), ast_verb, c, analog_pvt::caller, analog_pvt::callwaitcas, ast_control_pvt_cause_code::chan_name, analog_pvt::channel, cid_name, analog_pvt::cid_name, cid_num, analog_pvt::cid_num, analog_pvt::cidrings, ast_control_pvt_cause_code::code, analog_pvt::dahditrcallerid, ast_frame::data, ast_frame::datalen, analog_pvt::dialdest, analog_pvt::dialednone, analog_pvt::dialing, analog_dialoperation::dialstr, analog_pvt::dop, analog_pvt::echobreak, analog_pvt::echorest, analog_pvt::echotraining, analog_subchannel::f, analog_pvt::finaldial, analog_pvt::flashtime, ast_frame::frametype, analog_pvt::fxsoffhookstate, analog_pvt::hanguponpolarityswitch, ast_party_caller::id, analog_pvt::inalarm, ast_frame_subclass::integer, analog_subchannel::inthreeway, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_frame::mallocd, MIN_MS_SINCE_FLASH, analog_pvt::mohsuggest, analog_pvt::msgstate, ast_party_id::name, NULL, ast_party_id::number, ast_frame::offset, analog_pvt::onhooktime, analog_dialoperation::op, analog_pvt::origcid_name, analog_pvt::origcid_num, analog_pvt::outgoing, analog_pvt::outsigmod, analog_subchannel::owner, analog_pvt::owner, analog_pvt::polarity, POLARITY_IDLE, POLARITY_REV, analog_pvt::polaritydelaytv, analog_pvt::polarityonanswerdelay, ast_frame::ptr, analog_pvt::ringt_base, S_COR, ast_frame::samples, analog_pvt::sig, ast_frame::src, analog_pvt::ss_astchan, ast_party_name::str, ast_party_number::str, ast_frame::subclass, analog_pvt::subs, analog_pvt::threewaycalling, analog_pvt::transfer, analog_pvt::transfertobusy, ast_party_name::valid, ast_party_number::valid, and analog_pvt::whichwink.

Referenced by analog_exception().

◆ __analog_ss_thread()

static void* __analog_ss_thread ( void *  data)
static

Definition at line 1713 of file sig_analog.c.

1714 {
1715  struct analog_pvt *p = data;
1716  struct ast_channel *chan = p->ss_astchan;
1717  char exten[AST_MAX_EXTENSION] = "";
1718  char exten2[AST_MAX_EXTENSION] = "";
1719  char dtmfcid[300];
1720  char dtmfbuf[300];
1721  char namebuf[ANALOG_MAX_CID];
1722  char numbuf[ANALOG_MAX_CID];
1723  char *name = NULL, *number = NULL;
1724  int flags = 0;
1725  struct ast_smdi_md_message *smdi_msg = NULL;
1726  int timeout;
1727  int getforward = 0;
1728  char *s1, *s2;
1729  int len = 0;
1730  int res;
1731  int idx;
1732  ast_callid callid;
1733  RAII_VAR(struct ast_features_pickup_config *, pickup_cfg, NULL, ao2_cleanup);
1734  const char *pickupexten;
1735 
1737 
1738  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1739 
1740  if (!chan) {
1741  /* What happened to the channel? */
1742  goto quit;
1743  }
1744 
1745  if ((callid = ast_channel_callid(chan))) {
1747  }
1748 
1749  /* in the bizarre case where the channel has become a zombie before we
1750  even get started here, abort safely
1751  */
1752  if (!ast_channel_tech_pvt(chan)) {
1753  ast_log(LOG_WARNING, "Channel became a zombie before simple switch could be started (%s)\n", ast_channel_name(chan));
1754  ast_hangup(chan);
1755  goto quit;
1756  }
1757 
1758  ast_verb(3, "Starting simple switch on '%s'\n", ast_channel_name(chan));
1759  idx = analog_get_index(chan, p, 0);
1760  if (idx < 0) {
1761  ast_hangup(chan);
1762  goto quit;
1763  }
1764 
1765  ast_channel_lock(chan);
1766  pickup_cfg = ast_get_chan_features_pickup_config(chan);
1767  if (!pickup_cfg) {
1768  ast_log(LOG_ERROR, "Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n");
1769  pickupexten = "";
1770  } else {
1771  pickupexten = ast_strdupa(pickup_cfg->pickupexten);
1772  }
1773  ast_channel_unlock(chan);
1774 
1776  switch (p->sig) {
1777  case ANALOG_SIG_FEATD:
1778  case ANALOG_SIG_FEATDMF:
1779  case ANALOG_SIG_FEATDMF_TA:
1780  case ANALOG_SIG_E911:
1781  case ANALOG_SIG_FGC_CAMAMF:
1782  case ANALOG_SIG_FEATB:
1783  case ANALOG_SIG_EMWINK:
1784  case ANALOG_SIG_SF_FEATD:
1785  case ANALOG_SIG_SF_FEATDMF:
1786  case ANALOG_SIG_SF_FEATB:
1787  case ANALOG_SIG_SFWINK:
1788  if (analog_wink(p, idx))
1789  goto quit;
1790  /* Fall through */
1791  case ANALOG_SIG_EM:
1792  case ANALOG_SIG_EM_E1:
1793  case ANALOG_SIG_SF:
1794  case ANALOG_SIG_FGC_CAMA:
1795  res = analog_play_tone(p, idx, -1);
1796 
1798 
1799  /* set digit mode appropriately */
1800  if (ANALOG_NEED_MFDETECT(p)) {
1802  } else {
1804  }
1805 
1806  memset(dtmfbuf, 0, sizeof(dtmfbuf));
1807  /* Wait for the first digit only if immediate=no */
1808  if (!p->immediate) {
1809  /* Wait for the first digit (up to 5 seconds). */
1810  res = ast_waitfordigit(chan, 5000);
1811  } else {
1812  res = 0;
1813  }
1814  if (res > 0) {
1815  /* save first char */
1816  dtmfbuf[0] = res;
1817  switch (p->sig) {
1818  case ANALOG_SIG_FEATD:
1819  case ANALOG_SIG_SF_FEATD:
1820  res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
1821  if (res > 0) {
1822  res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
1823  }
1824  if (res < 1) {
1826  }
1827  break;
1828  case ANALOG_SIG_FEATDMF_TA:
1829  res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
1830  if (res < 1) {
1832  }
1833  if (analog_wink(p, idx)) {
1834  goto quit;
1835  }
1836  dtmfbuf[0] = 0;
1837  /* Wait for the first digit (up to 5 seconds). */
1838  res = ast_waitfordigit(chan, 5000);
1839  if (res <= 0) {
1840  break;
1841  }
1842  dtmfbuf[0] = res;
1843  /* fall through intentionally */
1844  case ANALOG_SIG_FEATDMF:
1845  case ANALOG_SIG_E911:
1846  case ANALOG_SIG_FGC_CAMAMF:
1847  case ANALOG_SIG_SF_FEATDMF:
1848  res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
1849  /* if international caca, do it again to get real ANO */
1850  if ((p->sig == ANALOG_SIG_FEATDMF) && (dtmfbuf[1] != '0')
1851  && (strlen(dtmfbuf) != 14)) {
1852  if (analog_wink(p, idx)) {
1853  goto quit;
1854  }
1855  dtmfbuf[0] = 0;
1856  /* Wait for the first digit (up to 5 seconds). */
1857  res = ast_waitfordigit(chan, 5000);
1858  if (res <= 0) {
1859  break;
1860  }
1861  dtmfbuf[0] = res;
1862  res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
1863  }
1864  if (res > 0) {
1865  /* if E911, take off hook */
1866  if (p->sig == ANALOG_SIG_E911) {
1867  analog_off_hook(p);
1868  }
1869  }
1870  if (res < 1) {
1872  }
1873  break;
1874  case ANALOG_SIG_FEATB:
1875  case ANALOG_SIG_SF_FEATB:
1876  res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
1877  if (res < 1) {
1879  }
1880  break;
1881  case ANALOG_SIG_EMWINK:
1882  /* if we received a '*', we are actually receiving Feature Group D
1883  dial syntax, so use that mode; otherwise, fall through to normal
1884  mode
1885  */
1886  if (res == '*') {
1887  res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
1888  if (res > 0) {
1889  res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
1890  }
1891  if (res < 1) {
1893  }
1894  break;
1895  }
1896  default:
1897  /* If we got the first digit, get the rest */
1898  len = 1;
1899  dtmfbuf[len] = '\0';
1900  while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
1901  if (ast_exists_extension(chan, ast_channel_context(chan), dtmfbuf, 1, p->cid_num)) {
1902  timeout = analog_get_matchdigit_timeout(p);
1903  } else {
1904  timeout = analog_get_interdigit_timeout(p);
1905  }
1906  res = ast_waitfordigit(chan, timeout);
1907  if (res < 0) {
1908  ast_debug(1, "waitfordigit returned < 0...\n");
1909  ast_hangup(chan);
1910  goto quit;
1911  } else if (res) {
1912  dtmfbuf[len++] = res;
1913  dtmfbuf[len] = '\0';
1914  } else {
1915  break;
1916  }
1917  }
1918  break;
1919  }
1920  }
1921  if (res == -1) {
1922  ast_log(LOG_WARNING, "getdtmf on channel %d: %s\n", p->channel, strerror(errno));
1923  ast_hangup(chan);
1924  goto quit;
1925  } else if (res < 0) {
1926  ast_debug(1, "Got hung up before digits finished\n");
1927  ast_hangup(chan);
1928  goto quit;
1929  }
1930 
1931  if (p->sig == ANALOG_SIG_FGC_CAMA || p->sig == ANALOG_SIG_FGC_CAMAMF) {
1932  /* This if block is where we process ANI for CAMA */
1933 
1934  char anibuf[100];
1935  struct ast_party_caller *caller;
1936 
1937  /* cnoffset is the point at which we pull the calling number out
1938  * of anibuf. Must be the number of ani_info_digits + 1 to account
1939  * for the KP, which is considered a digit. */
1940 
1941  /* The 1XB with ANI-B will send a full 10 digits
1942  * or 2 digits in case of ANI failure.
1943  * (CD-95811-01 Section II, page 10)
1944  * 10 digit string example: *08320123#
1945  * 2 digit string example: *2
1946  * KP (*) and ST (#) are considered to be digits */
1947 
1948  int cnoffset = p->ani_info_digits + 1;
1949  ast_debug(1, "cnoffset: %d\n", cnoffset);
1950 
1951  /* This is how long to wait before the wink to start ANI spill
1952  * Pulled from chan_dahdi.conf, default is 1000ms */
1953  if (ast_safe_sleep(chan,p->ani_wink_time) == -1) {
1954  ast_hangup(chan);
1955  goto quit;
1956  }
1957  analog_off_hook(p);
1958  ast_debug(1, "Sent wink to signal ANI start\n");
1960 
1961  /* ani_timeout is configured in chan_dahdi.conf. default is 10000ms.
1962  * ST, STP, ST2P, ST3P can all signal transmission complete, regardless of timeout */
1963  res = analog_my_getsigstr(chan, anibuf, "#ABC", p->ani_timeout);
1964 
1965  /* so we can work with the ani buffer */
1966  pbx_builtin_setvar_helper(chan, "ANIBUF", anibuf);
1967 
1968  /* as long as we get a terminating pulse OR the length of ANI buffer is at least >=2, we can treat
1969  * this as a complete spill for the purposes of setting anistart */
1970  if ((res > 0) || (strlen(anibuf) >= 2)) {
1971  char anistart[2] = "X";
1972  char f[101] = {0};
1973  if (strchr("#ABC", anibuf[strlen(anibuf) - 1])) {
1974  anistart[0] = anibuf[strlen(anibuf) - 1];
1975  anibuf[strlen(anibuf) - 1] = 0;
1976  }
1977  ast_set_callerid(chan, anibuf + cnoffset, NULL, anibuf + cnoffset);
1978 
1979  caller = ast_channel_caller(chan);
1980  strncpy(f, &(anibuf[1]), MIN((int)(p->ani_info_digits), sizeof(f)-1));
1981  caller->ani2 = atoi(f);
1982 
1983  anibuf[cnoffset] = 0;
1984 
1985  /* so we can work with the different start pulses as used in ANI-D */
1986  pbx_builtin_setvar_helper(chan, "ANISTART", anistart);
1987  /* so we can use our ANI INFO digits in our dialplan */
1988  pbx_builtin_setvar_helper(chan, "ANI2", anibuf + 1);
1989  }
1991  }
1992 
1993  ast_copy_string(exten, dtmfbuf, sizeof(exten));
1994  if (ast_strlen_zero(exten)) {
1995  ast_copy_string(exten, "s", sizeof(exten));
1996  }
1997  if (p->sig == ANALOG_SIG_FEATD || p->sig == ANALOG_SIG_EMWINK) {
1998  /* Look for Feature Group D on all E&M Wink and Feature Group D trunks */
1999  if (exten[0] == '*') {
2000  char *stringp=NULL;
2001  ast_copy_string(exten2, exten, sizeof(exten2));
2002  /* Parse out extension and callerid */
2003  stringp=exten2 +1;
2004  s1 = strsep(&stringp, "*");
2005  s2 = strsep(&stringp, "*");
2006  if (s2) {
2007  if (!ast_strlen_zero(p->cid_num)) {
2008  ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
2009  } else {
2010  ast_set_callerid(chan, s1, NULL, s1);
2011  }
2012  ast_copy_string(exten, s2, sizeof(exten));
2013  } else {
2014  ast_copy_string(exten, s1, sizeof(exten));
2015  }
2016  } else if (p->sig == ANALOG_SIG_FEATD) {
2017  ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
2018  }
2019  }
2020  if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
2021  if (exten[0] == '*') {
2022  char *stringp=NULL;
2023  struct ast_party_caller *caller;
2024 
2025  ast_copy_string(exten2, exten, sizeof(exten2));
2026  /* Parse out extension and callerid */
2027  stringp=exten2 +1;
2028  s1 = strsep(&stringp, "#");
2029  s2 = strsep(&stringp, "#");
2030  if (s2) {
2031  if (!ast_strlen_zero(p->cid_num)) {
2032  ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
2033  } else {
2034  if (*(s1 + 2)) {
2035  ast_set_callerid(chan, s1 + 2, NULL, s1 + 2);
2036  }
2037  }
2038  ast_copy_string(exten, s2 + 1, sizeof(exten));
2039  } else {
2040  ast_copy_string(exten, s1 + 2, sizeof(exten));
2041  }
2042 
2043  /* The first two digits are ani2 information. */
2044  caller = ast_channel_caller(chan);
2045  s1[2] = '\0';
2046  caller->ani2 = atoi(s1);
2047  } else {
2048  ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
2049  }
2050  }
2051  if ((p->sig == ANALOG_SIG_E911) || (p->sig == ANALOG_SIG_FGC_CAMAMF)) {
2052  if (exten[0] == '*') {
2053  char *stringp=NULL;
2054  ast_copy_string(exten2, exten, sizeof(exten2));
2055  /* Parse out extension and callerid */
2056  stringp=exten2 +1;
2057  s1 = strsep(&stringp, "#");
2058  s2 = strsep(&stringp, "#");
2059  if (s2 && (*(s2 + 1) == '0')) {
2060  if (*(s2 + 2)) {
2061  ast_set_callerid(chan, s2 + 2, NULL, s2 + 2);
2062  }
2063  }
2064  if (s1) {
2065  ast_copy_string(exten, s1, sizeof(exten));
2066  } else {
2067  ast_copy_string(exten, "911", sizeof(exten));
2068  }
2069  } else {
2070  ast_log(LOG_WARNING, "A KP was expected to start signaling for Feature Group C CAMA-MF, but we got something else. Received: %s on channel %d\n", exten, p->channel);
2071  }
2072  }
2073  if (p->sig == ANALOG_SIG_FEATB) {
2074  if (exten[0] == '*') {
2075  char *stringp=NULL;
2076  ast_copy_string(exten2, exten, sizeof(exten2));
2077  /* Parse out extension and callerid */
2078  stringp=exten2 +1;
2079  s1 = strsep(&stringp, "#");
2080  ast_copy_string(exten, exten2 + 1, sizeof(exten));
2081  } else {
2082  ast_log(LOG_WARNING, "A KP was expected to start signaling for Feature Group B, but we got something else. Received: %s on channel %d\n", exten, p->channel);
2083  }
2084  }
2085  if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
2086  analog_wink(p, idx);
2087  /*
2088  * Some switches require a minimum guard time between the last
2089  * FGD wink and something that answers immediately. This
2090  * ensures it.
2091  */
2092  if (ast_safe_sleep(chan, 100)) {
2093  ast_hangup(chan);
2094  goto quit;
2095  }
2096  }
2098 
2100 
2101  if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1,
2102  ast_channel_caller(chan)->id.number.valid ? ast_channel_caller(chan)->id.number.str : NULL)) {
2105  res = ast_pbx_run(chan);
2106  if (res) {
2107  ast_log(LOG_WARNING, "PBX exited non-zero\n");
2109  }
2110  goto quit;
2111  } else {
2112  ast_verb(3, "Unknown extension '%s' in context '%s' requested\n", exten, ast_channel_context(chan));
2113  sleep(2);
2114  res = analog_play_tone(p, idx, ANALOG_TONE_INFO);
2115  if (res < 0) {
2116  ast_log(LOG_WARNING, "Unable to start special tone on %d\n", p->channel);
2117  } else {
2118  sleep(1);
2119  }
2120  res = ast_streamfile(chan, "ss-noservice", ast_channel_language(chan));
2121  if (res >= 0) {
2122  ast_waitstream(chan, "");
2123  }
2125  ast_hangup(chan);
2126  goto quit;
2127  }
2128  break;
2129  case ANALOG_SIG_FXOLS:
2130  case ANALOG_SIG_FXOGS:
2131  case ANALOG_SIG_FXOKS:
2132  /* Read the first digit */
2133  timeout = analog_get_firstdigit_timeout(p);
2134  /* If starting a threeway call, never timeout on the first digit so someone
2135  can use flash-hook as a "hold" feature */
2136  if (p->subs[ANALOG_SUB_THREEWAY].owner) {
2137  timeout = 999999;
2138  }
2139  while (len < AST_MAX_EXTENSION-1) {
2140  int is_exten_parking = 0;
2141 
2142  /* Read digit unless it's supposed to be immediate, in which case the
2143  only answer is 's' */
2144  if (p->immediate) {
2145  res = 's';
2146  } else {
2147  res = ast_waitfordigit(chan, timeout);
2148  }
2149  timeout = 0;
2150  if (res < 0) {
2151  ast_debug(1, "waitfordigit returned < 0...\n");
2152  res = analog_play_tone(p, idx, -1);
2153  ast_hangup(chan);
2154  goto quit;
2155  } else if (res) {
2156  ast_debug(1,"waitfordigit returned '%c' (%d), timeout = %d\n", res, res, timeout);
2157  exten[len++]=res;
2158  exten[len] = '\0';
2159  }
2161  analog_play_tone(p, idx, -1);
2162  } else {
2164  }
2166  is_exten_parking = ast_parking_is_exten_park(ast_channel_context(chan), exten);
2167  }
2168  if (ast_exists_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num) && !is_exten_parking) {
2169  if (!res || !ast_matchmore_extension(chan, ast_channel_context(chan), exten, 1, p->cid_num)) {
2170  if (getforward) {
2171  /* Record this as the forwarding extension */
2173  ast_verb(3, "Setting call forward to '%s' on channel %d\n", p->call_forward, p->channel);
2175  if (res) {
2176  break;
2177  }
2178  usleep(500000);
2179  res = analog_play_tone(p, idx, -1);
2180  sleep(1);
2181  memset(exten, 0, sizeof(exten));
2182  res = analog_play_tone(p, idx, ANALOG_TONE_DIALTONE);
2183  len = 0;
2184  getforward = 0;
2185  } else {
2186  res = analog_play_tone(p, idx, -1);
2187  ast_channel_lock(chan);
2189  if (!ast_strlen_zero(p->cid_num)) {
2190  if (!p->hidecallerid) {
2191  ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
2192  } else {
2193  ast_set_callerid(chan, NULL, NULL, p->cid_num);
2194  }
2195  }
2196  if (!ast_strlen_zero(p->cid_name)) {
2197  if (!p->hidecallerid) {
2198  ast_set_callerid(chan, NULL, p->cid_name, NULL);
2199  }
2200  }
2202  ast_channel_unlock(chan);
2204  res = ast_pbx_run(chan);
2205  if (res) {
2206  ast_log(LOG_WARNING, "PBX exited non-zero\n");
2208  }
2209  goto quit;
2210  }
2211  } else {
2212  /* It's a match, but they just typed a digit, and there is an ambiguous match,
2213  so just set the timeout to analog_matchdigittimeout and wait some more */
2214  timeout = analog_get_matchdigit_timeout(p);
2215  }
2216  } else if (res == 0) {
2217  ast_debug(1, "not enough digits (and no ambiguous match)...\n");
2219  analog_wait_event(p);
2220  ast_hangup(chan);
2221  goto quit;
2222  } else if (p->callwaiting && !strcmp(exten, "*70")) {
2223  ast_verb(3, "Disabling call waiting on %s\n", ast_channel_name(chan));
2224  /* Disable call waiting if enabled */
2225  analog_set_callwaiting(p, 0);
2227  if (res) {
2228  ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2229  ast_channel_name(chan), strerror(errno));
2230  }
2231  len = 0;
2232  memset(exten, 0, sizeof(exten));
2233  timeout = analog_get_firstdigit_timeout(p);
2234 
2235  } else if (!strcmp(exten, pickupexten)) {
2236  /* Scan all channels and see if there are any
2237  * ringing channels that have call groups
2238  * that equal this channels pickup group
2239  */
2240  if (idx == ANALOG_SUB_REAL) {
2241  /* Switch us from Third call to Call Wait */
2242  if (p->subs[ANALOG_SUB_THREEWAY].owner) {
2243  /* If you make a threeway call and the *8# a call, it should actually
2244  look like a callwait */
2248  }
2250  if (ast_pickup_call(chan)) {
2251  ast_debug(1, "No call pickup possible...\n");
2253  analog_wait_event(p);
2254  }
2255  ast_hangup(chan);
2256  goto quit;
2257  } else {
2258  ast_log(LOG_WARNING, "Huh? Got *8# on call not on real\n");
2259  ast_hangup(chan);
2260  goto quit;
2261  }
2262 
2263  } else if (!p->hidecallerid && !strcmp(exten, "*67")) {
2264  ast_verb(3, "Disabling Caller*ID on %s\n", ast_channel_name(chan));
2265  /* Disable Caller*ID if enabled */
2266  p->hidecallerid = 1;
2272  if (res) {
2273  ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2274  ast_channel_name(chan), strerror(errno));
2275  }
2276  len = 0;
2277  memset(exten, 0, sizeof(exten));
2278  timeout = analog_get_firstdigit_timeout(p);
2279  } else if (p->callreturn && !strcmp(exten, "*69")) {
2280  res = 0;
2281  if (!ast_strlen_zero(p->lastcid_num)) {
2282  res = ast_say_digit_str(chan, p->lastcid_num, "", ast_channel_language(chan));
2283  }
2284  if (!res) {
2286  }
2287  break;
2288  } else if (!strcmp(exten, "*78")) {
2289  /* Do not disturb enabled */
2290  analog_dnd(p, 1);
2292  getforward = 0;
2293  memset(exten, 0, sizeof(exten));
2294  len = 0;
2295  } else if (!strcmp(exten, "*79")) {
2296  /* Do not disturb disabled */
2297  analog_dnd(p, 0);
2299  getforward = 0;
2300  memset(exten, 0, sizeof(exten));
2301  len = 0;
2302  } else if (p->cancallforward && !strcmp(exten, "*72")) {
2304  getforward = 1;
2305  memset(exten, 0, sizeof(exten));
2306  len = 0;
2307  } else if (p->cancallforward && !strcmp(exten, "*73")) {
2308  ast_verb(3, "Cancelling call forwarding on channel %d\n", p->channel);
2310  memset(p->call_forward, 0, sizeof(p->call_forward));
2311  getforward = 0;
2312  memset(exten, 0, sizeof(exten));
2313  len = 0;
2314  } else if ((p->transfer || p->canpark) && is_exten_parking
2315  && p->subs[ANALOG_SUB_THREEWAY].owner) {
2316  struct ast_bridge_channel *bridge_channel;
2317 
2318  /*
2319  * This is a three way call, the main call being a real channel,
2320  * and we're parking the first call.
2321  */
2325  if (bridge_channel) {
2327  /*
2328  * Swap things around between the three-way and real call so we
2329  * can hear where the channel got parked.
2330  */
2335 
2336  ast_verb(3, "%s: Parked call\n", ast_channel_name(chan));
2337  ast_hangup(chan);
2338  ao2_ref(bridge_channel, -1);
2339  goto quit;
2340  }
2341  ao2_ref(bridge_channel, -1);
2342  }
2343  break;
2344  } else if (!ast_strlen_zero(p->lastcid_num) && !strcmp(exten, "*60")) {
2345  ast_verb(3, "Blacklisting number %s\n", p->lastcid_num);
2346  res = ast_db_put("blacklist", p->lastcid_num, "1");
2347  if (!res) {
2349  memset(exten, 0, sizeof(exten));
2350  len = 0;
2351  }
2352  } else if (p->hidecallerid && !strcmp(exten, "*82")) {
2353  ast_verb(3, "Enabling Caller*ID on %s\n", ast_channel_name(chan));
2354  /* Enable Caller*ID if enabled */
2355  p->hidecallerid = 0;
2358  if (res) {
2359  ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2360  ast_channel_name(chan), strerror(errno));
2361  }
2362  len = 0;
2363  memset(exten, 0, sizeof(exten));
2364  timeout = analog_get_firstdigit_timeout(p);
2365  } else if (!strcmp(exten, "*0")) {
2366  struct ast_channel *nbridge = p->subs[ANALOG_SUB_THREEWAY].owner;
2367  struct analog_pvt *pbridge = NULL;
2368  /* set up the private struct of the bridged one, if any */
2369  if (nbridge) {
2370  pbridge = analog_get_bridged_channel(nbridge);
2371  }
2372  if (pbridge && ISTRUNK(pbridge)) {
2373  /* Clear out the dial buffer */
2374  p->dop.dialstr[0] = '\0';
2375  /* flash hookswitch */
2376  if ((analog_flash(pbridge) == -1) && (errno != EINPROGRESS)) {
2378  "Unable to flash-hook bridged trunk from channel %s: %s\n",
2379  ast_channel_name(nbridge), strerror(errno));
2380  }
2385  ast_hangup(chan);
2386  goto quit;
2387  } else {
2389  analog_wait_event(p);
2390  analog_play_tone(p, idx, -1);
2394  ast_hangup(chan);
2395  goto quit;
2396  }
2397  } else if (!ast_canmatch_extension(chan, ast_channel_context(chan), exten, 1,
2398  ast_channel_caller(chan)->id.number.valid ? ast_channel_caller(chan)->id.number.str : NULL)
2399  && !analog_canmatch_featurecode(pickupexten, exten)) {
2400  ast_debug(1, "Can't match %s from '%s' in context %s\n", exten,
2401  ast_channel_caller(chan)->id.number.valid && ast_channel_caller(chan)->id.number.str
2402  ? ast_channel_caller(chan)->id.number.str : "<Unknown Caller>",
2403  ast_channel_context(chan));
2404  break;
2405  }
2406  if (!timeout) {
2407  timeout = analog_get_interdigit_timeout(p);
2408  }
2409  if (len && !ast_ignore_pattern(ast_channel_context(chan), exten)) {
2410  analog_play_tone(p, idx, -1);
2411  }
2412  }
2413  break;
2414  case ANALOG_SIG_FXSLS:
2415  case ANALOG_SIG_FXSGS:
2416  case ANALOG_SIG_FXSKS:
2417  /* check for SMDI messages */
2418  if (p->use_smdi && p->smdi_iface) {
2420  if (smdi_msg != NULL) {
2421  ast_channel_exten_set(chan, smdi_msg->fwd_st);
2422 
2423  if (smdi_msg->type == 'B')
2424  pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "b");
2425  else if (smdi_msg->type == 'N')
2426  pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "u");
2427 
2428  ast_debug(1, "Received SMDI message on %s\n", ast_channel_name(chan));
2429  } else {
2430  ast_log(LOG_WARNING, "SMDI enabled but no SMDI message present\n");
2431  }
2432  }
2433 
2434  if (p->use_callerid && (p->cid_signalling == CID_SIG_SMDI && smdi_msg)) {
2435  number = smdi_msg->calling_st;
2436 
2437  /* If we want caller id, we're in a prering state due to a polarity reversal
2438  * and we're set to use a polarity reversal to trigger the start of caller id,
2439  * grab the caller id and wait for ringing to start... */
2440  } else if (p->use_callerid && (ast_channel_state(chan) == AST_STATE_PRERING
2444  /* If set to use DTMF CID signalling, listen for DTMF */
2445  if (p->cid_signalling == CID_SIG_DTMF) {
2446  int k = 0;
2447  int oldlinearity;
2448  int timeout_ms;
2449  int ms;
2450  struct timeval start = ast_tvnow();
2451  ast_debug(1, "Receiving DTMF cid on channel %s\n", ast_channel_name(chan));
2452 
2453  oldlinearity = analog_set_linear_mode(p, idx, 0);
2454 
2455  /*
2456  * We are the only party interested in the Rx stream since
2457  * we have not answered yet. We don't need or even want DTMF
2458  * emulation. The DTMF digits can come so fast that emulation
2459  * can drop some of them.
2460  */
2461  ast_channel_lock(chan);
2463  ast_channel_unlock(chan);
2464  timeout_ms = 4000;/* This is a typical OFF time between rings. */
2465  for (;;) {
2466  struct ast_frame *f;
2467 
2468  ms = ast_remaining_ms(start, timeout_ms);
2469  res = ast_waitfor(chan, ms);
2470  if (res <= 0) {
2471  /*
2472  * We do not need to restore the analog_set_linear_mode()
2473  * or AST_FLAG_END_DTMF_ONLY flag settings since we
2474  * are hanging up the channel.
2475  */
2477  "DTMFCID timed out waiting for ring. Exiting simple switch\n");
2478  ast_hangup(chan);
2479  goto quit;
2480  }
2481  f = ast_read(chan);
2482  if (!f) {
2483  break;
2484  }
2485  if (f->frametype == AST_FRAME_DTMF) {
2486  if (k < ARRAY_LEN(dtmfbuf) - 1) {
2487  dtmfbuf[k++] = f->subclass.integer;
2488  }
2489  ast_debug(1, "CID got digit '%c'\n", f->subclass.integer);
2490  start = ast_tvnow();
2491  }
2492  ast_frfree(f);
2493  if (ast_channel_state(chan) == AST_STATE_RING ||
2495  break; /* Got ring */
2496  }
2497  }
2498  ast_channel_lock(chan);
2500  ast_channel_unlock(chan);
2501  dtmfbuf[k] = '\0';
2502 
2503  analog_set_linear_mode(p, idx, oldlinearity);
2504 
2505  /* Got cid and ring. */
2506  ast_debug(1, "CID got string '%s'\n", dtmfbuf);
2507  callerid_get_dtmf(dtmfbuf, dtmfcid, &flags);
2508  ast_debug(1, "CID is '%s', flags %d\n", dtmfcid, flags);
2509  /* If first byte is NULL, we have no cid */
2510  if (!ast_strlen_zero(dtmfcid)) {
2511  number = dtmfcid;
2512  } else {
2513  number = NULL;
2514  }
2515 
2516  /* If set to use V23 Signalling, launch our FSK gubbins and listen for it */
2517  } else if ((p->cid_signalling == CID_SIG_V23) || (p->cid_signalling == CID_SIG_V23_JP)) {
2518  namebuf[0] = 0;
2519  numbuf[0] = 0;
2520 
2522  int timeout = 10000; /* Ten seconds */
2523  struct timeval start = ast_tvnow();
2524  enum analog_event ev;
2525  int off_ms;
2526  int ms;
2527  struct timeval off_start;
2528 
2529  if (!p->usedistinctiveringdetection) {
2530  /* Disable distinctive ring timeout count */
2531  analog_set_ringtimeout(p, 0);
2532  }
2533  while ((ms = ast_remaining_ms(start, timeout))) {
2534  res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2535  if (res < 0) {
2537  "CallerID returned with error on channel '%s'\n",
2538  ast_channel_name(chan));
2539  break;
2540  }
2541  if (res == 0) {
2542  break;
2543  }
2544  if (res != 1) {
2545  continue;
2546  }
2547  if (ev == ANALOG_EVENT_NOALARM) {
2548  analog_set_alarm(p, 0);
2549  }
2550  if (p->cid_signalling == CID_SIG_V23_JP) {
2551  if (ev == ANALOG_EVENT_RINGBEGIN) {
2552  analog_off_hook(p);
2553  usleep(1);
2554  }
2555  } else {
2556  break;
2557  }
2558  }
2559 
2560  name = namebuf;
2561  number = numbuf;
2562 
2563  if (p->cid_signalling == CID_SIG_V23_JP) {
2564  analog_on_hook(p);
2565  usleep(1);
2566  }
2567 
2568  /* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
2569  off_start = ast_tvnow();
2570  off_ms = 4000;/* This is a typical OFF time between rings. */
2571  while ((ms = ast_remaining_ms(off_start, off_ms))) {
2572  struct ast_frame *f;
2573 
2574  res = ast_waitfor(chan, ms);
2575  if (res <= 0) {
2577  "CID timed out waiting for ring. Exiting simple switch\n");
2579  ast_hangup(chan);
2580  goto quit;
2581  }
2582  if (!(f = ast_read(chan))) {
2583  ast_log(LOG_WARNING, "Hangup received waiting for ring. Exiting simple switch\n");
2585  ast_hangup(chan);
2586  goto quit;
2587  }
2588  ast_frfree(f);
2589  if (ast_channel_state(chan) == AST_STATE_RING ||
2591  break; /* Got ring */
2592  }
2593 
2594  res = analog_distinctive_ring(chan, p, idx, NULL);
2596  if (res) {
2597  goto quit;
2598  }
2599  } else {
2600  ast_log(LOG_WARNING, "Unable to get caller ID space\n");
2601  }
2602  } else {
2604  "Channel %s in prering state, but I have nothing to do. Terminating simple switch, should be restarted by the actual ring.\n",
2605  ast_channel_name(chan));
2606  ast_hangup(chan);
2607  goto quit;
2608  }
2609  } else if (p->use_callerid && p->cid_start == ANALOG_CID_START_RING) {
2610  namebuf[0] = 0;
2611  numbuf[0] = 0;
2612 
2614  int timeout = 10000; /* Ten seconds */
2615  struct timeval start = ast_tvnow();
2616  enum analog_event ev;
2617  int ring_data[RING_PATTERNS] = { 0 };
2618  int ring_data_idx = 0;
2619  int ms;
2620 
2621  if (!p->usedistinctiveringdetection) {
2622  /* Disable distinctive ring timeout count */
2623  analog_set_ringtimeout(p, 0);
2624  }
2625  while ((ms = ast_remaining_ms(start, timeout))) {
2626  res = analog_get_callerid(p, namebuf, numbuf, &ev, ms);
2627  if (res < 0) {
2629  "CallerID returned with error on channel '%s'\n",
2630  ast_channel_name(chan));
2631  break;
2632  }
2633  if (res == 0) {
2634  break;
2635  }
2636  if (res != 1) {
2637  continue;
2638  }
2639  if (ev == ANALOG_EVENT_NOALARM) {
2640  analog_set_alarm(p, 0);
2641  } else if (ev == ANALOG_EVENT_POLARITY
2643  && p->polarity == POLARITY_REV) {
2644  ast_debug(1,
2645  "Hanging up due to polarity reversal on channel %d while detecting callerid\n",
2646  p->channel);
2647  p->polarity = POLARITY_IDLE;
2649  ast_hangup(chan);
2650  goto quit;
2651  } else if (ev == ANALOG_EVENT_RINGOFFHOOK
2653  && ring_data_idx < RING_PATTERNS) {
2654  /*
2655  * Detect callerid while collecting possible
2656  * distinctive ring pattern.
2657  */
2658  ring_data[ring_data_idx] = p->ringt;
2659  ++ring_data_idx;
2660  }
2661  }
2662 
2663  name = namebuf;
2664  number = numbuf;
2665 
2666  res = analog_distinctive_ring(chan, p, idx, ring_data);
2668  if (res) {
2669  goto quit;
2670  }
2671  } else {
2672  ast_log(LOG_WARNING, "Unable to get caller ID space\n");
2673  }
2674  }
2675 
2676  if (number) {
2678  }
2680 
2681  analog_handle_notify_message(chan, p, flags, -1);
2682 
2683  ast_channel_lock(chan);
2685  ast_channel_rings_set(chan, 1);
2686  ast_channel_unlock(chan);
2688  res = ast_pbx_run(chan);
2689  if (res) {
2690  ast_hangup(chan);
2691  ast_log(LOG_WARNING, "PBX exited non-zero\n");
2692  }
2693  goto quit;
2694  default:
2695  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);
2696  break;
2697  }
2699  if (res < 0) {
2700  ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
2701  }
2702  ast_hangup(chan);
2703 quit:
2704  ao2_cleanup(smdi_msg);
2706  return NULL;
2707 }
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: main/db.c:327
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define CID_SIG_V23_JP
Definition: callerid.h:62
#define CID_SIG_SMDI
Definition: callerid.h:63
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()'s,...
Definition: callerid.c:947
#define CID_SIG_DTMF
Definition: callerid.h:61
#define CID_SIG_V23
Definition: callerid.h:60
void callerid_get_dtmf(char *cidstring, char *number, int *flags)
Get and parse DTMF-based callerid.
Definition: callerid.c:201
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:122
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3176
void ast_party_name_init(struct ast_party_name *init)
Initialize the given name structure.
Definition: channel.c:1585
void ast_party_number_init(struct ast_party_number *init)
Initialize the given number structure.
Definition: channel.c:1638
void * ast_channel_tech_pvt(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3163
ast_callid ast_channel_callid(const struct ast_channel *chan)
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4292
void ast_party_name_free(struct ast_party_name *doomed)
Destroy the party name contents.
Definition: channel.c:1632
@ AST_FLAG_END_DTMF_ONLY
Definition: channel.h:1007
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:7417
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
const char * ast_channel_language(const struct ast_channel *chan)
struct ast_bridge_channel * ast_channel_get_bridge_channel(struct ast_channel *chan)
Get a reference to the channel's bridge pointer.
Definition: channel.c:10768
void ast_party_number_free(struct ast_party_number *doomed)
Destroy the party number contents.
Definition: channel.c:1685
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1568
#define AST_MAX_EXTENSION
Definition: channel.h:134
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:1291
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1817
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * strsep(char **str, const char *delims)
struct ast_features_pickup_config * ast_get_chan_features_pickup_config(struct ast_channel *chan)
Get the pickup configuration options for a channel.
#define AST_FRAME_DTMF
#define ast_frfree(fr)
int ast_callid_threadassoc_add(ast_callid callid)
Adds a known callid to thread storage of the calling thread.
Definition: logger.c:2070
int errno
int ast_parking_blind_transfer_park(struct ast_bridge_channel *parker, const char *context, const char *exten, transfer_channel_cb parked_channel_cb, struct transfer_channel_data *parked_channel_data)
Perform a blind transfer to a parking extension.
Definition: parking.c:143
int ast_parking_is_exten_park(const char *context, const char *exten)
Determine if the context/exten is a "parking" extension.
Definition: parking.c:179
int ast_parking_provider_registered(void)
Check whether a parking provider is registered.
Definition: parking.c:241
enum ast_pbx_result ast_pbx_run(struct ast_channel *c)
Execute the PBX in the current thread.
Definition: pbx.c:4762
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:4182
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
int ast_canmatch_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks for a valid matching extension.
Definition: pbx.c:4197
int ast_ignore_pattern(const char *context, const char *pattern)
Checks to see if a number should be ignored.
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:4202
int ast_pickup_call(struct ast_channel *chan)
Pickup a call.
Definition: pickup.c:199
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:8342
static void analog_set_callwaiting(struct analog_pvt *p, int callwaiting_enable)
Definition: sig_analog.c:875
static int analog_my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms)
Definition: sig_analog.c:1608
static int analog_stop_cid_detect(struct analog_pvt *p)
Definition: sig_analog.c:170
static int analog_dsp_reset_and_flush_digits(struct analog_pvt *p)
Definition: sig_analog.c:428
static void analog_increase_ss_count(void)
Definition: sig_analog.c:1637
static int analog_handle_notify_message(struct ast_channel *chan, struct analog_pvt *p, int cid_flags, int neon_mwievent)
Definition: sig_analog.c:1628
static int analog_canmatch_featurecode(const char *pickupexten, const char *exten)
Definition: sig_analog.c:1688
static int analog_flash(struct analog_pvt *p)
Definition: sig_analog.c:505
static int analog_set_linear_mode(struct analog_pvt *p, enum analog_sub sub, int linear_mode)
Definition: sig_analog.c:968
int analog_dnd(struct analog_pvt *p, int flag)
Definition: sig_analog.c:4061
static void * analog_get_bridged_channel(struct ast_channel *chan)
Definition: sig_analog.c:1670
static int analog_dsp_set_digitmode(struct analog_pvt *p, enum analog_dsp_digitmode mode)
Definition: sig_analog.c:659
const char * name
Definition: sig_analog.c:70
const char * analog_sigtype_to_str(enum analog_sigtype sigtype)
Definition: sig_analog.c:123
static void analog_decrease_ss_count(void)
Definition: sig_analog.c:1644
static int analog_wait_event(struct analog_pvt *p)
Definition: sig_analog.c:202
#define ISTRUNK(p)
Definition: sig_analog.c:107
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_wink(struct analog_pvt *p, enum analog_sub index)
Definition: sig_analog.c:674
static int analog_start_cid_detect(struct analog_pvt *p, int cid_signalling)
Definition: sig_analog.c:162
static int analog_distinctive_ring(struct ast_channel *chan, struct analog_pvt *p, int idx, int *ringdata)
Definition: sig_analog.c:1651
#define ANALOG_NEED_MFDETECT(p)
Definition: sig_analog.c:1686
#define ANALOG_MAX_CID
Definition: sig_analog.h:33
@ ANALOG_DIGITMODE_DTMF
Definition: sig_analog.h:115
@ ANALOG_DIGITMODE_MF
Definition: sig_analog.h:116
#define ANALOG_SMDI_MD_WAIT_TIMEOUT
Definition: sig_analog.h:32
#define RING_PATTERNS
Definition: sig_analog.h:35
analog_event
Definition: sig_analog.h:79
@ ANALOG_TONE_INFO
Definition: sig_analog.h:76
@ ANALOG_CID_START_RING
Definition: sig_analog.h:122
@ ANALOG_CID_START_DTMF_NOALERT
Definition: sig_analog.h:123
@ ANALOG_CID_START_POLARITY
Definition: sig_analog.h:120
@ ANALOG_CID_START_POLARITY_IN
Definition: sig_analog.h:121
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
unsigned int immediate
Definition: sig_analog.h:290
unsigned int canpark
Definition: sig_analog.h:287
unsigned int ani_wink_time
Definition: sig_analog.h:282
unsigned int usedistinctiveringdetection
Definition: sig_analog.h:298
unsigned int callwaiting
Definition: sig_analog.h:322
char call_forward[AST_MAX_EXTENSION]
Definition: sig_analog.h:354
enum analog_cid_start cid_start
Definition: sig_analog.h:315
unsigned int hidecallerid
Definition: sig_analog.h:327
unsigned int callreturn
Definition: sig_analog.h:285
unsigned int use_smdi
TRUE if SMDI (Simplified Message Desk Interface) is enabled.
Definition: sig_analog.h:303
unsigned int ani_timeout
Definition: sig_analog.h:281
unsigned int ani_info_digits
Definition: sig_analog.h:280
unsigned int cancallforward
Definition: sig_analog.h:286
char lastcid_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:340
int cid_signalling
Definition: sig_analog.h:312
unsigned int use_callerid
Definition: sig_analog.h:297
struct ast_smdi_interface * smdi_iface
The SMDI interface to get SMDI messages from.
Definition: sig_analog.h:305
Structure that contains information regarding a channel in a bridge.
struct ast_channel * chan
struct ast_flags flags
Configuration relating to call pickup.
unsigned int flags
Caller Party information.
Definition: channel.h:418
An SMDI message desk message.
Definition: smdi.h:65
char calling_st[SMDI_MAX_STATION_NUM_LEN+1]
Definition: smdi.h:70
char fwd_st[SMDI_MAX_STATION_NUM_LEN+1]
Definition: smdi.h:69
Number structure.
Definition: app_followme.c:154
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition: main/utils.c:2179
#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:936
#define MIN(a, b)
Definition: utils.h:226
#define ast_clear_flag(p, flag)
Definition: utils.h:77
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define ARRAY_LEN(a)
Definition: utils.h:661

References analog_alloc_sub(), analog_canmatch_featurecode(), ANALOG_CID_START_DTMF_NOALERT, ANALOG_CID_START_POLARITY, ANALOG_CID_START_POLARITY_IN, ANALOG_CID_START_RING, analog_decrease_ss_count(), ANALOG_DIGITMODE_DTMF, ANALOG_DIGITMODE_MF, analog_distinctive_ring(), analog_dnd(), analog_dsp_reset_and_flush_digits(), analog_dsp_set_digitmode(), ANALOG_EVENT_NOALARM, ANALOG_EVENT_POLARITY, ANALOG_EVENT_RINGBEGIN, ANALOG_EVENT_RINGOFFHOOK, analog_flash(), analog_get_bridged_channel(), analog_get_callerid(), analog_get_index, analog_handle_notify_message(), analog_increase_ss_count(), analog_lock_private(), ANALOG_MAX_CID, analog_my_getsigstr(), ANALOG_NEED_MFDETECT, analog_off_hook(), analog_on_hook(), analog_play_tone(), analog_set_alarm(), analog_set_callwaiting(), analog_set_echocanceller(), analog_set_linear_mode(), analog_set_new_owner(), analog_set_ringtimeout(), ANALOG_SIG_E911, ANALOG_SIG_EM, ANALOG_SIG_EM_E1, ANALOG_SIG_EMWINK, ANALOG_SIG_FEATB, ANALOG_SIG_FEATD, ANALOG_SIG_FEATDMF, ANALOG_SIG_FEATDMF_TA, ANALOG_SIG_FGC_CAMA, ANALOG_SIG_FGC_CAMAMF, ANALOG_SIG_FXOGS, ANALOG_SIG_FXOKS, ANALOG_SIG_FXOLS, ANALOG_SIG_FXSGS, ANALOG_SIG_FXSKS, ANALOG_SIG_FXSLS, ANALOG_SIG_SF, ANALOG_SIG_SF_FEATB, ANALOG_SIG_SF_FEATD, ANALOG_SIG_SF_FEATDMF, ANALOG_SIG_SFWINK, analog_sigtype_to_str(), ANALOG_SMDI_MD_WAIT_TIMEOUT, analog_start_cid_detect(), analog_stop_cid_detect(), ANALOG_SUB_CALLWAIT, ANALOG_SUB_REAL, ANALOG_SUB_THREEWAY, analog_swap_subs(), ANALOG_TONE_CONGESTION, ANALOG_TONE_DIALRECALL, ANALOG_TONE_DIALTONE, ANALOG_TONE_INFO, analog_unalloc_sub(), analog_unlock_private(), analog_wait_event(), analog_wink(), ast_party_caller::ani2, analog_pvt::ani_info_digits, analog_pvt::ani_timeout, analog_pvt::ani_wink_time, ao2_cleanup, ao2_ref, ARRAY_LEN, ast_callid_threadassoc_add(), ast_canmatch_extension(), ast_channel_caller(), ast_channel_callid(), ast_channel_context(), ast_channel_exten_set(), ast_channel_flags(), ast_channel_get_bridge_channel(), ast_channel_language(), ast_channel_lock, ast_channel_name(), ast_channel_rings_set(), ast_channel_tech_pvt(), ast_channel_unlock, ast_clear_flag, ast_copy_string(), ast_db_put(), ast_debug, ast_exists_extension(), AST_FLAG_END_DTMF_ONLY, AST_FRAME_DTMF, ast_frfree, ast_get_chan_features_pickup_config(), ast_hangup(), ast_ignore_pattern(), ast_log, ast_matchmore_extension(), AST_MAX_EXTENSION, ast_parking_blind_transfer_park(), ast_parking_is_exten_park(), ast_parking_provider_registered(), ast_party_name_free(), ast_party_name_init(), ast_party_number_free(), ast_party_number_init(), ast_pbx_run(), ast_pickup_call(), ast_queue_unhold(), ast_read(), ast_remaining_ms(), ast_safe_sleep(), ast_say_digit_str(), ast_set_callerid(), ast_set_flag, ast_setstate(), ast_shrink_phone_number(), ast_smdi_md_message_wait(), AST_STATE_PRERING, AST_STATE_RING, AST_STATE_RINGING, ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_tvnow(), ast_verb, ast_waitfor(), ast_waitfordigit(), ast_waitstream(), analog_pvt::call_forward, callerid_get_dtmf(), ast_smdi_md_message::calling_st, analog_pvt::callreturn, analog_pvt::callwaiting, analog_pvt::cancallforward, analog_pvt::canpark, ast_bridge_channel::chan, analog_pvt::channel, analog_pvt::cid_name, analog_pvt::cid_num, CID_SIG_DTMF, CID_SIG_SMDI, CID_SIG_V23, CID_SIG_V23_JP, analog_pvt::cid_signalling, analog_pvt::cid_start, analog_dialoperation::dialstr, analog_pvt::dop, errno, exten, ast_frame::flags, ast_channel::flags, ast_frame::frametype, ast_smdi_md_message::fwd_st, analog_pvt::hanguponpolarityswitch, analog_pvt::hidecallerid, analog_pvt::immediate, ast_frame_subclass::integer, ISTRUNK, analog_pvt::lastcid_num, len(), LOG_ERROR, LOG_WARNING, MIN, name, NULL, analog_subchannel::owner, pbx_builtin_setvar_helper(), analog_pvt::polarity, POLARITY_IDLE, POLARITY_REV, RAII_VAR, RING_PATTERNS, analog_pvt::ringt, analog_pvt::ringt_base, analog_pvt::sig, analog_pvt::smdi_iface, analog_pvt::ss_astchan, strsep(), ast_frame::subclass, analog_pvt::subs, analog_pvt::transfer, ast_smdi_md_message::type, analog_pvt::use_callerid, analog_pvt::use_smdi, and analog_pvt::usedistinctiveringdetection.

Referenced by __analog_handle_event(), analog_handle_init_event(), and analog_ss_thread_start().

◆ _analog_get_index()

static int _analog_get_index ( struct ast_channel ast,
struct analog_pvt p,
int  nullok,
const char *  fname,
unsigned long  line 
)
static

Definition at line 408 of file sig_analog.c.

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 }

References ANALOG_SUB_CALLWAIT, ANALOG_SUB_REAL, ANALOG_SUB_THREEWAY, ast_channel_name(), ast_log, analog_pvt::channel, LOG_WARNING, analog_subchannel::owner, and analog_pvt::subs.

◆ analog_all_subchannels_hungup()

static void analog_all_subchannels_hungup ( struct analog_pvt p)
static

Definition at line 553 of file sig_analog.c.

554 {
557  }
558 }
struct analog_callback analog_callbacks
Definition: chan_dahdi.c:3392
void(*const all_subchannels_hungup)(void *pvt)
Definition: sig_analog.h:213
void * chan_pvt
Definition: sig_analog.h:268

References analog_callback::all_subchannels_hungup, analog_callbacks, and analog_pvt::chan_pvt.

Referenced by analog_hangup().

◆ analog_alloc_sub()

static int analog_alloc_sub ( struct analog_pvt p,
enum analog_sub  x 
)
static

Definition at line 368 of file sig_analog.c.

369 {
371  int res;
373  if (!res) {
374  p->subs[x].allocd = 1;
375  }
376  return res;
377  }
378  return 0;
379 }
int(*const allocate_sub)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:195
unsigned int allocd
Definition: sig_analog.h:261

References analog_callback::allocate_sub, analog_subchannel::allocd, analog_callbacks, analog_pvt::chan_pvt, analog_pvt::subs, and ast_channel::x.

Referenced by __analog_handle_event(), __analog_ss_thread(), and analog_request().

◆ analog_answer()

int analog_answer ( struct analog_pvt p,
struct ast_channel ast 
)

Definition at line 1463 of file sig_analog.c.

1464 {
1465  int res = 0;
1466  int idx;
1467  int oldstate = ast_channel_state(ast);
1468 
1469  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1470  ast_setstate(ast, AST_STATE_UP);
1471  idx = analog_get_index(ast, p, 1);
1472  if (idx < 0) {
1473  idx = ANALOG_SUB_REAL;
1474  }
1475  switch (p->sig) {
1476  case ANALOG_SIG_FXSLS:
1477  case ANALOG_SIG_FXSGS:
1478  case ANALOG_SIG_FXSKS:
1479  analog_set_ringtimeout(p, 0);
1480  /* Fall through */
1481  case ANALOG_SIG_EM:
1482  case ANALOG_SIG_EM_E1:
1483  case ANALOG_SIG_EMWINK:
1484  case ANALOG_SIG_FEATD:
1485  case ANALOG_SIG_FEATDMF:
1486  case ANALOG_SIG_FEATDMF_TA:
1487  case ANALOG_SIG_E911:
1488  case ANALOG_SIG_FGC_CAMA:
1489  case ANALOG_SIG_FGC_CAMAMF:
1490  case ANALOG_SIG_FEATB:
1491  case ANALOG_SIG_SF:
1492  case ANALOG_SIG_SFWINK:
1493  case ANALOG_SIG_SF_FEATD:
1494  case ANALOG_SIG_SF_FEATDMF:
1495  case ANALOG_SIG_SF_FEATB:
1496  case ANALOG_SIG_FXOLS:
1497  case ANALOG_SIG_FXOGS:
1498  case ANALOG_SIG_FXOKS:
1499  /* Pick up the line */
1500  ast_debug(1, "Took %s off hook\n", ast_channel_name(ast));
1501  if (p->hanguponpolarityswitch) {
1502  gettimeofday(&p->polaritydelaytv, NULL);
1503  }
1504  res = analog_off_hook(p);
1505  analog_play_tone(p, idx, -1);
1506  analog_set_dialing(p, 0);
1507  if ((idx == ANALOG_SUB_REAL) && p->subs[ANALOG_SUB_THREEWAY].inthreeway) {
1508  if (oldstate == AST_STATE_RINGING) {
1509  ast_debug(1, "Finally swapping real and threeway\n");
1513  }
1514  }
1515 
1516  switch (p->sig) {
1517  case ANALOG_SIG_FXSLS:
1518  case ANALOG_SIG_FXSKS:
1519  case ANALOG_SIG_FXSGS:
1522  break;
1523  case ANALOG_SIG_FXOLS:
1524  case ANALOG_SIG_FXOKS:
1525  case ANALOG_SIG_FXOGS:
1527  break;
1528  default:
1529  break;
1530  }
1531  break;
1532  default:
1533  ast_log(LOG_WARNING, "Don't know how to answer signalling %d (channel %d)\n", p->sig, p->channel);
1534  res = -1;
1535  break;
1536  }
1537  ast_setstate(ast, AST_STATE_UP);
1538  return res;
1539 }

References analog_answer_polarityswitch(), analog_get_index, analog_off_hook(), analog_play_tone(), analog_set_dialing(), analog_set_echocanceller(), analog_set_new_owner(), analog_set_ringtimeout(), ANALOG_SIG_E911, ANALOG_SIG_EM, ANALOG_SIG_EM_E1, ANALOG_SIG_EMWINK, ANALOG_SIG_FEATB, ANALOG_SIG_FEATD, ANALOG_SIG_FEATDMF, ANALOG_SIG_FEATDMF_TA, ANALOG_SIG_FGC_CAMA, ANALOG_SIG_FGC_CAMAMF, ANALOG_SIG_FXOGS, ANALOG_SIG_FXOKS, ANALOG_SIG_FXOLS, ANALOG_SIG_FXSGS, ANALOG_SIG_FXSKS, ANALOG_SIG_FXSLS, ANALOG_SIG_SF, ANALOG_SIG_SF_FEATB, ANALOG_SIG_SF_FEATD, ANALOG_SIG_SF_FEATDMF, ANALOG_SIG_SFWINK, ANALOG_SUB_REAL, ANALOG_SUB_THREEWAY, analog_swap_subs(), analog_train_echocanceller(), ast_channel_name(), ast_debug, ast_log, ast_setstate(), AST_STATE_RINGING, AST_STATE_UP, analog_pvt::channel, analog_pvt::hanguponpolarityswitch, analog_subchannel::inthreeway, LOG_WARNING, NULL, analog_subchannel::owner, analog_pvt::polaritydelaytv, analog_pvt::sig, and analog_pvt::subs.

Referenced by dahdi_answer().

◆ analog_answer_polarityswitch()

static void analog_answer_polarityswitch ( struct analog_pvt p)
static

Definition at line 645 of file sig_analog.c.

646 {
649  }
650 }
void(*const answer_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch=yes.
Definition: sig_analog.h:167

References analog_callbacks, analog_callback::answer_polarityswitch, and analog_pvt::chan_pvt.

Referenced by __analog_handle_event(), and analog_answer().

◆ analog_attempt_transfer()

static int analog_attempt_transfer ( struct analog_pvt p)
static

Definition at line 710 of file sig_analog.c.

711 {
712  struct ast_channel *owner_real;
713  struct ast_channel *owner_3way;
714  enum ast_transfer_result xfer_res;
715  int res = 0;
716 
717  owner_real = ast_channel_ref(p->subs[ANALOG_SUB_REAL].owner);
718  owner_3way = ast_channel_ref(p->subs[ANALOG_SUB_THREEWAY].owner);
719 
720  ast_verb(3, "TRANSFERRING %s to %s\n",
721  ast_channel_name(owner_3way), ast_channel_name(owner_real));
722 
723  ast_channel_unlock(owner_real);
724  ast_channel_unlock(owner_3way);
726 
727  xfer_res = ast_bridge_transfer_attended(owner_3way, owner_real);
728  if (xfer_res != AST_BRIDGE_TRANSFER_SUCCESS) {
729  ast_softhangup(owner_3way, AST_SOFTHANGUP_DEV);
730  res = -1;
731  }
732 
733  /* Must leave with these locked. */
734  ast_channel_lock(owner_real);
736 
737  ast_channel_unref(owner_real);
738  ast_channel_unref(owner_3way);
739 
740  return res;
741 }
ast_transfer_result
Definition: bridge.h:1098
@ AST_BRIDGE_TRANSFER_SUCCESS
Definition: bridge.h:1100
enum ast_transfer_result ast_bridge_transfer_attended(struct ast_channel *to_transferee, struct ast_channel *to_transfer_target)
Attended transfer.
Definition: bridge.c:4662
#define ast_channel_ref(c)
Increase channel reference count.
Definition: channel.h:2947
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958

References analog_lock_private(), ANALOG_SUB_REAL, ANALOG_SUB_THREEWAY, analog_unlock_private(), ast_bridge_transfer_attended(), AST_BRIDGE_TRANSFER_SUCCESS, ast_channel_lock, ast_channel_name(), ast_channel_ref, ast_channel_unlock, ast_channel_unref, ast_softhangup(), AST_SOFTHANGUP_DEV, ast_verb, analog_subchannel::owner, and analog_pvt::subs.

Referenced by __analog_handle_event().

◆ analog_available()

int analog_available ( struct analog_pvt p)

Definition at line 793 of file sig_analog.c.

794 {
795  int offhook;
796 
797  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
798 
799  /* If do not disturb, definitely not */
800  if (p->dnd) {
801  return 0;
802  }
803  /* If guard time, definitely not */
804  if (p->guardtime && (time(NULL) < p->guardtime)) {
805  return 0;
806  }
807 
808  /* If no owner definitely available */
809  if (!p->owner) {
810  offhook = analog_is_off_hook(p);
811 
812  /* TDM FXO card, "onhook" means out of service (no battery on the line) */
813  if ((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || (p->sig == ANALOG_SIG_FXSGS)) {
814 #ifdef DAHDI_CHECK_HOOKSTATE
815  if (offhook) {
816  return 1;
817  }
818  return 0;
819 #endif
820  /* TDM FXS card, "offhook" means someone took the hook off so it's unavailable! */
821  } else if (offhook) {
822  ast_debug(1, "Channel %d off hook, can't use\n", p->channel);
823  /* Not available when the other end is off hook */
824  return 0;
825  }
826  return 1;
827  }
828 
829  /* If it's not an FXO, forget about call wait */
830  if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) {
831  return 0;
832  }
833 
834  if (!p->callwaiting) {
835  /* If they don't have call waiting enabled, then for sure they're unavailable at this point */
836  return 0;
837  }
838 
839  if (p->subs[ANALOG_SUB_CALLWAIT].allocd) {
840  /* If there is already a call waiting call, then we can't take a second one */
841  return 0;
842  }
843 
844  if ((ast_channel_state(p->owner) != AST_STATE_UP) &&
846  /* If the current call is not up, then don't allow the call */
847  return 0;
848  }
850  /* Can't take a call wait when the three way calling hasn't been merged yet. */
851  return 0;
852  }
853  /* We're cool */
854  return 1;
855 }
static int analog_is_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:489
unsigned int dnd
Definition: sig_analog.h:325
time_t guardtime
Definition: sig_analog.h:348

References analog_subchannel::allocd, analog_is_off_hook(), ANALOG_SIG_FXOGS, ANALOG_SIG_FXOKS, ANALOG_SIG_FXOLS, ANALOG_SIG_FXSGS, ANALOG_SIG_FXSKS, ANALOG_SIG_FXSLS, ANALOG_SUB_CALLWAIT, ANALOG_SUB_THREEWAY, ast_debug, AST_STATE_RINGING, AST_STATE_UP, analog_pvt::callwaiting, analog_pvt::channel, analog_pvt::dnd, analog_pvt::guardtime, analog_subchannel::inthreeway, NULL, analog_pvt::outgoing, analog_subchannel::owner, analog_pvt::owner, analog_pvt::sig, and analog_pvt::subs.

Referenced by available().

◆ analog_call()

int analog_call ( struct analog_pvt p,
struct ast_channel ast,
const char *  rdest,
int  timeout 
)

Definition at line 985 of file sig_analog.c.

986 {
987  int res, idx, mysig;
988  char *c, *n, *l;
989  char dest[256]; /* must be same length as p->dialdest */
990 
991  ast_debug(1, "CALLING CID_NAME: %s CID_NUM:: %s\n",
992  S_COR(ast_channel_connected(ast)->id.name.valid, ast_channel_connected(ast)->id.name.str, ""),
993  S_COR(ast_channel_connected(ast)->id.number.valid, ast_channel_connected(ast)->id.number.str, ""));
994 
995  ast_copy_string(dest, rdest, sizeof(dest));
996  ast_copy_string(p->dialdest, rdest, sizeof(p->dialdest));
997 
998  if ((ast_channel_state(ast) == AST_STATE_BUSY)) {
1000  return 0;
1001  }
1002 
1004  ast_log(LOG_WARNING, "analog_call called on %s, neither down nor reserved\n", ast_channel_name(ast));
1005  return -1;
1006  }
1007 
1008  p->dialednone = 0;
1009  analog_set_outgoing(p, 1);
1010 
1011  mysig = p->sig;
1012  if (p->outsigmod > -1) {
1013  mysig = p->outsigmod;
1014  }
1015 
1016  switch (mysig) {
1017  case ANALOG_SIG_FXOLS:
1018  case ANALOG_SIG_FXOGS:
1019  case ANALOG_SIG_FXOKS:
1020  if (p->owner == ast) {
1021  /* Normal ring, on hook */
1022 
1023  /* Don't send audio while on hook, until the call is answered */
1024  analog_set_dialing(p, 1);
1025  analog_set_cadence(p, ast); /* and set p->cidrings */
1026 
1027  /* nick@dccinc.com 4/3/03 mods to allow for deferred dialing */
1028  c = strchr(dest, '/');
1029  if (c) {
1030  c++;
1031  }
1032  if (c && (strlen(c) < p->stripmsd)) {
1033  ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1034  c = NULL;
1035  }
1036  if (c && (strlen(c) > sizeof(p->dop.dialstr) - 3 /* "Tw\0" */)) {
1037  ast_log(LOG_WARNING, "Number '%s' is longer than %d bytes\n", c, (int)sizeof(p->dop.dialstr) - 2);
1038  c = NULL;
1039  }
1040  if (c) {
1042  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "Tw%s", c);
1043  ast_debug(1, "FXO: setup deferred dialstring: %s\n", c);
1044  } else {
1045  p->dop.dialstr[0] = '\0';
1046  }
1047 
1048  if (analog_ring(p)) {
1049  ast_log(LOG_WARNING, "Unable to ring phone: %s\n", strerror(errno));
1050  return -1;
1051  }
1052  analog_set_dialing(p, 1);
1053  } else {
1054  /* Call waiting call */
1055  if (ast_channel_connected(ast)->id.number.valid && ast_channel_connected(ast)->id.number.str) {
1057  } else {
1058  p->callwait_num[0] = '\0';
1059  }
1060  if (ast_channel_connected(ast)->id.name.valid && ast_channel_connected(ast)->id.name.str) {
1062  } else {
1063  p->callwait_name[0] = '\0';
1064  }
1065 
1066  /* Call waiting tone instead */
1067  if (analog_callwait(p)) {
1068  return -1;
1069  }
1070  /* Make ring-back */
1072  ast_log(LOG_WARNING, "Unable to generate call-wait ring-back on channel %s\n", ast_channel_name(ast));
1073  }
1074 
1075  }
1078  if (l) {
1079  ast_copy_string(p->lastcid_num, l, sizeof(p->lastcid_num));
1080  } else {
1081  p->lastcid_num[0] = '\0';
1082  }
1083  if (n) {
1084  ast_copy_string(p->lastcid_name, n, sizeof(p->lastcid_name));
1085  } else {
1086  p->lastcid_name[0] = '\0';
1087  }
1088 
1089  if (p->use_callerid) {
1090  p->caller.id.name.str = p->lastcid_name;
1091  p->caller.id.number.str = p->lastcid_num;
1092  }
1093 
1095  idx = analog_get_index(ast, p, 0);
1096  if (idx > -1) {
1097  struct ast_cc_config_params *cc_params;
1098 
1099  /* This is where the initial ringing frame is queued for an analog call.
1100  * As such, this is a great time to offer CCNR to the caller if it's available.
1101  */
1102  cc_params = ast_channel_get_cc_config_params(p->subs[idx].owner);
1103  if (cc_params) {
1104  switch (ast_get_cc_monitor_policy(cc_params)) {
1105  case AST_CC_MONITOR_NEVER:
1106  break;
1107  case AST_CC_MONITOR_NATIVE:
1108  case AST_CC_MONITOR_ALWAYS:
1112  break;
1113  }
1114  }
1116  }
1117  break;
1118  case ANALOG_SIG_FXSLS:
1119  case ANALOG_SIG_FXSGS:
1120  case ANALOG_SIG_FXSKS:
1122  ast_debug(1, "Ignore possible polarity reversal on line seizure\n");
1123  p->polaritydelaytv = ast_tvnow();
1124  }
1125  /* fall through */
1126  case ANALOG_SIG_EMWINK:
1127  case ANALOG_SIG_EM:
1128  case ANALOG_SIG_EM_E1:
1129  case ANALOG_SIG_FEATD:
1130  case ANALOG_SIG_FEATDMF:
1131  case ANALOG_SIG_E911:
1132  case ANALOG_SIG_FGC_CAMA:
1133  case ANALOG_SIG_FGC_CAMAMF:
1134  case ANALOG_SIG_FEATB:
1135  case ANALOG_SIG_SFWINK:
1136  case ANALOG_SIG_SF:
1137  case ANALOG_SIG_SF_FEATD:
1138  case ANALOG_SIG_SF_FEATDMF:
1139  case ANALOG_SIG_FEATDMF_TA:
1140  case ANALOG_SIG_SF_FEATB:
1141  c = strchr(dest, '/');
1142  if (c) {
1143  c++;
1144  } else {
1145  c = "";
1146  }
1147  if (strlen(c) < p->stripmsd) {
1148  ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1149  return -1;
1150  }
1151  res = analog_start(p);
1152  if (res < 0) {
1153  if (errno != EINPROGRESS) {
1154  return -1;
1155  }
1156  }
1157  ast_debug(1, "Dialing '%s'\n", c);
1159 
1160  c += p->stripmsd;
1161 
1162  switch (mysig) {
1163  case ANALOG_SIG_FEATD:
1165  if (l) {
1166  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T*%s*%s*", l, c);
1167  } else {
1168  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T**%s*", c);
1169  }
1170  break;
1171  case ANALOG_SIG_FEATDMF:
1173  if (l) {
1174  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*00%s#*%s#", l, c);
1175  } else {
1176  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*02#*%s#", c);
1177  }
1178  break;
1179  case ANALOG_SIG_FEATDMF_TA:
1180  {
1181  const char *cic = "", *ozz = "";
1182 
1183  /* If you have to go through a Tandem Access point you need to use this */
1184 #ifndef STANDALONE
1185  ozz = pbx_builtin_getvar_helper(p->owner, "FEATDMF_OZZ");
1186  if (!ozz) {
1187  ozz = analog_defaultozz;
1188  }
1189  cic = pbx_builtin_getvar_helper(p->owner, "FEATDMF_CIC");
1190  if (!cic) {
1191  cic = analog_defaultcic;
1192  }
1193 #endif
1194  if (!ozz || !cic) {
1195  ast_log(LOG_WARNING, "Unable to dial channel of type feature group D MF tandem access without CIC or OZZ set\n");
1196  return -1;
1197  }
1198  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s%s#", ozz, cic);
1199  snprintf(p->finaldial, sizeof(p->finaldial), "M*%s#", c);
1200  p->whichwink = 0;
1201  }
1202  break;
1203  case ANALOG_SIG_E911:
1204  ast_copy_string(p->dop.dialstr, "M*911#", sizeof(p->dop.dialstr));
1205  break;
1206  case ANALOG_SIG_FGC_CAMA:
1207  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%s", c);
1208  break;
1209  case ANALOG_SIG_FGC_CAMAMF:
1210  case ANALOG_SIG_FEATB:
1211  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s#", c);
1212  break;
1213  default:
1214  if (p->pulse) {
1215  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%sw", c);
1216  } else {
1217  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T%sw", c);
1218  }
1219  break;
1220  }
1221 
1222  if (p->echotraining && (strlen(p->dop.dialstr) > 4)) {
1223  memset(p->echorest, 'w', sizeof(p->echorest) - 1);
1224  strcpy(p->echorest + (p->echotraining / 400) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
1225  p->echorest[sizeof(p->echorest) - 1] = '\0';
1226  p->echobreak = 1;
1227  p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
1228  } else {
1229  p->echobreak = 0;
1230  }
1231  analog_set_waitingfordt(p, ast);
1232  if (!res) {
1233  if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
1234  analog_on_hook(p);
1235  return -1;
1236  }
1237  } else {
1238  ast_debug(1, "Deferring dialing...\n");
1239  }
1240  analog_set_dialing(p, 1);
1241  if (ast_strlen_zero(c)) {
1242  p->dialednone = 1;
1243  }
1245  break;
1246  default:
1247  ast_debug(1, "not yet implemented\n");
1248  return -1;
1249  }
1250  return 0;
1251 }
#define AST_CC_GENERIC_MONITOR_TYPE
Definition: ccss.h:471
@ AST_CC_CCNR
Definition: ccss.h:38
@ AST_CC_MONITOR_NEVER
Definition: ccss.h:76
@ AST_CC_MONITOR_ALWAYS
Definition: ccss.h:87
@ AST_CC_MONITOR_NATIVE
Definition: ccss.h:78
@ AST_CC_MONITOR_GENERIC
Definition: ccss.h:83
enum ast_cc_monitor_policies ast_get_cc_monitor_policy(struct ast_cc_config_params *config)
Get the cc_monitor_policy.
Definition: ccss.c:884
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:4147
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
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:10660
@ AST_CONTROL_BUSY
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
static char analog_defaultozz[64]
Definition: sig_analog.c:66
static int analog_callwait(struct analog_pvt *p)
Definition: sig_analog.c:866
static void analog_set_outgoing(struct analog_pvt *p, int is_outgoing)
Definition: sig_analog.c:537
static char analog_defaultcic[64]
Definition: sig_analog.c:65
static void analog_set_cadence(struct analog_pvt *p, struct ast_channel *chan)
Definition: sig_analog.c:883
static int analog_start(struct analog_pvt *p)
Definition: sig_analog.c:513
static void analog_set_waitingfordt(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:914
static const char * analog_get_orig_dialstring(struct analog_pvt *p)
Definition: sig_analog.c:186
@ ANALOG_TONE_RINGTONE
Definition: sig_analog.h:71
unsigned int pulse
Definition: sig_analog.h:293
char callwait_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:338
char lastcid_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:341
int stripmsd
Definition: sig_analog.h:314
char callwait_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:339
struct ast_party_id id
Connected party ID.
Definition: channel.h:458

References analog_callwait(), analog_defaultcic, analog_defaultozz, analog_dial_digits(), ANALOG_DIAL_OP_REPLACE, analog_get_index, analog_get_orig_dialstring(), analog_on_hook(), analog_play_tone(), analog_ring(), analog_set_cadence(), analog_set_dialing(), analog_set_outgoing(), analog_set_waitingfordt(), ANALOG_SIG_E911, ANALOG_SIG_EM, ANALOG_SIG_EM_E1, ANALOG_SIG_EMWINK, ANALOG_SIG_FEATB, ANALOG_SIG_FEATD, ANALOG_SIG_FEATDMF, ANALOG_SIG_FEATDMF_TA, ANALOG_SIG_FGC_CAMA, ANALOG_SIG_FGC_CAMAMF, ANALOG_SIG_FXOGS, ANALOG_SIG_FXOKS, ANALOG_SIG_FXOLS, ANALOG_SIG_FXSGS, ANALOG_SIG_FXSKS, ANALOG_SIG_FXSLS, ANALOG_SIG_SF, ANALOG_SIG_SF_FEATB, ANALOG_SIG_SF_FEATD, ANALOG_SIG_SF_FEATDMF, ANALOG_SIG_SFWINK, analog_start(), ANALOG_SUB_CALLWAIT, ANALOG_SUB_REAL, ANALOG_TONE_RINGTONE, analog_pvt::answeronpolarityswitch, AST_CC_CCNR, AST_CC_GENERIC_MONITOR_TYPE, AST_CC_MONITOR_ALWAYS, AST_CC_MONITOR_GENERIC, AST_CC_MONITOR_NATIVE, AST_CC_MONITOR_NEVER, ast_channel_connected(), ast_channel_get_cc_config_params(), ast_channel_name(), AST_CONTROL_BUSY, AST_CONTROL_RINGING, ast_copy_string(), ast_debug, ast_get_cc_monitor_policy(), ast_log, ast_queue_cc_frame(), ast_queue_control(), ast_setstate(), AST_STATE_BUSY, AST_STATE_DIALING, AST_STATE_DOWN, AST_STATE_RESERVED, AST_STATE_RINGING, ast_strlen_zero(), ast_tvnow(), c, analog_pvt::caller, analog_pvt::callwait_name, analog_pvt::callwait_num, analog_pvt::dialdest, analog_pvt::dialednone, analog_dialoperation::dialstr, analog_pvt::dop, analog_pvt::echobreak, analog_pvt::echorest, analog_pvt::echotraining, errno, analog_pvt::finaldial, analog_pvt::hanguponpolarityswitch, ast_party_caller::id, ast_party_connected_line::id, analog_pvt::lastcid_name, analog_pvt::lastcid_num, LOG_WARNING, name, ast_party_id::name, NULL, ast_party_id::number, analog_dialoperation::op, analog_pvt::outsigmod, analog_subchannel::owner, analog_pvt::owner, pbx_builtin_getvar_helper(), analog_pvt::polaritydelaytv, analog_pvt::pulse, S_COR, analog_pvt::sig, ast_party_name::str, ast_party_number::str, analog_pvt::stripmsd, analog_pvt::subs, analog_pvt::use_callerid, ast_party_name::valid, ast_party_number::valid, and analog_pvt::whichwink.

Referenced by dahdi_call().

◆ analog_callwait()

static int analog_callwait ( struct analog_pvt p)
static

Definition at line 866 of file sig_analog.c.

867 {
871  }
872  return 0;
873 }
int(*const callwait)(void *pvt)
Definition: sig_analog.h:190
unsigned int callwaitingcallerid
Definition: sig_analog.h:299

References analog_callbacks, analog_callback::callwait, analog_pvt::callwaitcas, analog_pvt::callwaitingcallerid, and analog_pvt::chan_pvt.

Referenced by analog_call().

◆ analog_cancel_cidspill()

static void analog_cancel_cidspill ( struct analog_pvt p)
static

Definition at line 946 of file sig_analog.c.

947 {
950  }
951 }
void(*const cancel_cidspill)(void *pvt)
Definition: sig_analog.h:240

References analog_callbacks, analog_callback::cancel_cidspill, and analog_pvt::chan_pvt.

Referenced by __analog_handle_event(), and analog_handle_init_event().

◆ analog_canmatch_featurecode()

static int analog_canmatch_featurecode ( const char *  pickupexten,
const char *  exten 
)
static

Definition at line 1688 of file sig_analog.c.

1689 {
1690  int extlen = strlen(exten);
1691  if (!extlen) {
1692  return 1;
1693  }
1694  if (extlen < strlen(pickupexten) && !strncmp(pickupexten, exten, extlen)) {
1695  return 1;
1696  }
1697  /* hardcoded features are *60, *67, *69, *70, *72, *73, *78, *79, *82, *0 */
1698  if (exten[0] == '*' && extlen < 3) {
1699  if (extlen == 1) {
1700  return 1;
1701  }
1702  /* "*0" should be processed before it gets here */
1703  switch (exten[1]) {
1704  case '6':
1705  case '7':
1706  case '8':
1707  return 1;
1708  }
1709  }
1710  return 0;
1711 }

References exten.

Referenced by __analog_ss_thread().

◆ analog_cb_handle_dtmf()

static void analog_cb_handle_dtmf ( struct analog_pvt p,
struct ast_channel ast,
enum analog_sub  analog_index,
struct ast_frame **  dest 
)
static

Definition at line 667 of file sig_analog.c.

668 {
670  analog_callbacks.handle_dtmf(p->chan_pvt, ast, analog_index, dest);
671  }
672 }
void(*const handle_dtmf)(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
Definition: sig_analog.h:147

References analog_callbacks, analog_pvt::chan_pvt, and analog_callback::handle_dtmf.

Referenced by analog_handle_dtmf().

◆ analog_check_confirmanswer()

static int analog_check_confirmanswer ( struct analog_pvt p)
static

Definition at line 937 of file sig_analog.c.

938 {
941  }
942 
943  return 0;
944 }
int(*const check_confirmanswer)(void *pvt)
Definition: sig_analog.h:238

References analog_callbacks, analog_pvt::chan_pvt, and analog_callback::check_confirmanswer.

Referenced by __analog_handle_event(), and analog_handle_dtmf().

◆ analog_check_for_conference()

static int analog_check_for_conference ( struct analog_pvt p)
static

Definition at line 545 of file sig_analog.c.

546 {
549  }
550  return -1;
551 }
int(*const check_for_conference)(void *pvt)
Definition: sig_analog.h:216

References analog_callbacks, analog_pvt::chan_pvt, and analog_callback::check_for_conference.

Referenced by __analog_handle_event().

◆ analog_check_waitingfordt()

static int analog_check_waitingfordt ( struct analog_pvt p)
static

Definition at line 921 of file sig_analog.c.

922 {
925  }
926 
927  return 0;
928 }
int(*const check_waitingfordt)(void *pvt)
Definition: sig_analog.h:236

References analog_callbacks, analog_pvt::chan_pvt, and analog_callback::check_waitingfordt.

Referenced by __analog_handle_event().

◆ analog_cidstart_to_str()

const char* analog_cidstart_to_str ( enum analog_cid_start  cid_start)

Definition at line 249 of file sig_analog.c.

250 {
251  switch (cid_start) {
253  return "Ring";
255  return "Polarity";
257  return "Polarity_In";
259  return "DTMF";
260  }
261 
262  return "Unknown";
263 }

References ANALOG_CID_START_DTMF_NOALERT, ANALOG_CID_START_POLARITY, ANALOG_CID_START_POLARITY_IN, and ANALOG_CID_START_RING.

◆ analog_cidtype_to_str()

const char* analog_cidtype_to_str ( unsigned int  cid_type)

Definition at line 149 of file sig_analog.c.

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 }
static const struct @154 cidtypes[]
unsigned int cid_type
Definition: sig_analog.c:96

References ARRAY_LEN, cid_type, and cidtypes.

◆ analog_config_complete()

int analog_config_complete ( struct analog_pvt p)

Definition at line 4005 of file sig_analog.c.

4006 {
4007  /* No call waiting on non FXS channels */
4008  if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) {
4009  p->permcallwaiting = 0;
4010  }
4011 
4013 
4014  return 0;
4015 }
unsigned int permcallwaiting
Definition: sig_analog.h:291

References analog_set_callwaiting(), ANALOG_SIG_FXOGS, ANALOG_SIG_FXOKS, ANALOG_SIG_FXOLS, analog_pvt::permcallwaiting, and analog_pvt::sig.

Referenced by mkintf().

◆ analog_confmute()

static int analog_confmute ( struct analog_pvt p,
int  mute 
)
static

Definition at line 953 of file sig_analog.c.

954 {
957  }
958  return 0;
959 }
static int mute
Definition: chan_alsa.c:148
int(*const confmute)(void *pvt, int mute)
Definition: sig_analog.h:241

References analog_callbacks, analog_pvt::chan_pvt, analog_callback::confmute, and mute.

Referenced by __analog_handle_event().

◆ analog_deadlock_avoidance_private()

static void analog_deadlock_avoidance_private ( struct analog_pvt p)
static

Definition at line 574 of file sig_analog.c.

575 {
578  } else {
579  /* Fallback to manual avoidance if callback not present. */
581  usleep(1);
583  }
584 }
void(*const deadlock_avoidance_private)(void *pvt)
Definition: sig_analog.h:142

References analog_callbacks, analog_lock_private(), analog_unlock_private(), analog_pvt::chan_pvt, and analog_callback::deadlock_avoidance_private.

Referenced by analog_lock_sub_owner().

◆ analog_decrease_ss_count()

static void analog_decrease_ss_count ( void  )
static

Definition at line 1644 of file sig_analog.c.

1645 {
1648  }
1649 }
void(*const decrease_ss_count)(void)
Definition: sig_analog.h:221

References analog_callbacks, and analog_callback::decrease_ss_count.

Referenced by __analog_ss_thread().

◆ analog_delete()

void analog_delete ( struct analog_pvt doomed)

Delete the analog private structure.

Since
1.8
Parameters
doomedAnalog private structure to delete.

Definition at line 4000 of file sig_analog.c.

4001 {
4002  ast_free(doomed);
4003 }
#define ast_free(a)
Definition: astmm.h:180

References ast_free.

Referenced by destroy_dahdi_pvt().

◆ analog_dial_digits()

static int analog_dial_digits ( struct analog_pvt p,
enum analog_sub  sub,
struct analog_dialoperation dop 
)
static

Definition at line 521 of file sig_analog.c.

522 {
524  return analog_callbacks.dial_digits(p->chan_pvt, sub, dop);
525  }
526  return -1;
527 }
struct stasis_forward * sub
Definition: res_corosync.c:240
int(*const dial_digits)(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop)
Definition: sig_analog.h:173

References analog_callbacks, analog_pvt::chan_pvt, analog_callback::dial_digits, and sub.

Referenced by __analog_handle_event(), and analog_call().

◆ analog_distinctive_ring()

static int analog_distinctive_ring ( struct ast_channel chan,
struct analog_pvt p,
int  idx,
int *  ringdata 
)
static

Definition at line 1651 of file sig_analog.c.

1652 {
1653  if (!p->usedistinctiveringdetection) {
1654  return 0;
1655  }
1657  return analog_callbacks.distinctive_ring(chan, p->chan_pvt, idx, ringdata);
1658  }
1659  return -1;
1660 
1661 }
int(*const distinctive_ring)(struct ast_channel *chan, void *pvt, int idx, int *ringdata)
Definition: sig_analog.h:223

References analog_callbacks, analog_pvt::chan_pvt, analog_callback::distinctive_ring, and analog_pvt::usedistinctiveringdetection.

Referenced by __analog_ss_thread().

◆ analog_dnd()

int analog_dnd ( struct analog_pvt p,
int  flag 
)

Definition at line 4061 of file sig_analog.c.

4062 {
4063  if (flag == -1) {
4064  return p->dnd;
4065  }
4066 
4067  p->dnd = flag;
4068 
4069  ast_verb(3, "%s DND on channel %d\n",
4070  flag ? "Enabled" : "Disabled",
4071  p->channel);
4072  analog_publish_dnd_state(p->channel, flag ? "enabled" : "disabled");
4073 
4074  return 0;
4075 }
long int flag
Definition: f2c.h:83
static void analog_publish_dnd_state(int channel, const char *status)
Definition: sig_analog.c:4041

References analog_publish_dnd_state(), ast_verb, analog_pvt::channel, and analog_pvt::dnd.

Referenced by __analog_ss_thread(), and dahdi_dnd().

◆ analog_dsp_reset_and_flush_digits()

static int analog_dsp_reset_and_flush_digits ( struct analog_pvt p)
static

Definition at line 428 of file sig_analog.c.

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 }
int(*const dsp_reset_and_flush_digits)(void *pvt)
Definition: sig_analog.h:180

References analog_callbacks, analog_pvt::chan_pvt, and analog_callback::dsp_reset_and_flush_digits.

Referenced by __analog_ss_thread().

◆ analog_dsp_set_digitmode()

static int analog_dsp_set_digitmode ( struct analog_pvt p,
enum analog_dsp_digitmode  mode 
)
static

Definition at line 659 of file sig_analog.c.

660 {
663  }
664  return -1;
665 }
int(*const dsp_set_digitmode)(void *pvt, enum analog_dsp_digitmode mode)
Definition: sig_analog.h:179

References analog_callbacks, analog_pvt::chan_pvt, and analog_callback::dsp_set_digitmode.

Referenced by __analog_ss_thread(), and analog_hangup().

◆ analog_event2str()

static char* analog_event2str ( enum analog_event  event)
static

Definition at line 265 of file sig_analog.c.

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 }
@ ANALOG_EVENT_NEONMWI_ACTIVE
Definition: sig_analog.h:95
@ ANALOG_EVENT_NEONMWI_INACTIVE
Definition: sig_analog.h:96
@ ANALOG_EVENT_REMOVED
Definition: sig_analog.h:94
Definition: astman.c:222

References ANALOG_EVENT_ALARM, ANALOG_EVENT_DIALCOMPLETE, ANALOG_EVENT_DTMFDOWN, ANALOG_EVENT_DTMFUP, ANALOG_EVENT_EC_DISABLED, ANALOG_EVENT_EC_NLP_DISABLED, ANALOG_EVENT_EC_NLP_ENABLED, ANALOG_EVENT_HOOKCOMPLETE, ANALOG_EVENT_NEONMWI_ACTIVE, ANALOG_EVENT_NEONMWI_INACTIVE, ANALOG_EVENT_NOALARM, ANALOG_EVENT_ONHOOK, ANALOG_EVENT_POLARITY, ANALOG_EVENT_PULSE_START, ANALOG_EVENT_PULSEDIGIT, ANALOG_EVENT_REMOVED, ANALOG_EVENT_RINGBEGIN, ANALOG_EVENT_RINGEROFF, ANALOG_EVENT_RINGERON, ANALOG_EVENT_RINGOFFHOOK, ANALOG_EVENT_RX_CED_DETECTED, ANALOG_EVENT_TX_CED_DETECTED, and ANALOG_EVENT_WINKFLASH.

Referenced by __analog_handle_event(), analog_exception(), and analog_handle_init_event().

◆ analog_exception()

struct ast_frame* analog_exception ( struct analog_pvt p,
struct ast_channel ast 
)

Definition at line 3599 of file sig_analog.c.

3600 {
3601  int res;
3602  int idx;
3603  struct ast_frame *f;
3604 
3605  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
3606 
3607  idx = analog_get_index(ast, p, 1);
3608  if (idx < 0) {
3609  idx = ANALOG_SUB_REAL;
3610  }
3611 
3612  p->subs[idx].f.frametype = AST_FRAME_NULL;
3613  p->subs[idx].f.datalen = 0;
3614  p->subs[idx].f.samples = 0;
3615  p->subs[idx].f.mallocd = 0;
3616  p->subs[idx].f.offset = 0;
3617  p->subs[idx].f.subclass.integer = 0;
3618  p->subs[idx].f.delivery = ast_tv(0,0);
3619  p->subs[idx].f.src = "dahdi_exception";
3620  p->subs[idx].f.data.ptr = NULL;
3621 
3622  if (!p->owner) {
3623  /* If nobody owns us, absorb the event appropriately, otherwise
3624  we loop indefinitely. This occurs when, during call waiting, the
3625  other end hangs up our channel so that it no longer exists, but we
3626  have neither FLASH'd nor ONHOOK'd to signify our desire to
3627  change to the other channel. */
3628  res = analog_get_event(p);
3629 
3630  /* Switch to real if there is one and this isn't something really silly... */
3631  if ((res != ANALOG_EVENT_RINGEROFF) && (res != ANALOG_EVENT_RINGERON) &&
3632  (res != ANALOG_EVENT_HOOKCOMPLETE)) {
3633  ast_debug(1, "Restoring owner of channel %d on event %d\n", p->channel, res);
3635  if (p->owner && ast != p->owner) {
3636  /*
3637  * Could this even happen?
3638  * Possible deadlock because we do not have the real-call lock.
3639  */
3640  ast_log(LOG_WARNING, "Event %s on %s is not restored owner %s\n",
3642  }
3643  if (p->owner) {
3644  ast_queue_unhold(p->owner);
3645  }
3646  }
3647  switch (res) {
3648  case ANALOG_EVENT_ONHOOK:
3650  if (p->owner) {
3651  ast_verb(3, "Channel %s still has call, ringing phone\n", ast_channel_name(p->owner));
3652  analog_ring(p);
3654  } else {
3655  ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
3656  analog_event2str(res));
3657  }
3658  analog_update_conf(p);
3659  break;
3662  analog_off_hook(p);
3663  if (p->owner && (ast_channel_state(p->owner) == AST_STATE_RINGING)) {
3665  analog_set_dialing(p, 0);
3666  }
3667  break;
3669  case ANALOG_EVENT_RINGERON:
3671  /* Do nothing */
3672  break;
3674  gettimeofday(&p->flashtime, NULL);
3675  if (p->owner) {
3676  ast_verb(3, "Channel %d flashed to other channel %s\n", p->channel, ast_channel_name(p->owner));
3677  if (ast_channel_state(p->owner) != AST_STATE_UP) {
3678  /* Answer if necessary */
3681  }
3683  ast_queue_unhold(p->owner);
3684  } else {
3685  ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
3686  analog_event2str(res));
3687  }
3688  analog_update_conf(p);
3689  break;
3690  default:
3691  ast_log(LOG_WARNING, "Don't know how to absorb event %s\n", analog_event2str(res));
3692  break;
3693  }
3694  f = &p->subs[idx].f;
3695  return f;
3696  }
3697  ast_debug(1, "Exception on %d, channel %d\n", ast_channel_fd(ast, 0), p->channel);
3698  /* If it's not us, return NULL immediately */
3699  if (ast != p->owner) {
3700  ast_log(LOG_WARNING, "We're %s, not %s\n", ast_channel_name(ast), ast_channel_name(p->owner));
3701  f = &p->subs[idx].f;
3702  return f;
3703  }
3704 
3705  f = __analog_handle_event(p, ast);
3706  if (!f) {
3707  const char *name = ast_strdupa(ast_channel_name(ast));
3708 
3709  /* Tell the CDR this DAHDI device hung up */
3711  ast_channel_unlock(ast);
3712  ast_set_hangupsource(ast, name, 0);
3713  ast_channel_lock(ast);
3715  }
3716  return f;
3717 }
int ast_channel_fd(const struct ast_channel *chan, int which)