2 * Copyright (c) 1997, 2001 Hellmuth Michaelis. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 *---------------------------------------------------------------------------
27 * i4b daemon - misc support routines
28 * ----------------------------------
30 * $FreeBSD: src/usr.sbin/i4b/isdnd/support.c,v 1.6.2.2 2001/12/16 15:13:38 hm Exp $
32 * last edit-date: [Thu May 3 17:15:00 2001]
34 *---------------------------------------------------------------------------*/
38 static int isvalidtime(cfg_entry_t *cep);
40 /*---------------------------------------------------------------------------*
41 * find an active entry by driver type and driver unit
42 *---------------------------------------------------------------------------*/
44 find_active_entry_by_driver(int drivertype, int driverunit)
46 cfg_entry_t *cep = NULL;
49 for(i=0; i < nentries; i++)
51 cep = &cfg_entry_tab[i]; /* ptr to config entry */
53 if(!((cep->usrdevicename == drivertype) &&
54 (cep->usrdeviceunit == driverunit)))
59 /* check time interval */
61 if(isvalidtime(cep) == 0)
63 DBGL(DL_VALID, (log(LL_DBG, "find_active_entry_by_driver: entry %d, time not valid!", i)));
69 if(cep->cdid == CDID_UNUSED)
71 DBGL(DL_MSG, (log(LL_DBG, "find_active_entry_by_driver: entry %d [%s%d], cdid=CDID_UNUSED !",
72 i, bdrivername(drivertype), driverunit)));
75 else if(cep->cdid == CDID_RESERVED)
77 DBGL(DL_MSG, (log(LL_DBG, "find_active_entry_by_driver: entry %d [%s%d], cdid=CDID_RESERVED!",
78 i, bdrivername(drivertype), driverunit)));
86 /*---------------------------------------------------------------------------*
87 * find entry by drivertype and driverunit and setup for dialing out
88 *---------------------------------------------------------------------------*/
90 find_by_device_for_dialout(int drivertype, int driverunit)
92 cfg_entry_t *cep = NULL;
95 for(i=0; i < nentries; i++)
97 cep = &cfg_entry_tab[i]; /* ptr to config entry */
99 /* compare driver type and unit */
101 if(!((cep->usrdevicename == drivertype) &&
102 (cep->usrdeviceunit == driverunit)))
107 /* check time interval */
109 if(isvalidtime(cep) == 0)
111 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_dialout: entry %d, time not valid!", i)));
115 /* found, check if already reserved */
117 if(cep->cdid == CDID_RESERVED)
119 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_dialout: entry %d, cdid reserved!", i)));
123 /* check if this entry is already in use ? */
125 if(cep->cdid != CDID_UNUSED)
127 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_dialout: entry %d, cdid in use", i)));
131 if((setup_dialout(cep)) == GOOD)
133 /* found an entry to be used for calling out */
135 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_dialout: found entry %d!", i)));
140 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_dialout: entry %d, setup_dialout() failed!", i)));
145 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_dialout: no entry found!")));
149 /*---------------------------------------------------------------------------*
150 * find entry by drivertype and driverunit and setup for dialing out
151 *---------------------------------------------------------------------------*/
153 find_by_device_for_dialoutnumber(int drivertype, int driverunit, int cmdlen, char *cmd)
155 cfg_entry_t *cep = NULL;
158 for(i=0; i < nentries; i++)
160 cep = &cfg_entry_tab[i]; /* ptr to config entry */
162 /* compare driver type and unit */
164 if(!((cep->usrdevicename == drivertype) &&
165 (cep->usrdeviceunit == driverunit)))
170 /* check time interval */
172 if(isvalidtime(cep) == 0)
174 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_dialoutnumber: entry %d, time not valid!", i)));
178 /* found, check if already reserved */
180 if(cep->cdid == CDID_RESERVED)
182 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_dialoutnumber: entry %d, cdid reserved!", i)));
186 /* check if this entry is already in use ? */
188 if(cep->cdid != CDID_UNUSED)
190 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_dialoutnumber: entry %d, cdid in use", i)));
194 cep->keypad[0] = '\0';
196 /* check number and copy to cep->remote_numbers[] */
198 for(j = 0; j < cmdlen; j++)
200 if(!(isdigit(*(cmd+j))))
202 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_dialoutnumber: entry %d, dial string contains non-digit at pos %d", i, j)));
205 /* fill in number to dial */
206 cep->remote_numbers[0].number[j] = *(cmd+j);
208 cep->remote_numbers[0].number[j] = '\0';
209 cep->remote_numbers_count = 1;
211 if((setup_dialout(cep)) == GOOD)
213 /* found an entry to be used for calling out */
215 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_dialoutnumber: found entry %d!", i)));
220 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_dialoutnumber: entry %d, setup_dialout() failed!", i)));
225 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_dialoutnumber: no entry found!")));
229 /*---------------------------------------------------------------------------*
230 * find entry by drivertype and driverunit and setup for send keypad
231 *---------------------------------------------------------------------------*/
233 find_by_device_for_keypad(int drivertype, int driverunit, int cmdlen, char *cmd)
235 cfg_entry_t *cep = NULL;
238 for(i=0; i < nentries; i++)
240 cep = &cfg_entry_tab[i]; /* ptr to config entry */
242 /* compare driver type and unit */
244 if(!((cep->usrdevicename == drivertype) &&
245 (cep->usrdeviceunit == driverunit)))
250 /* check time interval */
252 if(isvalidtime(cep) == 0)
254 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_keypad: entry %d, time not valid!", i)));
258 /* found, check if already reserved */
260 if(cep->cdid == CDID_RESERVED)
262 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_keypad: entry %d, cdid reserved!", i)));
266 /* check if this entry is already in use ? */
268 if(cep->cdid != CDID_UNUSED)
270 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_keypad: entry %d, cdid in use", i)));
274 cep->remote_numbers[0].number[0] = '\0';
275 cep->remote_numbers_count = 0;
276 cep->remote_phone_dialout[0] = '\0';
278 bzero(cep->keypad, KEYPAD_MAX);
279 strncpy(cep->keypad, cmd, cmdlen);
281 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_keypad: entry %d, keypad string is %s", i, cep->keypad)));
283 if((setup_dialout(cep)) == GOOD)
285 /* found an entry to be used for calling out */
287 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_keypad: found entry %d!", i)));
292 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_keypad: entry %d, setup_dialout() failed!", i)));
297 DBGL(DL_MSG, (log(LL_DBG, "find_by_device_for_keypad: no entry found!")));
301 /*---------------------------------------------------------------------------*
302 * find entry by drivertype and driverunit and setup for dialing out
303 *---------------------------------------------------------------------------*/
305 setup_dialout(cfg_entry_t *cep)
309 /* check controller operational */
311 if((get_controller_state(cep->isdncontroller)) != CTRL_UP)
313 DBGL(DL_MSG, (log(LL_DBG, "setup_dialout: entry %s, controller is down", cep->name)));
317 cep->isdncontrollerused = cep->isdncontroller;
319 /* check channel available */
321 switch(cep->isdnchannel)
324 for (i = 0; i < isdn_ctrl_tab[cep->isdncontroller].nbch; i++)
326 if(ret_channel_state(cep->isdncontroller, i) == CHAN_IDLE)
330 if (i == isdn_ctrl_tab[cep->isdncontroller].nbch)
332 DBGL(DL_MSG, (log(LL_DBG, "setup_dialout: entry %s, no channel free", cep->name)));
335 cep->isdnchannelused = CHAN_ANY;
339 if((ret_channel_state(cep->isdncontroller, cep->isdnchannel)) != CHAN_IDLE)
341 DBGL(DL_MSG, (log(LL_DBG, "setup_dialout: entry %s, channel not free", cep->name)));
344 cep->isdnchannelused = cep->isdnchannel;
348 DBGL(DL_MSG, (log(LL_DBG, "setup_dialout: entry %s ok!", cep->name)));
350 /* preset disconnect cause */
352 SET_CAUSE_TYPE(cep->disc_cause, CAUSET_I4B);
353 SET_CAUSE_VAL(cep->disc_cause, CAUSE_I4B_NORMAL);
358 /*---------------------------------------------------------------------------*
359 * find entry by drivertype and driverunit
360 *---------------------------------------------------------------------------*/
362 get_cep_by_driver(int drivertype, int driverunit)
364 cfg_entry_t *cep = NULL;
367 for(i=0; i < nentries; i++)
369 cep = &cfg_entry_tab[i]; /* ptr to config entry */
371 if(!((cep->usrdevicename == drivertype) &&
372 (cep->usrdeviceunit == driverunit)))
377 /* check time interval */
379 if(isvalidtime(cep) == 0)
381 DBGL(DL_MSG, (log(LL_DBG, "get_cep_by_driver: entry %d, time not valid!", i)));
385 DBGL(DL_MSG, (log(LL_DBG, "get_cep_by_driver: found entry %d!", i)));
391 /*---------------------------------------------------------------------------*
392 * find a matching entry for an incoming call
394 * - not found/no match: log output with LL_CHD and return NULL
395 * - found/match: make entry in free cep, return address
396 *---------------------------------------------------------------------------*/
398 find_matching_entry_incoming(msg_connect_ind_t *mp)
400 cfg_entry_t *cep = NULL;
403 /* check for CW (call waiting) early */
405 if(mp->channel == CHAN_NO)
409 char *src_tela = "ERROR-src_tela";
410 char *dst_tela = "ERROR-dst_tela";
412 src_tela = get_alias(mp->src_telno);
413 dst_tela = get_alias(mp->dst_telno);
415 log(LL_CHD, "%05d <unknown> CW from %s to %s (no channel free)",
416 mp->header.cdid, src_tela, dst_tela);
420 log(LL_CHD, "%05d <unknown> call waiting from %s to %s (no channel free)",
421 mp->header.cdid, mp->src_telno, mp->dst_telno);
426 for(i=0; i < nentries; i++)
429 cep = &cfg_entry_tab[i]; /* ptr to config entry */
431 /* check my number */
433 if(strncmp(cep->local_phone_incoming, mp->dst_telno, strlen(cep->local_phone_incoming)))
435 DBGL(DL_MSG, (log(LL_DBG, "find_matching_entry_incoming: entry %d, myno %s != incomingno %s", i,
436 cep->local_phone_incoming, mp->dst_telno)));
440 /* check all allowed remote number's for this entry */
442 for (n = 0; n < cep->incoming_numbers_count; n++)
444 incoming_number_t *in = &cep->remote_phone_incoming[n];
445 if(in->number[0] == '*')
447 if(strncmp(in->number, mp->src_telno, strlen(in->number)))
449 DBGL(DL_MSG, (log(LL_DBG, "find_matching_entry_incoming: entry %d, remno %s != incomingfromno %s", i,
450 in->number, mp->src_telno)));
455 if (n >= cep->incoming_numbers_count)
458 /* check b protocol */
460 if(cep->b1protocol != mp->bprot)
462 DBGL(DL_MSG, (log(LL_DBG, "find_matching_entry_incoming: entry %d, bprot %d != incomingprot %d", i,
463 cep->b1protocol, mp->bprot)));
467 /* is this entry currently in use ? */
469 if(cep->cdid != CDID_UNUSED)
471 if(cep->cdid == CDID_RESERVED)
473 DBGL(DL_MSG, (log(LL_DBG, "find_matching_entry_incoming: entry %d, cdid is reserved", i)));
475 else if (cep->dialin_reaction == REACT_ACCEPT
476 && cep->dialouttype == DIALOUT_CALLEDBACK)
479 * We might consider doing this even if this is
480 * not a calledback config entry - BUT: there are
481 * severe race conditions and timinig problems
482 * ex. if both sides run I4B with no callback
483 * delay - both may shutdown the outgoing call
484 * and never be able to establish a connection.
485 * In the called-back case this should not happen.
487 DBGL(DL_MSG, (log(LL_DBG, "find_matching_entry_incoming: entry %d, incoming call for callback in progress (cdid %05d)", i, cep->cdid)));
489 /* save the current call state, we're going to overwrite it with the
490 * new incoming state below... */
491 cep->saved_call.cdid = cep->cdid;
492 cep->saved_call.controller = cep->isdncontrollerused;
493 cep->saved_call.channel = cep->isdnchannelused;
497 DBGL(DL_MSG, (log(LL_DBG, "find_matching_entry_incoming: entry %d, cdid in use", i)));
498 continue; /* yes, next */
502 /* check controller value ok */
504 if(mp->controller > ncontroller)
506 log(LL_CHD, "%05d %s incoming call with invalid controller %d",
507 mp->header.cdid, cep->name, mp->controller);
511 /* check controller marked up */
513 if((get_controller_state(mp->controller)) != CTRL_UP)
515 log(LL_CHD, "%05d %s incoming call, controller %d DOWN!",
516 mp->header.cdid, cep->name, mp->controller);
521 * check controller he wants, check for any
522 * controller or specific controller
525 if( (mp->controller != -1) &&
526 (mp->controller != cep->isdncontroller) )
528 log(LL_CHD, "%05d %s incoming call, controller %d != incoming %d",
529 mp->header.cdid, cep->name,
530 cep->isdncontroller, mp->controller);
534 /* check channel he wants */
539 for (i = 0; i < isdn_ctrl_tab[mp->controller].nbch; i++)
541 if(ret_channel_state(mp->controller, i) == CHAN_IDLE)
545 if (i == isdn_ctrl_tab[mp->controller].nbch)
547 log(LL_CHD, "%05d %s incoming call, no channel free!",
548 mp->header.cdid, cep->name);
554 log(LL_CHD, "%05d %s incoming call, call waiting (no channel available)!",
555 mp->header.cdid, cep->name);
560 if((ret_channel_state(mp->controller, mp->channel)) != CHAN_IDLE)
562 log(LL_CHD, "%05d %s incoming call, channel B%d not free!",
563 mp->header.cdid, cep->name, mp->channel+1);
569 /* check time interval */
571 if(isvalidtime(cep) == 0)
573 DBGL(DL_MSG, (log(LL_DBG, "find_matching_entry_incoming: entry %d, time not valid!", i)));
577 /* found a matching entry */
579 cep->cdid = mp->header.cdid;
580 cep->isdncontrollerused = mp->controller;
581 cep->isdnchannelused = mp->channel;
582 /*XXX*/ cep->disc_cause = 0;
584 /* cp number to real one used */
586 strcpy(cep->real_phone_incoming, mp->src_telno);
588 /* copy display string */
590 strcpy(cep->display, mp->display);
592 /* entry currently down ? */
594 if(cep->state == ST_DOWN)
596 msg_updown_ind_t mui;
598 /* set interface up */
600 DBGL(DL_MSG, (log(LL_DBG, "find_matching_entry_incoming: entry %d, ", i)));
602 mui.driver = cep->usrdevicename;
603 mui.driver_unit = cep->usrdeviceunit;
604 mui.updown = SOFT_ENA;
606 if((ioctl(isdnfd, I4B_UPDOWN_IND, &mui)) < 0)
608 log(LL_ERR, "find_matching_entry_incoming: ioctl I4B_UPDOWN_IND failed: %s", strerror(errno));
609 error_exit(1, "find_matching_entry_incoming: ioctl I4B_UPDOWN_IND failed: %s", strerror(errno));
612 cep->down_retry_count = 0;
613 cep->state = ST_IDLE;
620 char *src_tela = "ERROR-src_tela";
621 char *dst_tela = "ERROR-dst_tela";
623 src_tela = get_alias(mp->src_telno);
624 dst_tela = get_alias(mp->dst_telno);
626 log(LL_CHD, "%05d Call from %s to %s",
627 mp->header.cdid, src_tela, dst_tela);
631 log(LL_CHD, "%05d <unknown> incoming call from %s to %s ctrl %d",
632 mp->header.cdid, mp->src_telno, mp->dst_telno, mp->controller);
637 /*---------------------------------------------------------------------------*
638 * return address of ACTIVE config entry by controller and channel
639 *---------------------------------------------------------------------------*/
641 get_cep_by_cc(int ctrlr, int chan)
645 if((chan < 0) || (chan >= isdn_ctrl_tab[ctrlr].nbch))
648 for(i=0; i < nentries; i++)
650 if((cfg_entry_tab[i].cdid != CDID_UNUSED) &&
651 (cfg_entry_tab[i].cdid != CDID_RESERVED) &&
652 (cfg_entry_tab[i].isdnchannelused == chan) &&
653 (cfg_entry_tab[i].isdncontrollerused == ctrlr) &&
654 ((ret_channel_state(ctrlr, chan)) == CHAN_RUN))
656 return(&cfg_entry_tab[i]);
662 /*---------------------------------------------------------------------------*
663 * return address of config entry identified by cdid
664 *---------------------------------------------------------------------------*/
666 get_cep_by_cdid(int cdid)
670 for(i=0; i < nentries; i++)
672 if(cfg_entry_tab[i].cdid == cdid
673 || cfg_entry_tab[i].saved_call.cdid == cdid)
674 return(&cfg_entry_tab[i]);
679 /*---------------------------------------------------------------------------*
680 * return b channel driver type name string
681 *---------------------------------------------------------------------------*/
683 bdrivername(int drivertype)
685 static char *bdtab[] = {
694 if(drivertype >= BDRV_RBCH && drivertype <= BDRV_ING)
695 return(bdtab[drivertype]);
700 /*---------------------------------------------------------------------------*
701 * process AOCD charging messages
702 *---------------------------------------------------------------------------*/
704 handle_charge(cfg_entry_t *cep)
706 time_t now = time(NULL);
708 if(cep->aoc_last == 0) /* no last timestamp yet ? */
710 cep->aoc_last = now; /* add time stamp */
712 else if(cep->aoc_now == 0) /* no current timestamp yet ? */
714 cep->aoc_now = now; /* current timestamp */
718 cep->aoc_last = cep->aoc_now;
720 cep->aoc_diff = cep->aoc_now - cep->aoc_last;
721 cep->aoc_valid = AOC_VALID;
729 #ifdef I4B_EXTERNAL_MONITOR
730 if(do_monitor && accepted)
731 monitor_evnt_charge(cep, cep->charge, 0);
734 if(cep->aoc_valid == AOC_VALID)
736 if(cep->aoc_diff != cep->unitlength)
738 DBGL(DL_MSG, (log(LL_DBG, "handle_charge: AOCD unit length updated %d -> %d secs", cep->unitlength, cep->aoc_diff)));
740 cep->unitlength = cep->aoc_diff;
747 DBGL(DL_MSG, (log(LL_DBG, "handle_charge: AOCD unit length still %d secs", cep->unitlength)));
753 /*---------------------------------------------------------------------------*
754 * update kernel idle_time, earlyhup_time and unitlen_time
755 *---------------------------------------------------------------------------*/
757 unitlen_chkupd(cfg_entry_t *cep)
759 msg_timeout_upd_t tupd;
761 tupd.cdid = cep->cdid;
763 /* init the short hold data based on the shorthold algorithm type */
765 switch(cep->shorthold_algorithm)
768 tupd.shorthold_data.shorthold_algorithm = SHA_FIXU;
769 tupd.shorthold_data.unitlen_time = cep->unitlength;
770 tupd.shorthold_data.idle_time = cep->idle_time_out;
771 tupd.shorthold_data.earlyhup_time = cep->earlyhangup;
775 tupd.shorthold_data.shorthold_algorithm = SHA_VARU;
776 tupd.shorthold_data.unitlen_time = cep->unitlength;
777 tupd.shorthold_data.idle_time = cep->idle_time_out;
778 tupd.shorthold_data.earlyhup_time = 0;
781 log(LL_ERR, "unitlen_chkupd bad shorthold_algorithm %d", cep->shorthold_algorithm );
786 if((ioctl(isdnfd, I4B_TIMEOUT_UPD, &tupd)) < 0)
788 log(LL_ERR, "ioctl I4B_TIMEOUT_UPD failed: %s", strerror(errno));
789 error_exit(1, "ioctl I4B_TIMEOUT_UPD failed: %s", strerror(errno));
793 /*--------------------------------------------------------------------------*
794 * this is intended to be called by do_exit and closes down all
795 * active connections before the daemon exits or is reconfigured.
796 *--------------------------------------------------------------------------*/
798 close_allactive(void)
801 cfg_entry_t *cep = NULL;
805 for (i = 0; i < ncontroller; i++)
807 if((get_controller_state(i)) != CTRL_UP)
810 for (k = 0; k < isdn_ctrl_tab[i].nbch; k++)
812 if((ret_channel_state(i, k)) == CHAN_RUN)
814 if((cep = get_cep_by_cc(i, k)) != NULL)
818 display_disconnect(cep);
820 #ifdef I4B_EXTERNAL_MONITOR
821 monitor_evnt_disconnect(cep);
823 next_state(cep, EV_DRQ);
832 log(LL_DMN, "close_allactive: waiting for all connections terminated");
837 /*--------------------------------------------------------------------------*
838 * set an interface up
839 *--------------------------------------------------------------------------*/
841 if_up(cfg_entry_t *cep)
843 msg_updown_ind_t mui;
845 /* set interface up */
847 DBGL(DL_MSG, (log(LL_DBG, "if_up: taking %s%d up", bdrivername(cep->usrdevicename), cep->usrdeviceunit)));
849 mui.driver = cep->usrdevicename;
850 mui.driver_unit = cep->usrdeviceunit;
851 mui.updown = SOFT_ENA;
853 if((ioctl(isdnfd, I4B_UPDOWN_IND, &mui)) < 0)
855 log(LL_ERR, "if_up: ioctl I4B_UPDOWN_IND failed: %s", strerror(errno));
856 error_exit(1, "if_up: ioctl I4B_UPDOWN_IND failed: %s", strerror(errno));
858 cep->down_retry_count = 0;
862 display_updown(cep, 1);
864 #ifdef I4B_EXTERNAL_MONITOR
865 monitor_evnt_updown(cep, 1);
870 /*--------------------------------------------------------------------------*
871 * set an interface down
872 *--------------------------------------------------------------------------*/
874 if_down(cfg_entry_t *cep)
876 msg_updown_ind_t mui;
878 /* set interface up */
880 DBGL(DL_MSG, (log(LL_DBG, "if_down: taking %s%d down", bdrivername(cep->usrdevicename), cep->usrdeviceunit)));
882 mui.driver = cep->usrdevicename;
883 mui.driver_unit = cep->usrdeviceunit;
884 mui.updown = SOFT_DIS;
886 if((ioctl(isdnfd, I4B_UPDOWN_IND, &mui)) < 0)
888 log(LL_ERR, "if_down: ioctl I4B_UPDOWN_IND failed: %s", strerror(errno));
889 error_exit(1, "if_down: ioctl I4B_UPDOWN_IND failed: %s", strerror(errno));
891 cep->went_down_time = time(NULL);
892 cep->down_retry_count = 0;
896 display_updown(cep, 0);
898 #ifdef I4B_EXTERNAL_MONITOR
899 monitor_evnt_updown(cep, 0);
904 /*--------------------------------------------------------------------------*
905 * send a dial response to (an interface in) the kernel
906 *--------------------------------------------------------------------------*/
908 dialresponse(cfg_entry_t *cep, int dstat)
910 msg_dialout_resp_t mdr;
912 static char *stattab[] = {
916 "dialout not allowed"
919 if(dstat < DSTAT_NONE || dstat > DSTAT_INONLY)
921 log(LL_ERR, "dialresponse: dstat out of range %d!", dstat);
925 mdr.driver = cep->usrdevicename;
926 mdr.driver_unit = cep->usrdeviceunit;
928 mdr.cause = cep->disc_cause;
930 if((ioctl(isdnfd, I4B_DIALOUT_RESP, &mdr)) < 0)
932 log(LL_ERR, "dialresponse: ioctl I4B_DIALOUT_RESP failed: %s", strerror(errno));
933 error_exit(1, "dialresponse: ioctl I4B_DIALOUT_RESP failed: %s", strerror(errno));
936 DBGL(DL_DRVR, (log(LL_DBG, "dialresponse: sent [%s]", stattab[dstat])));
939 /*--------------------------------------------------------------------------*
940 * screening/presentation indicator
941 *--------------------------------------------------------------------------*/
943 handle_scrprs(int cdid, int scr, int prs, char *caller)
945 /* screening indicator */
947 if(scr < SCR_NONE || scr > SCR_NET)
949 log(LL_ERR, "msg_connect_ind: invalid screening indicator value %d!", scr);
953 static char *scrtab[] = {
954 "no screening indicator",
955 "sreening user provided, not screened",
956 "screening user provided, verified & passed",
957 "screening user provided, verified & failed",
958 "screening network provided", };
962 log(LL_CHD, "%05d %s %s", cdid, caller, scrtab[scr]);
966 DBGL(DL_MSG, (log(LL_DBG, "%s - %s", caller, scrtab[scr])));
970 /* presentation indicator */
972 if(prs < PRS_NONE || prs > PRS_RESERVED)
974 log(LL_ERR, "msg_connect_ind: invalid presentation indicator value %d!", prs);
978 static char *prstab[] = {
979 "no presentation indicator",
980 "presentation allowed",
981 "presentation restricted",
982 "number not available due to interworking",
983 "reserved presentation value" };
987 log(LL_CHD, "%05d %s %s", cdid, caller, prstab[prs]);
991 DBGL(DL_MSG, (log(LL_DBG, "%s - %s", caller, prstab[prs])));
996 /*--------------------------------------------------------------------------*
997 * check if the time is valid for an entry
998 *--------------------------------------------------------------------------*/
1000 isvalidtime(cfg_entry_t *cep)
1013 if(isholiday(tp->tm_mday, (tp->tm_mon)+1, (tp->tm_year)+1900))
1015 DBGL(DL_VALID, (log(LL_DBG, "isvalidtime: holiday %d.%d.%d", tp->tm_mday, (tp->tm_mon)+1, (tp->tm_year)+1900)));
1020 if(cep->day & (1 << tp->tm_wday))
1022 DBGL(DL_VALID, (log(LL_DBG, "isvalidtime: day match")));
1029 if(cep->fromhr==0 && cep->frommin==0 && cep->tohr==0 && cep->tomin==0)
1031 DBGL(DL_VALID, (log(LL_DBG, "isvalidtime: no time specified, match!")));
1035 if(cep->tohr < cep->fromhr)
1039 if( (tp->tm_hour > cep->fromhr) ||
1040 (tp->tm_hour == cep->fromhr && tp->tm_min > cep->frommin) )
1042 DBGL(DL_VALID, (log(LL_DBG, "isvalidtime: t<f-1, spec=%02d:%02d-%02d:%02d, curr=%02d:%02d, match!",
1043 cep->fromhr, cep->frommin,
1044 cep->tohr, cep->tomin,
1045 tp->tm_hour, tp->tm_min)));
1052 if( (tp->tm_hour < cep->tohr) ||
1053 (tp->tm_hour == cep->tohr && tp->tm_min < cep->tomin) )
1055 DBGL(DL_VALID, (log(LL_DBG, "isvalidtime: t<f-2, spec=%02d:%02d-%02d:%02d, curr=%02d:%02d, match!",
1056 cep->fromhr, cep->frommin,
1057 cep->tohr, cep->tomin,
1058 tp->tm_hour, tp->tm_min)));
1063 else if(cep->fromhr == cep->tohr)
1065 if(tp->tm_min >= cep->frommin && tp->tm_min < cep->tomin)
1067 DBGL(DL_VALID, (log(LL_DBG, "isvalidtime: f=t, spec=%02d:%02d-%02d:%02d, curr=%02d:%02d, match!",
1068 cep->fromhr, cep->frommin,
1069 cep->tohr, cep->tomin,
1070 tp->tm_hour, tp->tm_min)));
1077 if((tp->tm_hour > cep->fromhr && tp->tm_hour < cep->tohr) ||
1078 (tp->tm_hour == cep->fromhr && tp->tm_min >= cep->frommin) ||
1079 (tp->tm_hour == cep->tohr && tp->tm_min < cep->tomin) )
1081 DBGL(DL_VALID, (log(LL_DBG, "isvalidtime: t>f, spec=%02d:%02d-%02d:%02d, curr=%02d:%02d, match!",
1082 cep->fromhr, cep->frommin,
1083 cep->tohr, cep->tomin,
1084 tp->tm_hour, tp->tm_min)));
1088 DBGL(DL_VALID, (log(LL_DBG, "isvalidtime: spec=%02d:%02d-%02d:%02d, curr=%02d:%02d, no match!",
1089 cep->fromhr, cep->frommin,
1090 cep->tohr, cep->tomin,
1091 tp->tm_hour, tp->tm_min)));