1 /*****************************************************************************\
3 ** Linux Call Router **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** EndpointAppPBX header file **
10 \*****************************************************************************/
13 enum { /* release actions: see epoint.release */
15 RELEASE_JOIN, /* join, hold */
16 RELEASE_PORT_JOINONLY, /* join, port */
17 RELEASE_ALL, /* join, hold, port */
20 enum { /* states as viewed from io port (state of calls are always connected) */
21 EPOINT_STATE_IDLE, /* no call */
22 EPOINT_STATE_IN_SETUP, /* setup sent */
23 EPOINT_STATE_OUT_SETUP, /* setup sent */
24 EPOINT_STATE_IN_OVERLAP, /* more information */
25 EPOINT_STATE_OUT_OVERLAP, /* more information */
26 EPOINT_STATE_IN_PROCEEDING, /* proceeding */
27 EPOINT_STATE_OUT_PROCEEDING, /* proceeding */
28 EPOINT_STATE_IN_ALERTING, /* ringing */
29 EPOINT_STATE_OUT_ALERTING, /* ringing */
30 EPOINT_STATE_CONNECT, /* connected */
31 EPOINT_STATE_IN_DISCONNECT, /* disconnected receiving tones */
32 EPOINT_STATE_OUT_DISCONNECT, /* disconnected sending tones */
35 #define EPOINT_STATE_NAMES \
36 static const char *state_name[] = { \
37 "EPOINT_STATE_IDLE", \
38 "EPOINT_STATE_IN_SETUP", \
39 "EPOINT_STATE_OUT_SETUP", \
40 "EPOINT_STATE_IN_OVERLAP", \
41 "EPOINT_STATE_OUT_OVERLAP", \
42 "EPOINT_STATE_IN_PROCEEDING", \
43 "EPOINT_STATE_OUT_PROCEEDING", \
44 "EPOINT_STATE_IN_ALERTING", \
45 "EPOINT_STATE_OUT_ALERTING", \
46 "EPOINT_STATE_CONNECT", \
47 "EPOINT_STATE_IN_DISCONNECT", \
48 "EPOINT_STATE_OUT_DISCONNECT", \
50 int state_name_num = sizeof(state_name) / sizeof(char *);
52 int vbox_refresh(struct lcr_timer *timer, void *instance, int index);
54 extern class EndpointAppPBX *apppbx_first;
56 /* structure of an EndpointAppPBX */
57 class EndpointAppPBX : public EndpointApp
60 EndpointAppPBX(class Endpoint *epoint, int origin);
63 class EndpointAppPBX *next;
65 int e_hold; /* is this endpoint on hold ? */
66 char e_tone[256]; /* save tone for resuming ports */
68 unsigned int e_adminid;
71 int e_state; /* state of endpoint */
72 char e_extension_interface[32];/* current internal isdn interface (usefull for callback to internal phone) */
73 struct caller_info e_callerinfo; /* information about the caller */
74 struct dialing_info e_dialinginfo; /* information about dialing */
75 struct connect_info e_connectinfo; /* information about connected line */
76 struct redir_info e_redirinfo; /* info on redirection (to the calling user) */
77 struct capa_info e_capainfo; /* info on l3,l2 capacity */
78 time_t e_start, e_stop; /* time */
79 int e_origin; /* origin of call 0=incoming 1=outgoing */
80 struct route_ruleset *e_ruleset; /* current ruleset pointer (NULL=no ruleset) */
81 struct route_rule *e_rule; /* current rule pointer (NULL=no rule) */
82 struct route_action *e_action; /* current action pointer (NULL=no action) */
83 int e_rule_nesting; /* 'goto'/'menu' recrusion counter to prevent infinie loops */
84 struct route_action *e_match_to_action; /* what todo when timeout */
85 char *e_match_to_extdialing; /* dialing after matching timeout rule */
86 int e_select; /* current selection for various selector options */
87 char *e_extdialing; /* dialing after matching rule */
88 int e_overlap; /* is set if additional information is/are received after setup */
89 struct extension e_ext; /* extension information */
91 // int e_knocking; /* true, if knocking */
92 // double e_knocktime; /* next time to knock */
94 // char e_join_tone[64], e_hold_tone[64]; /* current tone */
95 int e_join_pattern/*, e_hold_pattern*/; /* pattern available */
98 char e_dialing_queue[32]; /* holds dialing during setup state */
99 double e_powerdelay; /* delay when to redial */
100 int e_powercount; /* power count */
101 int e_powerlimit; /* power limit */
102 struct lcr_timer e_action_timeout;
103 struct lcr_timer e_match_timeout;
106 int e_multipoint_cause; /* cause value of disconnected multiport calls (highest priority) */
107 int e_multipoint_location; /* location of cause with highest priority */
114 char e_cbdialing[256]; /* dialing information after callback */
115 char e_cbcaller[256]; /* extension for the epoint which calls back */
116 char e_cbto[32]; /* override callerid to call back to */
117 struct caller_info e_callbackinfo; /* information about the callback caller */
118 struct lcr_timer e_redial_timeout;
120 struct lcr_timer e_powerdial_timeout;
121 struct lcr_timer e_cfnr_timeout;
122 struct lcr_timer e_cfnr_call_timeout;
123 struct lcr_timer e_callback_timeout;
124 struct lcr_timer e_password_timeout;
127 int e_connectedmode; /* if the port should stay connected if the enpoint disconnects or releases (usefull for callback) */
128 int e_dtmf; /* allow dtmf */
129 /* read doc/keypad.txt for more information */
130 int e_dtmf_time; /* time when the last key was received. */
131 int e_dtmf_last; /* last dtmf key */
132 int e_enablekeypad; /* remote app requests dtmf */
134 /* transmit and receive state */
135 int e_tx_state; /* current endpoint's state */
136 int e_rx_state; /* current endpoint's state */
138 /* vbox playback variables */
139 char e_vbox[32]; /* current vbox extension (during playback) */
140 int e_vbox_state; /* state of vbox during playback */
141 int e_vbox_menu; /* currently selected menu using '*' and '#' */
142 char e_vbox_display[128]; /* current display message */
143 struct lcr_timer e_vbox_refresh; /* display must be refreshed du to change */
144 int e_vbox_counter; /* current playback counter in seconds */
145 int e_vbox_counter_max; /* size of file in seconds */
146 int e_vbox_counter_last; /* temp variable to recognise a change in seconds */
147 int e_vbox_play; /* current file that is played */
148 int e_vbox_speed; /* current speed to play */
149 int e_vbox_index_num; /* number of files */
150 char e_vbox_index_file[128]; /* current file name */
151 int e_vbox_index_hour; /* current time the file recorded... */
152 int e_vbox_index_min;
153 int e_vbox_index_mon;
154 int e_vbox_index_mday;
155 int e_vbox_index_year;
156 char e_vbox_index_callerid[128]; /* current caller id */
157 int e_vbox_index_callerid_index; /* next digit to speak */
160 int e_efi_state; /* current spoken sample */
161 int e_efi_digit; /* current spoken digit */
163 /* crypt states and vars */
164 int e_crypt; /* current user level crypt state */
165 int e_crypt_state; /* current crypt manager state */
166 char e_crypt_info[33]; /* last information text */
167 int e_crypt_timeout_sec; /* timer */
168 int e_crypt_timeout_usec; /* timer */
169 unsigned int e_crypt_random; /* current random number for ident */
170 unsigned int e_crypt_bogomips; /* bogomips for ident */
171 unsigned char e_crypt_key[256]; /* the session key */
173 unsigned char e_crypt_ckey[256]; /* the encrypted session key */
174 int e_crypt_ckey_len;
175 unsigned char e_crypt_rsa_n[512]; /* rsa key */
176 unsigned char e_crypt_rsa_e[16];
177 unsigned char e_crypt_rsa_d[512];
178 unsigned char e_crypt_rsa_p[512];
179 unsigned char e_crypt_rsa_q[512];
180 unsigned char e_crypt_rsa_dmp1[512];
181 unsigned char e_crypt_rsa_dmq1[512];
182 unsigned char e_crypt_rsa_iqmp[512];
183 int e_crypt_rsa_n_len;
184 int e_crypt_rsa_e_len;
185 int e_crypt_rsa_d_len;
186 int e_crypt_rsa_p_len;
187 int e_crypt_rsa_q_len;
188 int e_crypt_rsa_dmp1_len;
189 int e_crypt_rsa_dmq1_len;
190 int e_crypt_rsa_iqmp_len;
191 int e_crypt_keyengine_busy; /* current job and busy state */
192 int e_crypt_keyengine_return; /* return */
193 struct lcr_timer e_crypt_handler; /* poll timer for crypt events */
196 void hookflash(void);
197 void ea_message_port(unsigned int port_id, int message, union parameter *param);
198 void port_setup(struct port_list *portlist, int message_type, union parameter *param);
199 void port_information(struct port_list *portlist, int message_type, union parameter *param);
200 void port_dtmf(struct port_list *portlist, int message_type, union parameter *param);
201 void port_crypt(struct port_list *portlist, int message_type, union parameter *param);
202 void port_overlap(struct port_list *portlist, int message_type, union parameter *param);
203 void port_proceeding(struct port_list *portlist, int message_type, union parameter *param);
204 void port_alerting(struct port_list *portlist, int message_type, union parameter *param);
205 void port_connect(struct port_list *portlist, int message_type, union parameter *param);
206 void port_disconnect_release(struct port_list *portlist, int message_type, union parameter *param);
207 void port_timeout(struct port_list *portlist, int message_type, union parameter *param);
208 void port_notify(struct port_list *portlist, int message_type, union parameter *param);
209 void port_progress(struct port_list *portlist, int message_type, union parameter *param);
210 void port_facility(struct port_list *portlist, int message_type, union parameter *param);
211 void port_suspend(struct port_list *portlist, int message_type, union parameter *param);
212 void port_resume(struct port_list *portlist, int message_type, union parameter *param);
213 void ea_message_join(unsigned int join_id, int message, union parameter *param);
214 void join_crypt(struct port_list *portlist, int message_type, union parameter *param);
215 void join_mISDNsignal(struct port_list *portlist, int message_type, union parameter *param);
216 void join_setup(struct port_list *portlist, int message_type, union parameter *param);
217 void join_information(struct port_list *portlist, int message_type, union parameter *param);
218 void join_overlap(struct port_list *portlist, int message_type, union parameter *param);
219 void join_proceeding(struct port_list *portlist, int message_type, union parameter *param);
220 void join_alerting(struct port_list *portlist, int message_type, union parameter *param);
221 void join_connect(struct port_list *portlist, int message_type, union parameter *param);
222 void join_disconnect_release(int message_type, union parameter *param);
223 void join_notify(struct port_list *portlist, int message_type, union parameter *param);
224 void join_facility(struct port_list *portlist, int message_type, union parameter *param);
227 void new_state(int state);
228 void release(int release, int joinlocation, int joincause, int portlocation, int portcause, int force);
229 void notify_active(void);
230 void keypad_function(char digit);
231 void set_tone(struct port_list *portlist, const char *tone);
232 void out_setup(void);
233 struct mISDNport *hunt_port(char *ifname, int *channel);
234 char *apply_callerid_display(const char *id, int itype, int ntype, int present, int screen, const char *extension, const char *name);
235 void auth(int job, int bit_num);
237 /* vbox playback stuff */
238 void vbox_init(void);
239 void vbox_index_read(int num);
240 void vbox_index_remove(int num);
241 void efi_message_eof(void);
242 void vbox_message_eof(void);
243 void set_tone_vbox(const char *tone);
244 void set_play_vbox(const char *file, int offset);
245 void set_play_speed(int speed);
248 void set_tone_efi(const char *tone);
251 struct route_ruleset *rulesetbyname(char *name);
252 struct route_action *route(struct route_ruleset *ruleset);
253 struct route_param *routeparam(struct route_action *action, unsigned long long id);
255 /* init / dialing / hangup */
256 int _action_init_call(char *remote);
257 void action_init_call(void);
258 void action_init_remote(void);
259 void action_dialing_internal(void);
260 void action_dialing_external(void);
261 void action_dialing_h323(void);
262 void action_dialing_remote(void);
263 void action_dialing_vbox_record(void);
264 void action_init_partyline(void);
265 void action_hangup_call(void);
266 void action_dialing_login(void);
267 void action_init_change_callerid(void);
268 void _action_callerid_calleridnext(int next);
269 void action_dialing_callerid(void);
270 void action_dialing_calleridnext(void);
271 void action_init_change_forward(void);
272 void action_dialing_forward(void);
273 void action_init_redial_reply(void);
274 void _action_redial_reply(int in);
275 void action_dialing_redial(void);
276 void action_dialing_reply(void);
277 void action_dialing_powerdial(void);
278 void action_dialing_callback(void);
279 void action_hangup_callback(void);
280 void action_dialing_abbrev(void);
281 void action_dialing_test(void);
282 void action_init_play(void);
283 void action_init_vbox_play(void);
284 void action_init_efi(void);
285 void action_dialing_vbox_play(void);
286 void action_dialing_calculator(void);
287 void action_dialing_timer(void);
288 void _action_goto_menu(int mode);
289 void action_dialing_goto(void);
290 void action_dialing_menu(void);
291 void action_dialing_disconnect(void);
292 void action_dialing_release(void);
293 void action_dialing_help(void);
294 void action_dialing_deflect(void);
295 void action_dialing_setforward(void);
296 void action_init_execute(void);
297 void action_hangup_execute(void);
298 void action_execute(void);
299 void action_hangup_file(void);
300 void action_init_pick(void);
301 void action_dialing_password(void);
302 void action_dialing_password_wr(void);
303 void process_dialing(int timeout);
304 void process_hangup(int cause, int location);
306 /* facility function */
307 void pick_join(char *extension);
308 void join_join(void);
309 void encrypt_shared(void);
310 void encrypt_keyex(void);
311 void encrypt_off(void);
312 void encrypt_result(int message, char *text);
313 int check_external(const char **errstr, class Port **port);
316 void cryptman_keyengine(int job);
317 void cr_ident(int message, unsigned char *param, int len);
318 void cr_activate(int message, unsigned char *param, int len);
319 void cr_deactivate(int message, unsigned char *param, int len);
320 void cr_master(int message, unsigned char *param, int len);
321 void cr_slave(int message, unsigned char *param, int len);
322 void cr_looped(int message, unsigned char *param, int len);
323 void cr_abort(int message, unsigned char *param, int len);
324 void cr_abort_engine(int message, unsigned char *param, int len);
325 void cr_abort_wait(int message, unsigned char *param, int len);
326 void cr_genrsa(int message, unsigned char *param, int len);
327 void cr_keyerror(int message, unsigned char *param, int len);
328 void cr_pubkey(int message, unsigned char *param, int len);
329 void cr_cptrsa(int message, unsigned char *param, int len);
330 void cr_cskey(int message, unsigned char *param, int len);
331 void cr_decrsa(int message, unsigned char *param, int len);
332 void cr_waitdelay(int message, unsigned char *param, int len);
333 void cr_bfactive(int message, unsigned char *param, int len);
334 void cr_crypterror(int message, unsigned char *param, int len);
335 void cr_release(int message, unsigned char *param, int len);
336 void cr_sactivate(int message, unsigned char *param, int len);
337 void cr_sdeactivate(int message, unsigned char *param, int len);
338 void cr_sbfactive(int message, unsigned char *param, int len);
339 void cr_scrypterror(int message, unsigned char *param, int len);
340 void cr_sabort(int message, unsigned char *param, int len);
341 void cr_info(int message, unsigned char *param, int len);
342 void cryptman_message(int message, unsigned char *param, int len);
343 void cryptman_msg2man(unsigned char *param, int len);
344 void cryptman_addinf(unsigned char *buf, int buf_size, int element, int len, void *data);
345 int cryptman_sizeofinf(unsigned char *buf, int element);
346 unsigned char *cryptman_getinf(unsigned char *buf, int element, unsigned char *to);
347 void cryptman_msg2peer(unsigned char *buf);
348 void cryptman_msg2user(int msg, const char *text);
349 void cryptman_msg2crengine(int msg, unsigned char *buf, int len);
350 void cryptman_state(int state);
351 void cryptman_timeout(int secs);
352 void message_disconnect_port(struct port_list *portlist, int cause, int location, const char *display);
353 void logmessage(int message_type, union parameter *param, unsigned int port_id, int dir);
354 void trace_header(const char *name, int direction);
358 void apply_callerid_restriction(struct extension *ext, char *id, int *ntype, int *present, int *screen, char *extension, char *name);
359 void send_mail(char *filename, char *callerid, char *callerintern, char *callername, char *vbox_email, int vbox_year, int vbox_mon, int vbox_mday, int vbox_hour, int vbox_min, char *terminal);