From fb4b7f7a30d967afe146e89561292bdb2c48132e Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Tue, 25 May 2010 17:41:49 -0400 Subject: [PATCH] openzap: disable dtmf app and cmd line option --- libs/openzap/mod_openzap/mod_openzap.c | 61 ++++++++++++++++++- .../src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c | 35 ++++++++++- libs/openzap/src/zap_io.c | 30 +++------ 3 files changed, 101 insertions(+), 25 deletions(-) diff --git a/libs/openzap/mod_openzap/mod_openzap.c b/libs/openzap/mod_openzap/mod_openzap.c index 4741b24e42..03f618787b 100644 --- a/libs/openzap/mod_openzap/mod_openzap.c +++ b/libs/openzap/mod_openzap/mod_openzap.c @@ -2907,7 +2907,7 @@ void dump_chan_xml(zap_span_t *span, uint32_t chan_id, switch_stream_handle_t *s ); } -#define OZ_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix] || gains []" +#define OZ_SYNTAX "list || dump [] || q931_pcap on|off [pcapfilename without suffix] || gains [] || dtmf on|off []" SWITCH_STANDARD_API(oz_function) { char *mycmd = NULL, *argv[10] = { 0 }; @@ -3134,6 +3134,45 @@ SWITCH_STANDARD_API(oz_function) } } stream->write_function(stream, "+OK gains set to Rx %f and Tx %f\n", rxgain, txgain); + } else if (!strcasecmp(argv[0], "dtmf")) { + int i = 0; + uint32_t chan_id = 0; + zap_span_t *span = NULL; + zap_command_t zapcmd = ZAP_COMMAND_ENABLE_DTMF_DETECT; + if (argc < 3) { + stream->write_function(stream, "-ERR Usage: dtmf on|off []\n"); + goto end; + } + + if (switch_true(argv[1])) { + zapcmd = ZAP_COMMAND_ENABLE_DTMF_DETECT; + } else { + zapcmd = ZAP_COMMAND_DISABLE_DTMF_DETECT; + } + + zap_span_find_by_name(argv[2], &span); + if (!span) { + stream->write_function(stream, "-ERR invalid span\n"); + goto end; + } + + if (argc > 3) { + chan_id = atoi(argv[3]); + if (chan_id > span->chan_count) { + stream->write_function(stream, "-ERR invalid chan\n"); + goto end; + } + } + + if (chan_id) { + zap_channel_command(span->channels[chan_id], zapcmd, NULL); + } else { + for (i = 1; i <= (int)span->chan_count; i++) { + zap_channel_command(span->channels[i], zapcmd, NULL); + } + } + + stream->write_function(stream, "+OK DTMF detection was %s\n", zapcmd == ZAP_COMMAND_ENABLE_DTMF_DETECT ? "enabled" : "disabled"); } else if (!strcasecmp(argv[0], "trace")) { char tracepath[255]; int i = 0; @@ -3239,6 +3278,25 @@ SWITCH_STANDARD_APP(disable_ec_function) zap_log(ZAP_LOG_INFO, "Echo Canceller Disabled\n"); } +SWITCH_STANDARD_APP(disable_dtmf_function) +{ + private_t *tech_pvt; + if (!switch_core_session_check_interface(session, openzap_endpoint_interface)) { + zap_log(ZAP_LOG_ERROR, "This application is only for OpenZAP channels.\n"); + return; + } + + tech_pvt = switch_core_session_get_private(session); + + if (switch_test_flag(tech_pvt, TFLAG_DEAD)) { + switch_channel_hangup(switch_core_session_get_channel(session), SWITCH_CAUSE_LOSE_RACE); + return; + } + + zap_channel_command(tech_pvt->zchan, ZAP_COMMAND_DISABLE_DTMF_DETECT, NULL); + zap_log(ZAP_LOG_INFO, "DTMF detection Disabled in channel %d:%d\n", tech_pvt->zchan->span_id, tech_pvt->zchan->chan_id); +} + SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) { @@ -3270,6 +3328,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_openzap_load) SWITCH_ADD_API(commands_api_interface, "oz", "OpenZAP commands", oz_function, OZ_SYNTAX); SWITCH_ADD_APP(app_interface, "disable_ec", "Disable Echo Canceller", "Disable Echo Canceller", disable_ec_function, "", SAF_NONE); + SWITCH_ADD_APP(app_interface, "disable_dtmf", "Disable DTMF Detection", "Disable DTMF Detection", disable_dtmf_function, "", SAF_NONE); /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; diff --git a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c index 2c8068e523..5dea8289ff 100644 --- a/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c +++ b/libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c @@ -585,7 +585,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) { err=sangoma_tdm_enable_hwec(zchan->sockfd, &tdm_api); if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "HWEC Enable Failed"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "HWEC Enable Failed"); return ZAP_FAIL; } } @@ -594,12 +594,41 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command) { err=sangoma_tdm_disable_hwec(zchan->sockfd, &tdm_api); if (err) { - snprintf(zchan->last_error, sizeof(zchan->last_error), "HWEC Disable Failed"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "HWEC Disable Failed"); return ZAP_FAIL; } } break; - case ZAP_COMMAND_ENABLE_LOOP: + case ZAP_COMMAND_ENABLE_DTMF_DETECT: + { +#ifdef WP_API_FEATURE_DTMF_EVENTS + err = sangoma_tdm_enable_dtmf_events(zchan->sockfd, &tdm_api); + if (err) { + zap_log(ZAP_LOG_WARNING, "Enabling of Sangoma HW DTMF failed\n"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "HW DTMF Enable Failed"); + return ZAP_FAIL; + } + zap_log(ZAP_LOG_DEBUG, "Enabled DTMF events on chan %d:%d\n", zchan->span_id, zchan->chan_id); +#else + return ZAP_NOTIMPL; +#endif + } + break; + case ZAP_COMMAND_DISABLE_DTMF_DETECT: + { +#ifdef WP_API_FEATURE_DTMF_EVENTS + err = sangoma_tdm_disable_dtmf_events(zchan->sockfd, &tdm_api); + if (err) { + zap_log(ZAP_LOG_WARNING, "Disabling of Sangoma HW DTMF failed\n"); + snprintf(zchan->last_error, sizeof(zchan->last_error), "HW DTMF Disable Failed"); + return ZAP_FAIL; + } + zap_log(ZAP_LOG_DEBUG, "Disabled DTMF events on chan %d:%d\n", zchan->span_id, zchan->chan_id); +#else + return ZAP_NOTIMPL; +#endif + } + break; { #ifdef WP_API_FEATURE_LOOP err=sangoma_tdm_enable_loop(zchan->sockfd, &tdm_api); diff --git a/libs/openzap/src/zap_io.c b/libs/openzap/src/zap_io.c index b43f60586b..cb341f2a85 100644 --- a/libs/openzap/src/zap_io.c +++ b/libs/openzap/src/zap_io.c @@ -1629,35 +1629,23 @@ OZ_DECLARE(zap_status_t) zap_channel_command(zap_channel_t *zchan, zap_command_t { /* if they don't have thier own, use ours */ if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { - zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; - if (tt == ZAP_TONE_DTMF) { - teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); - zap_set_flag_locked(zchan, ZAP_CHANNEL_DTMF_DETECT); - zap_set_flag_locked(zchan, ZAP_CHANNEL_SUPRESS_DTMF); - GOTO_STATUS(done, ZAP_SUCCESS); - } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); - GOTO_STATUS(done, ZAP_FAIL); - } + teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); + zap_set_flag_locked(zchan, ZAP_CHANNEL_DTMF_DETECT); + zap_set_flag_locked(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + GOTO_STATUS(done, ZAP_SUCCESS); } } break; case ZAP_COMMAND_DISABLE_DTMF_DETECT: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_DTMF_DETECT)) { - zap_tone_type_t tt = ZAP_COMMAND_OBJ_INT; - if (tt == ZAP_TONE_DTMF) { - teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); - zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); - zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); - GOTO_STATUS(done, ZAP_SUCCESS); - } else { - snprintf(zchan->last_error, sizeof(zchan->last_error), "invalid command"); - GOTO_STATUS(done, ZAP_FAIL); - } + teletone_dtmf_detect_init (&zchan->dtmf_detect, zchan->rate); + zap_clear_flag(zchan, ZAP_CHANNEL_DTMF_DETECT); + zap_clear_flag(zchan, ZAP_CHANNEL_SUPRESS_DTMF); + GOTO_STATUS(done, ZAP_SUCCESS); } } - + break; case ZAP_COMMAND_SET_PRE_BUFFER_SIZE: { int val = ZAP_COMMAND_OBJ_INT;