Review Board 1.7.16


Improved support for T38 on initial INVITE

Review Request #208 - Created March 25, 2009 and submitted

Joshua Colp
/branches/1.4
Reviewers
asterisk-dev
Asterisk
This change improves our handling of T38 when we get it on an initial INVITE.

Previously we would try to setup a T38 only session end to end (between both endpoints) if the incoming call offered T38 (even if it also offered audio).

This change makes chan_sip respond appropriately to the incoming INVITE. If we get an offer with both T38 and audio, we setup both a T38 and audio session.
We do not, however, setup a T38 and audio session on a subsequent outgoing channel. We setup an audio only session. If the incoming channel sends us UDPTL
though we immediately trigger a reinvite on the outgoing channel to T38.

This seems to be the best compromise I can come to.
A few users have tested this change in their environments to confirm it works. I have also confirmed that the new behavior is present when T38 is present in the initial INVITE with my T38 test setup here.

Diff revision 1 (Latest)

  1. /branches/1.4/channels/chan_sip.c: Loading...
/branches/1.4/channels/chan_sip.c
Revision 184187 New Change
[20] 844 lines
[+20] [+] static int global_t38_capability = T38FAX_VERSION_0 | T38FAX_RATE_2400 | T38FAX_RATE_4800 | T38FAX_RATE_7200 | T38FAX_RATE_9600;
845
#define sipdebug_console	ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE)
845
#define sipdebug_console	ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE)
846

    
   
846

   
847
/*! \brief T38 States for a call */
847
/*! \brief T38 States for a call */
848
enum t38state {
848
enum t38state {
849
        T38_DISABLED = 0,                /*!< Not enabled */
849
        T38_DISABLED = 0,                /*!< Not enabled */
850
        T38_LOCAL_DIRECT,                /*!< Offered from local */

   
851
        T38_LOCAL_REINVITE,              /*!< Offered from local - REINVITE */
850
        T38_LOCAL_REINVITE,              /*!< Offered from local - REINVITE */
852
        T38_PEER_DIRECT,                 /*!< Offered from peer */
851
        T38_PEER_DIRECT,                 /*!< Offered from peer */
853
        T38_PEER_REINVITE,               /*!< Offered from peer - REINVITE */
852
        T38_PEER_REINVITE,               /*!< Offered from peer - REINVITE */
854
        T38_ENABLED                      /*!< Negotiated (enabled) */
853
        T38_ENABLED                      /*!< Negotiated (enabled) */
855
};
854
};
[+20] [20] 467 lines
[+20] [+] static int process_sdp(struct sip_pvt *p, struct sip_request *req);
1323
			     char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
1322
			     char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
1324
			     int debug, int *min_packet_size);
1323
			     int debug, int *min_packet_size);
1325
static void add_noncodec_to_sdp(const struct sip_pvt *p, int format, int sample_rate,
1324
static void add_noncodec_to_sdp(const struct sip_pvt *p, int format, int sample_rate,
1326
				char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
1325
				char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
1327
				int debug);
1326
				int debug);
1328
static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p);
1327
static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int add_audio, int add_t38);
1329
static void stop_media_flows(struct sip_pvt *p);
1328
static void stop_media_flows(struct sip_pvt *p);
1330

    
   
1329

   
1331
/*--- Authentication stuff */
1330
/*--- Authentication stuff */
1332
static int reply_digest(struct sip_pvt *p, struct sip_request *req, char *header, int sipmethod, char *digest, int digest_len);
1331
static int reply_digest(struct sip_pvt *p, struct sip_request *req, char *header, int sipmethod, char *digest, int digest_len);
1333
static int build_reply_digest(struct sip_pvt *p, int method, char *digest, int digest_len);
1332
static int build_reply_digest(struct sip_pvt *p, int method, char *digest, int digest_len);
[+20] [20] 1715 lines
[+20] [+] static int sip_call(struct ast_channel *ast, char *dest, int timeout)
3049
			/* This is the referer */
3048
			/* This is the referer */
3050
			referer = ast_var_value(current);
3049
			referer = ast_var_value(current);
3051
		} else if (!strcasecmp(ast_var_name(current), "SIPTRANSFER_REPLACES")) {
3050
		} else if (!strcasecmp(ast_var_name(current), "SIPTRANSFER_REPLACES")) {
3052
			/* We're replacing a call. */
3051
			/* We're replacing a call. */
3053
			p->options->replaces = ast_var_value(current);
3052
			p->options->replaces = ast_var_value(current);
3054
		} else if (!strcasecmp(ast_var_name(current), "T38CALL")) {

   
3055
			p->t38.state = T38_LOCAL_DIRECT;

   
3056
			if (option_debug)

   
3057
				ast_log(LOG_DEBUG,"T38State change to %d on channel %s\n", p->t38.state, ast->name);

   
3058
		}
3053
		}
3059

    
   

   
3060
	}
3054
	}
3061
	
3055
	
3062
	res = 0;
3056
	res = 0;
3063
	ast_set_flag(&p->flags[0], SIP_OUTGOING);
3057
	ast_set_flag(&p->flags[0], SIP_OUTGOING);
3064

    
   
3058

   
[+20] [20] 687 lines
[+20] [+] static int sip_answer(struct ast_channel *ast)
3752
		try_suggested_sip_codec(p);	
3746
		try_suggested_sip_codec(p);	
3753

    
   
3747

   
3754
		ast_setstate(ast, AST_STATE_UP);
3748
		ast_setstate(ast, AST_STATE_UP);
3755
		if (option_debug)
3749
		if (option_debug)
3756
			ast_log(LOG_DEBUG, "SIP answering channel: %s\n", ast->name);
3750
			ast_log(LOG_DEBUG, "SIP answering channel: %s\n", ast->name);
3757
		if (p->t38.state == T38_PEER_DIRECT) {
3751

   
3758
			p->t38.state = T38_ENABLED;

   
3759
			if (option_debug > 1)

   
3760
				ast_log(LOG_DEBUG,"T38State change to %d on channel %s\n", p->t38.state, ast->name);

   
3761
			res = transmit_response_with_t38_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL);

   
3762
			ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);

   
3763
		} else {

   
3764
			res = transmit_response_with_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL);
3752
		res = transmit_response_with_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL);
3765
			ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
3753
		ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
3766
		}
3754
	}
3767
	}

   
3768
	ast_mutex_unlock(&p->lock);
3755
	ast_mutex_unlock(&p->lock);
3769
	return res;
3756
	return res;
3770
}
3757
}
3771

    
   
3758

   
3772
/*! \brief Send frame to media channel (rtp) */
3759
/*! \brief Send frame to media channel (rtp) */
[+20] [20] 25 lines
[+20] [+] static int sip_write(struct ast_channel *ast, struct ast_frame *frame)
3798
				    !ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
3785
				    !ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
3799
					ast_rtp_new_source(p->rtp);
3786
					ast_rtp_new_source(p->rtp);
3800
					p->invitestate = INV_EARLY_MEDIA;
3787
					p->invitestate = INV_EARLY_MEDIA;
3801
					transmit_response_with_sdp(p, "183 Session Progress", &p->initreq, XMIT_UNRELIABLE);
3788
					transmit_response_with_sdp(p, "183 Session Progress", &p->initreq, XMIT_UNRELIABLE);
3802
					ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT);
3789
					ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT);
3803
				}
3790
				} else if (p->t38.state == T38_ENABLED) {

    
   
3791
					p->t38.state = T38_DISABLED;

    
   
3792
					transmit_reinvite_with_sdp(p);

    
   
3793
				} else {
3804
				p->lastrtptx = time(NULL);
3794
					p->lastrtptx = time(NULL);
3805
				res = ast_rtp_write(p->rtp, frame);
3795
					res = ast_rtp_write(p->rtp, frame);
3806
			}
3796
				}

    
   
3797
			}
3807
			ast_mutex_unlock(&p->lock);
3798
			ast_mutex_unlock(&p->lock);
3808
		}
3799
		}
3809
		break;
3800
		break;
3810
	case AST_FRAME_VIDEO:
3801
	case AST_FRAME_VIDEO:
3811
		if (p) {
3802
		if (p) {
[+20] [20] 21 lines
[+20] static int sip_write(struct ast_channel *ast, struct ast_frame *frame)
3833
			ast_mutex_lock(&p->lock);
3824
			ast_mutex_lock(&p->lock);
3834
			/* UDPTL requires two-way communication, so early media is not needed here.
3825
			/* UDPTL requires two-way communication, so early media is not needed here.
3835
				we simply forget the frames if we get modem frames before the bridge is up.
3826
				we simply forget the frames if we get modem frames before the bridge is up.
3836
				Fax will re-transmit.
3827
				Fax will re-transmit.
3837
			*/
3828
			*/
3838
			if (p->udptl && ast->_state == AST_STATE_UP) 
3829
			if (ast->_state == AST_STATE_UP) {

    
   
3830
				if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) && p->t38.state == T38_DISABLED) {

    
   
3831
					if (!p->pendinginvite) {

    
   
3832
						p->t38.state = T38_LOCAL_REINVITE;

    
   
3833
						transmit_reinvite_with_t38_sdp(p);

    
   
3834
					}

    
   
3835
				} else if (p->t38.state == T38_ENABLED) {
3839
				res = ast_udptl_write(p->udptl, frame);
3836
					res = ast_udptl_write(p->udptl, frame);

    
   
3837
				}

    
   
3838
			}
3840
			ast_mutex_unlock(&p->lock);
3839
			ast_mutex_unlock(&p->lock);
3841
		}
3840
		}
3842
		break;
3841
		break;
3843
	default: 
3842
	default: 
3844
		ast_log(LOG_WARNING, "Can't send %d type frames with SIP write\n", frame->frametype);
3843
		ast_log(LOG_WARNING, "Can't send %d type frames with SIP write\n", frame->frametype);
[+20] [20] 369 lines
[+20] [+] static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *title)
4214
	if (!ast_strlen_zero(i->callid))
4213
	if (!ast_strlen_zero(i->callid))
4215
		pbx_builtin_setvar_helper(tmp, "SIPCALLID", i->callid);
4214
		pbx_builtin_setvar_helper(tmp, "SIPCALLID", i->callid);
4216
	if (i->rtp)
4215
	if (i->rtp)
4217
		ast_jb_configure(tmp, &global_jbconf);
4216
		ast_jb_configure(tmp, &global_jbconf);
4218

    
   
4217

   
4219
	/* If the INVITE contains T.38 SDP information set the proper channel variable so a created outgoing call will also have T.38 */

   
4220
	if (i->udptl && i->t38.state == T38_PEER_DIRECT)

   
4221
		pbx_builtin_setvar_helper(tmp, "_T38CALL", "1");

   
4222

    
   

   
4223
	/* Set channel variables for this call from configuration */
4218
	/* Set channel variables for this call from configuration */
4224
	for (v = i->chanvars ; v ; v = v->next)
4219
	for (v = i->chanvars ; v ; v = v->next)
4225
		pbx_builtin_setvar_helper(tmp, v->name, v->value);
4220
		pbx_builtin_setvar_helper(tmp, v->name, v->value);
4226

    
   
4221

   
4227
	if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {
4222
	if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {
[+20] [20] 2274 lines
[+20] [+] static int t38_get_rate(int t38cap)
6502
			ast_log(LOG_DEBUG, "Strange, T38MaxBitRate NOT found in peers T38 SDP.\n");
6497
			ast_log(LOG_DEBUG, "Strange, T38MaxBitRate NOT found in peers T38 SDP.\n");
6503
		return 0;
6498
		return 0;
6504
	}
6499
	}
6505
}
6500
}
6506

    
   
6501

   
6507
/*! \brief Add T.38 Session Description Protocol message */

   
6508
static int add_t38_sdp(struct sip_request *resp, struct sip_pvt *p)

   
6509
{

   
6510
	int len = 0;

   
6511
	int x = 0;

   
6512
	struct sockaddr_in udptlsin;

   
6513
	char v[256] = "";

   
6514
	char s[256] = "";

   
6515
	char o[256] = "";

   
6516
	char c[256] = "";

   
6517
	char t[256] = "";

   
6518
	char m_modem[256];

   
6519
	char a_modem[1024];

   
6520
	char *m_modem_next = m_modem;

   
6521
	size_t m_modem_left = sizeof(m_modem);

   
6522
	char *a_modem_next = a_modem;

   
6523
	size_t a_modem_left = sizeof(a_modem);

   
6524
	struct sockaddr_in udptldest = { 0, };

   
6525
	int debug;

   
6526
	

   
6527
	debug = sip_debug_test_pvt(p);

   
6528
	len = 0;

   
6529
	if (!p->udptl) {

   
6530
		ast_log(LOG_WARNING, "No way to add SDP without an UDPTL structure\n");

   
6531
		return -1;

   
6532
	}

   
6533
	

   
6534
	if (!p->sessionid) {

   
6535
		p->sessionid = getpid();

   
6536
		p->sessionversion = p->sessionid;

   
6537
	} else

   
6538
		p->sessionversion++;

   
6539
	

   
6540
	/* Our T.38 end is */

   
6541
	ast_udptl_get_us(p->udptl, &udptlsin);

   
6542
	

   
6543
	/* Determine T.38 UDPTL destination */

   
6544
	if (p->udptlredirip.sin_addr.s_addr) {

   
6545
		udptldest.sin_port = p->udptlredirip.sin_port;

   
6546
		udptldest.sin_addr = p->udptlredirip.sin_addr;

   
6547
	} else {

   
6548
		udptldest.sin_addr = p->ourip;

   
6549
		udptldest.sin_port = udptlsin.sin_port;

   
6550
	}

   
6551
	

   
6552
	if (debug) 

   
6553
		ast_log(LOG_DEBUG, "T.38 UDPTL is at %s port %d\n", ast_inet_ntoa(p->ourip), ntohs(udptlsin.sin_port));

   
6554
	

   
6555
	/* We break with the "recommendation" and send our IP, in order that our

   
6556
	   peer doesn't have to ast_gethostbyname() us */

   
6557
	

   
6558
	if (debug) {

   
6559
		ast_log(LOG_DEBUG, "Our T38 capability (%d), peer T38 capability (%d), joint capability (%d)\n",

   
6560
			p->t38.capability,

   
6561
			p->t38.peercapability,

   
6562
			p->t38.jointcapability);

   
6563
	}

   
6564
	snprintf(v, sizeof(v), "v=0\r\n");

   
6565
	snprintf(o, sizeof(o), "o=root %d %d IN IP4 %s\r\n", p->sessionid, p->sessionversion, ast_inet_ntoa(udptldest.sin_addr));

   
6566
	snprintf(s, sizeof(s), "s=session\r\n");

   
6567
	snprintf(c, sizeof(c), "c=IN IP4 %s\r\n", ast_inet_ntoa(udptldest.sin_addr));

   
6568
	snprintf(t, sizeof(t), "t=0 0\r\n");

   
6569
	ast_build_string(&m_modem_next, &m_modem_left, "m=image %d udptl t38\r\n", ntohs(udptldest.sin_port));

   
6570
	

   
6571
	if ((p->t38.jointcapability & T38FAX_VERSION) == T38FAX_VERSION_0)

   
6572
		ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxVersion:0\r\n");

   
6573
	if ((p->t38.jointcapability & T38FAX_VERSION) == T38FAX_VERSION_1)

   
6574
		ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxVersion:1\r\n");

   
6575
	if ((x = t38_get_rate(p->t38.jointcapability)))

   
6576
		ast_build_string(&a_modem_next, &a_modem_left, "a=T38MaxBitRate:%d\r\n",x);

   
6577
	if ((p->t38.jointcapability & T38FAX_FILL_BIT_REMOVAL) == T38FAX_FILL_BIT_REMOVAL)

   
6578
		ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxFillBitRemoval\r\n");

   
6579
	if ((p->t38.jointcapability & T38FAX_TRANSCODING_MMR) == T38FAX_TRANSCODING_MMR)

   
6580
		ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxTranscodingMMR\r\n");

   
6581
	if ((p->t38.jointcapability & T38FAX_TRANSCODING_JBIG) == T38FAX_TRANSCODING_JBIG)

   
6582
		ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxTranscodingJBIG\r\n");

   
6583
	ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxRateManagement:%s\r\n", (p->t38.jointcapability & T38FAX_RATE_MANAGEMENT_LOCAL_TCF) ? "localTCF" : "transferredTCF");

   
6584
	x = ast_udptl_get_local_max_datagram(p->udptl);

   
6585
	ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxMaxBuffer:%d\r\n",x);

   
6586
	ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxMaxDatagram:%d\r\n",x);

   
6587
	if (p->t38.jointcapability != T38FAX_UDP_EC_NONE)

   
6588
		ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxUdpEC:%s\r\n", (p->t38.jointcapability & T38FAX_UDP_EC_REDUNDANCY) ? "t38UDPRedundancy" : "t38UDPFEC");

   
6589
	len = strlen(v) + strlen(s) + strlen(o) + strlen(c) + strlen(t) + strlen(m_modem) + strlen(a_modem);

   
6590
	add_header(resp, "Content-Type", "application/sdp");

   
6591
	add_header_contentLength(resp, len);

   
6592
	add_line(resp, v);

   
6593
	add_line(resp, o);

   
6594
	add_line(resp, s);

   
6595
	add_line(resp, c);

   
6596
	add_line(resp, t);

   
6597
	add_line(resp, m_modem);

   
6598
	add_line(resp, a_modem);

   
6599
	

   
6600
	/* Update lastrtprx when we send our SDP */

   
6601
	p->lastrtprx = p->lastrtptx = time(NULL);

   
6602
	

   
6603
	return 0;

   
6604
}

   
6605

    
   

   
6606

    
   

   
6607
/*! \brief Add RFC 2833 DTMF offer to SDP */
6502
/*! \brief Add RFC 2833 DTMF offer to SDP */
6608
static void add_noncodec_to_sdp(const struct sip_pvt *p, int format, int sample_rate,
6503
static void add_noncodec_to_sdp(const struct sip_pvt *p, int format, int sample_rate,
6609
				char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
6504
				char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
6610
				int debug)
6505
				int debug)
6611
{
6506
{
[+20] [20] 19 lines
[+20] static void add_noncodec_to_sdp(const struct sip_pvt *p, int format, int sample_rate,
6631
 * the future.
6526
 * the future.
6632
 */
6527
 */
6633
#define SDP_SAMPLE_RATE(x) 8000
6528
#define SDP_SAMPLE_RATE(x) 8000
6634

    
   
6529

   
6635
/*! \brief Add Session Description Protocol message */
6530
/*! \brief Add Session Description Protocol message */
6636
static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p)
6531
static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int add_audio, int add_t38)
6637
{
6532
{
6638
	int len = 0;
6533
	int len = 0;
6639
	int alreadysent = 0;
6534
	int alreadysent = 0;
6640

    
   
6535

   
6641
	struct sockaddr_in sin;
6536
	struct sockaddr_in sin;
[+20] [20] 9 lines
[+20] static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p) static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int add_audio, int add_t38)
6651
	char *stime = "t=0 0\r\n"; 			/* Time the session is active */
6546
	char *stime = "t=0 0\r\n"; 			/* Time the session is active */
6652
	char bandwidth[256] = "";			/* Max bitrate */
6547
	char bandwidth[256] = "";			/* Max bitrate */
6653
	char *hold;
6548
	char *hold;
6654
	char m_audio[256];				/* Media declaration line for audio */
6549
	char m_audio[256];				/* Media declaration line for audio */
6655
	char m_video[256];				/* Media declaration line for video */
6550
	char m_video[256];				/* Media declaration line for video */

    
   
6551
	char m_modem[256];                              /* Media declaration line for t38 */
6656
	char a_audio[1024];				/* Attributes for audio */
6552
	char a_audio[1024];				/* Attributes for audio */
6657
	char a_video[1024];				/* Attributes for video */
6553
	char a_video[1024];				/* Attributes for video */

    
   
6554
	char a_modem[1024];                             /* Attributes for t38 */
6658
	char *m_audio_next = m_audio;
6555
	char *m_audio_next = m_audio;
6659
	char *m_video_next = m_video;
6556
	char *m_video_next = m_video;

    
   
6557
	char *m_modem_next = m_modem;
6660
	size_t m_audio_left = sizeof(m_audio);
6558
	size_t m_audio_left = sizeof(m_audio);
6661
	size_t m_video_left = sizeof(m_video);
6559
	size_t m_video_left = sizeof(m_video);

    
   
6560
	size_t m_modem_left = sizeof(m_modem);
6662
	char *a_audio_next = a_audio;
6561
	char *a_audio_next = a_audio;
6663
	char *a_video_next = a_video;
6562
	char *a_video_next = a_video;

    
   
6563
	char *a_modem_next = a_modem;
6664
	size_t a_audio_left = sizeof(a_audio);
6564
	size_t a_audio_left = sizeof(a_audio);
6665
	size_t a_video_left = sizeof(a_video);
6565
	size_t a_video_left = sizeof(a_video);

    
   
6566
	size_t a_modem_left = sizeof(a_modem);
6666

    
   
6567

   
6667
	int x;
6568
	int x;
6668
	int capability;
6569
	int capability = 0;
6669
	int needvideo = FALSE;
6570
	int needvideo = FALSE;
6670
	int debug = sip_debug_test_pvt(p);
6571
	int debug = sip_debug_test_pvt(p);
6671
	int min_audio_packet_size = 0;
6572
	int min_audio_packet_size = 0;
6672
	int min_video_packet_size = 0;
6573
	int min_video_packet_size = 0;
6673

    
   
6574

   
6674
	m_video[0] = '\0';	/* Reset the video media string if it's not needed */
6575
	m_video[0] = '\0';	/* Reset the video media string if it's not needed */
6675

    
   
6576
	m_modem[0] = '\0';

    
   
6577
	
6676
	if (!p->rtp) {
6578
	if (!p->rtp) {
6677
		ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n");
6579
		ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n");
6678
		return AST_FAILURE;
6580
		return AST_FAILURE;
6679
	}
6581
	}
6680

    
   
6582

   
[+20] [20] 16 lines
[+20] static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p) static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int add_audio, int add_t38)
6697
	} else {
6599
	} else {
6698
		dest.sin_addr = p->ourip;
6600
		dest.sin_addr = p->ourip;
6699
		dest.sin_port = sin.sin_port;
6601
		dest.sin_port = sin.sin_port;
6700
	}
6602
	}
6701

    
   
6603

   
Moved from 6757

    
   
6604
        snprintf(owner, sizeof(owner), "o=root %d %d IN IP4 %s\r\n", p->sessionid, p->sessionversion, ast_inet_ntoa(dest.sin_addr));
Moved from 6758

    
   
6605
	snprintf(connection, sizeof(connection), "c=IN IP4 %s\r\n", ast_inet_ntoa(dest.sin_addr));

    
   
6606

   
Moved from 6761

    
   
6607
	if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_ONEDIR)
Moved from 6762

    
   
6608
		hold = "a=recvonly\r\n";
Moved from 6763

    
   
6609
	else if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_INACTIVE)
Moved from 6764

    
   
6610
		hold = "a=inactive\r\n";
Moved from 6765

    
   
6611
	else
Moved from 6766

    
   
6612
		hold = "a=sendrecv\r\n";

    
   
6613

   

    
   
6614
	if (add_audio) {
6702
	capability = p->jointcapability;
6615
		capability = p->jointcapability;
6703

    
   
6616

   
6704

    
   
6617

   
6705
	if (option_debug > 1) {
6618
		if (option_debug > 1) {
6706
		char codecbuf[SIPBUFSIZE];
6619
			char codecbuf[SIPBUFSIZE];
6707
		ast_log(LOG_DEBUG, "** Our capability: %s Video flag: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), capability), ast_test_flag(&p->flags[0], SIP_NOVIDEO) ? "True" : "False");
6620
			ast_log(LOG_DEBUG, "** Our capability: %s Video flag: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), capability), ast_test_flag(&p->flags[0], SIP_NOVIDEO) ? "True" : "False");
6708
		ast_log(LOG_DEBUG, "** Our prefcodec: %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), p->prefcodec));
6621
			ast_log(LOG_DEBUG, "** Our prefcodec: %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), p->prefcodec));
6709
	}
6622
		}
6710
	
6623

   
6711
#ifdef WHEN_WE_HAVE_T38_FOR_OTHER_TRANSPORTS
6624
#ifdef WHEN_WE_HAVE_T38_FOR_OTHER_TRANSPORTS
6712
	if (ast_test_flag(&p->t38.t38support, SIP_PAGE2_T38SUPPORT_RTP)) {
6625
		if (ast_test_flag(&p->t38.t38support, SIP_PAGE2_T38SUPPORT_RTP)) {
6713
		ast_build_string(&m_audio_next, &m_audio_left, " %d", 191);
6626
			ast_build_string(&m_audio_next, &m_audio_left, " %d", 191);
6714
		ast_build_string(&a_audio_next, &a_audio_left, "a=rtpmap:%d %s/%d\r\n", 191, "t38", 8000);
6627
			ast_build_string(&a_audio_next, &a_audio_left, "a=rtpmap:%d %s/%d\r\n", 191, "t38", 8000);
6715
	}
6628
		}
[+20] [20] 6 lines
[+20] static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p) static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int add_audio, int add_t38)
6722
			if (option_debug > 1)
6635
				if (option_debug > 1)
6723
				ast_log(LOG_DEBUG, "This call needs video offers!\n");
6636
					ast_log(LOG_DEBUG, "This call needs video offers!\n");
6724
		} else if (option_debug > 1)
6637
			} else if (option_debug > 1)
6725
			ast_log(LOG_DEBUG, "This call needs video offers, but there's no video support enabled!\n");
6638
				ast_log(LOG_DEBUG, "This call needs video offers, but there's no video support enabled!\n");
6726
	}
6639
		}
6727
		

   
6728

    
   
6640

   

    
   
6641

   
6729
	/* Ok, we need video. Let's add what we need for video and set codecs.
6642
		/* Ok, we need video. Let's add what we need for video and set codecs.
6730
	   Video is handled differently than audio since we can not transcode. */
6643
		   Video is handled differently than audio since we can not transcode. */
6731
	if (needvideo) {
6644
		if (needvideo) {
6732
		/* Determine video destination */
6645
			/* Determine video destination */
6733
		if (p->vredirip.sin_addr.s_addr) {
6646
			if (p->vredirip.sin_addr.s_addr) {
[+20] [20] 13 lines
[+20] static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p) static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int add_audio, int add_t38)
6747
	}
6660
		}
6748

    
   
6661

   
6749
	if (debug) 
6662
		if (debug) 
6750
		ast_verbose("Audio is at %s port %d\n", ast_inet_ntoa(p->ourip), ntohs(sin.sin_port));	
6663
			ast_verbose("Audio is at %s port %d\n", ast_inet_ntoa(p->ourip), ntohs(sin.sin_port));	
6751

    
   
6664

   
6752
	/* Start building generic SDP headers */

   
6753

    
   

   
6754
	/* We break with the "recommendation" and send our IP, in order that our

   
6755
	   peer doesn't have to ast_gethostbyname() us */

   
6756

    
   

   
6757
	snprintf(owner, sizeof(owner), "o=root %d %d IN IP4 %s\r\n", p->sessionid, p->sessionversion, ast_inet_ntoa(dest.sin_addr));
Moved to 6604

   
6758
	snprintf(connection, sizeof(connection), "c=IN IP4 %s\r\n", ast_inet_ntoa(dest.sin_addr));
Moved to 6605

   
6759
	ast_build_string(&m_audio_next, &m_audio_left, "m=audio %d RTP/AVP", ntohs(dest.sin_port));
6665
		ast_build_string(&m_audio_next, &m_audio_left, "m=audio %d RTP/AVP", ntohs(dest.sin_port));
6760

    
   
6666

   
6761
	if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_ONEDIR)
Moved to 6607

   
6762
		hold = "a=recvonly\r\n";
Moved to 6608

   
6763
	else if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_INACTIVE)
Moved to 6609

   
6764
		hold = "a=inactive\r\n";
Moved to 6610

   
6765
	else
Moved to 6611

   
6766
		hold = "a=sendrecv\r\n";
Moved to 6612

   
6767

    
   

   
6768
	/* Now, start adding audio codecs. These are added in this order:
6667
		/* Now, start adding audio codecs. These are added in this order:
6769
		- First what was requested by the calling channel
6668
		   - First what was requested by the calling channel
6770
		- Then preferences in order from sip.conf device config for this peer/user
6669
		   - Then preferences in order from sip.conf device config for this peer/user
6771
		- Then other codecs in capabilities, including video
6670
		   - Then other codecs in capabilities, including video
6772
	*/
6671
		*/
[+20] [20] 78 lines
[+20] static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p) static enum sip_result add_sdp(struct sip_request *resp, struct sip_pvt *p, int add_audio, int add_t38)
6851
		ast_log(LOG_WARNING, "SIP SDP may be truncated due to undersized buffer!!\n");
6750
			ast_log(LOG_WARNING, "SIP SDP may be truncated due to undersized buffer!!\n");
6852

    
   
6751

   
6853
	ast_build_string(&m_audio_next, &m_audio_left, "\r\n");
6752
		ast_build_string(&m_audio_next, &m_audio_left, "\r\n");
6854
	if (needvideo)
6753
		if (needvideo)
6855
		ast_build_string(&m_video_next, &m_video_left, "\r\n");
6754
			ast_build_string(&m_video_next, &m_video_left, "\r\n");

    
   
6755
	}

    
   
6756

   

    
   
6757
	if (add_t38 && p->udptl) {

    
   
6758
		struct sockaddr_in udptlsin;

    
   
6759
		struct sockaddr_in udptldest = { 0, };

    
   
6760

   

    
   
6761
		ast_udptl_get_us(p->udptl, &udptlsin);
6856

    
   
6762

   
6857
	len = strlen(version) + strlen(subject) + strlen(owner) + strlen(connection) + strlen(stime) + strlen(m_audio) + strlen(a_audio) + strlen(hold);
6763
		if (p->udptlredirip.sin_addr.s_addr) {
Moved from 6545

    
   
6764
			udptldest.sin_port = p->udptlredirip.sin_port;
Moved from 6546

    
   
6765
			udptldest.sin_addr = p->udptlredirip.sin_addr;
Moved from 6547

    
   
6766
		} else {
Moved from 6548

    
   
6767
			udptldest.sin_addr = p->ourip;
Moved from 6549

    
   
6768
			udptldest.sin_port = udptlsin.sin_port;
Moved from 6550

    
   
6769
		}

    
   
6770

   
Moved from 6558

    
   
6771
		if (debug) {
Moved from 6559

    
   
6772
			ast_log(LOG_DEBUG, "T.38 UDPTL is at %s port %d\n", ast_inet_ntoa(p->ourip), ntohs(udptlsin.sin_port));
Moved from 6560

    
   
6773
			ast_log(LOG_DEBUG, "Our T38 capability (%d), peer T38 capability (%d), joint capability (%d)\n",
Moved from 6561

    
   
6774
				p->t38.capability,
Moved from 6562

    
   
6775
				p->t38.peercapability,
Moved from 6563

    
   
6776
				p->t38.jointcapability);

    
   
6777
		}

    
   
6778

   

    
   
6779
		ast_build_string(&m_modem_next, &m_modem_left, "m=image %d udptl t38\r\n", ntohs(udptldest.sin_port));

    
   
6780

   
Moved from 6571

    
   
6781
		if ((p->t38.jointcapability & T38FAX_VERSION) == T38FAX_VERSION_0)
Moved from 6572

    
   
6782
			ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxVersion:0\r\n");
Moved from 6573

    
   
6783
		if ((p->t38.jointcapability & T38FAX_VERSION) == T38FAX_VERSION_1)
Moved from 6574

    
   
6784
			ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxVersion:1\r\n");
Moved from 6575

    
   
6785
		if ((x = t38_get_rate(p->t38.jointcapability)))
Moved from 6576

    
   
6786
			ast_build_string(&a_modem_next, &a_modem_left, "a=T38MaxBitRate:%d\r\n",x);
Moved from 6577

    
   
6787
		if ((p->t38.jointcapability & T38FAX_FILL_BIT_REMOVAL) == T38FAX_FILL_BIT_REMOVAL)
Moved from 6578

    
   
6788
			ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxFillBitRemoval\r\n");
Moved from 6579

    
   
6789
		if ((p->t38.jointcapability & T38FAX_TRANSCODING_MMR) == T38FAX_TRANSCODING_MMR)
Moved from 6580

    
   
6790
			ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxTranscodingMMR\r\n");
Moved from 6581

    
   
6791
		if ((p->t38.jointcapability & T38FAX_TRANSCODING_JBIG) == T38FAX_TRANSCODING_JBIG)
Moved from 6582

    
   
6792
			ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxTranscodingJBIG\r\n");
Moved from 6583

    
   
6793
		ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxRateManagement:%s\r\n", (p->t38.jointcapability & T38FAX_RATE_MANAGEMENT_LOCAL_TCF) ? "localTCF" : "transferredTCF");
Moved from 6584

    
   
6794
		x = ast_udptl_get_local_max_datagram(p->udptl);
Moved from 6585

    
   
6795
		ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxMaxBuffer:%d\r\n",x);
Moved from 6586

    
   
6796
		ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxMaxDatagram:%d\r\n",x);
Moved from 6587

    
   
6797
		if (p->t38.jointcapability != T38FAX_UDP_EC_NONE)
Moved from 6588

    
   
6798
			ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxUdpEC:%s\r\n", (p->t38.jointcapability & T38FAX_UDP_EC_REDUNDANCY) ? "t38UDPRedundancy" : "t38UDPFEC");

    
   
6799
	}

    
   
6800

   

    
   
6801
	len = strlen(version) + strlen(subject) + strlen(owner) + strlen(connection) + strlen(stime);

    
   
6802
	if (add_audio)

    
   
6803
		len += strlen(m_audio) + strlen(a_audio) + strlen(hold);
6858
	if (needvideo) /* only if video response is appropriate */
6804
	if (needvideo) /* only if video response is appropriate */
6859
		len += strlen(m_video) + strlen(a_video) + strlen(bandwidth) + strlen(hold);
6805
		len += strlen(m_video) + strlen(a_video) + strlen(bandwidth) + strlen(hold);

    
   
6806
	if (add_t38) {

    
   
6807
		len += strlen(m_modem) + strlen(a_modem);

    
   
6808
	}
6860

    
   
6809

   
6861
	add_header(resp, "Content-Type", "application/sdp");
6810
	add_header(resp, "Content-Type", "application/sdp");
6862
	add_header_contentLength(resp, len);
6811
	add_header_contentLength(resp, len);
6863
	add_line(resp, version);
6812
	add_line(resp, version);
6864
	add_line(resp, owner);
6813
	add_line(resp, owner);
6865
	add_line(resp, subject);
6814
	add_line(resp, subject);
6866
	add_line(resp, connection);
6815
	add_line(resp, connection);
6867
	if (needvideo)	 	/* only if video response is appropriate */
6816
	if (needvideo)	 	/* only if video response is appropriate */
6868
		add_line(resp, bandwidth);
6817
		add_line(resp, bandwidth);
6869
	add_line(resp, stime);
6818
	add_line(resp, stime);

    
   
6819
	if (add_audio) {
6870
	add_line(resp, m_audio);
6820
		add_line(resp, m_audio);
6871
	add_line(resp, a_audio);
6821
		add_line(resp, a_audio);
6872
	add_line(resp, hold);
6822
		add_line(resp, hold);

    
   
6823
	}
6873
	if (needvideo) { /* only if video response is appropriate */
6824
	if (needvideo) { /* only if video response is appropriate */
6874
		add_line(resp, m_video);
6825
		add_line(resp, m_video);
6875
		add_line(resp, a_video);
6826
		add_line(resp, a_video);
6876
		add_line(resp, hold);	/* Repeat hold for the video stream */
6827
		add_line(resp, hold);	/* Repeat hold for the video stream */
6877
	}
6828
	}

    
   
6829
	if (add_t38) {
Moved from 6597

    
   
6830
		add_line(resp, m_modem);
Moved from 6598

    
   
6831
		add_line(resp, a_modem);

    
   
6832
	}
6878

    
   
6833

   
6879
	/* Update lastrtprx when we send our SDP */
6834
	/* Update lastrtprx when we send our SDP */
6880
	p->lastrtprx = p->lastrtptx = time(NULL); /* XXX why both ? */
6835
	p->lastrtprx = p->lastrtptx = time(NULL); /* XXX why both ? */
6881

    
   
6836

   
6882
	if (option_debug > 2) {
6837
	if (option_debug > 2) {
[+20] [20] 14 lines
[+20] [+] static int transmit_response_with_t38_sdp(struct sip_pvt *p, char *msg, struct sip_request *req, int retrans)
6897
		ast_log(LOG_WARNING, "Unable to get seqno from '%s'\n", get_header(req, "CSeq"));
6852
		ast_log(LOG_WARNING, "Unable to get seqno from '%s'\n", get_header(req, "CSeq"));
6898
		return -1;
6853
		return -1;
6899
	}
6854
	}
6900
	respprep(&resp, p, msg, req);
6855
	respprep(&resp, p, msg, req);
6901
	if (p->udptl) {
6856
	if (p->udptl) {
6902
		ast_udptl_offered_from_local(p->udptl, 0);
6857
		add_sdp(&resp, p, 0, 1);
6903
		add_t38_sdp(&resp, p);

   
6904
	} else 
6858
	} else 
6905
		ast_log(LOG_ERROR, "Can't add SDP to response, since we have no UDPTL session allocated. Call-ID %s\n", p->callid);
6859
		ast_log(LOG_ERROR, "Can't add SDP to response, since we have no UDPTL session allocated. Call-ID %s\n", p->callid);
6906
	if (retrans && !p->pendinginvite)
6860
	if (retrans && !p->pendinginvite)
6907
		p->pendinginvite = seqno;		/* Buggy clients sends ACK on RINGING too */
6861
		p->pendinginvite = seqno;		/* Buggy clients sends ACK on RINGING too */
6908
	return send_response(p, &resp, retrans, seqno);
6862
	return send_response(p, &resp, retrans, seqno);
[+20] [20] 32 lines
[+20] [+] static int transmit_response_with_sdp(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable)
6941
		if (!p->autoframing && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
6895
		if (!p->autoframing && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
6942
			if (option_debug)
6896
			if (option_debug)
6943
				ast_log(LOG_DEBUG, "Setting framing from config on incoming call\n");
6897
				ast_log(LOG_DEBUG, "Setting framing from config on incoming call\n");
6944
			ast_rtp_codec_setpref(p->rtp, &p->prefs);
6898
			ast_rtp_codec_setpref(p->rtp, &p->prefs);
6945
		}
6899
		}
6946
		try_suggested_sip_codec(p);	
6900
		try_suggested_sip_codec(p);
6947
		add_sdp(&resp, p);
6901
		if (p->t38.state == T38_PEER_DIRECT || p->t38.state == T38_ENABLED) {

    
   
6902
			p->t38.state = T38_ENABLED;

    
   
6903
			add_sdp(&resp, p, 1, 1);

    
   
6904
		} else {

    
   
6905
			add_sdp(&resp, p, 1, 0);

    
   
6906
		}
6948
	} else 
6907
	} else 
6949
		ast_log(LOG_ERROR, "Can't add SDP to response, since we have no RTP session allocated. Call-ID %s\n", p->callid);
6908
		ast_log(LOG_ERROR, "Can't add SDP to response, since we have no RTP session allocated. Call-ID %s\n", p->callid);
6950
	if (reliable && !p->pendinginvite)
6909
	if (reliable && !p->pendinginvite)
6951
		p->pendinginvite = seqno;		/* Buggy clients sends ACK on RINGING too */
6910
		p->pendinginvite = seqno;		/* Buggy clients sends ACK on RINGING too */
6952
	return send_response(p, &resp, reliable, seqno);
6911
	return send_response(p, &resp, reliable, seqno);
[+20] [20] 56 lines
[+20] [+] static int transmit_reinvite_with_sdp(struct sip_pvt *p)
7009
	add_header(&req, "Supported", SUPPORTED_EXTENSIONS);
6968
	add_header(&req, "Supported", SUPPORTED_EXTENSIONS);
7010
	if (sipdebug)
6969
	if (sipdebug)
7011
		add_header(&req, "X-asterisk-Info", "SIP re-invite (External RTP bridge)");
6970
		add_header(&req, "X-asterisk-Info", "SIP re-invite (External RTP bridge)");
7012
	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
6971
	if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY))
7013
		append_history(p, "ReInv", "Re-invite sent");
6972
		append_history(p, "ReInv", "Re-invite sent");
7014
	add_sdp(&req, p);
6973
	add_sdp(&req, p, 1, 0);
7015
	/* Use this as the basis */
6974
	/* Use this as the basis */
7016
	initialize_initreq(p, &req);
6975
	initialize_initreq(p, &req);
7017
	p->lastinvite = p->ocseq;
6976
	p->lastinvite = p->ocseq;
7018
	ast_set_flag(&p->flags[0], SIP_OUTGOING);		/* Change direction of this dialog */
6977
	ast_set_flag(&p->flags[0], SIP_OUTGOING);		/* Change direction of this dialog */
7019
	return send_request(p, &req, XMIT_CRITICAL, p->ocseq);
6978
	return send_request(p, &req, XMIT_CRITICAL, p->ocseq);
[+20] [20] 11 lines
[+20] [+] static int transmit_reinvite_with_t38_sdp(struct sip_pvt *p)
7031
	
6990
	
7032
	add_header(&req, "Allow", ALLOWED_METHODS);
6991
	add_header(&req, "Allow", ALLOWED_METHODS);
7033
	add_header(&req, "Supported", SUPPORTED_EXTENSIONS);
6992
	add_header(&req, "Supported", SUPPORTED_EXTENSIONS);
7034
	if (sipdebug)
6993
	if (sipdebug)
7035
		add_header(&req, "X-asterisk-info", "SIP re-invite (T38 switchover)");
6994
		add_header(&req, "X-asterisk-info", "SIP re-invite (T38 switchover)");
7036
	ast_udptl_offered_from_local(p->udptl, 1);
6995
	add_sdp(&req, p, 0, 1);
7037
	add_t38_sdp(&req, p);
6996

   
7038
	/* Use this as the basis */
6997
	/* Use this as the basis */
7039
	initialize_initreq(p, &req);
6998
	initialize_initreq(p, &req);
7040
	ast_set_flag(&p->flags[0], SIP_OUTGOING);		/* Change direction of this dialog */
6999
	ast_set_flag(&p->flags[0], SIP_OUTGOING);		/* Change direction of this dialog */
7041
	p->lastinvite = p->ocseq;
7000
	p->lastinvite = p->ocseq;
7042
	return send_request(p, &req, XMIT_CRITICAL, p->ocseq);
7001
	return send_request(p, &req, XMIT_CRITICAL, p->ocseq);
[+20] [20] 315 lines
[+20] [+] static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init)
7358
		}
7317
		}
7359

    
   
7318

   
7360
		ast_channel_unlock(chan);
7319
		ast_channel_unlock(chan);
7361
	}
7320
	}
7362
	if (sdp) {
7321
	if (sdp) {
7363
		if (p->udptl && (p->t38.state == T38_LOCAL_DIRECT || p->t38.state == T38_LOCAL_REINVITE)) {
7322
		if (p->udptl && p->t38.state == T38_LOCAL_REINVITE) {
7364
			ast_udptl_offered_from_local(p->udptl, 1);
7323
			ast_udptl_offered_from_local(p->udptl, 1);
7365
			if (option_debug)
7324
			if (option_debug)
7366
				ast_log(LOG_DEBUG, "T38 is in state %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>");
7325
				ast_log(LOG_DEBUG, "T38 is in state %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>");
7367
			add_t38_sdp(&req, p);
7326
			add_sdp(&req, p, 0, 1);
7368
		} else if (p->rtp) 
7327
		} else if (p->rtp) 
7369
			add_sdp(&req, p);
7328
			add_sdp(&req, p, 1, 0);
7370
	} else {
7329
	} else {
7371
		add_header_contentLength(&req, 0);
7330
		add_header_contentLength(&req, 0);
7372
	}
7331
	}
7373

    
   
7332

   
7374
	if (!p->initreq.headers || init > 2)
7333
	if (!p->initreq.headers || init > 2)
[+20] [20] 5154 lines
[+20] [+] static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno)
12529
				p->t38.state = T38_DISABLED;
12488
				p->t38.state = T38_DISABLED;
12530
				if (option_debug > 1)
12489
				if (option_debug > 1)
12531
					ast_log(LOG_DEBUG,"T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>");
12490
					ast_log(LOG_DEBUG,"T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>");
12532
			}
12491
			}
12533
		}
12492
		}
12534
		if ((p->t38.state == T38_LOCAL_REINVITE) || (p->t38.state == T38_LOCAL_DIRECT)) {
12493
		if (p->t38.state == T38_LOCAL_REINVITE) {
12535
			/* If there was T38 reinvite and we are supposed to answer with 200 OK than this should set us to T38 negotiated mode */
12494
			/* If there was T38 reinvite and we are supposed to answer with 200 OK than this should set us to T38 negotiated mode */
12536
			p->t38.state = T38_ENABLED;
12495
			p->t38.state = T38_ENABLED;
12537
			if (option_debug)
12496
			if (option_debug)
12538
				ast_log(LOG_DEBUG, "T38 changed state to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>");
12497
				ast_log(LOG_DEBUG, "T38 changed state to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>");
12539
		}
12498
		}
[+20] [20] 99 lines
[+20] static void handle_response_invite(struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno)
12639
			   sides here? 
12598
			   sides here? 
12640
			*/
12599
			*/
12641
			/* While figuring that out, hangup the call */
12600
			/* While figuring that out, hangup the call */
12642
			if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE))
12601
			if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE))
12643
				ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
12602
				ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
12644
			ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);	

   
12645
		} else if (p->udptl && p->t38.state == T38_LOCAL_DIRECT) {

   
12646
			/* We tried to send T.38 out in an initial INVITE and the remote side rejected it,

   
12647
			   right now we can't fall back to audio so totally abort.

   
12648
			*/

   
12649
			p->t38.state = T38_DISABLED;

   
12650
			/* Try to reset RTP timers */

   
12651
			ast_rtp_set_rtptimers_onhold(p->rtp);

   
12652
			ast_log(LOG_ERROR, "Got error on T.38 initial invite. Bailing out.\n");

   
12653

    
   

   
12654
			/* The dialog is now terminated */

   
12655
			if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE))

   
12656
				ast_queue_control(p->owner, AST_CONTROL_CONGESTION);

   
12657
			ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
12603
			ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
12658
			sip_alreadygone(p);

   
12659
		} else {
12604
		} else {
12660
			/* We can't set up this call, so give up */
12605
			/* We can't set up this call, so give up */
12661
			if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE))
12606
			if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE))
12662
				ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
12607
				ast_queue_control(p->owner, AST_CONTROL_CONGESTION);
12663
			ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
12608
			ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
[+20] [20] 2149 lines
[+20] [+] static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct sockaddr_in *sin, int *recount, char *e, int *nounlock)
14813
					p->t38.state = T38_ENABLED;
14758
					p->t38.state = T38_ENABLED;
14814
					if (option_debug)
14759
					if (option_debug)
14815
						ast_log(LOG_DEBUG,"T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>");
14760
						ast_log(LOG_DEBUG,"T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>");
14816
				}
14761
				}
14817
			} else if (p->t38.state == T38_DISABLED) { /* Channel doesn't have T38 offered or enabled */
14762
			} else if (p->t38.state == T38_DISABLED) { /* Channel doesn't have T38 offered or enabled */
14818
				int sendok = TRUE;

   
14819

    
   

   
14820
				/* If we are bridged to a channel that has T38 enabled than this is a case of RTP re-invite after T38 session */

   
14821
				/* so handle it here (re-invite other party to RTP) */

   
14822
				struct ast_channel *bridgepeer = NULL;

   
14823
				struct sip_pvt *bridgepvt = NULL;

   
14824
				if ((bridgepeer = ast_bridged_channel(p->owner))) {

   
14825
					if ((bridgepeer->tech == &sip_tech || bridgepeer->tech == &sip_tech_info) && !ast_check_hangup(bridgepeer)) {

   
14826
						bridgepvt = (struct sip_pvt*)bridgepeer->tech_pvt;

   
14827
						/* Does the bridged peer have T38 ? */

   
14828
						if (bridgepvt->t38.state == T38_ENABLED) {

   
14829
							ast_log(LOG_WARNING, "RTP re-invite after T38 session not handled yet !\n");

   
14830
							/* Insted of this we should somehow re-invite the other side of the bridge to RTP */

   
14831
							if (ast_test_flag(req, SIP_PKT_IGNORE))

   
14832
								transmit_response(p, "488 Not Acceptable Here (unsupported)", req);

   
14833
							else

   
14834
								transmit_response_reliable(p, "488 Not Acceptable Here (unsupported)", req);

   
14835
							sendok = FALSE;

   
14836
						} 

   
14837
						/* No bridged peer with T38 enabled*/

   
14838
					}

   
14839
				} 

   
14840
				/* Respond to normal re-invite */

   
14841
				if (sendok) {

   
14842
					/* If this is not a re-invite or something to ignore - it's critical */
14763
				/* If this is not a re-invite or something to ignore - it's critical */
14843
					ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
14764
				ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED);
14844
					transmit_response_with_sdp(p, "200 OK", req, (reinvite ? XMIT_RELIABLE : (ast_test_flag(req, SIP_PKT_IGNORE) ? XMIT_UNRELIABLE : XMIT_CRITICAL)));
14765
				transmit_response_with_sdp(p, "200 OK", req, (reinvite ? XMIT_RELIABLE : (ast_test_flag(req, SIP_PKT_IGNORE) ? XMIT_UNRELIABLE : XMIT_CRITICAL)));
14845
				}
14766
			}
14846
			}

   
14847
			p->invitestate = INV_TERMINATED;
14767
			p->invitestate = INV_TERMINATED;
14848
			break;
14768
			break;
14849
		default:
14769
		default:
14850
			ast_log(LOG_WARNING, "Don't know how to handle INVITE in state %d\n", c->_state);
14770
			ast_log(LOG_WARNING, "Don't know how to handle INVITE in state %d\n", c->_state);
14851
			transmit_response(p, "100 Trying", req);
14771
			transmit_response(p, "100 Trying", req);
[+20] [20] 4195 lines
  1. /branches/1.4/channels/chan_sip.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.