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