From 415f82fe93918167e2853d2a70b56bb3a9b749c4 Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthm@freeswitch.org>
Date: Thu, 6 Nov 2014 18:26:16 -0600
Subject: [PATCH] FS-6954 #resolve #comment please test

---
 src/mod/endpoints/mod_sofia/sofia.c      | 14 +++++++++++---
 src/mod/endpoints/mod_sofia/sofia_glue.c |  4 ++++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c
index b0107b200e..a482d107f0 100644
--- a/src/mod/endpoints/mod_sofia/sofia.c
+++ b/src/mod/endpoints/mod_sofia/sofia.c
@@ -6538,9 +6538,17 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
 		if (!tech_pvt || !tech_pvt->nh) {
 			goto done;
 		}
-	
-		if ((status > 100 || switch_channel_test_flag(channel, CF_ANSWERED)) && status < 300 && !r_sdp && tech_pvt->mparams.last_sdp_str) {
-			r_sdp = tech_pvt->mparams.last_sdp_str;
+
+		if (!r_sdp && (status > 100 || switch_channel_test_flag(channel, CF_ANSWERED)) && status < 300) {
+			if (ss_state == nua_callstate_ready) {
+				if (tech_pvt->mparams.last_sdp_response) {
+					r_sdp = tech_pvt->mparams.last_sdp_response;
+				}
+			} else {
+				if (tech_pvt->mparams.last_sdp_str) {
+					r_sdp = tech_pvt->mparams.last_sdp_str;
+				}
+			}
 		}
 		tech_pvt->mparams.last_sdp_str = NULL;
 	
diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c
index 17edf89353..49079f106d 100644
--- a/src/mod/endpoints/mod_sofia/sofia_glue.c
+++ b/src/mod/endpoints/mod_sofia/sofia_glue.c
@@ -1235,6 +1235,10 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
 
 	tech_pvt->sent_invites++;
 
+	if (switch_channel_get_private(tech_pvt->channel, "t38_options")) {
+		sofia_clear_flag(tech_pvt, TFLAG_ENABLE_SOA);
+	}
+
 	if (sofia_use_soa(tech_pvt)) {
 		nua_invite(tech_pvt->nh,
 				   NUTAG_AUTOANSWER(0),