SIP: Fix incoming re-invite
[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 struct chan_call {
13         struct chan_call        *next;  /* link to next call instance */
14         int                     state;  /* current call state CHAN_LCR_STATE */
15         unsigned int            ref;    /* callref for this channel */
16         int                     ref_was_assigned;
17         void                    *ast;   /* current asterisk channel */
18         int                     pbx_started;
19                                         /* indicates if pbx que is available */
20         int                     audiopath;
21                                         /* audio is available */
22         int                     cause, location;
23                                         /* store cause from lcr */
24         char                    dialque[64];
25                                         /* queue dialing prior setup ack */
26         char                    oad[64];/* caller id in number format */
27
28         struct caller_info      callerinfo;
29         struct redir_info       redirinfo;
30         struct connect_info     connectinfo;
31                                         /* store connectinfo form lcr */
32         int                     bridge_id;
33                                         /* current ID or 0 */
34         struct chan_call        *bridge_call;
35                                         /* remote instance or NULL */
36         int                     pipe[2];
37                                         /* pipe for receive data */
38         unsigned char           read_buff[1024];
39                                         /* read buffer for frame */
40         struct ast_frame        read_fr;
41                                         /* frame for read */
42         char                    interface[32];
43                                         /* LCR interface name for setup */
44         char                    dialstring[64];
45                                         /* cached dial string for setup */
46 #ifndef AST_PARTY_CALLER
47         char                    cid_num[64]; /* cached cid for setup */
48         char                    cid_name[64]; /* cached cid for setup */
49         char                    cid_rdnis[64]; /* cached cid for setup */
50 #endif
51         char                    display[128];
52                                         /* display for setup */
53         int                     dsp_dtmf;
54                                         /* decode dtmf by dsp */
55         int                     inband_dtmf; /* generate dtmf tones, if
56                                               requested by asterisk */
57         int                     rebuffer; /* send only 160 bytes frames
58                                              to asterisk */
59
60         int                     framepos; /* send only 160 bytes frames to asterisk */
61         
62         int                     on_hold; /* track hold management, since
63                                             sip phones sometimes screw it up */
64         char                    pipeline[256];
65                                         /* echo cancel pipeline by option */
66         int                     tx_gain, rx_gain;
67                                         /* gain by option */
68         int                     keypad;
69                                         /* use keypad to dial number */
70         unsigned char           bf_key[56];
71         int                     bf_len; /* blowfish crypt key */
72         struct ast_dsp          *dsp; /* ast dsp processor for fax/tone detection */
73         struct ast_trans_pvt    *trans; /* Codec translation path as fax/tone detection requires slin */
74         int                     tx_queue, hdlc, faxdetect, ast_dsp;
75                                         /* flags for bchannel mode */
76         char                    queue_string[64];
77                                         /* queue for asterisk */
78         int                     has_pattern;
79                                         /* pattern are available, PROGRESS has been indicated */
80                 
81 };
82
83 enum {
84         CHAN_LCR_STATE_IN_PREPARE = 0,
85         CHAN_LCR_STATE_IN_SETUP,
86         CHAN_LCR_STATE_IN_DIALING,
87         CHAN_LCR_STATE_IN_PROCEEDING,
88         CHAN_LCR_STATE_IN_ALERTING,
89         CHAN_LCR_STATE_OUT_PREPARE,
90         CHAN_LCR_STATE_OUT_SETUP,
91         CHAN_LCR_STATE_OUT_DIALING,
92         CHAN_LCR_STATE_OUT_PROCEEDING,
93         CHAN_LCR_STATE_OUT_ALERTING,
94         CHAN_LCR_STATE_CONNECT,
95         CHAN_LCR_STATE_IN_DISCONNECT,
96         CHAN_LCR_STATE_OUT_DISCONNECT,
97         CHAN_LCR_STATE_RELEASE,
98 };
99
100 #define CHAN_LCR_STATE static const struct chan_lcr_state { \
101         char *name; \
102         char *meaning; \
103 } chan_lcr_state[] = { \
104         { "IN_PREPARE", \
105           "New call from ISDN is waiting for setup." }, \
106         { "IN_SETUP", \
107           "Call from ISDN is currently set up." }, \
108         { "IN_DIALING", \
109           "Call from ISDN is currently waiting for digits to be dialed." }, \
110         { "IN_PROCEEDING", \
111           "Call from ISDN is complete and proceeds to ring." }, \
112         { "IN_ALERTING", \
113           "Call from ISDN is ringing." }, \
114         { "OUT_PREPARE", \
115           "New call to ISDN is wating for setup." }, \
116         { "OUT_SETUP", \
117           "Call to ISDN is currently set up." }, \
118         { "OUT_DIALING", \
119           "Call to ISDN is currently waiting for digits to be dialed." }, \
120         { "OUT_PROCEEDING", \
121           "Call to ISDN is complete and proceeds to ring." }, \
122         { "OUT_ALERTING", \
123           "Call to ISDN is ringing." }, \
124         { "CONNECT", \
125           "Call has been answered." }, \
126         { "IN_DISCONNECT", \
127           "Call has been hung up on ISDN side." }, \
128         { "OUT_DISCONNECT", \
129           "Call has been hung up on Asterisk side." }, \
130         { "RELEASE", \
131           "Call is waiting for complete release." }, \
132 };
133
134
135 #define SOCKET_RETRY_TIMER      5
136
137 #define CERROR(call, ast, arg...) chan_lcr_log(__LOG_ERROR, __FILE__, __LINE__,  __FUNCTION__, call, ast, ##arg)
138 #define CDEBUG(call, ast, arg...) chan_lcr_log(__LOG_NOTICE, __FILE__, __LINE__,  __FUNCTION__, call, ast, ##arg)
139 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, ...);
140 extern unsigned char flip_bits[256];
141 void lcr_in_dtmf(struct chan_call *call, int val);