From c15a252a2b185d29f9b283d07433d91032a35e0f Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 30 Dec 2011 17:14:36 -0500 Subject: [PATCH 1/3] OPENZAP-176 --resolve Fix DAHDI/Zaptel incorrect FXO signaling status on module load --- libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c | 25 ++++++++++++++++++++++ libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.h | 4 ++++ 2 files changed, 29 insertions(+) diff --git a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c index 677bcbbd56..87632c8f66 100644 --- a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c +++ b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.c @@ -34,6 +34,7 @@ * * Moises Silva * W McRoberts + * Puskás Zsolt * */ @@ -877,10 +878,13 @@ static FIO_COMMAND_FUNCTION(zt_command) static FIO_GET_ALARMS_FUNCTION(zt_get_alarms) { struct zt_spaninfo info; + zt_params_t params; memset(&info, 0, sizeof(info)); info.span_no = ftdmchan->physical_span_id; + memset(¶ms, 0, sizeof(params)); + if (ioctl(CONTROL_FD, codes.SPANSTAT, &info)) { snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "ioctl failed (%s)", strerror(errno)); snprintf(ftdmchan->span->last_error, sizeof(ftdmchan->span->last_error), "ioctl failed (%s)", strerror(errno)); @@ -889,6 +893,27 @@ static FIO_GET_ALARMS_FUNCTION(zt_get_alarms) ftdmchan->alarm_flags = info.alarms; + /* get channel alarms if span has no alarms */ + if (info.alarms == FTDM_ALARM_NONE) { + if (ioctl(ftdmchan->sockfd, codes.GET_PARAMS, ¶ms)) { + snprintf(ftdmchan->last_error, sizeof(ftdmchan->last_error), "ioctl failed (%s)", strerror(errno)); + snprintf(ftdmchan->span->last_error, sizeof(ftdmchan->span->last_error), "ioctl failed (%s)", strerror(errno)); + return FTDM_FAIL; + } + + if (params.chan_alarms > 0) { + if (params.chan_alarms == DAHDI_ALARM_YELLOW) { + ftdmchan->alarm_flags = FTDM_ALARM_YELLOW; + } + else if (params.chan_alarms == DAHDI_ALARM_BLUE) { + ftdmchan->alarm_flags = FTDM_ALARM_BLUE; + } + else { + ftdmchan->alarm_flags = FTDM_ALARM_RED; + } + } + } + return FTDM_SUCCESS; } diff --git a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.h b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.h index 065d7e63e2..40b5a4e71d 100644 --- a/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.h +++ b/libs/freetdm/src/ftmod/ftmod_zt/ftmod_zt.h @@ -339,6 +339,10 @@ ZT_ABIT = 8 #define DAHDI_HDLCRAWMODE _IOW (DAHDI_CODE, 36, int) /* Set a clear channel into HDLC w/out FCS checking/calculation mode */ #define DAHDI_HDLCFCSMODE _IOW (DAHDI_CODE, 37, int) /* Set a clear channel into HDLC w/ FCS mode */ +/* Dahdi channel alarms */ +#define DAHDI_ALARM_YELLOW (1 << 2) /* Yellow Alarm */ +#define DAHDI_ALARM_BLUE (1 << 4) /* Blue Alarm */ + /* Specify a channel on /dev/dahdi/chan -- must be done before any other ioctl's and is only valid on /dev/dahdi/chan */ #define DAHDI_SPECIFY _IOW (DAHDI_CODE, 38, int) From 2b904c0b9ee9e58ae5e3abd436f76d5ed7e61666 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Fri, 30 Dec 2011 18:28:27 -0500 Subject: [PATCH 2/3] freetdm: ftmod_wanpipe - Do not set the output read length unless the read operation is successful --- libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index d0d66205a5..f63a275194 100644 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -1016,7 +1016,7 @@ static FIO_READ_FUNCTION(wanpipe_read) memset(&hdrframe, 0, sizeof(hdrframe)); rx_len = sangoma_readmsg_tdm(ftdmchan->sockfd, &hdrframe, (int)sizeof(hdrframe), data, (int)*datalen, 0); - *datalen = rx_len; + *datalen = 0; if (rx_len == 0) { ftdm_log_chan_msg(ftdmchan, FTDM_LOG_WARNING, "Read 0 bytes\n"); @@ -1033,6 +1033,7 @@ static FIO_READ_FUNCTION(wanpipe_read) #endif return FTDM_FAIL; } + *datalen = rx_len; if (ftdm_channel_test_feature(ftdmchan, FTDM_CHANNEL_FEATURE_IO_STATS)) { wanpipe_read_stats(ftdmchan, &hdrframe); From 79992ac5fe5d5b61bb8694e921e7ff824629156a Mon Sep 17 00:00:00 2001 From: Jeff Lenk Date: Sun, 1 Jan 2012 22:40:23 -0600 Subject: [PATCH 3/3] refactor switch_fulldate_cmp and correct usec comparison and year month error --- src/switch_utils.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/switch_utils.c b/src/switch_utils.c index 4624badc07..808afd0c57 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -2342,6 +2342,9 @@ SWITCH_DECLARE(int) switch_fulldate_cmp(const char *exp, switch_time_t *ts) char *sTime; switch_time_t tsStart; switch_time_t tsEnd; + struct tm tmTmp; + int year, month, day; + int hour, min, sec; switch_assert(dup); @@ -2350,16 +2353,13 @@ SWITCH_DECLARE(int) switch_fulldate_cmp(const char *exp, switch_time_t *ts) *sEnd++ = '\0'; sDate = sStart; if ((sTime=strchr(sStart, ' '))) { - struct tm tmTmp; - int year, month, day; - int hour, min, sec; - *sTime++ = '\0'; + memset(&tmTmp, 0, sizeof(tmTmp)); switch_split_date(sDate, &year, &month, &day); switch_split_time(sTime, &hour, &min, &sec); - tmTmp.tm_year = year; - tmTmp.tm_mon = month; + tmTmp.tm_year = year-1900; + tmTmp.tm_mon = month-1; tmTmp.tm_mday = day; tmTmp.tm_hour = hour; @@ -2370,16 +2370,13 @@ SWITCH_DECLARE(int) switch_fulldate_cmp(const char *exp, switch_time_t *ts) sDate = sEnd; if ((sTime=strchr(sEnd, ' '))) { - struct tm tmTmp; - int year, month, day; - int hour, min, sec; - *sTime++ = '\0'; + memset(&tmTmp, 0, sizeof(tmTmp)); switch_split_date(sDate, &year, &month, &day); switch_split_time(sTime, &hour, &min, &sec); - tmTmp.tm_year = year; - tmTmp.tm_mon = month; + tmTmp.tm_year = year-1900; + tmTmp.tm_mon = month-1; tmTmp.tm_mday = day; tmTmp.tm_hour = hour; @@ -2388,7 +2385,7 @@ SWITCH_DECLARE(int) switch_fulldate_cmp(const char *exp, switch_time_t *ts) tmTmp.tm_isdst = 0; tsEnd = mktime(&tmTmp); - if (tsStart <= *ts && tsEnd > *ts) { + if (tsStart <= *ts/1000000 && tsEnd > *ts/1000000) { switch_safe_free(dup); return 1; }