From a30989d769f7212e2ff42c436032e4307530e09e Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthm@freeswitch.org>
Date: Thu, 2 May 2013 22:22:59 -0500
Subject: [PATCH] prevent t38_passthru and fax_detect from both happening at
 once

---
 src/mod/endpoints/mod_sofia/sofia_glue.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c
index 80683c90ee..3904488f04 100644
--- a/src/mod/endpoints/mod_sofia/sofia_glue.c
+++ b/src/mod/endpoints/mod_sofia/sofia_glue.c
@@ -4843,7 +4843,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
 				match = 1;
 				goto done;
 			}
-
+			
 			if (switch_true(switch_channel_get_variable(channel, "refuse_t38"))) {
 				switch_channel_clear_app_flag_key("T38", tech_pvt->channel, CF_APP_T38);
 				match = 0;
@@ -4881,6 +4881,18 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
 					switch_port_t remote_port = switch_rtp_get_remote_port(tech_pvt->rtp_session);
 					char tmp[32] = "";
 
+					if (!switch_channel_test_flag(other_channel, CF_ANSWERED)) {
+						switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), 
+										  SWITCH_LOG_WARNING, "%s Error Passing T.38 to unanswered channel %s\n", 
+										  switch_channel_get_name(tech_pvt->channel), switch_channel_get_name(other_channel));
+						switch_core_session_rwunlock(other_session);						
+						sofia_set_flag(tech_pvt, TFLAG_NOREPLY);
+						pass = 0;
+						match = 0;
+						goto done;
+					}
+
+
 					if (switch_true(switch_channel_get_variable(tech_pvt->channel, "t38_broken_boolean")) && 
 						switch_true(switch_channel_get_variable(tech_pvt->channel, "t38_pass_broken_boolean"))) {
 						switch_channel_set_variable(other_channel, "t38_broken_boolean", "true");