920bd417d056bbe006176576b3966bc852bcb601
[asterisk/asterisk.git] / include / asterisk / vmodem.h
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Voice Modem Definitions
5  * 
6  * Copyright (C) 1999, Mark Spencer
7  *
8  * Mark Spencer <markster@linux-support.net>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #ifndef _ASTERISK_VMODEM_H
15 #define _ASTERISK_VMODEM_H
16
17 #include <asterisk/frame.h>
18 #include <asterisk/channel.h>
19
20 #define CHAR_DLE                0x10
21 #define CHAR_ETX                0x03
22
23 #define MODEM_DEV_TELCO         0
24 #define MODEM_DEV_TELCO_SPK     4
25 #define MODEM_DEV_SPKRPHONE     6
26 #define MODEM_DEV_HANDSET       9
27
28 /* Thirty millisecond sections */
29 #define MODEM_MAX_LEN 30
30 #define MODEM_MAX_BUF MODEM_MAX_LEN * 16
31
32 #define AST_MAX_INIT_STR        256
33
34 struct ast_modem_pvt;
35
36 struct ast_modem_driver {
37         char *name;
38         char **idents;
39         int formats;
40         int fullduplex;
41         void (*incusecnt)();
42         void (*decusecnt)();
43         char * (*identify)(struct ast_modem_pvt *);
44         int (*init)(struct ast_modem_pvt *);
45         int (*setdev)(struct ast_modem_pvt *, int dev);
46         struct ast_frame * (*read)(struct ast_modem_pvt *);
47         int (*write)(struct ast_modem_pvt *, struct ast_frame *fr);
48         int (*dial)(struct ast_modem_pvt *, char *);
49         int (*answer)(struct ast_modem_pvt *);
50         int (*hangup)(struct ast_modem_pvt *);
51         int (*startrec)(struct ast_modem_pvt *);
52         int (*stoprec)(struct ast_modem_pvt *);
53         int (*startpb)(struct ast_modem_pvt *);
54         int (*stoppb)(struct ast_modem_pvt *);
55         int (*setsilence)(struct ast_modem_pvt *, int onoff);
56         int (*dialdigit)(struct ast_modem_pvt *, char digit);
57         struct ast_modem_driver *next;
58 };
59
60 #define MODEM_MODE_IMMEDIATE            0
61 #define MODEM_MODE_WAIT_RING            1
62 #define MODEM_MODE_WAIT_ANSWER          2
63
64 struct ast_modem_pvt {
65         int fd;                                                 /* Raw file descriptor for this device */
66         FILE *f;                                                /* FILE * representation of device */
67         struct ast_channel *owner;              /* Channel we belong to, possibly NULL */
68         char dev[256];                                  /* Device name */
69         struct ast_frame fr;                    /* Frame */
70         char offset[AST_FRIENDLY_OFFSET];
71         char obuf[MODEM_MAX_BUF];               /* Outgoing buffer */
72         int tail;
73         char dialtype;                                  /* Pulse or tone dialling */
74         char dialtimeout;                               /* Time to wait for dial timeout */
75         int obuflen;
76         int mode;                                               /* Immediate, or wait for an answer */
77         int ministate;                                  /* State of modem in miniature */
78         int stripmsd;                                   /* Digits to strip on outgoing numbers */
79         char context[AST_MAX_EXTENSION];
80         char cid[AST_MAX_EXTENSION];    /* Caller ID if available */
81         char initstr[AST_MAX_INIT_STR]; /* Modem initialization String */
82         char language[MAX_LANGUAGE];    /* default language */
83         char response[256];                             /* Static response buffer */
84         struct ast_modem_driver *mc;    /* Modem Capability */
85         struct ast_modem_pvt *next;                     /* Next channel in list */
86 };
87
88 /* Register a driver */
89 extern int ast_register_modem_driver(struct ast_modem_driver *mc);
90
91 /* Unregister a driver */
92 extern int ast_unregister_modem_driver(struct ast_modem_driver *mc);
93
94 /* Send the command cmd (length len, or 0 if pure ascii) on modem */
95 extern int ast_modem_send(struct ast_modem_pvt *p, char *cmd, int len);
96
97 /* Wait for result to occur.  Return non-zero if times out or error, last
98    response is stored in p->response  */
99 extern int ast_modem_expect(struct ast_modem_pvt *p,  char *result, int timeout);
100
101 /* Wait for result to occur.    response is stored in p->response  */
102 extern int ast_modem_read_response(struct ast_modem_pvt *p,  int timeout);
103
104 /* Used by modem drivers to start up the PBX on a RING */
105 extern struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state);
106
107 /* Trim off trailing mess */
108 extern void ast_modem_trim(char *s);
109 #endif