1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
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_SS5 0x1300
22 #define PORT_CLASS_SIP 0x2000
23 #define PORT_CLASS_GSM 0x3000
24 #define PORT_CLASS_GSM_BS 0x3100
25 #define PORT_CLASS_GSM_MS 0x3200
26 #define PORT_CLASS_REMOTE 0x4000
27 #define PORT_CLASS_MASK 0xf000
28 #define PORT_CLASS_mISDN_MASK 0xff00
29 #define PORT_CLASS_DSS1_MASK 0xfff0
30 #define PORT_CLASS_GSM_MASK 0xff00
31 #define PORT_CLASS_DIR_MASK 0x000f
32 #define PORT_CLASS_DIR_IN 0x0001
33 #define PORT_CLASS_DIR_OUT 0x0002
35 #define PORT_TYPE_DSS1_NT_IN 0x1111
36 #define PORT_TYPE_DSS1_NT_OUT 0x1112
38 #define PORT_TYPE_DSS1_TE_IN 0x1121
39 #define PORT_TYPE_DSS1_TE_OUT 0x1122
41 #define PORT_TYPE_GSM_BS_IN 0x3101
42 #define PORT_TYPE_GSM_BS_OUT 0x3102
43 #define PORT_TYPE_GSM_MS_IN 0x3201
44 #define PORT_TYPE_GSM_MS_OUT 0x3202
46 #define PORT_TYPE_SS5_IN 0x1311
47 #define PORT_TYPE_SS5_OUT 0x1312
48 #define PORT_TYPE_SS5_IDLE 0x1313
50 #define PORT_TYPE_REMOTE_IN 0x4001
51 #define PORT_TYPE_REMOTE_OUT 0x4002
53 #define PORT_TYPE_SIP_IN 0x2001
54 #define PORT_TYPE_SIP_OUT 0x2002
55 /* answering machine */
56 #define PORT_TYPE_VBOX_OUT 0xf111
59 enum { /* states of call */
60 PORT_STATE_IDLE, /* no call */
61 PORT_STATE_IN_SETUP, /* incoming connection */
62 PORT_STATE_OUT_SETUP, /* outgoing connection */
63 PORT_STATE_IN_OVERLAP, /* more informatiopn needed */
64 PORT_STATE_OUT_OVERLAP, /* more informatiopn needed */
65 PORT_STATE_IN_PROCEEDING,/* call is proceeding */
66 PORT_STATE_OUT_PROCEEDING,/* call is proceeding */
67 PORT_STATE_IN_ALERTING, /* call is ringing */
68 PORT_STATE_OUT_ALERTING,/* call is ringing */
69 PORT_STATE_CONNECT_WAITING,/* connect is sent to the network, waiting for acknowledge */
70 PORT_STATE_CONNECT, /* call is connected and transmission is enabled */
71 PORT_STATE_IN_DISCONNECT,/* incoming disconnected */
72 PORT_STATE_OUT_DISCONNECT,/* outgoing disconnected */
73 PORT_STATE_RELEASE, /* call released */
76 #define PORT_STATE_NAMES \
77 static const char *state_name[] = { \
79 "PORT_STATE_IN_SETUP", \
80 "PORT_STATE_OUT_SETUP", \
81 "PORT_STATE_IN_OVERLAP", \
82 "PORT_STATE_OUT_OVERLAP", \
83 "PORT_STATE_IN_PROCEEDING", \
84 "PORT_STATE_OUT_PROCEEDING", \
85 "PORT_STATE_IN_ALERTING", \
86 "PORT_STATE_OUT_ALERTING", \
87 "PORT_STATE_CONNECT_WAITING", \
88 "PORT_STATE_CONNECT", \
89 "PORT_STATE_IN_DISCONNECT", \
90 "PORT_STATE_OUT_DISCONNECT", \
91 "PORT_STATE_RELEASE", \
95 enum { /* event list from listening to tty */
96 TTYI_EVENT_nodata, /* no data was received nor processed */
97 TTYI_EVENT_NONE, /* nothing happens */
98 TTYI_EVENT_CONNECT, /* a connection is made */
99 TTYI_EVENT_RING, /* incoming call */
100 TTYI_EVENT_CALLER, /* caller id information */
101 TTYI_EVENT_INFO, /* dialing information */
102 TTYI_EVENT_OVERLAP, /* setup complete, awaiting more dialing info */
103 TTYI_EVENT_PROC, /* proceeding */
104 TTYI_EVENT_ALRT, /* alerting */
105 TTYI_EVENT_CONN, /* connect */
106 TTYI_EVENT_DISC, /* disconnect */
107 TTYI_EVENT_RELE, /* release signal */
108 TTYI_EVENT_BUSY, /* channel unavailable */
111 #define RECORD_BUFFER_LENGTH 1024 // must be a binary border & must be greater 256, because 256 will be written if buffer overflows
112 #define RECORD_BUFFER_MASK 1023
114 #define PORT_TRANSMIT 256 // how much to transmit via bridge, if it is not defined by received data length
116 /* structure of epoint_list */
118 struct epoint_list *next;
119 unsigned int epoint_id;
123 inline unsigned int ACTIVE_EPOINT(struct epoint_list *epointlist)
127 if (epointlist->active)
128 return(epointlist->epoint_id);
129 epointlist = epointlist->next;
134 inline unsigned int INACTIVE_EPOINT(struct epoint_list *epointlist)
138 if (!epointlist->active)
139 return(epointlist->epoint_id);
140 epointlist = epointlist->next;
146 /* structure of port settings */
147 struct port_settings {
148 char tones_dir[256]; /* directory of current tone */
152 #define BRIDGE_BUFFER 4096
154 struct port_bridge_member {
155 struct port_bridge_member *next;
157 unsigned char buffer[BRIDGE_BUFFER];
158 int write_p; /* points to write position in buffer */
159 int min_space; /* minimum space to calculate how much delay can be removed */
162 /* port bridge instance */
164 struct port_bridge *next; /* next bridge node */
165 unsigned int bridge_id; /* unique ID to identify bridge */
166 struct port_bridge_member *first; /* list of ports that are bridged */
167 signed long sum_buffer[BRIDGE_BUFFER];
168 int read_p; /* points to read position in buffer */
169 struct lcr_timer timer; /* clock to transmit sum data */
170 int sample_count; /* counter of samples since last delay check */
173 extern struct port_bridge *p_bridge_first;
175 /* generic port class */
180 Port(int type, const char *portname, struct port_settings *settings, struct interface *interface);
182 class Port *next; /* next port in list */
183 int p_type; /* type of port */
184 virtual int message_epoint(unsigned int epoint_id, int message, union parameter *param);
185 virtual void set_echotest(int echotest);
186 virtual void set_tone(const char *dir, const char *name);
187 virtual int read_audio(unsigned char *buffer, int length);
188 virtual void update_load(void);
190 struct port_settings p_settings;
191 char p_interface_name[64];
194 char p_tone_dir[256]; /* name of current directory */
195 char p_tone_name[256]; /* name of current tone */
196 char p_tone_fh; /* file descriptor of current tone or -1 if not open */
197 void *p_tone_fetched; /* pointer to fetched data */
198 int p_tone_codec; /* codec that the tone is made of */
199 signed int p_tone_size, p_tone_left; /* size of tone in bytes (not samples), bytes left */
200 signed int p_tone_eof; /* flag that makes the use of eof message */
201 signed int p_tone_counter; /* flag that makes the use of counter message */
202 signed int p_tone_speed; /* speed of current tone, 1=normal, may also be negative */
203 // char p_knock_fh; /* file descriptor of knocking tone or -1 if not open */
204 // void *p_knock_fetched; /* pointer to fetched data */
205 // int p_knock_codec;
206 // signed int p_knock_size, p_knock_left;
207 void set_vbox_tone(const char *dir, const char *name);/* tone of answering machine */
208 void set_vbox_play(const char *name, int offset); /* sample of answ. */
209 void set_vbox_speed(int speed); /* speed of answ. */
212 unsigned int p_serial; /* serial unique id of port */
213 char p_name[128]; /* name of port or token (h323) */
215 /* endpoint relation */
216 struct epoint_list *p_epointlist; /* endpoint relation */
219 struct port_bridge *p_bridge; /* linked to a port bridge or NULL */
220 void bridge(unsigned int bridge_id); /* join a bridge */
221 int bridge_tx(unsigned char *data, int len); /* used to transmit data to remote port */
222 virtual int bridge_rx(unsigned char *data, int len); /* function to be inherited, so data is received */
225 int p_state; /* state of port */
226 void new_state(int state); /* set new state */
227 struct caller_info p_callerinfo; /* information about the caller */
228 struct dialing_info p_dialinginfo; /* information about dialing */
229 struct connect_info p_connectinfo; /* information about connected line */
230 struct redir_info p_redirinfo; /* info on redirection (to the calling user) */
231 struct capa_info p_capainfo; /* info on l2,l3 capacity */
232 int p_echotest; /* set to echo audio data FROM port back to port's mixer */
234 /* recording/tapping */
235 int open_record(int type, int mode, int skip, char *terminal, int anon_ignore, const char *vbox_email, int vbox_email_file);
236 void close_record(int beep, int mute);
237 void record(unsigned char *data, int length, int dir_fromup);
238 void tap(unsigned char *data, int length, int dir_fromup);
239 FILE *p_record; /* recording fp: if not NULL, recording is enabled */
240 unsigned int p_tap; /* enpoint to send tapping audio to */
241 int p_record_type; /* codec to use: RECORD_MONO, RECORD_STEREO, ... */
242 int p_record_skip; /* skip bytes before writing the sample */
243 unsigned int p_record_length; /* size of what's written so far */
245 signed short p_record_buffer[RECORD_BUFFER_LENGTH];
246 unsigned int p_record_buffer_readp;
247 unsigned int p_record_buffer_writep;
248 int p_record_buffer_dir; /* current direction in buffer */
250 char p_record_filename[256]; /* record filename */
251 int p_record_vbox; /* 0= normal recording, 1= announcement, 2= record to vbox dir */
252 int p_record_vbox_year; /* time when vbox recording started */
253 int p_record_vbox_mon;
254 int p_record_vbox_mday;
255 int p_record_vbox_hour;
256 int p_record_vbox_min;
257 char p_record_extension[32]; /* current name (digits) of extension */
258 int p_record_anon_ignore;
259 char p_record_vbox_email[128];
260 int p_record_vbox_email_file;
261 virtual void update_rxoff(void); /* inherited by mISDNport, to control rxoff */
263 void free_epointlist(struct epoint_list *epointlist);
264 void free_epointid(unsigned int epoint_id);
265 struct epoint_list *epointlist_new(unsigned int epoint_id);
269 extern Port *port_first;
270 extern unsigned int port_serial;
272 class Port *find_port_with_token(char *name);
273 class Port *find_port_id(unsigned int port_id);
276 #endif // PORT_HEADER