]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/i4b/isdnd/isdnd.h
This commit was generated by cvs2svn to compensate for changes in r56944,
[FreeBSD/FreeBSD.git] / usr.sbin / i4b / isdnd / isdnd.h
1 /*
2  * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
3  *
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.
12  *
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.
24  *
25  *---------------------------------------------------------------------------
26  *
27  *      i4b daemon - main header file
28  *      -----------------------------
29  *
30  *      $Id: isdnd.h,v 1.72 1999/12/13 21:25:24 hm Exp $ 
31  *
32  * $FreeBSD$
33  *
34  *      last edit-date: [Mon Dec 13 21:46:50 1999]
35  *
36  *---------------------------------------------------------------------------*/
37
38 #ifndef _ISDND_H_
39 #define _ISDND_H_
40
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>
51 #include <errno.h>
52
53 #ifdef USE_CURSES
54 #include <curses.h>
55 #endif
56
57 #include <fcntl.h>
58 #include <errno.h>
59 #include <signal.h>
60
61 #include <sys/queue.h>  /* TAILQ_ macros */
62 #include <sys/param.h>
63 #include <sys/stat.h>
64 #include <sys/time.h>
65 #include <sys/types.h>
66 #include <sys/ioctl.h>
67
68 #ifdef USE_RTPRIO
69 #include <sys/rtprio.h>
70 #endif
71
72 #include <machine/i4b_ioctl.h>
73 #include <machine/i4b_cause.h>
74
75 #include "config.h"             /* compile time configuration   */
76 #include "pathnames.h"          /* location of files            */
77 #include "alias.h"              /* alias file processing        */
78
79 /*---------------------------------------------------------------------------*
80  *      some general definitions
81  *---------------------------------------------------------------------------*/
82 #define GOOD    0               /* general "good" or "ok" return*/
83 #define ERROR   (-1)            /* general error return         */
84 #define WARNING (-2)            /* warning return               */
85 #define INVALID (-1)            /* an invalid integer           */
86
87 /*---------------------------------------------------------------------------*
88  *      misc
89  *---------------------------------------------------------------------------*/
90 #define RTPRIO_NOTUSED (-1)     /* rtprio is not used for isdnd */
91
92 /*---------------------------------------------------------------------------*
93  *      debug flag bits
94  *---------------------------------------------------------------------------*/
95 #define DL_MSG          0x0001  /* general debug messages               */
96 #define DL_RATES        0x0002  /* messages related to rates            */
97 #define DL_TIME         0x0004  /* messages related to timing           */
98 #define DL_STATE        0x0008  /* messages related to states changes   */
99 #define DL_RCVRY        0x0010  /* messages related to dial recovery    */
100 #define DL_DIAL         0x0020  /* messages related to dial recovery    */
101 #define DL_PROC         0x0040  /* messages related to process handling */
102 #define DL_DRVR         0x0080  /* messages related to kernel i4b msg i/o*/
103 #define DL_CNST         0x0100  /* messages related to controller state */
104 #define DL_RCCF         0x0200  /* messages related to isdnd.rc at boot */
105
106 #ifdef DEBUG
107 #define DBGL(cond, dolog) if(cond & debug_flags) dolog
108 #else
109 #define DBGL(cond, dolog)
110 #endif
111
112 /*---------------------------------------------------------------------------*
113  *      curses fullscreen display definitions
114  *---------------------------------------------------------------------------*/
115
116 /* window dimensions */
117 #define UPPER_B         2               /* upper window start  */
118
119 /* horizontal positions for upper window */
120 #define H_CNTL          0               /* controller           */
121 #define H_TEI           2               /* TEI                  */
122 #define H_CHAN          (H_TEI+4)       /* channel              */
123 #define H_TELN          (H_CHAN+2)      /* telephone number     */
124 #define H_IFN           (H_TELN+23)     /* interfacename        */
125 #define H_IO            (H_IFN+7)       /* incoming or outgoing */
126 #define H_OUT           (H_IO+4)        /* # of bytes out       */
127 #define H_OUTBPS        (H_OUT+11)      /* bytes per second out */
128 #define H_IN            (H_OUTBPS+5)    /* # of bytes in        */
129 #define H_INBPS         (H_IN+11)       /* bytes per second in  */
130 #define H_UNITS         (H_INBPS+6)     /* # of charging units  */
131
132 /* fullscreen mode menu window */
133 #define WMENU_LEN       35              /* width of menu window */
134 #define WMENU_TITLE     "Command"       /* title string */
135 #define WMENU_POSLN     10              /* menu position, line */
136 #define WMENU_POSCO     5               /* menu position, col */
137 #define WMITEMS         4               /* no of menu items */
138 #define WMENU_HGT       (WMITEMS + 4)   /* menu window height */
139
140 #define WREFRESH        0
141 #define WHANGUP         1
142 #define WREREAD         2
143 #define WQUIT           3
144
145 #define WMTIMEOUT       5               /* timeout in seconds */
146
147 /*---------------------------------------------------------------------------*
148  *      charging rates
149  *---------------------------------------------------------------------------*/
150 #define NDAYS   7       /* number of days in a week             */
151 #define NRATES  4       /* number of rate structures supported  */
152
153 /* struct for rates - each day has one or more */
154 struct rates
155 {
156         int start_time; /* hour and min at which this rate starts, e.g. 12:20 12*60+20*/
157         int end_time;   /* hour and min at which this rate ends, e.g. 19:10 19*60+10*/
158         int rate;       /* how long can I telephone at this price, seconds */
159         struct rates *next;
160 };
161
162 /*---------------------------------------------------------------------------*
163  * the internal identifiers for isdnd log levels. CAUTION: this has to stay
164  * in sync with the loglevel to text and sysloglevel table in log.c !!
165  *---------------------------------------------------------------------------*/
166 enum logids
167 {
168         LL_ERR, /* error conditions - everything which caused an error  */
169         LL_WRN, /* warning conditions - nonfatal abnormal conditions    */
170         LL_DMN, /* normal but significant condition - status of daemon  */
171         LL_CHD, /* informational - everything regarding call handling   */
172         LL_DBG, /* debug messages - everything which helps debugging    */
173         LL_MER, /* monitor error messages - not sent to remote          */
174         LL_PKT  /* packet logging - log the first few packets           */
175 };
176
177 /*---------------------------------------------------------------------------*
178  *      state machine events
179  *---------------------------------------------------------------------------*/
180 enum events
181 {
182         /* incoming messages */
183         
184         EV_MCI,         /* MSG_CONNECT_IND */
185         EV_MCAI,        /* MSG_CONNECT_ACTIVE_IND */
186         EV_MDI,         /* MSG_DISCONNECT_IND */
187         EV_MDO,         /* MSG_DIALOUT */
188
189         /* local requests */
190
191         EV_TIMO,        /* timer expired */
192         EV_DRQ,         /* disconnect request */
193         EV_CBRQ,        /* callback request */
194         EV_ALRT,        /* alerting request */
195         
196         /* illegal */
197         
198         EV_ILL          /* illegal event */
199 };
200
201 #define N_EVENTS (EV_ILL+1)     /* no of possible events */
202
203 /*---------------------------------------------------------------------------*
204  *      this struct describes the numbers to try to dial out
205  *---------------------------------------------------------------------------*/
206 typedef struct {
207         char number[TELNO_MAX]; /* remote number to dial        */
208         int  flag;              /* usage flag                   */
209 #define RNF_IDLE        0
210 #define RNF_SUCC        1       /* last dial was ok */
211 } remote_number_t;
212
213 /*---------------------------------------------------------------------------*
214  *      this struct describes numbers allowed to dial in
215  *---------------------------------------------------------------------------*/
216 typedef struct {
217         char number[TELNO_MAX]; /* calling party number         */
218 } incoming_number_t;
219
220 /*---------------------------------------------------------------------------*
221  *      this structure describes a prematurely aborted called-back dialout
222  *---------------------------------------------------------------------------*/
223 typedef struct {
224         int cdid;               /* call handle */
225         int controller;         /* the controller used to dial out */
226         int channel;            /* the channel assigned to the outgoing call */
227         /* XXX - timeout handling and error recovery? */
228 } phantom_t;
229
230 /*---------------------------------------------------------------------------*
231  *      this struct describes one complete configuration entry
232  *---------------------------------------------------------------------------*/
233 typedef struct cfg_entry {
234
235         /* ====== filled in at startup configuration, then static ===========*/
236
237         char name[32];                  /* id for this entry */
238
239         int isdncontroller;             /* controller to use 0 ... n */
240         int isdnchannel;                /* channel to use */
241
242         int isdntxdelin;                /* tx delay, incoming connections */
243         int isdntxdelout;               /* tx delay, outgoing connections */
244         
245         int usrdevicename;              /* userland device to use */
246         int usrdeviceunit;              /* userland unit to use */
247
248         int remote_numbers_count;       /* number of remote numbers     */
249 #define MAXRNUMBERS 8                   /* max remote numbers           */
250
251         remote_number_t remote_numbers[MAXRNUMBERS];    /* remote numbers to dial */
252
253         int remote_numbers_handling;    /* how to handle the remote dialing */
254 #define RNH_NEXT        0       /* use next number after last successfull   */
255 #define RNH_LAST        1       /* use last successfull for next call       */
256 #define RNH_FIRST       2       /* always use first number for next call    */
257
258         char local_phone_dialout[TELNO_MAX];    /* our number to tell remote*/
259         char local_phone_incoming[TELNO_MAX];   /* answer calls for this local number */
260
261 #define MAX_INCOMING    8
262         int incoming_numbers_count;     /* number of incoming allowed numbers */
263         incoming_number_t remote_phone_incoming[MAX_INCOMING];  /* answer calls from this remote machine */
264
265         int dialin_reaction;            /* what to do with incoming calls */
266 #define REACT_ACCEPT     0
267 #define REACT_REJECT     1
268 #define REACT_IGNORE     2
269 #define REACT_ANSWER     3
270 #define REACT_CALLBACK   4
271
272         int b1protocol;                 /* hdlc / raw */
273
274         int idle_time_in;               /* max idle time incoming calls */
275         int idle_time_out;              /* max idle time outgoing calls */
276
277         int shorthold_algorithm;        /* shorthold algorithm          */
278
279         int unitlength;                 /* length of a charging unit    */
280 #define UNITLENGTH_DEFAULT      60      /* last resort unit length      */
281
282         int earlyhangup;                /* time in seconds to hangup    */
283                                         /* before the next expected     */
284                                         /* charging unit                */
285 #define EARLYHANGUP_DEFAULT     5
286                                         
287         int ratetype;                   /* type of rate */
288 #define NO_RATE         (NRATES+1)
289 #define INVALID_RATE    (-1)
290
291         int  unitlengthsrc;     /* where we get the unit length from    */
292 #define ULSRC_NONE      0               /* nowhere specified            */
293 #define ULSRC_CMDL      1               /* specified on commandline     */
294 #define   ULSRC_CMDLMIN 5               /* minimum value from cmdl      */
295 #define   ULSRC_CMDLMAX 3600            /* minimum value from cmdl      */
296 #define ULSRC_CONF      2               /* get it from config file      */
297 #define ULSRC_RATE      3               /* get it dynamic from ratesfile*/
298 #define ULSRC_DYN       4               /* dynamic calculated from AOCD */
299
300         char *answerprog;               /* program to use for answering */
301         char *connectprog;      /* program run after negotiation finished */
302         char *disconnectprog;   /* program run after shutdown is complete */
303
304         int  callbackwait;              /* time to wait before calling back */
305 #define CALLBACKWAIT_MIN        1
306
307         int  calledbackwait;            /* time to wait for remote callback */  
308 #define CALLEDBACKWAIT_MIN      2
309
310         int  dialretries;               /* no. of dial tries            */
311 #define DIALRETRIES_DEF         1
312         
313         int  recoverytime;              /* time between 2 dial tries    */
314 #define RECOVERYTIME_MIN        1
315         
316         int  dialrandincr;              /* use random dial time incr    */
317         
318         int  usedown;                   /* set interface down yes/no    */
319         int  downtries;                 /* retries before i/f is set down */
320 #define DOWN_TRIES_MIN 2
321 #define DOWN_TRIES_MAX 20
322         int  downtime;                  /* time i/f is down             */
323 #define DOWN_TIME_MIN 10        /* 10 seconds */
324 #define DOWN_TIME_MAX 3600      /* 1 hour */
325
326         int  dialouttype;               /* type of outgoing connection  */
327 #define DIALOUT_NORMAL     0            /* normal dialout behaviour     */
328 #define DIALOUT_CALLEDBACK 1            /* remote is expected to callback */
329
330         int     alert;                  /* alert time in sec if nonzero */
331 #define MINALERT 5                      /* 5 secs min                   */
332 #define MAXALERT (3*60)                 /* 3 minutes max                */
333
334         int     inout;                  /* in/out, in-only or out-only  */
335 #define DIR_INOUT       0
336 #define DIR_INONLY      1
337 #define DIR_OUTONLY     2
338         
339 /*===========================================================================*/ 
340 /*============ filled in after start, then dynamic ==========================*/
341 /*===========================================================================*/ 
342
343         int cdid;                       /* cdid for call                */
344 #define CDID_RESERVED   (-1)
345
346         int isdncontrollerused;         /* the one we are using         */
347         int isdnchannelused;            /* the one we are using         */
348         
349         int fs_position;                /* fullscreen position          */
350
351         int     state;                  /* state of connection          */
352 #define ST_IDLE         0               /* connection is idle / disconnected  */
353
354                 /* normal dial out to remote */
355 #define ST_DIAL         1               /* dialing                            */
356 #define ST_DIALRTMRCHD  2               /* wait for dial retry time reached   */
357 #define ST_DIALRETRY    3               /* last/first dialing failed, retry   */
358
359                 /* PCB: passive callback, i'm being called back */
360 #define ST_PCB_DIAL     4               /* dialing, trigger a callback        */
361 #define ST_PCB_DIALFAIL 5               /* dialing failed triggering a callbk */
362 #define ST_PCB_WAITCALL 6               /* waiting for callback from remote   */
363
364                 /* ACB: active callback, i'm calling back */
365 #define ST_ACB_WAITDISC 7               /* got call, wait for disconnect      */
366 #define ST_ACB_WAITDIAL 8               /* wait until allowed to callback     */
367 #define ST_ACB_DIAL     9               /* callback to remote                 */
368 #define ST_ACB_DIALFAIL 10              /* callback to remote failed          */
369
370                 /* normal non-dialling states */
371 #define ST_ACCEPTED     11              /* remote accepted                    */
372 #define ST_CONNECTED    12              /* connected with remote              */
373 #define ST_WAITDISCI    13              /* tx disc req, wait for disc ind     */
374 #define ST_DOWN         14              /* interface is down                  */
375 #define ST_ALERT        15              /* interface is waiting for alert time*/
376
377                 /* illegal and pseudo states */
378 #define ST_ILL          16              /* illegal state                      */
379 #define ST_SUSE         17              /* subroutine sets new state          */
380
381 #define N_STATES        (ST_ILL+1)      /* max number of states               */
382
383         int disc_cause;                 /* cause from disconnect */
384
385         int local_disconnect;           /* flag, who disconnected */
386 #define DISCON_LOC      0
387 #define DISCON_REM      1
388
389         int timerval;                   /* value for timer, 0 if inactive */
390         int timerremain;                /* remaining time       */
391
392         int hangup;                     /* flag, hangup connection asap */
393
394         char real_phone_incoming[TELNO_MAX]; /* real remote telno in case of wildcard */
395
396         int last_remote_number;         /* index of last used dialout number*/
397
398         char remote_phone_dialout[TELNO_MAX]; /* used remote number to dial */
399         
400         int direction;                  /* incoming or outgoing */
401 #define DIR_IN  0
402 #define DIR_OUT 1
403         
404         int charge;                     /* charge in units */
405         int last_charge;                /* last charge in units */
406         
407         int inbytes;                    /* # of bytes from remote */
408         int iinbytes;                   /* # of bytes from remote on the line */
409         int inbps;                      /* bytes/sec from remote */
410         int outbytes;                   /* # of bytes to remote */
411         int ioutbytes;                  /* # of bytes to remote on the line */  
412         int outbps;                     /* bytes/sec to remote */
413         
414         time_t  connect_time;           /* time connection was established */
415
416         time_t aoc_last;                /* last AOCD timestamp          */
417         time_t aoc_now;                 /* current AOCD timestamp       */
418         time_t aoc_diff;                /* current unit length          */
419         time_t aoc_lastdiff;            /* last charge unit length      */
420         int aoc_valid;                  /* flag: time diff is valid     */
421 #define AOC_INVALID     0               /* aoc_diff is NOT valid        */
422 #define AOC_VALID       1               /* aoc_diff is valid            */
423
424         time_t  last_dial_time;         /* time of last dialing         */
425         time_t  last_release_time;      /* time of last hangup          */
426         
427         int     dial_count;             /* number of dialout tries      */
428         int     randomtime;             /* random() part of recoverytime*/
429 #define RANDOM_MASK 0x04                /* bits used from randomtime    */
430
431         int     down_retry_count;       /* retry cycle count for usedown*/
432         time_t  went_down_time;         /* time i/f went down           */
433         phantom_t saved_call;           /* outgoing call state if called
434                                            back too early */
435
436         int     alert_time;             /* count down of alert time     */      
437         char display[DISPLAY_MAX];
438 } cfg_entry_t;
439
440 /*---------------------------------------------------------------------------*
441  *      this struct describes state of controller with 2 b channels
442  *---------------------------------------------------------------------------*/
443 typedef struct isdn_ctrl_state {
444         int ctrl_type;                  /* type: active/passive         */
445         int card_type;                  /* manufacturer (CARD_XXXX)     */
446         int protocol;                   /* ISDN D-channel protocol      */      
447         int state;                      /* controller state             */
448 #define  CTRL_DOWN      0               /* controller inoparable        */
449 #define  CTRL_UP        1               /* controller may be used       */
450         int stateb1;                    /* B-channel 1                  */
451         int stateb2;                    /* B-channel 2                  */
452 #define  CHAN_IDLE      0               /* channel is free for usage    */
453 #define  CHAN_RUN       1               /* channel is occupied          */
454         int freechans;                  /* number of unused channels    */
455 #define  MAX_CHANCTRL   2               /* free channels per controller */
456         int tei;                        /* tei or -1 if invalid         */
457         int l1stat;                     /* layer 1 state                */
458         int l2stat;                     /* layer 2 state                */
459 } isdn_ctrl_state_t;
460
461 /*---------------------------------------------------------------------------*
462  *      this struct describes a logging regular expression
463  *---------------------------------------------------------------------------*/
464 struct rarr {
465         int re_flg;             /* valid entry flag */
466         char *re_expr;          /* plain text expression */
467         regex_t re;             /* compiled expression */
468         char *re_prog;          /* the program to be executed */
469 };
470
471 #ifdef I4B_EXTERNAL_MONITOR
472 /* for each rights entry we keep one of this structures around: */
473 struct monitor_rights {
474         TAILQ_ENTRY(monitor_rights) list;       /* a list of this structures */
475         char name[FILENAME_MAX];        /* net/host spec or filename */
476         int rights;                     /* bitmask of allowed acces rights */
477         u_int32_t net;                  /* net/host address (host byte order!) */
478         u_int32_t mask;                 /* bitmask 1 = network, 0 = host (host byte order!) */
479         int local;                      /* zero if remote access via tcp/ip */
480 };
481 #endif
482
483 /*---------------------------------------------------------------------------*
484  *      global variables, storage allocation
485  *---------------------------------------------------------------------------*/
486 #ifdef MAIN
487
488 int isdnfd;                                     /* file handle, /dev/i4b */
489
490 char mailto[MAXPATHLEN] = "";                   /* panic mail address */
491 char mailer[MAXPATHLEN] = "";                   /* panic mail address */
492
493 char *configfile = CONFIG_FILE_DEF;             /* configuration filename */
494 int config_error_flag = 0;                      /* error counter */
495
496 #ifdef DEBUG
497 int do_debug = 0;                               /* debug mode flag      */
498 int debug_flags = 0;                            /* debug options        */
499 int debug_noscreen = 0;                         /* not on fullscreen    */
500 #endif
501
502 int do_bell = 0;                                /* bell on connect/disconnect */
503
504 int do_fork = 1;                                /* run as daemon/foreground */
505
506 int do_ttytype = 0;                             /* got new terminal type */
507 char *ttype = "";                               /* termcap entry name string */
508
509 int do_rdev = 0;                                /* redirect output      */
510 char *rdev = "";                                /* new device string */
511
512 int do_print = 0;                               /* config file printout */
513
514 int got_unitlen = 0;                            /* flag, got length of a unit */
515 time_t unit_length;                             /* length of a unit */
516
517 cfg_entry_t cfg_entry_tab[CFG_ENTRY_MAX];       /* configuration table */
518 isdn_ctrl_state_t isdn_ctrl_tab[ISDN_CTRL_MAX]; /* controller states table */
519
520 int ncontroller = 0;                            /* # of controllers available */
521 int nentries = 0;                               /* # of entries in config tab */
522
523 int uselogfile = 0;                             /* flag, use a logfile */
524 char logfile[MAXPATHLEN] = LOG_FILE_DEF;        /* log filename */
525 FILE *logfp = NULL;                             /* log file pointer */
526 int logfacility = LOG_LOCAL0;                   /* the syslog facility used */
527 int nregex = 0;                                 /* number of reg expr */
528 struct rarr rarr[MAX_RE];                       /* regexpr & progs table */
529
530 char ratesfile[MAXPATHLEN] = RATES_FILE_DEF;    /* rates filename */
531 char *rate_error = NULL;                        /* errorcase: error string */
532 int got_rate = 0;                               /* flag, ratesfile found */
533 struct rates *rates[NRATES][NDAYS];             /* the rates structure */
534
535 int useacctfile = 0;                            /* flag, write accounting */
536 char acctfile[MAXPATHLEN] = ACCT_FILE_DEF;      /* accounting  filename */
537 FILE *acctfp = NULL;                            /* accounting file pointer */
538 int acct_all = 1;                               /* account all connections */
539
540 int aliasing = 0;                               /* enable alias processing */
541 char aliasfile[MAXPATHLEN] = ALIASFILE;         /* alias file location */
542
543 int do_fullscreen = 0;                          /* fullscreen log       */
544 int curses_ready = 0;                           /* curses initialized */
545
546 #ifdef USE_CURSES
547 WINDOW *upper_w;                /* curses upper window pointer */
548 WINDOW *mid_w;                  /* curses mid window pointer */
549 WINDOW *lower_w;                /* curses lower window pointer */
550 #endif
551
552 int rt_prio = RTPRIO_NOTUSED;                   /* realtime priority */
553
554 /* monitor via network */
555
556 int do_monitor = 0;
557 int inhibit_monitor = 0;
558 #ifdef I4B_EXTERNAL_MONITOR
559 int monitorport = DEF_MONPORT;
560 #else
561 int monitorport = -1;
562 #endif
563 int accepted = 0;
564
565 int isdntime = 0;               /* flag, log time from exchange */
566
567 char tinainitprog[MAXPATHLEN] = TINA_FILE_DEF;
568
569 char rotatesuffix[MAXPATHLEN] = "";
570
571 #else /* !MAIN */
572
573 int isdnfd;
574
575 char mailto[MAXPATHLEN];
576 char mailer[MAXPATHLEN];
577
578 char *configfile;
579 int config_error_flag;
580
581 #ifdef DEBUG
582 int do_debug;
583 int debug_flags;
584 int debug_noscreen;
585 #endif
586
587 int do_bell;
588
589 int do_fork;
590
591 int do_ttytype;
592 char *ttype;
593
594 int do_rdev;
595 char *rdev;
596
597 int do_print;
598
599 int got_unitlen;
600 time_t unit_length;
601
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 */
604
605 int ncontroller;
606 int nentries;
607
608 int uselogfile;
609 char logfile[MAXPATHLEN];
610 int logfacility;
611 int nregex;
612 struct rarr rarr[MAX_RE];
613
614 char ratesfile[MAXPATHLEN];
615 char *rate_error;
616 int got_rate;
617 struct rates *rates[NRATES][NDAYS];
618
619 int useacctfile;
620 char acctfile[MAXPATHLEN];
621 FILE *acctfp;
622 int acct_all;
623
624 int aliasing;
625 char aliasfile[MAXPATHLEN];
626
627 int do_fullscreen;
628 int curses_ready;
629
630 #ifdef USE_CURSES
631 WINDOW *upper_w;
632 WINDOW *mid_w;
633 WINDOW *lower_w;
634 #endif
635
636 int rt_prio;
637
638 int do_monitor;
639 int inhibit_monitor;
640 int monitorport;
641 int accepted;
642
643 int isdntime;
644
645 char tinainitprog[MAXPATHLEN];
646
647 char rotatesuffix[MAXPATHLEN];
648
649 #endif /* MAIN */
650
651 char * bdrivername ( int drivertype );
652 void cfg_setval ( int keyword );
653 void check_and_kill ( cfg_entry_t *cep );
654 void check_pid ( void );
655 void close_allactive ( void );
656 void configure ( char *filename, int reread );
657 void daemonize ( void );
658 void dialresponse(cfg_entry_t *cep, int dstat);
659 void display_acct ( cfg_entry_t *cep );
660 void display_bell ( void );
661 void display_ccharge ( cfg_entry_t *cep, int units );
662 void display_chans ( void );
663 void display_charge ( cfg_entry_t *cep );
664 void display_connect ( cfg_entry_t *cep );
665 void display_disconnect ( cfg_entry_t *cep );
666 void display_l12stat(int controller, int layer, int state);
667 void display_tei(int controller, int tei);
668 void display_updown ( cfg_entry_t *cep, int updown );
669 void do_exit ( int exitval );
670 void do_menu ( void );
671 int exec_answer ( cfg_entry_t *cep );
672 int exec_connect_prog ( cfg_entry_t *cep, const char *prog, int link_down );
673 pid_t exec_prog ( char *prog, char **arglist );
674 cfg_entry_t * find_by_device_for_dialout ( int drivertype, int driverunit );
675 cfg_entry_t *find_by_device_for_dialoutnumber(int drivertype, int driverunit, int cmdlen, char *cmd);
676 cfg_entry_t * find_matching_entry_incoming ( msg_connect_ind_t *mp );
677 cfg_entry_t * find_active_entry_by_driver ( int drivertype, int driverunit );
678 void finish_log ( void );
679 char * getlogdatetime ( void );
680 int get_cdid ( void );
681 cfg_entry_t * get_cep_by_cc ( int ctrlr, int chan );
682 cfg_entry_t * get_cep_by_driver ( int drivertype, int driverunit );
683 cfg_entry_t * get_cep_by_cdid ( int cdid );
684 int get_current_rate ( cfg_entry_t *cep, int logit );
685 void handle_charge ( cfg_entry_t *cep );
686 void handle_recovery ( void );
687 void if_up(cfg_entry_t *cep);
688 void if_down(cfg_entry_t *cep);
689 void init_controller ( void );
690 void init_controller_protocol ( void );
691 void init_log ( void );
692 void init_screen ( void );
693 void log ( int what, const char *fmt, ... );
694 int main ( int argc, char **argv );
695 void msg_accounting ( msg_accounting_ind_t *mp );
696 void msg_alert_ind ( msg_alert_ind_t *mp );
697 void msg_charging_ind ( msg_charging_ind_t *mp );
698 void msg_connect_active_ind ( msg_connect_active_ind_t *mp );
699 void msg_connect_ind ( msg_connect_ind_t *mp );
700 void msg_pdeact_ind(msg_pdeact_ind_t *md);
701 void msg_negcomplete_ind(msg_negcomplete_ind_t *ind);
702 void msg_ifstatechg_ind(msg_ifstatechg_ind_t *ind);
703 void msg_drvrdisc_req(msg_drvrdisc_req_t *mp);
704 void msg_dialout ( msg_dialout_ind_t *mp );
705 void msg_dialoutnumber(msg_dialoutnumber_ind_t *mp);
706 void msg_disconnect_ind ( msg_disconnect_ind_t *mp );
707 void msg_idle_timeout_ind ( msg_idle_timeout_ind_t *mp );
708 void msg_l12stat_ind(msg_l12stat_ind_t *ml);
709 void msg_teiasg_ind(msg_teiasg_ind_t *mt);
710 void msg_proceeding_ind ( msg_proceeding_ind_t *mp );
711 void msg_packet_ind( msg_packet_ind_t *mp );
712 const char * name_of_controller(int ctrl_type, int card_type);
713 void next_state ( cfg_entry_t *cep, int event );
714 char * print_i4b_cause( cause_t code );
715 char * printstate ( cfg_entry_t *cep );
716 int readrates ( char *filename );
717 int ret_channel_state(int controller, int channel);
718 void reopenfiles ( int dummy );
719 void rereadconfig ( int dummy );
720 void select_first_dialno ( cfg_entry_t *cep );
721 void select_next_dialno ( cfg_entry_t *cep );
722 void select_this_dialno ( cfg_entry_t *cep );
723 int sendm_alert_req ( cfg_entry_t *cep );
724 int sendm_connect_req ( cfg_entry_t *cep );
725 int sendm_connect_resp ( cfg_entry_t *cep, int cdid, int response, int cause );
726 int sendm_disconnect_req ( cfg_entry_t *cep, int cause );
727 int set_channel_busy(int controller, int channel);
728 int set_channel_idle(int controller, int channel);
729 int setup_dialout(cfg_entry_t *cep);
730 void sigchild_handler ( int sig );
731 void start_timer ( cfg_entry_t *cep, int seconds );
732 void stop_timer ( cfg_entry_t *cep );
733 void unitlen_chkupd( cfg_entry_t *cep );
734 void write_pid ( void );
735 void yyerror ( const char *msg );
736
737 void error_exit(int exitval, const char *fmt, ...);
738
739 /* montior server module */
740 void monitor_init();
741 void monitor_exit();
742 void monitor_clear_rights();
743 void monitor_fixup_rights();
744 int monitor_start_rights(const char *clientspec);
745 void monitor_add_rights(int rights);
746
747 /* possible return codes from monitor_start_rights: */
748 #define I4BMAR_OK       0       /* rights added successfully */
749 #define I4BMAR_LENGTH   1       /* local socket name to long */
750 #define I4BMAR_DUP      2       /* entry already exists */
751 #define I4BMAR_CIDR     3       /* cidr netmask is invalid */
752 #define I4BMAR_NOIP     4       /* host/net could not be resolved */
753
754 int monitor_create_local_socket();
755
756 #ifndef I4B_NOTCPIP_MONITOR
757 int monitor_create_remote_socket(int portno);
758 #endif
759
760 void monitor_prepselect(fd_set *selset, int *max_fd);
761 void monitor_handle_input(fd_set *selset);
762 void monitor_handle_connect(int sockfd, int is_local);
763 void monitor_evnt_charge(cfg_entry_t *cep, int units, int estimated);
764 void monitor_evnt_connect(cfg_entry_t *cep);
765 void monitor_evnt_disconnect(cfg_entry_t *cep);
766 void monitor_evnt_updown(cfg_entry_t *cep, int up);
767 void monitor_evnt_log(int prio, const char * what, const char * msg);
768
769 void monitor_evnt_l12stat(int controller, int layer, int state);
770 void monitor_evnt_tei(int controller, int tei);
771 void monitor_evnt_acct(cfg_entry_t *cep);
772
773 /* controller.c */
774
775 void init_active_controller(void);
776 int set_controller_state(int controller, int state);
777 int get_controller_state(int controller);
778 int decr_free_channels(int controller);
779 int incr_free_channels(int controller);
780 int get_free_channels(int controller);
781 int set_channel_busy(int controller, int channel);
782 int set_channel_idle(int controller, int channel);
783 int ret_channel_state(int controller, int channel);
784
785 /* alias.c */
786
787 void init_alias(char *filename);
788 void free_aliases(void);
789 char *get_alias(char *number);
790
791 #endif /* _ISDND_H_ */