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