5e8eba9a8b5f189a3d61075fd479d80777582840
[lcr.git] / port.h
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** port header file                                                          **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #ifndef PORT_HEADER
13 #define PORT_HEADER
14
15 /* type of port */
16 #define PORT_TYPE_NULL          0x0000
17 #define PORT_CLASS_mISDN        0x0100
18 #define PORT_CLASS_MASK         0xff00
19 #define PORT_CLASS_mISDN_DSS1   0x0110
20 #define PORT_CLASS_mISDN_GSM    0x0120
21 #define PORT_CLASS_mISDN_SS5    0x0130
22 #define PORT_CLASS_mISDN_MASK   0xfff0
23         /* nt-mode */
24 #define PORT_TYPE_DSS1_NT_IN    0x0111
25 #define PORT_TYPE_DSS1_NT_OUT   0x0112
26         /* te-mode */
27 #define PORT_TYPE_DSS1_TE_IN    0x0113
28 #define PORT_TYPE_DSS1_TE_OUT   0x0114
29         /* gsm */
30 #define PORT_TYPE_GSM_IN        0x0121
31 #define PORT_TYPE_GSM_OUT       0x0122
32         /* ss5 */
33 #define PORT_TYPE_SS5_IN        0x0131
34 #define PORT_TYPE_SS5_OUT       0x0132
35 #define PORT_TYPE_SS5_IDLE      0x0133
36         /* answering machine */
37 #define PORT_TYPE_VBOX_OUT      0x0311
38
39
40 enum { /* states of call */
41         PORT_STATE_IDLE,        /* no call */
42         PORT_STATE_IN_SETUP,    /* incoming connection */
43         PORT_STATE_OUT_SETUP,   /* outgoing connection */
44         PORT_STATE_IN_OVERLAP,  /* more informatiopn needed */
45         PORT_STATE_OUT_OVERLAP, /* more informatiopn needed */
46         PORT_STATE_IN_PROCEEDING,/* call is proceeding */
47         PORT_STATE_OUT_PROCEEDING,/* call is proceeding */
48         PORT_STATE_IN_ALERTING, /* call is ringing */
49         PORT_STATE_OUT_ALERTING,/* call is ringing */
50         PORT_STATE_CONNECT_WAITING,/* connect is sent to the network, waiting for acknowledge */
51         PORT_STATE_CONNECT,     /* call is connected and transmission is enabled */
52         PORT_STATE_IN_DISCONNECT,/* incoming disconnected */
53         PORT_STATE_OUT_DISCONNECT,/* outgoing disconnected */
54         PORT_STATE_RELEASE,     /* call released */
55 };
56
57 #define PORT_STATE_NAMES \
58 static const char *state_name[] = { \
59         "PORT_STATE_IDLE", \
60         "PORT_STATE_IN_SETUP", \
61         "PORT_STATE_OUT_SETUP", \
62         "PORT_STATE_IN_OVERLAP", \
63         "PORT_STATE_OUT_OVERLAP", \
64         "PORT_STATE_IN_PROCEEDING", \
65         "PORT_STATE_OUT_PROCEEDING", \
66         "PORT_STATE_IN_ALERTING", \
67         "PORT_STATE_OUT_ALERTING", \
68         "PORT_STATE_CONNECT_WAITING", \
69         "PORT_STATE_CONNECT", \
70         "PORT_STATE_IN_DISCONNECT", \
71         "PORT_STATE_OUT_DISCONNECT", \
72         "PORT_STATE_RELEASE", \
73 };
74
75
76 enum { /* event list from listening to tty */
77         TTYI_EVENT_nodata,      /* no data was received nor processed */
78         TTYI_EVENT_NONE,        /* nothing happens */
79         TTYI_EVENT_CONNECT,     /* a connection is made */
80         TTYI_EVENT_RING,        /* incoming call */
81         TTYI_EVENT_CALLER,      /* caller id information */
82         TTYI_EVENT_INFO,        /* dialing information */
83         TTYI_EVENT_OVERLAP,     /* setup complete, awaiting more dialing info */
84         TTYI_EVENT_PROC,        /* proceeding */
85         TTYI_EVENT_ALRT,        /* alerting */
86         TTYI_EVENT_CONN,        /* connect */
87         TTYI_EVENT_DISC,        /* disconnect */
88         TTYI_EVENT_RELE,        /* release signal */
89         TTYI_EVENT_BUSY,        /* channel unavailable */
90 };
91
92 #define RECORD_BUFFER_LENGTH    1024 // must be a binary border & must be greater 256, because 256 will be written if buffer overflows
93 #define RECORD_BUFFER_MASK      1023
94
95 /* structure of epoint_list */
96 struct epoint_list {
97         struct epoint_list      *next;
98         unsigned int            epoint_id;
99         int                     active;
100 };
101
102 inline unsigned int ACTIVE_EPOINT(struct epoint_list *epointlist)
103 {
104         while(epointlist)
105         {
106                 if (epointlist->active)
107                         return(epointlist->epoint_id);
108                 epointlist = epointlist->next;
109         }
110         return(0);
111 }
112
113 inline unsigned int INACTIVE_EPOINT(struct epoint_list *epointlist)
114 {
115         while(epointlist)
116         {
117                 if (!epointlist->active)
118                         return(epointlist->epoint_id);
119                 epointlist = epointlist->next;
120         }
121         return(0);
122 }
123
124
125 /* structure of port settings */
126 struct port_settings {
127         char tones_dir[256];                    /* directory of current tone */
128         int no_seconds;
129 };
130
131 /* generic port class */
132 class Port
133 {
134         public:
135         /* methods */
136         Port(int type, const char *portname, struct port_settings *settings);
137         virtual ~Port();
138         class Port *next;                       /* next port in list */
139         int p_type;                             /* type of port */
140         virtual int handler(void);
141         virtual int message_epoint(unsigned int epoint_id, int message, union parameter *param);
142         virtual void set_echotest(int echotest);
143         virtual void set_tone(const char *dir, const char *name);
144         virtual int read_audio(unsigned char *buffer, int length);
145
146         struct port_settings p_settings;
147         
148         /* tone */
149         char p_tone_dir[256];                   /* name of current directory */
150         char p_tone_name[256];                  /* name of current tone */
151         char p_tone_fh;                         /* file descriptor of current tone or -1 if not open */
152         void *p_tone_fetched;                   /* pointer to fetched data */
153         int p_tone_codec;                       /* codec that the tone is made of */
154         signed int p_tone_size, p_tone_left;    /* size of tone in bytes (not samples), bytes left */
155         signed int p_tone_eof;                  /* flag that makes the use of eof message */
156         signed int p_tone_counter;              /* flag that makes the use of counter message */
157         signed int p_tone_speed;                /* speed of current tone, 1=normal, may also be negative */
158 //      char p_knock_fh;                        /* file descriptor of knocking tone or -1 if not open */
159 //      void *p_knock_fetched;                  /* pointer to fetched data */
160 //      int p_knock_codec;
161 //      signed int p_knock_size, p_knock_left;
162         void set_vbox_tone(const char *dir, const char *name);/* tone of answering machine */
163         void set_vbox_play(const char *name, int offset); /* sample of answ. */
164         void set_vbox_speed(int speed); /* speed of answ. */
165
166         /* identification */
167         unsigned int p_serial;                  /* serial unique id of port */
168         char p_name[128];                       /* name of port or token (h323) */
169
170         /* endpoint relation */
171         struct epoint_list *p_epointlist;       /* endpoint relation */
172
173         /* state */
174         int p_state;                            /* state of port */
175         void new_state(int state);              /* set new state */
176         struct caller_info p_callerinfo;        /* information about the caller */
177         struct dialing_info p_dialinginfo;      /* information about dialing */
178         struct connect_info p_connectinfo;      /* information about connected line */
179         struct redir_info p_redirinfo;          /* info on redirection (to the calling user) */
180         struct capa_info p_capainfo;    /* info on l2,l3 capacity */
181         int p_echotest;                         /* set to echo audio data FROM port back to port's mixer */
182
183         /* recording */
184         int open_record(int type, int mode, int skip, char *terminal, int anon_ignore, const char *vbox_email, int vbox_email_file);
185         void close_record(int beep, int mute);
186         void record(unsigned char *data, int length, int dir_fromup);
187         FILE *p_record;                         /* recording fp: if not NULL, recording is enabled */
188         int p_record_type;                      /* codec to use: RECORD_MONO, RECORD_STEREO, ... */
189         int p_record_skip;                      /* skip bytes before writing the sample */
190         unsigned int p_record_length;           /* size of what's written so far */
191
192         signed short p_record_buffer[RECORD_BUFFER_LENGTH];
193         unsigned int p_record_buffer_readp;
194         unsigned int p_record_buffer_writep;
195         int p_record_buffer_dir;                /* current direction in buffer */
196
197         char p_record_filename[256];            /* record filename */
198         int p_record_vbox;                      /* 0= normal recording, 1= announcement, 2= record to vbox dir */
199         int p_record_vbox_year;                 /* time when vbox recording started */
200         int p_record_vbox_mon;
201         int p_record_vbox_mday;
202         int p_record_vbox_hour;
203         int p_record_vbox_min;
204         char p_record_extension[32];            /* current name (digits) of extension */
205         int p_record_anon_ignore;
206         char p_record_vbox_email[128];
207         int p_record_vbox_email_file;
208
209         void free_epointlist(struct epoint_list *epointlist);
210         void free_epointid(unsigned int epoint_id);
211         struct epoint_list *epointlist_new(unsigned int epoint_id);
212 };
213
214
215 extern Port *port_first;
216 extern unsigned int port_serial;
217
218 class Port *find_port_with_token(char *name);
219 class Port *find_port_id(unsigned int port_id);
220
221
222 #endif // PORT_HEADER
223
224