Sat Apr 26 2014 22:01:40

Asterisk developer's documentation


res_fax.h
Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2008-2009, Digium, Inc.
00005  *
00006  * Dwayne M. Hubbard <dhubbard@digium.com>
00007  * Kevin P. Fleming <kpfleming@digium.com>
00008  *
00009  * See http://www.asterisk.org for more information about
00010  * the Asterisk project. Please do not directly contact
00011  * any of the maintainers of this project for assistance;
00012  * the project provides a web site, mailing lists and IRC
00013  * channels for your use.
00014  *
00015  * This program is free software, distributed under the terms of
00016  * the GNU General Public License Version 2. See the LICENSE file
00017  * at the top of the source tree.
00018  */
00019 
00020 #ifndef _ASTERISK_RES_FAX_H
00021 #define _ASTERISK_RES_FAX_H
00022 
00023 #include <asterisk.h>
00024 #include <asterisk/lock.h>
00025 #include <asterisk/linkedlists.h>
00026 #include <asterisk/module.h>
00027 #include <asterisk/utils.h>
00028 #include <asterisk/options.h>
00029 #include <asterisk/frame.h>
00030 #include <asterisk/cli.h>
00031 #include <asterisk/stringfields.h>
00032 
00033 /*! \brief capabilities for res_fax to locate a fax technology module */
00034 enum ast_fax_capabilities {
00035    /*! SendFax is supported */
00036    AST_FAX_TECH_SEND      = (1 << 0),
00037    /*! ReceiveFax is supported */
00038    AST_FAX_TECH_RECEIVE   = (1 << 1),
00039    /*! Audio FAX session supported */
00040    AST_FAX_TECH_AUDIO     = (1 << 2),
00041    /*! T.38 FAX session supported */
00042    AST_FAX_TECH_T38       = (1 << 3),
00043    /*! sending mulitple documents supported */
00044    AST_FAX_TECH_MULTI_DOC = (1 << 4),
00045    /*! T.38 - T.30 Gateway */
00046    AST_FAX_TECH_GATEWAY = (1 << 5),
00047    /*! V21 detection is supported */
00048    AST_FAX_TECH_V21_DETECT = (1 << 6),
00049 };
00050 
00051 /*! \brief fax modem capabilities */
00052 enum ast_fax_modems {
00053    /*! V.17 */
00054    AST_FAX_MODEM_V17 = (1 << 0),
00055    /*! V.27 */
00056    AST_FAX_MODEM_V27 = (1 << 1),
00057    /*! V.29 */
00058    AST_FAX_MODEM_V29 = (1 << 2),
00059    /*! V.34 */
00060    AST_FAX_MODEM_V34 = (1 << 3),
00061 };
00062 
00063 /*! \brief current state of a fax session */
00064 enum ast_fax_state {
00065    /*! uninitialized state */
00066    AST_FAX_STATE_UNINITIALIZED = 0,
00067    /*! initialized state */
00068    AST_FAX_STATE_INITIALIZED,
00069    /*! fax resources open state */
00070    AST_FAX_STATE_OPEN,
00071    /*! fax session in progress */
00072    AST_FAX_STATE_ACTIVE,
00073    /*! fax session complete */
00074    AST_FAX_STATE_COMPLETE,
00075    /*! reserved state */
00076    AST_FAX_STATE_RESERVED,
00077    /*! inactive state */
00078    AST_FAX_STATE_INACTIVE,
00079 };
00080 
00081 /*! \brief fax session options */
00082 enum ast_fax_optflag {
00083    /*! false/disable configuration override */
00084    AST_FAX_OPTFLAG_FALSE = 0,
00085    /*! true/enable configuration override */
00086    AST_FAX_OPTFLAG_TRUE,
00087    /*! use the configured default */
00088    AST_FAX_OPTFLAG_DEFAULT,
00089 };
00090 
00091 struct ast_fax_t38_parameters {
00092    unsigned int version;               /*!< Supported T.38 version */
00093    unsigned int max_ifp;               /*!< Maximum IFP size supported */
00094    enum ast_control_t38_rate rate;           /*!< Maximum fax rate supported */
00095    enum ast_control_t38_rate_management rate_management; /*!< Rate management setting */
00096    unsigned int fill_bit_removal:1;       /*!< Set if fill bit removal can be used */
00097    unsigned int transcoding_mmr:1;           /*!< Set if MMR transcoding can be used */
00098    unsigned int transcoding_jbig:1;       /*!< Set if JBIG transcoding can be used */
00099 };
00100 
00101 struct ast_fax_document {
00102    AST_LIST_ENTRY(ast_fax_document) next;
00103    char filename[0];
00104 };
00105 
00106 AST_LIST_HEAD_NOLOCK(ast_fax_documents, ast_fax_document);
00107 
00108 /*! \brief The data communicated between the high level applications and the generic fax function */
00109 struct ast_fax_session_details {
00110    /*! fax session capability requirements.  The caps field is used to select
00111     * the proper fax technology module before the session starts */
00112    enum ast_fax_capabilities caps;
00113    /*! modem requirement for the session */
00114    enum ast_fax_modems modems;
00115    /*! session id */
00116    unsigned int id;
00117    /*! document(s) to be sent/received */
00118    struct ast_fax_documents documents;
00119    AST_DECLARE_STRING_FIELDS(
00120       /*! resolution negotiated during the fax session.  This is stored in the
00121        * FAXRESOLUTION channel variable when the fax session completes */
00122       AST_STRING_FIELD(resolution);
00123       /*! transfer rate negotiated during the fax session.  This is stored in the
00124        * FAXBITRATE channel variable when the fax session completes */
00125       AST_STRING_FIELD(transfer_rate);
00126       /*! local station identification.  This is set from the LOCALSTATIONID
00127        * channel variable before the fax session starts */
00128       AST_STRING_FIELD(localstationid);
00129       /*! remote station identification.  This is stored in the REMOTESTATIONID
00130        * channel variable after the fax session completes */
00131       AST_STRING_FIELD(remotestationid);
00132       /*! headerinfo variable is set from the LOCALHEADERINFO channel variable
00133        * before the fax session starts */
00134       AST_STRING_FIELD(headerinfo);
00135       /*! the result of the fax session */
00136       AST_STRING_FIELD(result);
00137       /*! a more descriptive result string of the fax session */
00138       AST_STRING_FIELD(resultstr);
00139       /*! the error reason of the fax session */
00140       AST_STRING_FIELD(error);
00141    );
00142    /*! the number of pages sent/received during a fax session */
00143    unsigned int pages_transferred;
00144    /*! session details flags for options */
00145    union {
00146       /*! dontuse dummy variable - do not ever use */ 
00147       uint32_t dontuse;
00148       struct {
00149          /*! flag to send debug manager events */
00150          uint32_t debug:2;
00151          /*! flag indicating the use of Error Correction Mode (ECM) */
00152          uint32_t ecm:1;
00153          /*! flag indicating the sending of status manager events */
00154          uint32_t statusevents:2;
00155          /*! allow audio mode FAX on T.38-capable channels */
00156          uint32_t allow_audio:2;
00157          /*! indicating the session switched to T38 */
00158          uint32_t switch_to_t38:1;
00159          /*! flag indicating whether CED should be sent (for receive mode) */
00160          uint32_t send_ced:1;
00161          /*! flag indicating whether CNG should be sent (for send mode) */
00162          uint32_t send_cng:1;
00163          /*! send a T.38 reinvite */
00164          uint32_t request_t38:1;
00165          /*! a V.21 preamble was detected */
00166          uint32_t v21_detected:1;
00167       };
00168    } option;
00169    /*! override the minimum transmission rate with a channel variable */
00170    unsigned int minrate;
00171    /*! override the maximum transmission rate with a channel varialbe */
00172    unsigned int maxrate;
00173    /*! our T.38 session parameters, if any */
00174    struct ast_fax_t38_parameters our_t38_parameters;
00175    /*! the other endpoint's T.38 session parameters, if any */
00176    struct ast_fax_t38_parameters their_t38_parameters;
00177    /*! the id of the t.38 gateway framehook for this channel */
00178    int gateway_id;
00179    /*! the timeout for this gateway in seconds */
00180    int gateway_timeout;
00181    /*! the id of the faxdetect framehook for this channel */
00182    int faxdetect_id;
00183 };
00184 
00185 struct ast_fax_tech;
00186 struct ast_fax_debug_info;
00187 struct ast_fax_tech_token;
00188 
00189 /*! \brief The data required to handle a fax session */
00190 struct ast_fax_session {
00191    /*! session id */
00192    unsigned int id;
00193    /*! session file descriptor */
00194    int fd;
00195    /*! fax session details structure */
00196    struct ast_fax_session_details *details;
00197    /*! fax frames received */
00198    unsigned long frames_received;
00199    /*! fax frames sent */
00200    unsigned long frames_sent;
00201    /*! the fax technology callbacks */
00202    const struct ast_fax_tech *tech;
00203    /*! private implementation pointer */
00204    void *tech_pvt;
00205    /*! fax state */
00206    enum ast_fax_state state;
00207    /*! name of the Asterisk channel using the fax session */
00208    char *channame;
00209    /*! unique ID of the Asterisk channel using the fax session */
00210    char *chan_uniqueid;
00211    /*! Asterisk channel using the fax session */
00212    struct ast_channel *chan;
00213    /*! fax debugging structure */
00214    struct ast_fax_debug_info *debug_info;
00215    /*! used to take variable-sized frames in and output frames of an expected size to the fax stack */
00216    struct ast_smoother *smoother;
00217 };
00218 
00219 /* if this overlaps with any AST_FRFLAG_* values, problems will occur */
00220 #define AST_FAX_FRFLAG_GATEWAY (1 << 13)
00221 
00222 /*! \brief used to register a FAX technology module with res_fax */
00223 struct ast_fax_tech {
00224    /*! the type of fax session supported with this ast_fax_tech structure */
00225    const char * const type;
00226    /*! a short description of the fax technology */
00227    const char * const description;
00228    /*! version string of the technology module */
00229    const char * const version;
00230    /*! the ast_fax_capabilities supported by the fax technology */
00231    const enum ast_fax_capabilities caps;
00232    /*! module information for the fax technology */
00233    struct ast_module *module;
00234    /*! reserves a session for future use; returns a token */
00235    struct ast_fax_tech_token *(* const reserve_session)(struct ast_fax_session *);
00236    /*! releases an unused session token */
00237    void (* const release_token)(struct ast_fax_tech_token *);
00238    /*! creates a new fax session, optionally using a previously-reserved token */
00239    void *(* const new_session)(struct ast_fax_session *, struct ast_fax_tech_token *);
00240    /*! destroys an existing fax session */
00241    void (* const destroy_session)(struct ast_fax_session *);
00242    /*! sends an Asterisk frame to res_fax */
00243    struct ast_frame *(* const read)(struct ast_fax_session *);
00244    /*! writes an Asterisk frame to the fax session */
00245    int (* const write)(struct ast_fax_session *, const struct ast_frame *);
00246    /*! starts the fax session */
00247    int (* const start_session)(struct ast_fax_session *);
00248    /*! cancels a fax session */
00249    int (* const cancel_session)(struct ast_fax_session *);
00250    /*! initiates the generation of silence to the fax session */
00251    int (* const generate_silence)(struct ast_fax_session *);
00252    /*! switches an existing dual-mode session from audio to T.38 */
00253    int (* const switch_to_t38)(struct ast_fax_session *);
00254    /*! displays capabilities of the fax technology */
00255    char * (* const cli_show_capabilities)(int);
00256    /*! displays details about the fax session */
00257    char * (* const cli_show_session)(struct ast_fax_session *, int);
00258    /*! displays statistics from the fax technology module */
00259    char * (* const cli_show_stats)(int);
00260    /*! displays settings from the fax technology module */
00261    char * (* const cli_show_settings)(int);
00262 };
00263 
00264 /*! \brief register a fax technology */
00265 int ast_fax_tech_register(struct ast_fax_tech *tech);
00266 
00267 /*! \brief unregister a fax technology */
00268 void ast_fax_tech_unregister(struct ast_fax_tech *tech);
00269 
00270 /*! \brief get the minimum supported fax rate */
00271 unsigned int ast_fax_minrate(void);
00272 
00273 /*! \brief get the maxiumum supported fax rate */
00274 unsigned int ast_fax_maxrate(void);
00275 
00276 /*! \brief convert an ast_fax_state to a string */
00277 const char *ast_fax_state_to_str(enum ast_fax_state state);
00278 
00279 /*!
00280  * \brief Log message at FAX or recommended level
00281  *
00282  * The first four parameters can be represented with Asterisk's
00283  * LOG_* levels. In other words, this function may be called
00284  * like
00285  *
00286  * ast_fax_log(LOG_DEBUG, msg);
00287  */
00288 void ast_fax_log(int level, const char *file, const int line, const char *function, const char *msg);
00289 
00290 #endif