From 63d49a667e802238e813f258b64618549d3293b4 Mon Sep 17 00:00:00 2001
From: Jim Dixon <telesistant@hotmail.com>
Date: Sun, 23 Mar 2003 17:14:29 +0000
Subject: [PATCH] Fixed so that dial from a Zap channel to a Zap channel in
 'dataquality' mode actually puts channels into CLEAR mode (so that 56k ISDN
 calls will work thru it) 64K calls STILL DONT.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@677 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 apps/app_dial.c          |  6 +++++-
 channels/chan_zap.c      | 18 +++++++++++++++++-
 include/asterisk/frame.h |  3 +++
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/apps/app_dial.c b/apps/app_dial.c
index ac9953bc3e..e68f5137e7 100755
--- a/apps/app_dial.c
+++ b/apps/app_dial.c
@@ -545,12 +545,16 @@ static int dial_exec(struct ast_channel *chan, void *data)
 			int x = 2;
 			if (tmp->dataquality) x = 0;
 			ast_channel_setoption(chan,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0);
+			x = 0;
+			ast_channel_setoption(chan,AST_OPTION_AUDIO_MODE,&x,sizeof(char),0);
 		}			
 		if (!strcmp(peer->type,"Zap"))
 		{
 			int x = 2;
 			if (tmp->dataquality) x = 0;
 			ast_channel_setoption(peer,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0);
+			x = 0;
+			ast_channel_setoption(chan,AST_OPTION_AUDIO_MODE,&x,sizeof(char),0);
 		}			
 		hanguptree(outgoing, peer);
 		outgoing = NULL;
@@ -573,7 +577,7 @@ static int dial_exec(struct ast_channel *chan, void *data)
  			ast_log(LOG_DEBUG, "app_dial: sendurl=%s.\n", url);
  			ast_channel_sendurl( peer, url );
  		} /* /JDG */
-		res = ast_bridge_call(chan, peer, allowredir, allowdisconnect);
+		res = ast_bridge_call(chan, peer, allowredir, allowdisconnect | tmp->dataquality);
 		ast_hangup(peer);
 	}	
 out:
diff --git a/channels/chan_zap.c b/channels/chan_zap.c
index d762d87cde..a6a49f3bda 100755
--- a/channels/chan_zap.c
+++ b/channels/chan_zap.c
@@ -1617,6 +1617,8 @@ static int zt_hangup(struct ast_channel *ast)
 		x = 0;
 		ast_channel_setoption(ast,AST_OPTION_TONE_VERIFY,&x,sizeof(char),0);
 		ast_channel_setoption(ast,AST_OPTION_TDD,&x,sizeof(char),0);
+		x = 1;
+		ast_channel_setoption(ast,AST_OPTION_AUDIO_MODE,&x,sizeof(char),0);
 		p->didtdd = 0;
 		p->cidspill = NULL;
 		p->callwaitcas = 0;
@@ -1743,7 +1745,7 @@ int	x;
 	struct zt_pvt *p = chan->pvt->pvt;
 
 	
-	if ((option != AST_OPTION_TONE_VERIFY) &&
+	if ((option != AST_OPTION_TONE_VERIFY) && (option != AST_OPTION_AUDIO_MODE) &&
 		(option != AST_OPTION_TDD) && (option != AST_OPTION_RELAXDTMF))
 	   {
 		errno = ENOSYS;
@@ -1857,6 +1859,20 @@ int	x;
 		}
 		ast_dsp_digitmode(p->dsp,x ? DSP_DIGITMODE_RELAXDTMF : DSP_DIGITMODE_DTMF | p->dtmfrelax);
 		break;
+	    case AST_OPTION_AUDIO_MODE:  /* Set AUDIO mode (or not) */
+		if (!*cp)
+		{		
+			ast_log(LOG_DEBUG, "Set option AUDIO MODE, value: OFF(0) on %s\n",chan->name);
+			x = 0;
+		}
+		else
+		{		
+			ast_log(LOG_DEBUG, "Set option AUDIO MODE, value: ON(1) on %s\n",chan->name);
+			x = 1;
+		}
+		if (ioctl(p->subs[SUB_REAL].zfd, ZT_AUDIOMODE, &x) == -1)
+			ast_log(LOG_WARNING, "Unable to set audio mode on channel %d\n", p->channel);
+		break;
 	}
 	errno = 0;
 	return 0;
diff --git a/include/asterisk/frame.h b/include/asterisk/frame.h
index e971a6d034..2dbcccf086 100755
--- a/include/asterisk/frame.h
+++ b/include/asterisk/frame.h
@@ -188,6 +188,9 @@ struct ast_frame_chain {
 /* Relax the parameters for DTMF reception (mainly for radio use) */
 #define	AST_OPTION_RELAXDTMF		3
 
+/* Set (or clear) Audio (Not-Clear) Mode */
+#define	AST_OPTION_AUDIO_MODE		4
+
 struct ast_option_header {
 	/* Always keep in network byte order */
 #if __BYTE_ORDER == __BIG_ENDIAN
-- 
GitLab