Index: channels/chan_dahdi.c =================================================================== --- channels/chan_dahdi.c (revision 134345) +++ channels/chan_dahdi.c (working copy) @@ -3596,14 +3596,33 @@ { int res; struct dahdi_spaninfo zi; +#if defined(HAVE_DAHDI) || defined(HAVE_ZAPTEL_CHANALARMS) + /* + * The conditional compilation is needed only in asterisk-1.4 for + * backward compatibility with old zaptel drivers that don't have + * a DAHDI_PARAMS.chan_alarms field. + */ + struct dahdi_params params; +#endif + memset(&zi, 0, sizeof(zi)); zi.spanno = p->span; - res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SPANSTAT, &zi); - if (res < 0) { + + /* First check for span alarms */ + if((res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_SPANSTAT, &zi)) < 0) { ast_log(LOG_WARNING, "Unable to determine alarm on channel %d: %s\n", p->channel, strerror(errno)); return 0; } - return zi.alarms; + if (zi.alarms != DAHDI_ALARM_NONE) + return zi.alarms; +#if defined(HAVE_DAHDI) || defined(HAVE_ZAPTEL_CHANALARMS) + /* No alarms on the span. Check for channel alarms. */ + if ((res = ioctl(p->subs[SUB_REAL].dfd, DAHDI_GET_PARAMS, ¶ms)) >= 0) + return params.chan_alarms; + /* ioctl failed */ + ast_log(LOG_WARNING, "Unable to determine alarm on channel %d\n", p->channel); +#endif + return DAHDI_ALARM_NONE; } static void dahdi_handle_dtmfup(struct ast_channel *ast, int index, struct ast_frame **dest) Index: configure.ac =================================================================== --- configure.ac (revision 134345) +++ configure.ac (working copy) @@ -1456,6 +1456,15 @@ fi PBX_ZAPTEL=1 AC_DEFINE([HAVE_ZAPTEL], 1, [Define if your system has the Zaptel headers.]) + saved_cppflags="${CPPFLAGS}" + CPPFLAGS="${CPPFLAGS} ${ZAPTEL_INCLUDE}" + AC_CHECK_MEMBER([ZT_PARAMS.chan_alarms],,,[#include ]) + CPPFLAGS="${saved_cppflags}" + if test "${ac_cv_member_ZT_PARAMS_chan_alarms}" = "yes"; then + AC_DEFINE([HAVE_ZAPTEL_CHANALARMS], 1, [Define if your Zaptel drivers have chan_alarms.]) + else + AC_DEFINE([HAVE_ZAPTEL_CHANALARMS], 0, [Define if your Zaptel drivers have chan_alarms.]) + fi elif test -n "${ZAPTEL_MANDATORY}"; then AC_MSG_NOTICE([***]) Index: include/asterisk/autoconfig.h.in =================================================================== --- include/asterisk/autoconfig.h.in (revision 134345) +++ include/asterisk/autoconfig.h.in (working copy) @@ -546,6 +546,9 @@ /* Define if your system has the Zaptel headers. */ #undef HAVE_ZAPTEL +/* Define if your Zaptel drivers have chan_alarms. */ +#undef HAVE_ZAPTEL_CHANALARMS + /* Define to indicate the ${ZLIB_DESCRIP} library */ #undef HAVE_ZLIB