Asterisk - The Open Source Telephony Project  21.4.1
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 <markster@digium.com>
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 <creslin@digium.com>
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 */
45 enum analog_sigtype {
46  ANALOG_SIG_NONE = -1,
47  ANALOG_SIG_FXOLS = 1,
48  ANALOG_SIG_FXOKS,
49  ANALOG_SIG_FXOGS,
50  ANALOG_SIG_FXSLS,
51  ANALOG_SIG_FXSKS,
52  ANALOG_SIG_FXSGS,
53  ANALOG_SIG_EMWINK,
54  ANALOG_SIG_EM,
55  ANALOG_SIG_EM_E1,
56  ANALOG_SIG_FEATD,
57  ANALOG_SIG_FEATDMF,
58  ANALOG_SIG_E911,
59  ANALOG_SIG_FGC_CAMA,
60  ANALOG_SIG_FGC_CAMAMF,
61  ANALOG_SIG_FEATB,
62  ANALOG_SIG_SFWINK,
63  ANALOG_SIG_SF,
64  ANALOG_SIG_SF_FEATD,
65  ANALOG_SIG_SF_FEATDMF,
66  ANALOG_SIG_FEATDMF_TA,
67  ANALOG_SIG_SF_FEATB,
68 };
69 
70 enum analog_tone {
71  ANALOG_TONE_RINGTONE = 0,
72  ANALOG_TONE_STUTTER,
73  ANALOG_TONE_CONGESTION,
74  ANALOG_TONE_DIALTONE,
75  ANALOG_TONE_DIALRECALL,
76  ANALOG_TONE_INFO,
77 };
78 
79 enum analog_event {
80  ANALOG_EVENT_NONE = 0,
81  ANALOG_EVENT_ONHOOK,
82  ANALOG_EVENT_RINGOFFHOOK,
83  ANALOG_EVENT_WINKFLASH,
84  ANALOG_EVENT_ALARM,
85  ANALOG_EVENT_NOALARM,
86  ANALOG_EVENT_DIALCOMPLETE,
87  ANALOG_EVENT_RINGERON,
88  ANALOG_EVENT_RINGEROFF,
89  ANALOG_EVENT_HOOKCOMPLETE,
90  ANALOG_EVENT_PULSE_START,
91  ANALOG_EVENT_POLARITY,
92  ANALOG_EVENT_RINGBEGIN,
93  ANALOG_EVENT_EC_DISABLED,
94  ANALOG_EVENT_REMOVED,
95  ANALOG_EVENT_NEONMWI_ACTIVE,
96  ANALOG_EVENT_NEONMWI_INACTIVE,
97  ANALOG_EVENT_TX_CED_DETECTED,
98  ANALOG_EVENT_RX_CED_DETECTED,
99  ANALOG_EVENT_EC_NLP_DISABLED,
100  ANALOG_EVENT_EC_NLP_ENABLED,
101  ANALOG_EVENT_ERROR, /* not a DAHDI event */
102  ANALOG_EVENT_DTMFCID, /* not a DAHDI event */
103  ANALOG_EVENT_PULSEDIGIT = (1 << 16),
104  ANALOG_EVENT_DTMFDOWN = (1 << 17),
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 
114 enum analog_dsp_digitmode {
115  ANALOG_DIGITMODE_DTMF = 1,
116  ANALOG_DIGITMODE_MF,
117 };
118 
119 enum analog_dialmode {
120  ANALOG_DIALMODE_BOTH = 0,
121  ANALOG_DIALMODE_PULSE,
122  ANALOG_DIALMODE_DTMF,
123  ANALOG_DIALMODE_NONE,
124 };
125 
126 enum analog_cid_start {
127  ANALOG_CID_START_POLARITY = 1,
128  ANALOG_CID_START_POLARITY_IN,
129  ANALOG_CID_START_RING,
130  ANALOG_CID_START_DTMF_NOALERT,
131 };
132 
133 enum dialop {
134  ANALOG_DIAL_OP_REPLACE = 2,
135 };
136 
137 
139  enum dialop op;
140  char dialstr[256];
141 };
142 
144  /* Unlock the private in the signalling private structure. This is used for three way calling madness. */
145  void (* const unlock_private)(void *pvt);
146  /* Lock the private in the signalling private structure. ... */
147  void (* const lock_private)(void *pvt);
148  /* Do deadlock avoidance for the private signaling structure lock. */
149  void (* const deadlock_avoidance_private)(void *pvt);
150 
151  /* Function which is called back to handle any other DTMF events that are received. Called by analog_handle_event. Why is this
152  * important to use, instead of just directly using events received before they are passed into the library? Because sometimes,
153  * (CWCID) the library absorbs DTMF events received. */
154  void (* const handle_dtmf)(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest);
155 
156  int (* const get_event)(void *pvt);
157  int (* const wait_event)(void *pvt);
158  int (* const is_off_hook)(void *pvt);
159  int (* const is_dialing)(void *pvt, enum analog_sub sub);
160  /* Start a trunk type signalling protocol (everything except phone ports basically */
161  int (* const start)(void *pvt);
162  int (* const ring)(void *pvt);
163  int (* const flash)(void *pvt);
164  /*! \brief Set channel on hook */
165  int (* const on_hook)(void *pvt);
166  /*! \brief Set channel off hook */
167  int (* const off_hook)(void *pvt);
168  void (* const set_needringing)(void *pvt, int value);
169  /*! \brief Set FXS line polarity to 0=IDLE NZ=REVERSED */
170  void (* const set_polarity)(void *pvt, int value);
171  /*! \brief Reset FXS line polarity to IDLE, based on answeronpolarityswitch and hanguponpolarityswitch */
172  void (* const start_polarityswitch)(void *pvt);
173  /*! \brief Switch FXS line polarity, based on answeronpolarityswitch=yes */
174  void (* const answer_polarityswitch)(void *pvt);
175  /*! \brief Switch FXS line polarity, based on answeronpolarityswitch and hanguponpolarityswitch */
176  void (* const hangup_polarityswitch)(void *pvt);
177  /* 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
178  * function */
179  int (* const wink)(void *pvt, enum analog_sub sub);
180  int (* const dial_digits)(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop);
181  int (* const send_fsk)(void *pvt, struct ast_channel *ast, char *fsk);
182  int (* const play_tone)(void *pvt, enum analog_sub sub, enum analog_tone tone);
183 
184  int (* const set_echocanceller)(void *pvt, int enable);
185  int (* const train_echocanceller)(void *pvt);
186  int (* const dsp_set_digitmode)(void *pvt, enum analog_dsp_digitmode mode);
187  int (* const dsp_reset_and_flush_digits)(void *pvt);
188  int (* const send_callerid)(void *pvt, int cwcid, struct ast_party_caller *caller);
189  /* Returns 0 if CID received. Returns 1 if event received, and -1 if error. name and num are size ANALOG_MAX_CID */
190  int (* const get_callerid)(void *pvt, char *name, char *num, enum analog_event *ev, size_t timeout);
191  /* Start CID detection */
192  int (* const start_cid_detect)(void *pvt, int cid_signalling);
193  /* Stop CID detection */
194  int (* const stop_cid_detect)(void *pvt);
195 
196  /* Play the CAS callwait tone on the REAL sub, then repeat after 10 seconds, and then stop */
197  int (* const callwait)(void *pvt);
198  /* Stop playing any CAS call waiting announcement tones that might be running on the REAL sub */
199  int (* const stop_callwait)(void *pvt);
200 
201  /* Bearer control related (non signalling) callbacks */
202  int (* const allocate_sub)(void *pvt, enum analog_sub sub);
203  int (* const unallocate_sub)(void *pvt, enum analog_sub sub);
204  /*! This function is for swapping of the owners with the underlying subs. Typically it means you need to change the fds
205  * of the new owner to be the fds of the sub specified, for each of the two subs given */
206  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);
207  struct ast_channel * (* const new_ast_channel)(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor);
208 
209  /* Add the given sub to a conference */
210  int (* const conf_add)(void *pvt, enum analog_sub sub);
211  /* Delete the given sub from any conference that might be running on the channels */
212  int (* const conf_del)(void *pvt, enum analog_sub sub);
213 
214  /* If you would like to do any optimizations after the conference members have been added and removed,
215  * you can do so here */
216  int (* const complete_conference_update)(void *pvt, int needconf);
217 
218  /* This is called when there are no more subchannels on the given private that are left up,
219  * for any cleanup or whatever else you would like to do. Called from analog_hangup() */
220  void (* const all_subchannels_hungup)(void *pvt);
221 
222  int (* const has_voicemail)(void *pvt);
223  int (* const check_for_conference)(void *pvt);
224  void (* const handle_notify_message)(struct ast_channel *chan, void *pvt, int cid_flags, int neon_mwievent);
225 
226  /* callbacks for increasing and decreasing ss_thread_count, will handle locking and condition signal */
227  void (* const increase_ss_count)(void);
228  void (* const decrease_ss_count)(void);
229 
230  int (* const distinctive_ring)(struct ast_channel *chan, void *pvt, int idx, int *ringdata);
231  /* Sets the specified sub-channel in and out of signed linear mode, returns the value that was overwritten */
232  int (* const set_linear_mode)(void *pvt, enum analog_sub sub, int linear_mode);
233  void (* const set_inthreeway)(void *pvt, enum analog_sub sub, int inthreeway);
234  void (* const get_and_handle_alarms)(void *pvt);
235  void * (* const get_sigpvt_bridged_channel)(struct ast_channel *chan);
236  int (* const get_sub_fd)(void *pvt, enum analog_sub sub);
237  void (* const set_cadence)(void *pvt, int *cidrings, struct ast_channel *chan);
238  void (* const set_alarm)(void *pvt, int in_alarm);
239  void (* const set_dialing)(void *pvt, int is_dialing);
240  void (* const set_outgoing)(void *pvt, int is_outgoing);
241  void (* const set_ringtimeout)(void *pvt, int ringt);
242  void (* const set_waitingfordt)(void *pvt, struct ast_channel *ast);
243  int (* const check_waitingfordt)(void *pvt);
244  void (* const set_confirmanswer)(void *pvt, int flag);
245  int (* const check_confirmanswer)(void *pvt);
246  void (* const set_callwaiting)(void *pvt, int callwaiting_enable);
247  void (* const cancel_cidspill)(void *pvt);
248  int (* const confmute)(void *pvt, int mute);
249  void (* const set_pulsedial)(void *pvt, int flag);
250  void (* const set_new_owner)(void *pvt, struct ast_channel *new_owner);
251 
252  const char *(* const get_orig_dialstring)(void *pvt);
253  int (* const have_progressdetect)(void *pvt);
254  int (* const get_firstdigit_timeout)(void *pvt);
255  int (* const get_interdigit_timeout)(void *pvt);
256  int (* const get_matchdigit_timeout)(void *pvt);
257 };
258 
259 /*! Global analog callbacks to the upper layer. */
260 extern struct analog_callback analog_callbacks;
261 
262 
264  struct ast_channel *owner;
265  struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */
266  unsigned int inthreeway:1;
267  /* Have we allocated a subchannel yet or not */
268  unsigned int allocd:1;
269 };
270 
271 struct analog_pvt {
272  /* Analog signalling type used in this private */
273  enum analog_sigtype sig;
274  /* To contain the private structure passed into the channel callbacks */
275  void *chan_pvt;
276  /* All members after this are going to be transient, and most will probably change */
277  struct ast_channel *owner; /*!< Our current active owner (if applicable) */
278 
279  struct analog_subchannel subs[3]; /*!< Sub-channels */
280  struct analog_dialoperation dop;
281  int onhooktime; /*< Time the interface went on-hook. */
282  int fxsoffhookstate; /*< TRUE if the FXS port is off-hook */
283  /*! \brief -1 = unknown, 0 = no messages, 1 = new messages available */
284  int msgstate;
285 
286  /* XXX: Option Variables - Set by allocator of private structure */
287  unsigned int ani_info_digits:8; /* Older switches use 1 INFO digit, newer switches use 2 */
288  unsigned int ani_timeout:16; /* Time in ms before we give up waiting for ANI spill */
289  unsigned int ani_wink_time:16; /* Safe wait time before we wink to start ANI spill */
290 
291  unsigned int answeronpolarityswitch:1;
292  unsigned int calledsubscriberheld:1; /*!< TRUE if a single incoming call can hold an FXS channel */
293  unsigned int callreturn:1;
294  unsigned int cancallforward:1;
295  unsigned int canpark:1;
296  unsigned int dahditrcallerid:1; /*!< should we use the callerid from incoming call on dahdi transfer or not */
297  unsigned int hanguponpolarityswitch:1;
298  unsigned int immediate:1;
299  unsigned int immediatering:1; /*!< TRUE if ringing should be provided for immediate execution */
300  unsigned int permcallwaiting:1; /*!< TRUE if call waiting is enabled. (Configured option) */
301  unsigned int permhidecallerid:1; /*!< Whether to hide our outgoing caller ID or not */
302  unsigned int pulse:1;
303  unsigned int threewaycalling:1;
304  unsigned int threewaysilenthold:1; /*!< Whether to time out a three-way dial tone to silence */
305  unsigned int transfer:1;
306  unsigned int transfertobusy:1; /*!< allow flash-transfers to busy channels */
307  unsigned int use_callerid:1; /*!< Whether or not to use caller id on this channel */
308  unsigned int usedistinctiveringdetection:1;
309  unsigned int callwaitingcallerid:1; /*!< TRUE if send caller ID for Call Waiting */
310  /*!
311  * \brief TRUE if SMDI (Simplified Message Desk Interface) is enabled
312  */
313  unsigned int use_smdi:1;
314  /*! \brief The SMDI interface to get SMDI messages from. */
316 
317  /* Not used for anything but log messages. Could be just the TCID */
318  int channel; /*!< Channel Number */
319 
320  enum analog_sigtype outsigmod;
321  enum analog_dialmode dialmode; /*!< Which of pulse and/or tone dialing to support */
322  int echotraining;
323  int cid_signalling; /*!< Asterisk callerid type we're using */
324  int polarityonanswerdelay;
325  int stripmsd;
326  enum analog_cid_start cid_start;
327  char mohsuggest[MAX_MUSICCLASS];
328  char cid_num[AST_MAX_EXTENSION];
329  char cid_name[AST_MAX_EXTENSION];
330 
331 
332  /* XXX: All variables after this are internal */
333  unsigned int callwaiting:1; /*!< TRUE if call waiting is enabled. (Active option) */
334  unsigned int cshactive:1; /*!< TRUE if FXS channel is currently held by an incoming call */
335  unsigned int dialednone:1;
336  unsigned int dialing:1; /*!< TRUE if in the process of dialing digits or sending something */
337  unsigned int dnd:1; /*!< TRUE if Do-Not-Disturb is enabled. */
338  unsigned int echobreak:1;
339  unsigned int hidecallerid:1;
340  unsigned int outgoing:1;
341  unsigned int inalarm:1;
342  /*!
343  * \brief TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
344  * \note
345  * After CAS is sent, the call waiting caller id will be sent if the phone
346  * gives a positive reply.
347  */
348  unsigned int callwaitcas:1;
349  unsigned int call_qualifier:1; /*!< Call qualifier delivery */
350 
351  char callwait_num[AST_MAX_EXTENSION];
352  char callwait_name[AST_MAX_EXTENSION];
353  char lastcid_num[AST_MAX_EXTENSION];
354  char lastcid_name[AST_MAX_EXTENSION];
355  struct ast_party_caller caller;
356  int redirecting_reason; /*!< Redirecting reason */
357 
358  int cidrings; /*!< Which ring to deliver CID on */
359  char echorest[20];
360  int polarity;
361  struct timeval polaritydelaytv;
362  char dialdest[256];
363  time_t guardtime; /*!< Must wait this much time before using for new call */
364  struct timeval flashtime; /*!< Last flash-hook time */
365  int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
366  char finaldial[64];
367  char *origcid_num; /*!< malloced original callerid */
368  char *origcid_name; /*!< malloced original callerid */
369  char call_forward[AST_MAX_EXTENSION];
370 
371  /* Ast channel to pass to __ss_analog_thread */
372  struct ast_channel *ss_astchan;
373 
374  /* All variables after this are definitely going to be audited */
375  int ringt;
376  int ringt_base;
377 };
378 
379 struct analog_pvt *analog_new(enum analog_sigtype signallingtype, void *private_data);
380 void analog_delete(struct analog_pvt *doomed);
381 
382 void analog_free(struct analog_pvt *p);
383 
384 int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout);
385 
386 int analog_hangup(struct analog_pvt *p, struct ast_channel *ast);
387 
388 int analog_answer(struct analog_pvt *p, struct ast_channel *ast);
389 
390 struct ast_frame *analog_exception(struct analog_pvt *p, struct ast_channel *ast);
391 
392 struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor);
393 
394 int analog_available(struct analog_pvt *p);
395 
396 void *analog_handle_init_event(struct analog_pvt *i, int event);
397 
398 int analog_config_complete(struct analog_pvt *p);
399 
400 void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub index, struct ast_frame **dest);
401 
402 enum analog_cid_start analog_str_to_cidstart(const char *value);
403 
404 const char *analog_cidstart_to_str(enum analog_cid_start cid_start);
405 
406 enum analog_sigtype analog_str_to_sigtype(const char *name);
407 
408 const char *analog_sigtype_to_str(enum analog_sigtype sigtype);
409 
410 unsigned int analog_str_to_cidtype(const char *name);
411 
412 const char *analog_cidtype_to_str(unsigned int cid_type);
413 
414 int analog_ss_thread_start(struct analog_pvt *p, struct ast_channel *ast);
415 
416 int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp);
417 
418 int analog_dnd(struct analog_pvt *p, int flag);
419 
420 #endif /* _SIG_ANSLOG_H */
enum analog_dialmode dialmode
Definition: sig_analog.h:321
int(*const on_hook)(void *pvt)
Set channel on hook.
Definition: sig_analog.h:165
unsigned int use_callerid
Definition: sig_analog.h:307
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:315
void(*const answer_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch=yes.
Definition: sig_analog.h:174
void(*const start_polarityswitch)(void *pvt)
Reset FXS line polarity to IDLE, based on answeronpolarityswitch and hanguponpolarityswitch.
Definition: sig_analog.h:172
#define MAX_MUSICCLASS
Definition: channel.h:173
void(*const hangup_polarityswitch)(void *pvt)
Switch FXS line polarity, based on answeronpolarityswitch and hanguponpolarityswitch.
Definition: sig_analog.h:176
unsigned int cshactive
Definition: sig_analog.h:334
int cid_signalling
Definition: sig_analog.h:323
time_t guardtime
Definition: sig_analog.h:363
Definition: astman.c:222
unsigned int dialing
Definition: sig_analog.h:336
unsigned int transfertobusy
Definition: sig_analog.h:306
struct timeval flashtime
Definition: sig_analog.h:364
unsigned int use_smdi
TRUE if SMDI (Simplified Message Desk Interface) is enabled.
Definition: sig_analog.h:313
void(*const set_polarity)(void *pvt, int value)
Set FXS line polarity to 0=IDLE NZ=REVERSED.
Definition: sig_analog.h:170
struct ast_channel * owner
Definition: sig_analog.h:277
General Asterisk PBX channel definitions.
#define AST_MAX_EXTENSION
Definition: channel.h:134
Caller Party information.
Definition: channel.h:418
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:701
static int ringt_base
Configured ring timeout base.
Definition: chan_dahdi.c:811
unsigned int immediatering
Definition: sig_analog.h:299
void(*const swap_subs)(void *pvt, enum analog_sub a, struct ast_channel *new_a_owner, enum analog_sub b, struct ast_channel *new_b_owner)
Definition: sig_analog.h:206
analog_sub
Definition: sig_analog.h:108
unsigned int callwaiting
Definition: sig_analog.h:333
int(*const off_hook)(void *pvt)
Set channel off hook.
Definition: sig_analog.h:167
char * origcid_num
Definition: sig_analog.h:367
int whichwink
Definition: sig_analog.h:365
unsigned int dahditrcallerid
Definition: sig_analog.h:296
int redirecting_reason
Definition: sig_analog.h:356
int msgstate
-1 = unknown, 0 = no messages, 1 = new messages available
Definition: sig_analog.h:284
SMDI support for Asterisk.
char * origcid_name
Definition: sig_analog.h:368
unsigned int permhidecallerid
Definition: sig_analog.h:301
unsigned int dnd
Definition: sig_analog.h:337
int cidrings
Definition: sig_analog.h:358
static int has_voicemail(const char *mailbox, const char *folder)
Determines if the given folder has messages.
unsigned int callwaitingcallerid
Definition: sig_analog.h:309
unsigned int call_qualifier
Definition: sig_analog.h:349
Data structure associated with a single frame of data.
unsigned int threewaysilenthold
Definition: sig_analog.h:304
unsigned int callwaitcas
TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
Definition: sig_analog.h:348
struct ast_frame f
Definition: sig_analog.h:265
struct analog_subchannel subs[3]
Definition: sig_analog.h:279
unsigned int calledsubscriberheld
Definition: sig_analog.h:292
unsigned int permcallwaiting
Definition: sig_analog.h:300
void analog_delete(struct analog_pvt *doomed)
Delete the analog private structure.
Definition: sig_analog.c:4104
struct analog_callback analog_callbacks
Definition: chan_dahdi.c:3616