Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:47:56 2009

## Asterisk developer's documentation

# vmodem.h

Go to the documentation of this file.

    00001 /*
    00002  * Asterisk -- An open source telephony toolkit.
    00003  *
    00004  * Copyright (C) 1999 - 2005, Digium, Inc.
    00005  *
    00006  * Mark Spencer <markster@digium.com>
    00007  *
    00008  * See http://www.asterisk.org for more information about
    00009  * the Asterisk project. Please do not directly contact
    00010  * any of the maintainers of this project for assistance;
    00011  * the project provides a web site, mailing lists and IRC
    00012  * channels for your use.
    00013  *
    00014  * This program is free software, distributed under the terms of
    00015  * the GNU General Public License Version 2. See the LICENSE file
    00016  * at the top of the source tree.
    00017  */
    00018
    00019 /*! \file
    00020  * \brief Voice Modem Definitions
    00021  */
    00022
    00023 #ifndef _ASTERISK_VMODEM_H
    00024 #define _ASTERISK_VMODEM_H
    00025
    00026 #include "asterisk/frame.h"
    00027 #include "asterisk/channel.h"
    00028
    00029 #define CHAR_DLE     0x10
    00030 #define CHAR_ETX     0x03
    00031 #define CHAR_DC4     0x14
    00032
    00033 #define MODEM_DEV_TELCO    0
    00034 #define MODEM_DEV_TELCO_SPK   4
    00035 #define MODEM_DEV_SPKRPHONE   6
    00036 #define MODEM_DEV_HANDSET  9
    00037
    00038 #define MODEM_DTMF_NONE    (1 << 0)
    00039 #define MODEM_DTMF_AST     (1 << 1)
    00040 #define MODEM_DTMF_I4L     (1 << 2)
    00041
    00042 /* Thirty millisecond sections */
    00043 #define MODEM_MAX_LEN      30
    00044 #define MODEM_MAX_BUF      MODEM_MAX_LEN * 16
    00045
    00046 #define AST_MAX_INIT_STR   256
    00047
    00048 struct ast_modem_pvt;
    00049
    00050 struct ast_modem_driver {
    00051    char *name;
    00052    char **idents;
    00053    int formats;
    00054    int fullduplex;
    00055    void (*incusecnt)(void);
    00056    void (*decusecnt)(void);
    00057    char * (*identify)(struct ast_modem_pvt *);
    00058    int (*init)(struct ast_modem_pvt *);
    00059    int (*setdev)(struct ast_modem_pvt *, int dev);
    00060    struct ast_frame * (*read)(struct ast_modem_pvt *);
    00061    int (*write)(struct ast_modem_pvt *, struct ast_frame *fr);
    00062    int (*dial)(struct ast_modem_pvt *, char *);
    00063    int (*answer)(struct ast_modem_pvt *);
    00064    int (*hangup)(struct ast_modem_pvt *);
    00065    int (*startrec)(struct ast_modem_pvt *);
    00066    int (*stoprec)(struct ast_modem_pvt *);
    00067    int (*startpb)(struct ast_modem_pvt *);
    00068    int (*stoppb)(struct ast_modem_pvt *);
    00069    int (*setsilence)(struct ast_modem_pvt *, int onoff);
    00070    int (*dialdigit)(struct ast_modem_pvt *, char digit);
    00071    struct ast_modem_driver *next;
    00072 };
    00073
    00074 #define MODEM_MODE_IMMEDIATE     0
    00075 #define MODEM_MODE_WAIT_RING     1
    00076 #define MODEM_MODE_WAIT_ANSWER      2
    00077
    00078 /*! Private data that needs to be filled by modem driver */
    00079 struct ast_modem_pvt {
    00080    /*! Raw file descriptor for this device */
    00081    int fd;
    00082    /*! FILE * representation of device */
    00083    FILE *f;
    00084    /*! Channel we belong to, possibly NULL */
    00085    struct ast_channel *owner;
    00086    /* Device name */
    00087    char dev[256];
    00088    /*! Frame */
    00089    struct ast_frame fr;
    00090
    00091    char offset[AST_FRIENDLY_OFFSET];
    00092    /*! Outgoing buffer */
    00093    char obuf[MODEM_MAX_BUF];
    00094
    00095    int tail;
    00096    /*! Pulse or tone dialling */
    00097    char dialtype;
    00098    /*! Time to wait for dial timeout */
    00099    char dialtimeout;
    00100
    00101    int obuflen;
    00102    /*! Immediate, or wait for an answer */
    00103    int mode;
    00104    /*! State of modem in miniature */
    00105    int ministate;
    00106    /*! Digits to strip on outgoing numbers */
    00107    int stripmsd;
    00108    /*! Is the last thing we saw an escape */
    00109    int escape;
    00110    /*! flag to say if has caller*id yet*/
    00111    int gotclid;
    00112    /* Has a fax tone already been handled? */
    00113    int faxhandled;
    00114    /*! ringer timeout */
    00115    int ringt;
    00116    /*! actual time of last ring */
    00117    time_t lastring;
    00118    /*! dtmf receive state/data */
    00119    char dtmfrx;
    00120
    00121    char context[AST_MAX_EXTENSION];
    00122    /*! Multiple Subscriber Number */
    00123    char msn[AST_MAX_EXTENSION];
    00124    /*! Multiple Subscriber Number we listen to (; separated list) */
    00125    char incomingmsn[AST_MAX_EXTENSION];
    00126    /*! Multiple Subscriber Number we accept for outgoing calls (; separated list) */
    00127    char outgoingmsn[AST_MAX_EXTENSION];
    00128    /*! Group(s) we belong to if available */
    00129    ast_group_t group;
    00130    /*! Caller ID if available */
    00131    char cid_name[AST_MAX_EXTENSION];
    00132    /*! Caller ID if available */
    00133    char cid_num[AST_MAX_EXTENSION];
    00134    /*! DTMF-detection mode (i4l/asterisk) */
    00135    int dtmfmode;
    00136    /*! DTMF-generation mode (i4l (outband) / asterisk (inband) */
    00137    int dtmfmodegen;
    00138    /*! DSP for DTMF detection */
    00139    struct ast_dsp *dsp;
    00140    /*! Dialed Number if available */
    00141    char dnid[AST_MAX_EXTENSION];
    00142    /*! Modem initialization String */
    00143    char initstr[AST_MAX_INIT_STR];
    00144    /*! default language */
    00145    char language[MAX_LANGUAGE];
    00146    /*! Static response buffer */
    00147    char response[256];
    00148    /*! Modem Capability */
    00149    struct ast_modem_driver *mc;
    00150    /*! Next channel in list */
    00151    struct ast_modem_pvt *next;
    00152 };
    00153
    00154
    00155 /*! Register a modem driver */
    00156 /*! Register a driver */
    00157 extern int ast_register_modem_driver(struct ast_modem_driver *mc);
    00158
    00159 /*! Unregisters a modem driver */
    00160 /*! Unregister a driver */
    00161 extern int ast_unregister_modem_driver(struct ast_modem_driver *mc);
    00162
    00163 /*! Sends command */
    00164 /*! Send the command cmd (length len, or 0 if pure ascii) on modem */
    00165 extern int ast_modem_send(struct ast_modem_pvt *p, char *cmd, int len);
    00166
    00167 /*! Waits for result */
    00168 /*! Wait for result to occur.  Return non-zero if times out or error, last
    00169    response is stored in p->response  */
    00170 extern int ast_modem_expect(struct ast_modem_pvt *p,  char *result, int timeout);
    00171
    00172 /*! Waits for result */
    00173 /*! Wait for result to occur.    response is stored in p->response  */
    00174 extern int ast_modem_read_response(struct ast_modem_pvt *p,  int timeout);
    00175
    00176 /*! Used to start up the PBX on a RING */
    00177 /*! Used by modem drivers to start up the PBX on a RING */
    00178 extern struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state);
    00179
    00180 /*! Trim string of trailing stuff */
    00181 /*! Trim off trailing mess */
    00182 extern void ast_modem_trim(char *s);
    00183
    00184 #endif /* _ASTERISK_VMODEM_H */