<html>
<head>
    <base href="https://wiki.asterisk.org/wiki">
            <link rel="stylesheet" href="/wiki/s/en/2172/18/9/_/styles/combined.css?spaceKey=AST&amp;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>
        update for new syntax and translations<br />
    </div>
        <br/>
                         <h4>Changes (7)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-unchanged" >h1. Overview <br></td></tr>
            <tr><td class="diff-changed-lines" >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 <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">hash</span> <span class="diff-added-words"style="background-color: #dfd;">function</span> resolves these issues by passing this data <span class="diff-added-words"style="background-color: #dfd;">and its AST_CAUSE translation</span> via control frames and creating a more generic mechanism that all channel technologies can share.  This allows the <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">channel</span> <span class="diff-added-words"style="background-color: #dfd;">techonology-specific</span> and <span class="diff-added-words"style="background-color: #dfd;">generic</span> cause code information to move through Asterisk&#39;s core along with other control frames to the parent channel. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h1. Differences in Usage <br></td></tr>
            <tr><td class="diff-changed-lines" >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.  <span class="diff-added-words"style="background-color: #dfd;">A comma-separated list of channels for which information is available can be acquired using the HANGUPCAUSE_KEYS function. </span> SIP_CAUSE has also been modified to use HANGUPCAUSE as its backend to take advantage of better performing code. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h1. Example <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>exten =&gt; h,1,noop() <br></td></tr>
            <tr><td class="diff-changed-lines" >exten =&gt; <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">h,n,set(HANGUPCAUSE_STRING=${HASHKEYS(HANGUPCAUSE)})</span> <span class="diff-added-words"style="background-color: #dfd;">h,n,set(HANGUPCAUSE_STRING=${HANGUPCAUSE_KEYS()})</span> <br></td></tr>
            <tr><td class="diff-unchanged" >; start loop <br>exten =&gt; h,n(hu_begin),noop() <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>; display the channel ID and cause code <br></td></tr>
            <tr><td class="diff-changed-lines" >exten =&gt; h,n,noop(got channel ID ${item} with pvt cause <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">${HASH(HANGUPCAUSE,${item})})</span> <span class="diff-added-words"style="background-color: #dfd;">${HANGUPCAUSE(${item},tech)})</span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br>; check exit condition (no more array to check) <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br>h1. Support for Other Channel Drivers <br></td></tr>
            <tr><td class="diff-changed-lines" >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 <span class="diff-changed-words">committed<span class="diff-added-chars"style="background-color: #dfd;"> along with minimal support required in other channel drivers to keep them from breaking on the new frame</span>.</span> <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h1. Understanding the Information Provided <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">In an effort to allow consumers of this information to better understand what is available, translation facilities will be provided that allow conversion of cause codes from channel-specific terms to Asterisk/ISDN cause codes.  This work is in progress. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">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 &quot;ast&quot; as the second parameter of the HANGUPCAUSE function instead of using &quot;tech&quot;.  This work is committed. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>h2. IAX2 <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 =&gt; s,1,Dial(SIP/bar)

exten =&gt; h,1,noop()
exten =&gt; h,n,set(HANGUPCAUSE_STRING=${HANGUPCAUSE_KEYS()})
; start loop
exten =&gt; h,n(hu_begin),noop()

; check exit condition (no more array to check)
exten =&gt; h,n,gotoif($[${LEN(${HANGUPCAUSE_STRING})} = 0]?hu_exit)

; pull the next item
exten =&gt; h,n,set(ARRAY(item)=${HANGUPCAUSE_STRING})
exten =&gt; h,n,set(HANGUPCAUSE_STRING=${HANGUPCAUSE_STRING:${LEN(${item})}})

; display the channel ID and cause code
exten =&gt; h,n,noop(got channel ID ${item} with pvt cause ${HANGUPCAUSE(${item},tech)})

; check exit condition (no more array to check)
exten =&gt; h,n,gotoif($[${LEN(${HANGUPCAUSE_STRING})} = 0]?hu_exit)

; we still have entries to process, so strip the leading comma
exten =&gt; h,n,set(HANGUPCAUSE_STRING=${HANGUPCAUSE_STRING:1})
; go back to the beginning of the loop
exten =&gt; h,n,goto(hu_begin)
exten =&gt; h,n(hu_exit),noop(All HANGUPCAUSE entries processed)</pre>
</div></div>

<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=6&originalVersion=5">View Changes</a>
                |
        <a href="https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=20185363&showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>