From ce70b28f38e6e22068fedc0f7711944f64d15c2d Mon Sep 17 00:00:00 2001
From: Doug Bailey <dbailey@digium.com>
Date: Thu, 25 Jun 2009 16:18:48 +0000
Subject: [PATCH] Insure ring cadence is set for fxs ports

Moved SETCADENCE ioctl call to before call into new analog signal module
to insure that it gets set.

(closes issue #15381)
Reported by: alecdavis
Patches:
      fix15381.diff uploaded by dbailey (license 819)
Tested by: dbailey



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@203126 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 channels/chan_dahdi.c | 39 +++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 765eb19d68..5e9cb5b1b9 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -4154,7 +4154,29 @@ static int dahdi_call(struct ast_channel *ast, char *rdest, int timeout)
 	p->outgoing = 1;
 
 	set_actual_gain(p->subs[SUB_REAL].dfd, 0, p->rxgain, p->txgain, p->law);
-
+	/* Set the ring cadence */
+	mysig = p->sig;
+	if (p->outsigmod > -1)
+		mysig = p->outsigmod;
+	switch (mysig) {
+	case SIG_FXOLS:
+	case SIG_FXOGS:
+	case SIG_FXOKS:
+		if (p->owner == ast) {
+			/* Choose proper cadence */
+			if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) {
+				if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &cadences[p->distinctivering - 1]))
+					ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s': %s\n", p->distinctivering, ast->name, strerror(errno));
+				p->cidrings = cidrings[p->distinctivering - 1];
+			} else {
+				if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, NULL))
+					ast_log(LOG_WARNING, "Unable to reset default ring on '%s': %s\n", ast->name, strerror(errno));
+				p->cidrings = p->sendcalleridafter;
+			}
+		}
+		break;
+	}
+	
 	/* If this is analog signalling we can exit here */
 	if (analog_lib_handles(p->sig, p->radio, p->oprmode)) {
 		p->callwaitrings = 0;
@@ -4163,10 +4185,6 @@ static int dahdi_call(struct ast_channel *ast, char *rdest, int timeout)
 		return res;
 	}
 
-	mysig = p->sig;
-	if (p->outsigmod > -1)
-		mysig = p->outsigmod;
-
 	switch (mysig) {
 	case SIG_FXOLS:
 	case SIG_FXOGS:
@@ -4189,17 +4207,6 @@ static int dahdi_call(struct ast_channel *ast, char *rdest, int timeout)
 					send_callerid(p);
 				}
 			}
-			/* Choose proper cadence */
-			if ((p->distinctivering > 0) && (p->distinctivering <= num_cadence)) {
-				if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, &cadences[p->distinctivering - 1]))
-					ast_log(LOG_WARNING, "Unable to set distinctive ring cadence %d on '%s': %s\n", p->distinctivering, ast->name, strerror(errno));
-				p->cidrings = cidrings[p->distinctivering - 1];
-			} else {
-				if (ioctl(p->subs[SUB_REAL].dfd, DAHDI_SETCADENCE, NULL))
-					ast_log(LOG_WARNING, "Unable to reset default ring on '%s': %s\n", ast->name, strerror(errno));
-				p->cidrings = p->sendcalleridafter;
-			}
-
 			/* nick@dccinc.com 4/3/03 mods to allow for deferred dialing */
 			c = strchr(dest, '/');
 			if (c)
-- 
GitLab