1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
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_MASK 0xfff0
23 #define PORT_TYPE_DSS1_NT_IN 0x0111
24 #define PORT_TYPE_DSS1_NT_OUT 0x0112
26 #define PORT_TYPE_DSS1_TE_IN 0x0113
27 #define PORT_TYPE_DSS1_TE_OUT 0x0114
29 #define PORT_TYPE_GSM_IN 0x0121
30 #define PORT_TYPE_GSM_OUT 0x0122
31 /* answering machine */
32 #define PORT_TYPE_VBOX_OUT 0x0311
35 enum { /* states of call */
36 PORT_STATE_IDLE, /* no call */
37 PORT_STATE_IN_SETUP, /* incoming connection */
38 PORT_STATE_OUT_SETUP, /* outgoing connection */
39 PORT_STATE_IN_OVERLAP, /* more informatiopn needed */
40 PORT_STATE_OUT_OVERLAP, /* more informatiopn needed */
41 PORT_STATE_IN_PROCEEDING,/* call is proceeding */
42 PORT_STATE_OUT_PROCEEDING,/* call is proceeding */
43 PORT_STATE_IN_ALERTING, /* call is ringing */
44 PORT_STATE_OUT_ALERTING,/* call is ringing */
45 PORT_STATE_CONNECT_WAITING,/* connect is sent to the network, waiting for acknowledge */
46 PORT_STATE_CONNECT, /* call is connected and transmission is enabled */
47 PORT_STATE_IN_DISCONNECT,/* incoming disconnected */
48 PORT_STATE_OUT_DISCONNECT,/* outgoing disconnected */
49 PORT_STATE_RELEASE, /* call released */
52 #define PORT_STATE_NAMES \
53 static const char *state_name[] = { \
55 "PORT_STATE_IN_SETUP", \
56 "PORT_STATE_OUT_SETUP", \
57 "PORT_STATE_IN_OVERLAP", \
58 "PORT_STATE_OUT_OVERLAP", \
59 "PORT_STATE_IN_PROCEEDING", \
60 "PORT_STATE_OUT_PROCEEDING", \
61 "PORT_STATE_IN_ALERTING", \
62 "PORT_STATE_OUT_ALERTING", \
63 "PORT_STATE_CONNECT_WAITING", \
64 "PORT_STATE_CONNECT", \
65 "PORT_STATE_IN_DISCONNECT", \
66 "PORT_STATE_OUT_DISCONNECT", \
67 "PORT_STATE_RELEASE", \
71 enum { /* event list from listening to tty */
72 TTYI_EVENT_nodata, /* no data was received nor processed */
73 TTYI_EVENT_NONE, /* nothing happens */
74 TTYI_EVENT_CONNECT, /* a connection is made */
75 TTYI_EVENT_RING, /* incoming call */
76 TTYI_EVENT_CALLER, /* caller id information */
77 TTYI_EVENT_INFO, /* dialing information */
78 TTYI_EVENT_OVERLAP, /* setup complete, awaiting more dialing info */
79 TTYI_EVENT_PROC, /* proceeding */
80 TTYI_EVENT_ALRT, /* alerting */
81 TTYI_EVENT_CONN, /* connect */
82 TTYI_EVENT_DISC, /* disconnect */
83 TTYI_EVENT_RELE, /* release signal */
84 TTYI_EVENT_BUSY, /* channel unavailable */
87 #define RECORD_BUFFER_LENGTH 1024 // must be a binary border & must be greater 256, because 256 will be written if buffer overflows
88 #define RECORD_BUFFER_MASK 1023
90 /* structure of epoint_list */
92 struct epoint_list *next;
93 unsigned int epoint_id;
97 inline unsigned int ACTIVE_EPOINT(struct epoint_list *epointlist)
101 if (epointlist->active)
102 return(epointlist->epoint_id);
103 epointlist = epointlist->next;
108 inline unsigned int INACTIVE_EPOINT(struct epoint_list *epointlist)
112 if (!epointlist->active)
113 return(epointlist->epoint_id);
114 epointlist = epointlist->next;
120 /* structure of port settings */
121 struct port_settings {
122 char tones_dir[256]; /* directory of current tone */
126 /* generic port class */
131 Port(int type, const char *portname, struct port_settings *settings);
133 class Port *next; /* next port in list */
134 int p_type; /* type of port */
135 virtual int handler(void);
136 virtual int message_epoint(unsigned int epoint_id, int message, union parameter *param);
137 virtual void set_echotest(int echotest);
138 virtual void set_tone(const char *dir, const char *name);
139 virtual int read_audio(unsigned char *buffer, int length);
141 struct port_settings p_settings;
144 char p_tone_dir[256]; /* name of current directory */
145 char p_tone_name[256]; /* name of current tone */
146 char p_tone_fh; /* file descriptor of current tone or -1 if not open */
147 void *p_tone_fetched; /* pointer to fetched data */
148 int p_tone_codec; /* codec that the tone is made of */
149 signed int p_tone_size, p_tone_left; /* size of tone in bytes (not samples), bytes left */
150 signed int p_tone_eof; /* flag that makes the use of eof message */
151 signed int p_tone_counter; /* flag that makes the use of counter message */
152 signed int p_tone_speed; /* speed of current tone, 1=normal, may also be negative */
153 // char p_knock_fh; /* file descriptor of knocking tone or -1 if not open */
154 // void *p_knock_fetched; /* pointer to fetched data */
155 // int p_knock_codec;
156 // signed int p_knock_size, p_knock_left;
157 void set_vbox_tone(const char *dir, const char *name);/* tone of answering machine */
158 void set_vbox_play(const char *name, int offset); /* sample of answ. */
159 void set_vbox_speed(int speed); /* speed of answ. */
162 unsigned int p_serial; /* serial unique id of port */
163 char p_name[128]; /* name of port or token (h323) */
165 /* endpoint relation */
166 struct epoint_list *p_epointlist; /* endpoint relation */
169 int p_state; /* state of port */
170 void new_state(int state); /* set new state */
171 struct caller_info p_callerinfo; /* information about the caller */
172 struct dialing_info p_dialinginfo; /* information about dialing */
173 struct connect_info p_connectinfo; /* information about connected line */
174 struct redir_info p_redirinfo; /* info on redirection (to the calling user) */
175 struct capa_info p_capainfo; /* info on l2,l3 capacity */
176 int p_echotest; /* set to echo audio data FROM port back to port's mixer */
179 int open_record(int type, int mode, int skip, char *terminal, int anon_ignore, const char *vbox_email, int vbox_email_file);
180 void close_record(int beep, int mute);
181 void record(unsigned char *data, int length, int dir_fromup);
182 FILE *p_record; /* recording fp: if not NULL, recording is enabled */
183 int p_record_type; /* codec to use: RECORD_MONO, RECORD_STEREO, ... */
184 int p_record_skip; /* skip bytes before writing the sample */
185 unsigned int p_record_length; /* size of what's written so far */
187 signed short p_record_buffer[RECORD_BUFFER_LENGTH];
188 unsigned int p_record_buffer_readp;
189 unsigned int p_record_buffer_writep;
190 int p_record_buffer_dir; /* current direction in buffer */
192 char p_record_filename[256]; /* record filename */
193 int p_record_vbox; /* 0= normal recording, 1= announcement, 2= record to vbox dir */
194 int p_record_vbox_year; /* time when vbox recording started */
195 int p_record_vbox_mon;
196 int p_record_vbox_mday;
197 int p_record_vbox_hour;
198 int p_record_vbox_min;
199 char p_record_extension[32]; /* current name (digits) of extension */
200 int p_record_anon_ignore;
201 char p_record_vbox_email[128];
202 int p_record_vbox_email_file;
204 void free_epointlist(struct epoint_list *epointlist);
205 void free_epointid(unsigned int epoint_id);
206 struct epoint_list *epointlist_new(unsigned int epoint_id);
210 extern Port *port_first;
211 extern unsigned int port_serial;
213 class Port *find_port_with_token(char *name);
214 class Port *find_port_id(unsigned int port_id);
217 #endif // PORT_HEADER