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