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