No empty .Rs/.Re
[netbsd-mini2440.git] / usr.sbin / isdn / isdnd / isdnd.h
blob4fa2679d0914b709652dddb63a0734b2310a4bfc
1 /*
2 * Copyright (c) 1997, 2000 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
6 * are met:
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
23 * SUCH DAMAGE.
25 *---------------------------------------------------------------------------
27 * i4b daemon - main header file
28 * -----------------------------
30 * $Id: isdnd.h,v 1.16 2009/04/16 05:56:32 lukem Exp $
32 * $FreeBSD$
34 * last edit-date: [Sat Jan 6 12:52:50 2001]
36 *---------------------------------------------------------------------------*/
38 #ifndef _ISDND_H_
39 #define _ISDND_H_
41 #include <stdio.h>
42 #include <stdlib.h>
43 #include <stdarg.h>
44 #include <unistd.h>
45 #include <strings.h>
46 #include <string.h>
47 #include <ctype.h>
48 #include <syslog.h>
49 #include <regex.h>
50 #include <time.h>
52 #ifdef USE_CURSES
53 #include <curses.h>
54 #endif
56 #include <fcntl.h>
57 #include <errno.h>
58 #include <signal.h>
60 #include <sys/queue.h> /* TAILQ_ macros */
61 #include <sys/param.h>
62 #include <sys/stat.h>
63 #include <sys/time.h>
64 #include <sys/types.h>
65 #include <sys/ioctl.h>
66 #include <sys/poll.h>
68 #ifdef USE_RTPRIO
69 #include <sys/rtprio.h>
70 #endif
73 #include <sys/socket.h>
74 #include <netinet/in.h>
75 #include <arpa/inet.h>
77 #include <net/if.h>
78 #include <net/if_sppp.h>
79 #include <netisdn/i4b_ioctl.h>
80 #include <netisdn/i4b_cause.h>
82 #include "config.h" /* compile time configuration */
83 #include "pathnames.h" /* location of files */
84 #include "alias.h" /* alias file processing */
86 /*---------------------------------------------------------------------------*
87 * some general definitions
88 *---------------------------------------------------------------------------*/
89 #define GOOD 0 /* general "good" or "ok" return*/
90 #define ERROR (-1) /* general error return */
91 #define WARNING (-2) /* warning return */
92 #define INVALID (-1) /* an invalid integer */
94 /*---------------------------------------------------------------------------*
95 * misc
96 *---------------------------------------------------------------------------*/
97 #define RTPRIO_NOTUSED (-1) /* rtprio is not used for isdnd */
99 /*---------------------------------------------------------------------------*
100 * debug flag bits
101 *---------------------------------------------------------------------------*/
102 #define DL_MSG 0x0001 /* general debug messages */
103 #define DL_RATES 0x0002 /* messages related to rates */
104 #define DL_TIME 0x0004 /* messages related to timing */
105 #define DL_STATE 0x0008 /* messages related to states changes */
106 #define DL_RCVRY 0x0010 /* messages related to dial recovery */
107 #define DL_DIAL 0x0020 /* messages related to dial recovery */
108 #define DL_PROC 0x0040 /* messages related to process handling */
109 #define DL_DRVR 0x0080 /* messages related to kernel i4b msg i/o*/
110 #define DL_CNST 0x0100 /* messages related to controller state */
111 #define DL_RCCF 0x0200 /* messages related to isdnd.rc at boot */
112 #define DL_BDGT 0x0400 /* messages related to budgets */
114 #ifdef DEBUG
115 #define DBGL(cond, dolog) if (cond & debug_flags) dolog
116 #else
117 #define DBGL(cond, dolog)
118 #endif
120 /*---------------------------------------------------------------------------*
121 * curses fullscreen display definitions
122 *---------------------------------------------------------------------------*/
124 /* window dimensions */
125 #define UPPER_B 2 /* upper window start */
127 /* horizontal positions for upper window */
128 #define H_CNTL 0 /* controller */
129 #define H_TEI 2 /* TEI */
130 #define H_CHAN (H_TEI+4) /* channel */
131 #define H_TELN (H_CHAN+2) /* telephone number */
132 #define H_IFN (H_TELN+23) /* interfacename */
133 #define H_IO (H_IFN+7) /* incoming or outgoing */
134 #define H_OUT (H_IO+4) /* # of bytes out */
135 #define H_OUTBPS (H_OUT+11) /* bytes per second out */
136 #define H_IN (H_OUTBPS+5) /* # of bytes in */
137 #define H_INBPS (H_IN+11) /* bytes per second in */
138 #define H_UNITS (H_INBPS+6) /* # of charging units */
140 /* fullscreen mode menu window */
141 #define WMENU_LEN 35 /* width of menu window */
142 #define WMENU_TITLE "Command" /* title string */
143 #define WMENU_POSLN 10 /* menu position, line */
144 #define WMENU_POSCO 5 /* menu position, col */
145 #define WMITEMS 6 /* no of menu items */
146 #define WMENU_HGT (WMITEMS + 4) /* menu window height */
148 #define WREFRESH 0
149 #define WHANGUP 1
150 #define WREREAD 2
151 #define WSHOW 3
152 #define WBUDGET 4
153 #define WQUIT 5
155 #define WMTIMEOUT 5 /* timeout in seconds */
157 /*---------------------------------------------------------------------------*
158 * charging rates
159 *---------------------------------------------------------------------------*/
160 #define NDAYS 7 /* number of days in a week */
161 #define NRATES 4 /* number of rate structures supported */
163 /* struct for rates - each day has one or more */
164 struct rates
166 int start_time; /* hour and min at which this rate starts, e.g. 12:20 12*60+20*/
167 int end_time; /* hour and min at which this rate ends, e.g. 19:10 19*60+10*/
168 int rate; /* how long can I telephone at this price, seconds */
169 struct rates *next;
172 /*---------------------------------------------------------------------------*
173 * the internal identifiers for isdnd log levels. CAUTION: this has to stay
174 * in sync with the loglevel to text and sysloglevel table in log.c !!
175 *---------------------------------------------------------------------------*/
176 enum logids
178 LL_ERR, /* error conditions - everything which caused an error */
179 LL_WRN, /* warning conditions - nonfatal abnormal conditions */
180 LL_DMN, /* normal but significant condition - status of daemon */
181 LL_CHD, /* informational - everything regarding call handling */
182 LL_DBG, /* debug messages - everything which helps debugging */
183 LL_MER, /* monitor error messages - not sent to remote */
184 LL_PKT /* packet logging - log the first few packets */
187 /*---------------------------------------------------------------------------*
188 * state machine events
189 *---------------------------------------------------------------------------*/
190 enum events
192 /* incoming messages */
194 EV_MCI, /* MSG_CONNECT_IND */
195 EV_MCAI, /* MSG_CONNECT_ACTIVE_IND */
196 EV_MDI, /* MSG_DISCONNECT_IND */
197 EV_MDO, /* MSG_DIALOUT */
199 /* local requests */
201 EV_TIMO, /* timer expired */
202 EV_DRQ, /* disconnect request */
203 EV_CBRQ, /* callback request */
204 EV_ALRT, /* alerting request */
206 /* illegal */
208 EV_ILL /* illegal event */
211 #define N_EVENTS (EV_ILL+1) /* no of possible events */
213 /*---------------------------------------------------------------------------*
214 * this struct describes the numbers to try to dial out
215 *---------------------------------------------------------------------------*/
216 typedef struct {
217 char number[TELNO_MAX]; /* remote number to dial */
218 int flag; /* usage flag */
219 #define RNF_IDLE 0
220 #define RNF_SUCC 1 /* last dial was ok */
221 } remote_number_t;
223 /*---------------------------------------------------------------------------*
224 * this struct describes numbers allowed to dial in
225 *---------------------------------------------------------------------------*/
226 typedef struct {
227 char number[TELNO_MAX]; /* calling party number */
228 } incoming_number_t;
230 /*---------------------------------------------------------------------------*
231 * this structure describes a prematurely aborted called-back dialout
232 *---------------------------------------------------------------------------*/
233 typedef struct {
234 int cdid; /* call handle */
235 int controller; /* the controller used to dial out */
236 int channel; /* the channel assigned to the outgoing call */
237 /* XXX - timeout handling and error recovery? */
238 } phantom_t;
240 /*---------------------------------------------------------------------------*
241 * this struct describes one complete configuration entry
242 *---------------------------------------------------------------------------*/
243 struct cfg_entry {
245 SIMPLEQ_ENTRY(cfg_entry) cfgq;
246 int index;
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 char usrdevicename[16];
259 int usrdevice; /* B channel device name & index */
260 int usrdeviceunit; /* userland unit to use */
262 int remote_numbers_count; /* number of remote numbers */
263 #define MAXRNUMBERS 8 /* max remote numbers */
265 remote_number_t remote_numbers[MAXRNUMBERS]; /* remote numbers to dial */
267 int remote_numbers_handling; /* how to handle the remote dialing */
268 #define RNH_NEXT 0 /* use next number after last successful */
269 #define RNH_LAST 1 /* use last successful for next call */
270 #define RNH_FIRST 2 /* always use first number for next call */
272 char local_phone_dialout[TELNO_MAX]; /* our number to tell remote*/
273 char local_phone_incoming[TELNO_MAX]; /* answer calls for this local number */
275 #define MAX_INCOMING 8
276 int incoming_numbers_count; /* number of incoming allowed numbers */
277 incoming_number_t remote_phone_incoming[MAX_INCOMING]; /* answer calls from this remote machine */
279 int dialin_reaction; /* what to do with incoming calls */
280 #define REACT_ACCEPT 0
281 #define REACT_REJECT 1
282 #define REACT_IGNORE 2
283 #define REACT_ANSWER 3
284 #define REACT_CALLBACK 4
286 int b1protocol; /* hdlc / raw */
288 int idle_time_in; /* max idle time incoming calls */
289 int idle_time_out; /* max idle time outgoing calls */
291 int shorthold_algorithm; /* shorthold algorithm */
293 int unitlength; /* length of a charging unit */
294 #define UNITLENGTH_DEFAULT 60 /* last resort unit length */
296 int earlyhangup; /* time in seconds to hangup */
297 /* before the next expected */
298 /* charging unit */
299 #define EARLYHANGUP_DEFAULT 5
301 int ratetype; /* type of rate */
302 #define NO_RATE (NRATES+1)
303 #define INVALID_RATE (-1)
305 int unitlengthsrc; /* where we get the unit length from */
306 #define ULSRC_NONE 0 /* nowhere specified */
307 #define ULSRC_CMDL 1 /* specified on commandline */
308 #define ULSRC_CMDLMIN 5 /* minimum value from cmdl */
309 #define ULSRC_CMDLMAX 3600 /* minimum value from cmdl */
310 #define ULSRC_CONF 2 /* get it from config file */
311 #define ULSRC_RATE 3 /* get it dynamic from ratesfile*/
312 #define ULSRC_DYN 4 /* dynamic calculated from AOCD */
314 const char *answerprog; /* program to use for answering */
315 char *connectprog; /* program run after negotiation finished */
316 char *disconnectprog; /* program run after shutdown is complete */
318 int callbackwait; /* time to wait before calling back */
319 #define CALLBACKWAIT_MIN 1
321 int calledbackwait; /* time to wait for remote callback */
322 #define CALLEDBACKWAIT_MIN 2
324 int dialretries; /* no. of dial tries */
325 #define DIALRETRIES_DEF 1
327 int recoverytime; /* time between 2 dial tries */
328 #define RECOVERYTIME_MIN 1
330 int dialrandincr; /* use random dial time incr */
332 int usedown; /* set interface down yes/no */
333 int downtries; /* retries before i/f is set down */
334 #define DOWN_TRIES_MIN 2
335 #define DOWN_TRIES_MAX 20
336 int downtime; /* time i/f is down */
337 #define DOWN_TIME_MIN 10 /* 10 seconds */
338 #define DOWN_TIME_MAX 3600 /* 1 hour */
340 int dialouttype; /* type of outgoing connection */
341 #define DIALOUT_NORMAL 0 /* normal dialout behaviour */
342 #define DIALOUT_CALLEDBACK 1 /* remote is expected to callback */
344 int alert; /* alert time in sec if nonzero */
345 #define MINALERT 5 /* 5 secs min */
346 #define MAXALERT (3*60) /* 3 minutes max */
348 int inout; /* in/out, in-only or out-only */
349 #define DIR_INOUT 0
350 #define DIR_INONLY 1
351 #define DIR_OUTONLY 2
353 int autoupdown; /* do we handle interface up/down? */
354 #define AUTOUPDOWN_NO 0
355 #define AUTOUPDOWN_YES 1
356 #define AUTOUPDOWN_DONE 2
358 int budget_callbackperiod; /* length of a budget period (s)*/
359 int budget_callbackncalls; /* call budget for a period */
360 char *budget_callbacks_file; /* filename to store callback stats */
361 char budget_callbacksfile_rotate;
363 int budget_calloutperiod; /* length of a budget period (s)*/
364 int budget_calloutncalls; /* call budget for a period */
365 char *budget_callouts_file; /* filename to store callout stats */
366 char budget_calloutsfile_rotate;
368 int ppp_expect_auth;
369 int ppp_send_auth;
370 #define AUTH_UNDEF 0
371 #define AUTH_NONE 1
372 #define AUTH_PAP 2
373 #define AUTH_CHAP 3
375 int ppp_auth_flags;
376 #define AUTH_RECHALLENGE 0x01
377 #define AUTH_REQUIRED 0x02
379 char *ppp_expect_name; /* PPP PAP/CHAP login name */
380 char *ppp_send_name;
382 char *ppp_expect_password;
383 char *ppp_send_password;
385 int day; /* days valid */
386 #define SU 0x01
387 #define MO 0x02
388 #define TU 0x04
389 #define WE 0x08
390 #define TH 0x10
391 #define FR 0x20
392 #define SA 0x40
393 #define HD 0x80 /* holiday */
394 int fromhr; /* time valid */
395 int frommin;
396 int tohr;
397 int tomin;
399 /*===========================================================================*/
400 /*============ filled in after start, then dynamic ==========================*/
401 /*===========================================================================*/
403 int cdid; /* cdid for call */
404 #define CDID_RESERVED (-1)
406 int isdncontrollerused; /* the one we are using */
407 int isdnchannelused; /* the one we are using */
409 int fs_position; /* fullscreen position */
411 int state; /* state of connection */
412 #define ST_IDLE 0 /* connection is idle / disconnected */
414 /* normal dial out to remote */
415 #define ST_DIAL 1 /* dialing */
416 #define ST_DIALRTMRCHD 2 /* wait for dial retry time reached */
417 #define ST_DIALRETRY 3 /* last/first dialing failed, retry */
419 /* PCB: passive callback, i'm being called back */
420 #define ST_PCB_DIAL 4 /* dialing, trigger a callback */
421 #define ST_PCB_DIALFAIL 5 /* dialing failed triggering a callbk */
422 #define ST_PCB_WAITCALL 6 /* waiting for callback from remote */
424 /* ACB: active callback, i'm calling back */
425 #define ST_ACB_WAITDISC 7 /* got call, wait for disconnect */
426 #define ST_ACB_WAITDIAL 8 /* wait until allowed to callback */
427 #define ST_ACB_DIAL 9 /* callback to remote */
428 #define ST_ACB_DIALFAIL 10 /* callback to remote failed */
430 /* normal non-dialling states */
431 #define ST_ACCEPTED 11 /* remote accepted */
432 #define ST_CONNECTED 12 /* connected with remote */
433 #define ST_WAITDISCI 13 /* tx disc req, wait for disc ind */
434 #define ST_DOWN 14 /* interface is down */
435 #define ST_ALERT 15 /* interface is waiting for alert time*/
437 /* illegal and pseudo states */
438 #define ST_ILL 16 /* illegal state */
439 #define ST_SUSE 17 /* subroutine sets new state */
441 #define N_STATES (ST_ILL+1) /* max number of states */
443 cause_t disc_cause; /* cause from disconnect */
445 int local_disconnect; /* flag, who disconnected */
446 #define DISCON_LOC 0
447 #define DISCON_REM 1
449 int timerval; /* value for timer, 0 if inactive */
450 int timerremain; /* remaining time */
452 int hangup; /* flag, hangup connection asap */
454 char real_phone_incoming[TELNO_MAX]; /* real remote telno in case of wildcard */
456 int last_remote_number; /* index of last used dialout number*/
458 char remote_phone_dialout[TELNO_MAX]; /* used remote number to dial */
460 int direction; /* incoming or outgoing */
461 #define DIR_IN 0
462 #define DIR_OUT 1
464 int charge; /* charge in units */
465 int last_charge; /* last charge in units */
467 int inbytes; /* # of bytes from remote */
468 int iinbytes; /* # of bytes from remote on the line */
469 int inbps; /* bytes/sec from remote */
470 int outbytes; /* # of bytes to remote */
471 int ioutbytes; /* # of bytes to remote on the line */
472 int outbps; /* bytes/sec to remote */
474 time_t connect_time; /* time connection was established */
476 time_t aoc_last; /* last AOCD timestamp */
477 time_t aoc_now; /* current AOCD timestamp */
478 time_t aoc_diff; /* current unit length */
479 time_t aoc_lastdiff; /* last charge unit length */
480 int aoc_valid; /* flag: time diff is valid */
481 #define AOC_INVALID 0 /* aoc_diff is NOT valid */
482 #define AOC_VALID 1 /* aoc_diff is valid */
484 time_t last_dial_time; /* time of last dialing */
485 time_t last_release_time; /* time of last hangup */
487 int dial_count; /* number of dialout tries */
488 int randomtime; /* random() part of recoverytime*/
489 #define RANDOM_MASK 0x04 /* bits used from randomtime */
491 int down_retry_count; /* retry cycle count for usedown*/
492 time_t went_down_time; /* time i/f went down */
493 phantom_t saved_call; /* outgoing call state if called
494 back too early */
496 int alert_time; /* count down of alert time */
497 char display[DISPLAY_MAX];
499 time_t budget_callbackperiod_time; /* end of current period */
500 int budget_callbackncalls_cnt; /* amount of calls left */
502 int budget_callback_req; /* requests */
503 int budget_callback_done; /* call done */
504 int budget_callback_rej; /* call refused */
506 time_t budget_calloutperiod_time; /* end of current period */
507 int budget_calloutncalls_cnt; /* amount of calls left */
509 int budget_callout_req; /* requests */
510 int budget_callout_done; /* call done */
511 int budget_callout_rej; /* call refused */
513 int budget_calltype; /* type of call */
514 #define BUDGET_TYPE_CBACK 1
515 #define BUDGET_TYPE_COUT 2
519 /*---------------------------------------------------------------------------*
520 * this struct describes state of controller with 2 b channels
521 *---------------------------------------------------------------------------*/
522 struct isdn_ctrl_state {
523 SLIST_ENTRY(isdn_ctrl_state) ctrlq;
525 char device_name[80]; /* device name, e.g. "isic0" */
526 char controller[80]; /* manufacturer/name */
527 int isdnif;
528 int protocol; /* ISDN D-channel protocol */
529 char *firmware; /* loadable firmware file name */
531 int state; /* controller state */
532 #define CTRL_DOWN 0 /* controller inoparable */
533 #define CTRL_UP 1 /* controller may be used */
534 #define MAX_BCHAN 30 /* support PRI-type adapters */
535 int stateb[MAX_BCHAN]; /* B channels */
536 int nbch; /* number of B channels on ctrl */
537 #define CHAN_IDLE 0 /* channel is free for usage */
538 #define CHAN_RUN 1 /* channel is occupied */
539 int freechans; /* number of unused channels */
540 #define MAX_CHANCTRL 2 /* free channels per controller */
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 *---------------------------------------------------------------------------*/
549 struct rarr {
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 */
566 #endif
568 /*---------------------------------------------------------------------------*
569 * global variables, storage allocation
570 *---------------------------------------------------------------------------*/
571 #ifdef MAIN
573 int isdnfd; /* file handle, /dev/isdn */
575 char mailto[MAXPATHLEN] = ""; /* panic mail address */
576 char mailer[MAXPATHLEN] = ""; /* panic mail address */
578 const char *configfile = CONFIG_FILE_DEF; /* configuration filename */
579 int config_error_flag = 0; /* error counter */
581 #ifdef DEBUG
582 int do_debug = 0; /* debug mode flag */
583 int debug_flags = 0; /* debug options */
584 int debug_noscreen = 0; /* not on fullscreen */
585 #endif
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 const char *ttype = ""; /* termcap entry name string */
594 int do_rdev = 0; /* redirect output */
595 const 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 int uselogfile = 0; /* flag, use a logfile */
603 char logfile[MAXPATHLEN] = LOG_FILE_DEF; /* log filename */
604 FILE *logfp = NULL; /* log file pointer */
605 int logfacility = LOG_LOCAL0; /* the syslog facility used */
606 int nregex = 0; /* number of reg expr */
607 struct rarr rarr[MAX_RE]; /* regexpr & progs table */
609 char ratesfile[MAXPATHLEN] = RATES_FILE_DEF; /* rates filename */
610 char *rate_error = NULL; /* errorcase: error string */
611 int got_rate = 0; /* flag, ratesfile found */
612 struct rates *rates[NRATES][NDAYS]; /* the rates structure */
614 int useacctfile = 0; /* flag, write accounting */
615 char acctfile[MAXPATHLEN] = ACCT_FILE_DEF; /* accounting filename */
616 FILE *acctfp = NULL; /* accounting file pointer */
617 int acct_all = 1; /* account all connections */
619 int aliasing = 0; /* enable alias processing */
620 char aliasfile[MAXPATHLEN] = ALIASFILE; /* alias file location */
622 int do_fullscreen = 0; /* fullscreen log */
623 int curses_ready = 0; /* curses initialized */
625 #ifdef USE_CURSES
626 WINDOW *upper_w; /* curses upper window pointer */
627 WINDOW *mid_w; /* curses mid window pointer */
628 WINDOW *lower_w; /* curses lower window pointer */
629 #endif
631 int rt_prio = RTPRIO_NOTUSED; /* realtime priority */
633 /* monitor via network */
635 int do_monitor = 0;
636 int inhibit_monitor = 0;
637 #ifdef I4B_EXTERNAL_MONITOR
638 int monitorport = DEF_MONPORT;
639 #else
640 int monitorport = -1;
641 #endif
642 int accepted = 0;
644 int isdntime = 0; /* flag, log time from exchange */
645 int extcallattr = 0; /* flag, display extended caller attributes */
647 char tinainitprog[MAXPATHLEN] = TINA_FILE_DEF;
649 char rotatesuffix[MAXPATHLEN] = "";
651 time_t starttime = 0;
653 char holidayfile[MAXPATHLEN] = HOLIDAY_FILE_DEF; /* holiday filename */
655 #else /* !MAIN */
657 int isdnfd;
659 char mailto[MAXPATHLEN];
660 char mailer[MAXPATHLEN];
662 char *configfile;
663 int config_error_flag;
665 #ifdef DEBUG
666 int do_debug;
667 int debug_flags;
668 int debug_noscreen;
669 #endif
671 int do_bell;
673 int do_fork;
675 int do_ttytype;
676 char *ttype;
678 int do_rdev;
679 char *rdev;
681 int do_print;
683 int got_unitlen;
684 time_t unit_length;
686 int uselogfile;
687 char logfile[MAXPATHLEN];
688 FILE *logfp;
689 int logfacility;
690 int nregex;
691 struct rarr rarr[MAX_RE];
693 char ratesfile[MAXPATHLEN];
694 char *rate_error;
695 int got_rate;
696 struct rates *rates[NRATES][NDAYS];
698 int useacctfile;
699 char acctfile[MAXPATHLEN];
700 FILE *acctfp;
701 int acct_all;
703 int aliasing;
704 char aliasfile[MAXPATHLEN];
706 int do_fullscreen;
707 int curses_ready;
709 #ifdef USE_CURSES
710 WINDOW *upper_w;
711 WINDOW *mid_w;
712 WINDOW *lower_w;
713 #endif
715 int rt_prio;
717 int do_monitor;
718 int inhibit_monitor;
719 int monitorport;
720 int accepted;
722 int isdntime;
723 int extcallattr;
725 char tinainitprog[MAXPATHLEN];
727 char rotatesuffix[MAXPATHLEN];
729 time_t starttime;
731 char holidayfile[MAXPATHLEN];
733 #endif /* MAIN */
736 struct cfg_entry * find_cfg_entry(int index);
737 struct cfg_entry * get_first_cfg_entry(void);
738 int add_cfg_entry(struct cfg_entry *cfe);
739 #define NEXT_CFE(c) SIMPLEQ_NEXT(c, cfgq)
740 int count_cfg_entries(void);
741 void remove_all_cfg_entries(void);
742 struct isdn_ctrl_state * find_ctrl_state(int controller);
743 struct isdn_ctrl_state * get_first_ctrl_state(void);
744 #define NEXT_CTRL(c) SLIST_NEXT(c, ctrlq)
745 int count_ctrl_states(void);
746 int add_ctrl_state(struct isdn_ctrl_state *cstate);
747 int remove_ctrl_state(int controller);
748 void remove_all_ctrl_state(void);
750 void cfg_setval ( int keyword );
751 void check_and_kill ( struct cfg_entry *cep );
752 void check_pid ( void );
753 void close_allactive ( void );
754 void configure ( const char *filename, int reread );
755 void daemonize ( void );
756 void dialresponse(struct cfg_entry *cep, int dstat);
757 void display_acct ( struct cfg_entry *cep );
758 void display_bell ( void );
759 void display_ccharge ( struct cfg_entry *cep, int units );
760 void display_chans ( void );
761 void display_charge ( struct cfg_entry *cep );
762 void display_connect ( struct cfg_entry *cep );
763 void display_disconnect ( struct cfg_entry *cep );
764 void display_l12stat(int controller, int layer, int state);
765 void display_tei(int controller, int tei);
766 void display_updown ( struct cfg_entry *cep, int updown );
767 void do_exit ( int exitval );
768 void do_menu ( void );
769 int exec_answer ( struct cfg_entry *cep );
770 int exec_connect_prog ( struct cfg_entry *cep, const char *prog, int link_down );
771 pid_t exec_prog ( const char *prog, const char **arglist );
772 struct cfg_entry * find_by_device_for_dialout ( int drivertype, int driverunit );
773 struct cfg_entry *find_by_device_for_dialoutnumber(int drivertype, int driverunit, int cmdlen, char *cmd);
774 struct cfg_entry * find_matching_entry_incoming ( msg_connect_ind_t *mp, int len );
775 struct cfg_entry * find_active_entry_by_driver ( int drivertype, int driverunit );
776 void finish_log ( void );
777 char * getlogdatetime ( void );
778 int get_cdid ( void );
779 struct cfg_entry * get_cep_by_cc ( int ctrlr, int chan );
780 struct cfg_entry * get_cep_by_driver ( int drivertype, int driverunit );
781 struct cfg_entry * get_cep_by_cdid ( int cdid );
782 int get_current_rate ( struct cfg_entry *cep, int logit );
783 void handle_charge ( struct cfg_entry *cep );
784 void handle_recovery ( void );
785 void handle_scrprs(int cdid, int scr, int prs, const char *caller);
786 void if_up(struct cfg_entry *cep);
787 void if_down(struct cfg_entry *cep);
788 void init_controller ( void );
789 void init_new_controller(int isdnif);
790 void init_controller_protocol ( void );
791 void init_single_controller_protocol ( struct isdn_ctrl_state *ctrl );
792 void init_log ( void );
793 void init_screen ( void );
794 void logit ( int what, const char *fmt, ... );
795 int main ( int argc, char **argv );
796 void msg_accounting ( msg_accounting_ind_t *mp );
797 void msg_alert_ind ( msg_alert_ind_t *mp );
798 void msg_charging_ind ( msg_charging_ind_t *mp );
799 void msg_connect_active_ind ( msg_connect_active_ind_t *mp );
800 void msg_connect_ind ( msg_connect_ind_t *mp, int len );
801 void msg_pdeact_ind(msg_pdeact_ind_t *md);
802 void msg_negcomplete_ind(msg_negcomplete_ind_t *ind);
803 void msg_ifstatechg_ind(msg_ifstatechg_ind_t *ind);
804 void msg_drvrdisc_req(msg_drvrdisc_req_t *mp);
805 void msg_dialout ( msg_dialout_ind_t *mp );
806 void msg_dialoutnumber(msg_dialoutnumber_ind_t *mp);
807 void msg_disconnect_ind ( msg_disconnect_ind_t *mp );
808 void msg_idle_timeout_ind ( msg_idle_timeout_ind_t *mp );
809 void msg_l12stat_ind(msg_l12stat_ind_t *ml);
810 void msg_teiasg_ind(msg_teiasg_ind_t *mt);
811 void msg_proceeding_ind ( msg_proceeding_ind_t *mp );
812 void msg_packet_ind( msg_packet_ind_t *mp );
813 void msg_ctrl_ev_ind( msg_ctrl_ev_ind_t *mp );
814 void next_state ( struct cfg_entry *cep, int event );
815 char * print_i4b_cause( cause_t code );
816 const char * printstate ( struct cfg_entry *cep );
817 int readrates ( char *filename );
818 void reopenfiles ( int dummy );
819 void rereadconfig ( int dummy );
820 void select_first_dialno ( struct cfg_entry *cep );
821 void select_next_dialno ( struct cfg_entry *cep );
822 void select_this_dialno ( struct cfg_entry *cep );
823 int sendm_alert_req ( struct cfg_entry *cep );
824 int sendm_connect_req ( struct cfg_entry *cep );
825 int sendm_connect_resp ( struct cfg_entry *cep, int cdid, int response, cause_t cause );
826 int sendm_disconnect_req ( struct cfg_entry *cep, cause_t cause );
827 int setup_dialout(struct cfg_entry *cep);
828 void sigchild_handler ( int sig );
829 void start_timer ( struct cfg_entry *cep, int seconds );
830 void stop_timer ( struct cfg_entry *cep );
831 void unitlen_chkupd( struct cfg_entry *cep );
832 void write_pid ( void );
833 void yyerror ( const char *msg );
835 void error_exit(int exitval, const char *fmt, ...);
837 /* montior server module */
838 void monitor_init(void);
839 void monitor_exit(void);
840 void monitor_clear_rights(void);
841 void monitor_fixup_rights(void);
842 int monitor_start_rights(const char *clientspec);
843 void monitor_add_rights(int rights);
845 /* possible return codes from monitor_start_rights: */
846 #define I4BMAR_OK 0 /* rights added successfully */
847 #define I4BMAR_LENGTH 1 /* local socket name to long */
848 #define I4BMAR_DUP 2 /* entry already exists */
849 #define I4BMAR_CIDR 3 /* cidr netmask is invalid */
850 #define I4BMAR_NOIP 4 /* host/net could not be resolved */
852 int monitor_create_local_socket(void);
854 #ifndef I4B_NOTCPIP_MONITOR
855 int monitor_create_remote_socket(int portno);
856 #endif
858 void monitor_prepselect(fd_set *selset, int *max_fd);
859 void monitor_handle_input(fd_set *selset);
860 void monitor_handle_connect(int sockfd, int is_local);
861 void monitor_evnt_charge(struct cfg_entry *cep, int units, int estimated);
862 void monitor_evnt_connect(struct cfg_entry *cep);
863 void monitor_evnt_disconnect(struct cfg_entry *cep);
864 void monitor_evnt_updown(struct cfg_entry *cep, int up);
865 void monitor_evnt_log(int prio, const char * what, const char * msg);
867 void monitor_evnt_l12stat(int controller, int layer, int state);
868 void monitor_evnt_tei(int controller, int tei);
869 void monitor_evnt_acct(struct cfg_entry *cep);
871 /* controller.c */
873 void init_active_controller(void);
874 int set_controller_state(struct isdn_ctrl_state *cstate, int state);
875 int get_controller_state(struct isdn_ctrl_state *cstate);
876 int decr_free_channels(struct isdn_ctrl_state *cstate);
877 int incr_free_channels(struct isdn_ctrl_state *cstate);
878 int get_free_channels(struct isdn_ctrl_state *cstate);
879 int set_channel_busy(struct isdn_ctrl_state *cstate, int channel);
880 int set_channel_idle(struct isdn_ctrl_state *cstate, int channel);
881 int ret_channel_state(struct isdn_ctrl_state *cstate, int channel);
883 /* alias.c */
885 void init_alias(char *filename);
886 void free_aliases(void);
887 char *get_alias(char *number);
889 void upd_callstat_file(char *filename, int rotateflag);
891 /* holiday.c */
893 void init_holidays(char *filename);
894 void free_holidays(void);
895 int isholiday(int d, int m, int y);
897 #endif /* _ISDND_H_ */