From 938b642245f6d8289400d413e3abcdb4d2ebafc4 Mon Sep 17 00:00:00 2001
From: Richard Mudgett <rmudgett@digium.com>
Date: Mon, 5 Dec 2011 17:44:15 +0000
Subject: [PATCH] Restore call progress code for analog ports.

Extracting sig_analog from chan_dahdi lost call progress detection
functionality.

* Fix analog ports from considering a call answered immediately after
dialing has completed if the callprogress option is enabled.

(closes issue ASTERISK-18841)
Reported by: Richard Miller
Patches:
      chan_dahdi.diff (license #5685) patch uploaded by Richard Miller (Modified by me)
      sig_analog.c.diff (license #5685) patch uploaded by Richard Miller (Modified by me)
      sig_analog.h.diff (license #5685) patch uploaded by Richard Miller
........

Merged revisions 347006 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 347007 from http://svn.asterisk.org/svn/asterisk/branches/10


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@347008 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 channels/chan_dahdi.c | 12 ++++++++++++
 channels/sig_analog.c | 13 ++++++++++++-
 channels/sig_analog.h |  1 +
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index aa3c71fd84..f0ae82650e 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -3615,7 +3615,18 @@ static void my_handle_notify_message(struct ast_channel *chan, void *pvt, int ci
 	}
 }
 
+static int my_have_progressdetect(void *pvt)
+{
+	struct dahdi_pvt *p = pvt;
 
+	if ((p->callprogress & CALLPROGRESS_PROGRESS)
+		&& CANPROGRESSDETECT(p) && p->dsp && p->outgoing) {
+		return 1;
+	} else {
+		/* Don't have progress detection. */
+		return 0;
+	}
+}
 
 static struct analog_callback dahdi_analog_callbacks =
 {
@@ -3683,6 +3694,7 @@ static struct analog_callback dahdi_analog_callbacks =
 	.start_polarityswitch = my_start_polarityswitch,
 	.answer_polarityswitch = my_answer_polarityswitch,
 	.hangup_polarityswitch = my_hangup_polarityswitch,
+	.have_progressdetect = my_have_progressdetect,
 };
 
 /*! Round robin search locations. */
diff --git a/channels/sig_analog.c b/channels/sig_analog.c
index 0035637673..edfd0da9ec 100644
--- a/channels/sig_analog.c
+++ b/channels/sig_analog.c
@@ -200,6 +200,15 @@ static int analog_wait_event(struct analog_pvt *p)
 	return -1;
 }
 
+static int analog_have_progressdetect(struct analog_pvt *p)
+{
+	if (p->calls->have_progressdetect) {
+		return p->calls->have_progressdetect(p->chan_pvt);
+	}
+	/* Don't have progress detection. */
+	return 0;
+}
+
 enum analog_cid_start analog_str_to_cidstart(const char *value)
 {
 	if (!strcasecmp(value, "ring")) {
@@ -2744,7 +2753,9 @@ static struct ast_frame *__analog_handle_event(struct analog_pvt *p, struct ast_
 					}
 				}
 				if (ast->_state == AST_STATE_DIALING) {
-					if (analog_check_confirmanswer(p) || (!p->dialednone
+					if (analog_have_progressdetect(p)) {
+						ast_debug(1, "Done dialing, but waiting for progress detection before doing more...\n");
+					} else if (analog_check_confirmanswer(p) || (!p->dialednone
 						&& ((mysig == ANALOG_SIG_EM) || (mysig == ANALOG_SIG_EM_E1)
 							|| (mysig == ANALOG_SIG_EMWINK) || (mysig == ANALOG_SIG_FEATD)
 							|| (mysig == ANALOG_SIG_FEATDMF_TA) || (mysig == ANALOG_SIG_FEATDMF)
diff --git a/channels/sig_analog.h b/channels/sig_analog.h
index 0f1a6563d5..fd19b53528 100644
--- a/channels/sig_analog.h
+++ b/channels/sig_analog.h
@@ -235,6 +235,7 @@ struct analog_callback {
 	void (* const set_new_owner)(void *pvt, struct ast_channel *new_owner);
 
 	const char *(* const get_orig_dialstring)(void *pvt);
+	int (* const have_progressdetect)(void *pvt);
 };
 
 
-- 
GitLab