From f49ee5ebf9dfcb2cbde425fa4f9d57ed97cb893d Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Thu, 6 Sep 2012 16:53:58 -0400 Subject: [PATCH] FreeTDM: Added function to listen for mg-tdm-dtmfremoval command to disable/enable DTMF removal per channel --- libs/freetdm/mod_freetdm/tdm.c | 64 +++++++++++++------ .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 22 +++++++ libs/freetdm/src/include/freetdm.h | 4 ++ 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index aa787d30c4..0c7657301d 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -141,6 +141,25 @@ static void ctdm_report_alarms(ftdm_channel_t *channel) return; } +static ftdm_channel_t *ctdm_get_channel_from_event(switch_event_t *event, ftdm_span_t *span) +{ + uint32_t chan_id = 0; + const char *chan_number = NULL; + + chan_number = switch_event_get_header(event, "chan-number"); + + if (zstr(chan_number)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channel number specified\n"); + return NULL; + } + chan_id = atoi(chan_number); + if (!chan_id) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid channel number:%s\n", chan_number); + return NULL; + } + + return ftdm_span_get_channel(span, chan_id); +} static void ctdm_event_handler(switch_event_t *event) @@ -152,17 +171,15 @@ static void ctdm_event_handler(switch_event_t *event) ftdm_span_t *span = NULL; ftdm_channel_t *channel = NULL; const char *span_name = NULL; - const char *chan_number = NULL; - uint32_t chan_id = 0; + const char *cond = switch_event_get_header(event, "condition"); - + const char *command = switch_event_get_header(event, "command"); if (zstr(cond)) { return; } span_name = switch_event_get_header(event, "span-name"); - chan_number = switch_event_get_header(event, "chan-number"); - + if (ftdm_span_find_by_name(span_name, &span) != FTDM_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find span [%s]\n", span_name); return; @@ -171,22 +188,12 @@ static void ctdm_event_handler(switch_event_t *event) if (!strcmp(cond, "mg-tdm-prepare")) { status = ctdm_span_prepare(span); if (status == FTDM_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Span %s prepared successfully\n", span_name); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s:prepared successfully\n", span_name); } else if (status != FTDM_EINVAL) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to prepare span %s.\n", span_name); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s:Failed to prepare span\n", span_name); } } else if (!strcmp(cond, "mg-tdm-check")) { - if (zstr(chan_number)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No channel number specified\n"); - return; - } - chan_id = atoi(chan_number); - if (!chan_id) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid channel number:%s\n", chan_number); - return; - } - - channel = ftdm_span_get_channel(span, chan_id); + channel = ctdm_get_channel_from_event(event, span); if (!channel) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find channel\n"); return; @@ -196,6 +203,27 @@ static void ctdm_event_handler(switch_event_t *event) ftdm_channel_get_span_name(channel), ftdm_channel_get_id(channel)); ctdm_report_alarms(channel); + } else if (!strcmp(cond, "mg-tdm-dtmfremoval")) { + uint8_t enable = 0; + channel = ctdm_get_channel_from_event(event, span); + if (!channel) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not find channel\n"); + return; + } + + if (zstr(command)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s:No command specified for mg-tdm-dtmfremoval\n", span_name); + return; + } + + if (!strcmp(command, "enable")) { + enable = 1; + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s DTMF-removal for %s:%d\n", + enable ? "Enabling" : "Disabling", ftdm_channel_get_span_name(channel), ftdm_channel_get_id(channel)); + + ftdm_channel_command(channel, enable ? FTDM_COMMAND_ENABLE_DTMF_REMOVAL : FTDM_COMMAND_DISABLE_DTMF_REMOVAL, 0); } } break; diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index 87ba7ed728..707a82282a 100755 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -764,6 +764,28 @@ static FIO_COMMAND_FUNCTION(wanpipe_command) ftdm_log_chan_msg(ftdmchan, FTDM_LOG_DEBUG, "Disabled DTMF events\n"); #else return FTDM_NOTIMPL; +#endif + } + break; + case FTDM_COMMAND_ENABLE_DTMF_REMOVAL: + { +#ifdef WP_API_FEATURE_LIBSNG_HWEC + int return_code = 0; + err = sangoma_hwec_set_hwdtmf_removal(ftdmchan->sockfd, ftdmchan->physical_chan_id, &return_code, 1, 0); + if (return_code) { + ftdm_log_chan_msg(ftdmchan, FTDM_LOG_ERROR, "Wanpipe failed to Disable HW-DTMF removal\n"); + } +#endif + } + break; + case FTDM_COMMAND_DISABLE_DTMF_REMOVAL: + { +#ifdef WP_API_FEATURE_LIBSNG_HWEC + int return_code = 0; + err = sangoma_hwec_set_hwdtmf_removal(ftdmchan->sockfd, ftdmchan->physical_chan_id, &return_code, 0, 0); + if (return_code) { + ftdm_log_chan_msg(ftdmchan, FTDM_LOG_ERROR, "Wanpipe failed to Disable HW-DTMF removal\n"); + } #endif } break; diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index e041e1f0e7..6f0ac50371 100755 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -733,6 +733,10 @@ typedef enum { /*!< Enable/disable IO stats in the channel */ FTDM_COMMAND_SWITCH_IOSTATS = 60, + /*!< Enable/disable DTMF removal */ + FTDM_COMMAND_ENABLE_DTMF_REMOVAL = 61, + FTDM_COMMAND_DISABLE_DTMF_REMOVAL = 62, + FTDM_COMMAND_COUNT, } ftdm_command_t;