Wed Jan 8 2020 09:50:20

Asterisk developer's documentation


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/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/cel.h"
#include "asterisk/causes.h"
#include "sig_analog.h"

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 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 inthreeway)
 
int analog_available (struct analog_pvt *p)
 
int analog_call (struct analog_pvt *p, struct ast_channel *ast, 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 *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 int analog_decrease_ss_count (struct analog_pvt *p)
 
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 analog_pvt *p, 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 int analog_increase_ss_count (struct analog_pvt *p)
 
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, struct analog_callback *c, 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)
 
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)
 

Variables

static char analog_defaultcic [64] = ""
 
static char analog_defaultozz [64] = ""
 
static int analog_firstdigittimeout = 16000
 
static int analog_gendigittimeout = 8000
 
static int analog_matchdigittimeout = 3000
 
struct {
   unsigned int   cid_type
 
   const char const *   name
 
cidtypes []
 
struct {
   const char const *   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

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

Definition at line 1710 of file sig_analog.c.

Referenced by __analog_ss_thread().

#define ISTRUNK (   p)
Value:

Definition at line 104 of file sig_analog.c.

Referenced by __analog_ss_thread().

#define MIN_MS_SINCE_FLASH   ( (2000) )

2000 ms

Definition at line 58 of file sig_analog.c.

Referenced by __analog_handle_event().

#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 56 of file sig_analog.c.

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

#define POLARITY_REV   1

Function Documentation

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 2651 of file sig_analog.c.

References __analog_ss_thread(), ast_channel::_state, 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_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_bridged_channel(), AST_CAUSE_NO_ANSWER, ast_channel_lock, ast_channel_unlock, AST_CONTROL_ANSWER, AST_CONTROL_FLASH, AST_CONTROL_HOLD, AST_CONTROL_OFFHOOK, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, 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_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, analog_pvt::caller, ast_channel::caller, analog_pvt::callwaitcas, analog_pvt::channel, cid_name, analog_pvt::cid_name, cid_num, analog_pvt::cid_num, analog_pvt::cidrings, 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, errno, EVENT_FLAG_SYSTEM, f, 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, manager_event, MIN_MS_SINCE_FLASH, analog_pvt::mohsuggest, analog_pvt::msgstate, ast_party_id::name, ast_channel::name, 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, ast_channel::pbx, analog_pvt::polarity, POLARITY_IDLE, POLARITY_REV, analog_pvt::polaritydelaytv, analog_pvt::polarityonanswerdelay, ast_frame::ptr, ast_channel::rings, analog_pvt::ringt_base, S_COR, S_OR, 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().

2652 {
2653  int res, x;
2654  int mysig;
2655  enum analog_sub idx;
2656  char *c;
2657  pthread_t threadid;
2658  struct ast_channel *chan;
2659  struct ast_frame *f;
2660 
2661  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
2662 
2663  idx = analog_get_index(ast, p, 0);
2664  if (idx < 0) {
2665  return &ast_null_frame;
2666  }
2667  if (idx != ANALOG_SUB_REAL) {
2668  ast_log(LOG_ERROR, "We got an event on a non real sub. Fix it!\n");
2669  }
2670 
2671  mysig = p->sig;
2672  if (p->outsigmod > -1) {
2673  mysig = p->outsigmod;
2674  }
2675 
2676  p->subs[idx].f.frametype = AST_FRAME_NULL;
2677  p->subs[idx].f.subclass.integer = 0;
2678  p->subs[idx].f.datalen = 0;
2679  p->subs[idx].f.samples = 0;
2680  p->subs[idx].f.mallocd = 0;
2681  p->subs[idx].f.offset = 0;
2682  p->subs[idx].f.src = "dahdi_handle_event";
2683  p->subs[idx].f.data.ptr = NULL;
2684  f = &p->subs[idx].f;
2685 
2686  res = analog_get_event(p);
2687 
2688  ast_debug(1, "Got event %s(%d) on channel %d (index %u)\n", analog_event2str(res), res, p->channel, idx);
2689 
2691  analog_set_pulsedial(p, (res & ANALOG_EVENT_PULSEDIGIT) ? 1 : 0);
2692  ast_debug(1, "Detected %sdigit '%c'\n", (res & ANALOG_EVENT_PULSEDIGIT) ? "pulse ": "", res & 0xff);
2693  analog_confmute(p, 0);
2694  p->subs[idx].f.frametype = AST_FRAME_DTMF_END;
2695  p->subs[idx].f.subclass.integer = res & 0xff;
2696  analog_handle_dtmf(p, ast, idx, &f);
2697  return f;
2698  }
2699 
2700  if (res & ANALOG_EVENT_DTMFDOWN) {
2701  ast_debug(1, "DTMF Down '%c'\n", res & 0xff);
2702  /* Mute conference */
2703  analog_confmute(p, 1);
2705  p->subs[idx].f.subclass.integer = res & 0xff;
2706  analog_handle_dtmf(p, ast, idx, &f);
2707  return f;
2708  }
2709 
2710  switch (res) {
2712  ast_verb(3, "Channel %d echo canceler disabled due to CED detection\n", p->channel);
2714  break;
2715 #ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
2717  ast_verb(3, "Channel %d detected a CED tone towards the network.\n", p->channel);
2718  break;
2720  ast_verb(3, "Channel %d detected a CED tone from the network.\n", p->channel);
2721  break;
2723  ast_verb(3, "Channel %d echo canceler disabled its NLP.\n", p->channel);
2724  break;
2726  ast_verb(3, "Channel %d echo canceler enabled its NLP.\n", p->channel);
2727  break;
2728 #endif
2730  /* Stop tone if there's a pulse start and the PBX isn't started */
2731  if (!ast->pbx)
2733  break;
2735  if (p->inalarm) {
2736  break;
2737  }
2738  x = analog_is_dialing(p, idx);
2739  if (!x) { /* if not still dialing in driver */
2741  if (p->echobreak) {
2743  ast_copy_string(p->dop.dialstr, p->echorest, sizeof(p->dop.dialstr));
2745  if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
2746  int dial_err = errno;
2747  ast_log(LOG_WARNING, "Dialing failed on channel %d: %s\n", p->channel, strerror(dial_err));
2748  }
2749  p->echobreak = 0;
2750  } else {
2751  analog_set_dialing(p, 0);
2752  if ((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) {
2753  /* if thru with dialing after offhook */
2754  if (ast->_state == AST_STATE_DIALING_OFFHOOK) {
2755  ast_setstate(ast, AST_STATE_UP);
2756  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
2758  break;
2759  } else { /* if to state wait for offhook to dial rest */
2760  /* we now wait for off hook */
2762  }
2763  }
2764  if (ast->_state == AST_STATE_DIALING) {
2765  if (analog_have_progressdetect(p)) {
2766  ast_debug(1, "Done dialing, but waiting for progress detection before doing more...\n");
2767  } else if (analog_check_confirmanswer(p) || (!p->dialednone
2768  && ((mysig == ANALOG_SIG_EM) || (mysig == ANALOG_SIG_EM_E1)
2769  || (mysig == ANALOG_SIG_EMWINK) || (mysig == ANALOG_SIG_FEATD)
2770  || (mysig == ANALOG_SIG_FEATDMF_TA) || (mysig == ANALOG_SIG_FEATDMF)
2771  || (mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA)
2772  || (mysig == ANALOG_SIG_FGC_CAMAMF) || (mysig == ANALOG_SIG_FEATB)
2773  || (mysig == ANALOG_SIG_SF) || (mysig == ANALOG_SIG_SFWINK)
2774  || (mysig == ANALOG_SIG_SF_FEATD) || (mysig == ANALOG_SIG_SF_FEATDMF)
2775  || (mysig == ANALOG_SIG_SF_FEATB)))) {
2777  } else if (!p->answeronpolarityswitch) {
2778  ast_setstate(ast, AST_STATE_UP);
2779  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
2781  /* If aops=0 and hops=1, this is necessary */
2782  p->polarity = POLARITY_REV;
2783  } else {
2784  /* Start clean, so we can catch the change to REV polarity when party answers */
2785  p->polarity = POLARITY_IDLE;
2786  }
2787  }
2788  }
2789  }
2790  break;
2791  case ANALOG_EVENT_ALARM:
2792  analog_set_alarm(p, 1);
2794  /* Intentionally fall through to analog_set_echocanceller() call */
2795  case ANALOG_EVENT_ONHOOK:
2796  switch (p->sig) {
2797  case ANALOG_SIG_FXOLS:
2798  case ANALOG_SIG_FXOGS:
2799  case ANALOG_SIG_FXOKS:
2801  p->fxsoffhookstate = 0;
2802  p->onhooktime = time(NULL);
2803  p->msgstate = -1;
2804  /* Check for some special conditions regarding call waiting */
2805  if (idx == ANALOG_SUB_REAL) {
2806  /* The normal line was hung up */
2807  if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
2808  /* Need to hold the lock for real-call, private, and call-waiting call */
2810  if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
2811  /*
2812  * The call waiting call dissappeared.
2813  * This is now a normal hangup.
2814  */
2816  return NULL;
2817  }
2818 
2819  /* There's a call waiting call, so ring the phone, but make it unowned in the mean time */
2821  ast_verb(3, "Channel %d still has (callwait) call, ringing phone\n", p->channel);
2824  analog_set_new_owner(p, NULL);
2825  /* Don't start streaming audio yet if the incoming call isn't up yet */
2827  analog_set_dialing(p, 1);
2828  }
2829  /* Unlock the call-waiting call that we swapped to real-call. */
2831  analog_ring(p);
2832  } else if (p->subs[ANALOG_SUB_THREEWAY].owner) {
2833  unsigned int mssinceflash;
2834 
2835  /* Need to hold the lock for real-call, private, and 3-way call */
2837  if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
2838  ast_log(LOG_NOTICE, "Whoa, threeway disappeared kinda randomly.\n");
2839  /* Just hangup */
2840  return NULL;
2841  }
2842  if (p->owner != ast) {
2844  ast_log(LOG_WARNING, "This isn't good...\n");
2845  /* Just hangup */
2846  return NULL;
2847  }
2848 
2849  mssinceflash = ast_tvdiff_ms(ast_tvnow(), p->flashtime);
2850  ast_debug(1, "Last flash was %u ms ago\n", mssinceflash);
2851  if (mssinceflash < MIN_MS_SINCE_FLASH) {
2852  /* It hasn't been long enough since the last flashook. This is probably a bounce on
2853  hanging up. Hangup both channels now */
2854  ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel);
2858  } else if ((ast->pbx) || (ast->_state == AST_STATE_UP)) {
2859  if (p->transfer) {
2860  int inthreeway;
2861 
2862  inthreeway = p->subs[ANALOG_SUB_THREEWAY].inthreeway;
2863 
2864  /* In any case this isn't a threeway call anymore */
2867 
2868  /* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */
2869  if (!p->transfertobusy && ast->_state == AST_STATE_BUSY) {
2870  /* Swap subs and dis-own channel */
2872  /* Unlock the 3-way call that we swapped to real-call. */
2874  analog_set_new_owner(p, NULL);
2875  /* Ring the phone */
2876  analog_ring(p);
2877  } else if (!analog_attempt_transfer(p, inthreeway)) {
2878  /*
2879  * Transfer successful. Don't actually hang up at this point.
2880  * Let our channel legs of the calls die off as the transfer
2881  * percolates through the core.
2882  */
2883  break;
2884  }
2885  } else {
2888  }
2889  } else {
2890  /* Swap subs and dis-own channel */
2892  /* Unlock the 3-way call that we swapped to real-call. */
2894  analog_set_new_owner(p, NULL);
2895  /* Ring the phone */
2896  analog_ring(p);
2897  }
2898  }
2899  } else {
2900  ast_log(LOG_WARNING, "Got a hangup and my index is %u?\n", idx);
2901  }
2902  /* Fall through */
2903  default:
2905  return NULL;
2906  }
2907  break;
2909  if (p->inalarm) {
2910  break;
2911  }
2912  /* for E911, its supposed to wait for offhook then dial
2913  the second half of the dial string */
2914  if (((mysig == ANALOG_SIG_E911) || (mysig == ANALOG_SIG_FGC_CAMA) || (mysig == ANALOG_SIG_FGC_CAMAMF)) && (ast->_state == AST_STATE_DIALING_OFFHOOK)) {
2915  c = strchr(p->dialdest, '/');
2916  if (c) {
2917  c++;
2918  } else {
2919  c = p->dialdest;
2920  }
2921  if (*c) {
2922  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*0%s#", c);
2923  } else {
2924  ast_copy_string(p->dop.dialstr,"M*2#", sizeof(p->dop.dialstr));
2925  }
2926  if (strlen(p->dop.dialstr) > 4) {
2927  memset(p->echorest, 'w', sizeof(p->echorest) - 1);
2928  strcpy(p->echorest + (p->echotraining / 401) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
2929  p->echorest[sizeof(p->echorest) - 1] = '\0';
2930  p->echobreak = 1;
2931  p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
2932  } else {
2933  p->echobreak = 0;
2934  }
2935  if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
2936  int saveerr = errno;
2937  analog_on_hook(p);
2938  ast_log(LOG_WARNING, "Dialing failed on channel %d: %s\n", p->channel, strerror(saveerr));
2939  return NULL;
2940  }
2941  analog_set_dialing(p, 1);
2942  return &p->subs[idx].f;
2943  }
2944  switch (p->sig) {
2945  case ANALOG_SIG_FXOLS:
2946  case ANALOG_SIG_FXOGS:
2947  case ANALOG_SIG_FXOKS:
2948  p->fxsoffhookstate = 1;
2949  switch (ast->_state) {
2950  case AST_STATE_RINGING:
2953  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
2955  /* Make sure it stops ringing */
2956  analog_set_needringing(p, 0);
2957  analog_off_hook(p);
2958  ast_debug(1, "channel %d answered\n", p->channel);
2959 
2960  /* Cancel any running CallerID spill */
2962 
2963  analog_set_dialing(p, 0);
2964  p->callwaitcas = 0;
2965  if (analog_check_confirmanswer(p)) {
2966  /* Ignore answer if "confirm answer" is enabled */
2967  p->subs[idx].f.frametype = AST_FRAME_NULL;
2968  p->subs[idx].f.subclass.integer = 0;
2969  } else if (!ast_strlen_zero(p->dop.dialstr)) {
2970  /* nick@dccinc.com 4/3/03 - fxo should be able to do deferred dialing */
2971  res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
2972  if (res < 0) {
2973  ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d: %s\n", p->channel, strerror(errno));
2974  p->dop.dialstr[0] = '\0';
2975  return NULL;
2976  } else {
2977  ast_debug(1, "Sent FXO deferred digit string: %s\n", p->dop.dialstr);
2978  p->subs[idx].f.frametype = AST_FRAME_NULL;
2979  p->subs[idx].f.subclass.integer = 0;
2980  analog_set_dialing(p, 1);
2981  }
2982  p->dop.dialstr[0] = '\0';
2984  } else {
2985  ast_setstate(ast, AST_STATE_UP);
2987  }
2988  return &p->subs[idx].f;
2989  case AST_STATE_DOWN:
2991  ast->rings = 1;
2992  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
2994  ast_debug(1, "channel %d picked up\n", p->channel);
2995  return &p->subs[idx].f;
2996  case AST_STATE_UP:
2997  /* Make sure it stops ringing */
2998  analog_off_hook(p);
2999  /* Okay -- probably call waiting*/
3000  if (ast_bridged_channel(p->owner)) {
3002  }
3003  break;
3004  case AST_STATE_RESERVED:
3005  /* Start up dialtone */
3006  if (analog_has_voicemail(p)) {
3008  } else {
3010  }
3011  break;
3012  default:
3013  ast_log(LOG_WARNING, "FXO phone off hook in weird state %u??\n", ast->_state);
3014  }
3015  break;
3016  case ANALOG_SIG_FXSLS:
3017  case ANALOG_SIG_FXSGS:
3018  case ANALOG_SIG_FXSKS:
3019  if (ast->_state == AST_STATE_RING) {
3021  }
3022 
3023  /* Fall through */
3024  case ANALOG_SIG_EM:
3025  case ANALOG_SIG_EM_E1:
3026  case ANALOG_SIG_EMWINK:
3027  case ANALOG_SIG_FEATD:
3028  case ANALOG_SIG_FEATDMF:
3029  case ANALOG_SIG_FEATDMF_TA:
3030  case ANALOG_SIG_E911:
3031  case ANALOG_SIG_FGC_CAMA:
3032  case ANALOG_SIG_FGC_CAMAMF:
3033  case ANALOG_SIG_FEATB:
3034  case ANALOG_SIG_SF:
3035  case ANALOG_SIG_SFWINK:
3036  case ANALOG_SIG_SF_FEATD:
3037  case ANALOG_SIG_SF_FEATDMF:
3038  case ANALOG_SIG_SF_FEATB:
3039  switch (ast->_state) {
3040  case AST_STATE_PRERING:
3042  /* Fall through */
3043  case AST_STATE_DOWN:
3044  case AST_STATE_RING:
3045  ast_debug(1, "Ring detected\n");
3046  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
3048  break;
3049  case AST_STATE_RINGING:
3050  case AST_STATE_DIALING:
3051  if (p->outgoing) {
3052  ast_debug(1, "Line answered\n");
3053  if (analog_check_confirmanswer(p)) {
3054  p->subs[idx].f.frametype = AST_FRAME_NULL;
3055  p->subs[idx].f.subclass.integer = 0;
3056  } else {
3057  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
3059  ast_setstate(ast, AST_STATE_UP);
3060  }
3061  break;
3062  }
3063  /* Fall through */
3064  default:
3065  ast_log(LOG_WARNING, "Ring/Off-hook in strange state %u on channel %d\n", ast->_state, p->channel);
3066  break;
3067  }
3068  break;
3069  default:
3070  ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3071  break;
3072  }
3073  break;
3075  switch (p->sig) {
3076  case ANALOG_SIG_FXSLS:
3077  case ANALOG_SIG_FXSGS:
3078  case ANALOG_SIG_FXSKS:
3079  if (ast->_state == AST_STATE_RING) {
3081  }
3082  break;
3083  default:
3084  break;
3085  }
3086  break;
3088  if (p->inalarm) break;
3089  ast->rings++;
3090  if (ast->rings == p->cidrings) {
3091  analog_send_callerid(p, 0, &p->caller);
3092  }
3093 
3094  if (ast->rings > p->cidrings) {
3096  p->callwaitcas = 0;
3097  }
3098  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
3100  break;
3101  case ANALOG_EVENT_RINGERON:
3102  break;
3103  case ANALOG_EVENT_NOALARM:
3104  analog_set_alarm(p, 0);
3105  ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", p->channel);
3106  manager_event(EVENT_FLAG_SYSTEM, "AlarmClear",
3107  "Channel: %d\r\n", p->channel);
3108  break;
3110  if (p->inalarm) {
3111  break;
3112  }
3113  /* Remember last time we got a flash-hook */
3114  gettimeofday(&p->flashtime, NULL);
3115  switch (mysig) {
3116  case ANALOG_SIG_FXOLS:
3117  case ANALOG_SIG_FXOGS:
3118  case ANALOG_SIG_FXOKS:
3119  ast_debug(1, "Winkflash, index: %u, normal: %d, callwait: %d, thirdcall: %d\n",
3121 
3122  /* Cancel any running CallerID spill */
3124  p->callwaitcas = 0;
3125 
3126  if (idx != ANALOG_SUB_REAL) {
3127  ast_log(LOG_WARNING, "Got flash hook with index %u on channel %d?!?\n", idx, p->channel);
3128  goto winkflashdone;
3129  }
3130 
3131  if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
3132  /* Need to hold the lock for real-call, private, and call-waiting call */
3134  if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
3135  /*
3136  * The call waiting call dissappeared.
3137  * Let's just ignore this flash-hook.
3138  */
3139  ast_log(LOG_NOTICE, "Whoa, the call-waiting call disappeared.\n");
3140  goto winkflashdone;
3141  }
3142 
3143  /* Swap to call-wait */
3147  ast_debug(1, "Making %s the new owner\n", p->owner->name);
3151  }
3153 
3154  /* Start music on hold if appropriate */
3157  S_OR(p->mohsuggest, NULL),
3158  !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
3159  }
3162  S_OR(p->mohsuggest, NULL),
3163  !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
3164  }
3166 
3167  /* Unlock the call-waiting call that we swapped to real-call. */
3169  } else if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3170  if (!p->threewaycalling) {
3171  /* Just send a flash if no 3-way calling */
3173  goto winkflashdone;
3174  } else if (!analog_check_for_conference(p)) {
3175  char cid_num[256];
3176  char cid_name[256];
3177 
3178  cid_num[0] = '\0';
3179  cid_name[0] = '\0';
3180  if (p->dahditrcallerid && p->owner) {
3181  if (p->owner->caller.id.number.valid
3182  && p->owner->caller.id.number.str) {
3183  ast_copy_string(cid_num, p->owner->caller.id.number.str,
3184  sizeof(cid_num));
3185  }
3186  if (p->owner->caller.id.name.valid
3187  && p->owner->caller.id.name.str) {
3188  ast_copy_string(cid_name, p->owner->caller.id.name.str,
3189  sizeof(cid_name));
3190  }
3191  }
3192  /* XXX This section needs much more error checking!!! XXX */
3193  /* Start a 3-way call if feasible */
3194  if (!((ast->pbx) ||
3195  (ast->_state == AST_STATE_UP) ||
3196  (ast->_state == AST_STATE_RING))) {
3197  ast_debug(1, "Flash when call not up or ringing\n");
3198  goto winkflashdone;
3199  }
3201  ast_log(LOG_WARNING, "Unable to allocate three-way subchannel\n");
3202  goto winkflashdone;
3203  }
3204 
3205  /*
3206  * Make new channel
3207  *
3208  * We cannot hold the p or ast locks while creating a new
3209  * channel.
3210  */
3212  ast_channel_unlock(ast);
3214  ast_channel_lock(ast);
3216  if (!chan) {
3218  "Cannot allocate new call structure on channel %d\n",
3219  p->channel);
3221  goto winkflashdone;
3222  }
3223  if (p->dahditrcallerid) {
3224  if (!p->origcid_num) {
3225  p->origcid_num = ast_strdup(p->cid_num);
3226  }
3227  if (!p->origcid_name) {
3228  p->origcid_name = ast_strdup(p->cid_name);
3229  }
3230  ast_copy_string(p->cid_num, cid_num, sizeof(p->cid_num));
3231  ast_copy_string(p->cid_name, cid_name, sizeof(p->cid_name));
3232  }
3233  /* Swap things around between the three-way and real call */
3235  /* Disable echo canceller for better dialing */
3238  if (res) {
3239  ast_log(LOG_WARNING, "Unable to start dial recall tone on channel %d\n", p->channel);
3240  }
3241  analog_set_new_owner(p, chan);
3242  p->ss_astchan = chan;
3243  if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, p)) {
3244  ast_log(LOG_WARNING, "Unable to start simple switch on channel %d\n", p->channel);
3247  ast_hangup(chan);
3248  } else {
3249  ast_verb(3, "Started three way call on channel %d\n", p->channel);
3250 
3251  /* Start music on hold if appropriate */
3254  S_OR(p->mohsuggest, NULL),
3255  !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
3256  }
3257  }
3258  }
3259  } else {
3260  /* Already have a 3 way call */
3261  enum analog_sub orig_3way_sub;
3262 
3263  /* Need to hold the lock for real-call, private, and 3-way call */
3265  if (!p->subs[ANALOG_SUB_THREEWAY].owner) {
3266  /*
3267  * The 3-way call dissappeared.
3268  * Let's just ignore this flash-hook.
3269  */
3270  ast_log(LOG_NOTICE, "Whoa, the 3-way call disappeared.\n");
3271  goto winkflashdone;
3272  }
3273  orig_3way_sub = ANALOG_SUB_THREEWAY;
3274 
3276  /* Call is already up, drop the last person */
3277  ast_debug(1, "Got flash with three way call up, dropping last call on %d\n", p->channel);
3278  /* If the primary call isn't answered yet, use it */
3279  if ((p->subs[ANALOG_SUB_REAL].owner->_state != AST_STATE_UP) &&
3281  /* Swap back -- we're dropping the real 3-way that isn't finished yet*/
3283  orig_3way_sub = ANALOG_SUB_REAL;
3285  }
3286  /* Drop the last call and stop the conference */
3287  ast_verb(3, "Dropping three-way call on %s\n", p->subs[ANALOG_SUB_THREEWAY].owner->name);
3291  } else {
3292  /* Lets see what we're up to */
3293  if (((ast->pbx) || (ast->_state == AST_STATE_UP)) &&
3294  (p->transfertobusy || (ast->_state != AST_STATE_BUSY))) {
3295  ast_verb(3, "Building conference call with %s and %s\n",
3298  /* Put them in the threeway, and flip */
3301  if (ast->_state == AST_STATE_UP) {
3303  orig_3way_sub = ANALOG_SUB_REAL;
3304  }
3305  if (ast_bridged_channel(p->subs[orig_3way_sub].owner)) {
3306  ast_queue_control(p->subs[orig_3way_sub].owner, AST_CONTROL_UNHOLD);
3307  }
3309  } else {
3310  ast_verb(3, "Dumping incomplete call on %s\n", p->subs[ANALOG_SUB_THREEWAY].owner->name);
3312  orig_3way_sub = ANALOG_SUB_REAL;
3317  }
3319  }
3320  }
3321  ast_channel_unlock(p->subs[orig_3way_sub].owner);
3322  }
3323 winkflashdone:
3324  analog_update_conf(p);
3325  break;
3326  case ANALOG_SIG_EM:
3327  case ANALOG_SIG_EM_E1:
3328  case ANALOG_SIG_FEATD:
3329  case ANALOG_SIG_SF:
3330  case ANALOG_SIG_SFWINK:
3331  case ANALOG_SIG_SF_FEATD:
3332  case ANALOG_SIG_FXSLS:
3333  case ANALOG_SIG_FXSGS:
3334  if (p->dialing) {
3335  ast_debug(1, "Ignoring wink on channel %d\n", p->channel);
3336  } else {
3337  ast_debug(1, "Got wink in weird state %u on channel %d\n", ast->_state, p->channel);
3338  }
3339  break;
3340  case ANALOG_SIG_FEATDMF_TA:
3341  switch (p->whichwink) {
3342  case 0:
3343  ast_debug(1, "ANI2 set to '%d' and ANI is '%s'\n", p->owner->caller.ani2,
3345  p->owner->caller.ani.number.str, ""));
3346  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%d%s#",
3347  p->owner->caller.ani2,
3349  p->owner->caller.ani.number.str, ""));
3350  break;
3351  case 1:
3352  ast_copy_string(p->dop.dialstr, p->finaldial, sizeof(p->dop.dialstr));
3353  break;
3354  case 2:
3355  ast_log(LOG_WARNING, "Received unexpected wink on channel of type ANALOG_SIG_FEATDMF_TA\n");
3356  return NULL;
3357  }
3358  p->whichwink++;
3359  /* Fall through */
3360  case ANALOG_SIG_FEATDMF:
3361  case ANALOG_SIG_E911:
3362  case ANALOG_SIG_FGC_CAMAMF:
3363  case ANALOG_SIG_FGC_CAMA:
3364  case ANALOG_SIG_FEATB:
3365  case ANALOG_SIG_SF_FEATDMF:
3366  case ANALOG_SIG_SF_FEATB:
3367  case ANALOG_SIG_EMWINK:
3368  /* FGD MF and EMWINK *Must* wait for wink */
3369  if (!ast_strlen_zero(p->dop.dialstr)) {
3370  res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3371  if (res < 0) {
3372  ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d: %s\n", p->channel, strerror(errno));
3373  p->dop.dialstr[0] = '\0';
3374  return NULL;
3375  } else {
3376  ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3377  }
3378  }
3379  p->dop.dialstr[0] = '\0';
3380  break;
3381  default:
3382  ast_log(LOG_WARNING, "Don't know how to handle ring/off hook for signalling %d\n", p->sig);
3383  }
3384  break;
3386  if (p->inalarm) break;
3387  if (analog_check_waitingfordt(p)) {
3388  break;
3389  }
3390  switch (mysig) {
3391  case ANALOG_SIG_FXSLS: /* only interesting for FXS */
3392  case ANALOG_SIG_FXSGS:
3393  case ANALOG_SIG_FXSKS:
3394  case ANALOG_SIG_EM:
3395  case ANALOG_SIG_EM_E1:
3396  case ANALOG_SIG_EMWINK:
3397  case ANALOG_SIG_FEATD:
3398  case ANALOG_SIG_SF:
3399  case ANALOG_SIG_SFWINK:
3400  case ANALOG_SIG_SF_FEATD:
3401  if (!ast_strlen_zero(p->dop.dialstr)) {
3402  res = analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop);
3403  if (res < 0) {
3404  ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d: %s\n", p->channel, strerror(errno));
3405  p->dop.dialstr[0] = '\0';
3406  return NULL;
3407  } else {
3408  ast_debug(1, "Sent deferred digit string on channel %d: %s\n", p->channel, p->dop.dialstr);
3409  }
3410  }
3411  p->dop.dialstr[0] = '\0';
3413  break;
3414  case ANALOG_SIG_FEATDMF:
3415  case ANALOG_SIG_FEATDMF_TA:
3416  case ANALOG_SIG_E911:
3417  case ANALOG_SIG_FGC_CAMA:
3418  case ANALOG_SIG_FGC_CAMAMF:
3419  case ANALOG_SIG_FEATB:
3420  case ANALOG_SIG_SF_FEATDMF:
3421  case ANALOG_SIG_SF_FEATB:
3422  ast_debug(1, "Got hook complete in MF FGD, waiting for wink now on channel %d\n",p->channel);
3423  break;
3424  default:
3425  break;
3426  }
3427  break;
3428  case ANALOG_EVENT_POLARITY:
3429  /*
3430  * If we get a Polarity Switch event, this could be
3431  * due to line seizure, remote end connect or remote end disconnect.
3432  *
3433  * Check to see if we should change the polarity state and
3434  * mark the channel as UP or if this is an indication
3435  * of remote end disconnect.
3436  */
3437 
3438  if (p->polarityonanswerdelay > 0) {
3439  /* check if event is not too soon after OffHook or Answer */
3441  switch (ast->_state) {
3442  case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3443  case AST_STATE_RINGING: /*!< Remote end is ringing */
3444  if (p->answeronpolarityswitch) {
3445  ast_debug(1, "Answering on polarity switch! channel %d\n", p->channel);
3447  p->polarity = POLARITY_REV;
3448  if (p->hanguponpolarityswitch) {
3449  p->polaritydelaytv = ast_tvnow();
3450  }
3451  } else {
3452  ast_debug(1, "Ignore Answer on polarity switch, channel %d\n", p->channel);
3453  }
3454  break;
3455 
3456  case AST_STATE_UP: /*!< Line is up */
3457  case AST_STATE_RING: /*!< Line is ringing */
3458  if (p->hanguponpolarityswitch) {
3459  ast_debug(1, "HangingUp on polarity switch! channel %d\n", p->channel);
3461  p->polarity = POLARITY_IDLE;
3462  } else {
3463  ast_debug(1, "Ignore Hangup on polarity switch, channel %d\n", p->channel);
3464  }
3465  break;
3466 
3467  case AST_STATE_DOWN: /*!< Channel is down and available */
3468  case AST_STATE_RESERVED: /*!< Channel is down, but reserved */
3469  case AST_STATE_OFFHOOK: /*!< Channel is off hook */
3470  case AST_STATE_BUSY: /*!< Line is busy */
3471  case AST_STATE_DIALING_OFFHOOK: /*!< Digits (or equivalent) have been dialed while offhook */
3472  case AST_STATE_PRERING: /*!< Channel has detected an incoming call and is waiting for ring */
3473  default:
3475  ast_debug(1, "Ignoring Polarity switch on channel %d, state %u\n", p->channel, ast->_state);
3476  }
3477  break;
3478  }
3479 
3480  } else {
3481  /* event is too soon after OffHook or Answer */
3482  switch (ast->_state) {
3483  case AST_STATE_DIALING: /*!< Digits (or equivalent) have been dialed */
3484  case AST_STATE_RINGING: /*!< Remote end is ringing */
3485  if (p->answeronpolarityswitch) {
3486  ast_debug(1, "Polarity switch detected but NOT answering (too close to OffHook event) on channel %d, state %u\n", p->channel, ast->_state);
3487  }
3488  break;
3489 
3490  case AST_STATE_UP: /*!< Line is up */
3491  case AST_STATE_RING: /*!< Line is ringing */
3492  if (p->hanguponpolarityswitch) {
3493  ast_debug(1, "Polarity switch detected but NOT hanging up (too close to Answer event) on channel %d, state %u\n", p->channel, ast->_state);
3494  }
3495  break;
3496 
3497  default:
3499  ast_debug(1, "Polarity switch detected (too close to previous event) on channel %d, state %u\n", p->channel, ast->_state);
3500  }
3501  break;
3502  }
3503  }
3504  }
3505 
3506  /* Added more log_debug information below to provide a better indication of what is going on */
3507  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->_state, p->polarity, p->answeronpolarityswitch, p->hanguponpolarityswitch, p->polarityonanswerdelay, ast_tvdiff_ms(ast_tvnow(), p->polaritydelaytv) );
3508  break;
3509  default:
3510  ast_debug(1, "Dunno what to do with event %d on channel %d\n", res, p->channel);
3511  }
3512  return &p->subs[idx].f;
3513 }
static int analog_send_callerid(struct analog_pvt *p, int cwcid, struct ast_party_caller *caller)
Definition: sig_analog.c:373
union ast_frame_subclass subclass
Definition: frame.h:146
int ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2804
char cid_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:303
#define POLARITY_IDLE
Definition: sig_analog.c:56
#define analog_get_index(ast, p, nullok)
Definition: sig_analog.c:389
unsigned int threewaycalling
Definition: sig_analog.h:280
#define ast_channel_lock(chan)
Definition: channel.h:2466
Main Channel structure associated with a channel.
Definition: channel.h:742
#define POLARITY_REV
Definition: sig_analog.c:57
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
static int analog_unalloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition: sig_analog.c:363
int rings
Definition: channel.h:840
int offset
Definition: frame.h:156
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame with payload.
Definition: channel.c:1601
struct ast_party_caller caller
Definition: sig_analog.h:327
struct ast_frame ast_null_frame
Definition: frame.c:131
struct ast_party_caller caller
Channel Caller ID information.
Definition: channel.h:804
struct timeval polaritydelaytv
Definition: sig_analog.h:331
static int analog_check_for_conference(struct analog_pvt *p)
Definition: sig_analog.c:527
#define ast_strdup(a)
Definition: astmm.h:109
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:422
int polarity
Definition: sig_analog.h:330
static int analog_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:592
struct ast_party_name name
Subscriber name.
Definition: channel.h:290
void * ptr
Definition: frame.h:160
char mohsuggest[MAX_MUSICCLASS]
Definition: sig_analog.h:301
static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
Definition: sig_analog.c:420
int echotraining
Definition: sig_analog.h:296
int ringt_base
Definition: sig_analog.h:346
#define LOG_WARNING
Definition: logger.h:144
static void analog_lock_sub_owner(struct analog_pvt *pvt, enum analog_sub sub_idx)
Definition: sig_analog.c:571
static int analog_train_echocanceller(struct analog_pvt *p)
Definition: sig_analog.c:463
char dialdest[256]
Definition: sig_analog.h:332
char finaldial[64]
Definition: sig_analog.h:336
struct ast_channel * owner
Definition: sig_analog.h:245
static int analog_get_event(struct analog_pvt *p)
Definition: sig_analog.c:191
static void analog_start_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:616
void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub idx, struct ast_frame **dest)
Definition: sig_analog.c:1589
char * str
Subscriber name (Malloced)
Definition: channel.h:214
unsigned int dialing
Definition: sig_analog.h:309
struct ast_channel * ss_astchan
Definition: sig_analog.h:342
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
unsigned int transfertobusy
Definition: sig_analog.h:282
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:90
struct timeval flashtime
Definition: sig_analog.h:334
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:157
int polarityonanswerdelay
Definition: sig_analog.h:298
#define ast_verb(level,...)
Definition: logger.h:243
char echorest[20]
Definition: sig_analog.h:329
static int analog_get_sub_fd(struct analog_pvt *p, enum analog_sub sub)
Definition: sig_analog.c:1702
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
Definition: channel.c:1581
struct ast_channel * owner
Definition: sig_analog.h:260
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
static void analog_unlock_private(struct analog_pvt *p)
Definition: sig_analog.c:542
#define EVENT_FLAG_SYSTEM
Definition: manager.h:71
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static int analog_alloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition: sig_analog.c:350
struct ast_party_id ani
Automatic Number Identification (ANI)
Definition: channel.h:377
int onhooktime
Definition: sig_analog.h:264
static void * __analog_ss_thread(void *data)
Definition: sig_analog.c:1739
static int analog_dial_digits(struct analog_pvt *p, enum analog_sub sub, struct analog_dialoperation *dop)
Definition: sig_analog.c:503
const char * src
Definition: frame.h:158
static void analog_swap_subs(struct analog_pvt *p, enum analog_sub a, enum analog_sub b)
Definition: sig_analog.c:330
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
int datalen
Definition: frame.h:148
#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:83
int ast_softhangup(struct ast_channel *chan, int reason)
Softly hangup up a channel.
Definition: channel.c:2746
static void analog_answer_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:622
#define AST_CAUSE_NO_ANSWER
Definition: causes.h:108
analog_sub
Definition: sig_analog.h:101
static int analog_stop_callwait(struct analog_pvt *p)
Definition: sig_analog.c:870
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:436
unsigned int dialednone
Definition: sig_analog.h:308
char cid_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:302
static void analog_set_inthreeway(struct analog_pvt *p, enum analog_sub sub, int inthreeway)
Definition: sig_analog.c:995
static int analog_on_hook(struct analog_pvt *p)
Definition: sig_analog.c:511
struct analog_dialoperation dop
Definition: sig_analog.h:263
#define LOG_ERROR
Definition: logger.h:155
static char * analog_event2str(enum analog_event event)
Definition: sig_analog.c:247
unsigned int outgoing
Definition: sig_analog.h:313
static int analog_attempt_transfer(struct analog_pvt *p, int inthreeway)
Definition: sig_analog.c:688
int ani2
Automatic Number Identification 2 (Info Digits)
Definition: channel.h:380
enum ast_channel_state _state
Definition: channel.h:839
struct ast_channel * ast_bridged_channel(struct ast_channel *chan)
Find bridged channel.
Definition: channel.c:7160
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
unsigned int inthreeway
Definition: sig_analog.h:247
#define LOG_NOTICE
Definition: logger.h:133
char * origcid_num
Definition: sig_analog.h:337
int ast_softhangup_nolock(struct ast_channel *chan, int reason)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2733
static int analog_check_confirmanswer(struct analog_pvt *p)
Definition: sig_analog.c:952
#define ast_channel_unlock(chan)
Definition: channel.h:2467
int errno
int whichwink
Definition: sig_analog.h:335
unsigned int dahditrcallerid
Definition: sig_analog.h:274
static struct ast_format f[]
Definition: format_g726.c:181
int msgstate
-1 = unknown, 0 = no messages, 1 = new messages available
Definition: sig_analog.h:267
char * origcid_name
Definition: sig_analog.h:338
static int analog_has_voicemail(struct analog_pvt *p)
Definition: sig_analog.c:659
static void analog_set_pulsedial(struct analog_pvt *p, int flag)
Definition: sig_analog.c:978
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:158
int mallocd
Definition: frame.h:152
static int analog_confmute(struct analog_pvt *p, int mute)
Definition: sig_analog.c:970
static int analog_check_waitingfordt(struct analog_pvt *p)
Definition: sig_analog.c:935
static void analog_set_needringing(struct analog_pvt *p, int value)
Definition: sig_analog.c:600
int cidrings
Definition: sig_analog.h:328
static void analog_lock_private(struct analog_pvt *p)
Definition: sig_analog.c:549
static int analog_set_echocanceller(struct analog_pvt *p, int enable)
Definition: sig_analog.c:455
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
static int analog_is_dialing(struct analog_pvt *p, enum analog_sub index)
Definition: sig_analog.c:667
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7119
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:1608
static int analog_have_progressdetect(struct analog_pvt *p)
Definition: sig_analog.c:207
#define MIN_MS_SINCE_FLASH
Definition: sig_analog.c:58
static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
Definition: sig_analog.c:428
Data structure associated with a single frame of data.
Definition: frame.h:142
enum analog_sigtype outsigmod
Definition: sig_analog.h:295
unsigned int inalarm
Definition: sig_analog.h:314
int fxsoffhookstate
Definition: sig_analog.h:265
static void analog_cancel_cidspill(struct analog_pvt *p)
Definition: sig_analog.c:961
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
Definition: sig_analog.h:321
struct ast_frame f
Definition: sig_analog.h:246
enum ast_frame_type frametype
Definition: frame.h:144
static int analog_update_conf(struct analog_pvt *p)
Definition: sig_analog.c:756
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:229
unsigned int transfer
Definition: sig_analog.h:281
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
static void analog_get_and_handle_alarms(struct analog_pvt *p)
Definition: sig_analog.c:1687
unsigned int hanguponpolarityswitch
Definition: sig_analog.h:275
static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
Definition: sig_analog.c:919
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:219
static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
Definition: sig_analog.c:903
enum analog_sigtype sig
Definition: sig_analog.h:254
union ast_frame::@172 data
unsigned int echobreak
Definition: sig_analog.h:311
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:247
static void analog_set_alarm(struct analog_pvt *p, int in_alarm)
Definition: sig_analog.c:911
static int analog_ring(struct analog_pvt *p)
Definition: sig_analog.c:479
int samples
Definition: frame.h:150
unsigned int answeronpolarityswitch
Definition: sig_analog.h:270
struct ast_pbx * pbx
Definition: channel.h:761
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292
static void* __analog_ss_thread ( void *  data)
static

Definition at line 1739 of file sig_analog.c.

References ast_channel::_state, 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_NONE, ANALOG_EVENT_POLARITY, ANALOG_EVENT_RINGBEGIN, ANALOG_EVENT_RINGOFFHOOK, analog_firstdigittimeout, analog_flash(), analog_gendigittimeout, analog_get_bridged_channel(), analog_get_callerid(), analog_get_index, analog_handle_notify_message(), analog_increase_ss_count(), analog_matchdigittimeout, 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_wait_event(), analog_wink(), ARRAY_LEN, ast_bridged_channel(), ast_canmatch_extension(), ast_clear_flag, AST_CONTROL_UNHOLD, ast_copy_string(), ast_db_put(), ast_debug, ast_exists_extension(), AST_FLAG_END_DTMF_ONLY, AST_FRAME_DTMF, ast_frfree, ast_hangup(), ast_ignore_pattern(), ast_log(), ast_masq_park_call_exten(), ast_matchmore_extension(), AST_MAX_EXTENSION, ast_parking_ext_valid(), ast_party_name_free(), ast_party_name_init(), ast_party_number_free(), ast_party_number_init(), ast_pbx_run(), ast_pickup_call(), ast_pickup_ext(), ast_queue_control(), 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_destroy(), ast_smdi_md_message_wait(), AST_STATE_PRERING, AST_STATE_RING, AST_STATE_RINGING, ast_streamfile(), ast_strlen_zero(), ast_tvdiff_ms(), ast_tvnow(), ast_verb, ast_waitfor(), ast_waitfordigit(), ast_waitstream(), ASTOBJ_UNREF, analog_pvt::call_forward, ast_channel::caller, callerid_free(), callerid_get_dtmf(), ast_smdi_md_message::calling_st, analog_pvt::callreturn, analog_pvt::callwaiting, analog_pvt::cancallforward, analog_pvt::canpark, 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, ast_channel::context, analog_dialoperation::dialstr, analog_pvt::dop, errno, exten, ast_channel::exten, f, callerid_state::flags, ast_frame::frametype, ast_smdi_md_message::fwd_st, analog_pvt::hanguponpolarityswitch, analog_pvt::hidecallerid, ast_party_caller::id, analog_pvt::immediate, ast_frame_subclass::integer, ISTRUNK, ast_channel::language, analog_pvt::lastcid_num, len(), LOG_WARNING, name, ast_party_id::name, ast_channel::name, ast_party_id::number, analog_subchannel::owner, pbx_builtin_setvar_helper(), analog_pvt::polarity, POLARITY_IDLE, POLARITY_REV, RING_PATTERNS, ast_channel::rings, analog_pvt::ringt, analog_pvt::ringt_base, analog_pvt::sig, analog_pvt::smdi_iface, analog_pvt::ss_astchan, ast_party_number::str, strsep(), ast_frame::subclass, analog_pvt::subs, ast_channel::tech_pvt, analog_pvt::transfer, ast_smdi_md_message::type, analog_pvt::use_callerid, analog_pvt::use_smdi, and ast_party_number::valid.

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

1740 {
1741  struct analog_pvt *p = data;
1742  struct ast_channel *chan = p->ss_astchan;
1743  char exten[AST_MAX_EXTENSION] = "";
1744  char exten2[AST_MAX_EXTENSION] = "";
1745  char dtmfcid[300];
1746  char dtmfbuf[300];
1747  char namebuf[ANALOG_MAX_CID];
1748  char numbuf[ANALOG_MAX_CID];
1749  struct callerid_state *cs = NULL;
1750  char *name = NULL, *number = NULL;
1751  int flags = 0;
1752  struct ast_smdi_md_message *smdi_msg = NULL;
1753  int timeout;
1754  int getforward = 0;
1755  char *s1, *s2;
1756  int len = 0;
1757  int res;
1758  int idx;
1759 
1761 
1762  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1763 
1764  if (!chan) {
1765  /* What happened to the channel? */
1766  goto quit;
1767  }
1768  /* in the bizarre case where the channel has become a zombie before we
1769  even get started here, abort safely
1770  */
1771  if (!chan->tech_pvt) {
1772  ast_log(LOG_WARNING, "Channel became a zombie before simple switch could be started (%s)\n", chan->name);
1773  ast_hangup(chan);
1774  goto quit;
1775  }
1776 
1777  ast_verb(3, "Starting simple switch on '%s'\n", chan->name);
1778  idx = analog_get_index(chan, p, 0);
1779  if (idx < 0) {
1780  ast_hangup(chan);
1781  goto quit;
1782  }
1784  switch (p->sig) {
1785  case ANALOG_SIG_FEATD:
1786  case ANALOG_SIG_FEATDMF:
1787  case ANALOG_SIG_FEATDMF_TA:
1788  case ANALOG_SIG_E911:
1789  case ANALOG_SIG_FGC_CAMAMF:
1790  case ANALOG_SIG_FEATB:
1791  case ANALOG_SIG_EMWINK:
1792  case ANALOG_SIG_SF_FEATD:
1793  case ANALOG_SIG_SF_FEATDMF:
1794  case ANALOG_SIG_SF_FEATB:
1795  case ANALOG_SIG_SFWINK:
1796  if (analog_wink(p, idx))
1797  goto quit;
1798  /* Fall through */
1799  case ANALOG_SIG_EM:
1800  case ANALOG_SIG_EM_E1:
1801  case ANALOG_SIG_SF:
1802  case ANALOG_SIG_FGC_CAMA:
1803  res = analog_play_tone(p, idx, -1);
1804 
1806 
1807  /* set digit mode appropriately */
1808  if (ANALOG_NEED_MFDETECT(p)) {
1810  } else {
1812  }
1813 
1814  memset(dtmfbuf, 0, sizeof(dtmfbuf));
1815  /* Wait for the first digit only if immediate=no */
1816  if (!p->immediate) {
1817  /* Wait for the first digit (up to 5 seconds). */
1818  res = ast_waitfordigit(chan, 5000);
1819  } else {
1820  res = 0;
1821  }
1822  if (res > 0) {
1823  /* save first char */
1824  dtmfbuf[0] = res;
1825  switch (p->sig) {
1826  case ANALOG_SIG_FEATD:
1827  case ANALOG_SIG_SF_FEATD:
1828  res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
1829  if (res > 0) {
1830  res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
1831  }
1832  if (res < 1) {
1834  }
1835  break;
1836  case ANALOG_SIG_FEATDMF_TA:
1837  res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
1838  if (res < 1) {
1840  }
1841  if (analog_wink(p, idx)) {
1842  goto quit;
1843  }
1844  dtmfbuf[0] = 0;
1845  /* Wait for the first digit (up to 5 seconds). */
1846  res = ast_waitfordigit(chan, 5000);
1847  if (res <= 0) {
1848  break;
1849  }
1850  dtmfbuf[0] = res;
1851  /* fall through intentionally */
1852  case ANALOG_SIG_FEATDMF:
1853  case ANALOG_SIG_E911:
1854  case ANALOG_SIG_FGC_CAMAMF:
1855  case ANALOG_SIG_SF_FEATDMF:
1856  res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
1857  /* if international caca, do it again to get real ANO */
1858  if ((p->sig == ANALOG_SIG_FEATDMF) && (dtmfbuf[1] != '0')
1859  && (strlen(dtmfbuf) != 14)) {
1860  if (analog_wink(p, idx)) {
1861  goto quit;
1862  }
1863  dtmfbuf[0] = 0;
1864  /* Wait for the first digit (up to 5 seconds). */
1865  res = ast_waitfordigit(chan, 5000);
1866  if (res <= 0) {
1867  break;
1868  }
1869  dtmfbuf[0] = res;
1870  res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
1871  }
1872  if (res > 0) {
1873  /* if E911, take off hook */
1874  if (p->sig == ANALOG_SIG_E911) {
1875  analog_off_hook(p);
1876  }
1877  res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "#", 3000);
1878  }
1879  if (res < 1) {
1881  }
1882  break;
1883  case ANALOG_SIG_FEATB:
1884  case ANALOG_SIG_SF_FEATB:
1885  res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
1886  if (res < 1) {
1888  }
1889  break;
1890  case ANALOG_SIG_EMWINK:
1891  /* if we received a '*', we are actually receiving Feature Group D
1892  dial syntax, so use that mode; otherwise, fall through to normal
1893  mode
1894  */
1895  if (res == '*') {
1896  res = analog_my_getsigstr(chan, dtmfbuf + 1, "*", 3000);
1897  if (res > 0) {
1898  res = analog_my_getsigstr(chan, dtmfbuf + strlen(dtmfbuf), "*", 3000);
1899  }
1900  if (res < 1) {
1902  }
1903  break;
1904  }
1905  default:
1906  /* If we got the first digit, get the rest */
1907  len = 1;
1908  dtmfbuf[len] = '\0';
1909  while ((len < AST_MAX_EXTENSION-1) && ast_matchmore_extension(chan, chan->context, dtmfbuf, 1, p->cid_num)) {
1910  if (ast_exists_extension(chan, chan->context, dtmfbuf, 1, p->cid_num)) {
1911  timeout = analog_matchdigittimeout;
1912  } else {
1913  timeout = analog_gendigittimeout;
1914  }
1915  res = ast_waitfordigit(chan, timeout);
1916  if (res < 0) {
1917  ast_debug(1, "waitfordigit returned < 0...\n");
1918  ast_hangup(chan);
1919  goto quit;
1920  } else if (res) {
1921  dtmfbuf[len++] = res;
1922  dtmfbuf[len] = '\0';
1923  } else {
1924  break;
1925  }
1926  }
1927  break;
1928  }
1929  }
1930  if (res == -1) {
1931  ast_log(LOG_WARNING, "getdtmf on channel %d: %s\n", p->channel, strerror(errno));
1932  ast_hangup(chan);
1933  goto quit;
1934  } else if (res < 0) {
1935  ast_debug(1, "Got hung up before digits finished\n");
1936  ast_hangup(chan);
1937  goto quit;
1938  }
1939 
1940  if (p->sig == ANALOG_SIG_FGC_CAMA) {
1941  char anibuf[100];
1942 
1943  if (ast_safe_sleep(chan,1000) == -1) {
1944  ast_hangup(chan);
1945  goto quit;
1946  }
1947  analog_off_hook(p);
1949  res = analog_my_getsigstr(chan, anibuf, "#", 10000);
1950  if ((res > 0) && (strlen(anibuf) > 2)) {
1951  if (anibuf[strlen(anibuf) - 1] == '#') {
1952  anibuf[strlen(anibuf) - 1] = 0;
1953  }
1954  ast_set_callerid(chan, anibuf + 2, NULL, anibuf + 2);
1955  }
1957  }
1958 
1959  ast_copy_string(exten, dtmfbuf, sizeof(exten));
1960  if (ast_strlen_zero(exten)) {
1961  ast_copy_string(exten, "s", sizeof(exten));
1962  }
1963  if (p->sig == ANALOG_SIG_FEATD || p->sig == ANALOG_SIG_EMWINK) {
1964  /* Look for Feature Group D on all E&M Wink and Feature Group D trunks */
1965  if (exten[0] == '*') {
1966  char *stringp=NULL;
1967  ast_copy_string(exten2, exten, sizeof(exten2));
1968  /* Parse out extension and callerid */
1969  stringp=exten2 +1;
1970  s1 = strsep(&stringp, "*");
1971  s2 = strsep(&stringp, "*");
1972  if (s2) {
1973  if (!ast_strlen_zero(p->cid_num)) {
1974  ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
1975  } else {
1976  ast_set_callerid(chan, s1, NULL, s1);
1977  }
1978  ast_copy_string(exten, s2, sizeof(exten));
1979  } else {
1980  ast_copy_string(exten, s1, sizeof(exten));
1981  }
1982  } else if (p->sig == ANALOG_SIG_FEATD) {
1983  ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
1984  }
1985  }
1986  if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
1987  if (exten[0] == '*') {
1988  char *stringp=NULL;
1989  ast_copy_string(exten2, exten, sizeof(exten2));
1990  /* Parse out extension and callerid */
1991  stringp=exten2 +1;
1992  s1 = strsep(&stringp, "#");
1993  s2 = strsep(&stringp, "#");
1994  if (s2) {
1995  if (!ast_strlen_zero(p->cid_num)) {
1996  ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
1997  } else {
1998  if (*(s1 + 2)) {
1999  ast_set_callerid(chan, s1 + 2, NULL, s1 + 2);
2000  }
2001  }
2002  ast_copy_string(exten, s2 + 1, sizeof(exten));
2003  } else {
2004  ast_copy_string(exten, s1 + 2, sizeof(exten));
2005  }
2006  } else {
2007  ast_log(LOG_WARNING, "Got a non-Feature Group D input on channel %d. Assuming E&M Wink instead\n", p->channel);
2008  }
2009  }
2010  if ((p->sig == ANALOG_SIG_E911) || (p->sig == ANALOG_SIG_FGC_CAMAMF)) {
2011  if (exten[0] == '*') {
2012  char *stringp=NULL;
2013  ast_copy_string(exten2, exten, sizeof(exten2));
2014  /* Parse out extension and callerid */
2015  stringp=exten2 +1;
2016  s1 = strsep(&stringp, "#");
2017  s2 = strsep(&stringp, "#");
2018  if (s2 && (*(s2 + 1) == '0')) {
2019  if (*(s2 + 2)) {
2020  ast_set_callerid(chan, s2 + 2, NULL, s2 + 2);
2021  }
2022  }
2023  if (s1) {
2024  ast_copy_string(exten, s1, sizeof(exten));
2025  } else {
2026  ast_copy_string(exten, "911", sizeof(exten));
2027  }
2028  } else {
2029  ast_log(LOG_WARNING, "Got a non-E911/FGC CAMA input on channel %d. Assuming E&M Wink instead\n", p->channel);
2030  }
2031  }
2032  if (p->sig == ANALOG_SIG_FEATB) {
2033  if (exten[0] == '*') {
2034  char *stringp=NULL;
2035  ast_copy_string(exten2, exten, sizeof(exten2));
2036  /* Parse out extension and callerid */
2037  stringp=exten2 +1;
2038  s1 = strsep(&stringp, "#");
2039  ast_copy_string(exten, exten2 + 1, sizeof(exten));
2040  } else {
2041  ast_log(LOG_WARNING, "Got a non-Feature Group B input on channel %d. Assuming E&M Wink instead\n", p->channel);
2042  }
2043  }
2044  if ((p->sig == ANALOG_SIG_FEATDMF) || (p->sig == ANALOG_SIG_FEATDMF_TA)) {
2045  analog_wink(p, idx);
2046  /*
2047  * Some switches require a minimum guard time between the last
2048  * FGD wink and something that answers immediately. This
2049  * ensures it.
2050  */
2051  if (ast_safe_sleep(chan, 100)) {
2052  ast_hangup(chan);
2053  goto quit;
2054  }
2055  }
2057 
2059 
2060  if (ast_exists_extension(chan, chan->context, exten, 1,
2061  chan->caller.id.number.valid ? chan->caller.id.number.str : NULL)) {
2062  ast_copy_string(chan->exten, exten, sizeof(chan->exten));
2064  res = ast_pbx_run(chan);
2065  if (res) {
2066  ast_log(LOG_WARNING, "PBX exited non-zero\n");
2068  }
2069  goto quit;
2070  } else {
2071  ast_verb(3, "Unknown extension '%s' in context '%s' requested\n", exten, chan->context);
2072  sleep(2);
2073  res = analog_play_tone(p, idx, ANALOG_TONE_INFO);
2074  if (res < 0) {
2075  ast_log(LOG_WARNING, "Unable to start special tone on %d\n", p->channel);
2076  } else {
2077  sleep(1);
2078  }
2079  res = ast_streamfile(chan, "ss-noservice", chan->language);
2080  if (res >= 0) {
2081  ast_waitstream(chan, "");
2082  }
2084  ast_hangup(chan);
2085  goto quit;
2086  }
2087  break;
2088  case ANALOG_SIG_FXOLS:
2089  case ANALOG_SIG_FXOGS:
2090  case ANALOG_SIG_FXOKS:
2091  /* Read the first digit */
2092  timeout = analog_firstdigittimeout;
2093  /* If starting a threeway call, never timeout on the first digit so someone
2094  can use flash-hook as a "hold" feature */
2095  if (p->subs[ANALOG_SUB_THREEWAY].owner) {
2096  timeout = 999999;
2097  }
2098  while (len < AST_MAX_EXTENSION-1) {
2099  /* Read digit unless it's supposed to be immediate, in which case the
2100  only answer is 's' */
2101  if (p->immediate) {
2102  res = 's';
2103  } else {
2104  res = ast_waitfordigit(chan, timeout);
2105  }
2106  timeout = 0;
2107  if (res < 0) {
2108  ast_debug(1, "waitfordigit returned < 0...\n");
2109  res = analog_play_tone(p, idx, -1);
2110  ast_hangup(chan);
2111  goto quit;
2112  } else if (res) {
2113  ast_debug(1,"waitfordigit returned '%c' (%d), timeout = %d\n", res, res, timeout);
2114  exten[len++]=res;
2115  exten[len] = '\0';
2116  }
2117  if (!ast_ignore_pattern(chan->context, exten)) {
2118  analog_play_tone(p, idx, -1);
2119  } else {
2121  }
2122  if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num) && !ast_parking_ext_valid(exten, chan, chan->context)) {
2123  if (!res || !ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) {
2124  if (getforward) {
2125  /* Record this as the forwarding extension */
2126  ast_copy_string(p->call_forward, exten, sizeof(p->call_forward));
2127  ast_verb(3, "Setting call forward to '%s' on channel %d\n", p->call_forward, p->channel);
2129  if (res) {
2130  break;
2131  }
2132  usleep(500000);
2133  res = analog_play_tone(p, idx, -1);
2134  sleep(1);
2135  memset(exten, 0, sizeof(exten));
2136  res = analog_play_tone(p, idx, ANALOG_TONE_DIALTONE);
2137  len = 0;
2138  getforward = 0;
2139  } else {
2140  res = analog_play_tone(p, idx, -1);
2141  ast_copy_string(chan->exten, exten, sizeof(chan->exten));
2142  if (!ast_strlen_zero(p->cid_num)) {
2143  if (!p->hidecallerid) {
2144  ast_set_callerid(chan, p->cid_num, NULL, p->cid_num);
2145  } else {
2146  ast_set_callerid(chan, NULL, NULL, p->cid_num);
2147  }
2148  }
2149  if (!ast_strlen_zero(p->cid_name)) {
2150  if (!p->hidecallerid) {
2151  ast_set_callerid(chan, NULL, p->cid_name, NULL);
2152  }
2153  }
2156  res = ast_pbx_run(chan);
2157  if (res) {
2158  ast_log(LOG_WARNING, "PBX exited non-zero\n");
2160  }
2161  goto quit;
2162  }
2163  } else {
2164  /* It's a match, but they just typed a digit, and there is an ambiguous match,
2165  so just set the timeout to analog_matchdigittimeout and wait some more */
2166  timeout = analog_matchdigittimeout;
2167  }
2168  } else if (res == 0) {
2169  ast_debug(1, "not enough digits (and no ambiguous match)...\n");
2171  analog_wait_event(p);
2172  ast_hangup(chan);
2173  goto quit;
2174  } else if (p->callwaiting && !strcmp(exten, "*70")) {
2175  ast_verb(3, "Disabling call waiting on %s\n", chan->name);
2176  /* Disable call waiting if enabled */
2177  analog_set_callwaiting(p, 0);
2179  if (res) {
2180  ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2181  chan->name, strerror(errno));
2182  }
2183  len = 0;
2184  memset(exten, 0, sizeof(exten));
2185  timeout = analog_firstdigittimeout;
2186 
2187  } else if (!strcmp(exten,ast_pickup_ext())) {
2188  /* Scan all channels and see if there are any
2189  * ringing channels that have call groups
2190  * that equal this channels pickup group
2191  */
2192  if (idx == ANALOG_SUB_REAL) {
2193  /* Switch us from Third call to Call Wait */
2194  if (p->subs[ANALOG_SUB_THREEWAY].owner) {
2195  /* If you make a threeway call and the *8# a call, it should actually
2196  look like a callwait */
2200  }
2202  if (ast_pickup_call(chan)) {
2203  ast_debug(1, "No call pickup possible...\n");
2205  analog_wait_event(p);
2206  }
2207  ast_hangup(chan);
2208  goto quit;
2209  } else {
2210  ast_log(LOG_WARNING, "Huh? Got *8# on call not on real\n");
2211  ast_hangup(chan);
2212  goto quit;
2213  }
2214 
2215  } else if (!p->hidecallerid && !strcmp(exten, "*67")) {
2216  ast_verb(3, "Disabling Caller*ID on %s\n", chan->name);
2217  /* Disable Caller*ID if enabled */
2218  p->hidecallerid = 1;
2224  if (res) {
2225  ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2226  chan->name, strerror(errno));
2227  }
2228  len = 0;
2229  memset(exten, 0, sizeof(exten));
2230  timeout = analog_firstdigittimeout;
2231  } else if (p->callreturn && !strcmp(exten, "*69")) {
2232  res = 0;
2233  if (!ast_strlen_zero(p->lastcid_num)) {
2234  res = ast_say_digit_str(chan, p->lastcid_num, "", chan->language);
2235  }
2236  if (!res) {
2238  }
2239  break;
2240  } else if (!strcmp(exten, "*78")) {
2241  /* Do not disturb enabled */
2242  analog_dnd(p, 1);
2244  getforward = 0;
2245  memset(exten, 0, sizeof(exten));
2246  len = 0;
2247  } else if (!strcmp(exten, "*79")) {
2248  /* Do not disturb disabled */
2249  analog_dnd(p, 0);
2251  getforward = 0;
2252  memset(exten, 0, sizeof(exten));
2253  len = 0;
2254  } else if (p->cancallforward && !strcmp(exten, "*72")) {
2256  getforward = 1;
2257  memset(exten, 0, sizeof(exten));
2258  len = 0;
2259  } else if (p->cancallforward && !strcmp(exten, "*73")) {
2260  ast_verb(3, "Cancelling call forwarding on channel %d\n", p->channel);
2262  memset(p->call_forward, 0, sizeof(p->call_forward));
2263  getforward = 0;
2264  memset(exten, 0, sizeof(exten));
2265  len = 0;
2266  } else if ((p->transfer || p->canpark) && ast_parking_ext_valid(exten, chan, chan->context) &&
2269  /* This is a three way call, the main call being a real channel,
2270  and we're parking the first call. */
2273  chan->context, 0, NULL);
2274  ast_verb(3, "Parking call to '%s'\n", chan->name);
2275  break;
2276  } else if (!ast_strlen_zero(p->lastcid_num) && !strcmp(exten, "*60")) {
2277  ast_verb(3, "Blacklisting number %s\n", p->lastcid_num);
2278  res = ast_db_put("blacklist", p->lastcid_num, "1");
2279  if (!res) {
2281  memset(exten, 0, sizeof(exten));
2282  len = 0;
2283  }
2284  } else if (p->hidecallerid && !strcmp(exten, "*82")) {
2285  ast_verb(3, "Enabling Caller*ID on %s\n", chan->name);
2286  /* Enable Caller*ID if enabled */
2287  p->hidecallerid = 0;
2288  ast_set_callerid(chan, p->cid_num, p->cid_name, NULL);
2290  if (res) {
2291  ast_log(LOG_WARNING, "Unable to do dial recall on channel %s: %s\n",
2292  chan->name, strerror(errno));
2293  }
2294  len = 0;
2295  memset(exten, 0, sizeof(exten));
2296  timeout = analog_firstdigittimeout;
2297  } else if (!strcmp(exten, "*0")) {
2298  struct ast_channel *nbridge = p->subs[ANALOG_SUB_THREEWAY].owner;
2299  struct analog_pvt *pbridge = NULL;
2300  /* set up the private struct of the bridged one, if any */
2301  if (nbridge) {
2302  pbridge = analog_get_bridged_channel(p, nbridge);
2303  }
2304  if (pbridge && ISTRUNK(pbridge)) {
2305  /* Clear out the dial buffer */
2306  p->dop.dialstr[0] = '\0';
2307  /* flash hookswitch */
2308  if ((analog_flash(pbridge) == -1) && (errno != EINPROGRESS)) {
2310  "Unable to flash-hook bridged trunk from channel %s: %s\n",
2311  nbridge->name, strerror(errno));
2312  }
2318  }
2319  ast_hangup(chan);
2320  goto quit;
2321  } else {
2323  analog_wait_event(p);
2324  analog_play_tone(p, idx, -1);
2328  ast_hangup(chan);
2329  goto quit;
2330  }
2331  } else if (!ast_canmatch_extension(chan, chan->context, exten, 1,
2332  chan->caller.id.number.valid ? chan->caller.id.number.str : NULL)
2333  && !analog_canmatch_featurecode(exten)) {
2334  ast_debug(1, "Can't match %s from '%s' in context %s\n", exten,
2335  chan->caller.id.number.valid && chan->caller.id.number.str
2336  ? chan->caller.id.number.str : "<Unknown Caller>",
2337  chan->context);
2338  break;
2339  }
2340  if (!timeout) {
2341  timeout = analog_gendigittimeout;
2342  }
2343  if (len && !ast_ignore_pattern(chan->context, exten)) {
2344  analog_play_tone(p, idx, -1);
2345  }
2346  }
2347  break;
2348  case ANALOG_SIG_FXSLS:
2349  case ANALOG_SIG_FXSGS:
2350  case ANALOG_SIG_FXSKS:
2351  /* check for SMDI messages */
2352  if (p->use_smdi && p->smdi_iface) {
2354  if (smdi_msg != NULL) {
2355  ast_copy_string(chan->exten, smdi_msg->fwd_st, sizeof(chan->exten));
2356 
2357  if (smdi_msg->type == 'B')
2358  pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "b");
2359  else if (smdi_msg->type == 'N')
2360  pbx_builtin_setvar_helper(chan, "_SMDI_VM_TYPE", "u");
2361 
2362  ast_debug(1, "Received SMDI message on %s\n", chan->name);
2363  } else {
2364  ast_log(LOG_WARNING, "SMDI enabled but no SMDI message present\n");
2365  }
2366  }
2367 
2368  if (p->use_callerid && (p->cid_signalling == CID_SIG_SMDI && smdi_msg)) {
2369  number = smdi_msg->calling_st;
2370 
2371  /* If we want caller id, we're in a prering state due to a polarity reversal
2372  * and we're set to use a polarity reversal to trigger the start of caller id,
2373  * grab the caller id and wait for ringing to start... */
2374  } else if (p->use_callerid && (chan->_state == AST_STATE_PRERING
2378  /* If set to use DTMF CID signalling, listen for DTMF */
2379  if (p->cid_signalling == CID_SIG_DTMF) {
2380  int k = 0;
2381  int oldlinearity;
2382  int timeout_ms;
2383  int ms;
2384  struct timeval start = ast_tvnow();
2385  cs = NULL;
2386  ast_debug(1, "Receiving DTMF cid on channel %s\n", chan->name);
2387 
2388  oldlinearity = analog_set_linear_mode(p, idx, 0);
2389 
2390  /*
2391  * We are the only party interested in the Rx stream since
2392  * we have not answered yet. We don't need or even want DTMF
2393  * emulation. The DTMF digits can come so fast that emulation
2394  * can drop some of them.
2395  */
2397  timeout_ms = 4000;/* This is a typical OFF time between rings. */
2398  for (;;) {
2399  struct ast_frame *f;
2400 
2401  ms = ast_remaining_ms(start, timeout_ms);
2402  res = ast_waitfor(chan, ms);
2403  if (res <= 0) {
2404  /*
2405  * We do not need to restore the analog_set_linear_mode()
2406  * or AST_FLAG_END_DTMF_ONLY flag settings since we
2407  * are hanging up the channel.
2408  */
2409  ast_log(LOG_WARNING, "DTMFCID timed out waiting for ring. "
2410  "Exiting simple switch\n");
2411  ast_hangup(chan);
2412  goto quit;
2413  }
2414  f = ast_read(chan);
2415  if (!f) {
2416  break;
2417  }
2418  if (f->frametype == AST_FRAME_DTMF) {
2419  if (k < ARRAY_LEN(dtmfbuf) - 1) {
2420  dtmfbuf[k++] = f->subclass.integer;
2421  }
2422  ast_debug(1, "CID got digit '%c'\n", f->subclass.integer);
2423  start = ast_tvnow();
2424  }
2425  ast_frfree(f);
2426  if (chan->_state == AST_STATE_RING ||
2427  chan->_state == AST_STATE_RINGING) {
2428  break; /* Got ring */
2429  }
2430  }
2432  dtmfbuf[k] = '\0';
2433 
2434  analog_set_linear_mode(p, idx, oldlinearity);
2435 
2436  /* Got cid and ring. */
2437  ast_debug(1, "CID got string '%s'\n", dtmfbuf);
2438  callerid_get_dtmf(dtmfbuf, dtmfcid, &flags);
2439  ast_debug(1, "CID is '%s', flags %d\n", dtmfcid, flags);
2440  /* If first byte is NULL, we have no cid */
2441  if (!ast_strlen_zero(dtmfcid)) {
2442  number = dtmfcid;
2443  } else {
2444  number = NULL;
2445  }
2446 
2447  /* If set to use V23 Signalling, launch our FSK gubbins and listen for it */
2448  } else if ((p->cid_signalling == CID_SIG_V23) || (p->cid_signalling == CID_SIG_V23_JP)) {
2449  int timeout = 10000; /* Ten seconds */
2450  struct timeval start = ast_tvnow();
2451  enum analog_event ev;
2452 
2453  namebuf[0] = 0;
2454  numbuf[0] = 0;
2455 
2457  int off_ms;
2458  int ms;
2459  struct timeval off_start;
2460  while (1) {
2461  res = analog_get_callerid(p, namebuf, numbuf, &ev, timeout - ast_tvdiff_ms(ast_tvnow(), start));
2462 
2463  if (res == 0) {
2464  break;
2465  }
2466 
2467  if (res == 1) {
2468  if (ev == ANALOG_EVENT_NOALARM) {
2469  analog_set_alarm(p, 0);
2470  }
2471  if (p->cid_signalling == CID_SIG_V23_JP) {
2472  if (ev == ANALOG_EVENT_RINGBEGIN) {
2473  analog_off_hook(p);
2474  usleep(1);
2475  }
2476  } else {
2477  ev = ANALOG_EVENT_NONE;
2478  break;
2479  }
2480  }
2481 
2482  if (ast_tvdiff_ms(ast_tvnow(), start) > timeout)
2483  break;
2484 
2485  }
2486  name = namebuf;
2487  number = numbuf;
2488 
2490 
2491  if (p->cid_signalling == CID_SIG_V23_JP) {
2492  res = analog_on_hook(p);
2493  usleep(1);
2494  }
2495 
2496  /* Finished with Caller*ID, now wait for a ring to make sure there really is a call coming */
2497  off_start = ast_tvnow();
2498  off_ms = 4000;/* This is a typical OFF time between rings. */
2499  while ((ms = ast_remaining_ms(off_start, off_ms))) {
2500  struct ast_frame *f;
2501 
2502  res = ast_waitfor(chan, ms);
2503  if (res <= 0) {
2504  ast_log(LOG_WARNING, "CID timed out waiting for ring. "
2505  "Exiting simple switch\n");
2506  ast_hangup(chan);
2507  goto quit;
2508  }
2509  if (!(f = ast_read(chan))) {
2510  ast_log(LOG_WARNING, "Hangup received waiting for ring. Exiting simple switch\n");
2511  ast_hangup(chan);
2512  goto quit;
2513  }
2514  ast_frfree(f);
2515  if (chan->_state == AST_STATE_RING ||
2516  chan->_state == AST_STATE_RINGING)
2517  break; /* Got ring */
2518  }
2519 
2520  if (analog_distinctive_ring(chan, p, idx, NULL)) {
2521  goto quit;
2522  }
2523 
2524  if (res < 0) {
2525  ast_log(LOG_WARNING, "CallerID returned with error on channel '%s'\n", chan->name);
2526  }
2527  } else {
2528  ast_log(LOG_WARNING, "Unable to get caller ID space\n");
2529  }
2530  } else {
2531  ast_log(LOG_WARNING, "Channel %s in prering "
2532  "state, but I have nothing to do. "
2533  "Terminating simple switch, should be "
2534  "restarted by the actual ring.\n",
2535  chan->name);
2536  ast_hangup(chan);
2537  goto quit;
2538  }
2539  } else if (p->use_callerid && p->cid_start == ANALOG_CID_START_RING) {
2540  int timeout = 10000; /* Ten seconds */
2541  struct timeval start = ast_tvnow();
2542  enum analog_event ev;
2543  int curRingData[RING_PATTERNS] = { 0 };
2544  int receivedRingT = 0;
2545 
2546  namebuf[0] = 0;
2547  numbuf[0] = 0;
2548 
2550  while (1) {
2551  res = analog_get_callerid(p, namebuf, numbuf, &ev, timeout - ast_tvdiff_ms(ast_tvnow(), start));
2552 
2553  if (res == 0) {
2554  break;
2555  }
2556 
2557  if (res == 1 || res == 2) {
2558  if (ev == ANALOG_EVENT_NOALARM) {
2559  analog_set_alarm(p, 0);
2560  } else if (ev == ANALOG_EVENT_POLARITY && p->hanguponpolarityswitch && p->polarity == POLARITY_REV) {
2561  ast_debug(1, "Hanging up due to polarity reversal on channel %d while detecting callerid\n", p->channel);
2562  p->polarity = POLARITY_IDLE;
2563  ast_hangup(chan);
2564  goto quit;
2565  } else if (ev != ANALOG_EVENT_NONE && ev != ANALOG_EVENT_RINGBEGIN && ev != ANALOG_EVENT_RINGOFFHOOK) {
2566  break;
2567  }
2568  if (res != 2) {
2569  /* Let us detect callerid when the telco uses distinctive ring */
2570  curRingData[receivedRingT] = p->ringt;
2571 
2572  if (p->ringt < p->ringt_base/2) {
2573  break;
2574  }
2575  /* Increment the ringT counter so we can match it against
2576  values in chan_dahdi.conf for distinctive ring */
2577  if (++receivedRingT == RING_PATTERNS) {
2578  break;
2579  }
2580  }
2581  }
2582 
2583  if (ast_tvdiff_ms(ast_tvnow(), start) > timeout) {
2584  break;
2585  }
2586 
2587  }
2588  name = namebuf;
2589  number = numbuf;
2590 
2592 
2593  if (analog_distinctive_ring(chan, p, idx, curRingData)) {
2594  goto quit;
2595  }
2596 
2597  if (res < 0) {
2598  ast_log(LOG_WARNING, "CallerID returned with error on channel '%s'\n", chan->name);
2599  }
2600  } else {
2601  ast_log(LOG_WARNING, "Unable to get caller ID space\n");
2602  }
2603  } else {
2604  cs = NULL;
2605  }
2606 
2607  if (number) {
2608  ast_shrink_phone_number(number);
2609  }
2610  ast_set_callerid(chan, number, name, number);
2611 
2612  if (cs) {
2613  callerid_free(cs);
2614  }
2615 
2616  analog_handle_notify_message(chan, p, flags, -1);
2617 
2619  chan->rings = 1;
2621  res = ast_pbx_run(chan);
2622  if (res) {
2623  ast_hangup(chan);
2624  ast_log(LOG_WARNING, "PBX exited non-zero\n");
2625  }
2626  goto quit;
2627  default:
2628  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);
2629  break;
2630  }
2632  if (res < 0) {
2633  ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
2634  }
2635  ast_hangup(chan);
2636 quit:
2637  if (smdi_msg) {
2639  }
2641  return NULL;
2642 }
#define ANALOG_SMDI_MD_WAIT_TIMEOUT
Definition: sig_analog.h:32
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1916
union ast_frame_subclass subclass
Definition: frame.h:146
int ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2804
char cid_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:303
#define POLARITY_IDLE
Definition: sig_analog.c:56
#define analog_get_index(ast, p, nullok)
Definition: sig_analog.c:389
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:7051
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:5420
analog_event
Definition: sig_analog.h:72
unsigned int use_callerid
Definition: sig_analog.h:283
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
Main Channel structure associated with a channel.
Definition: channel.h:742
#define POLARITY_REV
Definition: sig_analog.c:57
struct ast_smdi_interface * smdi_iface
The SMDI interface to get SMDI messages from.
Definition: sig_analog.h:290
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
static int analog_unalloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition: sig_analog.c:363
char fwd_st[SMDI_MAX_STATION_NUM_LEN+1]
Definition: smdi.h:73
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:946
int rings
Definition: channel.h:840
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame with payload.
Definition: channel.c:1601
struct ast_party_caller caller
Channel Caller ID information.
Definition: channel.h:804
char * strsep(char **str, const char *delims)
unsigned int immediate
Definition: sig_analog.h:276
static int analog_stop_cid_detect(struct analog_pvt *p)
Definition: sig_analog.c:167
int polarity
Definition: sig_analog.h:330
static int analog_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:592
struct ast_party_name name
Subscriber name.
Definition: channel.h:290
void * tech_pvt
Definition: channel.h:744
static int analog_set_linear_mode(struct analog_pvt *p, enum analog_sub sub, int linear_mode)
Definition: sig_analog.c:986
#define CID_SIG_SMDI
Definition: callerid.h:63
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
static int analog_firstdigittimeout
Definition: sig_analog.c:61
#define ast_set_flag(p, flag)
Definition: utils.h:70
static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
Definition: sig_analog.c:420
int ringt_base
Definition: sig_analog.h:346
char calling_st[SMDI_MAX_STATION_NUM_LEN+1]
Definition: smdi.h:74
#define LOG_WARNING
Definition: logger.h:144
#define AST_FRAME_DTMF
Definition: frame.h:128
unsigned int callreturn
Definition: sig_analog.h:271
struct ast_channel * owner
Definition: sig_analog.h:245
static int analog_get_callerid(struct analog_pvt *p, char *name, char *number, enum analog_event *ev, size_t timeout)
Definition: sig_analog.c:175
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4383
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:8415
static int analog_handle_notify_message(struct ast_channel *chan, struct analog_pvt *p, int cid_flags, int neon_mwievent)
Definition: sig_analog.c:1651
static int analog_start_cid_detect(struct analog_pvt *p, int cid_signalling)
Definition: sig_analog.c:159
int ast_ignore_pattern(const char *context, const char *pattern)
Checks to see if a number should be ignored.
Definition: pbx.c:8650
int cid_signalling
Definition: sig_analog.h:297
struct ast_channel * ss_astchan
Definition: sig_analog.h:342
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
#define RING_PATTERNS
Definition: sig_analog.h:35
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:90
int ast_pickup_call(struct ast_channel *chan)
Pickup a call.
Definition: features.c:7380
unsigned int hidecallerid
Definition: sig_analog.h:312
#define ast_verb(level,...)
Definition: logger.h:243
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:603
static int analog_wink(struct analog_pvt *p, enum analog_sub index)
Definition: sig_analog.c:651
#define ISTRUNK(p)
Definition: sig_analog.c:104
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:5415
unsigned int use_smdi
TRUE if SMDI (Simplified Message Desk Interface) is enabled.
Definition: sig_analog.h:288
unsigned int cancallforward
Definition: sig_analog.h:272
Number structure.
Definition: app_followme.c:109
#define ANALOG_MAX_CID
Definition: sig_analog.h:33
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static int analog_alloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition: sig_analog.c:350
static void analog_swap_subs(struct analog_pvt *p, enum analog_sub a, enum analog_sub b)
Definition: sig_analog.c:330
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_MAX_EXTENSION
Definition: channel.h:135
void ast_smdi_md_message_destroy(struct ast_smdi_md_message *msg)
ast_smdi_md_message destructor.
Definition: res_smdi.c:824
void ast_party_number_init(struct ast_party_number *init)
Initialize the given number structure.
Definition: channel.c:1981
static int analog_matchdigittimeout
Definition: sig_analog.c:59
static int analog_distinctive_ring(struct ast_channel *chan, struct analog_pvt *p, int idx, int *ringdata)
Definition: sig_analog.c:1678
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:5400
An SMDI message desk message.
Definition: smdi.h:69
void ast_party_number_free(struct ast_party_number *doomed)
Destroy the party number contents.
Definition: channel.c:2028
const char * analog_sigtype_to_str(enum analog_sigtype sigtype)
Definition: sig_analog.c:120
#define ASTOBJ_UNREF(object, destructor)
Decrement the reference count on an object.
Definition: astobj.h:218
char cid_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:302
static int analog_on_hook(struct analog_pvt *p)
Definition: sig_analog.c:511
#define CID_SIG_V23_JP
Definition: callerid.h:62
struct analog_dialoperation dop
Definition: sig_analog.h:263
enum analog_cid_start cid_start
Definition: sig_analog.h:300
static int analog_dsp_reset_and_flush_digits(struct analog_pvt *p)
Definition: sig_analog.c:410
int ast_remaining_ms(struct timeval start, int max_ms)
Calculate remaining milliseconds given a starting timestamp and upper bound.
Definition: utils.c:1615
void ast_party_name_init(struct ast_party_name *init)
Initialize the given name structure.
Definition: channel.c:1928
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
enum ast_channel_state _state
Definition: channel.h:839
struct ast_channel * ast_bridged_channel(struct ast_channel *chan)
Find bridged channel.
Definition: channel.c:7160
unsigned int callwaiting
Definition: sig_analog.h:307
#define CID_SIG_DTMF
Definition: callerid.h:61
static int analog_decrease_ss_count(struct analog_pvt *p)
Definition: sig_analog.c:1669
const ast_string_field name
Definition: channel.h:787
void ast_party_name_free(struct ast_party_name *doomed)
Destroy the party name contents.
Definition: channel.c:1975
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static int analog_canmatch_featurecode(const char *exten)
Definition: sig_analog.c:1712
int errno
static const char name[]
static struct ast_format f[]
Definition: format_g726.c:181
static void analog_set_callwaiting(struct analog_pvt *p, int callwaiting_enable)
Definition: sig_analog.c:888
static int analog_gendigittimeout
Definition: sig_analog.c:60
#define ast_clear_flag(p, flag)
Definition: utils.h:77
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...
Definition: pbx.c:10546
static int analog_wait_event(struct analog_pvt *p)
Definition: sig_analog.c:199
static void * analog_get_bridged_channel(struct analog_pvt *p, struct ast_channel *chan)
Definition: sig_analog.c:1694
#define ANALOG_NEED_MFDETECT(p)
Definition: sig_analog.c:1710
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3552
void callerid_free(struct callerid_state *cid)
This function frees callerid_state cid.
Definition: callerid.c:735
char call_forward[AST_MAX_EXTENSION]
Definition: sig_analog.h:339
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3539
static int analog_increase_ss_count(struct analog_pvt *p)
Definition: sig_analog.c:1660
static int analog_set_echocanceller(struct analog_pvt *p, int enable)
Definition: sig_analog.c:455
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1343
char lastcid_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:325
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7119
static int analog_my_getsigstr(struct ast_channel *chan, char *str, const char *term, int ms)
Definition: sig_analog.c:1631
enum ast_pbx_result ast_pbx_run(struct ast_channel *c)
Execute the PBX in the current thread.
Definition: pbx.c:5926
static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
Definition: sig_analog.c:428
Data structure associated with a single frame of data.
Definition: frame.h:142
int ast_masq_park_call_exten(struct ast_channel *park_me, struct ast_channel *parker, const char *park_exten, const char *park_context, int timeout, int *extout)
Park a call via a masqueraded channel.
Definition: features.c:1803
int ast_db_put(const char *family, const char *key, const char *value)
Store value addressed by family/key.
Definition: db.c:260
int ast_parking_ext_valid(const char *exten_str, struct ast_channel *chan, const char *context)
Determine if parking extension exists in a given context.
Definition: features.c:844
enum ast_frame_type frametype
Definition: frame.h:144
#define ast_frfree(fr)
Definition: frame.h:583
unsigned int transfer
Definition: sig_analog.h:281
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
void callerid_get_dtmf(char *cidstring, char *number, int *flags)
Get and parse DTMF-based callerid.
Definition: callerid.c:202
unsigned int hanguponpolarityswitch
Definition: sig_analog.h:275
void ast_shrink_phone_number(char *n)
Shrink a phone number in place to just digits (more accurately it just removes ()&#39;s, .&#39;s, and -&#39;s...
Definition: callerid.c:948
static int analog_flash(struct analog_pvt *p)
Definition: sig_analog.c:487
static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
Definition: sig_analog.c:919
unsigned int canpark
Definition: sig_analog.h:273
static int analog_dsp_set_digitmode(struct analog_pvt *p, enum analog_dsp_digitmode mode)
Definition: sig_analog.c:636
enum analog_sigtype sig
Definition: sig_analog.h:254
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:247
int analog_dnd(struct analog_pvt *p, int flag)
Definition: sig_analog.c:3955
static void analog_set_alarm(struct analog_pvt *p, int in_alarm)
Definition: sig_analog.c:911
const ast_string_field language
Definition: channel.h:787
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
const char * ast_pickup_ext(void)
Determine system call pickup extension.
Definition: features.c:849
#define CID_SIG_V23
Definition: callerid.h:60
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292
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 390 of file sig_analog.c.

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

391 {
392  int res;
393  if (p->subs[ANALOG_SUB_REAL].owner == ast) {
394  res = ANALOG_SUB_REAL;
395  } else if (p->subs[ANALOG_SUB_CALLWAIT].owner == ast) {
396  res = ANALOG_SUB_CALLWAIT;
397  } else if (p->subs[ANALOG_SUB_THREEWAY].owner == ast) {
398  res = ANALOG_SUB_THREEWAY;
399  } else {
400  res = -1;
401  if (!nullok) {
403  "Unable to get index for '%s' on channel %d (%s(), line %lu)\n",
404  ast ? ast->name : "", p->channel, fname, line);
405  }
406  }
407  return res;
408 }
#define LOG_WARNING
Definition: logger.h:144
struct ast_channel * owner
Definition: sig_analog.h:245
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
static void analog_all_subchannels_hungup ( struct analog_pvt p)
static

Definition at line 535 of file sig_analog.c.

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

Referenced by analog_hangup().

536 {
537  if (p->calls->all_subchannels_hungup) {
539  }
540 }
void(*const all_subchannels_hungup)(void *pvt)
Definition: sig_analog.h:206
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_alloc_sub ( struct analog_pvt p,
enum analog_sub  x 
)
static

Definition at line 350 of file sig_analog.c.

References analog_callback::allocate_sub, analog_subchannel::allocd, analog_pvt::calls, analog_pvt::chan_pvt, and analog_pvt::subs.

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

351 {
352  if (p->calls->allocate_sub) {
353  int res;
354  res = p->calls->allocate_sub(p->chan_pvt, x);
355  if (!res) {
356  p->subs[x].allocd = 1;
357  }
358  return res;
359  }
360  return 0;
361 }
unsigned int allocd
Definition: sig_analog.h:249
int(*const allocate_sub)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:188
struct analog_callback * calls
Definition: sig_analog.h:258
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
void * chan_pvt
Definition: sig_analog.h:256
int analog_answer ( struct analog_pvt p,
struct ast_channel ast 
)

Definition at line 1486 of file sig_analog.c.

References ast_channel::_state, 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_debug, ast_log(), ast_setstate(), AST_STATE_RINGING, AST_STATE_UP, analog_pvt::channel, analog_pvt::hanguponpolarityswitch, analog_subchannel::inthreeway, LOG_WARNING, ast_channel::name, analog_subchannel::owner, analog_pvt::polaritydelaytv, analog_pvt::sig, and analog_pvt::subs.

Referenced by dahdi_answer().

1487 {
1488  int res = 0;
1489  int idx;
1490  int oldstate = ast->_state;
1491 
1492  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1493  ast_setstate(ast, AST_STATE_UP);
1494  idx = analog_get_index(ast, p, 1);
1495  if (idx < 0) {
1496  idx = ANALOG_SUB_REAL;
1497  }
1498  switch (p->sig) {
1499  case ANALOG_SIG_FXSLS:
1500  case ANALOG_SIG_FXSGS:
1501  case ANALOG_SIG_FXSKS:
1502  analog_set_ringtimeout(p, 0);
1503  /* Fall through */
1504  case ANALOG_SIG_EM:
1505  case ANALOG_SIG_EM_E1:
1506  case ANALOG_SIG_EMWINK:
1507  case ANALOG_SIG_FEATD:
1508  case ANALOG_SIG_FEATDMF:
1509  case ANALOG_SIG_FEATDMF_TA:
1510  case ANALOG_SIG_E911:
1511  case ANALOG_SIG_FGC_CAMA:
1512  case ANALOG_SIG_FGC_CAMAMF:
1513  case ANALOG_SIG_FEATB:
1514  case ANALOG_SIG_SF:
1515  case ANALOG_SIG_SFWINK:
1516  case ANALOG_SIG_SF_FEATD:
1517  case ANALOG_SIG_SF_FEATDMF:
1518  case ANALOG_SIG_SF_FEATB:
1519  case ANALOG_SIG_FXOLS:
1520  case ANALOG_SIG_FXOGS:
1521  case ANALOG_SIG_FXOKS:
1522  /* Pick up the line */
1523  ast_debug(1, "Took %s off hook\n", ast->name);
1524  if (p->hanguponpolarityswitch) {
1525  gettimeofday(&p->polaritydelaytv, NULL);
1526  }
1527  res = analog_off_hook(p);
1528  analog_play_tone(p, idx, -1);
1529  analog_set_dialing(p, 0);
1530  if ((idx == ANALOG_SUB_REAL) && p->subs[ANALOG_SUB_THREEWAY].inthreeway) {
1531  if (oldstate == AST_STATE_RINGING) {
1532  ast_debug(1, "Finally swapping real and threeway\n");
1536  }
1537  }
1538 
1539  switch (p->sig) {
1540  case ANALOG_SIG_FXSLS:
1541  case ANALOG_SIG_FXSKS:
1542  case ANALOG_SIG_FXSGS:
1545  break;
1546  case ANALOG_SIG_FXOLS:
1547  case ANALOG_SIG_FXOKS:
1548  case ANALOG_SIG_FXOGS:
1550  break;
1551  default:
1552  break;
1553  }
1554  break;
1555  default:
1556  ast_log(LOG_WARNING, "Don't know how to answer signalling %d (channel %d)\n", p->sig, p->channel);
1557  res = -1;
1558  break;
1559  }
1560  ast_setstate(ast, AST_STATE_UP);
1561  return res;
1562 }
#define analog_get_index(ast, p, nullok)
Definition: sig_analog.c:389
struct timeval polaritydelaytv
Definition: sig_analog.h:331
static int analog_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:592
static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
Definition: sig_analog.c:420
#define LOG_WARNING
Definition: logger.h:144
static int analog_train_echocanceller(struct analog_pvt *p)
Definition: sig_analog.c:463
struct ast_channel * owner
Definition: sig_analog.h:245
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static void analog_swap_subs(struct analog_pvt *p, enum analog_sub a, enum analog_sub b)
Definition: sig_analog.c:330
static void analog_answer_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:622
enum ast_channel_state _state
Definition: channel.h:839
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
unsigned int inthreeway
Definition: sig_analog.h:247
static int analog_set_echocanceller(struct analog_pvt *p, int enable)
Definition: sig_analog.c:455
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7119
static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
Definition: sig_analog.c:428
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
unsigned int hanguponpolarityswitch
Definition: sig_analog.h:275
static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
Definition: sig_analog.c:919
static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
Definition: sig_analog.c:903
enum analog_sigtype sig
Definition: sig_analog.h:254
static void analog_answer_polarityswitch ( struct analog_pvt p)
static

Definition at line 622 of file sig_analog.c.

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

Referenced by __analog_handle_event(), and analog_answer().

623 {
624  if (p->calls->answer_polarityswitch) {
625  return p->calls->answer_polarityswitch(p->chan_pvt);
626  }
627 }
void(*const answer_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch=yes.
Definition: sig_analog.h:160
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_attempt_transfer ( struct analog_pvt p,
int  inthreeway 
)
static

Definition at line 688 of file sig_analog.c.

References ast_channel::_state, ANALOG_SUB_REAL, ANALOG_SUB_THREEWAY, ast_bridged_channel(), AST_CEL_ATTENDEDTRANSFER, AST_CEL_BLINDTRANSFER, ast_cel_report_event(), ast_channel_transfer_masquerade(), ast_channel_unlock, ast_debug, ast_log(), AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), AST_STATE_RINGING, ast_verb, ast_channel::connected, ast_channel::linkedid, LOG_WARNING, ast_channel::name, analog_subchannel::owner, and analog_pvt::subs.

Referenced by __analog_handle_event().

689 {
690  struct ast_channel *owner_real;
691  struct ast_channel *owner_3way;
692  struct ast_channel *bridge_real;
693  struct ast_channel *bridge_3way;
694  int ret = 0;
695 
696  owner_real = p->subs[ANALOG_SUB_REAL].owner;
697  owner_3way = p->subs[ANALOG_SUB_THREEWAY].owner;
698  bridge_real = ast_bridged_channel(owner_real);
699  bridge_3way = ast_bridged_channel(owner_3way);
700 
701  /*
702  * In order to transfer, we need at least one of the channels to
703  * actually be in a call bridge. We can't conference two
704  * applications together. Why would we want to?
705  */
706  if (bridge_3way) {
707  ast_verb(3, "TRANSFERRING %s to %s\n", owner_3way->name, owner_real->name);
708  ast_cel_report_event(owner_3way,
709  (owner_real->_state == AST_STATE_RINGING
710  || owner_3way->_state == AST_STATE_RINGING)
712  NULL, owner_3way->linkedid, NULL);
713 
714  /*
715  * The three-way party we're about to transfer is on hold if he
716  * is not in a three way conference.
717  */
718  if (ast_channel_transfer_masquerade(owner_real, &owner_real->connected, 0,
719  bridge_3way, &owner_3way->connected, !inthreeway)) {
720  ast_log(LOG_WARNING, "Unable to masquerade %s as %s\n",
721  bridge_3way->name, owner_real->name);
722  ret = -1;
723  }
724  } else if (bridge_real) {
725  /* Try transferring the other way. */
726  ast_verb(3, "TRANSFERRING %s to %s\n", owner_real->name, owner_3way->name);
727  ast_cel_report_event(owner_3way,
728  (owner_real->_state == AST_STATE_RINGING
729  || owner_3way->_state == AST_STATE_RINGING)
731  NULL, owner_3way->linkedid, NULL);
732 
733  /*
734  * The three-way party we're about to transfer is on hold if he
735  * is not in a three way conference.
736  */
737  if (ast_channel_transfer_masquerade(owner_3way, &owner_3way->connected,
738  !inthreeway, bridge_real, &owner_real->connected, 0)) {
739  ast_log(LOG_WARNING, "Unable to masquerade %s as %s\n",
740  bridge_real->name, owner_3way->name);
741  ret = -1;
742  }
743  } else {
744  ast_debug(1, "Neither %s nor %s are in a bridge, nothing to transfer\n",
745  owner_real->name, owner_3way->name);
746  ret = -1;
747  }
748 
749  if (ret) {
751  }
752  ast_channel_unlock(owner_3way);
753  return ret;
754 }
Main Channel structure associated with a channel.
Definition: channel.h:742
struct ast_party_connected_line connected
Channel Connected Line ID information.
Definition: channel.h:811
#define LOG_WARNING
Definition: logger.h:144
int ast_cel_report_event(struct ast_channel *chan, enum ast_cel_event_type event_type, const char *userdefevname, const char *extra, struct ast_channel *peer2)
Report a channel event.
Definition: cel.c:645
struct ast_channel * owner
Definition: sig_analog.h:245
const ast_string_field linkedid
Definition: channel.h:787
#define ast_verb(level,...)
Definition: logger.h:243
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
a transfer occurs
Definition: cel.h:74
a transfer occurs
Definition: cel.h:76
int ast_channel_transfer_masquerade(struct ast_channel *target_chan, const struct ast_party_connected_line *target_id, int target_held, struct ast_channel *transferee_chan, const struct ast_party_connected_line *transferee_id, int transferee_held)
Setup a masquerade to transfer a call.
Definition: channel.c:6184
enum ast_channel_state _state
Definition: channel.h:839
struct ast_channel * ast_bridged_channel(struct ast_channel *chan)
Find bridged channel.
Definition: channel.c:7160
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int ast_softhangup_nolock(struct ast_channel *chan, int reason)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2733
#define ast_channel_unlock(chan)
Definition: channel.h:2467
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
int analog_available ( struct analog_pvt p)

Definition at line 806 of file sig_analog.c.

References ast_channel::_state, 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, analog_pvt::outgoing, analog_subchannel::owner, analog_pvt::owner, analog_pvt::sig, and analog_pvt::subs.

Referenced by available().

807 {
808  int offhook;
809 
810  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
811 
812  /* If do not disturb, definitely not */
813  if (p->dnd) {
814  return 0;
815  }
816  /* If guard time, definitely not */
817  if (p->guardtime && (time(NULL) < p->guardtime)) {
818  return 0;
819  }
820 
821  /* If no owner definitely available */
822  if (!p->owner) {
823  offhook = analog_is_off_hook(p);
824 
825  /* TDM FXO card, "onhook" means out of service (no battery on the line) */
826  if ((p->sig == ANALOG_SIG_FXSLS) || (p->sig == ANALOG_SIG_FXSKS) || (p->sig == ANALOG_SIG_FXSGS)) {
827 #ifdef DAHDI_CHECK_HOOKSTATE
828  if (offhook) {
829  return 1;
830  }
831  return 0;
832 #endif
833  /* TDM FXS card, "offhook" means someone took the hook off so it's unavailable! */
834  } else if (offhook) {
835  ast_debug(1, "Channel %d off hook, can't use\n", p->channel);
836  /* Not available when the other end is off hook */
837  return 0;
838  }
839  return 1;
840  }
841 
842  /* If it's not an FXO, forget about call wait */
843  if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) {
844  return 0;
845  }
846 
847  if (!p->callwaiting) {
848  /* If they don't have call waiting enabled, then for sure they're unavailable at this point */
849  return 0;
850  }
851 
852  if (p->subs[ANALOG_SUB_CALLWAIT].allocd) {
853  /* If there is already a call waiting call, then we can't take a second one */
854  return 0;
855  }
856 
857  if ((p->owner->_state != AST_STATE_UP) &&
858  ((p->owner->_state != AST_STATE_RINGING) || p->outgoing)) {
859  /* If the current call is not up, then don't allow the call */
860  return 0;
861  }
863  /* Can't take a call wait when the three way calling hasn't been merged yet. */
864  return 0;
865  }
866  /* We're cool */
867  return 1;
868 }
struct ast_channel * owner
Definition: sig_analog.h:245
time_t guardtime
Definition: sig_analog.h:333
unsigned int allocd
Definition: sig_analog.h:249
struct ast_channel * owner
Definition: sig_analog.h:260
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
unsigned int outgoing
Definition: sig_analog.h:313
enum ast_channel_state _state
Definition: channel.h:839
unsigned int callwaiting
Definition: sig_analog.h:307
unsigned int inthreeway
Definition: sig_analog.h:247
static int analog_is_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:471
unsigned int dnd
Definition: sig_analog.h:310
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
enum analog_sigtype sig
Definition: sig_analog.h:254
int analog_call ( struct analog_pvt p,
struct ast_channel ast,
char *  rdest,
int  timeout 
)

Definition at line 1003 of file sig_analog.c.

References ast_channel::_state, 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_get_cc_config_params(), 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(), analog_pvt::caller, analog_pvt::callwait_name, analog_pvt::callwait_num, analog_pvt::channel, ast_channel::connected, 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, ast_party_id::name, ast_channel::name, 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().

1004 {
1005  int res, idx, mysig;
1006  char *c, *n, *l;
1007  char dest[256]; /* must be same length as p->dialdest */
1008 
1009  ast_debug(1, "CALLING CID_NAME: %s CID_NUM:: %s\n",
1010  S_COR(ast->connected.id.name.valid, ast->connected.id.name.str, ""),
1011  S_COR(ast->connected.id.number.valid, ast->connected.id.number.str, ""));
1012 
1013  ast_copy_string(dest, rdest, sizeof(dest));
1014  ast_copy_string(p->dialdest, rdest, sizeof(p->dialdest));
1015 
1016  if ((ast->_state == AST_STATE_BUSY)) {
1018  return 0;
1019  }
1020 
1021  if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
1022  ast_log(LOG_WARNING, "analog_call called on %s, neither down nor reserved\n", ast->name);
1023  return -1;
1024  }
1025 
1026  p->dialednone = 0;
1027  analog_set_outgoing(p, 1);
1028 
1029  mysig = p->sig;
1030  if (p->outsigmod > -1) {
1031  mysig = p->outsigmod;
1032  }
1033 
1034  switch (mysig) {
1035  case ANALOG_SIG_FXOLS:
1036  case ANALOG_SIG_FXOGS:
1037  case ANALOG_SIG_FXOKS:
1038  if (p->owner == ast) {
1039  /* Normal ring, on hook */
1040 
1041  /* Don't send audio while on hook, until the call is answered */
1042  analog_set_dialing(p, 1);
1043  analog_set_cadence(p, ast); /* and set p->cidrings */
1044 
1045  /* nick@dccinc.com 4/3/03 mods to allow for deferred dialing */
1046  c = strchr(dest, '/');
1047  if (c) {
1048  c++;
1049  }
1050  if (c && (strlen(c) < p->stripmsd)) {
1051  ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1052  c = NULL;
1053  }
1054  if (c) {
1056  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "Tw%s", c);
1057  ast_debug(1, "FXO: setup deferred dialstring: %s\n", c);
1058  } else {
1059  p->dop.dialstr[0] = '\0';
1060  }
1061 
1062  if (analog_ring(p)) {
1063  ast_log(LOG_WARNING, "Unable to ring phone: %s\n", strerror(errno));
1064  return -1;
1065  }
1066  analog_set_dialing(p, 1);
1067  } else {
1068  /* Call waiting call */
1069  if (ast->connected.id.number.valid && ast->connected.id.number.str) {
1071  } else {
1072  p->callwait_num[0] = '\0';
1073  }
1074  if (ast->connected.id.name.valid && ast->connected.id.name.str) {
1076  } else {
1077  p->callwait_name[0] = '\0';
1078  }
1079 
1080  /* Call waiting tone instead */
1081  if (analog_callwait(p)) {
1082  return -1;
1083  }
1084  /* Make ring-back */
1086  ast_log(LOG_WARNING, "Unable to generate call-wait ring-back on channel %s\n", ast->name);
1087  }
1088 
1089  }
1090  n = ast->connected.id.name.valid ? ast->connected.id.name.str : NULL;
1091  l = ast->connected.id.number.valid ? ast->connected.id.number.str : NULL;
1092  if (l) {
1093  ast_copy_string(p->lastcid_num, l, sizeof(p->lastcid_num));
1094  } else {
1095  p->lastcid_num[0] = '\0';
1096  }
1097  if (n) {
1098  ast_copy_string(p->lastcid_name, n, sizeof(p->lastcid_name));
1099  } else {
1100  p->lastcid_name[0] = '\0';
1101  }
1102 
1103  if (p->use_callerid) {
1104  p->caller.id.name.str = p->lastcid_name;
1105  p->caller.id.number.str = p->lastcid_num;
1106  }
1107 
1109  idx = analog_get_index(ast, p, 0);
1110  if (idx > -1) {
1111  struct ast_cc_config_params *cc_params;
1112 
1113  /* This is where the initial ringing frame is queued for an analog call.
1114  * As such, this is a great time to offer CCNR to the caller if it's available.
1115  */
1116  cc_params = ast_channel_get_cc_config_params(p->subs[idx].owner);
1117  if (cc_params) {
1118  switch (ast_get_cc_monitor_policy(cc_params)) {
1119  case AST_CC_MONITOR_NEVER:
1120  break;
1121  case AST_CC_MONITOR_NATIVE:
1122  case AST_CC_MONITOR_ALWAYS:
1126  break;
1127  }
1128  }
1130  }
1131  break;
1132  case ANALOG_SIG_FXSLS:
1133  case ANALOG_SIG_FXSGS:
1134  case ANALOG_SIG_FXSKS:
1136  ast_debug(1, "Ignore possible polarity reversal on line seizure\n");
1137  p->polaritydelaytv = ast_tvnow();
1138  }
1139  /* fall through */
1140  case ANALOG_SIG_EMWINK:
1141  case ANALOG_SIG_EM:
1142  case ANALOG_SIG_EM_E1:
1143  case ANALOG_SIG_FEATD:
1144  case ANALOG_SIG_FEATDMF:
1145  case ANALOG_SIG_E911:
1146  case ANALOG_SIG_FGC_CAMA:
1147  case ANALOG_SIG_FGC_CAMAMF:
1148  case ANALOG_SIG_FEATB:
1149  case ANALOG_SIG_SFWINK:
1150  case ANALOG_SIG_SF:
1151  case ANALOG_SIG_SF_FEATD:
1152  case ANALOG_SIG_SF_FEATDMF:
1153  case ANALOG_SIG_FEATDMF_TA:
1154  case ANALOG_SIG_SF_FEATB:
1155  c = strchr(dest, '/');
1156  if (c) {
1157  c++;
1158  } else {
1159  c = "";
1160  }
1161  if (strlen(c) < p->stripmsd) {
1162  ast_log(LOG_WARNING, "Number '%s' is shorter than stripmsd (%d)\n", c, p->stripmsd);
1163  return -1;
1164  }
1165  res = analog_start(p);
1166  if (res < 0) {
1167  if (errno != EINPROGRESS) {
1168  return -1;
1169  }
1170  }
1171  ast_debug(1, "Dialing '%s'\n", c);
1173 
1174  c += p->stripmsd;
1175 
1176  switch (mysig) {
1177  case ANALOG_SIG_FEATD:
1178  l = ast->connected.id.number.valid ? ast->connected.id.number.str : NULL;
1179  if (l) {
1180  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T*%s*%s*", l, c);
1181  } else {
1182  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T**%s*", c);
1183  }
1184  break;
1185  case ANALOG_SIG_FEATDMF:
1186  l = ast->connected.id.number.valid ? ast->connected.id.number.str : NULL;
1187  if (l) {
1188  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*00%s#*%s#", l, c);
1189  } else {
1190  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*02#*%s#", c);
1191  }
1192  break;
1193  case ANALOG_SIG_FEATDMF_TA:
1194  {
1195  const char *cic = "", *ozz = "";
1196 
1197  /* If you have to go through a Tandem Access point you need to use this */
1198 #ifndef STANDALONE
1199  ozz = pbx_builtin_getvar_helper(p->owner, "FEATDMF_OZZ");
1200  if (!ozz) {
1201  ozz = analog_defaultozz;
1202  }
1203  cic = pbx_builtin_getvar_helper(p->owner, "FEATDMF_CIC");
1204  if (!cic) {
1205  cic = analog_defaultcic;
1206  }
1207 #endif
1208  if (!ozz || !cic) {
1209  ast_log(LOG_WARNING, "Unable to dial channel of type feature group D MF tandem access without CIC or OZZ set\n");
1210  return -1;
1211  }
1212  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s%s#", ozz, cic);
1213  snprintf(p->finaldial, sizeof(p->finaldial), "M*%s#", c);
1214  p->whichwink = 0;
1215  }
1216  break;
1217  case ANALOG_SIG_E911:
1218  ast_copy_string(p->dop.dialstr, "M*911#", sizeof(p->dop.dialstr));
1219  break;
1220  case ANALOG_SIG_FGC_CAMA:
1221  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%s", c);
1222  break;
1223  case ANALOG_SIG_FGC_CAMAMF:
1224  case ANALOG_SIG_FEATB:
1225  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "M*%s#", c);
1226  break;
1227  default:
1228  if (p->pulse) {
1229  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "P%sw", c);
1230  } else {
1231  snprintf(p->dop.dialstr, sizeof(p->dop.dialstr), "T%sw", c);
1232  }
1233  break;
1234  }
1235 
1236  if (p->echotraining && (strlen(p->dop.dialstr) > 4)) {
1237  memset(p->echorest, 'w', sizeof(p->echorest) - 1);
1238  strcpy(p->echorest + (p->echotraining / 400) + 1, p->dop.dialstr + strlen(p->dop.dialstr) - 2);
1239  p->echorest[sizeof(p->echorest) - 1] = '\0';
1240  p->echobreak = 1;
1241  p->dop.dialstr[strlen(p->dop.dialstr)-2] = '\0';
1242  } else {
1243  p->echobreak = 0;
1244  }
1245  analog_set_waitingfordt(p, ast);
1246  if (!res) {
1247  if (analog_dial_digits(p, ANALOG_SUB_REAL, &p->dop)) {
1248  int saveerr = errno;
1249 
1250  analog_on_hook(p);
1251  ast_log(LOG_WARNING, "Dialing failed on channel %d: %s\n", p->channel, strerror(saveerr));
1252  return -1;
1253  }
1254  } else {
1255  ast_debug(1, "Deferring dialing...\n");
1256  }
1257  analog_set_dialing(p, 1);
1258  if (ast_strlen_zero(c)) {
1259  p->dialednone = 1;
1260  }
1262  break;
1263  default:
1264  ast_debug(1, "not yet implemented\n");
1265  return -1;
1266  }
1267  return 0;
1268 }
#define analog_get_index(ast, p, nullok)
Definition: sig_analog.c:389
unsigned int use_callerid
Definition: sig_analog.h:283
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
struct ast_party_connected_line connected
Channel Connected Line ID information.
Definition: channel.h:811
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame with payload.
Definition: channel.c:1601
struct ast_party_caller caller
Definition: sig_analog.h:327
struct timeval polaritydelaytv
Definition: sig_analog.h:331
struct ast_party_id id
Connected party ID.
Definition: channel.h:403
struct ast_party_name name
Subscriber name.
Definition: channel.h:290
static int analog_start(struct analog_pvt *p)
Definition: sig_analog.c:495
static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
Definition: sig_analog.c:420
int echotraining
Definition: sig_analog.h:296
#define LOG_WARNING
Definition: logger.h:144
char dialdest[256]
Definition: sig_analog.h:332
char finaldial[64]
Definition: sig_analog.h:336
char callwait_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:324
struct ast_channel * owner
Definition: sig_analog.h:245
char * str
Subscriber name (Malloced)
Definition: channel.h:214
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
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:3886
static void analog_set_outgoing(struct analog_pvt *p, int is_outgoing)
Definition: sig_analog.c:519
char echorest[20]
Definition: sig_analog.h:329
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
Definition: pbx.c:10475
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:9754
static const char * analog_get_orig_dialstring(struct analog_pvt *p)
Definition: sig_analog.c:183
static void analog_set_waitingfordt(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:928
enum ast_cc_monitor_policies ast_get_cc_monitor_policy(struct ast_cc_config_params *config)
Get the cc_monitor_policy.
Definition: ccss.c:763
struct ast_channel * owner
Definition: sig_analog.h:260
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
int stripmsd
Definition: sig_analog.h:299
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static int analog_dial_digits(struct analog_pvt *p, enum analog_sub sub, struct analog_dialoperation *dop)
Definition: sig_analog.c:503
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#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:83
static char analog_defaultcic[64]
Definition: sig_analog.c:62
char callwait_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:323
unsigned int dialednone
Definition: sig_analog.h:308
#define AST_CC_GENERIC_MONITOR_TYPE
Definition: ccss.h:472
char lastcid_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:326
static int analog_on_hook(struct analog_pvt *p)
Definition: sig_analog.c:511
struct analog_dialoperation dop
Definition: sig_analog.h:263
static char analog_defaultozz[64]
Definition: sig_analog.c:63
static int analog_callwait(struct analog_pvt *p)
Definition: sig_analog.c:879
enum ast_channel_state _state
Definition: channel.h:839
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
int whichwink
Definition: sig_analog.h:335
static void analog_set_cadence(struct analog_pvt *p, struct ast_channel *chan)
Definition: sig_analog.c:896
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
char lastcid_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:325
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7119
enum analog_sigtype outsigmod
Definition: sig_analog.h:295
unsigned int pulse
Definition: sig_analog.h:279
unsigned char valid
TRUE if the name information is valid/present.
Definition: channel.h:229
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
unsigned int hanguponpolarityswitch
Definition: sig_analog.h:275
static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
Definition: sig_analog.c:903
enum analog_sigtype sig
Definition: sig_analog.h:254
unsigned int echobreak
Definition: sig_analog.h:311
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:247
static int analog_ring(struct analog_pvt *p)
Definition: sig_analog.c:479
unsigned int answeronpolarityswitch
Definition: sig_analog.h:270
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292
static int analog_callwait ( struct analog_pvt p)
static

Definition at line 879 of file sig_analog.c.

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

Referenced by analog_call().

880 {
882  if (p->calls->callwait) {
883  return p->calls->callwait(p->chan_pvt);
884  }
885  return 0;
886 }
int(*const callwait)(void *pvt)
Definition: sig_analog.h:183
unsigned int callwaitingcallerid
Definition: sig_analog.h:284
struct analog_callback * calls
Definition: sig_analog.h:258
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
Definition: sig_analog.h:321
void * chan_pvt
Definition: sig_analog.h:256
static void analog_cancel_cidspill ( struct analog_pvt p)
static

Definition at line 961 of file sig_analog.c.

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

Referenced by __analog_handle_event(), and analog_handle_init_event().

962 {
963  if (!p->calls->cancel_cidspill) {
964  return;
965  }
966 
968 }
void(*const cancel_cidspill)(void *pvt)
Definition: sig_analog.h:233
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_canmatch_featurecode ( const char *  exten)
static

Definition at line 1712 of file sig_analog.c.

References ast_pickup_ext(), and pickup_ext.

Referenced by __analog_ss_thread().

1713 {
1714  int extlen = strlen(exten);
1715  const char *pickup_ext;
1716  if (!extlen) {
1717  return 1;
1718  }
1719  pickup_ext = ast_pickup_ext();
1720  if (extlen < strlen(pickup_ext) && !strncmp(pickup_ext, exten, extlen)) {
1721  return 1;
1722  }
1723  /* hardcoded features are *60, *67, *69, *70, *72, *73, *78, *79, *82, *0 */
1724  if (exten[0] == '*' && extlen < 3) {
1725  if (extlen == 1) {
1726  return 1;
1727  }
1728  /* "*0" should be processed before it gets here */
1729  switch (exten[1]) {
1730  case '6':
1731  case '7':
1732  case '8':
1733  return 1;
1734  }
1735  }
1736  return 0;
1737 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
static char pickup_ext[AST_MAX_EXTENSION]
Definition: features.c:421
const char * ast_pickup_ext(void)
Determine system call pickup extension.
Definition: features.c:849
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 644 of file sig_analog.c.

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

Referenced by analog_handle_dtmf().

645 {
646  if (p->calls->handle_dtmf) {
647  p->calls->handle_dtmf(p->chan_pvt, ast, analog_index, dest);
648  }
649 }
struct analog_callback * calls
Definition: sig_analog.h:258
void(*const handle_dtmf)(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
Definition: sig_analog.h:140
void * chan_pvt
Definition: sig_analog.h:256
static int analog_check_confirmanswer ( struct analog_pvt p)
static

Definition at line 952 of file sig_analog.c.

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

Referenced by __analog_handle_event(), and analog_handle_dtmf().

953 {
954  if (p->calls->check_confirmanswer) {
955  return p->calls->check_confirmanswer(p->chan_pvt);
956  }
957 
958  return 0;
959 }
int(*const check_confirmanswer)(void *pvt)
Definition: sig_analog.h:231
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_check_for_conference ( struct analog_pvt p)
static

Definition at line 527 of file sig_analog.c.

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

Referenced by __analog_handle_event().

528 {
529  if (p->calls->check_for_conference) {
530  return p->calls->check_for_conference(p->chan_pvt);
531  }
532  return -1;
533 }
int(*const check_for_conference)(void *pvt)
Definition: sig_analog.h:209
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_check_waitingfordt ( struct analog_pvt p)
static

Definition at line 935 of file sig_analog.c.

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

Referenced by __analog_handle_event().

936 {
937  if (p->calls->check_waitingfordt) {
938  return p->calls->check_waitingfordt(p->chan_pvt);
939  }
940 
941  return 0;
942 }
int(*const check_waitingfordt)(void *pvt)
Definition: sig_analog.h:229
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
const char* analog_cidstart_to_str ( enum analog_cid_start  cid_start)

Definition at line 231 of file sig_analog.c.

References ANALOG_CID_START_DTMF_NOALERT, ANALOG_CID_START_POLARITY, ANALOG_CID_START_POLARITY_IN, and ANALOG_CID_START_RING.

232 {
233  switch (cid_start) {
235  return "Ring";
237  return "Polarity";
239  return "Polarity_In";
241  return "DTMF";
242  }
243 
244  return "Unknown";
245 }
const char* analog_cidtype_to_str ( unsigned int  cid_type)

Definition at line 146 of file sig_analog.c.

References ARRAY_LEN, and cidtypes.

147 {
148  int i;
149 
150  for (i = 0; i < ARRAY_LEN(cidtypes); i++) {
151  if (cid_type == cidtypes[i].cid_type) {
152  return cidtypes[i].name;
153  }
154  }
155 
156  return "Unknown";
157 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct @119 cidtypes[]
unsigned int cid_type
Definition: sig_analog.c:93
int analog_config_complete ( struct analog_pvt p)

Definition at line 3919 of file sig_analog.c.

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

Referenced by mkintf().

3920 {
3921  /* No call waiting on non FXS channels */
3922  if ((p->sig != ANALOG_SIG_FXOKS) && (p->sig != ANALOG_SIG_FXOLS) && (p->sig != ANALOG_SIG_FXOGS)) {
3923  p->permcallwaiting = 0;
3924  }
3925 
3927 
3928  return 0;
3929 }
static void analog_set_callwaiting(struct analog_pvt *p, int callwaiting_enable)
Definition: sig_analog.c:888
enum analog_sigtype sig
Definition: sig_analog.h:254
unsigned int permcallwaiting
Definition: sig_analog.h:277
static int analog_confmute ( struct analog_pvt p,
int  mute 
)
static

Definition at line 970 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::confmute.

Referenced by __analog_handle_event().

971 {
972  if (p->calls->confmute) {
973  return p->calls->confmute(p->chan_pvt, mute);
974  }
975  return 0;
976 }
int(*const confmute)(void *pvt, int mute)
Definition: sig_analog.h:234
static int mute
Definition: chan_alsa.c:135
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_decrease_ss_count ( struct analog_pvt p)
static

Definition at line 1669 of file sig_analog.c.

References analog_pvt::calls, and analog_callback::decrease_ss_count.

Referenced by __analog_ss_thread().

1670 {
1671  if (p->calls->decrease_ss_count) {
1672  p->calls->decrease_ss_count();
1673  return 0;
1674  }
1675  return -1;
1676 }
void(*const decrease_ss_count)(void)
Definition: sig_analog.h:214
struct analog_callback * calls
Definition: sig_analog.h:258
void analog_delete ( struct analog_pvt doomed)

Delete the analog private structure.

Since
1.8
Parameters
doomedAnalog private structure to delete.
Returns
Nothing

Definition at line 3914 of file sig_analog.c.

References ast_free.

Referenced by destroy_dahdi_pvt().

3915 {
3916  ast_free(doomed);
3917 }
#define ast_free(a)
Definition: astmm.h:97
static int analog_dial_digits ( struct analog_pvt p,
enum analog_sub  sub,
struct analog_dialoperation dop 
)
static

Definition at line 503 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::dial_digits.

Referenced by __analog_handle_event(), and analog_call().

504 {
505  if (p->calls->dial_digits) {
506  return p->calls->dial_digits(p->chan_pvt, sub, dop);
507  }
508  return -1;
509 }
int(*const dial_digits)(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop)
Definition: sig_analog.h:166
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_distinctive_ring ( struct ast_channel chan,
struct analog_pvt p,
int  idx,
int *  ringdata 
)
static

Definition at line 1678 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::distinctive_ring.

Referenced by __analog_ss_thread().

1679 {
1680  if (p->calls->distinctive_ring) {
1681  return p->calls->distinctive_ring(chan, p->chan_pvt, idx, ringdata);
1682  }
1683  return -1;
1684 
1685 }
int(*const distinctive_ring)(struct ast_channel *chan, void *pvt, int idx, int *ringdata)
Definition: sig_analog.h:216
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
int analog_dnd ( struct analog_pvt p,
int  flag 
)

Definition at line 3955 of file sig_analog.c.

References ast_verb, analog_pvt::channel, analog_pvt::dnd, EVENT_FLAG_SYSTEM, and manager_event.

Referenced by __analog_ss_thread(), and dahdi_dnd().

3956 {
3957  if (flag == -1) {
3958  return p->dnd;
3959  }
3960 
3961  p->dnd = flag;
3962 
3963  ast_verb(3, "%s DND on channel %d\n",
3964  flag ? "Enabled" : "Disabled",
3965  p->channel);
3966  manager_event(EVENT_FLAG_SYSTEM, "DNDState",
3967  "Channel: DAHDI/%d\r\n"
3968  "Status: %s\r\n", p->channel,
3969  flag ? "enabled" : "disabled");
3970 
3971  return 0;
3972 }
#define ast_verb(level,...)
Definition: logger.h:243
#define EVENT_FLAG_SYSTEM
Definition: manager.h:71
unsigned int dnd
Definition: sig_analog.h:310
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:219
static int analog_dsp_reset_and_flush_digits ( struct analog_pvt p)
static

Definition at line 410 of file sig_analog.c.

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

Referenced by __analog_ss_thread().

411 {
414  }
415 
416  /* Return 0 since I think this is unnecessary to do in most cases it is used. Mostly only for ast_dsp */
417  return 0;
418 }
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
int(*const dsp_reset_and_flush_digits)(void *pvt)
Definition: sig_analog.h:173
static int analog_dsp_set_digitmode ( struct analog_pvt p,
enum analog_dsp_digitmode  mode 
)
static

Definition at line 636 of file sig_analog.c.

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

Referenced by __analog_ss_thread(), and analog_hangup().

637 {
638  if (p->calls->dsp_set_digitmode) {
639  return p->calls->dsp_set_digitmode(p->chan_pvt, mode);
640  }
641  return -1;
642 }
int(*const dsp_set_digitmode)(void *pvt, enum analog_dsp_digitmode mode)
Definition: sig_analog.h:172
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static char* analog_event2str ( enum analog_event  event)
static

Definition at line 247 of file sig_analog.c.

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().

248 {
249  char *res;
250  switch (event) {
251  case ANALOG_EVENT_ONHOOK:
252  res = "ANALOG_EVENT_ONHOOK";
253  break;
255  res = "ANALOG_EVENT_RINGOFFHOOK";
256  break;
258  res = "ANALOG_EVENT_WINKFLASH";
259  break;
260  case ANALOG_EVENT_ALARM:
261  res = "ANALOG_EVENT_ALARM";
262  break;
264  res = "ANALOG_EVENT_NOALARM";
265  break;
267  res = "ANALOG_EVENT_DIALCOMPLETE";
268  break;
270  res = "ANALOG_EVENT_HOOKCOMPLETE";
271  break;
273  res = "ANALOG_EVENT_PULSE_START";
274  break;
276  res = "ANALOG_EVENT_POLARITY";
277  break;
279  res = "ANALOG_EVENT_RINGBEGIN";
280  break;
282  res = "ANALOG_EVENT_EC_DISABLED";
283  break;
285  res = "ANALOG_EVENT_RINGERON";
286  break;
288  res = "ANALOG_EVENT_RINGEROFF";
289  break;
291  res = "ANALOG_EVENT_REMOVED";
292  break;
294  res = "ANALOG_EVENT_NEONMWI_ACTIVE";
295  break;
297  res = "ANALOG_EVENT_NEONMWI_INACTIVE";
298  break;
299 #ifdef HAVE_DAHDI_ECHOCANCEL_FAX_MODE
301  res = "ANALOG_EVENT_TX_CED_DETECTED";
302  break;
304  res = "ANALOG_EVENT_RX_CED_DETECTED";
305  break;
307  res = "ANALOG_EVENT_EC_NLP_DISABLED";
308  break;
310  res = "ANALOG_EVENT_EC_NLP_ENABLED";
311  break;
312 #endif
314  res = "ANALOG_EVENT_PULSEDIGIT";
315  break;
317  res = "ANALOG_EVENT_DTMFDOWN";
318  break;
319  case ANALOG_EVENT_DTMFUP:
320  res = "ANALOG_EVENT_DTMFUP";
321  break;
322  default:
323  res = "UNKNOWN/OTHER";
324  break;
325  }
326 
327  return res;
328 }
struct ast_frame* analog_exception ( struct analog_pvt p,
struct ast_channel ast 
)

Definition at line 3515 of file sig_analog.c.

References __analog_handle_event(), ast_channel::_state, analog_event2str(), ANALOG_EVENT_HOOKCOMPLETE, ANALOG_EVENT_ONHOOK, ANALOG_EVENT_RINGEROFF, ANALOG_EVENT_RINGERON, ANALOG_EVENT_RINGOFFHOOK, ANALOG_EVENT_WINKFLASH, analog_get_event(), analog_get_index, analog_lock_private(), analog_off_hook(), analog_ring(), analog_set_dialing(), analog_set_echocanceller(), analog_set_new_owner(), analog_stop_callwait(), ANALOG_SUB_REAL, analog_unlock_private(), analog_update_conf(), ast_bridged_channel(), ast_channel_lock, ast_channel_unlock, AST_CONTROL_ANSWER, AST_CONTROL_UNHOLD, ast_debug, AST_FRAME_NULL, ast_log(), ast_queue_control(), ast_set_hangupsource(), ast_setstate(), AST_STATE_RINGING, AST_STATE_UP, ast_strdupa, ast_tv(), ast_verb, analog_pvt::channel, ast_frame::data, ast_frame::datalen, ast_frame::delivery, f, analog_subchannel::f, ast_channel::fds, analog_pvt::flashtime, ast_frame::frametype, ast_frame_subclass::integer, LOG_WARNING, ast_frame::mallocd, name, ast_channel::name, ast_frame::offset, analog_subchannel::owner, analog_pvt::owner, ast_frame::ptr, ast_frame::samples, ast_frame::src, ast_frame::subclass, and analog_pvt::subs.

Referenced by dahdi_exception(), and dahdi_read().

3516 {
3517  int res;
3518  int idx;
3519  struct ast_frame *f;
3520 
3521  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
3522 
3523  idx = analog_get_index(ast, p, 1);
3524  if (idx < 0) {
3525  idx = ANALOG_SUB_REAL;
3526  }
3527 
3528  p->subs[idx].f.frametype = AST_FRAME_NULL;
3529  p->subs[idx].f.datalen = 0;
3530  p->subs[idx].f.samples = 0;
3531  p->subs[idx].f.mallocd = 0;
3532  p->subs[idx].f.offset = 0;
3533  p->subs[idx].f.subclass.integer = 0;
3534  p->subs[idx].f.delivery = ast_tv(0,0);
3535  p->subs[idx].f.src = "dahdi_exception";
3536  p->subs[idx].f.data.ptr = NULL;
3537 
3538  if (!p->owner) {
3539  /* If nobody owns us, absorb the event appropriately, otherwise
3540  we loop indefinitely. This occurs when, during call waiting, the
3541  other end hangs up our channel so that it no longer exists, but we
3542  have neither FLASH'd nor ONHOOK'd to signify our desire to
3543  change to the other channel. */
3544  res = analog_get_event(p);
3545 
3546  /* Switch to real if there is one and this isn't something really silly... */
3547  if ((res != ANALOG_EVENT_RINGEROFF) && (res != ANALOG_EVENT_RINGERON) &&
3548  (res != ANALOG_EVENT_HOOKCOMPLETE)) {
3549  ast_debug(1, "Restoring owner of channel %d on event %d\n", p->channel, res);
3551  if (p->owner && ast != p->owner) {
3552  /*
3553  * Could this even happen?
3554  * Possible deadlock because we do not have the real-call lock.
3555  */
3556  ast_log(LOG_WARNING, "Event %s on %s is not restored owner %s\n",
3557  analog_event2str(res), ast->name, p->owner->name);
3558  }
3559  if (p->owner && ast_bridged_channel(p->owner)) {
3561  }
3562  }
3563  switch (res) {
3564  case ANALOG_EVENT_ONHOOK:
3566  if (p->owner) {
3567  ast_verb(3, "Channel %s still has call, ringing phone\n", p->owner->name);
3568  analog_ring(p);
3570  } else {
3571  ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
3572  analog_event2str(res));
3573  }
3574  analog_update_conf(p);
3575  break;
3578  analog_off_hook(p);
3579  if (p->owner && (p->owner->_state == AST_STATE_RINGING)) {
3581  analog_set_dialing(p, 0);
3582  }
3583  break;
3585  case ANALOG_EVENT_RINGERON:
3587  /* Do nothing */
3588  break;
3590  gettimeofday(&p->flashtime, NULL);
3591  if (p->owner) {
3592  ast_verb(3, "Channel %d flashed to other channel %s\n", p->channel, p->owner->name);
3593  if (p->owner->_state != AST_STATE_UP) {
3594  /* Answer if necessary */
3597  }
3599  if (ast_bridged_channel(p->owner)) {
3601  }
3602  } else {
3603  ast_log(LOG_WARNING, "Absorbed %s, but nobody is left!?!?\n",
3604  analog_event2str(res));
3605  }
3606  analog_update_conf(p);
3607  break;
3608  default:
3609  ast_log(LOG_WARNING, "Don't know how to absorb event %s\n", analog_event2str(res));
3610  break;
3611  }
3612  f = &p->subs[idx].f;
3613  return f;
3614  }
3615  ast_debug(1, "Exception on %d, channel %d\n", ast->fds[0],p->channel);
3616  /* If it's not us, return NULL immediately */
3617  if (ast != p->owner) {
3618  ast_log(LOG_WARNING, "We're %s, not %s\n", ast->name, p->owner->name);
3619  f = &p->subs[idx].f;
3620  return f;
3621  }
3622 
3623  f = __analog_handle_event(p, ast);
3624  if (!f) {
3625  const char *name = ast_strdupa(ast->name);
3626 
3627  /* Tell the CDR this DAHDI device hung up */
3629  ast_channel_unlock(ast);
3630  ast_set_hangupsource(ast, name, 0);
3631  ast_channel_lock(ast);
3633  }
3634  return f;
3635 }
union ast_frame_subclass subclass
Definition: frame.h:146
#define analog_get_index(ast, p, nullok)
Definition: sig_analog.c:389
#define ast_channel_lock(chan)
Definition: channel.h:2466
int offset
Definition: frame.h:156
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame with payload.
Definition: channel.c:1601
static struct ast_frame * __analog_handle_event(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:2651
static int analog_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:592
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
struct ast_channel * owner
Definition: sig_analog.h:245
static int analog_get_event(struct analog_pvt *p)
Definition: sig_analog.c:191
struct timeval flashtime
Definition: sig_analog.h:334
#define ast_verb(level,...)
Definition: logger.h:243
struct ast_channel * owner
Definition: sig_analog.h:260
static void analog_unlock_private(struct analog_pvt *p)
Definition: sig_analog.c:542
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
void ast_set_hangupsource(struct ast_channel *chan, const char *source, int force)
Set the source of the hangup in this channel and it&#39;s bridge.
Definition: channel.c:2769
const char * src
Definition: frame.h:158
int datalen
Definition: frame.h:148
static int analog_stop_callwait(struct analog_pvt *p)
Definition: sig_analog.c:870
int fds[AST_MAX_FDS]
Definition: channel.h:829
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static char * analog_event2str(enum analog_event event)
Definition: sig_analog.c:247
enum ast_channel_state _state
Definition: channel.h:839
struct ast_channel * ast_bridged_channel(struct ast_channel *chan)
Find bridged channel.
Definition: channel.c:7160
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
static const char name[]
static struct ast_format f[]
Definition: format_g726.c:181
struct timeval delivery
Definition: frame.h:162
int mallocd
Definition: frame.h:152
static void analog_lock_private(struct analog_pvt *p)
Definition: sig_analog.c:549
static int analog_set_echocanceller(struct analog_pvt *p, int enable)
Definition: sig_analog.c:455
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
Definition: time.h:179
int ast_setstate(struct ast_channel *chan, enum ast_channel_state)
Change the state of a channel.
Definition: channel.c:7119
static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
Definition: sig_analog.c:428
Data structure associated with a single frame of data.
Definition: frame.h:142
struct ast_frame f
Definition: sig_analog.h:246
enum ast_frame_type frametype
Definition: frame.h:144
static int analog_update_conf(struct analog_pvt *p)
Definition: sig_analog.c:756
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
Definition: sig_analog.c:903
union ast_frame::@172 data
static int analog_ring(struct analog_pvt *p)
Definition: sig_analog.c:479
int samples
Definition: frame.h:150
int analog_fixup ( struct ast_channel oldchan,
struct ast_channel newchan,
void *  newp 
)

Definition at line 3937 of file sig_analog.c.

References analog_set_new_owner(), analog_update_conf(), ast_debug, analog_pvt::channel, ast_channel::name, analog_subchannel::owner, analog_pvt::owner, and analog_pvt::subs.

Referenced by dahdi_fixup().

3938 {
3939  struct analog_pvt *new_pvt = newp;
3940  int x;
3941  ast_debug(1, "New owner for channel %d is %s\n", new_pvt->channel, newchan->name);
3942  if (new_pvt->owner == oldchan) {
3943  analog_set_new_owner(new_pvt, newchan);
3944  }
3945  for (x = 0; x < 3; x++) {
3946  if (new_pvt->subs[x].owner == oldchan) {
3947  new_pvt->subs[x].owner = newchan;
3948  }
3949  }
3950 
3951  analog_update_conf(new_pvt);
3952  return 0;
3953 }
struct ast_channel * owner
Definition: sig_analog.h:245
struct ast_channel * owner
Definition: sig_analog.h:260
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
const ast_string_field name
Definition: channel.h:787
static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
Definition: sig_analog.c:428
static int analog_update_conf(struct analog_pvt *p)
Definition: sig_analog.c:756
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
static int analog_flash ( struct analog_pvt p)
static

Definition at line 487 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::flash.

Referenced by __analog_ss_thread().

488 {
489  if (p->calls->flash) {
490  return p->calls->flash(p->chan_pvt);
491  }
492  return -1;
493 }
int(*const flash)(void *pvt)
Definition: sig_analog.h:149
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
void analog_free ( struct analog_pvt p)

Definition at line 3931 of file sig_analog.c.

References ast_free.

3932 {
3933  ast_free(p);
3934 }
#define ast_free(a)
Definition: astmm.h:97
static void analog_get_and_handle_alarms ( struct analog_pvt p)
static

Definition at line 1687 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::get_and_handle_alarms.

Referenced by __analog_handle_event(), and analog_handle_init_event().

1688 {
1689  if (p->calls->get_and_handle_alarms) {
1690  return p->calls->get_and_handle_alarms(p->chan_pvt);
1691  }
1692 }
void(*const get_and_handle_alarms)(void *pvt)
Definition: sig_analog.h:220
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static void* analog_get_bridged_channel ( struct analog_pvt p,
struct ast_channel chan 
)
static

Definition at line 1694 of file sig_analog.c.

References analog_pvt::calls, and analog_callback::get_sigpvt_bridged_channel.

Referenced by __analog_ss_thread().

1695 {
1697  return p->calls->get_sigpvt_bridged_channel(chan);
1698  }
1699  return NULL;
1700 }
void *(*const get_sigpvt_bridged_channel)(struct ast_channel *chan)
Definition: sig_analog.h:221
struct analog_callback * calls
Definition: sig_analog.h:258
static int analog_get_callerid ( struct analog_pvt p,
char *  name,
char *  number,
enum analog_event ev,
size_t  timeout 
)
static

Definition at line 175 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::get_callerid.

Referenced by __analog_ss_thread().

176 {
177  if (p->calls->get_callerid) {
178  return p->calls->get_callerid(p->chan_pvt, name, number, ev, timeout);
179  }
180  return -1;
181 }
Number structure.
Definition: app_followme.c:109
static const char name[]
int(*const get_callerid)(void *pvt, char *name, char *num, enum analog_event *ev, size_t timeout)
Definition: sig_analog.h:176
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_get_event ( struct analog_pvt p)
static

Definition at line 191 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::get_event.

Referenced by __analog_handle_event(), and analog_exception().

192 {
193  if (p->calls->get_event) {
194  return p->calls->get_event(p->chan_pvt);
195  }
196  return -1;
197 }
struct analog_callback * calls
Definition: sig_analog.h:258
int(*const get_event)(void *pvt)
Definition: sig_analog.h:142
void * chan_pvt
Definition: sig_analog.h:256
static const char* analog_get_orig_dialstring ( struct analog_pvt p)
static

Definition at line 183 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::get_orig_dialstring.

Referenced by analog_call().

184 {
185  if (p->calls->get_orig_dialstring) {
186  return p->calls->get_orig_dialstring(p->chan_pvt);
187  }
188  return "";
189 }
struct analog_callback * calls
Definition: sig_analog.h:258
const char *(*const get_orig_dialstring)(void *pvt)
Definition: sig_analog.h:238
void * chan_pvt
Definition: sig_analog.h:256
static int analog_get_sub_fd ( struct analog_pvt p,
enum analog_sub  sub 
)
static

Definition at line 1702 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::get_sub_fd.

Referenced by __analog_handle_event().

1703 {
1704  if (p->calls->get_sub_fd) {
1705  return p->calls->get_sub_fd(p->chan_pvt, sub);
1706  }
1707  return -1;
1708 }
int(*const get_sub_fd)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:222
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
void analog_handle_dtmf ( struct analog_pvt p,
struct ast_channel ast,
enum analog_sub  idx,
struct ast_frame **  dest 
)

Definition at line 1589 of file sig_analog.c.

References analog_cb_handle_dtmf(), analog_check_confirmanswer(), analog_handles_digit(), analog_send_callerid(), analog_set_confirmanswer(), AST_CONTROL_ANSWER, ast_debug, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_NULL, analog_pvt::caller, analog_pvt::callwait_name, analog_pvt::callwait_num, analog_pvt::callwaitcas, f, analog_subchannel::f, ast_frame::frametype, ast_party_caller::id, ast_frame_subclass::integer, ast_party_id::name, ast_channel::name, ast_party_id::number, ast_party_name::str, ast_party_number::str, ast_frame::subclass, and analog_pvt::subs.

Referenced by __analog_handle_event(), and dahdi_read().

1590 {
1591  struct ast_frame *f = *dest;
1592 
1593  ast_debug(1, "%s DTMF digit: 0x%02X '%c' on %s\n",
1594  f->frametype == AST_FRAME_DTMF_BEGIN ? "Begin" : "End",
1595  (unsigned)f->subclass.integer, f->subclass.integer, ast->name);
1596 
1597  if (analog_check_confirmanswer(p)) {
1598  if (f->frametype == AST_FRAME_DTMF_END) {
1599  ast_debug(1, "Confirm answer on %s!\n", ast->name);
1600  /* Upon receiving a DTMF digit, consider this an answer confirmation instead
1601  of a DTMF digit */
1602  p->subs[idx].f.frametype = AST_FRAME_CONTROL;
1604  /* Reset confirmanswer so DTMF's will behave properly for the duration of the call */
1606  } else {
1607  p->subs[idx].f.frametype = AST_FRAME_NULL;
1608  p->subs[idx].f.subclass.integer = 0;
1609  }
1610  *dest = &p->subs[idx].f;
1611  } else if (p->callwaitcas) {
1612  if (f->frametype == AST_FRAME_DTMF_END) {
1613  if ((f->subclass.integer == 'A') || (f->subclass.integer == 'D')) {
1614  ast_debug(1, "Got some DTMF, but it's for the CAS\n");
1615  p->caller.id.name.str = p->callwait_name;
1616  p->caller.id.number.str = p->callwait_num;
1617  analog_send_callerid(p, 1, &p->caller);
1618  }
1619  if (analog_handles_digit(f)) {
1620  p->callwaitcas = 0;
1621  }
1622  }
1623  p->subs[idx].f.frametype = AST_FRAME_NULL;
1624  p->subs[idx].f.subclass.integer = 0;
1625  *dest = &p->subs[idx].f;
1626  } else {
1627  analog_cb_handle_dtmf(p, ast, idx, dest);
1628  }
1629 }
static int analog_send_callerid(struct analog_pvt *p, int cwcid, struct ast_party_caller *caller)
Definition: sig_analog.c:373
static int analog_handles_digit(struct ast_frame *f)
Definition: sig_analog.c:1564
union ast_frame_subclass subclass
Definition: frame.h:146
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
struct ast_party_caller caller
Definition: sig_analog.h:327
struct ast_party_name name
Subscriber name.
Definition: channel.h:290
char callwait_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:324
char * str
Subscriber name (Malloced)
Definition: channel.h:214
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
char callwait_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:323
const ast_string_field name
Definition: channel.h:787
static void analog_cb_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest)
Definition: sig_analog.c:644
static int analog_check_confirmanswer(struct analog_pvt *p)
Definition: sig_analog.c:952
static struct ast_format f[]
Definition: format_g726.c:181
static void analog_set_confirmanswer(struct analog_pvt *p, int flag)
Definition: sig_analog.c:944
Data structure associated with a single frame of data.
Definition: frame.h:142
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
Definition: sig_analog.h:321
struct ast_frame f
Definition: sig_analog.h:246
enum ast_frame_type frametype
Definition: frame.h:144
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292
void* analog_handle_init_event ( struct analog_pvt i,
int  event 
)

Definition at line 3637 of file sig_analog.c.

References __analog_ss_thread(), analog_cancel_cidspill(), ANALOG_CID_START_DTMF_NOALERT, ANALOG_CID_START_POLARITY, ANALOG_CID_START_POLARITY_IN, analog_event2str(), ANALOG_EVENT_ALARM, ANALOG_EVENT_DTMFCID, ANALOG_EVENT_NEONMWI_ACTIVE, ANALOG_EVENT_NEONMWI_INACTIVE, ANALOG_EVENT_NOALARM, ANALOG_EVENT_ONHOOK, ANALOG_EVENT_POLARITY, ANALOG_EVENT_REMOVED, ANALOG_EVENT_RINGOFFHOOK, ANALOG_EVENT_WINKFLASH, analog_get_and_handle_alarms(), analog_handle_notify_message(), analog_has_voicemail(), analog_new_ast_channel(), analog_off_hook(), analog_on_hook(), analog_play_tone(), analog_set_alarm(), analog_set_echocanceller(), 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_start_polarityswitch(), ANALOG_SUB_REAL, ANALOG_TONE_CONGESTION, ANALOG_TONE_DIALTONE, ANALOG_TONE_RINGTONE, ANALOG_TONE_STUTTER, ast_debug, ast_hangup(), ast_log(), ast_pthread_create_detached, AST_STATE_PRERING, AST_STATE_RESERVED, AST_STATE_RING, ast_verb, analog_pvt::chan_pvt, analog_pvt::channel, analog_pvt::cid_start, errno, EVENT_FLAG_SYSTEM, analog_pvt::fxsoffhookstate, analog_pvt::hanguponpolarityswitch, analog_pvt::immediate, analog_pvt::inalarm, LOG_NOTICE, LOG_WARNING, manager_event, analog_pvt::polarity, POLARITY_REV, analog_pvt::ringt_base, analog_pvt::sig, and analog_pvt::ss_astchan.

Referenced by do_monitor().

3638 {
3639  int res;
3640  pthread_t threadid;
3641  struct ast_channel *chan;
3642 
3643  ast_debug(1, "channel (%d) - signaling (%d) - event (%s)\n",
3644  i->channel, i->sig, analog_event2str(event));
3645 
3646  /* Handle an event on a given channel for the monitor thread. */
3647  switch (event) {
3650  if (i->inalarm) {
3651  break;
3652  }
3653  /* Got a ring/answer. What kind of channel are we? */
3654  switch (i->sig) {
3655  case ANALOG_SIG_FXOLS:
3656  case ANALOG_SIG_FXOGS:
3657  case ANALOG_SIG_FXOKS:
3658  res = analog_off_hook(i);
3659  i->fxsoffhookstate = 1;
3660  if (res && (errno == EBUSY)) {
3661  break;
3662  }
3663 
3664  /* Cancel VMWI spill */
3666 
3667  if (i->immediate) {
3669  /* The channel is immediately up. Start right away */
3672  if (!chan) {
3673  ast_log(LOG_WARNING, "Unable to start PBX on channel %d\n", i->channel);
3675  if (res < 0) {
3676  ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
3677  }
3678  }
3679  } else {
3680  /* Check for callerid, digits, etc */
3682  i->ss_astchan = chan;
3683  if (chan) {
3684  if (analog_has_voicemail(i)) {
3686  } else {
3688  }
3689  if (res < 0)
3690  ast_log(LOG_WARNING, "Unable to play dialtone on channel %d, do you have defaultzone and loadzone defined?\n", i->channel);
3691 
3692  if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
3693  ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
3695  if (res < 0) {
3696  ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
3697  }
3698  ast_hangup(chan);
3699  }
3700  } else
3701  ast_log(LOG_WARNING, "Unable to create channel\n");
3702  }
3703  break;
3704  case ANALOG_SIG_FXSLS:
3705  case ANALOG_SIG_FXSGS:
3706  case ANALOG_SIG_FXSKS:
3708  /* Fall through */
3709  case ANALOG_SIG_EMWINK:
3710  case ANALOG_SIG_FEATD:
3711  case ANALOG_SIG_FEATDMF:
3712  case ANALOG_SIG_FEATDMF_TA:
3713  case ANALOG_SIG_E911:
3714  case ANALOG_SIG_FGC_CAMA:
3715  case ANALOG_SIG_FGC_CAMAMF:
3716  case ANALOG_SIG_FEATB:
3717  case ANALOG_SIG_EM:
3718  case ANALOG_SIG_EM_E1:
3719  case ANALOG_SIG_SFWINK:
3720  case ANALOG_SIG_SF_FEATD:
3721  case ANALOG_SIG_SF_FEATDMF:
3722  case ANALOG_SIG_SF_FEATB:
3723  case ANALOG_SIG_SF:
3724  /* Check for callerid, digits, etc */
3727  } else {
3729  }
3730  i->ss_astchan = chan;
3731  if (!chan) {
3732  ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
3733  } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
3734  ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
3736  if (res < 0) {
3737  ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
3738  }
3739  ast_hangup(chan);
3740  }
3741  break;
3742  default:
3743  ast_log(LOG_WARNING, "Don't know how to handle ring/answer with signalling %s on channel %d\n", analog_sigtype_to_str(i->sig), i->channel);
3745  if (res < 0) {
3746  ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
3747  }
3748  return NULL;
3749  }
3750  break;
3751  case ANALOG_EVENT_NOALARM:
3752  analog_set_alarm(i, 0);
3753  ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", i->channel);
3754  manager_event(EVENT_FLAG_SYSTEM, "AlarmClear",
3755  "Channel: %d\r\n", i->channel);
3756  break;
3757  case ANALOG_EVENT_ALARM:
3758  analog_set_alarm(i, 1);
3760  /* fall thru intentionally */
3761  case ANALOG_EVENT_ONHOOK:
3762  /* Back on hook. Hang up. */
3763  switch (i->sig) {
3764  case ANALOG_SIG_FXOLS:
3765  case ANALOG_SIG_FXOGS:
3766  i->fxsoffhookstate = 0;
3768  /* Fall through */
3769  case ANALOG_SIG_FEATD:
3770  case ANALOG_SIG_FEATDMF:
3771  case ANALOG_SIG_FEATDMF_TA:
3772  case ANALOG_SIG_E911:
3773  case ANALOG_SIG_FGC_CAMA:
3774  case ANALOG_SIG_FGC_CAMAMF:
3775  case ANALOG_SIG_FEATB:
3776  case ANALOG_SIG_EM:
3777  case ANALOG_SIG_EM_E1:
3778  case ANALOG_SIG_EMWINK:
3779  case ANALOG_SIG_SF_FEATD:
3780  case ANALOG_SIG_SF_FEATDMF:
3781  case ANALOG_SIG_SF_FEATB:
3782  case ANALOG_SIG_SF:
3783  case ANALOG_SIG_SFWINK:
3784  case ANALOG_SIG_FXSLS:
3785  case ANALOG_SIG_FXSGS:
3786  case ANALOG_SIG_FXSKS:
3788  res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
3789  analog_on_hook(i);
3790  break;
3791  case ANALOG_SIG_FXOKS:
3792  i->fxsoffhookstate = 0;
3795  /* Diddle the battery for the zhone */
3796 #ifdef ZHONE_HACK
3797  analog_off_hook(i);
3798  usleep(1);
3799 #endif
3800  res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
3801  analog_on_hook(i);
3802  break;
3803  default:
3804  ast_log(LOG_WARNING, "Don't know how to handle on hook with signalling %s on channel %d\n", analog_sigtype_to_str(i->sig), i->channel);
3805  res = analog_play_tone(i, ANALOG_SUB_REAL, -1);
3806  return NULL;
3807  }
3808  break;
3809  case ANALOG_EVENT_POLARITY:
3810  switch (i->sig) {
3811  case ANALOG_SIG_FXSLS:
3812  case ANALOG_SIG_FXSKS:
3813  case ANALOG_SIG_FXSGS:
3814  /* We have already got a PR before the channel was
3815  created, but it wasn't handled. We need polarity
3816  to be REV for remote hangup detection to work.
3817  At least in Spain */
3818  if (i->hanguponpolarityswitch) {
3819  i->polarity = POLARITY_REV;
3820  }
3822  i->polarity = POLARITY_REV;
3823  ast_verb(2, "Starting post polarity "
3824  "CID detection on channel %d\n",
3825  i->channel);
3827  i->ss_astchan = chan;
3828  if (!chan) {
3829  ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
3830  } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
3831  ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
3832  ast_hangup(chan);
3833  }
3834  }
3835  break;
3836  default:
3837  ast_log(LOG_WARNING, "handle_init_event detected "
3838  "polarity reversal on non-FXO (ANALOG_SIG_FXS) "
3839  "interface %d\n", i->channel);
3840  break;
3841  }
3842  break;
3843  case ANALOG_EVENT_DTMFCID:
3844  switch (i->sig) {
3845  case ANALOG_SIG_FXSLS:
3846  case ANALOG_SIG_FXSKS:
3847  case ANALOG_SIG_FXSGS:
3849  ast_verb(2, "Starting DTMF CID detection on channel %d\n",
3850  i->channel);
3852  i->ss_astchan = chan;
3853  if (!chan) {
3854  ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
3855  } else if (ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, i)) {
3856  ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
3857  ast_hangup(chan);
3858  }
3859  }
3860  break;
3861  default:
3862  ast_log(LOG_WARNING, "handle_init_event detected "
3863  "dtmfcid generation event on non-FXO (ANALOG_SIG_FXS) "
3864  "interface %d\n", i->channel);
3865  break;
3866  }
3867  break;
3868  case ANALOG_EVENT_REMOVED: /* destroy channel, will actually do so in do_monitor */
3869  ast_log(LOG_NOTICE, "Got ANALOG_EVENT_REMOVED. Destroying channel %d\n",
3870  i->channel);
3871  return i->chan_pvt;
3874  break;
3877  break;
3878  }
3879  return NULL;
3880 }
int ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2804
Main Channel structure associated with a channel.
Definition: channel.h:742
#define POLARITY_REV
Definition: sig_analog.c:57
unsigned int immediate
Definition: sig_analog.h:276
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:422
int polarity
Definition: sig_analog.h:330
static int analog_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:592
static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
Definition: sig_analog.c:420
int ringt_base
Definition: sig_analog.h:346
#define LOG_WARNING
Definition: logger.h:144
static int analog_handle_notify_message(struct ast_channel *chan, struct analog_pvt *p, int cid_flags, int neon_mwievent)
Definition: sig_analog.c:1651
static void analog_start_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:616
struct ast_channel * ss_astchan
Definition: sig_analog.h:342
#define ast_verb(level,...)
Definition: logger.h:243
#define EVENT_FLAG_SYSTEM
Definition: manager.h:71
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static void * __analog_ss_thread(void *data)
Definition: sig_analog.c:1739
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:436
const char * analog_sigtype_to_str(enum analog_sigtype sigtype)
Definition: sig_analog.c:120
static int analog_on_hook(struct analog_pvt *p)
Definition: sig_analog.c:511
enum analog_cid_start cid_start
Definition: sig_analog.h:300
static char * analog_event2str(enum analog_event event)
Definition: sig_analog.c:247
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
int errno
static int analog_has_voicemail(struct analog_pvt *p)
Definition: sig_analog.c:659
static int analog_set_echocanceller(struct analog_pvt *p, int enable)
Definition: sig_analog.c:455
unsigned int inalarm
Definition: sig_analog.h:314
int fxsoffhookstate
Definition: sig_analog.h:265
static void analog_cancel_cidspill(struct analog_pvt *p)
Definition: sig_analog.c:961
static void analog_get_and_handle_alarms(struct analog_pvt *p)
Definition: sig_analog.c:1687
unsigned int hanguponpolarityswitch
Definition: sig_analog.h:275
void * chan_pvt
Definition: sig_analog.h:256
static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
Definition: sig_analog.c:919
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:219
enum analog_sigtype sig
Definition: sig_analog.h:254
static void analog_set_alarm(struct analog_pvt *p, int in_alarm)
Definition: sig_analog.c:911
static int analog_handle_notify_message ( struct ast_channel chan,
struct analog_pvt p,
int  cid_flags,
int  neon_mwievent 
)
static

Definition at line 1651 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::handle_notify_message.

Referenced by __analog_ss_thread(), and analog_handle_init_event().

1652 {
1653  if (p->calls->handle_notify_message) {
1654  p->calls->handle_notify_message(chan, p->chan_pvt, cid_flags, neon_mwievent);
1655  return 0;
1656  }
1657  return -1;
1658 }
void(*const handle_notify_message)(struct ast_channel *chan, void *pvt, int cid_flags, int neon_mwievent)
Definition: sig_analog.h:210
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_handles_digit ( struct ast_frame f)
static

Definition at line 1564 of file sig_analog.c.

References ast_frame_subclass::integer, and ast_frame::subclass.

Referenced by analog_handle_dtmf().

1565 {
1566  char subclass = toupper(f->subclass.integer);
1567 
1568  switch (subclass) {
1569  case '1':
1570  case '2':
1571  case '3':
1572  case '4':
1573  case '5':
1574  case '6':
1575  case '7':
1576  case '9':
1577  case 'A':
1578  case 'B':
1579  case 'C':
1580  case 'D':
1581  case 'E':
1582  case 'F':
1583  return 1;
1584  default:
1585  return 0;
1586  }
1587 }
union ast_frame_subclass subclass
Definition: frame.h:146
int analog_hangup ( struct analog_pvt p,
struct ast_channel ast 
)

Definition at line 1270 of file sig_analog.c.

References ast_channel::_state, analog_subchannel::allocd, analog_all_subchannels_hungup(), ANALOG_DIGITMODE_DTMF, analog_dsp_set_digitmode(), analog_get_index, analog_hangup_polarityswitch(), analog_is_off_hook(), analog_lock_sub_owner(), analog_on_hook(), analog_play_tone(), analog_set_callwaiting(), analog_set_confirmanswer(), analog_set_dialing(), analog_set_echocanceller(), analog_set_inthreeway(), analog_set_linear_mode(), analog_set_new_owner(), analog_set_outgoing(), analog_set_pulsedial(), analog_set_ringtimeout(), ANALOG_SIG_FXOGS, ANALOG_SIG_FXOKS, ANALOG_SIG_FXOLS, ANALOG_SIG_FXSGS, ANALOG_SIG_FXSKS, ANALOG_SIG_FXSLS, analog_stop_callwait(), ANALOG_SUB_CALLWAIT, ANALOG_SUB_REAL, ANALOG_SUB_THREEWAY, analog_swap_subs(), ANALOG_TONE_CONGESTION, analog_unalloc_sub(), analog_update_conf(), ast_bridged_channel(), ast_channel_setoption(), ast_channel_unlock, AST_CONTROL_ANSWER, AST_CONTROL_HOLD, AST_CONTROL_UNHOLD, ast_copy_string(), ast_debug, ast_free, ast_log(), AST_OPTION_TDD, AST_OPTION_TONE_VERIFY, ast_queue_control(), ast_queue_control_data(), AST_STATE_RESERVED, AST_STATE_UP, ast_strlen_zero(), ast_verb, analog_pvt::callwaitcas, analog_pvt::channel, analog_pvt::cid_name, analog_pvt::cid_num, analog_pvt::cidrings, analog_pvt::guardtime, analog_pvt::hidecallerid, analog_subchannel::inthreeway, LOG_ERROR, LOG_WARNING, analog_pvt::mohsuggest, ast_channel::name, analog_pvt::onhooktime, analog_pvt::origcid_name, analog_pvt::origcid_num, analog_subchannel::owner, analog_pvt::owner, analog_pvt::permcallwaiting, analog_pvt::permhidecallerid, analog_pvt::polarity, POLARITY_IDLE, S_OR, analog_pvt::sig, analog_pvt::subs, and ast_channel::tech_pvt.

Referenced by dahdi_hangup().

1271 {
1272  int res;
1273  int idx, x;
1274 
1275  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
1276  if (!ast->tech_pvt) {
1277  ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
1278  return 0;
1279  }
1280 
1281  idx = analog_get_index(ast, p, 1);
1282 
1283  x = 0;
1284  if (p->origcid_num) {
1285  ast_copy_string(p->cid_num, p->origcid_num, sizeof(p->cid_num));
1286  ast_free(p->origcid_num);
1287  p->origcid_num = NULL;
1288  }
1289  if (p->origcid_name) {
1290  ast_copy_string(p->cid_name, p->origcid_name, sizeof(p->cid_name));
1291  ast_free(p->origcid_name);
1292  p->origcid_name = NULL;
1293  }
1294 
1296 
1297  ast_debug(1, "Hangup: channel: %d index = %d, normal = %d, callwait = %d, thirdcall = %d\n",
1299  if (idx > -1) {
1300  /* Real channel, do some fixup */
1301  p->subs[idx].owner = NULL;
1302  p->polarity = POLARITY_IDLE;
1303  analog_set_linear_mode(p, idx, 0);
1304  switch (idx) {
1305  case ANALOG_SUB_REAL:
1307  ast_debug(1, "Normal call hung up with both three way call and a call waiting call in place?\n");
1309  /* We had flipped over to answer a callwait and now it's gone */
1310  ast_debug(1, "We were flipped over to the callwait, moving back and unowning.\n");
1311  /* Move to the call-wait, but un-own us until they flip back. */
1314  analog_set_new_owner(p, NULL);
1315  } else {
1316  /* The three way hung up, but we still have a call wait */
1317  ast_debug(1, "We were in the threeway and have a callwait still. Ditching the threeway.\n");
1320  if (p->subs[ANALOG_SUB_REAL].inthreeway) {
1321  /* This was part of a three way call. Immediately make way for
1322  another call */
1323  ast_debug(1, "Call was complete, setting owner to former third call\n");
1326  } else {
1327  /* This call hasn't been completed yet... Set owner to NULL */
1328  ast_debug(1, "Call was incomplete, setting owner to NULL\n");
1329  analog_set_new_owner(p, NULL);
1330  }
1331  }
1332  } else if (p->subs[ANALOG_SUB_CALLWAIT].allocd) {
1333  /* Need to hold the lock for real-call, private, and call-waiting call */
1335  if (!p->subs[ANALOG_SUB_CALLWAIT].owner) {
1336  /* The call waiting call dissappeared. */
1337  analog_set_new_owner(p, NULL);
1338  break;
1339  }
1340 
1341  /* Move to the call-wait and switch back to them. */
1345  if (p->owner->_state != AST_STATE_UP) {
1347  }
1350  }
1351  /* Unlock the call-waiting call that we swapped to real-call. */
1353  } else if (p->subs[ANALOG_SUB_THREEWAY].allocd) {
1356  if (p->subs[ANALOG_SUB_REAL].inthreeway) {
1357  /* This was part of a three way call. Immediately make way for
1358  another call */
1359  ast_debug(1, "Call was complete, setting owner to former third call\n");
1362  } else {
1363  /* This call hasn't been completed yet... Set owner to NULL */
1364  ast_debug(1, "Call was incomplete, setting owner to NULL\n");
1365  analog_set_new_owner(p, NULL);
1366  }
1367  }
1368  break;
1369  case ANALOG_SUB_CALLWAIT:
1370  /* Ditch the holding callwait call, and immediately make it available */
1372  /* Need to hold the lock for call-waiting call, private, and 3-way call */
1374 
1375  /* This is actually part of a three way, placed on hold. Place the third part
1376  on music on hold now */
1379  S_OR(p->mohsuggest, NULL),
1380  !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
1381  }
1383  /* Make it the call wait now */
1386  if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1387  /* Unlock the 3-way call that we swapped to call-waiting call. */
1389  }
1390  } else {
1392  }
1393  break;
1394  case ANALOG_SUB_THREEWAY:
1395  /* Need to hold the lock for 3-way call, private, and call-waiting call */
1398  /* The other party of the three way call is currently in a call-wait state.
1399  Start music on hold for them, and take the main guy out of the third call */
1403  S_OR(p->mohsuggest, NULL),
1404  !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0);
1405  }
1406  }
1407  if (p->subs[ANALOG_SUB_CALLWAIT].owner) {
1409  }
1411  /* If this was part of a three way call index, let us make
1412  another three way call */
1414  break;
1415  default:
1416  /*
1417  * Should never happen.
1418  * This wasn't any sort of call, so how are we an index?
1419  */
1420  ast_log(LOG_ERROR, "Index found but not any type of call?\n");
1421  break;
1422  }
1423  }
1424 
1426  analog_set_new_owner(p, NULL);
1427  analog_set_ringtimeout(p, 0);
1429  analog_set_pulsedial(p, 0);
1430  analog_set_outgoing(p, 0);
1431  p->onhooktime = time(NULL);
1432  p->cidrings = 1;
1433 
1434  /* Perform low level hangup if no owner left */
1435  res = analog_on_hook(p);
1436  if (res < 0) {
1437  ast_log(LOG_WARNING, "Unable to hangup line %s\n", ast->name);
1438  }
1439  switch (p->sig) {
1440  case ANALOG_SIG_FXOGS:
1441  case ANALOG_SIG_FXOLS:
1442  case ANALOG_SIG_FXOKS:
1443  /* If they're off hook, try playing congestion */
1444  if (analog_is_off_hook(p)) {
1447  } else {
1449  }
1450  break;
1451  case ANALOG_SIG_FXSGS:
1452  case ANALOG_SIG_FXSLS:
1453  case ANALOG_SIG_FXSKS:
1454  /* Make sure we're not made available for at least two seconds assuming
1455  we were actually used for an inbound or outbound call. */
1456  if (ast->_state != AST_STATE_RESERVED) {
1457  time(&p->guardtime);
1458  p->guardtime += 2;
1459  }
1460  break;
1461  default:
1463  break;
1464  }
1465 
1467 
1468  x = 0;
1469  ast_channel_setoption(ast,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0);
1470  ast_channel_setoption(ast,AST_OPTION_TDD,&x,sizeof(char),0);
1471  p->callwaitcas = 0;
1474  analog_set_dialing(p, 0);
1475  analog_update_conf(p);
1477  }
1478 
1480 
1481  ast_verb(3, "Hanging up on '%s'\n", ast->name);
1482 
1483  return 0;
1484 }
char cid_name[AST_MAX_EXTENSION]
Definition: sig_analog.h:303
#define POLARITY_IDLE
Definition: sig_analog.c:56
#define analog_get_index(ast, p, nullok)
Definition: sig_analog.c:389
static int analog_unalloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition: sig_analog.c:363
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame with payload.
Definition: channel.c:1601
int polarity
Definition: sig_analog.h:330
void * tech_pvt
Definition: channel.h:744
static int analog_set_linear_mode(struct analog_pvt *p, enum analog_sub sub, int linear_mode)
Definition: sig_analog.c:986
char mohsuggest[MAX_MUSICCLASS]
Definition: sig_analog.h:301
static int analog_play_tone(struct analog_pvt *p, enum analog_sub sub, enum analog_tone tone)
Definition: sig_analog.c:420
#define LOG_WARNING
Definition: logger.h:144
static void analog_lock_sub_owner(struct analog_pvt *pvt, enum analog_sub sub_idx)
Definition: sig_analog.c:571
struct ast_channel * owner
Definition: sig_analog.h:245
#define AST_OPTION_TDD
Definition: frame.h:445
time_t guardtime
Definition: sig_analog.h:333
#define AST_OPTION_TONE_VERIFY
Definition: frame.h:441
static void analog_all_subchannels_hungup(struct analog_pvt *p)
Definition: sig_analog.c:535
unsigned int allocd
Definition: sig_analog.h:249
unsigned int hidecallerid
Definition: sig_analog.h:312
int ast_channel_setoption(struct ast_channel *channel, int option, void *data, int datalen, int block)
Sets an option on a channel.
Definition: channel.c:7795
static void analog_set_outgoing(struct analog_pvt *p, int is_outgoing)
Definition: sig_analog.c:519
static void analog_hangup_polarityswitch(struct analog_pvt *p)
Definition: sig_analog.c:629
#define ast_verb(level,...)
Definition: logger.h:243
struct ast_channel * owner
Definition: sig_analog.h:260
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
int onhooktime
Definition: sig_analog.h:264
static void analog_swap_subs(struct analog_pvt *p, enum analog_sub a, enum analog_sub b)
Definition: sig_analog.c:330
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static int analog_stop_callwait(struct analog_pvt *p)
Definition: sig_analog.c:870
char cid_num[AST_MAX_EXTENSION]
Definition: sig_analog.h:302
static void analog_set_inthreeway(struct analog_pvt *p, enum analog_sub sub, int inthreeway)
Definition: sig_analog.c:995
static int analog_on_hook(struct analog_pvt *p)
Definition: sig_analog.c:511
#define LOG_ERROR
Definition: logger.h:155
enum ast_channel_state _state
Definition: channel.h:839
struct ast_channel * ast_bridged_channel(struct ast_channel *chan)
Find bridged channel.
Definition: channel.c:7160
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
unsigned int inthreeway
Definition: sig_analog.h:247
char * origcid_num
Definition: sig_analog.h:337
#define ast_channel_unlock(chan)
Definition: channel.h:2467
#define ast_free(a)
Definition: astmm.h:97
static int analog_is_off_hook(struct analog_pvt *p)
Definition: sig_analog.c:471
static void analog_set_confirmanswer(struct analog_pvt *p, int flag)
Definition: sig_analog.c:944
char * origcid_name
Definition: sig_analog.h:338
unsigned int permhidecallerid
Definition: sig_analog.h:278
static void analog_set_callwaiting(struct analog_pvt *p, int callwaiting_enable)
Definition: sig_analog.c:888
static void analog_set_pulsedial(struct analog_pvt *p, int flag)
Definition: sig_analog.c:978
int cidrings
Definition: sig_analog.h:328
static int analog_set_echocanceller(struct analog_pvt *p, int enable)
Definition: sig_analog.c:455
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
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:1608
static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
Definition: sig_analog.c:428
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
Definition: sig_analog.h:321
static int analog_update_conf(struct analog_pvt *p)
Definition: sig_analog.c:756
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
static void analog_set_ringtimeout(struct analog_pvt *p, int ringt)
Definition: sig_analog.c:919
static void analog_set_dialing(struct analog_pvt *p, int is_dialing)
Definition: sig_analog.c:903
static int analog_dsp_set_digitmode(struct analog_pvt *p, enum analog_dsp_digitmode mode)
Definition: sig_analog.c:636
enum analog_sigtype sig
Definition: sig_analog.h:254
unsigned int permcallwaiting
Definition: sig_analog.h:277
static void analog_hangup_polarityswitch ( struct analog_pvt p)
static

Definition at line 629 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::hangup_polarityswitch.

Referenced by analog_hangup().

630 {
631  if (p->calls->hangup_polarityswitch) {
632  return p->calls->hangup_polarityswitch(p->chan_pvt);
633  }
634 }
void(*const hangup_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch and hanguponpolarityswitch.
Definition: sig_analog.h:162
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_has_voicemail ( struct analog_pvt p)
static

Definition at line 659 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::has_voicemail.

Referenced by __analog_handle_event(), and analog_handle_init_event().

660 {
661  if (p->calls->has_voicemail) {
662  return p->calls->has_voicemail(p->chan_pvt);
663  }
664  return -1;
665 }
int(*const has_voicemail)(void *pvt)
Definition: sig_analog.h:208
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_have_progressdetect ( struct analog_pvt p)
static

Definition at line 207 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::have_progressdetect.

Referenced by __analog_handle_event().

208 {
209  if (p->calls->have_progressdetect) {
210  return p->calls->have_progressdetect(p->chan_pvt);
211  }
212  /* Don't have progress detection. */
213  return 0;
214 }
int(*const have_progressdetect)(void *pvt)
Definition: sig_analog.h:239
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_increase_ss_count ( struct analog_pvt p)
static

Definition at line 1660 of file sig_analog.c.

References analog_pvt::calls, and analog_callback::increase_ss_count.

Referenced by __analog_ss_thread().

1661 {
1662  if (p->calls->increase_ss_count) {
1663  p->calls->increase_ss_count();
1664  return 0;
1665  }
1666  return -1;
1667 }
void(*const increase_ss_count)(void)
Definition: sig_analog.h:213
struct analog_callback * calls
Definition: sig_analog.h:258
static int analog_is_dialing ( struct analog_pvt p,
enum analog_sub  index 
)
static

Definition at line 667 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::is_dialing.

Referenced by __analog_handle_event().

668 {
669  if (p->calls->is_dialing) {
670  return p->calls->is_dialing(p->chan_pvt, index);
671  }
672  return -1;
673 }
int(*const is_dialing)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:145
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_is_off_hook ( struct analog_pvt p)
static

Definition at line 471 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::is_off_hook.

Referenced by analog_available(), and analog_hangup().

472 {
473  if (p->calls->is_off_hook) {
474  return p->calls->is_off_hook(p->chan_pvt);
475  }
476  return -1;
477 }
int(*const is_off_hook)(void *pvt)
Definition: sig_analog.h:144
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static void analog_lock_private ( struct analog_pvt p)
static

Definition at line 549 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::lock_private.

Referenced by __analog_handle_event(), and analog_exception().

550 {
551  if (p->calls->lock_private) {
552  p->calls->lock_private(p->chan_pvt);
553  }
554 }
void(*const lock_private)(void *pvt)
Definition: sig_analog.h:133
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static void analog_lock_sub_owner ( struct analog_pvt pvt,
enum analog_sub  sub_idx 
)
static

Definition at line 571 of file sig_analog.c.

References ast_channel_trylock, analog_pvt::calls, analog_pvt::chan_pvt, analog_callback::deadlock_avoidance_private, analog_subchannel::owner, and analog_pvt::subs.

Referenced by __analog_handle_event(), and analog_hangup().

572 {
573  for (;;) {
574  if (!pvt->subs[sub_idx].owner) {
575  /* No subchannel owner pointer */
576  break;
577  }
578  if (!ast_channel_trylock(pvt->subs[sub_idx].owner)) {
579  /* Got subchannel owner lock */
580  break;
581  }
582  /* We must unlock the private to avoid the possibility of a deadlock */
583  if (pvt->calls->deadlock_avoidance_private) {
585  } else {
586  /* Don't use 100% CPU if required callback not present. */
587  usleep(1);
588  }
589  }
590 }
void(*const deadlock_avoidance_private)(void *pvt)
Definition: sig_analog.h:135
struct ast_channel * owner
Definition: sig_analog.h:245
struct analog_callback * calls
Definition: sig_analog.h:258
#define ast_channel_trylock(chan)
Definition: channel.h:2468
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
void * chan_pvt
Definition: sig_analog.h:256
static int analog_my_getsigstr ( struct ast_channel chan,
char *  str,
const char *  term,
int  ms 
)
static

Definition at line 1631 of file sig_analog.c.

References ast_waitfordigit().

Referenced by __analog_ss_thread().

1632 {
1633  char c;
1634 
1635  *str = 0; /* start with empty output buffer */
1636  for (;;) {
1637  /* Wait for the first digit (up to specified ms). */
1638  c = ast_waitfordigit(chan, ms);
1639  /* if timeout, hangup or error, return as such */
1640  if (c < 1) {
1641  return c;
1642  }
1643  *str++ = c;
1644  *str = 0;
1645  if (strchr(term, c)) {
1646  return 1;
1647  }
1648  }
1649 }
const char * str
Definition: app_jack.c:144
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3552
struct analog_pvt* analog_new ( enum analog_sigtype  signallingtype,
struct analog_callback c,
void *  private_data 
)

Definition at line 3883 of file sig_analog.c.

References analog_subchannel::allocd, ANALOG_CID_START_RING, ANALOG_SIG_NONE, ANALOG_SUB_REAL, ast_calloc, analog_pvt::calls, analog_pvt::chan_pvt, CID_SIG_BELL, analog_pvt::cid_signalling, analog_pvt::cid_start, analog_pvt::outsigmod, analog_pvt::sig, and analog_pvt::subs.

Referenced by mkintf().

3884 {
3885  struct analog_pvt *p;
3886 
3887  p = ast_calloc(1, sizeof(*p));
3888  if (!p) {
3889  return p;
3890  }
3891 
3892  p->calls = c;
3894  p->sig = signallingtype;
3895  p->chan_pvt = private_data;
3896 
3897  /* Some defaults for values */
3900  /* Sub real is assumed to always be alloc'd */
3901  p->subs[ANALOG_SUB_REAL].allocd = 1;
3902 
3903  return p;
3904 }
int cid_signalling
Definition: sig_analog.h:297
#define CID_SIG_BELL
Definition: callerid.h:59
unsigned int allocd
Definition: sig_analog.h:249
enum analog_cid_start cid_start
Definition: sig_analog.h:300
#define ast_calloc(a, b)
Definition: astmm.h:82
struct analog_callback * calls
Definition: sig_analog.h:258
enum analog_sigtype outsigmod
Definition: sig_analog.h:295
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
void * chan_pvt
Definition: sig_analog.h:256
enum analog_sigtype sig
Definition: sig_analog.h:254
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 
)
static

Definition at line 436 of file sig_analog.c.

References analog_set_new_owner(), ast_string_field_set, analog_pvt::call_forward, ast_channel::call_forward, analog_pvt::calls, analog_pvt::chan_pvt, analog_callback::new_ast_channel, analog_subchannel::owner, analog_pvt::owner, and analog_pvt::subs.

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

437 {
438  struct ast_channel *c;
439 
440  if (!p->calls->new_ast_channel) {
441  return NULL;
442  }
443 
444  c = p->calls->new_ast_channel(p->chan_pvt, state, startpbx, sub, requestor);
445  if (c) {
447  }
448  p->subs[sub].owner = c;
449  if (!p->owner) {
450  analog_set_new_owner(p, c);
451  }
452  return c;
453 }
Main Channel structure associated with a channel.
Definition: channel.h:742
struct ast_channel * owner
Definition: sig_analog.h:245
struct ast_channel * owner
Definition: sig_analog.h:260
struct ast_channel *(*const new_ast_channel)(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor)
Definition: sig_analog.h:193
const ast_string_field call_forward
Definition: channel.h:787
char call_forward[AST_MAX_EXTENSION]
Definition: sig_analog.h:339
struct analog_callback * calls
Definition: sig_analog.h:258
static void analog_set_new_owner(struct analog_pvt *p, struct ast_channel *new_owner)
Definition: sig_analog.c:428
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
void * chan_pvt
Definition: sig_analog.h:256
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:344
static int analog_off_hook ( struct analog_pvt p)
static

Definition at line 592 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::off_hook.

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

593 {
594  if (p->calls->off_hook) {
595  return p->calls->off_hook(p->chan_pvt);
596  }
597  return -1;
598 }
int(*const off_hook)(void *pvt)
Set channel off hook.
Definition: sig_analog.h:153
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_on_hook ( struct analog_pvt p)
static

Definition at line 511 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::on_hook.

Referenced by __analog_handle_event(), __analog_ss_thread(), analog_call(), analog_handle_init_event(), and analog_hangup().

512 {
513  if (p->calls->on_hook) {
514  return p->calls->on_hook(p->chan_pvt);
515  }
516  return -1;
517 }
int(*const on_hook)(void *pvt)
Set channel on hook.
Definition: sig_analog.h:151
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_play_tone ( struct analog_pvt p,
enum analog_sub  sub,
enum analog_tone  tone 
)
static

Definition at line 420 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::play_tone.

Referenced by __analog_handle_event(), __analog_ss_thread(), analog_answer(), analog_call(), analog_handle_init_event(), and analog_hangup().

421 {
422  if (p->calls->play_tone) {
423  return p->calls->play_tone(p->chan_pvt, sub, tone);
424  }
425  return -1;
426 }
int(*const play_tone)(void *pvt, enum analog_sub sub, enum analog_tone tone)
Definition: sig_analog.h:168
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
struct ast_channel* analog_request ( struct analog_pvt p,
int *  callwait,
const struct ast_channel requestor 
)

Definition at line 783 of file sig_analog.c.

References analog_alloc_sub(), analog_new_ast_channel(), analog_set_outgoing(), ANALOG_SUB_CALLWAIT, ANALOG_SUB_REAL, ast_debug, ast_log(), AST_STATE_RESERVED, analog_pvt::channel, LOG_ERROR, and analog_pvt::owner.

Referenced by dahdi_request().

784 {
785  struct ast_channel *ast;
786 
787  ast_debug(1, "%s %d\n", __FUNCTION__, p->channel);
788  *callwait = (p->owner != NULL);
789 
790  if (p->owner) {
792  ast_log(LOG_ERROR, "Unable to alloc subchannel\n");
793  return NULL;
794  }
795  }
796 
797  analog_set_outgoing(p, 1);
799  p->owner ? ANALOG_SUB_CALLWAIT : ANALOG_SUB_REAL, requestor);
800  if (!ast) {
801  analog_set_outgoing(p, 0);
802  }
803  return ast;
804 }
Main Channel structure associated with a channel.
Definition: channel.h:742
static void analog_set_outgoing(struct analog_pvt *p, int is_outgoing)
Definition: sig_analog.c:519
struct ast_channel * owner
Definition: sig_analog.h:260
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static int analog_alloc_sub(struct analog_pvt *p, enum analog_sub x)
Definition: sig_analog.c:350
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:436
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static int analog_ring ( struct analog_pvt p)
static

Definition at line 479 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::ring.

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

480 {
481  if (p->calls->ring) {
482  return p->calls->ring(p->chan_pvt);
483  }
484  return -1;
485 }
int(*const ring)(void *pvt)
Definition: sig_analog.h:148
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_send_callerid ( struct analog_pvt p,
int  cwcid,
struct ast_party_caller caller 
)
static

Definition at line 373 of file sig_analog.c.

References ast_debug, analog_pvt::calls, analog_pvt::callwaitcas, analog_pvt::chan_pvt, ast_party_caller::id, ast_party_id::name, ast_party_id::number, analog_callback::send_callerid, ast_party_name::str, and ast_party_number::str.

Referenced by __analog_handle_event(), and analog_handle_dtmf().

374 {
375  ast_debug(1, "Sending callerid. CID_NAME: '%s' CID_NUM: '%s'\n",
376  caller->id.name.str,
377  caller->id.number.str);
378 
379  if (cwcid) {
380  p->callwaitcas = 0;
381  }
382 
383  if (p->calls->send_callerid) {
384  return p->calls->send_callerid(p->chan_pvt, cwcid, caller);
385  }
386  return 0;
387 }
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
struct ast_party_name name
Subscriber name.
Definition: channel.h:290
char * str
Subscriber name (Malloced)
Definition: channel.h:214
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
int(*const send_callerid)(void *pvt, int cwcid, struct ast_party_caller *caller)
Definition: sig_analog.h:174
struct analog_callback * calls
Definition: sig_analog.h:258
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
Definition: sig_analog.h:321
void * chan_pvt
Definition: sig_analog.h:256
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292
static void analog_set_alarm ( struct analog_pvt p,
int  in_alarm 
)
static

Definition at line 911 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, analog_pvt::inalarm, and analog_callback::set_alarm.

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

912 {
913  p->inalarm = in_alarm;
914  if (p->calls->set_alarm) {
915  return p->calls->set_alarm(p->chan_pvt, in_alarm);
916  }
917 }
struct analog_callback * calls
Definition: sig_analog.h:258
unsigned int inalarm
Definition: sig_analog.h:314
void * chan_pvt
Definition: sig_analog.h:256
void(*const set_alarm)(void *pvt, int in_alarm)
Definition: sig_analog.h:224
static void analog_set_cadence ( struct analog_pvt p,
struct ast_channel chan 
)
static

Definition at line 896 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, analog_pvt::cidrings, and analog_callback::set_cadence.

Referenced by analog_call().

897 {
898  if (p->calls->set_cadence) {
899  return p->calls->set_cadence(p->chan_pvt, &p->cidrings, chan);
900  }
901 }
void(*const set_cadence)(void *pvt, int *cidrings, struct ast_channel *chan)
Definition: sig_analog.h:223
int cidrings
Definition: sig_analog.h:328
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static void analog_set_callwaiting ( struct analog_pvt p,
int  callwaiting_enable 
)
static

Definition at line 888 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::callwaiting, analog_pvt::chan_pvt, and analog_callback::set_callwaiting.

Referenced by __analog_ss_thread(), analog_config_complete(), and analog_hangup().

889 {
890  p->callwaiting = callwaiting_enable;
891  if (p->calls->set_callwaiting) {
892  p->calls->set_callwaiting(p->chan_pvt, callwaiting_enable);
893  }
894 }
void(*const set_callwaiting)(void *pvt, int callwaiting_enable)
Definition: sig_analog.h:232
unsigned int callwaiting
Definition: sig_analog.h:307
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static void analog_set_confirmanswer ( struct analog_pvt p,
int  flag 
)
static

Definition at line 944 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::set_confirmanswer.

Referenced by analog_handle_dtmf(), and analog_hangup().

945 {
946  if (!p->calls->set_confirmanswer) {
947  return;
948  }
949  p->calls->set_confirmanswer(p->chan_pvt, flag);
950 }
void(*const set_confirmanswer)(void *pvt, int flag)
Definition: sig_analog.h:230
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static void analog_set_dialing ( struct analog_pvt p,
int  is_dialing 
)
static

Definition at line 903 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, analog_pvt::dialing, and analog_callback::set_dialing.

Referenced by __analog_handle_event(), analog_answer(), analog_call(), analog_exception(), and analog_hangup().

904 {
905  p->dialing = is_dialing;
906  if (p->calls->set_dialing) {
907  return p->calls->set_dialing(p->chan_pvt, is_dialing);
908  }
909 }
unsigned int dialing
Definition: sig_analog.h:309
struct analog_callback * calls
Definition: sig_analog.h:258
void(*const set_dialing)(void *pvt, int is_dialing)
Definition: sig_analog.h:225
void * chan_pvt
Definition: sig_analog.h:256
static int analog_set_echocanceller ( struct analog_pvt p,
int  enable 
)
static

Definition at line 455 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::set_echocanceller.

Referenced by __analog_handle_event(), __analog_ss_thread(), analog_answer(), analog_exception(), analog_handle_init_event(), and analog_hangup().

456 {
457  if (p->calls->set_echocanceller) {
458  return p->calls->set_echocanceller(p->chan_pvt, enable);
459  }
460  return -1;
461 }
int(*const set_echocanceller)(void *pvt, int enable)
Definition: sig_analog.h:170
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static void analog_set_inthreeway ( struct analog_pvt p,
enum analog_sub  sub,
int  inthreeway 
)
static

Definition at line 995 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, analog_subchannel::inthreeway, analog_callback::set_inthreeway, and analog_pvt::subs.

Referenced by __analog_handle_event(), and analog_hangup().

996 {
997  p->subs[sub].inthreeway = inthreeway;
998  if (p->calls->set_inthreeway) {
999  p->calls->set_inthreeway(p->chan_pvt, sub, inthreeway);
1000  }
1001 }
void(*const set_inthreeway)(void *pvt, enum analog_sub sub, int inthreeway)
Definition: sig_analog.h:219
unsigned int inthreeway
Definition: sig_analog.h:247
struct analog_callback * calls
Definition: sig_analog.h:258
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
void * chan_pvt
Definition: sig_analog.h:256
static int analog_set_linear_mode ( struct analog_pvt p,
enum analog_sub  sub,
int  linear_mode 
)
static

Definition at line 986 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::set_linear_mode.

Referenced by __analog_ss_thread(), and analog_hangup().

987 {
988  if (p->calls->set_linear_mode) {
989  /* Return provides old linear_mode setting or error indication */
990  return p->calls->set_linear_mode(p->chan_pvt, sub, linear_mode);
991  }
992  return -1;
993 }
int(*const set_linear_mode)(void *pvt, enum analog_sub sub, int linear_mode)
Definition: sig_analog.h:218
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static void analog_set_needringing ( struct analog_pvt p,
int  value 
)
static

Definition at line 600 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::set_needringing.

Referenced by __analog_handle_event().

601 {
602  if (p->calls->set_needringing) {
603  return p->calls->set_needringing(p->chan_pvt, value);
604  }
605 }
int value
Definition: syslog.c:39
void(*const set_needringing)(void *pvt, int value)
Definition: sig_analog.h:154
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static void analog_set_new_owner ( struct analog_pvt p,
struct ast_channel new_owner 
)
static

Definition at line 428 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, analog_pvt::owner, and analog_callback::set_new_owner.

Referenced by __analog_handle_event(), __analog_ss_thread(), analog_answer(), analog_exception(), analog_fixup(), analog_hangup(), and analog_new_ast_channel().

429 {
430  p->owner = new_owner;
431  if (p->calls->set_new_owner) {
432  p->calls->set_new_owner(p->chan_pvt, new_owner);
433  }
434 }
void(*const set_new_owner)(void *pvt, struct ast_channel *new_owner)
Definition: sig_analog.h:236
struct ast_channel * owner
Definition: sig_analog.h:260
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static void analog_set_outgoing ( struct analog_pvt p,
int  is_outgoing 
)
static

Definition at line 519 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, analog_pvt::outgoing, and analog_callback::set_outgoing.

Referenced by analog_call(), analog_hangup(), and analog_request().

520 {
521  p->outgoing = is_outgoing;
522  if (p->calls->set_outgoing) {
523  p->calls->set_outgoing(p->chan_pvt, is_outgoing);
524  }
525 }
unsigned int outgoing
Definition: sig_analog.h:313
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
void(*const set_outgoing)(void *pvt, int is_outgoing)
Definition: sig_analog.h:226
static void analog_set_pulsedial ( struct analog_pvt p,
int  flag 
)
static

Definition at line 978 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::set_pulsedial.

Referenced by __analog_handle_event(), and analog_hangup().

979 {
980  if (!p->calls->set_pulsedial) {
981  return;
982  }
983  p->calls->set_pulsedial(p->chan_pvt, flag);
984 }
void(*const set_pulsedial)(void *pvt, int flag)
Definition: sig_analog.h:235
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static void analog_set_ringtimeout ( struct analog_pvt p,
int  ringt 
)
static

Definition at line 919 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, analog_pvt::ringt, and analog_callback::set_ringtimeout.

Referenced by __analog_handle_event(), __analog_ss_thread(), analog_answer(), analog_handle_init_event(), and analog_hangup().

920 {
921  p->ringt = ringt;
922  if (!p->calls->set_ringtimeout) {
923  return;
924  }
925  p->calls->set_ringtimeout(p->chan_pvt, ringt);
926 }
void(*const set_ringtimeout)(void *pvt, int ringt)
Definition: sig_analog.h:227
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static void analog_set_waitingfordt ( struct analog_pvt p,
struct ast_channel ast 
)
static

Definition at line 928 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::set_waitingfordt.

Referenced by analog_call().

929 {
930  if (p->calls->set_waitingfordt) {
931  return p->calls->set_waitingfordt(p->chan_pvt, ast);
932  }
933 }
void(*const set_waitingfordt)(void *pvt, struct ast_channel *ast)
Definition: sig_analog.h:228
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
const char* analog_sigtype_to_str ( enum analog_sigtype  sigtype)

Definition at line 120 of file sig_analog.c.

References ARRAY_LEN, and sigtypes.

Referenced by __analog_ss_thread(), and analog_handle_init_event().

121 {
122  int i;
123 
124  for (i = 0; i < ARRAY_LEN(sigtypes); i++) {
125  if (sigtype == sigtypes[i].sigtype) {
126  return sigtypes[i].name;
127  }
128  }
129 
130  return "Unknown";
131 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
enum analog_sigtype sigtype
Definition: sig_analog.c:66
static struct @118 sigtypes[]
int analog_ss_thread_start ( struct analog_pvt p,
struct ast_channel chan 
)

Definition at line 2644 of file sig_analog.c.

References __analog_ss_thread(), and ast_pthread_create_detached.

Referenced by mwi_thread().

2645 {
2646  pthread_t threadid;
2647 
2648  return ast_pthread_create_detached(&threadid, NULL, __analog_ss_thread, p);
2649 }
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:422
static void * __analog_ss_thread(void *data)
Definition: sig_analog.c:1739
static int analog_start ( struct analog_pvt p)
static

Definition at line 495 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::start.

Referenced by analog_call().

496 {
497  if (p->calls->start) {
498  return p->calls->start(p->chan_pvt);
499  }
500  return -1;
501 }
int(*const start)(void *pvt)
Definition: sig_analog.h:147
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_start_cid_detect ( struct analog_pvt p,
int  cid_signalling 
)
static

Definition at line 159 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::start_cid_detect.

Referenced by __analog_ss_thread().

160 {
161  if (p->calls->start_cid_detect) {
162  return p->calls->start_cid_detect(p->chan_pvt, cid_signalling);
163  }
164  return -1;
165 }
int(*const start_cid_detect)(void *pvt, int cid_signalling)
Definition: sig_analog.h:178
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static void analog_start_polarityswitch ( struct analog_pvt p)
static

Definition at line 616 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::start_polarityswitch.

Referenced by __analog_handle_event(), and analog_handle_init_event().

617 {
618  if (p->calls->start_polarityswitch) {
619  return p->calls->start_polarityswitch(p->chan_pvt);
620  }
621 }
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
void(*const start_polarityswitch)(void *pvt)
Reset FXS line polarity to IDLE, based on answeronpolarityswitch and hanguponpolarityswitch.
Definition: sig_analog.h:158
static int analog_stop_callwait ( struct analog_pvt p)
static

Definition at line 870 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::callwaitcas, analog_pvt::chan_pvt, and analog_callback::stop_callwait.

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

871 {
872  p->callwaitcas = 0;
873  if (p->calls->stop_callwait) {
874  return p->calls->stop_callwait(p->chan_pvt);
875  }
876  return 0;
877 }
int(*const stop_callwait)(void *pvt)
Definition: sig_analog.h:185
struct analog_callback * calls
Definition: sig_analog.h:258
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
Definition: sig_analog.h:321
void * chan_pvt
Definition: sig_analog.h:256
static int analog_stop_cid_detect ( struct analog_pvt p)
static

Definition at line 167 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::stop_cid_detect.

Referenced by __analog_ss_thread().

168 {
169  if (p->calls->stop_cid_detect) {
170  return p->calls->stop_cid_detect(p->chan_pvt);
171  }
172  return -1;
173 }
int(*const stop_cid_detect)(void *pvt)
Definition: sig_analog.h:180
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
enum analog_cid_start analog_str_to_cidstart ( const char *  value)

Definition at line 216 of file sig_analog.c.

References ANALOG_CID_START_DTMF_NOALERT, ANALOG_CID_START_POLARITY, ANALOG_CID_START_POLARITY_IN, and ANALOG_CID_START_RING.

217 {
218  if (!strcasecmp(value, "ring")) {
219  return ANALOG_CID_START_RING;
220  } else if (!strcasecmp(value, "polarity")) {
222  } else if (!strcasecmp(value, "polarity_in")) {
224  } else if (!strcasecmp(value, "dtmf")) {
226  }
227 
228  return 0;
229 }
int value
Definition: syslog.c:39
unsigned int analog_str_to_cidtype ( const char *  name)

Definition at line 133 of file sig_analog.c.

References ARRAY_LEN, and cidtypes.

134 {
135  int i;
136 
137  for (i = 0; i < ARRAY_LEN(cidtypes); i++) {
138  if (!strcasecmp(cidtypes[i].name, name)) {
139  return cidtypes[i].cid_type;
140  }
141  }
142 
143  return 0;
144 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct @119 cidtypes[]
static const char name[]
enum analog_sigtype analog_str_to_sigtype ( const char *  name)

Definition at line 107 of file sig_analog.c.

References ARRAY_LEN, and sigtypes.

108 {
109  int i;
110 
111  for (i = 0; i < ARRAY_LEN(sigtypes); i++) {
112  if (!strcasecmp(sigtypes[i].name, name)) {
113  return sigtypes[i].sigtype;
114  }
115  }
116 
117  return 0;
118 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static const char name[]
static struct @118 sigtypes[]
static void analog_swap_subs ( struct analog_pvt p,
enum analog_sub  a,
enum analog_sub  b 
)
static

Definition at line 330 of file sig_analog.c.

References ast_debug, analog_pvt::calls, analog_pvt::chan_pvt, analog_subchannel::inthreeway, analog_subchannel::owner, analog_pvt::subs, and analog_callback::swap_subs.

Referenced by __analog_handle_event(), __analog_ss_thread(), analog_answer(), and analog_hangup().

331 {
332  int tinthreeway;
333  struct ast_channel *towner;
334 
335  ast_debug(1, "Swapping %u and %u\n", a, b);
336 
337  towner = p->subs[a].owner;
338  p->subs[a].owner = p->subs[b].owner;
339  p->subs[b].owner = towner;
340 
341  tinthreeway = p->subs[a].inthreeway;
342  p->subs[a].inthreeway = p->subs[b].inthreeway;
343  p->subs[b].inthreeway = tinthreeway;
344 
345  if (p->calls->swap_subs) {
346  p->calls->swap_subs(p->chan_pvt, a, p->subs[a].owner, b, p->subs[b].owner);
347  }
348 }
Main Channel structure associated with a channel.
Definition: channel.h:742
void(*const swap_subs)(void *pvt, enum analog_sub a, struct ast_channel *new_a_owner, enum analog_sub b, struct ast_channel *new_b_owner)
Definition: sig_analog.h:192
struct ast_channel * owner
Definition: sig_analog.h:245
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
unsigned int inthreeway
Definition: sig_analog.h:247
struct analog_callback * calls
Definition: sig_analog.h:258
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
void * chan_pvt
Definition: sig_analog.h:256
static int analog_train_echocanceller ( struct analog_pvt p)
static

Definition at line 463 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::train_echocanceller.

Referenced by __analog_handle_event(), and analog_answer().

464 {
465  if (p->calls->train_echocanceller) {
466  return p->calls->train_echocanceller(p->chan_pvt);
467  }
468  return -1;
469 }
int(*const train_echocanceller)(void *pvt)
Definition: sig_analog.h:171
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_unalloc_sub ( struct analog_pvt p,
enum analog_sub  x 
)
static

Definition at line 363 of file sig_analog.c.

References analog_subchannel::allocd, analog_pvt::calls, analog_pvt::chan_pvt, analog_subchannel::owner, analog_pvt::subs, and analog_callback::unallocate_sub.

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

364 {
365  p->subs[x].allocd = 0;
366  p->subs[x].owner = NULL;
367  if (p->calls->unallocate_sub) {
368  return p->calls->unallocate_sub(p->chan_pvt, x);
369  }
370  return 0;
371 }
struct ast_channel * owner
Definition: sig_analog.h:245
unsigned int allocd
Definition: sig_analog.h:249
int(*const unallocate_sub)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:189
struct analog_callback * calls
Definition: sig_analog.h:258
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
void * chan_pvt
Definition: sig_analog.h:256
static void analog_unlock_private ( struct analog_pvt p)
static

Definition at line 542 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::unlock_private.

Referenced by __analog_handle_event(), and analog_exception().

543 {
544  if (p->calls->unlock_private) {
545  p->calls->unlock_private(p->chan_pvt);
546  }
547 }
void(*const unlock_private)(void *pvt)
Definition: sig_analog.h:131
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_update_conf ( struct analog_pvt p)
static

Definition at line 756 of file sig_analog.c.

References analog_subchannel::allocd, ast_debug, analog_pvt::calls, analog_pvt::chan_pvt, analog_pvt::channel, analog_callback::complete_conference_update, analog_callback::conf_add, analog_callback::conf_del, analog_subchannel::inthreeway, and analog_pvt::subs.

Referenced by __analog_handle_event(), analog_exception(), analog_fixup(), and analog_hangup().

757 {
758  int x;
759  int needconf = 0;
760 
761  /* Start with the obvious, general stuff */
762  for (x = 0; x < 3; x++) {
763  /* Look for three way calls */
764  if ((p->subs[x].allocd) && p->subs[x].inthreeway) {
765  if (p->calls->conf_add) {
766  p->calls->conf_add(p->chan_pvt, x);
767  }
768  needconf++;
769  } else {
770  if (p->calls->conf_del) {
771  p->calls->conf_del(p->chan_pvt, x);
772  }
773  }
774  }
775  ast_debug(1, "Updated conferencing on %d, with %d conference users\n", p->channel, needconf);
776 
778  p->calls->complete_conference_update(p->chan_pvt, needconf);
779  }
780  return 0;
781 }
int(*const conf_add)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:196
int(*const conf_del)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:198
unsigned int allocd
Definition: sig_analog.h:249
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
int(*const complete_conference_update)(void *pvt, int needconf)
Definition: sig_analog.h:202
unsigned int inthreeway
Definition: sig_analog.h:247
struct analog_callback * calls
Definition: sig_analog.h:258
struct analog_subchannel subs[3]
Definition: sig_analog.h:262
void * chan_pvt
Definition: sig_analog.h:256
static int analog_wait_event ( struct analog_pvt p)
static

Definition at line 199 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::wait_event.

Referenced by __analog_ss_thread().

200 {
201  if (p->calls->wait_event) {
202  return p->calls->wait_event(p->chan_pvt);
203  }
204  return -1;
205 }
int(*const wait_event)(void *pvt)
Definition: sig_analog.h:143
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256
static int analog_wink ( struct analog_pvt p,
enum analog_sub  index 
)
static

Definition at line 651 of file sig_analog.c.

References analog_pvt::calls, analog_pvt::chan_pvt, and analog_callback::wink.

Referenced by __analog_ss_thread().

652 {
653  if (p->calls->wink) {
654  return p->calls->wink(p->chan_pvt, index);
655  }
656  return -1;
657 }
int(*const wink)(void *pvt, enum analog_sub sub)
Definition: sig_analog.h:165
struct analog_callback * calls
Definition: sig_analog.h:258
void * chan_pvt
Definition: sig_analog.h:256

Variable Documentation

char analog_defaultcic[64] = ""
static

Definition at line 62 of file sig_analog.c.

Referenced by analog_call().

char analog_defaultozz[64] = ""
static

Definition at line 63 of file sig_analog.c.

Referenced by analog_call().

int analog_firstdigittimeout = 16000
static

Definition at line 61 of file sig_analog.c.

Referenced by __analog_ss_thread().

int analog_gendigittimeout = 8000
static

Definition at line 60 of file sig_analog.c.

Referenced by __analog_ss_thread().

int analog_matchdigittimeout = 3000
static

Definition at line 59 of file sig_analog.c.

Referenced by __analog_ss_thread().

unsigned int cid_type

Definition at line 93 of file sig_analog.c.

struct { ... } cidtypes[]
const char const* name

Definition at line 67 of file sig_analog.c.

enum analog_sigtype sigtype

Definition at line 66 of file sig_analog.c.

Referenced by sigtype_to_signalling().

struct { ... } sigtypes[]