From abb8f08bbbf7d22a96f876a3ca7029fa1c63a93a Mon Sep 17 00:00:00 2001 From: Konrad Hammel Date: Thu, 23 Sep 2010 11:04:10 -0400 Subject: [PATCH 1/8] freetdm: ss7 - bug fixes --- .../ftmod_sangoma_ss7/ftmod_sangoma_ss7_cfg.c | 36 ++-- .../ftmod_sangoma_ss7/ftmod_sangoma_ss7_cli.c | 15 ++ .../ftmod_sangoma_ss7_cntrl.c | 6 +- .../ftmod_sangoma_ss7_handle.c | 144 ++++----------- .../ftmod_sangoma_ss7_main.c | 44 ++++- .../ftmod_sangoma_ss7_main.h | 18 +- .../ftmod_sangoma_ss7_support.c | 164 ++++++++++++++++++ 7 files changed, 290 insertions(+), 137 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cfg.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cfg.c index 21ab1d32d2..21feb4f8fe 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cfg.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cfg.c @@ -85,35 +85,35 @@ int ft_to_sngss7_cfg_all(void) if (ftmod_ss7_mtp1_gen_config()) { SS7_CRITICAL("MTP1 General configuration FAILED!\n"); - SS7_ASSERT + return 1; } else { SS7_INFO("MTP1 General configuration DONE\n"); } if (ftmod_ss7_mtp2_gen_config()) { SS7_CRITICAL("MTP2 General configuration FAILED!\n"); - SS7_ASSERT + return 1; } else { SS7_INFO("MTP2 General configuration DONE\n"); } if (ftmod_ss7_mtp3_gen_config()) { SS7_CRITICAL("MTP3 General configuration FAILED!\n"); - SS7_ASSERT + return 1; } else { SS7_INFO("MTP3 General configuration DONE\n"); } if (ftmod_ss7_isup_gen_config()) { SS7_CRITICAL("ISUP General configuration FAILED!\n"); - SS7_ASSERT + return 1; } else { SS7_INFO("ISUP General configuration DONE\n"); } if (ftmod_ss7_cc_gen_config()) { SS7_CRITICAL("CC General configuration FAILED!\n"); - SS7_ASSERT + return 1; } else { SS7_INFO("CC General configuration DONE\n"); } @@ -131,7 +131,7 @@ int ft_to_sngss7_cfg_all(void) /* configure mtp1 */ if (ftmod_ss7_mtp1_psap_config(x)) { SS7_CRITICAL("MTP1 PSAP %d configuration FAILED!\n", x); - SS7_ASSERT; + return 1;; } else { SS7_INFO("MTP1 PSAP %d configuration DONE!\n", x); } @@ -139,7 +139,7 @@ int ft_to_sngss7_cfg_all(void) /* configure mtp2 */ if (ftmod_ss7_mtp2_dlsap_config(x)) { SS7_CRITICAL("MTP2 DLSAP %d configuration FAILED!\n",x); - SS7_ASSERT; + return 1;; } else { SS7_INFO("MTP2 DLSAP %d configuration DONE!\n", x); } @@ -147,7 +147,7 @@ int ft_to_sngss7_cfg_all(void) /* configure mtp3 */ if (ftmod_ss7_mtp3_dlsap_config(x)) { SS7_CRITICAL("MTP3 DLSAP %d configuration FAILED!\n", x); - SS7_ASSERT; + return 1;; } else { SS7_INFO("MTP3 DLSAP %d configuration DONE!\n", x); } @@ -166,14 +166,14 @@ int ft_to_sngss7_cfg_all(void) if (ftmod_ss7_mtp3_nsap_config(x)) { SS7_CRITICAL("MTP3 NSAP %d configuration FAILED!\n", x); - SS7_ASSERT + return 1; } else { SS7_INFO("MTP3 NSAP %d configuration DONE!\n", x); } if (ftmod_ss7_isup_nsap_config(x)) { SS7_CRITICAL("ISUP NSAP %d configuration FAILED!\n", x); - SS7_ASSERT + return 1; } else { SS7_INFO("ISUP NSAP %d configuration DONE!\n", x); } @@ -192,7 +192,7 @@ int ft_to_sngss7_cfg_all(void) if (ftmod_ss7_mtp3_linkset_config(x)) { SS7_CRITICAL("MTP3 LINKSET %d configuration FAILED!\n", x); - SS7_ASSERT + return 1; } else { SS7_INFO("MTP3 LINKSET %d configuration DONE!\n", x); } @@ -211,7 +211,7 @@ int ft_to_sngss7_cfg_all(void) if (ftmod_ss7_mtp3_route_config(x)) { SS7_CRITICAL("MTP3 ROUTE %d configuration FAILED!\n", x); - SS7_ASSERT + return 1; } else { SS7_INFO("MTP3 ROUTE %d configuration DONE!\n",x); } @@ -227,7 +227,7 @@ int ft_to_sngss7_cfg_all(void) if (ftmod_ss7_mtp3_route_config(0)) { SS7_CRITICAL("MTP3 ROUTE 0 configuration FAILED!\n"); - SS7_ASSERT + return 1; } else { SS7_INFO("MTP3 ROUTE 0 configuration DONE!\n"); } @@ -244,14 +244,14 @@ int ft_to_sngss7_cfg_all(void) if (ftmod_ss7_isup_isap_config(x)) { SS7_CRITICAL("ISUP ISAP %d configuration FAILED!\n", x); - SS7_ASSERT + return 1; } else { SS7_INFO("ISUP ISAP %d configuration DONE!\n", x); } if (ftmod_ss7_cc_isap_config(x)) { SS7_CRITICAL("CC ISAP %d configuration FAILED!\n", x); - SS7_ASSERT + return 1; } else { SS7_INFO("CC ISAP %d configuration DONE!\n", x); } @@ -270,9 +270,11 @@ int ft_to_sngss7_cfg_all(void) if (ftmod_ss7_isup_intf_config(x)) { SS7_CRITICAL("ISUP INTF %d configuration FAILED!\n", x); - SS7_ASSERT + return 1; } else { SS7_INFO("ISUP INTF %d configuration DONE!\n", x); + /* set the interface to paused */ + sngss7_set_flag(&g_ftdm_sngss7_data.cfg.isupIntf[x], SNGSS7_PAUSED); } /* set the CONFIGURED flag */ @@ -289,7 +291,7 @@ int ft_to_sngss7_cfg_all(void) if ( g_ftdm_sngss7_data.cfg.isupCkt[x].type == 0) { if (ftmod_ss7_isup_ckt_config(x)) { SS7_CRITICAL("ISUP CKT %d configuration FAILED!\n", x); - SS7_ASSERT + return 1; } else { SS7_INFO("ISUP CKT %d configuration DONE!\n", x); } diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cli.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cli.c index cf56f51a0a..6ccc693478 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cli.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cli.c @@ -1156,7 +1156,12 @@ static ftdm_status_t handle_tx_blo(ftdm_stream_handle_t *stream, int span, int c /* check if there is a pending state change|give it a bit to clear */ if (check_for_state_change(ftdmchan)) { SS7_ERROR("Failed to wait for pending state change on CIC = %d\n", ss7_info->circuit->cic); + /* check if we need to die */ SS7_ASSERT; + /* unlock the channel again before we exit */ + ftdm_mutex_unlock(ftdmchan->mutex); + /* move to the next channel */ + continue; } else { /* throw the ckt block flag */ sngss7_set_flag(ss7_info, FLAG_CKT_MN_BLOCK_TX); @@ -1217,7 +1222,12 @@ static ftdm_status_t handle_tx_ubl(ftdm_stream_handle_t *stream, int span, int c /* check if there is a pending state change|give it a bit to clear */ if (check_for_state_change(ftdmchan)) { SS7_ERROR("Failed to wait for pending state change on CIC = %d\n", ss7_info->circuit->cic); + /* check if we need to die */ SS7_ASSERT; + /* unlock the channel again before we exit */ + ftdm_mutex_unlock(ftdmchan->mutex); + /* move to the next channel */ + continue; } else { /* throw the ckt block flag */ sngss7_set_flag(ss7_info, FLAG_CKT_MN_UNBLK_TX); @@ -1466,7 +1476,12 @@ static ftdm_status_t handle_tx_grs(ftdm_stream_handle_t *stream, int span, int c /* check if there is a pending state change|give it a bit to clear */ if (check_for_state_change(ftdmchan)) { SS7_ERROR("Failed to wait for pending state change on CIC = %d\n", sngss7_info->circuit->cic); + /* check if we need to die */ SS7_ASSERT; + /* unlock the channel again before we exit */ + ftdm_mutex_unlock(ftdmchan->mutex); + /* move to the next channel */ + continue; } else { /* throw the grp reset flag */ sngss7_set_flag(sngss7_info, FLAG_GRP_RESET_TX); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cntrl.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cntrl.c index 0d76329d25..87733dd594 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cntrl.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_cntrl.c @@ -75,7 +75,7 @@ int ft_to_sngss7_activate_all(void) if (ftmod_ss7_enable_isap(x)) { SS7_CRITICAL("ISAP %d Enable: NOT OK\n", x); - SS7_ASSERT; + return 1; } else { SS7_INFO("ISAP %d Enable: OK\n", x); } @@ -94,7 +94,7 @@ int ft_to_sngss7_activate_all(void) if (ftmod_ss7_enable_nsap(x)) { SS7_CRITICAL("NSAP %d Enable: NOT OK\n", x); - SS7_ASSERT; + return 1; } else { SS7_INFO("NSAP %d Enable: OK\n", x); } @@ -113,7 +113,7 @@ int ft_to_sngss7_activate_all(void) if (ftmod_ss7_enable_mtpLinkSet(x)) { SS7_CRITICAL("LinkSet \"%s\" Enable: NOT OK\n", g_ftdm_sngss7_data.cfg.mtpLinkSet[x].name); - SS7_ASSERT; + return 1; } else { SS7_INFO("LinkSet \"%s\" Enable: OK\n", g_ftdm_sngss7_data.cfg.mtpLinkSet[x].name); } diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_handle.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_handle.c index 5e6a246ba2..ac7a61646f 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_handle.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_handle.c @@ -1029,6 +1029,9 @@ ftdm_status_t handle_pause(uint32_t suInstId, uint32_t spInstId, uint32_t circui /* extract the affected infId from the circuit structure */ infId = g_ftdm_sngss7_data.cfg.isupCkt[circuit].infId; + + /* set the interface to paused */ + sngss7_set_flag(&g_ftdm_sngss7_data.cfg.isupIntf[infId], SNGSS7_PAUSED); /* go through all the circuits now and find any other circuits on this infId */ i = 1; @@ -1050,6 +1053,7 @@ ftdm_status_t handle_pause(uint32_t suInstId, uint32_t spInstId, uint32_t circui /* check if the circuit is fully started */ if (ftdm_test_flag(ftdmchan->span, FTDM_SPAN_IN_THREAD)) { + SS7_DEBUG_CHAN(ftdmchan, "Rx PAUSE%s\n", ""); /* set the pause flag on the channel */ sngss7_set_flag(sngss7_info, FLAG_INFID_PAUSED); } @@ -1081,6 +1085,9 @@ ftdm_status_t handle_resume(uint32_t suInstId, uint32_t spInstId, uint32_t circu /* extract the affect infId from the circuit structure */ infId = g_ftdm_sngss7_data.cfg.isupCkt[circuit].infId; + /* set the interface to resumed */ + sngss7_clear_flag(&g_ftdm_sngss7_data.cfg.isupIntf[infId], SNGSS7_PAUSED); + /* go through all the circuits now and find any other circuits on this infId */ i = 1; while (g_ftdm_sngss7_data.cfg.isupCkt[i].id != 0) { @@ -1101,6 +1108,8 @@ ftdm_status_t handle_resume(uint32_t suInstId, uint32_t spInstId, uint32_t circu /* only resume if we are paused */ if (sngss7_test_flag(sngss7_info, FLAG_INFID_PAUSED)) { + SS7_DEBUG_CHAN(ftdmchan, "Rx RESUME%s\n", ""); + /* set the resume flag on the channel */ sngss7_set_flag(sngss7_info, FLAG_INFID_RESUME); @@ -1527,7 +1536,7 @@ ftdm_status_t handle_grs_req(uint32_t suInstId, uint32_t spInstId, uint32_t circ ftdm_channel_t *ftdmchan = NULL; sngss7_span_data_t *sngss7_span = NULL; int range; - int x; + if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) { SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit); @@ -1544,51 +1553,12 @@ ftdm_status_t handle_grs_req(uint32_t suInstId, uint32_t spInstId, uint32_t circ return FTDM_FAIL; } - /* loop over the cics starting from circuit until range+1 */ - for (x = circuit; x < (circuit + range + 1); x++) { - if (g_ftdm_sngss7_data.cfg.isupCkt[x].type != VOICE) continue; - /* grab the circuit in question */ - if (extract_chan_data(x, &sngss7_info, &ftdmchan)) { - SS7_ERROR("Failed to extract channel data for circuit = %d!\n", x); - break; - } - - /* lock the channel */ - ftdm_mutex_lock(ftdmchan->mutex); + /* fill in the span structure for this circuit */ + sngss7_span = ftdmchan->span->mod_data; + sngss7_span->rx_grs.circuit = circuit; + sngss7_span->rx_grs.range = range; - /* fill in the span structure for this circuit */ - sngss7_span = ftdmchan->span->mod_data; - sngss7_span->rx_grs.circuit = circuit; - sngss7_span->rx_grs.range = range; - - SS7_INFO_CHAN(ftdmchan, "Rx GRS (%d:%d)\n", - g_ftdm_sngss7_data.cfg.isupCkt[circuit].cic, - (g_ftdm_sngss7_data.cfg.isupCkt[circuit].cic + range)); - - /* flag the channel as having received a reset */ - sngss7_set_flag(sngss7_info, FLAG_GRP_RESET_RX); - - switch (ftdmchan->state) { - /**************************************************************************/ - case FTDM_CHANNEL_STATE_RESTART: - - /* go to idle so that we can redo the restart state*/ - ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_IDLE); - - break; - /**************************************************************************/ - default: - - /* set the state of the channel to restart...the rest is done by the chan monitor */ - ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART); - break; - /**************************************************************************/ - } - - /* unlock the channel again before we exit */ - ftdm_mutex_unlock(ftdmchan->mutex); - - } + /* the reset will be started in the main thread by "check_if_rx_grs_started" */ SS7_FUNC_TRACE_EXIT(__FUNCTION__); return FTDM_SUCCESS; @@ -1599,10 +1569,16 @@ ftdm_status_t handle_grs_rsp(uint32_t suInstId, uint32_t spInstId, uint32_t circ { SS7_FUNC_TRACE_ENTER(__FUNCTION__); - sngss7_chan_data_t *sngss7_info = NULL; - ftdm_channel_t *ftdmchan = NULL; + sngss7_chan_data_t *sngss7_info = NULL; + ftdm_channel_t *ftdmchan = NULL; + sngss7_span_data_t *sngss7_span = NULL; int range; - int x; + + if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) { + SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit); + SS7_FUNC_TRACE_EXIT(__FUNCTION__); + return FTDM_FAIL; + } /* extract the range value from the event structure */ if ((siStaEvnt->rangStat.eh.pres == PRSNT_NODEF) && (siStaEvnt->rangStat.range.pres == PRSNT_NODEF)) { @@ -1613,70 +1589,20 @@ ftdm_status_t handle_grs_rsp(uint32_t suInstId, uint32_t spInstId, uint32_t circ return FTDM_FAIL; } - /* go through all the circuits in the range */ - for ( x = circuit; x < (circuit + range + 1); x++) { + /* fill in the span structure for this circuit */ + sngss7_span = ftdmchan->span->mod_data; + sngss7_span->rx_gra.circuit = circuit; + sngss7_span->rx_gra.range = range; - /* grab the circuit in question */ - if (extract_chan_data(x, &sngss7_info, &ftdmchan)) { - SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit); - break; - } + /* check if there is a cause value in the GRA */ + if ((siStaEvnt != NULL) && + (siStaEvnt->causeDgn.eh.pres == PRSNT_NODEF) && + (siStaEvnt->causeDgn.causeVal.pres == PRSNT_NODEF)) { - /* lock the channel */ - ftdm_mutex_lock(ftdmchan->mutex); - - SS7_INFO_CHAN(ftdmchan, "Rx GRA (%d:%d)\n", - g_ftdm_sngss7_data.cfg.isupCkt[circuit].cic, - (g_ftdm_sngss7_data.cfg.isupCkt[circuit].cic + range)); + sngss7_span->rx_gra.cause = siStaEvnt->causeDgn.causeVal.val; + } - switch (ftdmchan->state) { - /**********************************************************************/ - case FTDM_CHANNEL_STATE_RESTART: - - /* throw the FLAG_RESET_TX_RSP to indicate we have acknowledgement from the remote side */ - sngss7_set_flag(sngss7_info, FLAG_GRP_RESET_TX_RSP); - - /* go to DOWN */ - ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); - - break; - /**********************************************************************/ - case FTDM_CHANNEL_STATE_DOWN: - - /* do nothing, just drop the message */ - SS7_DEBUG("Receveived GRA in down state, dropping\n"); - - break; - /**********************************************************************/ - case FTDM_CHANNEL_STATE_TERMINATING: - case FTDM_CHANNEL_STATE_HANGUP: - case FTDM_CHANNEL_STATE_HANGUP_COMPLETE: - - /* throw the FLAG_RESET_TX_RSP to indicate we have acknowledgement from the remote side */ - sngss7_set_flag(sngss7_info, FLAG_GRP_RESET_TX_RSP); - - break; - /**********************************************************************/ - default: - /* ITU Q764-2.9.5.1.c -> release the circuit */ - if ((siStaEvnt != NULL) && - (siStaEvnt->causeDgn.eh.pres ==PRSNT_NODEF) && - (siStaEvnt->causeDgn.causeVal.pres == PRSNT_NODEF)) { - ftdmchan->caller_data.hangup_cause = siStaEvnt->causeDgn.causeVal.val; - } else { - ftdmchan->caller_data.hangup_cause = 98; /* Message not compatiable with call state */ - } - - /* go to terminating to hang up the call */ - ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING); - break; - /**********************************************************************/ - } - - /* unlock the channel again before we exit */ - ftdm_mutex_unlock(ftdmchan->mutex); - - } /* for (( x = 0; x < (circuit + range); x++) */ + /* the reset will be started in the main thread by "check_if_rx_gra_started" */ SS7_FUNC_TRACE_EXIT(__FUNCTION__); return FTDM_SUCCESS; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c index 3ef8db53d1..ce9423cd00 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c @@ -46,7 +46,7 @@ ftdm_sngss7_data_t g_ftdm_sngss7_data; /* PROTOTYPES *****************************************************************/ static void *ftdm_sangoma_ss7_run (ftdm_thread_t * me, void *obj); -static void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t *ftdmchan); +void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t *ftdmchan); static void ftdm_sangoma_ss7_process_stack_event (sngss7_event_data_t *sngss7_event); static ftdm_status_t ftdm_sangoma_ss7_stop (ftdm_span_t * span); @@ -342,8 +342,16 @@ static void *ftdm_sangoma_ss7_run(ftdm_thread_t * me, void *obj) /**********************************************************************/ } /* switch ((ftdm_interrupt_wait(ftdm_sangoma_ss7_int, 100))) */ + /* check if there is a GRA to proccess on the span */ + if (sngss7_span->rx_gra.range > 0) { + check_if_rx_gra_started(ftdmspan); + } /* if (sngss7->span->rx_gra.range > 0) */ + /* check if there is a GRS being processed on the span */ if (sngss7_span->rx_grs.range > 0) { + /* check if the rx_grs has started */ + check_if_rx_grs_started(ftdmspan); + /* check if the rx_grs has cleared */ check_if_rx_grs_processed(ftdmspan); } /* if (sngss7_span->rx_grs.range > 0) */ @@ -452,7 +460,7 @@ static void ftdm_sangoma_ss7_process_stack_event (sngss7_event_data_t *sngss7_ev } /******************************************************************************/ -static void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) +void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) { sngss7_chan_data_t *sngss7_info = ftdmchan->call_data; int i = 0; @@ -727,6 +735,11 @@ static void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) /**************************************************************************/ case FTDM_CHANNEL_STATE_DOWN: /*the call is finished and removed */ + if (ftdmchan->last_state == FTDM_CHANNEL_STATE_SUSPENDED) { + SS7_DEBUG("re-entering state from processing block/unblock request ... do nothing\n"); + break; + } + /* check if there is a reset response that needs to be sent */ if (sngss7_test_flag (sngss7_info, FLAG_RESET_RX)) { /* send a RSC-RLC */ @@ -776,6 +789,11 @@ static void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_TX); sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_BASE); sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_SENT); + + /* clean out the spans GRA structure */ + sngss7_span_data_t *span = ftdmchan->span->mod_data; + span->rx_gra.circuit = 0; + span->rx_gra.range = 0; } /* check if we came from reset (aka we just processed a reset) */ @@ -965,6 +983,7 @@ static void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) /**********************************************************************/ if (sngss7_test_flag(sngss7_info, FLAG_INFID_RESUME)) { + SS7_DEBUG_CHAN(ftdmchan, "Processing RESUME%s\n", ""); /* clear the RESUME flag */ sngss7_clear_flag(sngss7_info, FLAG_INFID_RESUME); @@ -990,6 +1009,7 @@ static void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) } /* if (sngss7_test_flag(sngss7_info, FLAG_INFID_RESUME)) */ if (sngss7_test_flag(sngss7_info, FLAG_INFID_PAUSED)) { + SS7_DEBUG_CHAN(ftdmchan, "Processing PAUSE%s\n", ""); /* bring the sig status down */ sigev.event_id = FTDM_SIGEVENT_SIGSTATUS_CHANGED; @@ -1165,9 +1185,10 @@ static FIO_CHANNEL_OUTGOING_CALL_FUNCTION(ftdm_sangoma_ss7_outgoing_call) /* check if there is a pending state change, give it a bit to clear */ if (check_for_state_change(ftdmchan)) { SS7_ERROR("Failed to wait for pending state change on CIC = %d\n", sngss7_info->circuit->cic); - ftdm_mutex_unlock(ftdmchan->mutex); - SS7_FUNC_TRACE_EXIT(__FUNCTION__); + /* check if we need to die */ SS7_ASSERT; + /* end the request */ + goto outgoing_fail; }; /* check if the channel sig state is UP */ @@ -1278,6 +1299,7 @@ static ftdm_status_t ftdm_sangoma_ss7_start(ftdm_span_t * span) ftdm_channel_t *ftdmchan = NULL; sngss7_chan_data_t *sngss7_info = NULL; sngss7_span_data_t *sngss7_span = NULL; + sng_isup_inf_t *sngss7_intf = NULL; int x; @@ -1290,12 +1312,22 @@ static ftdm_status_t ftdm_sangoma_ss7_start(ftdm_span_t * span) if (ftdmchan->call_data == NULL) continue; sngss7_info = ftdmchan->call_data; sngss7_span = ftdmchan->span->mod_data; + sngss7_intf = &g_ftdm_sngss7_data.cfg.isupIntf[sngss7_info->circuit->infId]; + /* lock the channel */ ftdm_mutex_lock(ftdmchan->mutex); - /* throw the pause flag */ - sngss7_set_flag(sngss7_info, FLAG_INFID_PAUSED); + /* check if the interface is paused or resumed */ + if (sngss7_test_flag(sngss7_intf, SNGSS7_PAUSED)) { + /* throw the pause flag */ + sngss7_clear_flag(sngss7_info, FLAG_INFID_RESUME); + sngss7_set_flag(sngss7_info, FLAG_INFID_PAUSED); + } else { + /* throw the pause flag */ + sngss7_clear_flag(sngss7_info, FLAG_INFID_PAUSED); + sngss7_set_flag(sngss7_info, FLAG_INFID_RESUME); + } #if 0 /* throw the grp reset flag */ sngss7_set_flag(sngss7_info, FLAG_GRP_RESET_TX); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.h b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.h index 850bbf0d1a..ae2412381c 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.h @@ -79,7 +79,8 @@ typedef enum { typedef enum { CONFIGURED = (1 << 0), - ACTIVE = (1 << 1) + ACTIVE = (1 << 1), + SNGSS7_PAUSED = (1 << 7) } sng_flag_t; typedef struct sng_mtp_link { @@ -335,6 +336,7 @@ typedef struct sngss7_group_data { uint32_t range; uint8_t status[255]; uint8_t type; + uint8_t cause; }sngss7_group_data_t; typedef struct sngss7_chan_data { @@ -353,6 +355,7 @@ typedef struct sngss7_chan_data { typedef struct sngss7_span_data { ftdm_sched_t *sched; sngss7_group_data_t rx_grs; + sngss7_group_data_t rx_gra; sngss7_group_data_t tx_grs; sngss7_group_data_t rx_cgb; sngss7_group_data_t tx_cgb; @@ -427,6 +430,8 @@ extern int cmbLinkSetId; /******************************************************************************/ /* PROTOTYPES *****************************************************************/ +void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t *ftdmchan); + void handle_sng_log(uint8_t level, char *fmt,...); void handle_sng_mtp1_alarm(Pst *pst, L1Mngmt *sta); void handle_sng_mtp2_alarm(Pst *pst, SdMngmt *sta); @@ -546,7 +551,9 @@ void handle_isup_t35(void *userdata); ftdm_status_t ftdm_sngss7_handle_cli_cmd(ftdm_stream_handle_t *stream, const char *data); +ftdm_status_t check_if_rx_grs_started(ftdm_span_t *ftdmspan); ftdm_status_t check_if_rx_grs_processed(ftdm_span_t *ftdmspan); +ftdm_status_t check_if_rx_gra_started(ftdm_span_t *ftdmspan); ftdm_status_t check_for_res_sus_flag(ftdm_span_t *ftdmspan); /******************************************************************************/ @@ -678,7 +685,14 @@ ftdm_status_t check_for_res_sus_flag(ftdm_span_t *ftdmspan); #define sngss7_clear_flag(obj, flag) ((obj)->flags &= ~(flag)) #define sngss7_set_flag(obj, flag) ((obj)->flags |= (flag)) -# define SS7_ASSERT *(int*)0=0; +#ifdef SS7_PRODUCTION +# define SS7_ASSERT \ + SS7_INFO_CHAN(ftdmchan,"Production Mode, continuing%s\n", ""); +#else +# define SS7_ASSERT \ + SS7_ERROR_CHAN(ftdmchan, "Debugging Mode, ending%s\n", ""); \ + *(int*)0=0; +#endif /******************************************************************************/ /******************************************************************************/ diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_support.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_support.c index aaffeb0a36..8e7c6496aa 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_support.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_support.c @@ -57,7 +57,9 @@ unsigned long get_unique_id(void); ftdm_status_t extract_chan_data(uint32_t circuit, sngss7_chan_data_t **sngss7_info, ftdm_channel_t **ftdmchan); +ftdm_status_t check_if_rx_grs_started(ftdm_span_t *ftdmspan); ftdm_status_t check_if_rx_grs_processed(ftdm_span_t *ftdmspan); +ftdm_status_t check_if_rx_gra_started(ftdm_span_t *ftdmspan); ftdm_status_t check_for_res_sus_flag(ftdm_span_t *ftdmspan); /******************************************************************************/ @@ -445,6 +447,68 @@ unsigned long get_unique_id(void) return(sngss7_id); } +/******************************************************************************/ +ftdm_status_t check_if_rx_grs_started(ftdm_span_t *ftdmspan) +{ + ftdm_channel_t *ftdmchan = NULL; + sngss7_chan_data_t *sngss7_info = NULL; + sngss7_span_data_t *sngss7_span = (sngss7_span_data_t *)ftdmspan->mod_data; + int i; + + for ( i = sngss7_span->rx_grs.circuit; i < (sngss7_span->rx_grs.circuit + sngss7_span->rx_grs.range + 1); i++) { + + /* extract the channel in question */ + if (extract_chan_data(i, &sngss7_info, &ftdmchan)) { + SS7_ERROR("Failed to extract channel data for circuit = %d!\n", i); + continue; + } + + /* check if the GRP_RESET_RX flag is already up */ + if (sngss7_test_flag(sngss7_info, FLAG_GRP_RESET_RX)) { + /* we have already processed this channel...move along */ + continue; + } + + /* lock the channel */ + ftdm_mutex_lock(ftdmchan->mutex); + + /* clear up any pending state changes */ + while (ftdm_test_flag (ftdmchan, FTDM_CHANNEL_STATE_CHANGE)) { + ftdm_sangoma_ss7_process_state_change (ftdmchan); + } + + SS7_INFO_CHAN(ftdmchan, "Rx GRS (%d:%d)\n", + g_ftdm_sngss7_data.cfg.isupCkt[sngss7_span->rx_grs.circuit].cic, + (g_ftdm_sngss7_data.cfg.isupCkt[sngss7_span->rx_grs.circuit].cic + sngss7_span->rx_grs.range)); + + /* flag the channel as having received a reset */ + sngss7_set_flag(sngss7_info, FLAG_GRP_RESET_RX); + + switch (ftdmchan->state) { + /**************************************************************************/ + case FTDM_CHANNEL_STATE_RESTART: + + /* go to idle so that we can redo the restart state*/ + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_IDLE); + + break; + /**************************************************************************/ + default: + + /* set the state of the channel to restart...the rest is done by the chan monitor */ + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_RESTART); + break; + /**************************************************************************/ + } /* switch (ftdmchan->state) */ + + /* unlock the channel again before we exit */ + ftdm_mutex_unlock(ftdmchan->mutex); + + } /* for (chans in GRS */ + + return FTDM_SUCCESS; +} + /******************************************************************************/ ftdm_status_t check_if_rx_grs_processed(ftdm_span_t *ftdmspan) { @@ -493,7 +557,10 @@ ftdm_status_t check_if_rx_grs_processed(ftdm_span_t *ftdmspan) /* extract the channel in question */ if (extract_chan_data(i, &sngss7_info, &ftdmchan)) { SS7_ERROR("Failed to extract channel data for circuit = %d!\n",i); + /* check if we need to die */ SS7_ASSERT; + /* move along */ + continue; } /* throw the GRP reset flag complete flag */ @@ -534,6 +601,91 @@ GRS_UNLOCK_ALL: return FTDM_SUCCESS; } +/******************************************************************************/ +ftdm_status_t check_if_rx_gra_started(ftdm_span_t *ftdmspan) +{ + ftdm_channel_t *ftdmchan = NULL; + sngss7_chan_data_t *sngss7_info = NULL; + sngss7_span_data_t *sngss7_span = (sngss7_span_data_t *)ftdmspan->mod_data; + int i; + + for ( i = sngss7_span->rx_gra.circuit; i < (sngss7_span->rx_gra.circuit + sngss7_span->rx_gra.range + 1); i++) { + + /* extract the channel in question */ + if (extract_chan_data(i, &sngss7_info, &ftdmchan)) { + SS7_ERROR("Failed to extract channel data for circuit = %d!\n", i); + continue; + } + + /* check if the channel is already procoessing the GRA */ + if (sngss7_test_flag(sngss7_info, FLAG_GRP_RESET_TX_RSP)) { + /* move along */ + continue; + } + + /* lock the channel */ + ftdm_mutex_lock(ftdmchan->mutex); + + /* clear up any pending state changes */ + while (ftdm_test_flag (ftdmchan, FTDM_CHANNEL_STATE_CHANGE)) { + ftdm_sangoma_ss7_process_state_change (ftdmchan); + } + + SS7_INFO_CHAN(ftdmchan, "Rx GRA (%d:%d)\n", + g_ftdm_sngss7_data.cfg.isupCkt[sngss7_span->rx_gra.circuit].cic, + (g_ftdm_sngss7_data.cfg.isupCkt[sngss7_span->rx_gra.circuit].cic + sngss7_span->rx_gra.range)); + + switch (ftdmchan->state) { + /**********************************************************************/ + case FTDM_CHANNEL_STATE_RESTART: + + /* throw the FLAG_RESET_TX_RSP to indicate we have acknowledgement from the remote side */ + sngss7_set_flag(sngss7_info, FLAG_GRP_RESET_TX_RSP); + + /* go to DOWN */ + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_DOWN); + + break; + /**********************************************************************/ + case FTDM_CHANNEL_STATE_DOWN: + + /* do nothing, just drop the message */ + SS7_DEBUG("Receveived GRA in down state, dropping\n"); + + break; + /**********************************************************************/ + case FTDM_CHANNEL_STATE_TERMINATING: + case FTDM_CHANNEL_STATE_HANGUP: + case FTDM_CHANNEL_STATE_HANGUP_COMPLETE: + + /* throw the FLAG_RESET_TX_RSP to indicate we have acknowledgement from the remote side */ + sngss7_set_flag(sngss7_info, FLAG_GRP_RESET_TX_RSP); + + break; + /**********************************************************************/ + default: + /* ITU Q764-2.9.5.1.c -> release the circuit */ + if (sngss7_span->rx_gra.cause != 0) { + ftdmchan->caller_data.hangup_cause = sngss7_span->rx_gra.cause; + } else { + ftdmchan->caller_data.hangup_cause = 98; /* Message not compatiable with call state */ + } + + /* go to terminating to hang up the call */ + ftdm_set_state_locked(ftdmchan, FTDM_CHANNEL_STATE_TERMINATING); + break; + /**********************************************************************/ + } + + /* unlock the channel again before we exit */ + ftdm_mutex_unlock(ftdmchan->mutex); + + } /* for ( circuits in request */ + + + return FTDM_SUCCESS; +} + /******************************************************************************/ ftdm_status_t check_for_res_sus_flag(ftdm_span_t *ftdmspan) { @@ -564,6 +716,11 @@ ftdm_status_t check_for_res_sus_flag(ftdm_span_t *ftdmspan) /* if we have the PAUSED flag and the sig status is still UP */ if ((sngss7_test_flag(sngss7_info, FLAG_INFID_PAUSED)) && (ftdm_test_flag(ftdmchan, FTDM_CHANNEL_SIG_UP))) { + + /* clear up any pending state changes */ + while (ftdm_test_flag (ftdmchan, FTDM_CHANNEL_STATE_CHANGE)) { + ftdm_sangoma_ss7_process_state_change (ftdmchan); + } /* throw the channel into SUSPENDED to process the flag */ /* after doing this once the sig status will be down */ @@ -573,6 +730,13 @@ ftdm_status_t check_for_res_sus_flag(ftdm_span_t *ftdmspan) /* if the RESUME flag is up go to SUSPENDED to process the flag */ /* after doing this the flag will be cleared */ if (sngss7_test_flag(sngss7_info, FLAG_INFID_RESUME)) { + + /* clear up any pending state changes */ + while (ftdm_test_flag (ftdmchan, FTDM_CHANNEL_STATE_CHANGE)) { + ftdm_sangoma_ss7_process_state_change (ftdmchan); + } + + /* got SUSPENDED state to clear the flag */ ftdm_set_state_locked (ftdmchan, FTDM_CHANNEL_STATE_SUSPENDED); } From dd529b0e3abcd72cea921068377f2abfd7b28d5e Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 24 Sep 2010 17:34:40 -0400 Subject: [PATCH 2/8] freetdm: remove ftdm_cpu_monitor_disable API (dup) --- libs/freetdm/sample/boost/ftdmstart.c | 7 ------- libs/freetdm/sample/dso/ftdmload.c | 2 -- libs/freetdm/sample/sched/ftdmsched.c | 2 -- libs/freetdm/src/include/freetdm.h | 10 ---------- 4 files changed, 21 deletions(-) diff --git a/libs/freetdm/sample/boost/ftdmstart.c b/libs/freetdm/sample/boost/ftdmstart.c index 972ed43146..bff0664bce 100644 --- a/libs/freetdm/sample/boost/ftdmstart.c +++ b/libs/freetdm/sample/boost/ftdmstart.c @@ -313,13 +313,6 @@ int main(int argc, char *argv[]) /* set the logging level to use */ ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); - /* this is optional. - * cpu monitor is a default feature in freetdm that launches 1 thread - * to monitor system-wide CPU usage. If it goes above a predefined threshold - * it will stop accepting calls to try to protect the quality of current calls */ - ftdm_cpu_monitor_disable(); - - /* Initialize the FTDM library */ if (ftdm_global_init() != FTDM_SUCCESS) { fprintf(stderr, "Error loading FreeTDM\n"); diff --git a/libs/freetdm/sample/dso/ftdmload.c b/libs/freetdm/sample/dso/ftdmload.c index 5b150d67ed..80bcc02fc0 100644 --- a/libs/freetdm/sample/dso/ftdmload.c +++ b/libs/freetdm/sample/dso/ftdmload.c @@ -134,8 +134,6 @@ int main(int argc, char *argv[]) ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); - ftdm_cpu_monitor_disable(); - if (ftdm_global_init() != FTDM_SUCCESS) { fprintf(stderr, "Error loading FreeTDM\n"); exit(-1); diff --git a/libs/freetdm/sample/sched/ftdmsched.c b/libs/freetdm/sample/sched/ftdmsched.c index 5cd7d6340a..e6e391ee4b 100644 --- a/libs/freetdm/sample/sched/ftdmsched.c +++ b/libs/freetdm/sample/sched/ftdmsched.c @@ -73,8 +73,6 @@ int main(int argc, char *argv[]) ftdm_global_set_default_logger(FTDM_LOG_LEVEL_DEBUG); - ftdm_cpu_monitor_disable(); - if (ftdm_global_init() != FTDM_SUCCESS) { fprintf(stderr, "Error loading FreeTDM\n"); exit(-1); diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index 078875b09c..a418152251 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -1176,16 +1176,6 @@ FT_DECLARE(ftdm_iterator_t *) ftdm_span_get_chan_iterator(const ftdm_span_t *spa */ FT_DECLARE(char *) ftdm_api_execute(const char *cmd); -/*! - * \brief Disables CPU monitoring - * - * \note CPU monitoring is enabled by default. This means a thread will be launched at startup (ftdm_global_init) - * with the sole purpose of monitoring system-wide CPU usage. If the CPU usage raises above a defined - * threshold, no new calls will be accepted (neither incoming or outgoing) - * - */ -FT_DECLARE(void) ftdm_cpu_monitor_disable(void); - /*! * \brief Create a configuration node * From bdcad14a4630b312ed32740d60b8bbe99a599e87 Mon Sep 17 00:00:00 2001 From: Konrad Hammel Date: Mon, 27 Sep 2010 13:37:21 -0400 Subject: [PATCH 3/8] freetdm: ss7 - added functions to clear flags for reset --- .../ftmod_sangoma_ss7_main.c | 10 +++- .../ftmod_sangoma_ss7_support.c | 47 +++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c index ce9423cd00..4125c84101 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c @@ -1136,8 +1136,14 @@ void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) if (sngss7_test_flag (sngss7_info, FLAG_CKT_UCIC_UNBLK)) { SS7_DEBUG_CHAN(ftdmchan, "Processing CKT_UCIC_UNBLK flag %s\n", "");; - /* throw the channel into reset from our side since it is already in reset from the remote side */ - sngss7_set_flag (sngss7_info, FLAG_RESET_TX); + /* remove the UCIC block flag */ + sngss7_clear_flag(sngss7_info, FLAG_CKT_UCIC_BLOCK); + + /* remove the UCIC unblock flag */ + sngss7_clear_flag(sngss7_info, FLAG_CKT_UCIC_UNBLK); + + /* throw the channel into reset to sync states */ + sngss7_set_flag(sngss7_info, FLAG_RESET_TX); /* bring the channel into restart again */ goto suspend_goto_restart; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_support.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_support.c index 8e7c6496aa..dfa174e85a 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_support.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_support.c @@ -61,6 +61,11 @@ ftdm_status_t check_if_rx_grs_started(ftdm_span_t *ftdmspan); ftdm_status_t check_if_rx_grs_processed(ftdm_span_t *ftdmspan); ftdm_status_t check_if_rx_gra_started(ftdm_span_t *ftdmspan); ftdm_status_t check_for_res_sus_flag(ftdm_span_t *ftdmspan); + +ftdm_status_t clear_rx_grs_flags(sngss7_chan_data_t *sngss7_info); +ftdm_status_t clear_tx_grs_flags(sngss7_chan_data_t *sngss7_info); +ftdm_status_t clear_rx_rsc_flags(sngss7_chan_data_t *sngss7_info); +ftdm_status_t clear_tx_rsc_flags(sngss7_chan_data_t *sngss7_info); /******************************************************************************/ /* FUNCTIONS ******************************************************************/ @@ -752,7 +757,49 @@ ftdm_status_t check_for_res_sus_flag(ftdm_span_t *ftdmspan) } /******************************************************************************/ +ftdm_status_t clear_rx_grs_flags(sngss7_chan_data_t *sngss7_info) +{ + /* clear all the flags related to an incoming GRS */ + sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_RX); + sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_RX_DN); + sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_RX_CMPLT); + return FTDM_SUCCESS; +} + +/******************************************************************************/ +ftdm_status_t clear_tx_grs_flags(sngss7_chan_data_t *sngss7_info) +{ + /* clear all the flags related to an outgoing GRS */ + sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_BASE); + sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_TX); + sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_SENT); + sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_TX_RSP); + + return FTDM_SUCCESS; +} + +/******************************************************************************/ +ftdm_status_t clear_rx_rsc_flags(sngss7_chan_data_t *sngss7_info) +{ + /* clear all the flags related to an incoming RSC */ + sngss7_clear_flag(sngss7_info, FLAG_RESET_RX); + + return FTDM_SUCCESS; +} + +/******************************************************************************/ +ftdm_status_t clear_tx_rsc_flags(sngss7_chan_data_t *sngss7_info) +{ + /* clear all the flags related to an outgoing RSC */ + sngss7_clear_flag(sngss7_info, FLAG_RESET_TX); + sngss7_clear_flag(sngss7_info, FLAG_RESET_SENT); + sngss7_clear_flag(sngss7_info, FLAG_RESET_TX_RSP); + + return FTDM_SUCCESS; +} + +/******************************************************************************/ /******************************************************************************/ /* For Emacs: From fb71965fd2fa1ce653994c91440b5e3c7843e946 Mon Sep 17 00:00:00 2001 From: Konrad Hammel Date: Mon, 27 Sep 2010 14:24:51 -0400 Subject: [PATCH 4/8] freetdm: ss7 - bug fix --- .../ftmod_sangoma_ss7_main.c | 35 ++++++------------- .../ftmod_sangoma_ss7_main.h | 33 +++++++++++++---- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c index 4125c84101..fc14d04c80 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c @@ -746,8 +746,8 @@ void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) ft_to_sngss7_rsca (ftdmchan); /* clear the reset flag */ - sngss7_clear_flag (sngss7_info, FLAG_RESET_RX); - } + clear_rx_rsc_flags(sngss7_info); + } /* if (sngss7_test_flag (sngss7_info, FLAG_RESET_RX)) */ /* check if there was a GRS that needs a GRA */ if ((sngss7_test_flag(sngss7_info, FLAG_GRP_RESET_RX)) && @@ -769,32 +769,24 @@ void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) } /* clear the grp reset flag */ - sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_RX); - sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_RX_DN); - sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_RX_CMPLT); - + clear_rx_grs_flags(sngss7_info); }/* if ( sngss7_test_flag ( sngss7_info, FLAG_GRP_RESET_RX ) ) */ /* check if we got the reset response */ if (sngss7_test_flag(sngss7_info, FLAG_RESET_TX_RSP)) { /* clear the reset flag */ - sngss7_clear_flag(sngss7_info, FLAG_RESET_TX_RSP); - sngss7_clear_flag(sngss7_info, FLAG_RESET_SENT); - sngss7_clear_flag(sngss7_info, FLAG_RESET_TX); - } + clear_tx_rsc_flags(sngss7_info); + } /* if (sngss7_test_flag(sngss7_info, FLAG_RESET_TX_RSP)) */ if (sngss7_test_flag(sngss7_info, FLAG_GRP_RESET_TX_RSP)) { /* clear the reset flag */ - sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_TX_RSP); - sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_TX); - sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_BASE); - sngss7_clear_flag(sngss7_info, FLAG_GRP_RESET_SENT); + clear_tx_grs_flags(sngss7_info); /* clean out the spans GRA structure */ sngss7_span_data_t *span = ftdmchan->span->mod_data; span->rx_gra.circuit = 0; span->rx_gra.range = 0; - } + } /* if (sngss7_test_flag(sngss7_info, FLAG_GRP_RESET_TX_RSP)) */ /* check if we came from reset (aka we just processed a reset) */ if ((ftdmchan->last_state == FTDM_CHANNEL_STATE_RESTART) || @@ -825,7 +817,6 @@ void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) } /* if (!ftdm_test_flag (ftdmchan, FTDM_CHANNEL_SIG_UP)) */ } /* if !blocked */ } else { - SS7_DEBUG_CHAN(ftdmchan,"Reset flags present (0x%X)\n", sngss7_info->flags); /* there is still another reset pending so go back to reset*/ @@ -1120,14 +1111,10 @@ void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) ftdm_span_send_signal (ftdmchan->span, &sigev); /* remove any reset flags */ - sngss7_clear_flag (sngss7_info, FLAG_GRP_RESET_TX_RSP); - sngss7_clear_flag (sngss7_info, FLAG_GRP_RESET_TX); - sngss7_clear_flag (sngss7_info, FLAG_RESET_TX_RSP); - sngss7_clear_flag (sngss7_info, FLAG_RESET_TX); - sngss7_clear_flag (sngss7_info, FLAG_RESET_SENT); - sngss7_clear_flag (sngss7_info, FLAG_GRP_RESET_RX); - sngss7_clear_flag (sngss7_info, FLAG_RESET_RX); - sngss7_clear_flag (sngss7_info, FLAG_GRP_RESET_BASE); + clear_rx_grs_flags(sngss7_info); + clear_tx_grs_flags(sngss7_info); + clear_rx_rsc_flags(sngss7_info); + clear_tx_rsc_flags(sngss7_info); /* bring the channel down */ goto suspend_goto_last; diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.h b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.h index ae2412381c..d44815df0f 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.h @@ -430,8 +430,10 @@ extern int cmbLinkSetId; /******************************************************************************/ /* PROTOTYPES *****************************************************************/ +/* in ftmod_sangoma_ss7_main.c */ void ftdm_sangoma_ss7_process_state_change (ftdm_channel_t *ftdmchan); +/* in ftmod_sangoma_ss7_logger.c */ void handle_sng_log(uint8_t level, char *fmt,...); void handle_sng_mtp1_alarm(Pst *pst, L1Mngmt *sta); void handle_sng_mtp2_alarm(Pst *pst, SdMngmt *sta); @@ -439,6 +441,7 @@ void handle_sng_mtp3_alarm(Pst *pst, SnMngmt *sta); void handle_sng_isup_alarm(Pst *pst, SiMngmt *sta); void handle_sng_cc_alarm(Pst *pst, CcMngmt *sta); +/* in ftmod_sangoma_ss7_cfg.c */ int ft_to_sngss7_cfg_all(void); int ftmod_ss7_mtp1_gen_config(void); int ftmod_ss7_mtp2_gen_config(void); @@ -457,6 +460,9 @@ int ftmod_ss7_isup_ckt_config(int id); int ftmod_ss7_isup_isap_config(int id); int ftmod_ss7_cc_isap_config(int id); +/* in ftmod_sangoma_ss7_cntrl.c */ +int ft_to_sngss7_activate_all(void); + int ftmod_ss7_inhibit_mtplink(uint32_t id); int ftmod_ss7_uninhibit_mtplink(uint32_t id); int ftmod_ss7_activate_mtplink(uint32_t id); @@ -468,11 +474,12 @@ int ftmod_ss7_deactivate2_mtplinkSet(uint32_t id); int ftmod_ss7_lpo_mtplink(uint32_t id); int ftmod_ss7_lpr_mtplink(uint32_t id); +/* in ftmod_sangoma_ss7_sta.c */ int ftmod_ss7_mtplink_sta(uint32_t id, SnMngmt *cfm); int ftmod_ss7_mtplinkSet_sta(uint32_t id, SnMngmt *cfm); -int ft_to_sngss7_activate_all(void); +/* in ftmod_sangoma_ss7_out.c */ void ft_to_sngss7_iam(ftdm_channel_t *ftdmchan); void ft_to_sngss7_acm(ftdm_channel_t *ftdmchan); void ft_to_sngss7_anm(ftdm_channel_t *ftdmchan); @@ -492,6 +499,7 @@ void ft_to_sngss7_cgua(ftdm_channel_t * ftdmchan); void ft_to_sngss7_cgb(ftdm_channel_t * ftdmchan); void ft_to_sngss7_cgu(ftdm_channel_t * ftdmchan); +/* in ftmod_sangoma_ss7_in.c */ void sngss7_sta_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt); void sngss7_con_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiConEvnt *siConEvnt); void sngss7_con_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiConEvnt *siConEvnt); @@ -504,6 +512,7 @@ void sngss7_fac_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint void sngss7_sta_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt); void sngss7_umsg_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit); +/* in ftmod_sangoma_ss7_handle.c */ ftdm_status_t handle_con_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiConEvnt *siConEvnt); ftdm_status_t handle_con_sta(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiCnStEvnt *siCnStEvnt, uint8_t evntType); ftdm_status_t handle_con_cfm(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, SiConEvnt *siConEvnt); @@ -534,6 +543,13 @@ ftdm_status_t handle_local_blk(uint32_t suInstId, uint32_t spInstId, uint32_t ci ftdm_status_t handle_local_ubl(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt); ftdm_status_t handle_ucic(uint32_t suInstId, uint32_t spInstId, uint32_t circuit, uint8_t globalFlg, uint8_t evntType, SiStaEvnt *siStaEvnt); +/* in ftmod_sangoma_ss7_xml.c */ +int ftmod_ss7_parse_xml(ftdm_conf_parameter_t *ftdm_parameters, ftdm_span_t *span); + +/* in ftmod_sangoma_ss7_cli.c */ +ftdm_status_t ftdm_sngss7_handle_cli_cmd(ftdm_stream_handle_t *stream, const char *data); + +/* in ftmod_sangoma_ss7_support.c */ uint8_t copy_cgPtyNum_from_sngss7(ftdm_caller_data_t *ftdm, SiCgPtyNum *cgPtyNum); uint8_t copy_cgPtyNum_to_sngss7(ftdm_caller_data_t *ftdm, SiCgPtyNum *cgPtyNum); uint8_t copy_cdPtyNum_from_sngss7(ftdm_caller_data_t *ftdm, SiCdPtyNum *cdPtyNum); @@ -545,16 +561,19 @@ int check_for_reset(sngss7_chan_data_t *sngss7_info); ftdm_status_t extract_chan_data(uint32_t circuit, sngss7_chan_data_t **sngss7_info, ftdm_channel_t **ftdmchan); unsigned long get_unique_id(void); -int ftmod_ss7_parse_xml(ftdm_conf_parameter_t *ftdm_parameters, ftdm_span_t *span); - -void handle_isup_t35(void *userdata); - -ftdm_status_t ftdm_sngss7_handle_cli_cmd(ftdm_stream_handle_t *stream, const char *data); - ftdm_status_t check_if_rx_grs_started(ftdm_span_t *ftdmspan); ftdm_status_t check_if_rx_grs_processed(ftdm_span_t *ftdmspan); ftdm_status_t check_if_rx_gra_started(ftdm_span_t *ftdmspan); ftdm_status_t check_for_res_sus_flag(ftdm_span_t *ftdmspan); + +ftdm_status_t clear_rx_grs_flags(sngss7_chan_data_t *sngss7_info); +ftdm_status_t clear_tx_grs_flags(sngss7_chan_data_t *sngss7_info); +ftdm_status_t clear_rx_rsc_flags(sngss7_chan_data_t *sngss7_info); +ftdm_status_t clear_tx_rsc_flags(sngss7_chan_data_t *sngss7_info); + + +/* in ftmod_sangoma_ss7_timers.c */ +void handle_isup_t35(void *userdata); /******************************************************************************/ /* MACROS *********************************************************************/ From ba5a250cc80ada70049cf2c292786de226f85380 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 28 Sep 2010 11:05:54 -0400 Subject: [PATCH 5/8] freetdm: stop scheduler but do not destroy it until the very end (dup) --- libs/freetdm/src/ftdm_io.c | 19 ++++++++----------- libs/freetdm/src/ftdm_sched.c | 18 ++++++++++++++++++ libs/freetdm/src/include/private/ftdm_sched.h | 3 +++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 299106f599..79d55c4d16 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -4932,16 +4932,19 @@ FT_DECLARE(uint32_t) ftdm_running(void) FT_DECLARE(ftdm_status_t) ftdm_global_destroy(void) { ftdm_span_t *sp; - uint32_t sanity = 100; time_end(); + /* many freetdm event loops rely on this variable to decide when to stop, do this first */ globals.running = 0; - ftdm_sched_destroy(&globals.timingsched); + /* stop the scheduling thread */ + ftdm_free_sched_stop(); + /* stop the cpu monitor thread */ ftdm_cpu_monitor_stop(); + /* now destroy channels and spans */ globals.span_index = 0; ftdm_span_close_all(); @@ -4966,18 +4969,12 @@ FT_DECLARE(ftdm_status_t) ftdm_global_destroy(void) globals.spans = NULL; ftdm_mutex_unlock(globals.span_mutex); + /* destroy signaling and io modules */ ftdm_unload_modules(); - while (ftdm_free_sched_running() && --sanity) { - ftdm_log(FTDM_LOG_DEBUG, "Waiting for schedule thread to finish\n"); - ftdm_sleep(100); - } - - if (!sanity) { - ftdm_log(FTDM_LOG_CRIT, "schedule thread did not stop running, we may crash on shutdown\n"); - } - + /* finally destroy the globals */ ftdm_mutex_lock(globals.mutex); + ftdm_sched_destroy(&globals.timingsched); hashtable_destroy(globals.interface_hash); hashtable_destroy(globals.module_hash); hashtable_destroy(globals.span_hash); diff --git a/libs/freetdm/src/ftdm_sched.c b/libs/freetdm/src/ftdm_sched.c index be21696d71..47df7d973c 100644 --- a/libs/freetdm/src/ftdm_sched.c +++ b/libs/freetdm/src/ftdm_sched.c @@ -176,6 +176,24 @@ FT_DECLARE(ftdm_bool_t) ftdm_free_sched_running(void) return sched_globals.running; } +FT_DECLARE(ftdm_bool_t) ftdm_free_sched_stop(void) +{ + /* currently we really dont stop the thread here, we rely on freetdm being shutdown and ftdm_running() to be false + * so the scheduling thread dies and we just wait for it here */ + uint32_t sanity = 100; + while (ftdm_free_sched_running() && --sanity) { + ftdm_log(FTDM_LOG_DEBUG, "Waiting for main schedule thread to finish\n"); + ftdm_sleep(100); + } + + if (!sanity) { + ftdm_log(FTDM_LOG_CRIT, "schedule thread did not stop running, we may crash on shutdown\n"); + return FTDM_FALSE; + } + + return FTDM_TRUE; +} + FT_DECLARE(ftdm_status_t) ftdm_sched_create(ftdm_sched_t **sched, const char *name) { ftdm_sched_t *newsched = NULL; diff --git a/libs/freetdm/src/include/private/ftdm_sched.h b/libs/freetdm/src/include/private/ftdm_sched.h index 9a222896f5..c1818d8bb5 100644 --- a/libs/freetdm/src/include/private/ftdm_sched.h +++ b/libs/freetdm/src/include/private/ftdm_sched.h @@ -95,6 +95,9 @@ FT_DECLARE(ftdm_status_t) ftdm_sched_global_init(void); /*! \brief Checks if the main scheduling thread is running */ FT_DECLARE(ftdm_bool_t) ftdm_free_sched_running(void); +/*! \brief Stop the main scheduling thread (if running) */ +FT_DECLARE(ftdm_bool_t) ftdm_free_sched_stop(void); + #ifdef __cplusplus } #endif From 27096d4512ef6bf21403aa0f466908d940db0078 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Tue, 28 Sep 2010 13:55:46 -0400 Subject: [PATCH 6/8] Support for enabling/disabling HWEC based on call bearer_cap --- libs/freetdm/src/ftdm_io.c | 54 ++++++++++++++++--- .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 38 ++++++++++++- libs/freetdm/src/include/private/ftdm_types.h | 2 + 3 files changed, 86 insertions(+), 8 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 79d55c4d16..df139c548e 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -244,6 +244,39 @@ static __inline__ void ftdm_std_free(void *pool, void *ptr) free(ptr); } +static void ftdm_set_echocancel_call_begin(ftdm_channel_t *chan) +{ + ftdm_caller_data_t *caller_data = ftdm_channel_get_caller_data(chan); + if (ftdm_channel_test_feature(chan, FTDM_CHANNEL_FEATURE_HWEC)) { + if (ftdm_channel_test_feature(chan, FTDM_CHANNEL_FEATURE_HWEC_DISABLED_ON_IDLE)) { + if (caller_data->bearer_capability != FTDM_BEARER_CAP_64K_UNRESTRICTED) { + ftdm_channel_command(chan, FTDM_COMMAND_ENABLE_ECHOCANCEL, NULL); + } + } else { + if (caller_data->bearer_capability == FTDM_BEARER_CAP_64K_UNRESTRICTED) { + ftdm_channel_command(chan, FTDM_COMMAND_DISABLE_ECHOCANCEL, NULL); + } + } + } +} + +static void ftdm_set_echocancel_call_end(ftdm_channel_t *chan) +{ + ftdm_caller_data_t *caller_data = ftdm_channel_get_caller_data(chan); + if (ftdm_channel_test_feature(chan, FTDM_CHANNEL_FEATURE_HWEC)) { + if (ftdm_channel_test_feature(chan, FTDM_CHANNEL_FEATURE_HWEC_DISABLED_ON_IDLE)) { + if (caller_data->bearer_capability != FTDM_BEARER_CAP_64K_UNRESTRICTED) { + ftdm_channel_command(chan, FTDM_COMMAND_DISABLE_ECHOCANCEL, NULL); + } + } else { + if (caller_data->bearer_capability == FTDM_BEARER_CAP_64K_UNRESTRICTED) { + ftdm_channel_command(chan, FTDM_COMMAND_ENABLE_ECHOCANCEL, NULL); + } + } + } +} + + FT_DECLARE_DATA ftdm_memory_handler_t g_ftdm_mem_handler = { /*.pool =*/ NULL, @@ -2008,6 +2041,9 @@ done: static ftdm_status_t call_hangup(ftdm_channel_t *chan, const char *file, const char *func, int line) { ftdm_set_flag(chan, FTDM_CHANNEL_USER_HANGUP); + + ftdm_set_echocancel_call_end(chan); + if (chan->state != FTDM_CHANNEL_STATE_DOWN) { if (chan->state == FTDM_CHANNEL_STATE_HANGUP) { /* make user's life easier, and just ignore double hangup requests */ @@ -2173,10 +2209,12 @@ done: FT_DECLARE(ftdm_status_t) _ftdm_channel_call_place(const char *file, const char *func, int line, ftdm_channel_t *ftdmchan) { ftdm_status_t status = FTDM_FAIL; - + ftdm_assert_return(ftdmchan != NULL, FTDM_FAIL, "null channel"); ftdm_assert_return(ftdm_test_flag(ftdmchan, FTDM_CHANNEL_OUTBOUND), FTDM_FAIL, "Call place, but outbound flag not set\n"); + ftdm_set_echocancel_call_begin(ftdmchan); + ftdm_channel_lock(ftdmchan); if (ftdmchan->span->outgoing_call) { @@ -4740,11 +4778,15 @@ FT_DECLARE(ftdm_status_t) ftdm_span_send_signal(ftdm_span_t *span, ftdm_sigmsg_t break; case FTDM_SIGEVENT_START: - /* when cleaning up the public API I added this because mod_freetdm.c on_fxs_signal was - * doing it during SIGEVENT_START, but now that flags are private they can't, wonder if - * is needed at all? - * */ - ftdm_clear_flag(sigmsg->channel, FTDM_CHANNEL_HOLD); + { + ftdm_set_echocancel_call_begin(sigmsg->channel); + + /* when cleaning up the public API I added this because mod_freetdm.c on_fxs_signal was + * doing it during SIGEVENT_START, but now that flags are private they can't, wonder if + * is needed at all? + * */ + ftdm_clear_flag(sigmsg->channel, FTDM_CHANNEL_HOLD); + } break; case FTDM_SIGEVENT_STOP: diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index be99f94aff..23463e9088 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -280,6 +280,25 @@ static unsigned wp_open_range(ftdm_span_t *span, unsigned spanno, unsigned start ftdm_channel_set_feature(chan, FTDM_CHANNEL_FEATURE_DTMF_DETECT); dtmf = "hardware"; } + + err = sangoma_tdm_get_hw_ec(chan->sockfd, &tdm_api); + if (err > 0) { + ftdm_channel_set_feature(chan, FTDM_CHANNEL_FEATURE_HWEC); + } + +#ifdef WP_API_FEATURE_HWEC_PERSIST + err = sangoma_tdm_get_hwec_persist_status(chan->sockfd, &tdm_api); + if (err == 0) { + ftdm_channel_set_feature(chan, FTDM_CHANNEL_FEATURE_HWEC_DISABLED_ON_IDLE); + } +#else + if (span->trunk_type == FTDM_TRUNK_BRI || span->trunk_type == FTDM_TRUNK_BRI_PTMP) { + ftdm_log(FTDM_LOG_WARNING, "WP_API_FEATURE_HWEC_PERSIST feature is not supported \ + with your version of libsangoma, you should update your Wanpipe drivers\n"); + + } +#endif + } #ifdef LIBSANGOMA_VERSION @@ -598,18 +617,33 @@ static FIO_COMMAND_FUNCTION(wanpipe_command) break; case FTDM_COMMAND_ENABLE_ECHOCANCEL: { +#ifdef WP_API_FEATURE_EC_CHAN_STAT + err=sangoma_tdm_get_hwec_chan_status(ftdmchan->sockfd, &tdm_api); + if (err > 0) { + /* Hardware echo canceller already enabled */ + err = 0; + break; + } +#endif err=sangoma_tdm_enable_hwec(ftdmchan->sockfd, &tdm_api); if (err) { - snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "HWEC Enable Failed"); + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "HWEC Enable Failed"); return FTDM_FAIL; } } break; case FTDM_COMMAND_DISABLE_ECHOCANCEL: { +#ifdef WP_API_FEATURE_EC_CHAN_STAT + err=sangoma_tdm_get_hwec_chan_status(ftdmchan->sockfd, &tdm_api); + if (!err) { + /* Hardware echo canceller already disabled */ + break; + } +#endif err=sangoma_tdm_disable_hwec(ftdmchan->sockfd, &tdm_api); if (err) { - snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "HWEC Disable Failed"); + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "HWEC Disable Failed"); return FTDM_FAIL; } } diff --git a/libs/freetdm/src/include/private/ftdm_types.h b/libs/freetdm/src/include/private/ftdm_types.h index d0d19e5a55..016fd31c43 100644 --- a/libs/freetdm/src/include/private/ftdm_types.h +++ b/libs/freetdm/src/include/private/ftdm_types.h @@ -191,6 +191,8 @@ typedef enum { FTDM_CHANNEL_FEATURE_CALLERID = (1 << 4), /*!< Channel can detect caller id (read-only) */ FTDM_CHANNEL_FEATURE_PROGRESS = (1 << 5), /*!< Channel can detect inband progress (read-only) */ FTDM_CHANNEL_FEATURE_CALLWAITING = (1 << 6), /*!< Channel will allow call waiting (ie: FXS devices) (read/write) */ + FTDM_CHANNEL_FEATURE_HWEC = (1<<7), /*!< Channel has a hardware echo canceller */ + FTDM_CHANNEL_FEATURE_HWEC_DISABLED_ON_IDLE = (1<<8), /*!< hardware echo canceller is disabled when there are no calls on this channel */ } ftdm_channel_feature_t; typedef enum { From 1af641feac4cff3ccb372da90e997f371540061d Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 29 Sep 2010 15:05:49 -0400 Subject: [PATCH 7/8] d-channel FD now passed as a configuration parameter --- .../ftmod_sangoma_isdn_stack_cfg.c | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cfg.c b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cfg.c index 3a4a001089..7f3c4c3d07 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cfg.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_isdn/ftmod_sangoma_isdn_stack_cfg.c @@ -193,10 +193,12 @@ ftdm_status_t sng_isdn_stack_cfg_phy_gen(void) ftdm_status_t sng_isdn_stack_cfg_phy_psap(ftdm_span_t *span) { - /*local variables*/ - L1Mngmt cfg; /*configuration structure*/ - Pst pst; /*post structure*/ + ftdm_iterator_t *chaniter; + ftdm_iterator_t *curr; + L1Mngmt cfg; + Pst pst; + S32 d_channel_fd = -1; sngisdn_span_data_t *signal_data = (sngisdn_span_data_t*)span->signal_data; /* initalize the post structure */ @@ -219,20 +221,35 @@ ftdm_status_t sng_isdn_stack_cfg_phy_psap(ftdm_span_t *span) cfg.hdr.elmId.elmntInst1 = signal_data->link_id; - cfg.t.cfg.s.l1PSAP.span = span->channels[1]->physical_span_id; + + /* Find the d-channel */ + chaniter = ftdm_span_get_chan_iterator(span, NULL); + for (curr = chaniter; curr; curr = ftdm_iterator_next(curr)) { + ftdm_channel_t *ftdmchan = (ftdm_channel_t*)ftdm_iterator_current(curr); + if (ftdmchan->type == FTDM_CHAN_TYPE_DQ921) { + d_channel_fd = ftdmchan->sockfd; + break; + } + } + ftdm_iterator_free(chaniter); + + if(d_channel_fd < 0) { + ftdm_log(FTDM_LOG_ERROR, "%s:No d-channels specified\n", span->name); + return FTDM_FAIL; + } + + cfg.t.cfg.s.l1PSAP.sockfd = d_channel_fd; + switch(span->trunk_type) { case FTDM_TRUNK_E1: - cfg.t.cfg.s.l1PSAP.chan = 16; cfg.t.cfg.s.l1PSAP.type = SNG_L1_TYPE_PRI; break; case FTDM_TRUNK_T1: case FTDM_TRUNK_J1: - cfg.t.cfg.s.l1PSAP.chan = 24; cfg.t.cfg.s.l1PSAP.type = SNG_L1_TYPE_PRI; break; case FTDM_TRUNK_BRI: case FTDM_TRUNK_BRI_PTMP: - cfg.t.cfg.s.l1PSAP.chan = 3; cfg.t.cfg.s.l1PSAP.type = SNG_L1_TYPE_BRI; break; default: From 5a42adf40dec8dd084273d1d75f4ceb9f6317b2e Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 29 Sep 2010 16:51:00 -0400 Subject: [PATCH 8/8] freetdm: add some comments to sample configurations --- libs/freetdm/conf/freetdm.conf | 48 +++++++++++++++++++++++------- libs/freetdm/conf/freetdm.conf.xml | 11 +++++-- libs/freetdm/conf/pika.conf | 2 ++ libs/freetdm/conf/tones.conf | 2 ++ 4 files changed, 51 insertions(+), 12 deletions(-) diff --git a/libs/freetdm/conf/freetdm.conf b/libs/freetdm/conf/freetdm.conf index 1ea1a9f62a..bbaf1e3687 100644 --- a/libs/freetdm/conf/freetdm.conf +++ b/libs/freetdm/conf/freetdm.conf @@ -1,19 +1,47 @@ -[span wanpipe] -name => FreeTDM -number => 1 +; !! THIS IS A SAMPLE CONFIGURATION ONLY !! + +; refer to http://wiki.freeswitch.org/wiki/FreeTDM for further documentation + +[general] +; whether to launch a thread for CPU usage monitoring +cpu_monitor => no + +; How often (in milliseconds) monitor CPU usage +cpu_monitoring_interval => 1000 + +; At what CPU percentage raise a CPU alarm +cpu_set_alarm_threshold => 80 + +; At what CPU percentage stop the CPU alarm +cpu_reset_alarm_threshold => 70 + +; Which action to take when the CPU alarm is raised +; it can be warn and/or reject calls +; cpu_alarm_action => warn,reject +cpu_alarm_action => warn + +; spans are defined with [span ] +; the span type can either be zt, wanpipe or pika +; the span name can be any unique string +[span wanpipe myWanpipe] + +; valid trunk types are: FXO, FXS, EM, E1, T1, J1, BRI, BRI_PTMP +trunk_type => FXS + +; add FXS channels from 3 to 4 at wanpipe span 1 to this freetdm span fxs-channel => 1:3-4 -[span wanpipe] +[span wanpipe myWanpipe2] +trunk_type => FXO +; This number will be used as DNIS for FXO devices fxo-channel => 1:1-2 -[span zt] -name => FreeTDM -number => 2 +[span zt myZaptelSpan] +number => 9999 fxs-channel => 1 -[span zt] -name => FreeTDM +[span zt mySecondZaptelSpan] +; This number will be used as DNIS for FXO devices number => 2 fxo-channel => 3 - diff --git a/libs/freetdm/conf/freetdm.conf.xml b/libs/freetdm/conf/freetdm.conf.xml index 69bf99a0a0..986074dffb 100644 --- a/libs/freetdm/conf/freetdm.conf.xml +++ b/libs/freetdm/conf/freetdm.conf.xml @@ -1,3 +1,5 @@ + + @@ -5,6 +7,8 @@ + + @@ -24,9 +28,11 @@ - + + + - + @@ -42,4 +48,5 @@ + diff --git a/libs/freetdm/conf/pika.conf b/libs/freetdm/conf/pika.conf index 8cc8d9c11d..78e095205e 100644 --- a/libs/freetdm/conf/pika.conf +++ b/libs/freetdm/conf/pika.conf @@ -1,3 +1,5 @@ +; you dont need this file unless you use PIKA boards + ; each category is a config profile ; to apply the profile append it to a channel def in ; openzap.conf with @ diff --git a/libs/freetdm/conf/tones.conf b/libs/freetdm/conf/tones.conf index 36db1d4d91..155b5fe17e 100644 --- a/libs/freetdm/conf/tones.conf +++ b/libs/freetdm/conf/tones.conf @@ -1,3 +1,5 @@ +; This file is used to generate telephony tones by FreeTDM + [us] generate-dial => v=-7;%(1000,0,350,440) detect-dial => 350,440