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