From 39ac1a5b83bcd9f684eb7ce7340a962356ec3c07 Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Tue, 23 May 2006 19:40:16 +0000 Subject: added a l1watcher timeout, therefore removed the old behaviour of guessing the l1state. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@29803 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/misdn/chan_misdn_config.h | 2 +- channels/misdn/isdn_lib.c | 51 ++++++++++++++++++++++++++++++-------- channels/misdn/isdn_lib.h | 2 ++ 3 files changed, 43 insertions(+), 12 deletions(-) (limited to 'channels/misdn') diff --git a/channels/misdn/chan_misdn_config.h b/channels/misdn/chan_misdn_config.h index 722c4bb78..b119ffc65 100644 --- a/channels/misdn/chan_misdn_config.h +++ b/channels/misdn/chan_misdn_config.h @@ -57,7 +57,6 @@ enum misdn_cfg_elements { MISDN_CFG_PICKUPGROUP, /* ast_group_t */ MISDN_CFG_MAX_IN, /* int */ MISDN_CFG_MAX_OUT, /* int */ - MISDN_CFG_L1_POLL, /* int */ MISDN_CFG_MSNS, /* char[] */ MISDN_CFG_PTP, /* int (bool) */ MISDN_CFG_LAST, @@ -73,6 +72,7 @@ enum misdn_cfg_elements { MISDN_GEN_DYNAMIC_CRYPT, /* int (bool) */ MISDN_GEN_CRYPT_PREFIX, /* char[] */ MISDN_GEN_CRYPT_KEYS, /* char[] */ + MISDN_GEN_L1_TIMEOUT, /* int */ MISDN_GEN_LAST }; diff --git a/channels/misdn/isdn_lib.c b/channels/misdn/isdn_lib.c index d2ae1440b..9cb689ce0 100644 --- a/channels/misdn/isdn_lib.c +++ b/channels/misdn/isdn_lib.c @@ -93,9 +93,12 @@ struct misdn_lib { int midev; int midev_nt; + pthread_t l1watcher_thread; pthread_t event_thread; pthread_t event_handler_thread; - + + int l1watcher_timeout; + void *user_data; msg_queue_t upqueue; @@ -145,6 +148,7 @@ static struct misdn_lib *glob_mgr; unsigned char tone_425_flip[TONE_425_SIZE]; unsigned char tone_silence_flip[TONE_SILENCE_SIZE]; +static void misdn_lib_isdn_l1watcher(void *arg); static void misdn_lib_isdn_event_catcher(void *arg); static int handle_event_nt(void *dat, void *arg); @@ -2508,20 +2512,12 @@ int handle_mgmt(msg_t *msg) break; case SSTATUS_L1_DEACTIVATED: cb_log(1, 0, "MGMT: SSTATUS: L1_DEACTIVATED \n"); - - /*reopen L1 if down*/ - if (stack->l1link==2) - stack->l1link--; - else - stack->l1link=0; - + stack->l1link=0; break; case SSTATUS_L2_ESTABLISHED: cb_log(1, stack->port, "MGMT: SSTATUS: L2_ESTABLISH \n"); stack->l2link=1; - if ( !stack->ptp && !stack->nt ) - stack->l1link=2; break; case SSTATUS_L2_RELEASED: @@ -2603,6 +2599,33 @@ msg_t *fetch_msg(int midev) return NULL; } +static void misdn_lib_isdn_l1watcher(void *arg) +{ + struct misdn_lib *mgr = arg; + struct misdn_stack *stack; + + while (1) { + sleep(mgr->l1watcher_timeout); + + /* look out for l1 which are down + and try to pull the up. + + We might even try to pull the l2 up in the + ptp case. + */ + for (stack = mgr->stack_list; + stack; + stack = stack->next) { + cb_log(4,stack->port,"Checking L1 State\n"); + if (!stack->l1link) { + cb_log(4,stack->port,"L1 State Down, trying to get it up again\n"); + misdn_lib_get_short_status(stack); + misdn_lib_get_l1_up(stack); + misdn_lib_get_l2_up(stack); + } + } + } +} static void misdn_lib_isdn_event_catcher(void *arg) { @@ -3447,7 +3470,13 @@ int misdn_lib_init(char *portlist, struct misdn_lib_iface *iface, void *user_dat pthread_create( &mgr->event_thread, NULL, (void*)misdn_lib_isdn_event_catcher, mgr); cb_log(4, 0, "Event Catcher started\n"); - + + if (iface->l1watcher_timeout > 0) { + mgr->l1watcher_timeout=iface->l1watcher_timeout; + cb_log(4, 0, "Starting L1 watcher\n"); + pthread_create( &mgr->l1watcher_thread, NULL, (void*)misdn_lib_isdn_l1watcher, mgr); + } + global_state= MISDN_INITIALIZED; return (mgr == NULL); diff --git a/channels/misdn/isdn_lib.h b/channels/misdn/isdn_lib.h index 9cd091e8a..26e618771 100644 --- a/channels/misdn/isdn_lib.h +++ b/channels/misdn/isdn_lib.h @@ -321,6 +321,8 @@ struct misdn_lib_iface { enum event_response_e (*cb_event)(enum event_e event, struct misdn_bchannel *bc, void *user_data); void (*cb_log)(int level, int port, char *tmpl, ...); int (*cb_jb_empty)(struct misdn_bchannel *bc, char *buffer, int len); + + int l1watcher_timeout; }; /***** USER IFACE **********/ -- cgit v1.2.3