sig_analog.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. /*! \file
  21. *
  22. * \brief Interface header for analog signaling module
  23. *
  24. * \author Matthew Fredrickson <creslin@digium.com>
  25. */
  26. #include "asterisk/channel.h"
  27. #include "asterisk/frame.h"
  28. #include "asterisk/smdi.h"
  29. #define ANALOG_SMDI_MD_WAIT_TIMEOUT 1500 /* 1.5 seconds */
  30. #define ANALOG_MAX_CID 300
  31. #define READ_SIZE 160
  32. #define RING_PATTERNS 3
  33. /* Signalling types supported */
  34. enum analog_sigtype {
  35. ANALOG_SIG_NONE = -1,
  36. ANALOG_SIG_FXOLS = 1,
  37. ANALOG_SIG_FXOKS,
  38. ANALOG_SIG_FXOGS,
  39. ANALOG_SIG_FXSLS,
  40. ANALOG_SIG_FXSKS,
  41. ANALOG_SIG_FXSGS,
  42. ANALOG_SIG_EMWINK,
  43. ANALOG_SIG_EM,
  44. ANALOG_SIG_EM_E1,
  45. ANALOG_SIG_FEATD,
  46. ANALOG_SIG_FEATDMF,
  47. ANALOG_SIG_E911,
  48. ANALOG_SIG_FGC_CAMA,
  49. ANALOG_SIG_FGC_CAMAMF,
  50. ANALOG_SIG_FEATB,
  51. ANALOG_SIG_SFWINK,
  52. ANALOG_SIG_SF,
  53. ANALOG_SIG_SF_FEATD,
  54. ANALOG_SIG_SF_FEATDMF,
  55. ANALOG_SIG_FEATDMF_TA,
  56. ANALOG_SIG_SF_FEATB,
  57. };
  58. enum analog_tone {
  59. ANALOG_TONE_RINGTONE = 0,
  60. ANALOG_TONE_STUTTER,
  61. ANALOG_TONE_CONGESTION,
  62. ANALOG_TONE_DIALTONE,
  63. ANALOG_TONE_DIALRECALL,
  64. ANALOG_TONE_INFO,
  65. };
  66. enum analog_event {
  67. ANALOG_EVENT_NONE = 0,
  68. ANALOG_EVENT_ONHOOK,
  69. ANALOG_EVENT_RINGOFFHOOK,
  70. ANALOG_EVENT_WINKFLASH,
  71. ANALOG_EVENT_ALARM,
  72. ANALOG_EVENT_NOALARM,
  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,
  81. ANALOG_EVENT_REMOVED,
  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),
  93. };
  94. enum analog_sub {
  95. ANALOG_SUB_REAL = 0, /*!< Active call */
  96. ANALOG_SUB_CALLWAIT, /*!< Call-Waiting call on hold */
  97. ANALOG_SUB_THREEWAY, /*!< Three-way call */
  98. };
  99. enum analog_dsp_digitmode {
  100. ANALOG_DIGITMODE_DTMF = 1,
  101. ANALOG_DIGITMODE_MF,
  102. };
  103. enum analog_cid_start {
  104. ANALOG_CID_START_POLARITY = 1,
  105. ANALOG_CID_START_POLARITY_IN,
  106. ANALOG_CID_START_RING,
  107. ANALOG_CID_START_DTMF_NOALERT,
  108. };
  109. enum dialop {
  110. ANALOG_DIAL_OP_REPLACE = 2,
  111. };
  112. struct analog_dialoperation {
  113. enum dialop op;
  114. char dialstr[256];
  115. };
  116. struct analog_callback {
  117. /* Unlock the private in the signalling private structure. This is used for three way calling madness. */
  118. void (* const unlock_private)(void *pvt);
  119. /* Lock the private in the signalling private structure. ... */
  120. void (* const lock_private)(void *pvt);
  121. /* Do deadlock avoidance for the private signaling structure lock. */
  122. void (* const deadlock_avoidance_private)(void *pvt);
  123. /* Function which is called back to handle any other DTMF events that are received. Called by analog_handle_event. Why is this
  124. * important to use, instead of just directly using events received before they are passed into the library? Because sometimes,
  125. * (CWCID) the library absorbs DTMF events received. */
  126. void (* const handle_dtmf)(void *pvt, struct ast_channel *ast, enum analog_sub analog_index, struct ast_frame **dest);
  127. int (* const get_event)(void *pvt);
  128. int (* const wait_event)(void *pvt);
  129. int (* const is_off_hook)(void *pvt);
  130. int (* const is_dialing)(void *pvt, enum analog_sub sub);
  131. /* Start a trunk type signalling protocol (everything except phone ports basically */
  132. int (* const start)(void *pvt);
  133. int (* const ring)(void *pvt);
  134. int (* const flash)(void *pvt);
  135. /*! \brief Set channel on hook */
  136. int (* const on_hook)(void *pvt);
  137. /*! \brief Set channel off hook */
  138. int (* const off_hook)(void *pvt);
  139. void (* const set_needringing)(void *pvt, int value);
  140. /*! \brief Set FXS line polarity to 0=IDLE NZ=REVERSED */
  141. void (* const set_polarity)(void *pvt, int value);
  142. /*! \brief Reset FXS line polarity to IDLE, based on answeronpolarityswitch and hanguponpolarityswitch */
  143. void (* const start_polarityswitch)(void *pvt);
  144. /*! \brief Switch FXS line polarity, based on answeronpolarityswitch=yes */
  145. void (* const answer_polarityswitch)(void *pvt);
  146. /*! \brief Switch FXS line polarity, based on answeronpolarityswitch and hanguponpolarityswitch */
  147. void (* const hangup_polarityswitch)(void *pvt);
  148. /* 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. * function */
  150. int (* const wink)(void *pvt, enum analog_sub sub);
  151. int (* const dial_digits)(void *pvt, enum analog_sub sub, struct analog_dialoperation *dop);
  152. int (* const send_fsk)(void *pvt, struct ast_channel *ast, char *fsk);
  153. 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_party_caller *caller);
  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);
  165. /* Play the CAS callwait tone on the REAL sub, then repeat after 10 seconds, and then stop */
  166. int (* const callwait)(void *pvt);
  167. /* Stop playing any CAS call waiting announcement tones that might be running on the REAL sub */
  168. int (* const stop_callwait)(void *pvt);
  169. /* Bearer control related (non signalling) callbacks */
  170. int (* const allocate_sub)(void *pvt, enum analog_sub sub);
  171. int (* const unallocate_sub)(void *pvt, enum analog_sub sub);
  172. /*! This function is for swapping of the owners with the underlying subs. Typically it means you need to change the fds
  173. * of the new owner to be the fds of the sub specified, for each of the two subs given */
  174. 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);
  175. struct ast_channel * (* const new_ast_channel)(void *pvt, int state, int startpbx, enum analog_sub sub, const struct ast_channel *requestor);
  176. /* Add the given sub to a conference */
  177. int (* const conf_add)(void *pvt, enum analog_sub sub);
  178. /* Delete the given sub from any conference that might be running on the channels */
  179. int (* const conf_del)(void *pvt, enum analog_sub sub);
  180. /* If you would like to do any optimizations after the conference members have been added and removed,
  181. * you can do so here */
  182. int (* const complete_conference_update)(void *pvt, int needconf);
  183. /* This is called when there are no more subchannels on the given private that are left up,
  184. * for any cleanup or whatever else you would like to do. Called from analog_hangup() */
  185. void (* const all_subchannels_hungup)(void *pvt);
  186. int (* const has_voicemail)(void *pvt);
  187. int (* const check_for_conference)(void *pvt);
  188. void (* const handle_notify_message)(struct ast_channel *chan, void *pvt, int cid_flags, int neon_mwievent);
  189. /* callbacks for increasing and decreasing ss_thread_count, will handle locking and condition signal */
  190. void (* const increase_ss_count)(void);
  191. void (* const decrease_ss_count)(void);
  192. int (* const distinctive_ring)(struct ast_channel *chan, void *pvt, int idx, int *ringdata);
  193. /* Sets the specified sub-channel in and out of signed linear mode, returns the value that was overwritten */
  194. int (* const set_linear_mode)(void *pvt, enum analog_sub sub, int linear_mode);
  195. void (* const set_inthreeway)(void *pvt, enum analog_sub sub, int inthreeway);
  196. void (* const get_and_handle_alarms)(void *pvt);
  197. void * (* const get_sigpvt_bridged_channel)(struct ast_channel *chan);
  198. int (* const get_sub_fd)(void *pvt, enum analog_sub sub);
  199. void (* const set_cadence)(void *pvt, int *cidrings, struct ast_channel *chan);
  200. void (* const set_alarm)(void *pvt, int in_alarm);
  201. void (* const set_dialing)(void *pvt, int is_dialing);
  202. void (* const set_outgoing)(void *pvt, int is_outgoing);
  203. void (* const set_ringtimeout)(void *pvt, int ringt);
  204. void (* const set_waitingfordt)(void *pvt, struct ast_channel *ast);
  205. int (* const check_waitingfordt)(void *pvt);
  206. void (* const set_confirmanswer)(void *pvt, int flag);
  207. int (* const check_confirmanswer)(void *pvt);
  208. void (* const set_callwaiting)(void *pvt, int callwaiting_enable);
  209. void (* const cancel_cidspill)(void *pvt);
  210. int (* const confmute)(void *pvt, int mute);
  211. void (* const set_pulsedial)(void *pvt, int flag);
  212. void (* const set_new_owner)(void *pvt, struct ast_channel *new_owner);
  213. const char *(* const get_orig_dialstring)(void *pvt);
  214. int (* const have_progressdetect)(void *pvt);
  215. };
  216. /*! Global analog callbacks to the upper layer. */
  217. extern struct analog_callback analog_callbacks;
  218. struct analog_subchannel {
  219. struct ast_channel *owner;
  220. struct ast_frame f; /*!< One frame for each channel. How did this ever work before? */
  221. unsigned int inthreeway:1;
  222. /* Have we allocated a subchannel yet or not */
  223. unsigned int allocd:1;
  224. };
  225. struct analog_pvt {
  226. /* Analog signalling type used in this private */
  227. enum analog_sigtype sig;
  228. /* To contain the private structure passed into the channel callbacks */
  229. void *chan_pvt;
  230. /* All members after this are giong to be transient, and most will probably change */
  231. struct ast_channel *owner; /*!< Our current active owner (if applicable) */
  232. struct analog_subchannel subs[3]; /*!< Sub-channels */
  233. struct analog_dialoperation dop;
  234. int onhooktime; /*< Time the interface went on-hook. */
  235. int fxsoffhookstate; /*< TRUE if the FXS port is off-hook */
  236. /*! \brief -1 = unknown, 0 = no messages, 1 = new messages available */
  237. int msgstate;
  238. /* XXX: Option Variables - Set by allocator of private structure */
  239. unsigned int answeronpolarityswitch:1;
  240. unsigned int callreturn:1;
  241. unsigned int cancallforward:1;
  242. unsigned int canpark:1;
  243. unsigned int dahditrcallerid:1; /*!< should we use the callerid from incoming call on dahdi transfer or not */
  244. unsigned int hanguponpolarityswitch:1;
  245. unsigned int immediate:1;
  246. unsigned int permcallwaiting:1; /*!< TRUE if call waiting is enabled. (Configured option) */
  247. unsigned int permhidecallerid:1; /*!< Whether to hide our outgoing caller ID or not */
  248. unsigned int pulse:1;
  249. unsigned int threewaycalling:1;
  250. unsigned int transfer:1;
  251. unsigned int transfertobusy:1; /*!< allow flash-transfers to busy channels */
  252. unsigned int use_callerid:1; /*!< Whether or not to use caller id on this channel */
  253. unsigned int usedistinctiveringdetection:1;
  254. unsigned int callwaitingcallerid:1; /*!< TRUE if send caller ID for Call Waiting */
  255. /*!
  256. * \brief TRUE if SMDI (Simplified Message Desk Interface) is enabled
  257. */
  258. unsigned int use_smdi:1;
  259. /*! \brief The SMDI interface to get SMDI messages from. */
  260. struct ast_smdi_interface *smdi_iface;
  261. /* Not used for anything but log messages. Could be just the TCID */
  262. int channel; /*!< Channel Number */
  263. enum analog_sigtype outsigmod;
  264. int echotraining;
  265. int cid_signalling; /*!< Asterisk callerid type we're using */
  266. int polarityonanswerdelay;
  267. int stripmsd;
  268. enum analog_cid_start cid_start;
  269. char mohsuggest[MAX_MUSICCLASS];
  270. char cid_num[AST_MAX_EXTENSION];
  271. char cid_name[AST_MAX_EXTENSION];
  272. /* XXX: All variables after this are internal */
  273. unsigned int callwaiting:1; /*!< TRUE if call waiting is enabled. (Active option) */
  274. unsigned int dialednone:1;
  275. unsigned int dialing:1; /*!< TRUE if in the process of dialing digits or sending something */
  276. unsigned int dnd:1; /*!< TRUE if Do-Not-Disturb is enabled. */
  277. unsigned int echobreak:1;
  278. unsigned int hidecallerid:1;
  279. unsigned int outgoing:1;
  280. unsigned int inalarm:1;
  281. /*!
  282. * \brief TRUE if Call Waiting (CW) CPE Alert Signal (CAS) is being sent.
  283. * \note
  284. * After CAS is sent, the call waiting caller id will be sent if the phone
  285. * gives a positive reply.
  286. */
  287. unsigned int callwaitcas:1;
  288. char callwait_num[AST_MAX_EXTENSION];
  289. char callwait_name[AST_MAX_EXTENSION];
  290. char lastcid_num[AST_MAX_EXTENSION];
  291. char lastcid_name[AST_MAX_EXTENSION];
  292. struct ast_party_caller caller;
  293. int cidrings; /*!< Which ring to deliver CID on */
  294. char echorest[20];
  295. int polarity;
  296. struct timeval polaritydelaytv;
  297. char dialdest[256];
  298. time_t guardtime; /*!< Must wait this much time before using for new call */
  299. struct timeval flashtime; /*!< Last flash-hook time */
  300. int whichwink; /*!< SIG_FEATDMF_TA Which wink are we on? */
  301. char finaldial[64];
  302. char *origcid_num; /*!< malloced original callerid */
  303. char *origcid_name; /*!< malloced original callerid */
  304. char call_forward[AST_MAX_EXTENSION];
  305. /* Ast channel to pass to __ss_analog_thread */
  306. struct ast_channel *ss_astchan;
  307. /* All variables after this are definitely going to be audited */
  308. int ringt;
  309. int ringt_base;
  310. };
  311. struct analog_pvt *analog_new(enum analog_sigtype signallingtype, void *private_data);
  312. void analog_delete(struct analog_pvt *doomed);
  313. void analog_free(struct analog_pvt *p);
  314. int analog_call(struct analog_pvt *p, struct ast_channel *ast, const char *rdest, int timeout);
  315. int analog_hangup(struct analog_pvt *p, struct ast_channel *ast);
  316. int analog_answer(struct analog_pvt *p, struct ast_channel *ast);
  317. struct ast_frame *analog_exception(struct analog_pvt *p, struct ast_channel *ast);
  318. struct ast_channel * analog_request(struct analog_pvt *p, int *callwait, const struct ast_channel *requestor);
  319. int analog_available(struct analog_pvt *p);
  320. void *analog_handle_init_event(struct analog_pvt *i, int event);
  321. int analog_config_complete(struct analog_pvt *p);
  322. void analog_handle_dtmf(struct analog_pvt *p, struct ast_channel *ast, enum analog_sub index, struct ast_frame **dest);
  323. enum analog_cid_start analog_str_to_cidstart(const char *value);
  324. const char *analog_cidstart_to_str(enum analog_cid_start cid_start);
  325. enum analog_sigtype analog_str_to_sigtype(const char *name);
  326. const char *analog_sigtype_to_str(enum analog_sigtype sigtype);
  327. unsigned int analog_str_to_cidtype(const char *name);
  328. const char *analog_cidtype_to_str(unsigned int cid_type);
  329. int analog_ss_thread_start(struct analog_pvt *p, struct ast_channel *ast);
  330. int analog_fixup(struct ast_channel *oldchan, struct ast_channel *newchan, void *newp);
  331. int analog_dnd(struct analog_pvt *p, int flag);
  332. #endif /* _SIG_ANSLOG_H */