<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/en/2176/18/9/_/styles/combined.css?spaceKey=AST&forWysiwyg=true" type="text/css">
</head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
<h2><a href="https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=20185363">Who Hung Up?</a></h2>
<h4>Page <b>edited</b> by <a href="https://wiki.asterisk.org/wiki/display/~kmoore">Kinsey Moore</a>
</h4>
<div id="versionComment">
<b>Comment:</b>
Added information about local channels and their use with HANGUPCAUSE<br />
</div>
<br/>
<h4>Changes (1)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-snipped" >...<br></td></tr>
<tr><td class="diff-unchanged" > <br>h1. Additional Usage <br></td></tr>
<tr><td class="diff-changed-lines" >In addition to being available on the caller channel as a direct replacement for SIP_CAUSE, HANGUPCAUSE can be used on callee channels in conjunction with pre-dial dialplan execution and hangup handlers so that hangup cause information may be evaluated on a one-to-one basis instead of a many-to-one basis as it is used on caller channels. <span class="diff-added-words"style="background-color: #dfd;"> The primary exception to this use case is Local channels. Local channels do not aggregate information from branched dials further down the chain and do not generate their own hangup cause information and thus they will never have hangup cause information attributed directly to them.</span> <br></td></tr>
<tr><td class="diff-unchanged" > <br>h1. Support for Other Channel Drivers <br></td></tr>
<tr><td class="diff-snipped" >...<br></td></tr>
</table>
</div> <h4>Full Content</h4>
<div class="notificationGreySide">
<h1><a name="WhoHungUp%3F-Overview"></a>Overview</h1>
<p>Usage of SIP_CAUSE has been known for a while now to impact performance in some situations due to the use of the MASTER_CHANNEL dialplan function which must scan through the channel list. Another issue with SIP_CAUSE is that it is too technology-specific. The HANGUPCAUSE function resolves these issues by passing this data and its AST_CAUSE translation via control frames and creating a more generic mechanism that all channel technologies can share. This allows the techonology-specific and generic cause code information to move through Asterisk's core along with other control frames to the parent channel.</p>
<h1><a name="WhoHungUp%3F-DifferencesinUsage"></a>Differences in Usage</h1>
<p>HANGUPCAUSE may be used in any situation that calls for SIP_CAUSE as a drop-in replacement if only SIP channels are being called. If used with non-SIP channels, dialplan code using HANGUPCAUSE must be able to handle non-SIP cause codes or be able to safely ignore them. A comma-separated list of channels for which information is available can be acquired using the HANGUPCAUSE_KEYS function. SIP_CAUSE has also been modified to use HANGUPCAUSE as its backend to take advantage of better performing code.</p>
<h1><a name="WhoHungUp%3F-Example"></a>Example</h1>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">[foo]
exten => s,1,Dial(SIP/bar)
exten => h,1,noop()
exten => h,n,set(HANGUPCAUSE_STRING=${HANGUPCAUSE_KEYS()})
; start loop
exten => h,n(hu_begin),noop()
; check exit condition (no more array to check)
exten => h,n,gotoif($[${LEN(${HANGUPCAUSE_STRING})} = 0]?hu_exit)
; pull the next item
exten => h,n,set(ARRAY(item)=${HANGUPCAUSE_STRING})
exten => h,n,set(HANGUPCAUSE_STRING=${HANGUPCAUSE_STRING:${LEN(${item})}})
; display the channel ID and cause code
exten => h,n,noop(got channel ID ${item} with pvt cause ${HANGUPCAUSE(${item},tech)})
; check exit condition (no more array to check)
exten => h,n,gotoif($[${LEN(${HANGUPCAUSE_STRING})} = 0]?hu_exit)
; we still have entries to process, so strip the leading comma
exten => h,n,set(HANGUPCAUSE_STRING=${HANGUPCAUSE_STRING:1})
; go back to the beginning of the loop
exten => h,n,goto(hu_begin)
exten => h,n(hu_exit),noop(All HANGUPCAUSE entries processed)</pre>
</div></div>
<h1><a name="WhoHungUp%3F-AdditionalUsage"></a>Additional Usage</h1>
<p>In addition to being available on the caller channel as a direct replacement for SIP_CAUSE, HANGUPCAUSE can be used on callee channels in conjunction with pre-dial dialplan execution and hangup handlers so that hangup cause information may be evaluated on a one-to-one basis instead of a many-to-one basis as it is used on caller channels. The primary exception to this use case is Local channels. Local channels do not aggregate information from branched dials further down the chain and do not generate their own hangup cause information and thus they will never have hangup cause information attributed directly to them.</p>
<h1><a name="WhoHungUp%3F-SupportforOtherChannelDrivers"></a>Support for Other Channel Drivers</h1>
<p>The implementation that HANGUPCAUSE and the modified SIP_CAUSE use is extensible to other channel technologies as well. The implementation for chan_sip, chan_iax2, and chan_dahdi (analog, PRI, SS7, and MFC/R2) is complete and committed along with minimal support required in other channel drivers to keep them from breaking on the new frame.</p>
<h1><a name="WhoHungUp%3F-UnderstandingtheInformationProvided"></a>Understanding the Information Provided</h1>
<p>In an effort to allow consumers of this information to better understand what is available, translation facilities are provided that allow access to Asterisk/ISDN cause code equivalents. This information can be accessed by using "ast" as the second parameter of the HANGUPCAUSE function instead of using "tech". This work is committed.</p>
<h2><a name="WhoHungUp%3F-IAX2"></a>IAX2</h2>
<p>IAX2 already uses Asterisk/ISDN cause codes, so these are provided as-is.</p>
<h2><a name="WhoHungUp%3F-DAHDI"></a>DAHDI</h2>
<h3><a name="WhoHungUp%3F-ISDN"></a>ISDN</h3>
<p>Asterisk cause codes are a superset of ISDN cause codes. These are left unmodified.</p>
<h3><a name="WhoHungUp%3F-SS7"></a>SS7</h3>
<p>Asterisk cause codes are a superset of ISDN cause codes (which SS7 uses). These are left unmodified.</p>
<h3><a name="WhoHungUp%3F-Analog"></a>Analog</h3>
<p>Analog hangups will always present with AST_CAUSE_NORMAL_CLEARING (Normal Clearing). There is no way to get additional information for these channels.</p>
<h3><a name="WhoHungUp%3F-MFC%2FR2"></a>MFC/R2</h3>
<p>The mapping for MFC/R2 cause codes to Asterisk/ISDN cause codes can be found below.</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>MFC/R2 Cause Code</th>
<th class='confluenceTh'>Asterisk/ISDN Cause Code</th>
</tr>
<tr>
<td class='confluenceTd'>OR2_CAUSE_BUSY_NUMBER</td>
<td class='confluenceTd'>AST_CAUSE_BUSY</td>
</tr>
<tr>
<td class='confluenceTd'>OR2_CAUSE_NETWORK_CONGESTION</td>
<td class='confluenceTd'>AST_CAUSE_CONGESTION</td>
</tr>
<tr>
<td class='confluenceTd'>OR2_CAUSE_OUT_OF_ORDER</td>
<td class='confluenceTd'>AST_CAUSE_DESTINATION_OUT_OF_ORDER</td>
</tr>
<tr>
<td class='confluenceTd'>OR2_CAUSE_UNALLOCATED_NUMBER</td>
<td class='confluenceTd'>AST_CAUSE_UNREGISTERED</td>
</tr>
<tr>
<td class='confluenceTd'>OR2_CAUSE_NO_ANSWER</td>
<td class='confluenceTd'>AST_CAUSE_NO_ANSWER</td>
</tr>
<tr>
<td class='confluenceTd'>OR2_CAUSE_NORMAL_CLEARING</td>
<td class='confluenceTd'>AST_CAUSE_NORMAL_CLEARING</td>
</tr>
<tr>
<td class='confluenceTd'>OR2_CAUSE_UNSPECIFIED</td>
<td class='confluenceTd'>AST_CAUSE_NOTDEFINED</td>
</tr>
</tbody></table>
</div>
<h2><a name="WhoHungUp%3F-SIP"></a>SIP</h2>
<p>The cause code translations for SIP are based in part on RFC3398. They can be found in the table below.</p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>SIP Response</th>
<th class='confluenceTh'>Asterisk/ISDN Cause Code</th>
</tr>
<tr>
<td class='confluenceTd'>401</td>
<td class='confluenceTd'>AST_CAUSE_CALL_REJECTED</td>
</tr>
<tr>
<td class='confluenceTd'>403</td>
<td class='confluenceTd'>AST_CAUSE_CALL_REJECTED</td>
</tr>
<tr>
<td class='confluenceTd'>404</td>
<td class='confluenceTd'>AST_CAUSE_UNALLOCATED</td>
</tr>
<tr>
<td class='confluenceTd'>407</td>
<td class='confluenceTd'>AST_CAUSE_CALL_REJECTED</td>
</tr>
<tr>
<td class='confluenceTd'>408</td>
<td class='confluenceTd'>AST_CAUSE_NO_USER_RESPONSE</td>
</tr>
<tr>
<td class='confluenceTd'>409</td>
<td class='confluenceTd'>AST_CAUSE_NORMAL_TEMPORARY_FAILURE</td>
</tr>
<tr>
<td class='confluenceTd'>410</td>
<td class='confluenceTd'>AST_CAUSE_NUMBER_CHANGED</td>
</tr>
<tr>
<td class='confluenceTd'>420</td>
<td class='confluenceTd'>AST_CAUSE_NO_ROUTE_DESTINATION</td>
</tr>
<tr>
<td class='confluenceTd'>480</td>
<td class='confluenceTd'>AST_CAUSE_NO_ANSWER</td>
</tr>
<tr>
<td class='confluenceTd'>483</td>
<td class='confluenceTd'>AST_CAUSE_NO_ANSWER</td>
</tr>
<tr>
<td class='confluenceTd'>484</td>
<td class='confluenceTd'>AST_CAUSE_INVALID_NUMBER_FORMAT</td>
</tr>
<tr>
<td class='confluenceTd'>485</td>
<td class='confluenceTd'>AST_CAUSE_UNALLOCATED</td>
</tr>
<tr>
<td class='confluenceTd'>486</td>
<td class='confluenceTd'>AST_CAUSE_BUSY</td>
</tr>
<tr>
<td class='confluenceTd'>488</td>
<td class='confluenceTd'>AST_CAUSE_BEARERCAPABILITY_NOTAVAIL</td>
</tr>
<tr>
<td class='confluenceTd'>All Other 4xx</td>
<td class='confluenceTd'>AST_CAUSE_INTERWORKING</td>
</tr>
<tr>
<td class='confluenceTd'>500</td>
<td class='confluenceTd'>AST_CAUSE_FAILURE</td>
</tr>
<tr>
<td class='confluenceTd'>501</td>
<td class='confluenceTd'>AST_CAUSE_FACILITY_REJECTED</td>
</tr>
<tr>
<td class='confluenceTd'>502</td>
<td class='confluenceTd'>AST_CAUSE_DESTINATION_OUT_OF_ORDER</td>
</tr>
<tr>
<td class='confluenceTd'>504</td>
<td class='confluenceTd'>AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE</td>
</tr>
<tr>
<td class='confluenceTd'>505</td>
<td class='confluenceTd'>AST_CAUSE_INTERWORKING</td>
</tr>
<tr>
<td class='confluenceTd'>All Other 5xx</td>
<td class='confluenceTd'>AST_CAUSE_CONGESTION</td>
</tr>
<tr>
<td class='confluenceTd'>600</td>
<td class='confluenceTd'>AST_CAUSE_USER_BUSY</td>
</tr>
<tr>
<td class='confluenceTd'>603</td>
<td class='confluenceTd'>AST_CAUSE_CALL_REJECTED</td>
</tr>
<tr>
<td class='confluenceTd'>604</td>
<td class='confluenceTd'>AST_CAUSE_UNALLOCATED</td>
</tr>
<tr>
<td class='confluenceTd'>606</td>
<td class='confluenceTd'>AST_CAUSE_BEARERCAPABILITY_NOTAVAIL</td>
</tr>
<tr>
<td class='confluenceTd'>All Other 6xx</td>
<td class='confluenceTd'>AST_CAUSE_INTERWORKING</td>
</tr>
</tbody></table>
</div>
</div>
<div id="commentsSection" class="wiki-content pageSection">
<div style="float: right;" class="grey">
<a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=AST">Stop watching space</a>
<span style="padding: 0px 5px;">|</span>
<a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
<a href="https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=20185363">View Online</a>
|
<a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=20185363&revisedVersion=8&originalVersion=7">View Changes</a>
|
<a href="https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=20185363&showComments=true&showCommentArea=true#addcomment">Add Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>