diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index 710fdd614d..842bde8347 100644 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -2345,7 +2345,7 @@ static switch_status_t load_config(void) } } - if (ftdm_configure_span("ss7", span, on_ss7_signal, + if (ftdm_configure_span(span, "ss7", on_ss7_signal, "confnode", ss7confnode, "parameters", spanparameters, FTDM_TAG_END) != FTDM_SUCCESS) { @@ -2450,7 +2450,7 @@ static switch_status_t load_config(void) span_id = ftdm_span_get_id(span); } - if (ftdm_configure_span("analog", span, on_analog_signal, + if (ftdm_configure_span(span, "analog", on_analog_signal, "tonemap", tonegroup, "digit_timeout", &to, "max_dialstr", &max, @@ -2566,7 +2566,7 @@ static switch_status_t load_config(void) } - if (ftdm_configure_span("analog_em", span, on_analog_signal, + if (ftdm_configure_span(span, "analog_em", on_analog_signal, "tonemap", tonegroup, "digit_timeout", &to, "max_dialstr", &max, @@ -2683,7 +2683,7 @@ static switch_status_t load_config(void) tonegroup = "us"; } - if (ftdm_configure_span("isdn", span, on_clear_channel_signal, + if (ftdm_configure_span(span, "isdn", on_clear_channel_signal, "mode", mode, "dialect", dialect, "digit_timeout", &to, @@ -2778,7 +2778,7 @@ static switch_status_t load_config(void) } - if (ftdm_configure_span("libpri", span, on_clear_channel_signal, + if (ftdm_configure_span(span, "libpri", on_clear_channel_signal, "node", o_node, "switch", o_switch, "dp", o_dp, @@ -2866,7 +2866,7 @@ static switch_status_t load_config(void) span_id = ftdm_span_get_id(span); } - if (ftdm_configure_span_signaling("sangoma_boost", span, on_clear_channel_signal, spanparameters) != FTDM_SUCCESS) { + if (ftdm_configure_span_signaling(span, "sangoma_boost", on_clear_channel_signal, spanparameters) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "Error starting FreeTDM span %d error: %s\n", span_id, ftdm_span_get_last_error(span)); continue; } @@ -3001,7 +3001,7 @@ static switch_status_t load_config(void) span_id = ftdm_span_get_id(span); } - if (ftdm_configure_span("r2", span, on_r2_signal, + if (ftdm_configure_span(span, "r2", on_r2_signal, "variant", variant, "max_ani", max_ani, "max_dnis", max_dnis, @@ -3420,14 +3420,14 @@ SWITCH_STANDARD_API(ft_function) tmp_path=switch_mprintf("%s%s%s.pcap", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR, pcapfn); if(!strcasecmp(argv[2], "on")) { - if (ftdm_configure_span("isdn", span, on_clear_channel_signal, "q931topcap", 1, "pcapfilename", tmp_path, FTDM_TAG_END) != FTDM_SUCCESS) { + if (ftdm_configure_span(span, "isdn", on_clear_channel_signal, "q931topcap", 1, "pcapfilename", tmp_path, FTDM_TAG_END) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_WARNING, "Error couldn't (re-)enable Q931-To-Pcap!\n"); goto end; } else { stream->write_function(stream, "+OK\n"); } } else if(!strcasecmp(argv[2], "off")) { - if (ftdm_configure_span("isdn", span, on_clear_channel_signal, "q931topcap", 0, FTDM_TAG_END) != FTDM_SUCCESS) { + if (ftdm_configure_span(span, "isdn", on_clear_channel_signal, "q931topcap", 0, FTDM_TAG_END) != FTDM_SUCCESS) { ftdm_log(FTDM_LOG_ERROR, "Error couldn't enable Q931-To-Pcap!\n"); goto end; } else { diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 03c1853ddc..0aedd8ff0e 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -1369,7 +1369,6 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_group(uint32_t group_id, ftdm_dir status = check->fio->open(check); if (status == FTDM_SUCCESS) { - ftdm_set_flag(check, FTDM_CHANNEL_INUSE); ftdm_channel_open_chan(check); *ftdmchan = check; break; @@ -1489,7 +1488,6 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open_by_span(uint32_t span_id, ftdm_direc status = check->fio->open(check); if (status == FTDM_SUCCESS) { - ftdm_set_flag(check, FTDM_CHANNEL_INUSE); ftdm_channel_open_chan(check); *ftdmchan = check; break; @@ -1639,7 +1637,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_open(uint32_t span_id, uint32_t chan_id, status = FTDM_FAIL; if (ftdm_test_flag(check, FTDM_CHANNEL_READY) && (!ftdm_test_flag(check, FTDM_CHANNEL_INUSE) || - (check->type == FTDM_CHAN_TYPE_FXS && check->token_count == 1))) { + (check->type == FTDM_CHAN_TYPE_FXS && check->token_count == 1))) { if (!ftdm_test_flag(check, FTDM_CHANNEL_OPEN)) { status = check->fio->open(check); if (status == FTDM_SUCCESS) { @@ -3790,7 +3788,23 @@ FT_DECLARE(ftdm_status_t) ftdm_unload_modules(void) return FTDM_SUCCESS; } -FT_DECLARE(ftdm_status_t) ftdm_configure_span(const char *type, ftdm_span_t *span, fio_signal_cb_t sig_cb, ...) +static ftdm_status_t post_configure_span_channels(ftdm_span_t *span) +{ + unsigned i = 0; + ftdm_signaling_status_t status = FTDM_SUCCESS; + for (i = 1; i <= span->chan_count; i++) { + ftdm_channel_get_sig_status(span->channels[i], &status); + if (status == FTDM_SIG_STATE_UP) { + ftdm_set_flag(span->channels[i], FTDM_CHANNEL_SIG_UP); + } + } + if (ftdm_test_flag(span, FTDM_SPAN_USE_CHAN_QUEUE)) { + status = ftdm_queue_create(&span->pendingchans, SPAN_PENDING_CHANS_QUEUE_SIZE); + } + return status; +} + +FT_DECLARE(ftdm_status_t) ftdm_configure_span(ftdm_span_t *span, const char *type, fio_signal_cb_t sig_cb, ...) { ftdm_module_t *mod = (ftdm_module_t *) hashtable_search(globals.module_hash, (void *)type); ftdm_status_t status = FTDM_FAIL; @@ -3812,8 +3826,8 @@ FT_DECLARE(ftdm_status_t) ftdm_configure_span(const char *type, ftdm_span_t *spa va_start(ap, sig_cb); status = mod->sig_configure(span, sig_cb, ap); va_end(ap); - if (status == FTDM_SUCCESS && ftdm_test_flag(span, FTDM_SPAN_USE_CHAN_QUEUE)) { - status = ftdm_queue_create(&span->pendingchans, SPAN_PENDING_CHANS_QUEUE_SIZE); + if (status == FTDM_SUCCESS) { + status = post_configure_span_channels(span); } } else { ftdm_log(FTDM_LOG_ERROR, "can't find '%s'\n", type); @@ -3823,7 +3837,7 @@ FT_DECLARE(ftdm_status_t) ftdm_configure_span(const char *type, ftdm_span_t *spa return status; } -FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(const char *type, ftdm_span_t *span, fio_signal_cb_t sig_cb, ftdm_conf_parameter_t *parameters) +FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(ftdm_span_t *span, const char *type, fio_signal_cb_t sig_cb, ftdm_conf_parameter_t *parameters) { ftdm_module_t *mod = (ftdm_module_t *) hashtable_search(globals.module_hash, (void *)type); ftdm_status_t status = FTDM_FAIL; @@ -3852,8 +3866,8 @@ FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(const char *type, ftdm_s if (mod->configure_span_signaling) { status = mod->configure_span_signaling(span, sig_cb, parameters); - if (status == FTDM_SUCCESS && ftdm_test_flag(span, FTDM_SPAN_USE_CHAN_QUEUE)) { - status = ftdm_queue_create(&span->pendingchans, SPAN_PENDING_CHANS_QUEUE_SIZE); + if (status == FTDM_SUCCESS) { + status = post_configure_span_channels(span); } } else { ftdm_log(FTDM_LOG_ERROR, "Module %s did not implement the signaling configuration method\n", type); diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index b61a835b0f..c3bf93392d 100644 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -1005,8 +1005,8 @@ FT_DECLARE(uint32_t) ftdm_channel_get_ph_id(const ftdm_channel_t *ftdmchan); * * \note This function does the same as ftdm_configure_span_signaling * - * \param type The signaling type ("boost", "isdn" and others, this depends on the available signaling modules) * \param span The span to configure + * \param type The signaling type ("boost", "isdn" and others, this depends on the available signaling modules) * \param sig_cb The callback that the signaling stack will use to notify about events * \param ... variable argument list with "var", value sequence, the variable and values are signaling type dependant * the last argument must be FTDM_TAG_END @@ -1014,22 +1014,22 @@ FT_DECLARE(uint32_t) ftdm_channel_get_ph_id(const ftdm_channel_t *ftdmchan); * \retval FTDM_SUCCESS success * \retval FTDM_FAIL failure */ -FT_DECLARE(ftdm_status_t) ftdm_configure_span(const char *type, ftdm_span_t *span, fio_signal_cb_t sig_cb, ...); +FT_DECLARE(ftdm_status_t) ftdm_configure_span(ftdm_span_t *span, const char *type, fio_signal_cb_t sig_cb, ...); #define FTDM_TAG_END NULL /*! * \brief Configure span with a signaling type * - * \param type The signaling type ("boost", "isdn" and others, this depends on the available signaling modules) * \param span The span to configure + * \param type The signaling type ("boost", "isdn" and others, this depends on the available signaling modules) * \param sig_cb The callback that the signaling stack will use to notify about events * \param ... variable argument list with "var", value sequence, the variable and values are signaling type dependant * * \retval FTDM_SUCCESS success * \retval FTDM_FAIL failure */ -FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(const char *type, ftdm_span_t *span, fio_signal_cb_t sig_cb, ftdm_conf_parameter_t *parameters); +FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(ftdm_span_t *span, const char *type, fio_signal_cb_t sig_cb, ftdm_conf_parameter_t *parameters); /*! * \brief Start the span signaling (must call ftdm_configure_span_signaling first) diff --git a/libs/freetdm/src/testanalog.c b/libs/freetdm/src/testanalog.c index ccfa33a161..83bace9b4a 100644 --- a/libs/freetdm/src/testanalog.c +++ b/libs/freetdm/src/testanalog.c @@ -100,7 +100,7 @@ int main(int argc, char *argv[]) } - if (ftdm_configure_span("analog", span, on_signal, + if (ftdm_configure_span(span, "analog", on_signal, "tonemap", "us", "digit_timeout", &digit_timeout, "max_dialstr", &max_dialstr, diff --git a/libs/freetdm/src/testboost.c b/libs/freetdm/src/testboost.c index 93d7d894af..f55a46a11a 100644 --- a/libs/freetdm/src/testboost.c +++ b/libs/freetdm/src/testboost.c @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) parameters[1].var = "signalling"; parameters[1].val = "pri_cpe"; parameters[2].var = NULL; - if (ftdm_configure_span_signaling("sangoma_boost", span, on_signal, parameters) == FTDM_SUCCESS) { + if (ftdm_configure_span_signaling(span, "sangoma_boost", on_signal, parameters) == FTDM_SUCCESS) { ftdm_span_start(span); } else { fprintf(stderr, "Error starting SS7_BOOST\n"); diff --git a/libs/freetdm/src/testpri.c b/libs/freetdm/src/testpri.c index eb498f3b80..b75295d841 100644 --- a/libs/freetdm/src/testpri.c +++ b/libs/freetdm/src/testpri.c @@ -128,7 +128,7 @@ int main(int argc, char *argv[]) if (ftdm_configure_span( - "libpri", span, on_signal, + span, "libpri", on_signal, "node", "cpe", "switch", "euroisdn", "dp", "unknown", diff --git a/libs/freetdm/src/testr2.c b/libs/freetdm/src/testr2.c index 8ceb527e58..8ac90c59fd 100644 --- a/libs/freetdm/src/testr2.c +++ b/libs/freetdm/src/testr2.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) - if (ftdm_configure_span("r2", span, on_r2_signal, + if (ftdm_configure_span(span, "r2", on_r2_signal, "variant", "mx", "max_ani", 10, "max_dnis", 4, diff --git a/libs/freetdm/src/testsangomaboost.c b/libs/freetdm/src/testsangomaboost.c index 7dbe32e83d..b85bcc0634 100644 --- a/libs/freetdm/src/testsangomaboost.c +++ b/libs/freetdm/src/testsangomaboost.c @@ -339,7 +339,7 @@ int main(int argc, char *argv[]) parameters[3].var = NULL; /* send the configuration values down to the stack */ - if (ftdm_configure_span_signaling("sangoma_boost", span, on_signaling_event, parameters) != FTDM_SUCCESS) { + if (ftdm_configure_span_signaling(span, "sangoma_boost", on_signaling_event, parameters) != FTDM_SUCCESS) { fprintf(stderr, "Error configuring sangoma_boost signaling abstraction in span %s\n", ftdm_span_get_name(span)); goto done; }