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_REMOTE 0x1400
23 #define PORT_CLASS_SIP 0x2000
24 #define PORT_CLASS_GSM 0x3000
25 #define PORT_CLASS_GSM_BS 0x3100
26 #define PORT_CLASS_GSM_MS 0x3200
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 0x1411
51 #define PORT_TYPE_REMOTE_OUT 0x1412
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 /* port bridge instance */
154 struct port_bridge *next; /* next bridge node */
155 unsigned int bridge_id; /* unique ID to identify bridge */
156 class Port *sunrise; /* one side of the bridge */
157 class Port *sunset; /* other side of the bridge */
160 extern struct port_bridge *p_bridge_first;
162 /* generic port class */
167 Port(int type, const char *portname, struct port_settings *settings);
169 class Port *next; /* next port in list */
170 int p_type; /* type of port */
171 virtual int message_epoint(unsigned int epoint_id, int message, union parameter *param);
172 virtual void set_echotest(int echotest);
173 virtual void set_tone(const char *dir, const char *name);
174 virtual int read_audio(unsigned char *buffer, int length);
175 virtual void update_load(void);
177 struct port_settings p_settings;
180 char p_tone_dir[256]; /* name of current directory */
181 char p_tone_name[256]; /* name of current tone */
182 char p_tone_fh; /* file descriptor of current tone or -1 if not open */
183 void *p_tone_fetched; /* pointer to fetched data */
184 int p_tone_codec; /* codec that the tone is made of */
185 signed int p_tone_size, p_tone_left; /* size of tone in bytes (not samples), bytes left */
186 signed int p_tone_eof; /* flag that makes the use of eof message */
187 signed int p_tone_counter; /* flag that makes the use of counter message */
188 signed int p_tone_speed; /* speed of current tone, 1=normal, may also be negative */
189 // char p_knock_fh; /* file descriptor of knocking tone or -1 if not open */
190 // void *p_knock_fetched; /* pointer to fetched data */
191 // int p_knock_codec;
192 // signed int p_knock_size, p_knock_left;
193 void set_vbox_tone(const char *dir, const char *name);/* tone of answering machine */
194 void set_vbox_play(const char *name, int offset); /* sample of answ. */
195 void set_vbox_speed(int speed); /* speed of answ. */
198 unsigned int p_serial; /* serial unique id of port */
199 char p_name[128]; /* name of port or token (h323) */
201 /* endpoint relation */
202 struct epoint_list *p_epointlist; /* endpoint relation */
205 struct port_bridge *p_bridge; /* linked to a port bridge or NULL */
206 void bridge(unsigned int bridge_id); /* join a bridge */
207 class Port *bridge_remote(void); /* get remote port */
208 int bridge_tx(unsigned char *data, int len); /* used to transmit data to remote port */
209 virtual int bridge_rx(unsigned char *data, int len); /* function to be inherited, so data is received */
212 int p_state; /* state of port */
213 void new_state(int state); /* set new state */
214 struct caller_info p_callerinfo; /* information about the caller */
215 struct dialing_info p_dialinginfo; /* information about dialing */
216 struct connect_info p_connectinfo; /* information about connected line */
217 struct redir_info p_redirinfo; /* info on redirection (to the calling user) */
218 struct capa_info p_capainfo; /* info on l2,l3 capacity */
219 int p_echotest; /* set to echo audio data FROM port back to port's mixer */
222 int open_record(int type, int mode, int skip, char *terminal, int anon_ignore, const char *vbox_email, int vbox_email_file);
223 void close_record(int beep, int mute);
224 void record(unsigned char *data, int length, int dir_fromup);
225 FILE *p_record; /* recording fp: if not NULL, recording is enabled */
226 int p_record_type; /* codec to use: RECORD_MONO, RECORD_STEREO, ... */
227 int p_record_skip; /* skip bytes before writing the sample */
228 unsigned int p_record_length; /* size of what's written so far */
230 signed short p_record_buffer[RECORD_BUFFER_LENGTH];
231 unsigned int p_record_buffer_readp;
232 unsigned int p_record_buffer_writep;
233 int p_record_buffer_dir; /* current direction in buffer */
235 char p_record_filename[256]; /* record filename */
236 int p_record_vbox; /* 0= normal recording, 1= announcement, 2= record to vbox dir */
237 int p_record_vbox_year; /* time when vbox recording started */
238 int p_record_vbox_mon;
239 int p_record_vbox_mday;
240 int p_record_vbox_hour;
241 int p_record_vbox_min;
242 char p_record_extension[32]; /* current name (digits) of extension */
243 int p_record_anon_ignore;
244 char p_record_vbox_email[128];
245 int p_record_vbox_email_file;
246 virtual void update_rxoff(void); /* inherited by mISDNport, to control rxoff */
248 void free_epointlist(struct epoint_list *epointlist);
249 void free_epointid(unsigned int epoint_id);
250 struct epoint_list *epointlist_new(unsigned int epoint_id);
254 extern Port *port_first;
255 extern unsigned int port_serial;
257 class Port *find_port_with_token(char *name);
258 class Port *find_port_id(unsigned int port_id);
261 #endif // PORT_HEADER