freetdm: hangup the chan call when the core fails to create the session

This commit is contained in:
Moises Silva 2010-04-23 16:28:01 -04:00 committed by Moises Silva
parent 554e433322
commit 56db486189
7 changed files with 45 additions and 24 deletions

View File

@ -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) { 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); switch_core_session_destroy(new_session);
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; 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_codec_destroy(&tech_pvt->write_codec);
} }
switch_core_session_destroy(new_session); switch_core_session_destroy(new_session);
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
goto fail; goto fail;
} }
ftdm_channel_init(ftdmchan); 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; return SWITCH_CAUSE_SUCCESS;
} }
fail: fail:
if (ftdmchan) { if (ftdmchan) {
ftdm_channel_done(ftdmchan); ftdm_channel_call_hangup_with_cause(ftdmchan, FTDM_CAUSE_SWITCH_CONGESTION);
} }
return cause; return cause;

View File

@ -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); ftdm_span_channel_use_count(span, &count);
if (count >= span->chan_count) { if (count >= span->chan_count) {
ftdm_log(FTDM_LOG_CRIT, "All circuits are busy: active=%i max=%i.\n", ftdm_log(FTDM_LOG_ERROR, "All circuits are busy: active=%i max=%i.\n", count, span->chan_count);
count, span->chan_count);
*ftdmchan = NULL; *ftdmchan = NULL;
return FTDM_FAIL; return FTDM_FAIL;
} }
@ -1808,16 +1807,36 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_call_answer(ftdm_channel_t *ftdmchan)
return FTDM_SUCCESS; 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) 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; 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; return FTDM_SUCCESS;
} }
FT_DECLARE(ftdm_status_t) ftdm_channel_call_hangup(ftdm_channel_t *ftdmchan) 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; return FTDM_SUCCESS;
} }

View File

@ -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_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_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 * \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 /* NC: Do nothing here because we are in process
of stopping the call. So ignore the ANSWER. */ 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) { } else if (ftdmchan->state == FTDM_CHANNEL_STATE_HOLD) {
ftdmchan->init_state = FTDM_CHANNEL_STATE_UP; 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); ftdm_mutex_unlock(ftdmchan->mutex);
} else { } 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, sangomabc_exec_command(mcon,
event->span, event->span,
event->chan, 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: case SIGBOOST_EVENT_CALL_RELEASED:
if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 1))) { if (!(ftdmchan = find_ftdmchan(span, (sangomabc_short_event_t*)event, 1))) {
ftdm_log(FTDM_LOG_DEBUG, "PROCESS STATES CANT FIND CHAN %d:%d\n", 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)); BOOST_EVENT_CHAN(((ftdm_sangoma_boost_data_t*)(span->signal_data))->sigmod, event));
return NULL; 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) { ++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)); ftdm_log(FTDM_LOG_ERROR, "Error: Opening PCON Socket [%d] %s\n", sangoma_boost_data->pcon.socket, strerror(errno));
return FTDM_FAIL; return FTDM_FAIL;
} }
/* try to create the boost sockets interrupt objects */ /* 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) { 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; int cnt=0;
ftdm_channel_state_t state_e = ftdm_str2ftdm_channel_state(state); ftdm_channel_state_t state_e = ftdm_str2ftdm_channel_state(state);
if (state_e == FTDM_CHANNEL_STATE_INVALID) { 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++) { for(j = 1; j <= span->chan_count; j++) {
if (span->channels[j]->state != state_e) { if (span->channels[j]->state != state_e) {
@ -2187,7 +2185,7 @@ static ftdm_state_map_t boost_state_map = {
ZSM_UNACCEPTABLE, ZSM_UNACCEPTABLE,
{FTDM_CHANNEL_STATE_HOLD, FTDM_END}, {FTDM_CHANNEL_STATE_HOLD, FTDM_END},
{FTDM_CHANNEL_STATE_PROGRESS_MEDIA, FTDM_CHANNEL_STATE_PROGRESS, {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, ZSD_OUTBOUND,

View File

@ -82,8 +82,8 @@ static void sangomabc_print_event_call(sangomabc_connection_t *mcon, sangomabc_e
priority ? "P":"N", priority ? "P":"N",
sangomabc_event_id_name(event->event_id), sangomabc_event_id_name(event->event_id),
event->event_id, event->event_id,
event->span, BOOST_EVENT_SPAN(mcon->sigmod, event),
event->chan, BOOST_EVENT_CHAN(mcon->sigmod, event),
event->call_setup_id, event->call_setup_id,
event->fseqno, event->fseqno,
strlen(event->calling_name)?event->calling_name:"N/A", 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", priority ? "P":"N",
sangomabc_event_id_name(event->event_id), sangomabc_event_id_name(event->event_id),
event->event_id, event->event_id,
event->span, BOOST_EVENT_SPAN(mcon->sigmod, event),
event->chan, BOOST_EVENT_CHAN(mcon->sigmod, event),
event->release_cause, event->release_cause,
event->call_setup_id, event->call_setup_id,
event->fseqno); event->fseqno);
@ -247,7 +247,7 @@ int sangomabc_exec_command(sangomabc_connection_t *mcon, int span, int chan, int
return -1; return -1;
} else { } else {
ftdm_log(FTDM_LOG_WARNING, "Failed to tx on boost socket: %s :retry %i\n", strerror(errno), retry); ftdm_log(FTDM_LOG_WARNING, "Failed to tx on boost socket: %s :retry %i\n", strerror(errno), retry);
ftdm_sleep(1); ftdm_sleep(1);
} }
} }

View File

@ -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_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); 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 #endif

View File

@ -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_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_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_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(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); FT_DECLARE(uint32_t) ftdm_span_get_chan_count(const ftdm_span_t *span);

View File

@ -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(const char *name);
FT_DECLARE(int) ftdm_load_module_assume(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(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_slin2ulaw);
FIO_CODEC_FUNCTION(fio_ulaw2slin); FIO_CODEC_FUNCTION(fio_ulaw2slin);