From f1257ab8b510295a30ff2083cc6d4a11bef2a794 Mon Sep 17 00:00:00 2001 From: yannick Date: Thu, 6 Oct 2011 17:36:50 -0400 Subject: [PATCH] ftdm: fixing reset on in-use channel causing infinite state loop. --- .../ftmod_sangoma_ss7/ftmod_sangoma_ss7_cli.c | 8 +++++-- .../ftmod_sangoma_ss7_main.c | 24 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) 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 00a563962c..9eb737a7f3 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 @@ -29,6 +29,10 @@ * LIABILITY|WHETHER IN CONTRACT|STRICT LIABILITY|OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE|EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributors: + * James Zhang + * */ #if 0 @@ -1198,7 +1202,7 @@ static ftdm_status_t handle_show_blocks(ftdm_stream_handle_t *stream, int span, } #ifdef SMG_RELAY_DBG - stream->write_function(stream, " blk_flag= %x ckt_flag = %d", ss7_info->blk_flags, ss7_info->ckt_flags ); + stream->write_function(stream," blk_flag=%x | ckt_flag=%x | chan_flag=%x", ss7_info->blk_flags, ss7_info->ckt_flags, ftdmchan->flags); #endif stream->write_function(stream, "\n"); } /* if ( span and chan) */ @@ -1314,7 +1318,7 @@ static ftdm_status_t handle_show_status(ftdm_stream_handle_t *stream, int span, } #ifdef SMG_RELAY_DBG - stream->write_function(stream," blk_flag= %x ckt_flag = %d", ss7_info->blk_flags, ss7_info->ckt_flags ); + stream->write_function(stream," blk_flag=%x | ckt_flag=%x | chan_flag=%x", ss7_info->blk_flags, ss7_info->ckt_flags, ftdmchan->flags); #endif stream->write_function(stream, "\n"); } /* if ( hole, sig, voice) */ 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 5341983e46..44870a69a9 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 @@ -842,9 +842,18 @@ ftdm_status_t ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) if (sngss7_test_ckt_flag (sngss7_info, FLAG_REMOTE_REL)) { /* check if this hangup is from a tx RSC */ if (sngss7_test_ckt_flag (sngss7_info, FLAG_RESET_TX)) { - /* go to RESTART State until RSCa is received */ - state_flag = 0; - ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_RESTART); + if (!sngss7_test_ckt_flag(sngss7_info, FLAG_RESET_SENT)) { + ft_to_sngss7_rsc (ftdmchan); + sngss7_set_ckt_flag(sngss7_info, FLAG_RESET_SENT); + ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_RESTART); + } else if (sngss7_test_ckt_flag(sngss7_info, FLAG_RESET_TX_RSP)) { + state_flag = 0; + ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_DOWN); + } else { + /* go to RESTART State until RSCa is received */ + state_flag = 0; + ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_RESTART); + } } else { /* if the hangup is from a rx RSC, rx GRS, or glare don't sent RLC */ if (!(sngss7_test_ckt_flag(sngss7_info, FLAG_RESET_RX)) && @@ -1040,9 +1049,12 @@ ftdm_status_t ftdm_sangoma_ss7_process_state_change (ftdm_channel_t * ftdmchan) if ((sngss7_test_ckt_flag(sngss7_info, FLAG_RESET_TX)) && !(sngss7_test_ckt_flag(sngss7_info, FLAG_RESET_SENT))) { - /* send a reset request */ - ft_to_sngss7_rsc (ftdmchan); - sngss7_set_ckt_flag(sngss7_info, FLAG_RESET_SENT); + /* don't send out reset before finished hanging up if I'm in-use. */ + if (!ftdm_test_flag(ftdmchan, FTDM_CHANNEL_INUSE)) { + /* send a reset request */ + ft_to_sngss7_rsc (ftdmchan); + sngss7_set_ckt_flag(sngss7_info, FLAG_RESET_SENT); + } } /* if (sngss7_test_ckt_flag(sngss7_info, FLAG_RESET_TX)) */