2 * Copyright (c) 1997, 2002 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * i4b daemon - main header file
28 * -----------------------------
32 * last edit-date: [Sat May 13 13:18:48 2006]
34 *---------------------------------------------------------------------------*/
58 #include <sys/queue.h> /* TAILQ_ macros */
59 #include <sys/param.h>
62 #include <sys/types.h>
63 #include <sys/ioctl.h>
66 #include <sys/rtprio.h>
69 #include <net/if_sppp.h>
71 #include <i4b/i4b_ioctl.h>
72 #include <i4b/i4b_cause.h>
74 #include "config.h" /* compile time configuration */
75 #include "pathnames.h" /* location of files */
76 #include "alias.h" /* alias file processing */
78 /*---------------------------------------------------------------------------*
79 * some general definitions
80 *---------------------------------------------------------------------------*/
81 #define GOOD 0 /* general "good" or "ok" return*/
82 #define ERROR (-1) /* general error return */
83 #define WARNING (-2) /* warning return */
84 #define INVALID (-1) /* an invalid integer */
86 /*---------------------------------------------------------------------------*
88 *---------------------------------------------------------------------------*/
89 #define RTPRIO_NOTUSED (-1) /* rtprio is not used for isdnd */
91 /*---------------------------------------------------------------------------*
93 *---------------------------------------------------------------------------*/
94 #define DL_MSG 0x0001 /* general debug messages */
95 #define DL_RATES 0x0002 /* messages related to rates */
96 #define DL_TIME 0x0004 /* messages related to timing */
97 #define DL_STATE 0x0008 /* messages related to states changes */
98 #define DL_RCVRY 0x0010 /* messages related to dial recovery */
99 #define DL_DIAL 0x0020 /* messages related to dial recovery */
100 #define DL_PROC 0x0040 /* messages related to process handling */
101 #define DL_DRVR 0x0080 /* messages related to kernel i4b msg i/o*/
102 #define DL_CNST 0x0100 /* messages related to controller state */
103 #define DL_RCCF 0x0200 /* messages related to isdnd.rc at boot */
104 #define DL_BDGT 0x0400 /* messages related to budgets */
105 #define DL_VALID 0x0800 /* messages related to valid keyword */
108 #define DBGL(cond, dolog) if(cond & debug_flags) dolog
110 #define DBGL(cond, dolog)
113 /*---------------------------------------------------------------------------*
114 * curses fullscreen display definitions
115 *---------------------------------------------------------------------------*/
117 /* window dimensions */
118 #define UPPER_B 2 /* upper window start */
120 /* horizontal positions for upper window */
121 #define H_CNTL 0 /* controller */
122 #define H_TEI 2 /* TEI */
123 #define H_CHAN (H_TEI+4) /* channel */
124 #define H_TELN (H_CHAN+2) /* telephone number */
125 #define H_IFN (H_TELN+23) /* interfacename */
126 #define H_IO (H_IFN+7) /* incoming or outgoing */
127 #define H_OUT (H_IO+4) /* # of bytes out */
128 #define H_OUTBPS (H_OUT+11) /* bytes per second out */
129 #define H_IN (H_OUTBPS+5) /* # of bytes in */
130 #define H_INBPS (H_IN+11) /* bytes per second in */
131 #define H_UNITS (H_INBPS+6) /* # of charging units */
133 /* fullscreen mode menu window */
134 #define WMENU_LEN 35 /* width of menu window */
135 #define WMENU_TITLE "Command" /* title string */
136 #define WMENU_POSLN 10 /* menu position, line */
137 #define WMENU_POSCO 5 /* menu position, col */
138 #define WMITEMS 6 /* no of menu items */
139 #define WMENU_HGT (WMITEMS + 4) /* menu window height */
148 #define WMTIMEOUT 5 /* timeout in seconds */
150 /*---------------------------------------------------------------------------*
152 *---------------------------------------------------------------------------*/
153 #define NDAYS 7 /* number of days in a week */
154 #define NRATES 4 /* number of rate structures supported */
156 /* struct for rates - each day has one or more */
159 int start_time; /* hour and min at which this rate starts, e.g. 12:20 12*60+20*/
160 int end_time; /* hour and min at which this rate ends, e.g. 19:10 19*60+10*/
161 int rate; /* how long can I telephone at this price, seconds */
165 /*---------------------------------------------------------------------------*
166 * the internal identifiers for isdnd log levels. CAUTION: this has to stay
167 * in sync with the loglevel to text and sysloglevel table in log.c !!
168 *---------------------------------------------------------------------------*/
171 LL_ERR, /* error conditions - everything which caused an error */
172 LL_WRN, /* warning conditions - nonfatal abnormal conditions */
173 LL_DMN, /* normal but significant condition - status of daemon */
174 LL_CHD, /* informational - everything regarding call handling */
175 LL_DBG, /* debug messages - everything which helps debugging */
176 LL_MER, /* monitor error messages - not sent to remote */
177 LL_PKT /* packet logging - log the first few packets */
180 /*---------------------------------------------------------------------------*
181 * state machine events
182 *---------------------------------------------------------------------------*/
185 /* incoming messages */
187 EV_MCI, /* MSG_CONNECT_IND */
188 EV_MCAI, /* MSG_CONNECT_ACTIVE_IND */
189 EV_MDI, /* MSG_DISCONNECT_IND */
190 EV_MDO, /* MSG_DIALOUT */
194 EV_TIMO, /* timer expired */
195 EV_DRQ, /* disconnect request */
196 EV_CBRQ, /* callback request */
197 EV_ALRT, /* alerting request */
201 EV_ILL /* illegal event */
204 #define N_EVENTS (EV_ILL+1) /* no of possible events */
206 /*---------------------------------------------------------------------------*
207 * this struct describes the numbers to try to dial out
208 *---------------------------------------------------------------------------*/
210 char number[TELNO_MAX]; /* number */
211 char subaddr[SUBADDR_MAX]; /* subaddr */
214 /*---------------------------------------------------------------------------*
215 * this struct describes the numbers to try to dial out
216 *---------------------------------------------------------------------------*/
218 char number[TELNO_MAX]; /* remote number to dial */
219 char subaddr[SUBADDR_MAX]; /* remote subaddr */
220 int flag; /* usage flag */
222 #define RNF_SUCC 1 /* last dial was ok */
225 /*---------------------------------------------------------------------------*
226 * this struct describes numbers allowed to dial in
227 *---------------------------------------------------------------------------*/
229 char number[TELNO_MAX]; /* calling party number */
230 char subaddr[SUBADDR_MAX];/* calling party subaddr */
233 /*---------------------------------------------------------------------------*
234 * this structure describes a prematurely aborted called-back dialout
235 *---------------------------------------------------------------------------*/
237 int cdid; /* call handle */
238 int controller; /* the controller used to dial out */
239 int channel; /* the channel assigned to the outgoing call */
240 /* XXX - timeout handling and error recovery? */
243 /*---------------------------------------------------------------------------*
244 * this struct describes one complete configuration entry
245 *---------------------------------------------------------------------------*/
246 typedef struct cfg_entry {
248 /* ====== filled in at startup configuration, then static ===========*/
250 char name[32]; /* id for this entry */
252 int isdncontroller; /* controller to use 0 ... n */
253 int isdnchannel; /* channel to use */
255 int isdntxdelin; /* tx delay, incoming connections */
256 int isdntxdelout; /* tx delay, outgoing connections */
258 int usrdevicename; /* userland device to use */
259 int usrdeviceunit; /* userland unit to use */
261 int remote_numbers_count; /* number of remote numbers */
262 int remote_subaddr_count; /* number of remote subaddr */
263 #define MAXRNUMBERS 8 /* max remote numbers */
265 remote_number_t remote_numbers[MAXRNUMBERS]; /* remote numbers to dial */
268 int remote_numbers_handling; /* how to handle the remote dialing */
269 #define RNH_NEXT 0 /* use next number after last successfull */
270 #define RNH_LAST 1 /* use last successfull for next call */
271 #define RNH_FIRST 2 /* always use first number for next call */
273 number_t local_phone_dialout; /* our number to tell remote*/
274 number_t local_phone_incoming; /* answer calls for this local number */
276 #define MAX_INCOMING 8
277 int incoming_numbers_count; /* number of incoming allowed numbers */
278 int incoming_subaddr_count; /* number of incoming allowed subaddr */
279 incoming_number_t remote_phone_incoming[MAX_INCOMING]; /* answer calls from this remote machine */
281 int dialin_reaction; /* what to do with incoming calls */
282 #define REACT_ACCEPT 0
283 #define REACT_REJECT 1
284 #define REACT_IGNORE 2
285 #define REACT_ANSWER 3
286 #define REACT_CALLBACK 4
288 int b1protocol; /* hdlc / raw */
290 int bcap; /* special bearer capability (DoV) */
292 int idle_time_in; /* max idle time incoming calls */
293 int idle_time_out; /* max idle time outgoing calls */
295 int shorthold_algorithm; /* shorthold algorithm */
297 int unitlength; /* length of a charging unit */
298 #define UNITLENGTH_DEFAULT 60 /* last resort unit length */
300 int earlyhangup; /* time in seconds to hangup */
301 /* before the next expected */
303 #define EARLYHANGUP_DEFAULT 5
305 int ratetype; /* type of rate */
306 #define NO_RATE (NRATES+1)
307 #define INVALID_RATE (-1)
309 int unitlengthsrc; /* where we get the unit length from */
310 #define ULSRC_NONE 0 /* nowhere specified */
311 #define ULSRC_CMDL 1 /* specified on commandline */
312 #define ULSRC_CMDLMIN 5 /* minimum value from cmdl */
313 #define ULSRC_CMDLMAX 3600 /* minimum value from cmdl */
314 #define ULSRC_CONF 2 /* get it from config file */
315 #define ULSRC_RATE 3 /* get it dynamic from ratesfile*/
316 #define ULSRC_DYN 4 /* dynamic calculated from AOCD */
318 char *answerprog; /* program to use for answering */
319 char *connectprog; /* program run after negotiation finished */
320 char *disconnectprog; /* program run after shutdown is complete */
322 int callbackwait; /* time to wait before calling back */
323 #define CALLBACKWAIT_MIN 1
325 int calledbackwait; /* time to wait for remote callback */
326 #define CALLEDBACKWAIT_MIN 2
328 int dialretries; /* no. of dial tries */
329 #define DIALRETRIES_DEF 1
331 int recoverytime; /* time between 2 dial tries */
332 #define RECOVERYTIME_MIN 1
334 int dialrandincr; /* use random dial time incr */
336 int usedown; /* set interface down yes/no */
337 int downtries; /* retries before i/f is set down */
338 #define DOWN_TRIES_MIN 2
339 #define DOWN_TRIES_MAX 20
340 int downtime; /* time i/f is down */
341 #define DOWN_TIME_MIN 10 /* 10 seconds */
342 #define DOWN_TIME_MAX 3600 /* 1 hour */
344 int dialouttype; /* type of outgoing connection */
345 #define DIALOUT_NORMAL 0 /* normal dialout behaviour */
346 #define DIALOUT_CALLEDBACK 1 /* remote is expected to callback */
348 int alert; /* alert time in sec if nonzero */
349 #define MINALERT 5 /* 5 secs min */
350 #define MAXALERT (3*60) /* 3 minutes max */
352 int inout; /* in/out, in-only or out-only */
355 #define DIR_OUTONLY 2
357 int usesubaddr; /* use subaddresses */
359 int budget_callbackperiod; /* length of a budget period (s)*/
360 int budget_callbackncalls; /* call budget for a period */
361 char *budget_callbacks_file; /* filename to store callback stats */
362 char budget_callbacksfile_rotate;
364 int budget_calloutperiod; /* length of a budget period (s)*/
365 int budget_calloutncalls; /* call budget for a period */
366 char *budget_callouts_file; /* filename to store callout stats */
367 char budget_calloutsfile_rotate;
377 #define AUTH_RECHALLENGE 0x01
378 #define AUTH_REQUIRED 0x02
380 char ppp_expect_name[AUTHNAMELEN]; /* PPP PAP/CHAP login name */
381 char ppp_send_name[AUTHNAMELEN];
383 char ppp_expect_password[AUTHKEYLEN];
384 char ppp_send_password[AUTHKEYLEN];
386 int day; /* days valid */
394 #define HD 0x80 /* holiday */
395 int fromhr; /* time valid */
400 time_t maxconnecttime; /* maximum connection time */
402 /*===========================================================================*/
403 /*============ filled in after start, then dynamic ==========================*/
404 /*===========================================================================*/
406 int cdid; /* cdid for call */
407 #define CDID_RESERVED (-1)
409 int isdncontrollerused; /* the one we are using */
410 int isdnchannelused; /* the one we are using */
412 int fs_position; /* fullscreen position */
414 int state; /* state of connection */
415 #define ST_IDLE 0 /* connection is idle / disconnected */
417 /* normal dial out to remote */
418 #define ST_DIAL 1 /* dialing */
419 #define ST_DIALRTMRCHD 2 /* wait for dial retry time reached */
420 #define ST_DIALRETRY 3 /* last/first dialing failed, retry */
422 /* PCB: passive callback, i'm being called back */
423 #define ST_PCB_DIAL 4 /* dialing, trigger a callback */
424 #define ST_PCB_DIALFAIL 5 /* dialing failed triggering a callbk */
425 #define ST_PCB_WAITCALL 6 /* waiting for callback from remote */
427 /* ACB: active callback, i'm calling back */
428 #define ST_ACB_WAITDISC 7 /* got call, wait for disconnect */
429 #define ST_ACB_WAITDIAL 8 /* wait until allowed to callback */
430 #define ST_ACB_DIAL 9 /* callback to remote */
431 #define ST_ACB_DIALFAIL 10 /* callback to remote failed */
433 /* normal non-dialling states */
434 #define ST_ACCEPTED 11 /* remote accepted */
435 #define ST_CONNECTED 12 /* connected with remote */
436 #define ST_WAITDISCI 13 /* tx disc req, wait for disc ind */
437 #define ST_DOWN 14 /* interface is down */
438 #define ST_ALERT 15 /* interface is waiting for alert time*/
440 /* illegal and pseudo states */
441 #define ST_ILL 16 /* illegal state */
442 #define ST_SUSE 17 /* subroutine sets new state */
444 #define N_STATES (ST_ILL+1) /* max number of states */
446 cause_t disc_cause; /* cause from disconnect */
448 int local_disconnect; /* flag, who disconnected */
452 int timerval; /* value for timer, 0 if inactive */
453 int timerremain; /* remaining time */
455 int hangup; /* flag, hangup connection asap */
457 number_t real_phone_incoming; /* real remote telno in case of wildcard */
459 int last_remote_number; /* index of last used dialout number*/
461 number_t remote_phone_dialout; /* used remote number to dial */
463 int direction; /* incoming or outgoing */
467 int charge; /* charge in units */
468 int last_charge; /* last charge in units */
470 int inbytes; /* # of bytes from remote */
471 int iinbytes; /* # of bytes from remote on the line */
472 int inbps; /* bytes/sec from remote */
473 int outbytes; /* # of bytes to remote */
474 int ioutbytes; /* # of bytes to remote on the line */
475 int outbps; /* bytes/sec to remote */
477 time_t connect_time; /* time connection was established */
479 time_t aoc_last; /* last AOCD timestamp */
480 time_t aoc_now; /* current AOCD timestamp */
481 time_t aoc_diff; /* current unit length */
482 time_t aoc_lastdiff; /* last charge unit length */
483 int aoc_valid; /* flag: time diff is valid */
484 #define AOC_INVALID 0 /* aoc_diff is NOT valid */
485 #define AOC_VALID 1 /* aoc_diff is valid */
487 time_t last_dial_time; /* time of last dialing */
488 time_t last_release_time; /* time of last hangup */
490 int dial_count; /* number of dialout tries */
491 int randomtime; /* random() part of recoverytime*/
492 #define RANDOM_MASK 0x04 /* bits used from randomtime */
494 int down_retry_count; /* retry cycle count for usedown*/
495 time_t went_down_time; /* time i/f went down */
496 phantom_t saved_call; /* outgoing call state if called
499 int alert_time; /* count down of alert time */
500 char display[DISPLAY_MAX];
502 time_t budget_callbackperiod_time; /* end of current period */
503 int budget_callbackncalls_cnt; /* amount of calls left */
505 int budget_callback_req; /* requests */
506 int budget_callback_done; /* call done */
507 int budget_callback_rej; /* call refused */
509 time_t budget_calloutperiod_time; /* end of current period */
510 int budget_calloutncalls_cnt; /* amount of calls left */
512 int budget_callout_req; /* requests */
513 int budget_callout_done; /* call done */
514 int budget_callout_rej; /* call refused */
516 int budget_calltype; /* type of call */
517 #define BUDGET_TYPE_CBACK 1
518 #define BUDGET_TYPE_COUT 2
520 char keypad[KEYPAD_MAX]; /* keypad string */
523 /*---------------------------------------------------------------------------*
524 * this struct describes state of controller with MAX_BCHAN b channels
525 *---------------------------------------------------------------------------*/
526 typedef struct isdn_ctrl_state {
527 int ctrl_type; /* type: active/passive */
528 int card_type; /* manufacturer (CARD_XXXX) */
529 int protocol; /* ISDN D-channel protocol */
530 char* firmware; /* loadable fimrware file name */
532 int state; /* controller state */
533 #define CTRL_DOWN 0 /* controller inoparable */
534 #define CTRL_UP 1 /* controller may be used */
536 int stateb[MAX_BCHAN]; /* b channel state */
537 #define CHAN_IDLE 0 /* channel is free for usage */
538 #define CHAN_RUN 1 /* channel is occupied */
539 int nbch; /* number of b channels */
540 int freechans; /* number of unused channels */
541 int tei; /* tei or -1 if invalid */
542 int l1stat; /* layer 1 state */
543 int l2stat; /* layer 2 state */
546 /*---------------------------------------------------------------------------*
547 * this struct describes a logging regular expression
548 *---------------------------------------------------------------------------*/
550 int re_flg; /* valid entry flag */
551 char *re_expr; /* plain text expression */
552 regex_t re; /* compiled expression */
553 char *re_prog; /* the program to be executed */
556 #ifdef I4B_EXTERNAL_MONITOR
557 /* for each rights entry we keep one of this structures around: */
558 struct monitor_rights {
559 TAILQ_ENTRY(monitor_rights) list; /* a list of this structures */
560 char name[FILENAME_MAX]; /* net/host spec or filename */
561 int rights; /* bitmask of allowed acces rights */
562 u_int32_t net; /* net/host address (host byte order!) */
563 u_int32_t mask; /* bitmask 1 = network, 0 = host (host byte order!) */
564 int local; /* zero if remote access via tcp/ip */
568 /*---------------------------------------------------------------------------*
569 * global variables, storage allocation
570 *---------------------------------------------------------------------------*/
573 int isdnfd; /* file handle, /dev/i4b */
575 char mailto[MAXPATHLEN] = ""; /* panic mail address */
576 char mailer[MAXPATHLEN] = ""; /* panic mail address */
578 char *configfile = CONFIG_FILE_DEF; /* configuration filename */
579 int config_error_flag = 0; /* error counter */
582 int do_debug = 0; /* debug mode flag */
583 int debug_flags = 0; /* debug options */
584 int debug_noscreen = 0; /* not on fullscreen */
587 int do_bell = 0; /* bell on connect/disconnect */
589 int do_fork = 1; /* run as daemon/foreground */
591 int do_ttytype = 0; /* got new terminal type */
592 char *ttype = ""; /* termcap entry name string */
594 int do_rdev = 0; /* redirect output */
595 char *rdev = ""; /* new device string */
597 int do_print = 0; /* config file printout */
599 int got_unitlen = 0; /* flag, got length of a unit */
600 time_t unit_length; /* length of a unit */
602 cfg_entry_t cfg_entry_tab[CFG_ENTRY_MAX]; /* configuration table */
603 isdn_ctrl_state_t isdn_ctrl_tab[ISDN_CTRL_MAX]; /* controller states table */
605 int ncontroller = 0; /* # of controllers available */
606 int nentries = 0; /* # of entries in config tab */
608 int uselogfile = 0; /* flag, use a logfile */
609 char logfile[MAXPATHLEN] = LOG_FILE_DEF; /* log filename */
610 FILE *logfp = NULL; /* log file pointer */
611 int logfacility = LOG_LOCAL0; /* the syslog facility used */
612 int nregex = 0; /* number of reg expr */
613 struct rarr rarr[MAX_RE]; /* regexpr & progs table */
615 char ratesfile[MAXPATHLEN] = RATES_FILE_DEF; /* rates filename */
616 char *rate_error = NULL; /* errorcase: error string */
617 int got_rate = 0; /* flag, ratesfile found */
618 struct rates *rates[NRATES][NDAYS]; /* the rates structure */
620 int useacctfile = 0; /* flag, write accounting */
621 char acctfile[MAXPATHLEN] = ACCT_FILE_DEF; /* accounting filename */
622 FILE *acctfp = NULL; /* accounting file pointer */
623 int acct_all = 1; /* account all connections */
625 int aliasing = 0; /* enable alias processing */
626 char aliasfile[MAXPATHLEN] = ALIASFILE; /* alias file location */
628 int do_fullscreen = 0; /* fullscreen log */
629 int curses_ready = 0; /* curses initialized */
632 WINDOW *upper_w; /* curses upper window pointer */
633 WINDOW *mid_w; /* curses mid window pointer */
634 WINDOW *lower_w; /* curses lower window pointer */
637 int rt_prio = RTPRIO_NOTUSED; /* realtime priority */
639 /* monitor via network */
642 int inhibit_monitor = 0;
643 #ifdef I4B_EXTERNAL_MONITOR
644 int monitorport = DEF_MONPORT;
646 int monitorport = -1;
650 int isdntime = 0; /* flag, log time from exchange */
651 int extcallattr = 0; /* flag, display extended caller attributes */
653 char tinainitprog[MAXPATHLEN] = TINA_FILE_DEF;
655 char rotatesuffix[MAXPATHLEN] = "";
657 time_t starttime = 0;
659 char holidayfile[MAXPATHLEN] = HOLIDAY_FILE_DEF; /* holiday filename */
662 char prefixnational[TELNO_MAX] = "";
663 char prefixinternational[TELNO_MAX] = "";
669 char mailto[MAXPATHLEN];
670 char mailer[MAXPATHLEN];
673 int config_error_flag;
696 cfg_entry_t cfg_entry_tab[CFG_ENTRY_MAX]; /* configuration table */
697 isdn_ctrl_state_t isdn_ctrl_tab[ISDN_CTRL_MAX]; /* controller states table */
703 char logfile[MAXPATHLEN];
707 struct rarr rarr[MAX_RE];
709 char ratesfile[MAXPATHLEN];
712 struct rates *rates[NRATES][NDAYS];
715 char acctfile[MAXPATHLEN];
720 char aliasfile[MAXPATHLEN];
741 char tinainitprog[MAXPATHLEN];
743 char rotatesuffix[MAXPATHLEN];
747 char holidayfile[MAXPATHLEN];
750 char prefixnational[TELNO_MAX];
751 char prefixinternational[TELNO_MAX];
755 int add_number_prefix( char *number, int type_of_number );
756 char * bdrivername ( int drivertype );
757 void cfg_setval ( int keyword );
758 void check_and_kill ( cfg_entry_t *cep );
759 void check_pid ( void );
760 void close_allactive ( void );
761 void configure ( char *filename, int reread );
762 void daemonize ( void );
763 void dialresponse(cfg_entry_t *cep, int dstat);
764 void display_acct ( cfg_entry_t *cep );
765 void display_bell ( void );
766 void display_ccharge ( cfg_entry_t *cep, int units );
767 void display_chans ( void );
768 void display_charge ( cfg_entry_t *cep );
769 void display_connect ( cfg_entry_t *cep );
770 void display_disconnect ( cfg_entry_t *cep );
771 void display_l12stat(int controller, int layer, int state);
772 void display_tei(int controller, int tei);
773 void display_updown ( cfg_entry_t *cep, int updown );
774 void do_exit ( int exitval );
775 void do_menu ( void );
776 int exec_answer ( cfg_entry_t *cep );
777 int exec_connect_prog ( cfg_entry_t *cep, const char *prog, int link_down );
778 pid_t exec_prog ( char *prog, char **arglist );
779 cfg_entry_t * find_by_device_for_dialout ( int drivertype, int driverunit );
780 cfg_entry_t *find_by_device_for_dialoutnumber(msg_dialoutnumber_ind_t *mp);
781 cfg_entry_t *find_by_device_for_keypad(int drivertype, int driverunit, int cmdlen, char *cmd);
782 cfg_entry_t * find_matching_entry_incoming ( msg_connect_ind_t *mp );
783 cfg_entry_t * find_active_entry_by_driver ( int drivertype, int driverunit );
784 void finish_log ( void );
785 char * getlogdatetime ( void );
786 int get_cdid ( void );
787 cfg_entry_t * get_cep_by_cc ( int ctrlr, int chan );
788 cfg_entry_t * get_cep_by_driver ( int drivertype, int driverunit );
789 cfg_entry_t * get_cep_by_cdid ( int cdid );
790 int get_current_rate ( cfg_entry_t *cep, int logit );
791 void handle_charge ( cfg_entry_t *cep );
792 void handle_recovery ( void );
793 void handle_scrprs(int cdid, int scr, int prs, char *caller);
794 void if_up(cfg_entry_t *cep);
795 void if_down(cfg_entry_t *cep);
796 void init_controller ( void );
797 void init_controller_protocol ( void );
798 void init_log ( void );
799 void init_screen ( void );
800 void llog ( int what, const char *fmt, ... );
801 int main ( int argc, char **argv );
802 void msg_accounting ( msg_accounting_ind_t *mp );
803 void msg_alert_ind ( msg_alert_ind_t *mp );
804 void msg_charging_ind ( msg_charging_ind_t *mp );
805 void msg_connect_active_ind ( msg_connect_active_ind_t *mp );
806 void msg_connect_ind ( msg_connect_ind_t *mp );
807 void msg_pdeact_ind(msg_pdeact_ind_t *md);
808 void msg_negcomplete_ind(msg_negcomplete_ind_t *ind);
809 void msg_ifstatechg_ind(msg_ifstatechg_ind_t *ind);
810 void msg_drvrdisc_req(msg_drvrdisc_req_t *mp);
811 void msg_dialout ( msg_dialout_ind_t *mp );
812 void msg_dialoutnumber(msg_dialoutnumber_ind_t *mp);
813 void msg_disconnect_ind ( msg_disconnect_ind_t *mp );
814 void msg_idle_timeout_ind ( msg_idle_timeout_ind_t *mp );
815 void msg_l12stat_ind(msg_l12stat_ind_t *ml);
816 void msg_teiasg_ind(msg_teiasg_ind_t *mt);
817 void msg_proceeding_ind ( msg_proceeding_ind_t *mp );
818 void msg_packet_ind( msg_packet_ind_t *mp );
819 void msg_keypad(msg_keypad_ind_t *mp);
820 const char * name_of_controller(int ctrl_type, int card_type);
821 void next_state ( cfg_entry_t *cep, int event );
822 char * print_i4b_cause( cause_t code );
823 char * printstate ( cfg_entry_t *cep );
824 int readrates ( char *filename );
825 int ret_channel_state(int controller, int channel);
826 void reopenfiles ( int dummy );
827 void rereadconfig ( int dummy );
828 void select_first_dialno ( cfg_entry_t *cep );
829 void select_next_dialno ( cfg_entry_t *cep );
830 void select_this_dialno ( cfg_entry_t *cep );
831 int sendm_alert_req ( cfg_entry_t *cep );
832 int sendm_connect_req ( cfg_entry_t *cep );
833 int sendm_connect_resp ( cfg_entry_t *cep, int cdid, int response, cause_t cause );
834 int sendm_disconnect_req ( cfg_entry_t *cep, cause_t cause );
835 int set_channel_busy(int controller, int channel);
836 int set_channel_idle(int controller, int channel);
837 int setup_dialout(cfg_entry_t *cep);
838 void sigchild_handler ( int sig );
839 void start_timer ( cfg_entry_t *cep, int seconds );
840 void stop_timer ( cfg_entry_t *cep );
841 void unitlen_chkupd( cfg_entry_t *cep );
842 void write_pid ( void );
843 void yyerror ( const char *msg );
845 void error_exit(int exitval, const char *fmt, ...);
847 /* montior server module */
850 void monitor_clear_rights();
851 void monitor_fixup_rights();
852 int monitor_start_rights(const char *clientspec);
853 void monitor_add_rights(int rights);
855 /* possible return codes from monitor_start_rights: */
856 #define I4BMAR_OK 0 /* rights added successfully */
857 #define I4BMAR_LENGTH 1 /* local socket name to long */
858 #define I4BMAR_DUP 2 /* entry already exists */
859 #define I4BMAR_CIDR 3 /* cidr netmask is invalid */
860 #define I4BMAR_NOIP 4 /* host/net could not be resolved */
862 int monitor_create_local_socket();
864 #ifndef I4B_NOTCPIP_MONITOR
865 int monitor_create_remote_socket(int portno);
868 void monitor_prepselect(fd_set *selset, int *max_fd);
869 void monitor_handle_input(fd_set *selset);
870 void monitor_handle_connect(int sockfd, int is_local);
871 void monitor_evnt_charge(cfg_entry_t *cep, int units, int estimated);
872 void monitor_evnt_connect(cfg_entry_t *cep);
873 void monitor_evnt_disconnect(cfg_entry_t *cep);
874 void monitor_evnt_updown(cfg_entry_t *cep, int up);
875 void monitor_evnt_log(int prio, const char * what, const char * msg);
877 void monitor_evnt_l12stat(int controller, int layer, int state);
878 void monitor_evnt_tei(int controller, int tei);
879 void monitor_evnt_acct(cfg_entry_t *cep);
883 void init_active_controller(void);
884 int set_controller_state(int controller, int state);
885 int get_controller_state(int controller);
886 int decr_free_channels(int controller);
887 int incr_free_channels(int controller);
888 int get_free_channels(int controller);
889 int set_channel_busy(int controller, int channel);
890 int set_channel_idle(int controller, int channel);
891 int ret_channel_state(int controller, int channel);
895 void init_alias(char *filename);
896 void free_aliases(void);
897 char *get_alias(char *number);
899 void upd_callstat_file(char *filename, int rotateflag);
903 void init_holidays(char *filename);
904 void free_holidays(void);
905 int isholiday(int d, int m, int y);
907 #endif /* _ISDND_H_ */