From f57c33f1eee8ea5f818201fcd93ed11b579a9e3a Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Sat, 6 Aug 2011 21:29:46 -0400 Subject: [PATCH] OPENZAP-112 --resolve --- libs/freetdm/conf/freetdm.conf.xml | 5 ++++ libs/freetdm/mod_freetdm/mod_freetdm.c | 4 +++ .../src/ftmod/ftmod_analog/ftdm_analog.h | 3 ++- .../src/ftmod/ftmod_analog/ftmod_analog.c | 23 +++++++++++++++-- libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c | 25 ++++++++++++++++++- libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.h | 7 ++++++ 6 files changed, 63 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/conf/freetdm.conf.xml b/libs/freetdm/conf/freetdm.conf.xml index dd426b089a..d8fa55c8cb 100644 --- a/libs/freetdm/conf/freetdm.conf.xml +++ b/libs/freetdm/conf/freetdm.conf.xml @@ -75,6 +75,11 @@ with the signaling protocols that you can run on top of your I/O interfaces. --> + + + diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index c3ca4786d5..9d6eac94f5 100755 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -3021,6 +3021,7 @@ static switch_status_t load_config(void) const char *enable_callerid = "true"; const char *answer_polarity = "false"; const char *hangup_polarity = "false"; + const char *polarity_callerid = "false"; int polarity_delay = 600; int callwaiting = 1; int dialtone_timeout = 5000; @@ -3102,6 +3103,8 @@ static switch_status_t load_config(void) hangup_polarity = val; } else if (!strcasecmp(var, "polarity-delay")) { polarity_delay = atoi(val); + } else if (!strcasecmp(var, "polarity-callerid")) { + polarity_callerid = val; } else if (!strcasecmp(var, "fail-dial-regex")) { fail_dial_regex = val; } else if (!strcasecmp(var, "hold-music")) { @@ -3164,6 +3167,7 @@ static switch_status_t load_config(void) "enable_callerid", enable_callerid, "answer_polarity_reverse", answer_polarity, "hangup_polarity_reverse", hangup_polarity, + "polarity_callerid", polarity_callerid, "polarity_delay", &polarity_delay, "callwaiting", &callwaiting, "wait_dialtone_timeout", &dialtone_timeout, diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h b/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h index 39cbc5ff2b..a2339120c5 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h +++ b/libs/freetdm/src/ftmod/ftmod_analog/ftdm_analog.h @@ -39,7 +39,8 @@ typedef enum { FTDM_ANALOG_RUNNING = (1 << 0), FTDM_ANALOG_CALLERID = (1 << 1), FTDM_ANALOG_ANSWER_POLARITY_REVERSE = (1 << 2), - FTDM_ANALOG_HANGUP_POLARITY_REVERSE = (1 << 3) + FTDM_ANALOG_HANGUP_POLARITY_REVERSE = (1 << 3), + FTDM_ANALOG_POLARITY_CALLERID = (1 << 4) } ftdm_analog_flag_t; #define FTDM_MAX_HOTLINE_STR 20 diff --git a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c index 27eecb4f7f..cfbc4807f3 100644 --- a/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c +++ b/libs/freetdm/src/ftmod/ftmod_analog/ftmod_analog.c @@ -275,6 +275,15 @@ static FIO_SIG_CONFIGURE_FUNCTION(ftdm_analog_configure_span) break; } hotline = val; + } else if (!strcasecmp(var, "polarity_callerid")) { + if (!(val = va_arg(ap, char *))) { + break; + } + if (ftdm_true(val)) { + flags |= FTDM_ANALOG_POLARITY_CALLERID; + } else { + flags &= ~FTDM_ANALOG_POLARITY_CALLERID; + } } else { ftdm_log(FTDM_LOG_ERROR, "Unknown parameter %s in span %s\n", var, span->name); } @@ -1130,8 +1139,18 @@ static __inline__ ftdm_status_t process_event(ftdm_span_t *span, ftdm_event_t *e break; } if (event->channel->state == FTDM_CHANNEL_STATE_DOWN) { - ftdm_log_chan_msg(event->channel, FTDM_LOG_DEBUG, - "Ignoring polarity reversal because this channel is down\n"); + if (ftdm_test_flag(analog_data, FTDM_ANALOG_CALLERID) + && ftdm_test_flag(analog_data, FTDM_ANALOG_POLARITY_CALLERID)) { + ftdm_log_chan_msg(event->channel, "Polarity reversal detected while down, getting caller id now\n"); + ftdm_set_state(event->channel, FTDM_CHANNEL_STATE_GET_CALLERID); + event->channel->ring_count = 1; + ftdm_mutex_unlock(event->channel->mutex); + locked = 0; + ftdm_thread_create_detached(ftdm_analog_channel_run); + } else { + ftdm_log_chan_msg(event->channel, FTDM_LOG_DEBUG, + "Ignoring polarity reversal because this channel is down\n"); + } break; } /* we have a good channel, set the polarity flag and let the channel thread deal with it */ diff --git a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c index 982412d334..4e7914685b 100644 --- a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c +++ b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c @@ -29,6 +29,12 @@ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributors: + * + * Moises Silva + * W McRoberts + * */ #include "private/ftdm_core.h" @@ -94,6 +100,7 @@ struct ioctl_codes { ioctlcmd ECHOTRAIN; ioctlcmd SETTXBITS; ioctlcmd GETRXBITS; + ioctlcmd SETPOLARITY; }; /** @@ -169,7 +176,8 @@ static struct ioctl_codes dahdi_ioctl_codes = { .GETCONFMUTE = DAHDI_GETCONFMUTE, .ECHOTRAIN = DAHDI_ECHOTRAIN, .SETTXBITS = DAHDI_SETTXBITS, - .GETRXBITS = DAHDI_GETRXBITS + .GETRXBITS = DAHDI_GETRXBITS, + .SETPOLARITY = DAHDI_SETPOLARITY }; #define ZT_INVALID_SOCKET -1 @@ -826,6 +834,15 @@ static FIO_COMMAND_FUNCTION(zt_command) err = ioctl(ftdmchan->sockfd, codes.FLUSH, &flushmode); } break; + case FTDM_COMMAND_SET_POLARITY: + { + ftdm_polarity_t polarity = FTDM_COMMAND_OBJ_INT; + err = ioctl(ftdmchan->sockfd, codes.SETPOLARITY, polarity); + if (!err) { + ftdmchan->polarity = polarity; + } + } + break; case FTDM_COMMAND_FLUSH_RX_BUFFERS: { int flushmode = ZT_FLUSH_READ; @@ -1088,6 +1105,12 @@ static __inline__ ftdm_status_t zt_channel_process_event(ftdm_channel_t *fchan, *event_id = FTDM_OOB_NOOP; /* What else could we do? */ } break; + case ZT_EVENT_POLARITY: + { + ftdm_log_chan_msg(fchan, FTDM_LOG_ERROR, "Got polarity reverse (ZT_EVENT_POLARITY)\n"); + *event_id = FTDM_OOB_POLARITY_REVERSE; + } + break; case ZT_EVENT_NONE: { ftdm_log_chan_msg(fchan, FTDM_LOG_DEBUG, "No event\n"); diff --git a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.h b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.h index cf5479dba1..065d7e63e2 100644 --- a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.h +++ b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.h @@ -29,6 +29,12 @@ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Contributors: + * + * Moises Silva + * W McRoberts + * */ #ifndef FTDM_ZT_H @@ -349,6 +355,7 @@ ZT_ABIT = 8 #define DAHDI_SETTXBITS _IOW (DAHDI_CODE, 43, int) #define DAHDI_GETRXBITS _IOR (DAHDI_CODE, 43, int) +#define DAHDI_SETPOLARITY _IOW (DAHDI_CODE, 92, int) /* Polarity setting for FXO lines */ #endif