--- chan_sip.c.orig 2008-08-27 12:27:52.000000000 +0200 +++ chan_sip.c 2008-08-27 18:01:55.000000000 +0200 @@ -988,11 +988,12 @@ #define SIP_PAGE2_BUGGY_MWI (1 << 26) /*!< DP: Buggy CISCO MWI fix */ #define SIP_PAGE2_REGISTERTRYING (1 << 29) /*!< DP: Send 100 Trying on REGISTER attempts */ #define SIP_PAGE2_UDPTL_DESTINATION (1 << 30) /*!< DP: Use source IP of RTP as destination if NAT is enabled */ +#define SIP_PAGE2_Q850_REASON (1 << 31) /*!< DP: Get/send cause code via Reason header */ #define SIP_PAGE2_FLAGS_TO_COPY \ (SIP_PAGE2_ALLOWSUBSCRIBE | SIP_PAGE2_ALLOWOVERLAP | SIP_PAGE2_VIDEOSUPPORT | \ SIP_PAGE2_T38SUPPORT | SIP_PAGE2_RFC2833_COMPENSATE | SIP_PAGE2_BUGGY_MWI | \ - SIP_PAGE2_TEXTSUPPORT | SIP_PAGE2_UDPTL_DESTINATION) + SIP_PAGE2_TEXTSUPPORT | SIP_PAGE2_UDPTL_DESTINATION | SIP_PAGE2_Q850_REASON) /*@}*/ @@ -7570,12 +7571,24 @@ add_header_contentLength(&resp, 0); /* If we are cancelling an incoming invite for some reason, add information about the reason why we are doing this in clear text */ - if (p->method == SIP_INVITE && msg[0] != '1' && p->owner && p->owner->hangupcause) { - char buf[10]; - - add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->owner->hangupcause)); - snprintf(buf, sizeof(buf), "%d", p->owner->hangupcause); - add_header(&resp, "X-Asterisk-HangupCauseCode", buf); + if (p->method == SIP_INVITE && msg[0] != '1' && p->owner) { + char buf[10]; + char buf2[20]; + + if(p->owner->hangupcause) { + if(ast_test_flag(&p->flags[1], SIP_PAGE2_Q850_REASON)) { + sprintf(buf2, "Q.850;cause=%i", p->owner->hangupcause); + add_header(&resp, "Reason", buf2); + } + add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->owner->hangupcause)); + snprintf(buf, sizeof(buf), "%d", p->owner->hangupcause); + add_header(&resp, "X-Asterisk-HangupCauseCode", buf); + } else if(ast_test_flag(&p->flags[1], SIP_PAGE2_Q850_REASON)) { + strncpy(buf, msg, 3); + buf[4] = '\0'; + sprintf(buf2, "Q.850;cause=%i", hangup_sip2cause(atoi(buf))); + add_header(&resp, "Reason", buf2); + } } return send_response(p, &resp, reliable, seqno); } @@ -12748,6 +12761,7 @@ ast_cli(fd, " Sess-Refresh : %s\n", strefresher2str(peer->stimer.st_ref)); ast_cli(fd, " Sess-Expires : %d secs\n", peer->stimer.st_max_se); ast_cli(fd, " Min-Sess : %d secs\n", peer->stimer.st_min_se); + ast_cli(fd, " Use Reason : %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_Q850_REASON) ? "Yes" : "No"); ast_cli(fd, "\n"); unref_peer(peer); } else if (peer && type == 1) { /* manager listing */ @@ -12830,7 +12844,7 @@ astman_append(s, " %s,%s\r\n", v->name, v->value); } } - + astman_append(s, "SIP-Use-Reason-Header : %s\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_Q850_REASON))?"Y":"N"); unref_peer(peer); } else { @@ -15272,6 +15286,7 @@ char *c_copy = ast_strdupa(c); /* Skip the Cseq and its subsequent spaces */ const char *msg = ast_skip_blanks(ast_skip_nonblanks(c_copy)); + char *rp = NULL; if (!msg) msg = ""; @@ -15279,9 +15294,16 @@ sipmethod = find_sip_method(msg); owner = p->owner; - if (owner) - owner->hangupcause = hangup_sip2cause(resp); - + if (owner) { + if (ast_test_flag(&p->flags[1], SIP_PAGE2_Q850_REASON) && (rp = strstr(get_header(req, "Reason"), "cause="))) { + rp += 6; + owner->hangupcause = atoi(rp); + if (req->debug) + ast_verbose("Using Reason header for cause code:%i\n", owner->hangupcause); + } else { + owner->hangupcause = hangup_sip2cause(resp); + } + } /* Acknowledge whatever it is destined for */ if ((resp >= 100) && (resp <= 199)) __sip_semi_ack(p, seqno, 0, sipmethod); @@ -20578,6 +20600,8 @@ } else { peer->stimer.st_ref = i; } + } else if (!strcasecmp(v->name, "use_q850_reason")) { + ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_Q850_REASON); } }