Asterisk - The Open Source Telephony Project  18.5.0
sig_analog.h
Go to the documentation of this file.
1 #ifndef _SIG_ANALOG_H
2 #define _SIG_ANALOG_H
3 /*
4  * Asterisk -- An open source telephony toolkit.
5  *
6  * Copyright (C) 1999 - 2009, Digium, Inc.
7  *
8  * Mark Spencer <[email protected]>
9  *
10  * See http://www.asterisk.org for more information about
11  * the Asterisk project. Please do not directly contact
12  * any of the maintainers of this project for assistance;
13  * the project provides a web site, mailing lists and IRC
14  * channels for your use.
15  *
16  * This program is free software, distributed under the terms of
17  * the GNU General Public License Version 2. See the LICENSE file
18  * at the top of the source tree.
19  */
20 
21 /*! \file
22  *
23  * \brief Interface header for analog signaling module
24  *
25  * \author Matthew Fredrickson <[email protected]>
26  */
27 
28 #include "asterisk/channel.h"
29 #include "asterisk/frame.h"
30 #include "asterisk/smdi.h"
31 
32 #define ANALOG_SMDI_MD_WAIT_TIMEOUT 1500 /* 1.5 seconds */
33 #define ANALOG_MAX_CID 300
34 #define READ_SIZE 160
35 #define RING_PATTERNS 3
36 
37 /*! \brief Default time (ms) to detect first digit */
38 #define ANALOG_FIRST_DIGIT_TIMEOUT 16000
39 /*! \brief Default time (ms) to detect following digits */
40 #define ANALOG_INTER_DIGIT_TIMEOUT 8000
41 /*! \brief Default time (ms) to wait, in case of ambiguous match */
42 #define ANALOG_MATCH_DIGIT_TIMEOUT 3000
43 
44 /* Signalling types supported */
68 };
69 
77 };
78 
101  ANALOG_EVENT_ERROR, /* not a DAHDI event */
102  ANALOG_EVENT_DTMFCID, /* not a DAHDI event */
105  ANALOG_EVENT_DTMFUP = (1 << 18),
106 };
107 
109  ANALOG_SUB_REAL = 0, /*!< Active call */
110  ANALOG_SUB_CALLWAIT, /*!< Call-Waiting call on hold */
111  ANALOG_SUB_THREEWAY, /*!< Three-way call */
112 };
113 
117 };
118 
124 };
125 
126 enum dialop {
128 };
129 
130 
132  enum dialop op;
133  char dialstr[256];
134 };
135 
137  /* Unlock the private in the signalling private structure. This is used for three way calling madness. */
138  void (* const unlock_private)(void *pvt);
139  /* Lock the private in the signalling private structure. ... */
140  void (* const lock_private)(void *pvt);
141  /* Do deadlock avoidance for the private signaling structure lock. */
142  void (* const deadlock_avoidance_private)(void *pvt);
143 
144  /* Function which is called back to handle any other DTMF events that are received. Called by analog_handle_event. Why is this
145  * important to use, instead of just directly using events received before they are passed into the library? Because sometimes,
146  * (CWCID) the library absorbs DTMF events received. */
147  void (* const handle_dtmf)(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest);
148 
149  int (* const get_event)(void *pvt);
150  int (* const wait_event)(void *pvt);
151  int (* const is_off_hook)(void *pvt);
152  int (* const is_dialing)(void *pvt, enum analog_sub sub);
153  /* Start a trunk type signalling protocol (everything except phone ports basically */
154  int (* const start)(void *pvt);
155  int (* const ring)(void *pvt);
156  int (* const flash)(void *pvt);
157  /*! \brief Set channel on hook */
158  int (* const on_hook)(void *pvt);
159  /*! \brief Set channel off hook */
160  int (* const off_hook)(void *pvt);
161  void (* const set_needringing)(void *pvt, int value);
162  /*! \brief Set FXS line polarity to 0=IDLE NZ=REVERSED */
163  void (* const set_polarity)(void *pvt, int value);
164  /*! \brief Reset FXS line polarity to IDLE, based on answeronpolarityswitch and hanguponpolarityswitch */
165  void (* const start_polarityswitch)(void *pvt);
166  /*! \brief Switch FXS line polarity, based on answeronpolarityswitch=yes */
167  void (* const answer_polarityswitch)(void *pvt);
168  /*! \brief Switch FXS line polarity, based on answeronpolarityswitch and hanguponpolarityswitch */
169  void (* const hangup_polarityswitch)(void *pvt);
170  /* We're assuming that we're going to only wink on ANALOG_SUB_REAL - even though in the code there's an argument to the index
171  * function */
172  int (* const wink)(void *pvt, enum analog_sub sub);
173  int (* const dial_digits)(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop);
174  int (* const send_fsk)(void *pvt, struct ast_channel *ast, char *fsk);
175  int (* const play_tone)(void *pvt, enum analog_sub sub, enum analog_tone tone);
176 
177  int (* const set_echocanceller)(void *pvt, int enable);
178  int (* const train_echocanceller)(void *pvt);
179  int (* const dsp_set_digitmode)(void *pvt, enum analog_dsp_digitmode mode);
180  int (* const dsp_reset_and_flush_digits)(void *pvt);
181  int (* const send_callerid)(void *pvt, int cwcid, struct ast_party_caller *caller);
182  /* Returns 0 if CID received. Returns 1 if event received, and -1 if error. name and num are size ANALOG_MAX_CID */
183  int (* const get_callerid)(void *pvt, char *name, char *num, enum analog_event *ev, size_t timeout);
184  /* Start CID detection */
185  int (* const start_cid_detect)(void *pvt, int cid_signalling);
186  /* Stop CID detection */
187  int (* const stop_cid_detect)(void *pvt);
188 
189  /* Play the CAS callwait tone on the REAL sub, then repeat after 10 seconds, and then stop */
190  int (* const callwait)(void *pvt);
191  /* Stop playing any CAS call waiting announcement tones that might be running on the REAL sub */
192  int (* const stop_callwait)(void *pvt);
193 
194  /* Bearer control related (non signalling) callbacks */
195  int (* const allocate_sub)(void *pvt, enum analog_sub sub);
196  int (* const unallocate_sub)(void *pvt, enum analog_sub sub);
197  /*! This function is for swapping of the owners with the underlying subs. Typically it means you need to change the fds
198  * of the new owner to be the fds of the sub specified, for each of the two subs given */
199  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);
200  struct ast_channel * (* const new_ast_channel)(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor);
201 
202  /* Add the given sub to a conference */
203  int (* const conf_add)(void *pvt, enum analog_sub sub);
204  /* Delete the given sub from any conference that might be running on the channels */
205  int (* const conf_del)(void *pvt, enum analog_sub sub);
206 
207  /* If you would like to do any optimizations after the conference members have been added and removed,
208  * you can do so here */
209  int (* const complete_conference_update)(void *pvt, int needconf);
210 
211  /* This is called when there are no more subchannels on the given private that are left up,
212  * for any cleanup or whatever else you would like to do. Called from analog_hangup() */
213  void (* const all_subchannels_hungup)(void *pvt);
214 
215  int (* const has_voicemail)(void *pvt);
216  int (* const check_for_conference)(void *pvt);
217  void (* const handle_notify_message)(struct ast_channel *chan, void *pvt, int cid_flags, int neon_mwievent);
218 
219  /* callbacks for increasing and decreasing ss_thread_count, will handle locking and condition signal */
220  void (* const increase_ss_count)(void);
221  void (* const decrease_ss_count)(void);
222 
223  int (* const distinctive_ring)(struct ast_channel *chan, void *pvt, int idx, int *ringdata);
224  /* Sets the specified sub-channel in and out of signed linear mode, returns the value that was overwritten */
225  int (* const set_linear_mode)(void *pvt, enum analog_sub sub, int linear_mode);
226  void (* const set_inthreeway)(void *pvt, enum analog_sub sub, int inthreeway);
227  void (* const get_and_handle_alarms)(void *pvt);
228  void * (* const get_sigpvt_bridged_channel)(struct ast_channel *chan);
229  int (* const get_sub_fd)(void *pvt, enum analog_sub sub);
230  void (* const set_cadence)(void *pvt, int *cidrings, struct ast_channel *chan);
231  void (* const set_alarm)(void *pvt, int in_alarm);
232  void (* const set_dialing)(void *pvt, int is_dialing);
233  void (* const set_outgoing)(void *pvt, int is_outgoing);
234  void (* const set_ringtimeout)(void *pvt, int ringt);
235  void (* const set_waitingfordt)(void *pvt, struct ast_channel *ast);
236  int (* const check_waitingfordt)(void *pvt);
237  void (* const set_confirmanswer)(void *pvt, int flag);
238  int (* const check_confirmanswer)(void *pvt);
239  void (* const set_callwaiting)(void *pvt, int callwaiting_enable);
240  void (* const cancel_cidspill)(void *pvt);
241  int (* const confmute)(void *pvt, int mute);
242  void (* const set_pulsedial)(void *pvt, int flag);
243  void (* const set_new_owner)(void *pvt, struct ast_channel *new_owner);
244 
245  const char *(* const get_orig_dialstring)(void *pvt);
246  int (* const have_progressdetect)(void *pvt);
247  int (* const get_firstdigit_timeout)(void *pvt);
248  int (* const get_interdigit_timeout)(void *pvt);
249  int (* const get_matchdigit_timeout)(void *pvt);
250 };
251 
252 /*! Global analog callbacks to the upper layer. */
253 extern struct analog_callback analog_callbacks;
254 
255 
258  struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */
259  unsigned int inthreeway:1;
260  /* Have we allocated a subchannel yet or not */
261  unsigned int allocd:1;
262 };
263 
264 struct analog_pvt {
265  /* Analog signalling type used in this private */
266  enum analog_sigtype sig;
267  /* To contain the private structure passed into the channel callbacks */
268  void *chan_pvt;
269  /* All members after this are giong to be transient, and most will probably change */
270  struct ast_channel *owner; /*!< Our current active owner (if applicable) */
271 
272  struct analog_subchannel subs[3]; /*!< Sub-channels */
274  int onhooktime; /*< Time the interface went on-hook. */
275  int fxsoffhookstate; /*< TRUE if the FXS port is off-hook */
276  /*! \brief -1 = unknown, 0 = no messages, 1 = new messages available */
277  int msgstate;
278 
279  /* XXX: Option Variables - Set by allocator of private structure */
280  unsigned int answeronpolarityswitch:1;
281  unsigned int callreturn:1;
282  unsigned int cancallforward:1;
283  unsigned int canpark:1;
284  unsigned int dahditrcallerid:1; /*!< should we use the callerid from incoming call on dahdi transfer or not */
285  unsigned int hanguponpolarityswitch:1;
286  unsigned int immediate:1;
287  unsigned int permcallwaiting:1; /*!< TRUE if call waiting is enabled. (Configured option) */
288  unsigned int permhidecallerid:1; /*!< Whether to hide our outgoing caller ID or not */
289  unsigned int pulse:1;
290  unsigned int threewaycalling:1;
291  unsigned int transfer:1;
292  unsigned int transfertobusy:1; /*!< allow flash-transfers to busy channels */
293  unsigned int use_callerid:1; /*!< Whether or not to use caller id on this channel */
295  unsigned int callwaitingcallerid:1; /*!< TRUE if send caller ID for Call Waiting */
296  /*!
297  * \brief TRUE if SMDI (Simplified Message Desk Interface) is enabled
298  */
299  unsigned int use_smdi:1;
300  /*! \brief The SMDI interface to get SMDI messages from. */
302 
303  /* Not used for anything but log messages. Could be just the TCID */
304  int channel; /*!< Channel Number */
305 
306  enum analog_sigtype outsigmod;
308  int cid_signalling; /*!< Asterisk callerid type we're using */
310  int stripmsd;
311  enum analog_cid_start cid_start;
315 
316 
317  /* XXX: All variables after this are internal */
318  unsigned int callwaiting:1; /*!< TRUE if call waiting is enabled. (Active option) */
319  unsigned int dialednone:1;
320  unsigned int dialing:1; /*!< TRUE if in the process of dialing digits or sending something */
321  unsigned int dnd:1; /*!< TRUE if Do-Not-Disturb is enabled. */
322  unsigned int echobreak:1;
323  unsigned int hidecallerid:1;
324  unsigned int outgoing:1;
325  unsigned int inalarm:1;
326  /*!
327  * \brief TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
328  * \note
329  * After CAS is sent, the call waiting caller id will be sent if the phone
330  * gives a positive reply.
331  */
332  unsigned int callwaitcas:1;
333 
334  char callwait_num[AST_MAX_EXTENSION];
335  char callwait_name[AST_MAX_EXTENSION];
336  char lastcid_num[AST_MAX_EXTENSION];
337  char lastcid_name[AST_MAX_EXTENSION];
338  struct ast_party_caller caller;
339  int cidrings; /*!< Which ring to deliver CID on */
340  char echorest[20];
341  int polarity;
342  struct timeval polaritydelaytv;
343  char dialdest[256];
344  time_t guardtime; /*!< Must wait this much time before using for new call */
345  struct timeval flashtime; /*!< Last flash-hook time */
346  int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
347  char finaldial[64];
348  char *origcid_num; /*!< malloced original callerid */
349  char *origcid_name; /*!< malloced original callerid */
350  char call_forward[AST_MAX_EXTENSION];
351 
352  /* Ast channel to pass to __ss_analog_thread */
354 
355  /* All variables after this are definitely going to be audited */
356  int ringt;
358 };
359 
360 struct analog_pvt *analog_new(enum analog_sigtype signallingtype, void *private_data);
361 void analog_delete(struct analog_pvt *doomed);
362 
363 void analog_free(struct analog_pvt *p);
364 
365 int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout);
366 
367 int analog_hangup(struct analog_pvt *p, struct ast_channel *ast);
368 
369 int analog_answer(struct analog_pvt *p, struct ast_channel *ast);
370 
371 struct ast_frame *analog_exception(struct analog_pvt *p, struct ast_channel *ast);
372 
373 struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor);
374 
375 int analog_available(struct analog_pvt *p);
376 
377 void *analog_handle_init_event(struct analog_pvt *i, int event);
378 
379 int analog_config_complete(struct analog_pvt *p);
380 
381 void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub index, struct ast_frame **dest);
382 
384 
385 const char *analog_cidstart_to_str(enum analog_cid_start cid_start);
386 
387 enum analog_sigtype analog_str_to_sigtype(const char *name);
388 
390 
391 unsigned int analog_str_to_cidtype(const char *name);
392 
393 const char *analog_cidtype_to_str(unsigned int cid_type);
394 
395 int analog_ss_thread_start(struct analog_pvt *p, struct ast_channel *ast);
396 
397 int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp);
398 
399 int analog_dnd(struct analog_pvt *p, int flag);
400 
401 #endif /* _SIG_ANSLOG_H */
static void swap_subs(struct dahdi_pvt *p, int a, int b)
Definition: chan_dahdi.c:4058
analog_sigtype
Definition: sig_analog.h:45
static int conf_del(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index)
Definition: chan_dahdi.c:4506
struct ast_frame * analog_exception(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:3555
unsigned int threewaycalling
Definition: sig_analog.h:290
analog_event
Definition: sig_analog.h:79
unsigned int use_callerid
Definition: sig_analog.h:293
Main Channel structure associated with a channel.
struct ast_smdi_interface * smdi_iface
The SMDI interface to get SMDI messages from.
Definition: sig_analog.h:301
unsigned int immediate
Definition: sig_analog.h:286
int analog_config_complete(struct analog_pvt *p)
Definition: sig_analog.c:3963
analog_tone
Definition: sig_analog.h:70
int polarity
Definition: sig_analog.h:341
void analog_free(struct analog_pvt *p)
Definition: sig_analog.c:3975
#define MAX_MUSICCLASS
Definition: channel.h:174
static char get_event(const char *c)
static int wait_event(void)
Definition: muted.c:628
int echotraining
Definition: sig_analog.h:307
int ringt_base
Definition: sig_analog.h:357
static int timeout
Definition: cdr_mysql.c:86
unsigned int callreturn
Definition: sig_analog.h:281
struct ast_channel * owner
Definition: sig_analog.h:257
int cid_signalling
Definition: sig_analog.h:308
time_t guardtime
Definition: sig_analog.h:344
Definition: astman.c:222
const char *(*const get_orig_dialstring)(void *pvt)
Definition: sig_analog.h:245
unsigned int dialing
Definition: sig_analog.h:320
struct ast_channel * ss_astchan
Definition: sig_analog.h:353
unsigned int usedistinctiveringdetection
Definition: sig_analog.h:294
unsigned int transfertobusy
Definition: sig_analog.h:292
static int conf_add(struct dahdi_pvt *p, struct dahdi_subchannel *c, int index, int slavechannel)
Definition: chan_dahdi.c:4457
unsigned int allocd
Definition: sig_analog.h:261
int analog_answer(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:1461
int value
Definition: syslog.c:37
unsigned int hidecallerid
Definition: sig_analog.h:323
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:164
int polarityonanswerdelay
Definition: sig_analog.h:309
unsigned int use_smdi
TRUE if SMDI (Simplified Message Desk Interface) is enabled.
Definition: sig_analog.h:299
static int mute
Definition: chan_alsa.c:144
unsigned int cancallforward
Definition: sig_analog.h:282
struct ast_channel * owner
Definition: sig_analog.h:270
int analog_ss_thread_start(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:2665
dialop
Definition: sig_analog.h:126
int stripmsd
Definition: sig_analog.h:310
enum analog_sigtype sigtype
Definition: sig_analog.c:69
void *(*const get_sigpvt_bridged_channel)(struct ast_channel *chan)
Definition: sig_analog.h:228
General Asterisk PBX channel definitions.
int onhooktime
Definition: sig_analog.h:274
static char mohsuggest[MAX_MUSICCLASS]
Definition: chan_iax2.c:430
#define AST_MAX_EXTENSION
Definition: channel.h:135
Caller Party information.
Definition: channel.h:419
Asterisk internal frame definitions.
static int cidrings[NUM_CADENCE_MAX]
cidrings says in which pause to transmit the cid information, where the first pause is 1...
Definition: chan_dahdi.c:580
analog_sub
Definition: sig_analog.h:108
void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub index, struct ast_frame **dest)
Definition: sig_analog.c:1564
analog_cid_start
Definition: sig_analog.h:119
analog_dsp_digitmode
Definition: sig_analog.h:114
unsigned int dialednone
Definition: sig_analog.h:319
int analog_available(struct analog_pvt *p)
Definition: sig_analog.c:795
const char * analog_sigtype_to_str(enum analog_sigtype sigtype)
Definition: sig_analog.c:123
unsigned int outgoing
Definition: sig_analog.h:324
void * analog_handle_init_event(struct analog_pvt *i, int event)
Definition: sig_analog.c:3675
unsigned int analog_str_to_cidtype(const char *name)
Definition: sig_analog.c:136
unsigned int callwaiting
Definition: sig_analog.h:318
struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor)
Definition: sig_analog.c:772
int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout)
Definition: sig_analog.c:987
int analog_hangup(struct analog_pvt *p, struct ast_channel *ast)
Definition: sig_analog.c:1251
unsigned int inthreeway
Definition: sig_analog.h:259
char * origcid_num
Definition: sig_analog.h:348
long int flag
Definition: f2c.h:83
static const char name[]
Definition: cdr_mysql.c:74
int whichwink
Definition: sig_analog.h:346
unsigned int dahditrcallerid
Definition: sig_analog.h:284
int msgstate
-1 = unknown, 0 = no messages, 1 = new messages available
Definition: sig_analog.h:277
SMDI support for Asterisk.
char * origcid_name
Definition: sig_analog.h:349
unsigned int permhidecallerid
Definition: sig_analog.h:288
enum analog_cid_start analog_str_to_cidstart(const char *value)
Definition: sig_analog.c:234
static int send_callerid(struct dahdi_pvt *p)
Definition: chan_dahdi.c:5051
const char * analog_cidstart_to_str(enum analog_cid_start cid_start)
Definition: sig_analog.c:249
unsigned int dnd
Definition: sig_analog.h:321
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:165
int cidrings
Definition: sig_analog.h:339
static int has_voicemail(const char *mailbox, const char *folder)
Determines if the given folder has messages.
unsigned int callwaitingcallerid
Definition: sig_analog.h:295
int analog_dnd(struct analog_pvt *p, int flag)
Definition: sig_analog.c:4019
static int check_for_conference(struct dahdi_pvt *p)
Definition: chan_dahdi.c:7178
int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp)
Definition: sig_analog.c:3981
struct stasis_forward * sub
Definition: res_corosync.c:240
Data structure associated with a single frame of data.
unsigned int inalarm
Definition: sig_analog.h:325
int fxsoffhookstate
Definition: sig_analog.h:275
struct analog_pvt * analog_new(enum analog_sigtype signallingtype, void *private_data)
Definition: sig_analog.c:3928
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
Definition: sig_analog.h:332
static struct test_val b
unsigned int pulse
Definition: sig_analog.h:289
unsigned int transfer
Definition: sig_analog.h:291
unsigned int hanguponpolarityswitch
Definition: sig_analog.h:285
void * chan_pvt
Definition: sig_analog.h:268
enum analog_sigtype analog_str_to_sigtype(const char *name)
Definition: sig_analog.c:110
unsigned int canpark
Definition: sig_analog.h:283
const char * analog_cidtype_to_str(unsigned int cid_type)
Definition: sig_analog.c:149
unsigned int echobreak
Definition: sig_analog.h:322
unsigned int permcallwaiting
Definition: sig_analog.h:287
void analog_delete(struct analog_pvt *doomed)
Delete the analog private structure.
Definition: sig_analog.c:3958
unsigned int cid_type
Definition: sig_analog.c:96
struct analog_callback analog_callbacks
Definition: chan_dahdi.c:3355
unsigned int answeronpolarityswitch
Definition: sig_analog.h:280
static struct test_val a