res_fax.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2008-2009, Digium, Inc.
  5. *
  6. * Dwayne M. Hubbard <dhubbard@digium.com>
  7. * Kevin P. Fleming <kpfleming@digium.com>
  8. *
  9. * See http://www.asterisk.org for more information about
  10. * the Asterisk project. Please do not directly contact
  11. * any of the maintainers of this project for assistance;
  12. * the project provides a web site, mailing lists and IRC
  13. * channels for your use.
  14. *
  15. * This program is free software, distributed under the terms of
  16. * the GNU General Public License Version 2. See the LICENSE file
  17. * at the top of the source tree.
  18. */
  19. #ifndef _ASTERISK_RES_FAX_H
  20. #define _ASTERISK_RES_FAX_H
  21. #include "asterisk.h"
  22. #include "asterisk/lock.h"
  23. #include "asterisk/linkedlists.h"
  24. #include "asterisk/module.h"
  25. #include "asterisk/utils.h"
  26. #include "asterisk/options.h"
  27. #include "asterisk/frame.h"
  28. #include "asterisk/cli.h"
  29. #include "asterisk/stringfields.h"
  30. #include "asterisk/manager.h"
  31. /*! \brief capabilities for res_fax to locate a fax technology module */
  32. enum ast_fax_capabilities {
  33. /*! SendFax is supported */
  34. AST_FAX_TECH_SEND = (1 << 0),
  35. /*! ReceiveFax is supported */
  36. AST_FAX_TECH_RECEIVE = (1 << 1),
  37. /*! Audio FAX session supported */
  38. AST_FAX_TECH_AUDIO = (1 << 2),
  39. /*! T.38 FAX session supported */
  40. AST_FAX_TECH_T38 = (1 << 3),
  41. /*! sending mulitple documents supported */
  42. AST_FAX_TECH_MULTI_DOC = (1 << 4),
  43. /*! T.38 - T.30 Gateway */
  44. AST_FAX_TECH_GATEWAY = (1 << 5),
  45. /*! V21 detection is supported */
  46. AST_FAX_TECH_V21_DETECT = (1 << 6),
  47. };
  48. /*! \brief fax modem capabilities */
  49. enum ast_fax_modems {
  50. /*! V.17 */
  51. AST_FAX_MODEM_V17 = (1 << 0),
  52. /*! V.27ter */
  53. AST_FAX_MODEM_V27TER = (1 << 1),
  54. /*! V.29 */
  55. AST_FAX_MODEM_V29 = (1 << 2),
  56. /*! V.34 */
  57. AST_FAX_MODEM_V34 = (1 << 3),
  58. };
  59. /*! \brief current state of a fax session */
  60. enum ast_fax_state {
  61. /*! uninitialized state */
  62. AST_FAX_STATE_UNINITIALIZED = 0,
  63. /*! initialized state */
  64. AST_FAX_STATE_INITIALIZED,
  65. /*! fax resources open state */
  66. AST_FAX_STATE_OPEN,
  67. /*! fax session in progress */
  68. AST_FAX_STATE_ACTIVE,
  69. /*! fax session complete */
  70. AST_FAX_STATE_COMPLETE,
  71. /*! reserved state */
  72. AST_FAX_STATE_RESERVED,
  73. /*! inactive state */
  74. AST_FAX_STATE_INACTIVE,
  75. };
  76. /*! \brief fax session options */
  77. enum ast_fax_optflag {
  78. /*! false/disable configuration override */
  79. AST_FAX_OPTFLAG_FALSE = 0,
  80. /*! true/enable configuration override */
  81. AST_FAX_OPTFLAG_TRUE,
  82. /*! use the configured default */
  83. AST_FAX_OPTFLAG_DEFAULT,
  84. };
  85. struct ast_fax_t38_parameters {
  86. unsigned int version; /*!< Supported T.38 version */
  87. unsigned int max_ifp; /*!< Maximum IFP size supported */
  88. enum ast_control_t38_rate rate; /*!< Maximum fax rate supported */
  89. enum ast_control_t38_rate_management rate_management; /*!< Rate management setting */
  90. unsigned int fill_bit_removal:1; /*!< Set if fill bit removal can be used */
  91. unsigned int transcoding_mmr:1; /*!< Set if MMR transcoding can be used */
  92. unsigned int transcoding_jbig:1; /*!< Set if JBIG transcoding can be used */
  93. };
  94. struct ast_fax_document {
  95. AST_LIST_ENTRY(ast_fax_document) next;
  96. char filename[0];
  97. };
  98. AST_LIST_HEAD_NOLOCK(ast_fax_documents, ast_fax_document);
  99. /*! \brief The data communicated between the high level applications and the generic fax function */
  100. struct ast_fax_session_details {
  101. /*! fax session capability requirements. The caps field is used to select
  102. * the proper fax technology module before the session starts */
  103. enum ast_fax_capabilities caps;
  104. /*! modem requirement for the session */
  105. enum ast_fax_modems modems;
  106. /*! session id */
  107. unsigned int id;
  108. /*! document(s) to be sent/received */
  109. struct ast_fax_documents documents;
  110. AST_DECLARE_STRING_FIELDS(
  111. /*! resolution negotiated during the fax session. This is stored in the
  112. * FAXRESOLUTION channel variable when the fax session completes */
  113. AST_STRING_FIELD(resolution);
  114. /*! transfer rate negotiated during the fax session. This is stored in the
  115. * FAXBITRATE channel variable when the fax session completes */
  116. AST_STRING_FIELD(transfer_rate);
  117. /*! local station identification. This is set from the LOCALSTATIONID
  118. * channel variable before the fax session starts */
  119. AST_STRING_FIELD(localstationid);
  120. /*! remote station identification. This is stored in the REMOTESTATIONID
  121. * channel variable after the fax session completes */
  122. AST_STRING_FIELD(remotestationid);
  123. /*! headerinfo variable is set from the LOCALHEADERINFO channel variable
  124. * before the fax session starts */
  125. AST_STRING_FIELD(headerinfo);
  126. /*! the result of the fax session */
  127. AST_STRING_FIELD(result);
  128. /*! a more descriptive result string of the fax session */
  129. AST_STRING_FIELD(resultstr);
  130. /*! the error reason of the fax session */
  131. AST_STRING_FIELD(error);
  132. );
  133. /*! the number of pages sent/received during a fax session */
  134. unsigned int pages_transferred;
  135. /*! session details flags for options */
  136. union {
  137. /*! dontuse dummy variable - do not ever use */
  138. uint32_t dontuse;
  139. struct {
  140. /*! flag to send debug manager events */
  141. uint32_t debug:2;
  142. /*! flag indicating the use of Error Correction Mode (ECM) */
  143. uint32_t ecm:1;
  144. /*! flag indicating the sending of status manager events */
  145. uint32_t statusevents:2;
  146. /*! allow audio mode FAX on T.38-capable channels */
  147. uint32_t allow_audio:2;
  148. /*! indicating the session switched to T38 */
  149. uint32_t switch_to_t38:1;
  150. /*! flag indicating whether CED should be sent (for receive mode) */
  151. uint32_t send_ced:1;
  152. /*! flag indicating whether CNG should be sent (for send mode) */
  153. uint32_t send_cng:1;
  154. /*! send a T.38 reinvite */
  155. uint32_t request_t38:1;
  156. /*! a V.21 preamble was detected */
  157. uint32_t v21_detected:1;
  158. };
  159. } option;
  160. /*! override the minimum transmission rate with a channel variable */
  161. unsigned int minrate;
  162. /*! override the maximum transmission rate with a channel varialbe */
  163. unsigned int maxrate;
  164. /*! our T.38 session parameters, if any */
  165. struct ast_fax_t38_parameters our_t38_parameters;
  166. /*! the other endpoint's T.38 session parameters, if any */
  167. struct ast_fax_t38_parameters their_t38_parameters;
  168. /*! T.38 negotiation in ms */
  169. unsigned int t38timeout;
  170. /*! the id of the t.38 gateway framehook for this channel */
  171. int gateway_id;
  172. /*! The timeout for this gateway in ms */
  173. int gateway_timeout;
  174. /*! the id of the faxdetect framehook for this channel */
  175. int faxdetect_id;
  176. /*! The timeout for this fax detect in ms */
  177. int faxdetect_timeout;
  178. /*! flags used for fax detection */
  179. int faxdetect_flags;
  180. /*! Non-zero if T.38 is negotiated */
  181. int is_t38_negotiated;
  182. };
  183. struct ast_fax_tech;
  184. struct ast_fax_debug_info;
  185. struct ast_fax_tech_token;
  186. /*! \brief The data required to handle a fax session */
  187. struct ast_fax_session {
  188. /*! session id */
  189. unsigned int id;
  190. /*! session file descriptor */
  191. int fd;
  192. /*! fax session details structure */
  193. struct ast_fax_session_details *details;
  194. /*! fax frames received */
  195. unsigned long frames_received;
  196. /*! fax frames sent */
  197. unsigned long frames_sent;
  198. /*! the fax technology callbacks */
  199. const struct ast_fax_tech *tech;
  200. /*! private implementation pointer */
  201. void *tech_pvt;
  202. /*! fax state */
  203. enum ast_fax_state state;
  204. /*! name of the Asterisk channel using the fax session */
  205. char *channame;
  206. /*! unique ID of the Asterisk channel using the fax session */
  207. char *chan_uniqueid;
  208. /*! Asterisk channel using the fax session */
  209. struct ast_channel *chan;
  210. /*! fax debugging structure */
  211. struct ast_fax_debug_info *debug_info;
  212. /*! used to take variable-sized frames in and output frames of an expected size to the fax stack */
  213. struct ast_smoother *smoother;
  214. };
  215. /* if this overlaps with any AST_FRFLAG_* values, problems will occur */
  216. #define AST_FAX_FRFLAG_GATEWAY (1 << 13)
  217. /*! \brief used to register a FAX technology module with res_fax */
  218. struct ast_fax_tech {
  219. /*! the type of fax session supported with this ast_fax_tech structure */
  220. const char * const type;
  221. /*! a short description of the fax technology */
  222. const char * const description;
  223. /*! version string of the technology module */
  224. const char * const version;
  225. /*! the ast_fax_capabilities supported by the fax technology */
  226. const enum ast_fax_capabilities caps;
  227. /*! module information for the fax technology */
  228. struct ast_module *module;
  229. /*! reserves a session for future use; returns a token */
  230. struct ast_fax_tech_token *(* const reserve_session)(struct ast_fax_session *);
  231. /*! releases an unused session token */
  232. void (* const release_token)(struct ast_fax_tech_token *);
  233. /*! creates a new fax session, optionally using a previously-reserved token */
  234. void *(* const new_session)(struct ast_fax_session *, struct ast_fax_tech_token *);
  235. /*! destroys an existing fax session */
  236. void (* const destroy_session)(struct ast_fax_session *);
  237. /*! sends an Asterisk frame to res_fax */
  238. struct ast_frame *(* const read)(struct ast_fax_session *);
  239. /*! writes an Asterisk frame to the fax session */
  240. int (* const write)(struct ast_fax_session *, const struct ast_frame *);
  241. /*! starts the fax session */
  242. int (* const start_session)(struct ast_fax_session *);
  243. /*! cancels a fax session */
  244. int (* const cancel_session)(struct ast_fax_session *);
  245. /*! initiates the generation of silence to the fax session */
  246. int (* const generate_silence)(struct ast_fax_session *);
  247. /*! switches an existing dual-mode session from audio to T.38 */
  248. int (* const switch_to_t38)(struct ast_fax_session *);
  249. /*! displays capabilities of the fax technology */
  250. char * (* const cli_show_capabilities)(int);
  251. /*! displays details about the fax session */
  252. char * (* const cli_show_session)(struct ast_fax_session *, int);
  253. /*! Generates manager event detailing the fax session */
  254. void (* const manager_fax_session)(struct mansession *,
  255. const char *, struct ast_fax_session *);
  256. /*! displays statistics from the fax technology module */
  257. char * (* const cli_show_stats)(int);
  258. /*! displays settings from the fax technology module */
  259. char * (* const cli_show_settings)(int);
  260. };
  261. /*! \brief register a fax technology */
  262. int ast_fax_tech_register(struct ast_fax_tech *tech);
  263. /*! \brief unregister a fax technology */
  264. void ast_fax_tech_unregister(struct ast_fax_tech *tech);
  265. /*! \brief get the minimum supported fax rate */
  266. unsigned int ast_fax_minrate(void);
  267. /*! \brief get the maxiumum supported fax rate */
  268. unsigned int ast_fax_maxrate(void);
  269. /*! \brief convert an ast_fax_state to a string */
  270. const char *ast_fax_state_to_str(enum ast_fax_state state);
  271. /*! \brief get string representation of a FAX session's operation */
  272. const char *ast_fax_session_operation_str(struct ast_fax_session *s);
  273. /*!
  274. * \brief Log message at FAX or recommended level
  275. *
  276. * The first four parameters can be represented with Asterisk's
  277. * LOG_* levels. In other words, this function may be called
  278. * like
  279. *
  280. * ast_fax_log(LOG_DEBUG, msg);
  281. */
  282. void ast_fax_log(int level, const char *file, const int line, const char *function, const char *msg);
  283. #endif