Summary:ASTERISK-26396: chan_pjsip: HANGUPCAUSE return the wrong code when dialed channel answer.
Reporter:Aaron An (aaron)Labels:
Date Opened:2016-09-21 05:38:45Date Closed:2017-09-28 15:40:53
Versions:13.8.0 Frequency of
Environment:CentOS6.5 X64 Attachments:
Description:A dials into asterisk and runs dialplan. The dialplan execute Dial() to dial B, and B answer the call, but after that, NoOp($\{ $\{HANGUPCAUSE($\{CHANNEL_B},tech)}) on A channel shows the result of "SIP 183 Session Progress". it should be "SIP 200 Ok".

look at the source code channels/chan_pjsip.c function chan_pjsip_incoming_response(). In this function first call ast_queue_control(session->channel, AST_CONTROL_ANSWER) and then call ast_queue_control_data(session->channel, AST_CONTROL_PVT_CAUSE_CODE, cause_code, data_size).

look at the source code apps/app_dial.c function wait_for_answer. In this funciton if frame (frame_type=AST_FRAME_CONTROL && subclass=AST_CONTROL_ANSWER) first comes, the line

   while ((*to = ast_remaining_ms(start, orig)) && !peer) \{

will terminate the while and there is no chance to execute the below code

            case AST_CONTROL_PVT_CAUSE_CODE:
                   ast_indicate_data(in, AST_CONTROL_PVT_CAUSE_CODE, f->data.ptr, f->datalen);

I think it shoud revert the call sequence of  "ast_queue_control" and "ast_queue_control_data" in function chan_pjsip_incoming_response() of channels/chan_pjsip.c.

Is it ok? if so I can post a patch to gerrit.
Comments:By: Asterisk Team (asteriskteam) 2016-09-21 05:38:47.461-0500

Thanks for creating a report! The issue has entered the triage process. That means the issue will wait in this status until a Bug Marshal has an opportunity to review the issue. Once the issue has been reviewed you will receive comments regarding the next steps towards resolution.

A good first step is for you to review the [Asterisk Issue Guidelines|https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines] if you haven't already. The guidelines detail what is expected from an Asterisk issue report.

Then, if you are submitting a patch, please review the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process].

By: Joshua C. Colp (jcolp) 2016-09-21 06:39:07.701-0500

I think your fix sounds reasonable and correct. Feel free to post the change on gerrit!

By: Aaron An (aaron) 2016-09-22 01:46:59.963-0500