added timer for recovering missing activation/deactivation replies of bchannels from...
[lcr.git] / message.h
1 /*****************************************************************************\
2 **                                                                           **
3 ** Linux Call Router                                                         **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** message types and parameters                                              **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #define ISDN_TRANSMIT   256 // samples
13
14 enum { /* interface types */
15         INFO_ITYPE_ISDN,
16         INFO_ITYPE_ISDN_EXTENSION, /* call from internal extension */
17         INFO_ITYPE_CHAN,
18         INFO_ITYPE_VBOX,
19 };
20
21 enum { /* number types */
22         INFO_NTYPE_UNKNOWN,
23         INFO_NTYPE_SUBSCRIBER,
24         INFO_NTYPE_NATIONAL,
25         INFO_NTYPE_INTERNATIONAL,
26 };
27
28 enum { /* number presentation */
29         INFO_PRESENT_NULL,
30         INFO_PRESENT_ALLOWED,
31         INFO_PRESENT_RESTRICTED,
32         INFO_PRESENT_NOTAVAIL,
33 };
34
35 enum { /* number presentation */
36         INFO_SCREEN_USER, /* user provided */
37         INFO_SCREEN_NETWORK, /* network provided */
38 };
39
40 enum { /* redirection reason */
41         INFO_REDIR_UNKNOWN,
42         INFO_REDIR_BUSY,
43         INFO_REDIR_NORESPONSE,
44         INFO_REDIR_UNCONDITIONAL,
45         INFO_REDIR_OUTOFORDER,
46         INFO_REDIR_CALLDEFLECT,
47 };
48
49 #define INFO_NOTIFY_NONE                        0x00
50 #define INFO_NOTIFY_USER_SUSPENDED              0x80    
51 #define INFO_NOTIFY_USER_RESUMED                0x81
52 #define INFO_NOTIFY_BEARER_SERVICE_CHANGED      0x82
53 #define INFO_NOTIFY_CALL_COMPLETION_DELAY       0x83
54 #define INFO_NOTIFY_CONFERENCE_ESTABLISHED      0xc2
55 #define INFO_NOTIFY_CONFERENCE_DISCONNECTED     0xc3
56 #define INFO_NOTIFY_OTHER_PARTY_ADDED           0xc4
57 #define INFO_NOTIFY_ISOLATED                    0xc5
58 #define INFO_NOTIFY_REATTACHED                  0xc6
59 #define INFO_NOTIFY_OTHER_PARTY_ISOLATED        0xc7
60 #define INFO_NOTIFY_OTHER_PARTY_REATTACHED      0xc8
61 #define INFO_NOTIFY_OTHER_PARTY_SPLIT           0xc9
62 #define INFO_NOTIFY_OTHER_PARTY_DISCONNECTED    0xca
63 #define INFO_NOTIFY_CONFERENCE_FLOATING         0xcb
64 #define INFO_NOTIFY_CONFERENCE_DISCONNECTED_P   0xcc /* preemted */
65 #define INFO_NOTIFY_CONFERENCE_FLOATING_S_U_P   0xcf /* served user preemted */
66 #define INFO_NOTIFY_CALL_IS_A_WAITING_CALL      0xe0
67 #define INFO_NOTIFY_DIVERSION_ACTIVATED         0xe8
68 #define INFO_NOTIFY_RESERVED_CT_1               0xe9
69 #define INFO_NOTIFY_RESERVED_CT_2               0xea
70 #define INFO_NOTIFY_REVERSE_CHARGING            0xee
71 #define INFO_NOTIFY_REMOTE_HOLD                 0xf9
72 #define INFO_NOTIFY_REMOTE_RETRIEVAL            0xfa
73 #define INFO_NOTIFY_CALL_IS_DIVERTING           0xfb
74
75 enum { /* diversion types */
76         INFO_DIVERSION_CFU,
77         INFO_DIVERSION_CFNR,
78         INFO_DIVERSION_CFB,
79         INFO_DIVERSION_CFP,
80 };
81
82 /* bearer capabilities */
83 #define INFO_BC_SPEECH                                  0x00
84 #define INFO_BC_DATAUNRESTRICTED                        0x08
85 #define INFO_BC_DATARESTRICTED                          0x09
86 #define INFO_BC_AUDIO                                   0x10
87 #define INFO_BC_DATAUNRESTRICTED_TONES                  0x11
88 #define INFO_BC_VIDEO                                   0x18
89
90 /* bearer mode */
91 #define INFO_BMODE_CIRCUIT                              0
92 #define INFO_BMODE_PACKET                               2
93
94 /* bearer user l1 */
95 #define INFO_INFO1_NONE                                 0x00
96 #define INFO_INFO1_V110                                 0x81
97 #define INFO_INFO1_ULAW                                 0x82
98 #define INFO_INFO1_ALAW                                 0x83
99 #define INFO_INFO1_G721                                 0x84
100 #define INFO_INFO1_H221H242                             0x85
101 #define INFO_INFO1_NONCCITT                             0x87
102 #define INFO_INFO1_V120                                 0x88
103 #define INFO_INFO1_X31HDLC                              0x89
104
105 /* hlc */
106 #define INFO_HLC_NONE                                   0x00
107 #define INFO_HLC_TELEPHONY                              0x81
108 #define INFO_HLC_FAXG2G3                                0x84
109 #define INFO_HLC_FAXG4                                  0xa1
110 #define INFO_HLC_TELETEX1                               0xa4
111 #define INFO_HLC_TELETEX2                               0xa8
112 #define INFO_HLC_TELETEX3                               0xb1
113 #define INFO_HLC_VIDEOTEX1                              0xb2
114 #define INFO_HLC_VIDEOTEX2                              0xb3
115 #define INFO_HLC_TELEX                                  0xb5
116 #define INFO_HLC_MHS                                    0xb8
117 #define INFO_HLC_OSI                                    0xc1
118 #define INFO_HLC_MAINTENANCE                            0xde
119 #define INFO_HLC_MANAGEMENT                             0xdf
120 #define INFO_HLC_AUDIOVISUAL                            0xe0
121
122 enum { /* isdnsignal */
123         mISDNSIGNAL_VOLUME,             /* change volume */
124         mISDNSIGNAL_CONF,               /* joint/split conference */
125         mISDNSIGNAL_JOINDATA,           /* data required by join instance */
126         mISDNSIGNAL_ECHO,               /* enable/disable echoe */
127         mISDNSIGNAL_DELAY,              /* use delay or adaptive jitter */
128 };
129
130 enum { /* bchannel assignment */
131         BCHANNEL_REQUEST,               /* application requests bchannel */
132         BCHANNEL_ASSIGN,                /* bchannel assigned by LCR */
133         BCHANNEL_ASSIGN_ACK,            /* application acknowledges */
134         BCHANNEL_REMOVE,                /* bchannel removed by LCR */
135         BCHANNEL_REMOVE_ACK,            /* application acknowledges */
136 };
137 enum {
138         B_STATE_IDLE,           /* not open */
139         B_STATE_ACTIVATING,     /* DL_ESTABLISH sent */
140         B_STATE_ACTIVE,         /* channel active */
141         B_STATE_DEACTIVATING,   /* DL_RELEASE sent */
142         B_STATE_EXPORTING,      /* BCHANNEL_ASSIGN sent */
143         B_STATE_REMOTE,         /* bchannel assigned to remote application */
144         B_STATE_IMPORTING,      /* BCHANNEL_REMOVE sent */
145 };
146 enum {
147         B_EVENT_USE,            /* activate/export bchannel */
148         B_EVENT_EXPORTREQUEST,  /* remote app requests bchannel */
149         B_EVENT_ACTIVATED,      /* DL_ESTABLISH received */
150         B_EVENT_DROP,           /* deactivate/re-import bchannel */
151         B_EVENT_DEACTIVATED,    /* DL_RELEASE received */
152         B_EVENT_EXPORTED,       /* BCHANNEL_ASSIGN received */
153         B_EVENT_IMPORTED,       /* BCHANNEL_REMOVE received */
154         B_EVENT_TIMEOUT,        /* timeout for bchannel state */
155 };
156
157 /* call-info structure CALLER */
158 struct caller_info {
159         char id[32];                    /* id of caller (user number) */
160         char extension[32];             /* internal id */
161         char name[16];
162         int isdn_port;                  /* internal/external port (if call is isdn) */
163         char interface[32];             /* interface name the call was from */
164         int itype;                      /* type of interface */
165         int ntype;                      /* type of number */
166         int present;                    /* presentation */
167         int screen;                     /* who provided the number */
168         char display[84];               /* display information */
169 };
170
171 /* call-info structure DIALING */
172 struct dialing_info {
173         char id[256];                   /* number dialing (so far) */
174         char interfaces[128];           /* interfaces for extenal calls */
175         int itype;                      /* type of interface */
176         int ntype;                      /* type of number */
177         int sending_complete;           /* end of dialing */
178 };
179
180 /* call-info structure CONNECT */
181 struct connect_info {
182         char id[32];                    /* id of caller (user number) */
183         char extension[32];             /* internal id */
184         char name[16];
185         int isdn_port;                  /* internal/external port (if call is isdn) */
186         char interface[128];            /* interface for extenal calls */
187         int itype;                      /* type of interface */
188         int ntype;                      /* type of number */
189         int present;                    /* presentation */
190         int screen;                     /* who provided the number */
191         char display[84];               /* display information */
192 };
193
194 /* call-info structure DISCONNECT */
195 struct disconnect_info {
196         int cause;                      /* reason for disconnect */
197         int location;                   /* disconnect location */
198         char display[84];               /* optional display information */
199 };
200
201 /* call-info structure REDIR */
202 struct redir_info {
203         char id[32];                    /* id of caller (user number) */
204         char extension[32];             /* internal id */
205         int isdn_port;                  /* internal/external port (if call is isdn) */
206         int itype;                      /* type of interface */
207         int ntype;                      /* type of number */
208         int present;                    /* presentation */
209         int screen;                     /* who provided the number */
210         int reason;                     /* reason for redirecing */
211 };
212
213 /* call-info structure capability */
214 struct capa_info {
215         int bearer_capa;                /* capability */
216         int bearer_mode;                /* circuit/packet */
217         int bearer_info1;               /* alaw,ulaw,... */
218         int hlc;                        /* hlc capability */
219         int exthlc;                     /* extendet hlc */
220 };
221
222 /* call-info structure NOTIFY */
223 struct notify_info {
224         int notify;                     /* notifications (see INFO_NOTIFY_*) */
225         char id[32];                    /* redirection id (user number) */
226         char extension[32];             /* internal id */
227         int isdn_port;                  /* internal/external port (if call is isdn) */
228         int itype;                      /* type of interface */
229         int ntype;                      /* type of number */
230         int present;                    /* redirection presentation */
231         char display[84];               /* display information */
232         int local;                      /* if set, endpoints gets information about audio channel (open/close) */
233 };
234
235 /* call-info structure FACILITY */
236 struct facility_info {
237         char data[256];                 /* data info about facility */
238         int len;                        /* length of facility content */
239 };
240
241 /* call-info structure USERUSER */
242 struct useruser_info {
243         int protocol;
244         int len;
245         unsigned char data[128];        /* user-user info (not a sting!)*/
246 };
247
248 /* call-info structure SETUP */ 
249 struct message_setup {
250         int isdn_port; /* card number 1...n (only on calls from isdn port) */
251         int port_type; /* type of port (only required if message is port -> epoint) */
252         int dtmf; /* used to enabled dtmf dialing at setup state */
253         int partyline; /* if set, call will be a conference room */
254         int partyline_jingle; /* if set, the jingle will be played on conference join */
255         struct caller_info callerinfo;          /* information about the caller */
256         struct dialing_info dialinginfo;        /* information about dialing */
257         struct redir_info redirinfo;            /* info on redirection (to the calling user) */
258         struct capa_info capainfo;              /* info on l2,l3 capability */
259         struct useruser_info useruser;          /* user-user */
260 };
261
262 /* call-info structure PARK */
263 struct park_info {
264         char callid[8];
265         int len;
266 };
267
268 /* DATA */
269 struct param_data {
270         unsigned char data[ISDN_TRANSMIT]; /* audio/hdlc data */
271         int len; /* audio/hdlc data */
272 };
273
274 struct param_play {
275         char file[512]; /* file name */
276         int offset; /* offset to start file at (in seconds) */
277 };
278
279 struct param_tone {
280         char dir[128]; /* directory */
281         char name[128]; /* file name */
282 };
283
284 struct param_counter {
285         int current; /* current counter in seconds */
286         int max; /* total size of file (0=no info) */
287 };
288
289 struct param_mISDNsignal {
290         int message;
291         int tx_gain;
292         int rx_gain;
293         int conf;
294         int joindata;
295         int tone;
296         int echo;
297         int delay;
298 };
299
300 /* encryption control structure CRYPT */
301 struct param_crypt {
302         int type; /* see messages in crypt.h */
303         int len;
304         unsigned char data[512+32]; /* a block of 512 byte + some overhead */
305 };
306
307 struct param_hello {
308         char application[32]; /* name of remote application */
309 };
310
311 struct param_bchannel {
312         int type; /* BCHANNEL_* */
313         unsigned long handle; /* bchannel stack/portid */
314         int tx_gain, rx_gain;
315         char pipeline[256];
316         unsigned char crypt[128];
317         int crypt_len;
318         int crypt_type; /* 1 = blowfish */
319 };
320
321 /* structure of message parameter */
322 union parameter {
323         struct param_tone tone; /* MESSAGE_TONE */
324         char dtmf; /* MESSAGE_DTMF */
325         struct message_setup setup; /* MESSAGE_SETUP */
326         struct dialing_info information; /* MESSAGE_INFO */
327         struct connect_info connectinfo; /* CONNECT INFO */
328         struct disconnect_info disconnectinfo; /* DISCONNECT INFO */
329         struct notify_info notifyinfo; /* some notifications */
330         struct facility_info facilityinfo; /* some notifications */
331         struct park_info parkinfo; /* MESSAGE_SUSPEND, MESSAGE_RESUME */
332         int state; /* MESSAGE_TIMEOUT */
333         int knock; /* MESSAGE_KNOCK 0=off !0=on */
334         int audiopath; /* MESSAGE_audiopath see RELATION_CHANNEL_* (join.h) */
335         struct param_data data; /* MESSAGE_DATA */
336         struct param_play play; /* MESSAGE_VBOX_PLAY */
337         int speed; /* MESSAGE_VBOX_PLAY_SPEED */
338         struct param_counter counter; /* MESSAGE_TONE_COUNTER */
339         struct param_mISDNsignal mISDNsignal; /* MESSAGE_mISDNSIGNAL */
340         struct extension ext; /* tell port about extension information */
341         struct param_crypt crypt; /* MESSAGE_CRYPT */
342         struct param_hello hello; /* MESSAGE_HELLO */
343         struct param_bchannel bchannel; /* MESSAGE_BCHANNEL */
344         int direction; /* MESSAGE_NEWREF */
345 };
346
347 enum { /* message flow */
348         PORT_TO_EPOINT,
349         EPOINT_TO_JOIN,
350         JOIN_TO_EPOINT,
351         EPOINT_TO_PORT,
352 };
353
354 /* message structure */
355 struct message {
356         struct message *next;
357         int type; /* type of message */
358         int flow; /* from where to where */
359         unsigned long id_from; /* in case of flow==PORT_TO_EPOINT: id_from is the port's serial, id_to is the epoint's serial */
360         unsigned long id_to;
361         int keep;
362         union parameter param;
363 };
364
365 enum { /* messages between entities */
366         MESSAGE_NONE,           /* no message */
367         MESSAGE_TONE,           /* set information tone (to isdn port) */
368         MESSAGE_DTMF,           /* dtmf digit (from isdn port) */
369         MESSAGE_mISDNSIGNAL,    /* special mixer command (down to isdn port) */
370         MESSAGE_SETUP,          /* setup message */
371         MESSAGE_INFORMATION,    /* additional digit information */
372         MESSAGE_OVERLAP,        /* call accepted, send more information */
373         MESSAGE_PROCEEDING,     /* proceeding */
374         MESSAGE_ALERTING,       /* ringing */
375         MESSAGE_CONNECT,        /* connect */
376         MESSAGE_DISCONNECT,     /* disconnect with cause */
377         MESSAGE_RELEASE,        /* release with cause */
378         MESSAGE_TIMEOUT,        /* protocol state has timed out (port->epoint) */
379         MESSAGE_NOTIFY,         /* used to send progress and notify infos */
380         MESSAGE_FACILITY,       /* used to facility infos, like aocd */
381         MESSAGE_SUSPEND,        /* suspend port */
382         MESSAGE_RESUME,         /* resume port */
383         MESSAGE_AUDIOPATH,      /* set status of audio path to endpoint (to call, audio is also set) */
384 //      MESSAGE_REMOTE_AUDIO,   /* tell remote to set audio status */
385         MESSAGE_PATTERN,        /* pattern information tones available */
386         MESSAGE_NOPATTERN,      /* pattern information tones unavailable */
387         MESSAGE_CRYPT,          /* encryption message */
388         MESSAGE_DATA,           /* audio/hdlc data */
389         MESSAGE_VBOX_PLAY,      /* play recorded file */
390         MESSAGE_VBOX_PLAY_SPEED,/* change speed of file */
391         MESSAGE_VBOX_TONE,      /* set answering VBOX tone */
392         MESSAGE_TONE_COUNTER,   /* tone counter (for VBOX tone use) */
393         MESSAGE_TONE_EOF,       /* tone is end of file */
394         MESSAGE_BCHANNEL,       /* request/assign/remove bchannel */
395         MESSAGE_HELLO,          /* hello message for remote application */
396         MESSAGE_NEWREF,         /* special message to create and inform ref */
397 };
398
399 #define MESSAGES static const char *messages_txt[] = { \
400         "MESSAGE_NONE", \
401         "MESSAGE_TONE", \
402         "MESSAGE_DTMF", \
403         "MESSAGE_mISDNSIGNAL", \
404         "MESSAGE_SETUP", \
405         "MESSAGE_INFORMATION", \
406         "MESSAGE_OVERLAP", \
407         "MESSAGE_PROCEEDING", \
408         "MESSAGE_ALERTING", \
409         "MESSAGE_CONNECT", \
410         "MESSAGE_DISCONNECT", \
411         "MESSAGE_RELEASE", \
412         "MESSAGE_TIMEOUT", \
413         "MESSAGE_NOTIFY", \
414         "MESSAGE_FACILITY", \
415         "MESSAGE_SUSPEND", \
416         "MESSAGE_RESUME", \
417         "MESSAGE_AUDIOPATH", \
418 /*      "MESSAGE_REMOTE_AUDIO",*/ \
419         "MESSAGE_PATTERN", \
420         "MESSAGE_NOPATTERN", \
421         "MESSAGE_CRYPT", \
422         "MESSAGE_DATA", \
423         "MESSAGE_VBOX_PLAY", \
424         "MESSAGE_VBOX_PLAY_SPEED", \
425         "MESSAGE_VBOX_TONE", \
426         "MESSAGE_TONE_COUNTER", \
427         "MESSAGE_TONE_EOF", \
428         "MESSAGE_BCHANNEL", \
429         "MESSAGE_HELLO", \
430         "MESSAGE_NEWREF", \
431 };
432
433
434 struct message *message_create(int id_from, int id_to, int flow, int type);
435 void message_put(struct message *message);
436 struct message *message_forward(int id_from, int id_to, int flow, union parameter *param);
437 struct message *message_get(void);
438 void message_free(struct message *message);
439
440
441