4 * Asterisk -- An open source telephony toolkit.
6 * Copyright (C) 1999 - 2009, Digium, Inc.
8 * Mark Spencer <markster@digium.com>
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.
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.
23 * \brief Interface header for analog signaling module
25 * \author Matthew Fredrickson <creslin@digium.com>
28 #include "asterisk/channel.h"
29 #include "asterisk/frame.h"
31 /* Signalling types supported */
47 ANALOG_SIG_FGC_CAMAMF,
52 ANALOG_SIG_SF_FEATDMF,
53 ANALOG_SIG_FEATDMF_TA,
58 ANALOG_TONE_RINGTONE = 0,
60 ANALOG_TONE_CONGESTION,
62 ANALOG_TONE_DIALRECALL,
67 ANALOG_EVENT_NONE = 0,
69 ANALOG_EVENT_RINGOFFHOOK,
70 ANALOG_EVENT_WINKFLASH,
73 ANALOG_EVENT_DIALCOMPLETE,
74 ANALOG_EVENT_RINGERON,
75 ANALOG_EVENT_RINGEROFF,
76 ANALOG_EVENT_HOOKCOMPLETE,
77 ANALOG_EVENT_PULSE_START,
78 ANALOG_EVENT_POLARITY,
79 ANALOG_EVENT_RINGBEGIN,
80 ANALOG_EVENT_EC_DISABLED,
82 ANALOG_EVENT_NEONMWI_ACTIVE,
83 ANALOG_EVENT_NEONMWI_INACTIVE,
84 ANALOG_EVENT_TX_CED_DETECTED,
85 ANALOG_EVENT_RX_CED_DETECTED,
86 ANALOG_EVENT_EC_NLP_DISABLED,
87 ANALOG_EVENT_EC_NLP_ENABLED,
88 ANALOG_EVENT_ERROR, /* not a DAHDI event */
89 ANALOG_EVENT_DTMFCID, /* not a DAHDI event */
90 ANALOG_EVENT_PULSEDIGIT = (1 << 16),
91 ANALOG_EVENT_DTMFDOWN = (1 << 17),
92 ANALOG_EVENT_DTMFUP = (1 << 18),
96 ANALOG_SUB_REAL = 0, /*!< Active call */
97 ANALOG_SUB_CALLWAIT, /*!< Call-Waiting call on hold */
98 ANALOG_SUB_THREEWAY, /*!< Three-way call */
101 enum analog_dsp_digitmode {
102 ANALOG_DIGITMODE_DTMF = 1,
106 enum analog_cid_start {
107 ANALOG_CID_START_POLARITY = 1,
108 ANALOG_CID_START_POLARITY_IN,
109 ANALOG_CID_START_RING,
110 ANALOG_CID_START_DTMF_NOALERT,
113 #define ANALOG_MAX_CID 300
116 ANALOG_DIAL_OP_REPLACE = 2,
120 struct analog_dialoperation {
125 struct analog_callback {
126 /* Unlock the private in the signalling private structure. This is used for three way calling madness. */
127 void (* const unlock_private)(void *pvt);
128 /* Lock the private in the signalling private structure. ... */
129 void (* const lock_private)(void *pvt);
130 /* Function which is called back to handle any other DTMF up events that are received. Called by analog_handle_event. Why is this
131 * important to use, instead of just directly using events received before they are passed into the library? Because sometimes,
132 * (CWCID) the library absorbs DTMF events received. */
133 void (* const handle_dtmfup)(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest);
135 int (* const get_event)(void *pvt);
136 int (* const wait_event)(void *pvt);
137 int (* const is_off_hook)(void *pvt);
138 int (* const is_dialing)(void *pvt, enum analog_sub sub);
139 /* Start a trunk type signalling protocol (everything except phone ports basically */
140 int (* const start)(void *pvt);
141 int (* const ring)(void *pvt);
142 int (* const flash)(void *pvt);
143 /*! \brief Set channel on hook */
144 int (* const on_hook)(void *pvt);
145 /*! \brief Set channel off hook */
146 int (* const off_hook)(void *pvt);
147 /* 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
149 int (* const wink)(void *pvt, enum analog_sub sub);
150 int (* const dial_digits)(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop);
151 int (* const send_fsk)(void *pvt, struct ast_channel *ast, char *fsk);
152 int (* const play_tone)(void *pvt, enum analog_sub sub, enum analog_tone tone);
154 int (* const set_echocanceller)(void *pvt, int enable);
155 int (* const train_echocanceller)(void *pvt);
156 int (* const dsp_set_digitmode)(void *pvt, enum analog_dsp_digitmode mode);
157 int (* const dsp_reset_and_flush_digits)(void *pvt);
158 int (* const send_callerid)(void *pvt, int cwcid, struct ast_callerid *cid);
159 /* Returns 0 if CID received. Returns 1 if event received, and -1 if error. name and num are size ANALOG_MAX_CID */
160 int (* const get_callerid)(void *pvt, char *name, char *num, enum analog_event *ev, size_t timeout);
161 /* Start CID detection */
162 int (* const start_cid_detect)(void *pvt, int cid_signalling);
163 /* Stop CID detection */
164 int (* const stop_cid_detect)(void *pvt);
166 /* Play the CAS callwait tone on the REAL sub, then repeat after 10 seconds, and then stop */
167 int (* const callwait)(void *pvt);
168 /* Stop playing any CAS call waiting announcement tones that might be running on the REAL sub */
169 int (* const stop_callwait)(void *pvt);
171 /* Bearer control related (non signalling) callbacks */
172 int (* const allocate_sub)(void *pvt, enum analog_sub sub);
173 int (* const unallocate_sub)(void *pvt, enum analog_sub sub);
174 /*! This function is for swapping of the owners with the underlying subs. Typically it means you need to change the fds
175 * of the new owner to be the fds of the sub specified, for each of the two subs given */
176 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);
177 struct ast_channel * (* const new_ast_channel)(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor);
179 /* Add the given sub to a conference */
180 int (* const conf_add)(void *pvt, enum analog_sub sub);
181 /* Delete the given sub from any conference that might be running on the channels */
182 int (* const conf_del)(void *pvt, enum analog_sub sub);
184 /* If you would like to do any optimizations after the conference members have been added and removed,
185 * you can do so here */
186 int (* const complete_conference_update)(void *pvt, int needconf);
188 /* This is called when there are no more subchannels on the given private that are left up,
189 * for any cleanup or whatever else you would like to do. Called from analog_hangup() */
190 void (* const all_subchannels_hungup)(void *pvt);
192 int (* const has_voicemail)(void *pvt);
193 int (* const check_for_conference)(void *pvt);
194 void (* const handle_notify_message)(struct ast_channel *chan, void *pvt, int cid_flags, int neon_mwievent);
196 /* callbacks for increasing and decreasing ss_thread_count, will handle locking and condition signal */
197 void (* const increase_ss_count)(void);
198 void (* const decrease_ss_count)(void);
200 int (* const distinctive_ring)(struct ast_channel *chan, void *pvt, int idx, int *ringdata);
201 /* Sets the specified sub-channel in and out of signed linear mode, returns the value that was overwritten */
202 int (* const set_linear_mode)(void *pvt, int idx, int linear_mode);
203 void (* const get_and_handle_alarms)(void *pvt);
204 void * (* const get_sigpvt_bridged_channel)(struct ast_channel *chan);
205 int (* const get_sub_fd)(void *pvt, enum analog_sub sub);
206 void (* const set_cadence)(void *pvt, int *cidrings, struct ast_channel *chan);
207 void (* const set_dialing)(void *pvt, int flag);
208 void (* const set_ringtimeout)(void *pvt, int ringt);
209 void (* const set_waitingfordt)(void *pvt, struct ast_channel *ast);
210 int (* const check_waitingfordt)(void *pvt);
211 void (* const set_confirmanswer)(void *pvt, int flag);
212 int (* const check_confirmanswer)(void *pvt);
213 void (* const cancel_cidspill)(void *pvt);
214 int (* const confmute)(void *pvt, int mute);
215 void (* const set_pulsedial)(void *pvt, int flag);
220 #define READ_SIZE 160
222 struct analog_subchannel {
223 struct ast_channel *owner;
224 struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */
225 unsigned int inthreeway:1;
226 /* Have we allocated a subchannel yet or not */
227 unsigned int allocd:1;
231 /* Analog signalling type used in this private */
232 enum analog_sigtype sig;
233 /* To contain the private structure passed into the channel callbacks */
235 /* Callbacks for various functions needed by the analog API */
236 struct analog_callback *calls;
237 /* All members after this are giong to be transient, and most will probably change */
238 struct ast_channel *owner; /*!< Our current active owner (if applicable) */
240 struct analog_subchannel subs[3]; /*!< Sub-channels */
241 struct analog_dialoperation dop;
242 int onhooktime; /*< Time the interface went on-hook. */
243 int fxsoffhookstate; /*< TRUE if the FXS port is off-hook */
244 /*! \brief -1 = unknown, 0 = no messages, 1 = new messages available */
247 /* XXX: Option Variables - Set by allocator of private structure */
248 unsigned int answeronpolarityswitch:1;
249 unsigned int callreturn:1;
250 unsigned int cancallforward:1;
251 unsigned int canpark:1;
252 unsigned int dahditrcallerid:1; /*!< should we use the callerid from incoming call on dahdi transfer or not */
253 unsigned int hanguponpolarityswitch:1;
254 unsigned int immediate:1;
255 unsigned int permcallwaiting:1;
256 unsigned int permhidecallerid:1; /*!< Whether to hide our outgoing caller ID or not */
257 unsigned int pulse:1;
258 unsigned int threewaycalling:1;
259 unsigned int transfer:1;
260 unsigned int transfertobusy:1; /*!< allow flash-transfers to busy channels */
261 unsigned int use_callerid:1; /*!< Whether or not to use caller id on this channel */
262 const struct ast_channel_tech *chan_tech;
264 * \brief TRUE if distinctive rings are to be detected.
265 * \note For FXO lines
266 * \note Set indirectly from the "usedistinctiveringdetection" value read in from chan_dahdi.conf
268 unsigned int usedistinctiveringdetection:1;
270 /* Not used for anything but log messages. Could be just the TCID */
271 int channel; /*!< Channel Number */
272 enum analog_sigtype outsigmod;
274 int cid_signalling; /*!< Asterisk callerid type we're using */
275 int polarityonanswerdelay;
277 enum analog_cid_start cid_start;
278 int callwaitingcallerid;
279 char mohsuggest[MAX_MUSICCLASS];
280 char cid_num[AST_MAX_EXTENSION];
281 char cid_name[AST_MAX_EXTENSION];
284 /* XXX: All variables after this are internal */
285 unsigned int callwaiting:1;
286 unsigned int dialednone:1;
287 unsigned int dialing:1; /*!< TRUE if in the process of dialing digits or sending something */
288 unsigned int dnd:1; /*!< TRUE if Do-Not-Disturb is enabled. */
289 unsigned int echobreak:1;
290 unsigned int hidecallerid:1;
291 unsigned int outgoing:1;
293 char callwait_num[AST_MAX_EXTENSION];
294 char callwait_name[AST_MAX_EXTENSION];
295 char lastcid_num[AST_MAX_EXTENSION];
296 char lastcid_name[AST_MAX_EXTENSION];
297 struct ast_callerid cid;
298 int cidrings; /*!< Which ring to deliver CID on */
301 struct timeval polaritydelaytv;
303 time_t guardtime; /*!< Must wait this much time before using for new call */
304 struct timeval flashtime; /*!< Last flash-hook time */
305 int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
307 char *origcid_num; /*!< malloced original callerid */
308 char *origcid_name; /*!< malloced original callerid */
309 char call_forward[AST_MAX_EXTENSION];
311 /* Ast channel to pass to __ss_analog_thread */
312 struct ast_channel *ss_astchan;
314 /* All variables after this are definitely going to be audited */
315 unsigned int inalarm:1;
316 unsigned int unknown_alarm:1;
324 struct analog_pvt *analog_new(enum analog_sigtype signallingtype, struct analog_callback *c, void *private_data);
325 void analog_delete(struct analog_pvt *doomed);
327 void analog_free(struct analog_pvt *p);
329 int analog_call(struct analog_pvt *p, struct ast_channel *ast, char *rdest, int timeout);
331 int analog_hangup(struct analog_pvt *p, struct ast_channel *ast);
333 int analog_answer(struct analog_pvt *p, struct ast_channel *ast);
335 struct ast_frame *analog_exception(struct analog_pvt *p, struct ast_channel *ast);
337 struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor);
339 int analog_available(struct analog_pvt *p, int channelmatch, ast_group_t groupmatch, int *busy, int *channelmatched, int *groupmatched);
341 void *analog_handle_init_event(struct analog_pvt *i, int event);
343 int analog_config_complete(struct analog_pvt *p);
345 void analog_handle_dtmfup(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub index, struct ast_frame **dest);
347 enum analog_cid_start analog_str_to_cidstart(const char *value);
349 const char *analog_cidstart_to_str(enum analog_cid_start cid_start);
351 enum analog_sigtype analog_str_to_sigtype(const char *name);
353 const char *analog_sigtype_to_str(enum analog_sigtype sigtype);
355 unsigned int analog_str_to_cidtype(const char *name);
357 const char *analog_cidtype_to_str(unsigned int cid_type);
359 int analog_ss_thread_start(struct analog_pvt *p, struct ast_channel *ast);
361 int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp);
363 int analog_dnd(struct analog_pvt *p, int flag);
365 #endif /* _SIG_ANSLOG_H */