Change Version to 1.14
[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, /* call from external */
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_NOTPRESENT = 0,
21         INFO_NTYPE_UNKNOWN,
22         INFO_NTYPE_SUBSCRIBER,
23         INFO_NTYPE_NATIONAL,
24         INFO_NTYPE_INTERNATIONAL
25 };
26
27 enum { /* number presentation */
28         INFO_PRESENT_NOTAVAIL,
29         INFO_PRESENT_ALLOWED,
30         INFO_PRESENT_RESTRICTED
31 };
32
33 enum { /* number presentation */
34         INFO_SCREEN_USER, /* user provided */
35         INFO_SCREEN_USER_VERIFIED_PASSED,
36         INFO_SCREEN_USER_VERIFIED_FAILED,
37         INFO_SCREEN_NETWORK /* network provided */
38 };
39
40 enum { /* redirection reason */
41         INFO_REDIR_UNKNOWN = 0,
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_ECHO,               /* enable/disable echoe */
126         mISDNSIGNAL_DELAY,              /* use delay or adaptive jitter */
127 };
128
129 enum {
130         B_STATE_IDLE,           /* not open */
131         B_STATE_ACTIVATING,     /* DL_ESTABLISH sent */
132         B_STATE_ACTIVE,         /* channel active */
133         B_STATE_DEACTIVATING,   /* DL_RELEASE sent */
134 };
135
136 enum {
137         B_MODE_TRANSPARENT,     /* normal transparent audio */
138         B_MODE_HDLC,            /* hdlc data mode */
139 };
140
141 enum {
142         MEDIA_TYPE_ALAW = 1,
143         MEDIA_TYPE_ULAW,
144         MEDIA_TYPE_GSM,
145         MEDIA_TYPE_GSM_EFR,
146         MEDIA_TYPE_AMR,
147         MEDIA_TYPE_GSM_HR,
148 };
149
150 /* rtp-info structure */
151 struct rtp_info {
152         int payloads;                   /* number of payloads offered */
153         unsigned char payload_types[32];/* rtp payload types */
154         int media_types[32];            /* media type of given payload */
155         unsigned int ip;                /* peer's IP */
156         unsigned short port;            /* peer's port */
157 };
158
159 /* call-info structure CALLER */
160 struct caller_info {
161         char id[32];                    /* id of caller (user number) */
162         char extension[32];             /* internal id */
163         char name[16];
164         int isdn_port;                  /* internal/external port (if call is isdn) */
165         char interface[32];             /* interface name the call was from */
166         int itype;                      /* type of interface */
167         int ntype;                      /* type of number */
168         int present;                    /* presentation */
169         int screen;                     /* who provided the number */
170         char display[84];               /* display information */
171         char id2[32];                   /* second callerid */
172         int ntype2;                     /* second type of number */
173         int present2;                   /* second presentation */
174         int screen2;                    /* second who provided the number */
175         char imsi[16];                  /* IMSI for gsm originated calls */
176 };
177
178 /* call-info structure DIALING */
179 struct dialing_info {
180         char id[256];                   /* number dialing (so far) */
181         char interfaces[128];           /* interfaces for extenal calls */
182         int itype;                      /* type of interface */
183         int ntype;                      /* type of number */
184         int sending_complete;           /* end of dialing */
185         char display[84];               /* display information */
186         char keypad[33];                /* send keypad facility */
187         char context[32];               /* asterisk context */
188         int flash;                      /* flash key caused setup of call */
189 };
190
191 /* call-info structure CONNECT */
192 struct connect_info {
193         char id[32];                    /* id of caller (user number) */
194         char extension[32];             /* internal id */
195         char name[16];
196         int isdn_port;                  /* internal/external port (if call is isdn) */
197         char interface[128];            /* interface for extenal calls */
198         int itype;                      /* type of interface */
199         int ntype;                      /* type of number */
200         int present;                    /* presentation */
201         int screen;                     /* who provided the number */
202         char display[84];               /* display information */
203         char imsi[16];                  /* IMSI for gsm terminated calls */
204         struct rtp_info rtpinfo;        /* info about RTP peer */
205 };
206
207 /* call-info structure DISCONNECT */
208 struct disconnect_info {
209         int cause;                      /* reason for disconnect */
210         int location;                   /* disconnect location */
211         char display[84];               /* optional display information */
212         int force;                      /* special flag to release imediately */
213 };
214
215 /* call-info structure REDIR */
216 struct redir_info {
217         char id[32];                    /* id of caller (user number) */
218         char extension[32];             /* internal id */
219         int isdn_port;                  /* internal/external port (if call is isdn) */
220         int itype;                      /* type of interface */
221         int ntype;                      /* type of number */
222         int present;                    /* presentation */
223         int screen;                     /* who provided the number */
224         int reason;                     /* reason for redirecing */
225 };
226
227 /* call-info structure capability */
228 struct capa_info {
229         int source_mode;                /* forward mode */
230         int bearer_capa;                /* capability */
231         int bearer_mode;                /* circuit/packet */
232         int bearer_info1;               /* alaw,ulaw,... */
233         int hlc;                        /* hlc capability */
234         int exthlc;                     /* extendet hlc */
235 };
236
237 /* call-info structure NOTIFY */
238 struct notify_info {
239         int notify;                     /* notifications (see INFO_NOTIFY_*) */
240         char id[32];                    /* redirection id (user number) */
241         char extension[32];             /* internal id */
242         int isdn_port;                  /* internal/external port (if call is isdn) */
243         int itype;                      /* type of interface */
244         int ntype;                      /* type of number */
245         int present;                    /* redirection presentation */
246         char display[84];               /* display information */
247         int local;                      /* if set, endpoints gets information about audio channel (open/close) */
248 };
249
250 /* call-info structure PROGRESS */
251 struct progress_info {
252         int progress;                   /* progress indicator */
253         int location;                   /* progress location */
254         struct rtp_info rtpinfo;        /* info about RTP peer */
255 };
256
257 /* call-info structure FACILITY */
258 struct facility_info {
259         char data[256];                 /* data info about facility */
260         int len;                        /* length of facility content */
261 };
262
263 /* call-info structure USERUSER */
264 struct useruser_info {
265         int protocol;
266         int len;
267         unsigned char data[128];        /* user-user info (not a sting!)*/
268 };
269
270 /* call-info structure SETUP */ 
271 struct message_setup {
272         int isdn_port; /* card number 1...n (only on calls from isdn port) */
273         int port_type; /* type of port (only required if message is port -> epoint) */
274         int partyline; /* if set, call will be a conference room */
275         int partyline_jingle; /* if set, the jingle will be played on conference join */
276         struct caller_info callerinfo;          /* information about the caller */
277         struct dialing_info dialinginfo;        /* information about dialing */
278         struct redir_info redirinfo;            /* info on redirection (to the calling user) */
279         struct capa_info capainfo;              /* info on l2,l3 capability */
280         struct useruser_info useruser;          /* user-user */
281         struct progress_info progress;          /* info on call progress */
282         struct rtp_info rtpinfo;                /* info about RTP peer */
283 };
284
285 /* call-info structure PARK */
286 struct park_info {
287         char callid[8];
288         int len;
289 };
290
291 struct param_play {
292         char file[512]; /* file name */
293         int offset; /* offset to start file at (in seconds) */
294 };
295
296 struct param_tone {
297         char dir[128]; /* directory */
298         char name[128]; /* file name */
299 };
300
301 struct param_counter {
302         int current; /* current counter in seconds */
303         int max; /* total size of file (0=no info) */
304 };
305
306 struct param_mISDNsignal {
307         int message;
308         int tx_gain;
309         int rx_gain;
310         int conf;
311         int tone;
312         int echo;
313         int delay;
314 };
315
316 /* encryption control structure CRYPT */
317 struct param_crypt {
318         int type; /* see messages in crypt.h */
319         int len;
320         unsigned char data[512+32]; /* a block of 512 byte + some overhead */
321 };
322
323 struct param_hello {
324         char application[32]; /* name of remote application */
325 };
326
327 struct param_bchannel {
328         int type; /* BCHANNEL_* */
329         unsigned int handle; /* bchannel stack/portid */
330         int isloopback; /* in this case the application behaves like an interface, dsp should not be used */
331         int tx_gain, rx_gain;
332         char pipeline[256];
333         unsigned char crypt[128];
334         int crypt_len;
335         int crypt_type; /* 1 = blowfish */
336 };
337
338 struct param_newref {
339         int direction; /* who requests a refe? */
340         char interface[32]; /* interface name for selecting remote interface */
341 };
342
343 struct param_traffic {
344         int len;        /* how much data */
345         unsigned char data[160];        /* 20ms */
346 };
347
348 struct param_3pty {
349         int begin, end;
350         int invoke, result, error;
351         unsigned char invoke_id;
352 };
353
354 /* structure of message parameter */
355 union parameter {
356         struct param_tone tone; /* MESSAGE_TONE */
357         char dtmf; /* MESSAGE_DTMF */
358         struct message_setup setup; /* MESSAGE_SETUP */
359         struct dialing_info information; /* MESSAGE_INFO */
360         struct connect_info connectinfo; /* CONNECT INFO */
361         struct disconnect_info disconnectinfo; /* DISCONNECT INFO */
362         struct notify_info notifyinfo; /* some notifications */
363         struct progress_info progressinfo; /* some progress */
364         struct facility_info facilityinfo; /* some notifications */
365         struct park_info parkinfo; /* MESSAGE_SUSPEND, MESSAGE_RESUME */
366         int state; /* MESSAGE_TIMEOUT */
367         int knock; /* MESSAGE_KNOCK 0=off !0=on */
368         int audiopath; /* MESSAGE_audiopath see RELATION_CHANNEL_* (join.h) */
369         struct param_play play; /* MESSAGE_VBOX_PLAY */
370         int speed; /* MESSAGE_VBOX_PLAY_SPEED */
371         struct param_counter counter; /* MESSAGE_TONE_COUNTER */
372         struct param_mISDNsignal mISDNsignal; /* MESSAGE_mISDNSIGNAL */
373         struct extension ext; /* tell port about extension information */
374         struct param_crypt crypt; /* MESSAGE_CRYPT */
375         struct param_hello hello; /* MESSAGE_HELLO */
376         struct param_bchannel bchannel; /* MESSAGE_BCHANNEL */
377         struct param_newref newref; /* MESSAGE_NEWREF */
378         unsigned int bridge_id; /* MESSAGE_BRIDGE */
379         struct param_traffic traffic; /* MESSAGE_TRAFFIC */
380         struct param_3pty threepty; /* MESSAGE_TRAFFIC */
381         unsigned int queue; /* MESSAGE_DISABLE_DEJITTER */
382 };
383
384 enum { /* message flow */
385         PORT_TO_EPOINT,
386         EPOINT_TO_JOIN,
387         JOIN_TO_EPOINT,
388         EPOINT_TO_PORT,
389 };
390
391 /* message structure */
392 struct lcr_msg {
393         struct lcr_msg *next;
394         int type; /* type of message */
395         int flow; /* from where to where */
396         unsigned int id_from; /* in case of flow==PORT_TO_EPOINT: id_from is the port's serial, id_to is the epoint's serial */
397         unsigned int id_to;
398         int keep;
399         union parameter param;
400 };
401
402 enum { /* messages between entities */
403         MESSAGE_NONE,           /* no message */
404         MESSAGE_TONE,           /* set information tone (to isdn port) */
405         MESSAGE_DTMF,           /* dtmf digit (from isdn port) */
406         MESSAGE_ENABLEKEYPAD,   /* remote application requests keypad/dtmf */
407         MESSAGE_mISDNSIGNAL,    /* special mixer command (down to isdn port) */
408         MESSAGE_SETUP,          /* setup message */
409         MESSAGE_INFORMATION,    /* additional digit information */
410         MESSAGE_OVERLAP,        /* call accepted, send more information */
411         MESSAGE_PROCEEDING,     /* proceeding */
412         MESSAGE_ALERTING,       /* ringing */
413         MESSAGE_CONNECT,        /* connect */
414         MESSAGE_DISCONNECT,     /* disconnect with cause */
415         MESSAGE_RELEASE,        /* release with cause */
416         MESSAGE_TIMEOUT,        /* protocol state has timed out (port->epoint) */
417         MESSAGE_NOTIFY,         /* used to send notify info */
418         MESSAGE_PROGRESS,       /* used to send progress info */
419         MESSAGE_FACILITY,       /* used to facility infos, like aocd */
420         MESSAGE_SUSPEND,        /* suspend port */
421         MESSAGE_RESUME,         /* resume port */
422         MESSAGE_AUDIOPATH,      /* set status of audio path to endpoint (to call, audio is also set) */
423         MESSAGE_PATTERN,        /* pattern information tones available */
424         MESSAGE_NOPATTERN,      /* pattern information tones unavailable */
425         MESSAGE_CRYPT,          /* encryption message */
426         MESSAGE_VBOX_PLAY,      /* play recorded file */
427         MESSAGE_VBOX_PLAY_SPEED,/* change speed of file */
428         MESSAGE_VBOX_TONE,      /* set answering VBOX tone */
429         MESSAGE_TONE_COUNTER,   /* tone counter (for VBOX tone use) */
430         MESSAGE_TONE_EOF,       /* tone is end of file */
431         MESSAGE_BCHANNEL,       /* request/assign/remove bchannel */
432         MESSAGE_HELLO,          /* hello message for remote application */
433         MESSAGE_NEWREF,         /* special message to create and inform ref */
434         MESSAGE_BRIDGE,         /* control port bridge */
435         MESSAGE_TRAFFIC,        /* exchange bchannel traffic */
436         MESSAGE_3PTY,           /* 3PTY call invoke */
437         MESSAGE_TRANSFER,       /* call transfer invoke */
438         MESSAGE_DISABLE_DEJITTER/* tell (mISDN) port not to dejitter */
439 };
440
441 #define MESSAGES static const char *messages_txt[] = { \
442         "MESSAGE_NONE", \
443         "MESSAGE_TONE", \
444         "MESSAGE_DTMF", \
445         "MESSAGE_ENABLEKEYPAD", \
446         "MESSAGE_mISDNSIGNAL", \
447         "MESSAGE_SETUP", \
448         "MESSAGE_INFORMATION", \
449         "MESSAGE_OVERLAP", \
450         "MESSAGE_PROCEEDING", \
451         "MESSAGE_ALERTING", \
452         "MESSAGE_CONNECT", \
453         "MESSAGE_DISCONNECT", \
454         "MESSAGE_RELEASE", \
455         "MESSAGE_TIMEOUT", \
456         "MESSAGE_NOTIFY", \
457         "MESSAGE_PROGRESS", \
458         "MESSAGE_FACILITY", \
459         "MESSAGE_SUSPEND", \
460         "MESSAGE_RESUME", \
461         "MESSAGE_AUDIOPATH", \
462         "MESSAGE_PATTERN", \
463         "MESSAGE_NOPATTERN", \
464         "MESSAGE_CRYPT", \
465         "MESSAGE_VBOX_PLAY", \
466         "MESSAGE_VBOX_PLAY_SPEED", \
467         "MESSAGE_VBOX_TONE", \
468         "MESSAGE_TONE_COUNTER", \
469         "MESSAGE_TONE_EOF", \
470         "MESSAGE_BCHANNEL", \
471         "MESSAGE_HELLO", \
472         "MESSAGE_NEWREF", \
473         "MESSAGE_BRIDGE", \
474         "MESSAGE_TRAFFIC", \
475         "MESSAGE_3PTY", \
476         "MESSAGE_TRANSFER", \
477         "MESSAGE_DISABLE_DEJITTER", \
478 };
479
480
481 struct lcr_msg *message_create(int id_from, int id_to, int flow, int type);
482 #define message_put(m) _message_put(m, __FILE__, __LINE__)
483 void _message_put(struct lcr_msg *message, const char *file, int line);
484 struct lcr_msg *message_forward(int id_from, int id_to, int flow, union parameter *param);
485 struct lcr_msg *message_get(void);
486 void message_free(struct lcr_msg *message);
487 void init_message(void);
488 void cleanup_message(void);
489
490