00001 #ifndef _SIG_ANALOG_H
00002 #define _SIG_ANALOG_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk/channel.h"
00029 #include "asterisk/frame.h"
00030
00031 #define ANALOG_MAX_CID 300
00032 #define READ_SIZE 160
00033 #define RING_PATTERNS 3
00034
00035
00036 enum analog_sigtype {
00037 ANALOG_SIG_NONE = -1,
00038 ANALOG_SIG_FXOLS = 1,
00039 ANALOG_SIG_FXOKS,
00040 ANALOG_SIG_FXOGS,
00041 ANALOG_SIG_FXSLS,
00042 ANALOG_SIG_FXSKS,
00043 ANALOG_SIG_FXSGS,
00044 ANALOG_SIG_EMWINK,
00045 ANALOG_SIG_EM,
00046 ANALOG_SIG_EM_E1,
00047 ANALOG_SIG_FEATD,
00048 ANALOG_SIG_FEATDMF,
00049 ANALOG_SIG_E911,
00050 ANALOG_SIG_FGC_CAMA,
00051 ANALOG_SIG_FGC_CAMAMF,
00052 ANALOG_SIG_FEATB,
00053 ANALOG_SIG_SFWINK,
00054 ANALOG_SIG_SF,
00055 ANALOG_SIG_SF_FEATD,
00056 ANALOG_SIG_SF_FEATDMF,
00057 ANALOG_SIG_FEATDMF_TA,
00058 ANALOG_SIG_SF_FEATB,
00059 };
00060
00061 enum analog_tone {
00062 ANALOG_TONE_RINGTONE = 0,
00063 ANALOG_TONE_STUTTER,
00064 ANALOG_TONE_CONGESTION,
00065 ANALOG_TONE_DIALTONE,
00066 ANALOG_TONE_DIALRECALL,
00067 ANALOG_TONE_INFO,
00068 };
00069
00070 enum analog_event {
00071 ANALOG_EVENT_NONE = 0,
00072 ANALOG_EVENT_ONHOOK,
00073 ANALOG_EVENT_RINGOFFHOOK,
00074 ANALOG_EVENT_WINKFLASH,
00075 ANALOG_EVENT_ALARM,
00076 ANALOG_EVENT_NOALARM,
00077 ANALOG_EVENT_DIALCOMPLETE,
00078 ANALOG_EVENT_RINGERON,
00079 ANALOG_EVENT_RINGEROFF,
00080 ANALOG_EVENT_HOOKCOMPLETE,
00081 ANALOG_EVENT_PULSE_START,
00082 ANALOG_EVENT_POLARITY,
00083 ANALOG_EVENT_RINGBEGIN,
00084 ANALOG_EVENT_EC_DISABLED,
00085 ANALOG_EVENT_REMOVED,
00086 ANALOG_EVENT_NEONMWI_ACTIVE,
00087 ANALOG_EVENT_NEONMWI_INACTIVE,
00088 ANALOG_EVENT_TX_CED_DETECTED,
00089 ANALOG_EVENT_RX_CED_DETECTED,
00090 ANALOG_EVENT_EC_NLP_DISABLED,
00091 ANALOG_EVENT_EC_NLP_ENABLED,
00092 ANALOG_EVENT_ERROR,
00093 ANALOG_EVENT_DTMFCID,
00094 ANALOG_EVENT_PULSEDIGIT = (1 << 16),
00095 ANALOG_EVENT_DTMFDOWN = (1 << 17),
00096 ANALOG_EVENT_DTMFUP = (1 << 18),
00097 };
00098
00099 enum analog_sub {
00100 ANALOG_SUB_REAL = 0,
00101 ANALOG_SUB_CALLWAIT,
00102 ANALOG_SUB_THREEWAY,
00103 };
00104
00105 enum analog_dsp_digitmode {
00106 ANALOG_DIGITMODE_DTMF = 1,
00107 ANALOG_DIGITMODE_MF,
00108 };
00109
00110 enum analog_cid_start {
00111 ANALOG_CID_START_POLARITY = 1,
00112 ANALOG_CID_START_POLARITY_IN,
00113 ANALOG_CID_START_RING,
00114 ANALOG_CID_START_DTMF_NOALERT,
00115 };
00116
00117 enum dialop {
00118 ANALOG_DIAL_OP_REPLACE = 2,
00119 };
00120
00121
00122 struct analog_dialoperation {
00123 enum dialop op;
00124 char dialstr[256];
00125 };
00126
00127 struct analog_callback {
00128
00129 void (* const unlock_private)(void *pvt);
00130
00131 void (* const lock_private)(void *pvt);
00132
00133 void (* const deadlock_avoidance_private)(void *pvt);
00134
00135
00136
00137
00138 void (* const handle_dtmfup)(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest);
00139
00140 int (* const get_event)(void *pvt);
00141 int (* const wait_event)(void *pvt);
00142 int (* const is_off_hook)(void *pvt);
00143 int (* const is_dialing)(void *pvt, enum analog_sub sub);
00144
00145 int (* const start)(void *pvt);
00146 int (* const ring)(void *pvt);
00147 int (* const flash)(void *pvt);
00148
00149 int (* const on_hook)(void *pvt);
00150
00151 int (* const off_hook)(void *pvt);
00152 void (* const set_needringing)(void *pvt, int value);
00153
00154 void (* const set_polarity)(void *pvt, int value);
00155
00156 void (* const start_polarityswitch)(void *pvt);
00157
00158 void (* const answer_polarityswitch)(void *pvt);
00159
00160 void (* const hangup_polarityswitch)(void *pvt);
00161
00162
00163 int (* const wink)(void *pvt, enum analog_sub sub);
00164 int (* const dial_digits)(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop);
00165 int (* const send_fsk)(void *pvt, struct ast_channel *ast, char *fsk);
00166 int (* const play_tone)(void *pvt, enum analog_sub sub, enum analog_tone tone);
00167
00168 int (* const set_echocanceller)(void *pvt, int enable);
00169 int (* const train_echocanceller)(void *pvt);
00170 int (* const dsp_set_digitmode)(void *pvt, enum analog_dsp_digitmode mode);
00171 int (* const dsp_reset_and_flush_digits)(void *pvt);
00172 int (* const send_callerid)(void *pvt, int cwcid, struct ast_party_caller *caller);
00173
00174 int (* const get_callerid)(void *pvt, char *name, char *num, enum analog_event *ev, size_t timeout);
00175
00176 int (* const start_cid_detect)(void *pvt, int cid_signalling);
00177
00178 int (* const stop_cid_detect)(void *pvt);
00179
00180
00181 int (* const callwait)(void *pvt);
00182
00183 int (* const stop_callwait)(void *pvt);
00184
00185
00186 int (* const allocate_sub)(void *pvt, enum analog_sub sub);
00187 int (* const unallocate_sub)(void *pvt, enum analog_sub sub);
00188
00189
00190 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);
00191 struct ast_channel * (* const new_ast_channel)(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor);
00192
00193
00194 int (* const conf_add)(void *pvt, enum analog_sub sub);
00195
00196 int (* const conf_del)(void *pvt, enum analog_sub sub);
00197
00198
00199
00200 int (* const complete_conference_update)(void *pvt, int needconf);
00201
00202
00203
00204 void (* const all_subchannels_hungup)(void *pvt);
00205
00206 int (* const has_voicemail)(void *pvt);
00207 int (* const check_for_conference)(void *pvt);
00208 void (* const handle_notify_message)(struct ast_channel *chan, void *pvt, int cid_flags, int neon_mwievent);
00209
00210
00211 void (* const increase_ss_count)(void);
00212 void (* const decrease_ss_count)(void);
00213
00214 int (* const distinctive_ring)(struct ast_channel *chan, void *pvt, int idx, int *ringdata);
00215
00216 int (* const set_linear_mode)(void *pvt, int idx, int linear_mode);
00217 void (* const get_and_handle_alarms)(void *pvt);
00218 void * (* const get_sigpvt_bridged_channel)(struct ast_channel *chan);
00219 int (* const get_sub_fd)(void *pvt, enum analog_sub sub);
00220 void (* const set_cadence)(void *pvt, int *cidrings, struct ast_channel *chan);
00221 void (* const set_alarm)(void *pvt, int in_alarm);
00222 void (* const set_dialing)(void *pvt, int is_dialing);
00223 void (* const set_ringtimeout)(void *pvt, int ringt);
00224 void (* const set_waitingfordt)(void *pvt, struct ast_channel *ast);
00225 int (* const check_waitingfordt)(void *pvt);
00226 void (* const set_confirmanswer)(void *pvt, int flag);
00227 int (* const check_confirmanswer)(void *pvt);
00228 void (* const cancel_cidspill)(void *pvt);
00229 int (* const confmute)(void *pvt, int mute);
00230 void (* const set_pulsedial)(void *pvt, int flag);
00231
00232 const char *(* const get_orig_dialstring)(void *pvt);
00233 };
00234
00235
00236
00237 struct analog_subchannel {
00238 struct ast_channel *owner;
00239 struct ast_frame f;
00240 unsigned int inthreeway:1;
00241
00242 unsigned int allocd:1;
00243 };
00244
00245 struct analog_pvt {
00246
00247 enum analog_sigtype sig;
00248
00249 void *chan_pvt;
00250
00251 struct analog_callback *calls;
00252
00253 struct ast_channel *owner;
00254
00255 struct analog_subchannel subs[3];
00256 struct analog_dialoperation dop;
00257 int onhooktime;
00258 int fxsoffhookstate;
00259
00260 int msgstate;
00261
00262
00263 unsigned int answeronpolarityswitch:1;
00264 unsigned int callreturn:1;
00265 unsigned int cancallforward:1;
00266 unsigned int canpark:1;
00267 unsigned int dahditrcallerid:1;
00268 unsigned int hanguponpolarityswitch:1;
00269 unsigned int immediate:1;
00270 unsigned int permcallwaiting:1;
00271 unsigned int permhidecallerid:1;
00272 unsigned int pulse:1;
00273 unsigned int threewaycalling:1;
00274 unsigned int transfer:1;
00275 unsigned int transfertobusy:1;
00276 unsigned int use_callerid:1;
00277 unsigned int callwaitingcallerid:1;
00278 const struct ast_channel_tech *chan_tech;
00279
00280
00281
00282
00283
00284 unsigned int usedistinctiveringdetection:1;
00285
00286
00287 int channel;
00288 enum analog_sigtype outsigmod;
00289 int echotraining;
00290 int cid_signalling;
00291 int polarityonanswerdelay;
00292 int stripmsd;
00293 enum analog_cid_start cid_start;
00294 char mohsuggest[MAX_MUSICCLASS];
00295 char cid_num[AST_MAX_EXTENSION];
00296 char cid_name[AST_MAX_EXTENSION];
00297
00298
00299
00300 unsigned int callwaiting:1;
00301 unsigned int dialednone:1;
00302 unsigned int dialing:1;
00303 unsigned int dnd:1;
00304 unsigned int echobreak:1;
00305 unsigned int hidecallerid:1;
00306 unsigned int outgoing:1;
00307
00308 char callwait_num[AST_MAX_EXTENSION];
00309 char callwait_name[AST_MAX_EXTENSION];
00310 char lastcid_num[AST_MAX_EXTENSION];
00311 char lastcid_name[AST_MAX_EXTENSION];
00312 struct ast_party_caller caller;
00313 int cidrings;
00314 char echorest[20];
00315 int polarity;
00316 struct timeval polaritydelaytv;
00317 char dialdest[256];
00318 time_t guardtime;
00319 struct timeval flashtime;
00320 int whichwink;
00321 char finaldial[64];
00322 char *origcid_num;
00323 char *origcid_name;
00324 char call_forward[AST_MAX_EXTENSION];
00325
00326
00327 struct ast_channel *ss_astchan;
00328
00329
00330 unsigned int inalarm:1;
00331 unsigned int unknown_alarm:1;
00332
00333 int callwaitcas;
00334
00335 int ringt;
00336 int ringt_base;
00337 };
00338
00339 struct analog_pvt *analog_new(enum analog_sigtype signallingtype, struct analog_callback *c, void *private_data);
00340 void analog_delete(struct analog_pvt *doomed);
00341
00342 void analog_free(struct analog_pvt *p);
00343
00344 int analog_call(struct analog_pvt *p, struct ast_channel *ast, char *rdest, int timeout);
00345
00346 int analog_hangup(struct analog_pvt *p, struct ast_channel *ast);
00347
00348 int analog_answer(struct analog_pvt *p, struct ast_channel *ast);
00349
00350 struct ast_frame *analog_exception(struct analog_pvt *p, struct ast_channel *ast);
00351
00352 struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor);
00353
00354 int analog_available(struct analog_pvt *p);
00355
00356 void *analog_handle_init_event(struct analog_pvt *i, int event);
00357
00358 int analog_config_complete(struct analog_pvt *p);
00359
00360 void analog_handle_dtmfup(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub index, struct ast_frame **dest);
00361
00362 enum analog_cid_start analog_str_to_cidstart(const char *value);
00363
00364 const char *analog_cidstart_to_str(enum analog_cid_start cid_start);
00365
00366 enum analog_sigtype analog_str_to_sigtype(const char *name);
00367
00368 const char *analog_sigtype_to_str(enum analog_sigtype sigtype);
00369
00370 unsigned int analog_str_to_cidtype(const char *name);
00371
00372 const char *analog_cidtype_to_str(unsigned int cid_type);
00373
00374 int analog_ss_thread_start(struct analog_pvt *p, struct ast_channel *ast);
00375
00376 int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp);
00377
00378 int analog_dnd(struct analog_pvt *p, int flag);
00379
00380 #endif