Index: channels/chan_jingle.c =================================================================== --- channels/chan_jingle.c (revision 91829) +++ channels/chan_jingle.c (working copy) @@ -571,7 +571,7 @@ if (tmp) { tmp->alreadygone = 1; if (tmp->owner) - ast_queue_hangup(tmp->owner); + ast_queue_hangup(tmp->owner, -1); } else ast_log(LOG_NOTICE, "Whoa, didn't find call!\n"); jingle_response(client, pak, NULL, NULL); Index: channels/chan_h323.c =================================================================== --- channels/chan_h323.c (revision 91829) +++ channels/chan_h323.c (working copy) @@ -344,7 +344,7 @@ ast_debug(1, "Process pending hangup for %s\n", c->name); c->_softhangup |= AST_SOFTHANGUP_DEV; c->hangupcause = pvt->hangupcause; - ast_queue_hangup(c); + ast_queue_hangup(c, pvt->hangupcause); pvt->needhangup = 0; pvt->newstate = pvt->newcontrol = pvt->newdigit = pvt->DTMFsched = -1; } @@ -2384,7 +2384,7 @@ /* Send hangup */ if (pvt->owner) { pvt->owner->_softhangup |= AST_SOFTHANGUP_DEV; - ast_queue_hangup(pvt->owner); + ast_queue_hangup(pvt->owner, -1); ast_channel_unlock(pvt->owner); } ast_mutex_unlock(&pvt->lock); @@ -2409,7 +2409,7 @@ if (pvt->owner && !ast_channel_trylock(pvt->owner)) { pvt->owner->_softhangup |= AST_SOFTHANGUP_DEV; pvt->owner->hangupcause = pvt->hangupcause = cause; - ast_queue_hangup(pvt->owner); + ast_queue_hangup(pvt->owner, cause); ast_channel_unlock(pvt->owner); } else { Index: channels/chan_zap.c =================================================================== --- channels/chan_zap.c (revision 91829) +++ channels/chan_zap.c (working copy) @@ -4403,7 +4403,7 @@ /* It hasn't been long enough since the last flashook. This is probably a bounce on hanging up. Hangup both channels now */ if (p->subs[SUB_THREEWAY].owner) - ast_queue_hangup(p->subs[SUB_THREEWAY].owner); + ast_queue_hangup(p->subs[SUB_THREEWAY].owner, AST_CAUSE_NO_ANSWER); p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV; ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel); ast_channel_unlock(p->subs[SUB_THREEWAY].owner); @@ -9621,7 +9621,7 @@ ast_mutex_lock(&p->lock); } if (p->subs[x].owner) { - ast_queue_hangup(p->subs[x].owner); + ast_queue_hangup(p->subs[x].owner, AST_CAUSE_PRE_EMPTED); ast_channel_unlock(p->subs[x].owner); } } Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 91829) +++ channels/chan_sip.c (working copy) @@ -2359,7 +2359,7 @@ if (pkt->owner->owner) { sip_alreadygone(pkt->owner); ast_log(LOG_WARNING, "Hanging up call %s - no reply to our critical packet.\n", pkt->owner->callid); - ast_queue_hangup(pkt->owner->owner); + ast_queue_hangup(pkt->owner->owner, AST_CAUSE_PROTOCOL_ERROR); ast_channel_unlock(pkt->owner->owner); } else { /* If no channel owner, destroy now */ @@ -2479,7 +2479,7 @@ if (p->owner) { ast_log(LOG_WARNING, "Autodestruct on dialog '%s' with owner in place (Method: %s)\n", p->callid, sip_methods[p->method].text); - ast_queue_hangup(p->owner); + ast_queue_hangup(p->owner, AST_CAUSE_NORMAL_CLEARING); dialog_unref(p); } else if (p->refer) { ast_debug(3, "Finally hanging up channel after transfer: %s\n", p->callid); @@ -13588,7 +13588,7 @@ */ xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); if (p->owner && !req->ignore) { - ast_queue_hangup(p->owner); + ast_queue_hangup(p->owner, AST_CAUSE_NORMAL_CLEARING); append_history(p, "Hangup", "Got 487 on CANCEL request from us. Queued AST hangup request"); } else if (!req->ignore) { update_call_counter(p, DEC_CALL_LIMIT); @@ -14002,7 +14002,7 @@ if (p->owner) { if (!p->refer) { ast_log(LOG_WARNING, "Notify answer on an owned channel? - %s\n", p->owner->name); - ast_queue_hangup(p->owner); + ast_queue_hangup(p->owner, AST_CAUSE_NORMAL_UNSPECIFIED); } else ast_debug(4, "Got OK on REFER Notify message\n"); } else { @@ -14177,7 +14177,7 @@ default: /* Send hangup */ if (owner && sipmethod != SIP_MESSAGE && sipmethod != SIP_INFO && sipmethod != SIP_BYE) - ast_queue_hangup(p->owner); + ast_queue_hangup(p->owner, AST_CAUSE_PROTOCOL_ERROR); break; } /* ACK on invite */ @@ -14231,7 +14231,7 @@ ast_debug(1, "Got 200 OK on NOTIFY for transfer\n"); } else ast_log(LOG_WARNING, "Notify answer on an owned channel?\n"); - /* ast_queue_hangup(p->owner); Disabled */ + /* ast_queue_hangup(p->owner, -1); Disabled */ } else { if (!p->subscribed && !p->refer) p->needdestroy = 1; @@ -15911,7 +15911,7 @@ stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ if (p->owner) - ast_queue_hangup(p->owner); + ast_queue_hangup(p->owner, -1); else sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); if (p->initreq.len > 0) { @@ -16068,15 +16068,15 @@ ast_queue_control(c, AST_CONTROL_UNHOLD); ast_async_goto(bridged_to, p->context, p->refer->refer_to,1); } else - ast_queue_hangup(p->owner); + ast_queue_hangup(p->owner, -1); } } else { ast_log(LOG_WARNING, "Invalid transfer information from '%s'\n", ast_inet_ntoa(p->recv.sin_addr)); if (p->owner) - ast_queue_hangup(p->owner); + ast_queue_hangup(p->owner, AST_CAUSE_PROTOCOL_ERROR); } } else if (p->owner) { - ast_queue_hangup(p->owner); + ast_queue_hangup(p->owner, -1); ast_debug(3, "Received bye, issuing owner hangup\n"); } else { sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); Index: channels/chan_iax2.c =================================================================== --- channels/chan_iax2.c (revision 91829) +++ channels/chan_iax2.c (working copy) @@ -1626,7 +1626,7 @@ usleep(1); ast_mutex_lock(&iaxsl[callno]); } else { - ast_queue_hangup(iaxs[callno]->owner); + ast_queue_hangup(iaxs[callno]->owner, -1); ast_channel_unlock(iaxs[callno]->owner); break; } @@ -2122,7 +2122,7 @@ /* If there's an owner, prod it to give up */ /* It is ok to use ast_queue_hangup() here instead of iax2_queue_hangup() * because we already hold the owner channel lock. */ - ast_queue_hangup(owner); + ast_queue_hangup(owner, -1); } AST_LIST_LOCK(&frame_queue[pvt->callno]); @@ -2195,10 +2195,8 @@ ast_log(LOG_WARNING, "Max retries exceeded to host %s on %s (type = %d, subclass = %d, ts=%d, seqno=%d)\n", ast_inet_ntoa(iaxs[f->callno]->addr.sin_addr),iaxs[f->callno]->owner->name , f->af.frametype, f->af.subclass, f->ts, f->oseqno); iaxs[callno]->error = ETIMEDOUT; if (iaxs[callno]->owner) { - struct ast_frame fr = { 0, }; + struct ast_frame fr = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP, .seqno = AST_CAUSE_DESTINATION_OUT_OF_ORDER }; /* Hangup the fd */ - fr.frametype = AST_FRAME_CONTROL; - fr.subclass = AST_CONTROL_HANGUP; iax2_queue_frame(callno, &fr); /* XXX */ /* Remember, owner could disappear */ if (iaxs[callno] && iaxs[callno]->owner) Index: channels/chan_oss.c =================================================================== --- channels/chan_oss.c (revision 91829) +++ channels/chan_oss.c (working copy) @@ -1292,7 +1292,7 @@ } o->hookstate = 0; if (o->owner) - ast_queue_hangup(o->owner); + ast_queue_hangup(o->owner, AST_CAUSE_NORMAL_CLEARING); setformat(o, O_CLOSE); return CLI_SUCCESS; } Index: channels/chan_misdn.c =================================================================== --- channels/chan_misdn.c (revision 91829) +++ channels/chan_misdn.c (working copy) @@ -2303,13 +2303,13 @@ if (!p) { ast_log(LOG_WARNING, " --> Channel not connected ??\n"); - ast_queue_hangup(ast); + ast_queue_hangup(ast, AST_CAUSE_NETWORK_OUT_OF_ORDER); } if (!p->bc) { chan_misdn_log(1, 0, " --> Got Answer, but theres no bc obj ??\n"); - ast_queue_hangup(ast); + ast_queue_hangup(ast, AST_CAUSE_PROTOCOL_ERROR); } tmp = pbx_builtin_getvar_helper(p->ast, "CRYPT_KEY"); @@ -3642,7 +3642,7 @@ send_cause2ast(ch->ast, ch->bc, ch); if (ch->ast) - ast_queue_hangup(ch->ast); + ast_queue_hangup(ch->ast, ch->bc->cause); cb_log(2, port, " --> queue_hangup\n"); } else { cb_log(1, port, "Cannot hangup chan, no ast\n"); Index: channels/chan_skinny.c =================================================================== --- channels/chan_skinny.c (revision 91829) +++ channels/chan_skinny.c (working copy) @@ -4171,7 +4171,7 @@ if ((res = attempt_transfer(p)) < 0) { if (sub->next && sub->next->owner) { sub->next->alreadygone = 1; - ast_queue_hangup(sub->next->owner,1); + ast_queue_hangup(sub->next->owner, -1); } } else if (res) { ast_log(LOG_WARNING, "Transfer attempt failed\n"); @@ -4183,7 +4183,7 @@ /* If there is another active call, skinny_hangup will ring the phone with the other call */ if (sub->owner) { sub->alreadygone = 1; - ast_queue_hangup(sub->owner); + ast_queue_hangup(sub->owner, -1); } else { ast_log(LOG_WARNING, "Skinny(%s@%s-%d) channel already destroyed\n", l->name, d->name, sub->callid); @@ -4835,7 +4835,7 @@ if ((res = attempt_transfer(p)) < 0) { if (sub->next && sub->next->owner) { sub->next->alreadygone = 1; - ast_queue_hangup(sub->next->owner, 1); + ast_queue_hangup(sub->next->owner, -1); } } else if (res) { ast_log(LOG_WARNING, "Transfer attempt failed\n"); @@ -4847,7 +4847,7 @@ /* If there is another active call, skinny_hangup will ring the phone with the other call */ if (sub->owner) { sub->alreadygone = 1; - ast_queue_hangup(sub->owner); + ast_queue_hangup(sub->owner, -1); } else { ast_log(LOG_WARNING, "Skinny(%s@%s-%d) channel already destroyed\n", l->name, d->name, sub->callid); Index: channels/chan_alsa.c =================================================================== --- channels/chan_alsa.c (revision 91829) +++ channels/chan_alsa.c (working copy) @@ -1012,7 +1012,7 @@ hookstate = 0; grab_owner(); if (alsa.owner) { - ast_queue_hangup(alsa.owner); + ast_queue_hangup(alsa.owner, AST_CAUSE_NORMAL_CLEARING); ast_channel_unlock(alsa.owner); } } Index: channels/chan_mgcp.c =================================================================== --- channels/chan_mgcp.c (revision 91829) +++ channels/chan_mgcp.c (working copy) @@ -606,7 +606,7 @@ for(;;) { if (sub->owner) { if (!ast_channel_trylock(sub->owner)) { - ast_queue_hangup(sub->owner); + ast_queue_hangup(sub->owner, -1); ast_channel_unlock(sub->owner); break; } else { Index: channels/chan_unistim.c =================================================================== --- channels/chan_unistim.c (revision 91829) +++ channels/chan_unistim.c (working copy) @@ -1152,7 +1152,7 @@ if (sub->owner) { /* Call in progress ? */ if (unistimdebug) ast_verbose("Aborting call\n"); - ast_queue_hangup(sub->owner); + ast_queue_hangup(sub->owner, AST_CAUSE_NETWORK_OUT_OF_ORDER); } } else ast_log(LOG_WARNING, "Freeing a client with no subchannel !\n"); @@ -2004,11 +2004,11 @@ if (attempt_transfer(sub, l->subs[SUB_THREEWAY]) < 0) ast_verbose("attempt_transfer failed.\n"); } else - ast_queue_hangup(sub->owner); + ast_queue_hangup(sub->owner, -1); } else { if (l->subs[SUB_THREEWAY]) { if (l->subs[SUB_THREEWAY]->owner) - ast_queue_hangup(l->subs[SUB_THREEWAY]->owner); + ast_queue_hangup(l->subs[SUB_THREEWAY]->owner, AST_CAUSE_NORMAL_CLEARING); else ast_log(LOG_WARNING, "threeway sub without owner\n"); } else @@ -2343,7 +2343,7 @@ if (unistimdebug) ast_verbose("Transfer canceled, hangup our threeway channel\n"); if (p->subs[SUB_THREEWAY]->owner) - ast_queue_hangup(p->subs[SUB_THREEWAY]->owner); + ast_queue_hangup(p->subs[SUB_THREEWAY]->owner, AST_CAUSE_NORMAL_CLEARING); else ast_log(LOG_WARNING, "Canceling a threeway channel without owner\n"); return; @@ -2399,7 +2399,7 @@ /* start switch */ if (ast_pthread_create(&t, NULL, unistim_ss, c)) { display_last_error("Unable to create switch thread"); - ast_queue_hangup(c); + ast_queue_hangup(c, AST_CAUSE_SWITCH_CONGESTION); } } else ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", Index: channels/chan_local.c =================================================================== --- channels/chan_local.c (revision 91829) +++ channels/chan_local.c (working copy) @@ -488,7 +488,7 @@ { struct local_pvt *p = ast->tech_pvt; int isoutbound; - struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; + struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP, .seqno = ast->hangupcause }; struct ast_channel *ochan = NULL; int glaredetect = 0, res = 0; Index: channels/chan_gtalk.c =================================================================== --- channels/chan_gtalk.c (revision 91829) +++ channels/chan_gtalk.c (working copy) @@ -708,7 +708,7 @@ if (tmp) { tmp->alreadygone = 1; if (tmp->owner) - ast_queue_hangup(tmp->owner); + ast_queue_hangup(tmp->owner, -1); } else ast_log(LOG_NOTICE, "Whoa, didn't find call!\n"); gtalk_response(client, from, pak, NULL, NULL); Index: apps/app_alarmreceiver.c =================================================================== --- apps/app_alarmreceiver.c (revision 91829) +++ apps/app_alarmreceiver.c (working copy) @@ -264,6 +264,8 @@ /* If they hung up, leave */ if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP)){ + if (f->seqno) + chan->hangupcause = f->seqno; ast_frfree(f); res = -1; break; Index: apps/app_dial.c =================================================================== --- apps/app_dial.c (revision 91829) +++ apps/app_dial.c (working copy) @@ -771,8 +771,11 @@ *to = -1; strcpy(pa->status, "CANCEL"); ast_cdr_noanswer(in->cdr); - if (f) + if (f) { + if (f->seqno) + in->hangupcause = f->seqno; ast_frfree(f); + } return NULL; } Index: apps/app_disa.c =================================================================== --- apps/app_disa.c (revision 91829) +++ apps/app_disa.c (working copy) @@ -195,6 +195,8 @@ } if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP)) { + if (f->seqno) + chan->hangupcause = f->seqno; ast_frfree(f); ast_clear_flag(chan, AST_FLAG_END_DTMF_ONLY); return -1; Index: apps/app_externalivr.c =================================================================== --- apps/app_externalivr.c (revision 91829) +++ apps/app_externalivr.c (working copy) @@ -419,6 +419,8 @@ } else if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP)) { ast_chan_log(LOG_NOTICE, chan, "Got AST_CONTROL_HANGUP\n"); send_child_event(child_events, 'H', NULL, chan); + if (f->seqno) + chan->hangupcause = f->seqno; ast_frfree(f); res = -1; break; Index: apps/app_queue.c =================================================================== --- apps/app_queue.c (revision 91829) +++ apps/app_queue.c (working copy) @@ -2402,6 +2402,8 @@ /* Got hung up */ *to = -1; if (f) { + if (f->seqno) + in->hangupcause = f->seqno; ast_frfree(f); } return NULL; Index: apps/app_followme.c =================================================================== --- apps/app_followme.c (revision 91829) +++ apps/app_followme.c (working copy) @@ -607,6 +607,8 @@ case AST_CONTROL_HANGUP: if (option_verbose > 2) ast_verb(3, "%s received a hangup frame.\n", winner->name); + if (f->seqno) + chan->hangupcause = f->seqno; if (dg == 0) { ast_verb(3, "The calling channel hungup. Need to drop everyone else.\n"); clear_calling_tree(findme_user_list); Index: include/asterisk/channel.h =================================================================== --- include/asterisk/channel.h (revision 91829) +++ include/asterisk/channel.h (working copy) @@ -698,7 +698,7 @@ * * \note The channel does not need to be locked before calling this function. */ -int ast_queue_hangup(struct ast_channel *chan); +int ast_queue_hangup(struct ast_channel *chan, int cause); /*! * \brief Queue a control frame with payload Index: main/channel.c =================================================================== --- main/channel.c (revision 91829) +++ main/channel.c (working copy) @@ -854,12 +854,19 @@ } /*! \brief Queue a hangup frame for channel */ -int ast_queue_hangup(struct ast_channel *chan) +int ast_queue_hangup(struct ast_channel *chan, int cause) { struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; + + if (cause >= 0) + f.seqno = cause; + /* Yeah, let's not change a lock-critical value without locking */ if (!ast_channel_trylock(chan)) { chan->_softhangup |= AST_SOFTHANGUP_DEV; + if (cause < 0) + f.seqno = chan->hangupcause; + ast_channel_unlock(chan); } return ast_queue_frame(chan, &f); @@ -2121,7 +2128,7 @@ struct ast_frame *f = NULL; /* the return value */ int blah; int prestate; - int count = 0; + int count = 0, cause = 0; /* this function is very long so make sure there is only one return * point at the end (there are only two exceptions to this). @@ -2228,6 +2235,7 @@ /* Interpret hangup and return NULL */ /* XXX why not the same for frames from the channel ? */ if (f->frametype == AST_FRAME_CONTROL && f->subclass == AST_CONTROL_HANGUP) { + cause = f->seqno; ast_frfree(f); f = NULL; } @@ -2487,6 +2495,8 @@ } else { /* Make sure we always return NULL in the future */ chan->_softhangup |= AST_SOFTHANGUP_DEV; + if (cause) + chan->hangupcause = cause; if (chan->generator) ast_deactivate_generator(chan); /* End the CDR if appropriate */