Merge branch 'master' of ssh://schlaile@git.misdn.org/var/git/lcr
[lcr.git] / chan_lcr.h
1 /*****************************************************************************\
2 **                                                                           **
3 ** Linux Call Router                                                         **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** Asterisk socket client header                                             **
9 **                                                                           **
10 \*****************************************************************************/
11
12 /* structure for all calls */
13 struct bchannel;
14 struct chan_call {
15         struct chan_call        *next;  /* link to next call instance */
16         int                     state;  /* current call state CHAN_LCR_STATE */
17         unsigned int            ref;    /* callref for this channel */
18         int                     ref_was_assigned;
19         void                    *ast;   /* current asterisk channel */
20         int                     pbx_started;
21                                         /* indicates if pbx que is available */
22         struct bchannel         *bchannel;
23                                         /* reference to bchannel, if set */
24         int                     audiopath;
25                                         /* audio is available */
26         int                     cause, location;
27                                         /* store cause from lcr */
28         char                    dialque[64];
29                                         /* queue dialing prior setup ack */
30         char                    oad[64];/* caller id in number format */
31
32         struct connect_info     connectinfo;
33                                         /* store connectinfo form lcr */
34         int                     bridge_id;
35                                         /* current ID or 0 */
36         struct chan_call        *bridge_call;
37                                         /* remote instance or NULL */
38         int                     pipe[2];
39                                         /* pipe for receive data */
40         unsigned char           read_buff[1024];
41                                         /* read buffer for frame */
42         struct ast_frame        read_fr;
43                                         /* frame for read */
44         char                    interface[32];
45                                         /* LCR interface name for setup */
46         char                    dialstring[64];
47                                         /* cached dial string for setup */
48         char                    cid_num[64]; /* cached cid for setup */
49         char                    cid_name[64]; /* cached cid for setup */
50         char                    cid_rdnis[64]; /* cached cid for setup */
51         char                    display[128];
52                                         /* display for setup */
53         int                     dtmf;
54                                         /* shall dtmf be enabled */
55         int                     no_dtmf;
56                                         /* dtmf disabled by option */
57         int                     inband_dtmf; /* generate dtmf tones, if
58                                               requested by asterisk */
59         int                     rebuffer; /* send only 160 bytes frames
60                                              to asterisk */
61         int                     on_hold; /* track hold management, since
62                                             sip phones sometimes screw it up */
63         char                    pipeline[256];
64                                         /* echo cancel pipeline by option */
65         int                     tx_gain, rx_gain;
66                                         /* gain by option */
67         unsigned char           bf_key[56];
68         int                     bf_len; /* blowfish crypt key */
69         int                     nodsp, hdlc;
70                                         /* flags for bchannel mode */
71         char                    queue_string[64];
72                                         /* queue for asterisk */
73                 
74 };
75
76 enum {
77         CHAN_LCR_STATE_IN_PREPARE = 0,
78         CHAN_LCR_STATE_IN_SETUP,
79         CHAN_LCR_STATE_IN_DIALING,
80         CHAN_LCR_STATE_IN_PROCEEDING,
81         CHAN_LCR_STATE_IN_ALERTING,
82         CHAN_LCR_STATE_OUT_PREPARE,
83         CHAN_LCR_STATE_OUT_SETUP,
84         CHAN_LCR_STATE_OUT_DIALING,
85         CHAN_LCR_STATE_OUT_PROCEEDING,
86         CHAN_LCR_STATE_OUT_ALERTING,
87         CHAN_LCR_STATE_CONNECT,
88         CHAN_LCR_STATE_IN_DISCONNECT,
89         CHAN_LCR_STATE_OUT_DISCONNECT,
90         CHAN_LCR_STATE_RELEASE,
91 };
92
93 #define CHAN_LCR_STATE static const struct chan_lcr_state { \
94         char *name; \
95         char *meaning; \
96 } chan_lcr_state[] = { \
97         { "IN_PREPARE", \
98           "New call from ISDN is waiting for setup." }, \
99         { "IN_SETUP", \
100           "Call from ISDN is currently set up." }, \
101         { "IN_DIALING", \
102           "Call from ISDN is currently waiting for digits to be dialed." }, \
103         { "IN_PROCEEDING", \
104           "Call from ISDN is complete and proceeds to ring." }, \
105         { "IN_ALERTING", \
106           "Call from ISDN is ringing." }, \
107         { "OUT_PREPARE", \
108           "New call to ISDN is wating for setup." }, \
109         { "OUT_SETUP", \
110           "Call to ISDN is currently set up." }, \
111         { "OUT_DIALING", \
112           "Call to ISDN is currently waiting for digits to be dialed." }, \
113         { "OUT_PROCEEDING", \
114           "Call to ISDN is complete and proceeds to ring." }, \
115         { "OUT_ALERTING", \
116           "Call to ISDN is ringing." }, \
117         { "CONNECT", \
118           "Call has been answered." }, \
119         { "IN_DISCONNECT", \
120           "Call has been hung up on ISDN side." }, \
121         { "OUT_DISCONNECT", \
122           "Call has been hung up on Asterisk side." }, \
123         { "RELEASE", \
124           "Call is waiting for complete release." }, \
125 };
126
127
128 #define CERROR(call, ast, arg...) chan_lcr_log(__LOG_ERROR, __FILE__, __LINE__,  __FUNCTION__, call, ast, ##arg)
129 #define CDEBUG(call, ast, arg...) chan_lcr_log(__LOG_NOTICE, __FILE__, __LINE__,  __FUNCTION__, call, ast, ##arg)
130 void chan_lcr_log(int type, const char *file, int line, const char *function,  struct chan_call *call, struct ast_channel *ast, const char *fmt, ...);
131 extern unsigned char flip_bits[256];
132 void lcr_in_dtmf(struct chan_call *call, int val);