From e8a99a9962212fcc7b503e3e1ea42f9e2eed223b Mon Sep 17 00:00:00 2001
From: Jeff Peeler <jpeeler@digium.com>
Date: Wed, 3 Mar 2010 19:06:06 +0000
Subject: [PATCH] Merged revisions 250480 via svnmerge from
 https://origsvn.digium.com/svn/asterisk/branches/1.4

........
  r250480 | jpeeler | 2010-03-03 13:04:11 -0600 (Wed, 03 Mar 2010) | 15 lines

  Make sure to clear red alarm after polarity reversal.

  From the issue:
  The automatic overnight line tests (or manual ones) used on UK (BT) lines causes
  a red alarm on a dahdi / TDM400P connected channel. This is because the line
  uses voltage tests (battery loss) and polarity reversal. The polarity reversal
  causes chan_dahdi to initiate v23 CallerID processing but during this the event
  DAHDI_EVENT_NOALARM is ignored so that the alarm is never cleared.

  (closes issue #14163)
  Reported by: jedi98
  Patches:
        chan_dahdi-1.4-inalarm.diff uploaded by jedi98 (license 653)
  Tested by: mattbrown, Chainsaw, mikeeccleston
........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@250481 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 channels/chan_dahdi.c | 16 ++++++++++++++++
 channels/sig_analog.c |  7 ++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index a9f322769c..169760068b 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -1732,6 +1732,10 @@ static int my_distinctive_ring(struct ast_channel *chan, void *pvt, int idx, int
 			}
 			if (i & DAHDI_IOMUX_SIGEVENT) {
 				res = dahdi_get_event(p->subs[idx].dfd);
+				if (res == DAHDI_EVENT_NOALARM) {
+					p->inalarm = 0;
+					analog_p->inalarm = 0;
+				}
 				ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
 				res = 0;
 				/* Let us detect distinctive ring */
@@ -9516,6 +9520,9 @@ static void *analog_ss_thread(void *data)
 						if (i & DAHDI_IOMUX_SIGEVENT) {
 							res = dahdi_get_event(p->subs[idx].dfd);
 							ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
+							if (res == DAHDI_EVENT_NOALARM) {
+								p->inalarm = 0;
+							}
 
 							if (p->cid_signalling == CID_SIG_V23_JP) {
 								if (res == DAHDI_EVENT_RINGBEGIN) {
@@ -9617,6 +9624,9 @@ static void *analog_ss_thread(void *data)
 							if (i & DAHDI_IOMUX_SIGEVENT) {
 								res = dahdi_get_event(p->subs[idx].dfd);
 								ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
+								if (res == DAHDI_EVENT_NOALARM) {
+									p->inalarm = 0;
+								}
 								res = 0;
 								/* Let us detect distinctive ring */
 
@@ -9766,6 +9776,9 @@ static void *analog_ss_thread(void *data)
 						if (i & DAHDI_IOMUX_SIGEVENT) {
 							res = dahdi_get_event(p->subs[idx].dfd);
 							ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
+							if (res == DAHDI_EVENT_NOALARM) {
+								p->inalarm = 0;
+							}
 							/* If we get a PR event, they hung up while processing calerid */
 							if ( res == DAHDI_EVENT_POLARITY && p->hanguponpolarityswitch && p->polarity == POLARITY_REV) {
 								ast_log(LOG_DEBUG, "Hanging up due to polarity reversal on channel %d while detecting callerid\n", p->channel);
@@ -9835,6 +9848,9 @@ static void *analog_ss_thread(void *data)
 							if (i & DAHDI_IOMUX_SIGEVENT) {
 								res = dahdi_get_event(p->subs[idx].dfd);
 								ast_log(LOG_NOTICE, "Got event %d (%s)...\n", res, event2str(res));
+								if (res == DAHDI_EVENT_NOALARM) {
+									p->inalarm = 0;
+								}
 								res = 0;
 								/* Let us detect callerid when the telco uses distinctive ring */
 
diff --git a/channels/sig_analog.c b/channels/sig_analog.c
index 9542bacec8..3e8e9f317b 100644
--- a/channels/sig_analog.c
+++ b/channels/sig_analog.c
@@ -2161,6 +2161,9 @@ static void *__analog_ss_thread(void *data)
 						}
 
 						if (res == 1) {
+							if (ev == ANALOG_EVENT_NOALARM) {
+								p->inalarm = 0;
+							}
 							if (p->cid_signalling == CID_SIG_V23_JP) {
 								if (ev == ANALOG_EVENT_RINGBEGIN) {
 									analog_off_hook(p);
@@ -2249,7 +2252,9 @@ static void *__analog_ss_thread(void *data)
 					}
 
 					if (res == 1 || res == 2) {
-						if (ev == ANALOG_EVENT_POLARITY && p->hanguponpolarityswitch && p->polarity == POLARITY_REV) {
+						if (ev == ANALOG_EVENT_NOALARM) {
+							p->inalarm = 0;
+						} else if (ev == ANALOG_EVENT_POLARITY && p->hanguponpolarityswitch && p->polarity == POLARITY_REV) {
 							ast_debug(1, "Hanging up due to polarity reversal on channel %d while detecting callerid\n", p->channel);
 							p->polarity = POLARITY_IDLE;
 							ast_hangup(chan);
-- 
GitLab