diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index edb409fe05..24c0bef37c 100644 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -1324,7 +1324,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if (ftdm_channel_add_token(ftdmchan, switch_core_session_get_uuid(*new_session), ftdm_channel_get_token_count(ftdmchan)) != FTDM_SUCCESS) { switch_core_session_destroy(new_session); cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; - goto fail; + goto fail; } @@ -1337,8 +1337,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_core_codec_destroy(&tech_pvt->write_codec); } switch_core_session_destroy(new_session); - cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; - goto fail; + cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; + goto fail; } ftdm_channel_init(ftdmchan); @@ -1346,10 +1346,10 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi return SWITCH_CAUSE_SUCCESS; } - fail: +fail: if (ftdmchan) { - ftdm_channel_done(ftdmchan); + ftdm_channel_call_hangup_with_cause(ftdmchan, FTDM_CAUSE_SWITCH_CONGESTION); } return cause; diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 7d48260d5e..0c7b141078 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -1428,8 +1428,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direc ftdm_span_channel_use_count(span, &count); if (count >= span->chan_count) { - ftdm_log(FTDM_LOG_CRIT, "All circuits are busy: active=%i max=%i.\n", - count, span->chan_count); + ftdm_log(FTDM_LOG_ERROR, "All circuits are busy: active=%i max=%i.\n", count, span->chan_count); *ftdmchan = NULL; return FTDM_FAIL; } @@ -1808,16 +1807,36 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_call_answer(ftdm_channel_t *ftdmchan) return FTDM_SUCCESS; } + +static ftdm_status_t call_hangup(ftdm_channel_t *chan) +{ + if (chan->state != FTDM_CHANNEL_STATE_DOWN) { + ftdm_set_state_wait(chan, FTDM_CHANNEL_STATE_HANGUP); + } else { + /* the signaling stack did not touch the state, + * core is responsible from clearing flags and stuff */ + ftdm_channel_done(chan); + } + return FTDM_SUCCESS; +} + FT_DECLARE(ftdm_status_t) ftdm_channel_call_hangup_with_cause(ftdm_channel_t *ftdmchan, ftdm_call_cause_t cause) { + ftdm_channel_lock(ftdmchan); + ftdmchan->caller_data.hangup_cause = cause; - ftdm_set_state_locked_wait(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); + + call_hangup(ftdmchan); + + ftdm_channel_unlock(ftdmchan); return FTDM_SUCCESS; } FT_DECLARE(ftdm_status_t) ftdm_channel_call_hangup(ftdm_channel_t *ftdmchan) { - ftdm_set_state_locked_wait(ftdmchan, FTDM_CHANNEL_STATE_HANGUP); + ftdm_channel_lock(ftdmchan); + call_hangup(ftdmchan); + ftdm_channel_unlock(ftdmchan); return FTDM_SUCCESS; } diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c index c0f0e041cf..856541dbe3 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c @@ -69,9 +69,6 @@ static ftdm_status_t ftdm_sangoma_boost_list_sigmods(ftdm_stream_handle_t *strea #define BOOST_SPAN(ftdmchan) ((ftdm_sangoma_boost_data_t*)(ftdmchan)->span->signal_data)->sigmod ? ftdmchan->physical_span_id : ftdmchan->physical_span_id-1 #define BOOST_CHAN(ftdmchan) ((ftdm_sangoma_boost_data_t*)(ftdmchan)->span->signal_data)->sigmod ? ftdmchan->physical_chan_id : ftdmchan->physical_chan_id-1 -#define BOOST_EVENT_SPAN(sigmod, event) ((sigmod)? event->span:event->span+1) -#define BOOST_EVENT_CHAN(sigmod, event) ((sigmod)? event->chan:event->chan+1) - /** * \brief SANGOMA boost notification flag */ @@ -957,7 +954,8 @@ static void handle_call_answer(ftdm_span_t *span, sangomabc_connection_t *mcon, /* NC: Do nothing here because we are in process of stopping the call. So ignore the ANSWER. */ - ftdm_log(FTDM_LOG_CRIT, "ANSWER BUT CALL IS HANGUP %d:%d\n", event->span+1,event->chan+1); + ftdm_log(FTDM_LOG_DEBUG, "ANSWER BUT CALL IS HANGUP %d:%d\n", BOOST_EVENT_SPAN(mcon->sigmod, event), + BOOST_EVENT_CHAN(mcon->sigmod, event)); } else if (ftdmchan->state == FTDM_CHANNEL_STATE_HOLD) { ftdmchan->init_state = FTDM_CHANNEL_STATE_UP; @@ -968,7 +966,7 @@ static void handle_call_answer(ftdm_span_t *span, sangomabc_connection_t *mcon, } ftdm_mutex_unlock(ftdmchan->mutex); } else { - ftdm_log(FTDM_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", BOOST_EVENT_SPAN(mcon, event), BOOST_EVENT_CHAN(mcon, event)); + ftdm_log(FTDM_LOG_CRIT, "ANSWER CANT FIND A CHAN %d:%d\n", BOOST_EVENT_SPAN(mcon->sigmod, event), BOOST_EVENT_CHAN(mcon->sigmod, event)); sangomabc_exec_command(mcon, event->span, event->chan, @@ -1234,7 +1232,7 @@ static ftdm_channel_t* event_process_states(ftdm_span_t *span, sangomabc_short_e case SIGBOOST_EVENT_CALL_RELEASED: if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 1))) { ftdm_log(FTDM_LOG_DEBUG, "PROCESS STATES CANT FIND CHAN %d:%d\n", - BOOST_EVENT_SPAN(((ftdm_sangoma_boost_data_t*)(span->signal_data))->sigmod, event), + BOOST_EVENT_SPAN(((ftdm_sangoma_boost_data_t*)(span->signal_data))->sigmod, event), BOOST_EVENT_CHAN(((ftdm_sangoma_boost_data_t*)(span->signal_data))->sigmod, event)); return NULL; } @@ -1733,7 +1731,7 @@ static ftdm_status_t ftdm_boost_connection_open(ftdm_span_t *span) ++sangoma_boost_data->pcon.cfg.remote_port) < 0) { ftdm_log(FTDM_LOG_ERROR, "Error: Opening PCON Socket [%d] %s\n", sangoma_boost_data->pcon.socket, strerror(errno)); return FTDM_FAIL; - } + } /* try to create the boost sockets interrupt objects */ if (ftdm_interrupt_create(&sangoma_boost_data->pcon.sock_interrupt, sangoma_boost_data->pcon.socket) != FTDM_SUCCESS) { @@ -1924,7 +1922,7 @@ static void ftdm_cli_span_state_cmd(ftdm_span_t *span, char *state) int cnt=0; ftdm_channel_state_t state_e = ftdm_str2ftdm_channel_state(state); if (state_e == FTDM_CHANNEL_STATE_INVALID) { - ftdm_log(FTDM_LOG_CRIT, "Checking for channels not in the INVALID state is probably not waht you want\n"); + ftdm_log(FTDM_LOG_CRIT, "Checking for channels not in the INVALID state is probably not what you want\n"); } for(j = 1; j <= span->chan_count; j++) { if (span->channels[j]->state != state_e) { @@ -2187,7 +2185,7 @@ static ftdm_state_map_t boost_state_map = { ZSM_UNACCEPTABLE, {FTDM_CHANNEL_STATE_HOLD, FTDM_END}, {FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, - FTDM_CHANNEL_STATE_IDLE, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_UP, FTDM_END} + FTDM_CHANNEL_STATE_IDLE, FTDM_CHANNEL_STATE_TERMINATING, FTDM_CHANNEL_STATE_UP, FTDM_CHANNEL_STATE_HANGUP, FTDM_END} }, { ZSD_OUTBOUND, diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c index b2a38b198d..4ba009907e 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.c @@ -82,8 +82,8 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e priority ? "P":"N", sangomabc_event_id_name(event->event_id), event->event_id, - event->span, - event->chan, + BOOST_EVENT_SPAN(mcon->sigmod, event), + BOOST_EVENT_CHAN(mcon->sigmod, event), event->call_setup_id, event->fseqno, strlen(event->calling_name)?event->calling_name:"N/A", @@ -101,8 +101,8 @@ static void sangomabc_print_event_short(sangomabc_connection_t *mcon, sangomabc_ priority ? "P":"N", sangomabc_event_id_name(event->event_id), event->event_id, - event->span, - event->chan, + BOOST_EVENT_SPAN(mcon->sigmod, event), + BOOST_EVENT_CHAN(mcon->sigmod, event), event->release_cause, event->call_setup_id, event->fseqno); @@ -247,7 +247,7 @@ int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int return -1; } else { ftdm_log(FTDM_LOG_WARNING, "Failed to tx on boost socket: %s :retry %i\n", strerror(errno), retry); - ftdm_sleep(1); + ftdm_sleep(1); } } diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h index 12c3f12b8c..4f5f21c6e6 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_boost/sangoma_boost_client.h @@ -144,6 +144,10 @@ const char *sangomabc_event_id_name(uint32_t event_id); int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int id, int cmd, int cause, int flags); int sangomabc_exec_commandp(sangomabc_connection_t *pcon, int span, int chan, int id, int cmd, int cause); +#define BOOST_EVENT_SPAN(sigmod, event) ((sigmod)? event->span:event->span+1) +#define BOOST_EVENT_CHAN(sigmod, event) ((sigmod)? event->chan:event->chan+1) + + #endif diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index b0c2f1f65d..5d233d3c93 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -634,7 +634,6 @@ FT_DECLARE(ftdm_status_t) ftdm_conf_node_create(const char *name, ftdm_conf_node FT_DECLARE(ftdm_status_t) ftdm_conf_node_add_param(ftdm_conf_node_t *node, const char *param, const char *val); FT_DECLARE(ftdm_status_t) ftdm_conf_node_destroy(ftdm_conf_node_t *node); FT_DECLARE(ftdm_status_t) ftdm_configure_span_channels(ftdm_span_t *span, const char *str, ftdm_channel_config_t *chan_config, unsigned *configured); -FT_DECLARE(ftdm_status_t) ftdm_channel_done(ftdm_channel_t *ftdmchan); FT_DECLARE(ftdm_channel_t *) ftdm_span_get_channel(const ftdm_span_t *span, uint32_t chanid); FT_DECLARE(uint32_t) ftdm_span_get_chan_count(const ftdm_span_t *span); diff --git a/libs/freetdm/src/include/private/ftdm_core.h b/libs/freetdm/src/include/private/ftdm_core.h index 3ab807620c..ebaddec43e 100644 --- a/libs/freetdm/src/include/private/ftdm_core.h +++ b/libs/freetdm/src/include/private/ftdm_core.h @@ -559,6 +559,7 @@ FT_DECLARE(char *) ftdm_build_dso_path(const char *name, char *path, ftdm_size_t FT_DECLARE(int) ftdm_load_module(const char *name); FT_DECLARE(int) ftdm_load_module_assume(const char *name); FT_DECLARE(int) ftdm_vasprintf(char **ret, const char *fmt, va_list ap); +FT_DECLARE(ftdm_status_t) ftdm_channel_done(ftdm_channel_t *ftdmchan); FIO_CODEC_FUNCTION(fio_slin2ulaw); FIO_CODEC_FUNCTION(fio_ulaw2slin);