Debian Codegraph @

channels/sig_analog.h

raw symbols SCIP
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 */
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
108 enum analog_sub {
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
138 struct analog_dialoperation {
139 enum dialop op;
140 char dialstr[256];
141 };
142
143 struct analog_callback {
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
263 struct analog_subchannel {
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 lastnumredial:1; /*!< TRUE if last number redial allowed */
301 unsigned int permcallwaiting:1; /*!< TRUE if call waiting is enabled. (Configured option) */
302 unsigned int callwaitingdeluxe:1; /*!< TRUE if Call Waiting Deluxe options are available */
303 unsigned int permhidecallerid:1; /*!< Whether to hide our outgoing caller ID or not */
304 enum analog_dialmode permdialmode; /*!< Which of pulse and/or tone dialing to support */
305 unsigned int pulse:1;
306 unsigned int threewaycalling:1;
307 unsigned int threewaysilenthold:1; /*!< Whether to time out a three-way dial tone to silence */
308 unsigned int transfer:1;
309 unsigned int transfertobusy:1; /*!< allow flash-transfers to busy channels */
310 unsigned int use_callerid:1; /*!< Whether or not to use caller id on this channel */
311 unsigned int usedistinctiveringdetection:1;
312 unsigned int callwaitingcallerid:1; /*!< TRUE if send caller ID for Call Waiting */
313 /*!
314 * \brief TRUE if SMDI (Simplified Message Desk Interface) is enabled
315 */
316 unsigned int use_smdi:1;
317 /*! \brief The SMDI interface to get SMDI messages from. */
318 struct ast_smdi_interface *smdi_iface;
319
320 /* Not used for anything but log messages. Could be just the TCID */
321 int channel; /*!< Channel Number */
322
323 enum analog_sigtype outsigmod;
324 enum analog_dialmode dialmode; /*!< Which of pulse and/or tone dialing to support */
325 int echotraining;
326 int cid_signalling; /*!< Asterisk callerid type we're using */
327 int polarityonanswerdelay;
328 int stripmsd;
329 enum analog_cid_start cid_start;
330 char mohsuggest[MAX_MUSICCLASS];
331 char cid_num[AST_MAX_EXTENSION];
332 char cid_name[AST_MAX_EXTENSION];
333
334
335 /* XXX: All variables after this are internal */
336 unsigned int callwaiting:1; /*!< TRUE if call waiting is enabled. (Active option) */
337 unsigned int cshactive:1; /*!< TRUE if FXS channel is currently held by an incoming call */
338 unsigned int dialednone:1;
339 unsigned int dialing:1; /*!< TRUE if in the process of dialing digits or sending something */
340 unsigned int dnd:1; /*!< TRUE if Do-Not-Disturb is enabled. */
341 unsigned int echobreak:1;
342 unsigned int hidecallerid:1;
343 unsigned int outgoing:1;
344 unsigned int inalarm:1;
345 /*!
346 * \brief TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
347 * \note
348 * After CAS is sent, the call waiting caller id will be sent if the phone
349 * gives a positive reply.
350 */
351 unsigned int callwaitcas:1;
352
353 /*!
354 * \brief TRUE if a Call Waiting Deluxe action is currently pending.
355 */
356 unsigned int callwaitingdeluxepending:1;
357
358 unsigned int call_qualifier:1; /*!< Call qualifier delivery */
359
360 char callwait_num[AST_MAX_EXTENSION];
361 char callwait_name[AST_MAX_EXTENSION];
362 char lastcid_num[AST_MAX_EXTENSION];
363 char lastcid_name[AST_MAX_EXTENSION];
364 char lastexten[AST_MAX_EXTENSION]; /*!< Last number dialed */
365 struct ast_party_caller caller;
366 int redirecting_reason; /*!< Redirecting reason */
367
368 int cidrings; /*!< Which ring to deliver CID on */
369 char echorest[20];
370 int polarity;
371 struct timeval polaritydelaytv;
372 char dialdest[256];
373 time_t guardtime; /*!< Must wait this much time before using for new call */
374 struct timeval flashtime; /*!< Last flash-hook time */
375 int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
376 char finaldial[64];
377 char *origcid_num; /*!< malloced original callerid */
378 char *origcid_name; /*!< malloced original callerid */
379 char call_forward[AST_MAX_EXTENSION];
380
381 /* Ast channel to pass to __ss_analog_thread */
382 struct ast_channel *ss_astchan;
383
384 /* All variables after this are definitely going to be audited */
385 int ringt;
386 int ringt_base;
387 };
388
389 struct analog_pvt *analog_new(enum analog_sigtype signallingtype, void *private_data);
390 void analog_delete(struct analog_pvt *doomed);
391
392 void analog_free(struct analog_pvt *p);
393
394 int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout);
395
396 int analog_hangup(struct analog_pvt *p, struct ast_channel *ast);
397
398 int analog_answer(struct analog_pvt *p, struct ast_channel *ast);
399
400 struct ast_frame *analog_exception(struct analog_pvt *p, struct ast_channel *ast);
401
402 struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor);
403
404 int analog_available(struct analog_pvt *p);
405
406 void *analog_handle_init_event(struct analog_pvt *i, int event);
407
408 int analog_config_complete(struct analog_pvt *p);
409
410 int analog_callwaiting_deluxe(struct analog_pvt *p, int option);
411
412 void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub index, struct ast_frame **dest);
413
414 enum analog_cid_start analog_str_to_cidstart(const char *value);
415
416 const char *analog_cidstart_to_str(enum analog_cid_start cid_start);
417
418 enum analog_sigtype analog_str_to_sigtype(const char *name);
419
420 const char *analog_sigtype_to_str(enum analog_sigtype sigtype);
421
422 unsigned int analog_str_to_cidtype(const char *name);
423
424 const char *analog_cidtype_to_str(unsigned int cid_type);
425
426 int analog_ss_thread_start(struct analog_pvt *p, struct ast_channel *ast);
427
428 int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp);
429
430 int analog_dnd(struct analog_pvt *p, int flag);
431
432 #endif /* _SIG_ANSLOG_H */