Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 94396) +++ channels/chan_sip.c (working copy) @@ -1512,6 +1512,14 @@ (head) = (element)->next; \ } while (0) + +/* t38action flags for the process_sdp */ + +/* Presense of T38 options means that remote side initiates T38 to us */ +#define SDP_T38_INITIATE 1 +/* Presense of T38 options means that remote side accepts our T38 proposal */ +#define SDP_T38_ACCEPT 2 + /*---------------------------- Forward declarations of functions in chan_sip.c */ /*! \note This is added to help splitting up chan_sip.c into several files in coming releases */ @@ -1598,7 +1606,7 @@ static const char* get_sdp_iterate(int* start, struct sip_request *req, const char *name); static const char *get_sdp(struct sip_request *req, const char *name); static int find_sdp(struct sip_request *req); -static int process_sdp(struct sip_pvt *p, struct sip_request *req); +static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action); static void add_codec_to_sdp(const struct sip_pvt *p, int codec, int sample_rate, struct ast_str **m_buf, struct ast_str **a_buf, int debug, int *min_packet_size); @@ -5628,7 +5636,7 @@ Return 0 on success, a negative value on errors. Must be called after find_sdp(). */ -static int process_sdp(struct sip_pvt *p, struct sip_request *req) +static int process_sdp(struct sip_pvt *p, struct sip_request *req, int t38action) { const char *m; /* SDP media offer */ const char *c; @@ -5797,14 +5805,6 @@ ast_verbose("Got T.38 offer in SDP in dialog %s\n", p->callid); udptlportno = x; numberofmediastreams++; - - if (p->owner && p->lastinvite) { - p->t38.state = T38_PEER_REINVITE; /* T38 Offered in re-invite from remote party */ - ast_debug(2, "T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "" ); - } else { - p->t38.state = T38_PEER_DIRECT; /* T38 Offered directly from peer in first invite */ - ast_debug(2, "T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : ""); - } } else ast_log(LOG_WARNING, "Unsupported SDP media type in offer: %s\n", m); if (numberofports > 1) @@ -6113,11 +6113,25 @@ p->t38.capability, p->t38.peercapability, p->t38.jointcapability); + + + /* Remote party offers T38, we need to update state */ + if (t38action & SDP_T38_ACCEPT) { + if (p->t38.state == T38_LOCAL_DIRECT || p->t38.state == T38_LOCAL_REINVITE) + p->t38.state = T38_ENABLED; + } else if (t38action & SDP_T38_INITIATE) { + if (p->owner && p->lastinvite) { + p->t38.state = T38_PEER_REINVITE; /* T38 Offered in re-invite from remote party */ + } else { + p->t38.state = T38_PEER_DIRECT; /* T38 Offered directly from peer in first invite */ + } + } } else { p->t38.state = T38_DISABLED; - ast_debug(3, "T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : ""); } + ast_debug(3, "T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : ""); + /* Now gather all of the codecs that we are asked for: */ ast_rtp_get_current_formats(newaudiortp, &peercapability, &peernoncodeccapability); ast_rtp_get_current_formats(newvideortp, &vpeercapability, &vpeernoncodeccapability); @@ -13510,7 +13524,7 @@ } if (find_sdp(req)) { p->invitestate = INV_EARLY_MEDIA; - res = process_sdp(p, req); + res = process_sdp(p, req, 0); if (!req->ignore && p->owner) { /* Queue a progress frame only if we have SDP in 180 or 182 */ ast_queue_control(p->owner, AST_CONTROL_PROGRESS); @@ -13525,7 +13539,7 @@ /* Ignore 183 Session progress without SDP */ if (find_sdp(req)) { p->invitestate = INV_EARLY_MEDIA; - res = process_sdp(p, req); + res = process_sdp(p, req, 0); if (!req->ignore && p->owner) { /* Queue a progress frame */ ast_queue_control(p->owner, AST_CONTROL_PROGRESS); @@ -13539,7 +13553,7 @@ sip_cancel_destroy(p); p->authtries = 0; if (find_sdp(req)) { - if ((res = process_sdp(p, req)) && !req->ignore) + if ((res = process_sdp(p, req, SDP_T38_ACCEPT)) && !req->ignore) if (!reinvite) /* This 200 OK's SDP is not acceptable, so we need to ack, then hangup */ /* For re-invites, we try to recover */ @@ -14299,7 +14313,7 @@ if (!req->ignore) sip_cancel_destroy(p); if (find_sdp(req)) - process_sdp(p, req); + process_sdp(p, req, 0); if (p->owner) { /* Queue a progress frame */ ast_queue_control(p->owner, AST_CONTROL_PROGRESS); @@ -15214,7 +15228,7 @@ ast_clear_flag(&p->flags[0], SIP_OUTGOING); /* This is now an inbound dialog */ /* Handle SDP here if we already have an owner */ if (find_sdp(req)) { - if (process_sdp(p, req)) { + if (process_sdp(p, req, SDP_T38_INITIATE)) { transmit_response(p, "488 Not acceptable here", req); if (!p->lastinvite) sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); @@ -15255,7 +15269,7 @@ /* We have a succesful authentication, process the SDP portion if there is one */ if (find_sdp(req)) { - if (process_sdp(p, req)) { + if (process_sdp(p, req, SDP_T38_INITIATE)) { /* Unacceptable codecs */ transmit_response_reliable(p, "488 Not acceptable here", req); p->invitestate = INV_COMPLETED; @@ -16748,7 +16762,7 @@ p->pendinginvite = 0; __sip_ack(p, seqno, 1 /* response */, 0); if (find_sdp(req)) { - if (process_sdp(p, req)) + if (process_sdp(p, req, 0)) return -1; } check_pendings(p); @@ -19542,7 +19556,7 @@ { struct sip_pvt *p, *pl; struct ast_context *con; - + /* First, take us out of the channel type list */ ast_channel_unregister(&sip_tech);