<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>
        Added cause translation information for IAX2 and DAHDI<br />
    </div>
        <br/>
                         <h4>Changes (2)</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. Understanding the Information Provided <br></td></tr>
            <tr><td class="diff-changed-lines" >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 <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">one channel technology</span> <span class="diff-added-words"style="background-color: #dfd;">channel-specific terms</span> to <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">another.</span> <span class="diff-added-words"style="background-color: #dfd;">Asterisk/ISDN cause codes.</span>  This work is <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">also</span> in progress. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;"> <br>h2. IAX2 <br>IAX2 already uses Asterisk/ISDN cause codes, so these are provided as-is. <br> <br>h2. DAHDI <br>h3. ISDN <br>Asterisk cause codes are a superset of ISDN cause codes. These are left unmodified. <br>h3. SS7 <br>Asterisk cause codes are a superset of ISDN cause codes (which SS7 uses). These are left unmodified. <br>h3. Analog <br>Analog hangups will always present with AST_CAUSE_NORMAL_CLEARING (Normal Clearing). There is no way to get additional information for these channels. <br>h3. MFC/R2 <br>The mapping for MFC/R2 cause codes to Asterisk/ISDN cause codes can be found below. <br>||MFC/R2 Cause Code||Asterisk/ISDN Cause Code|| <br>|OR2_CAUSE_BUSY_NUMBER|AST_CAUSE_BUSY| <br>|OR2_CAUSE_NETWORK_CONGESTION|AST_CAUSE_CONGESTION| <br>|OR2_CAUSE_OUT_OF_ORDER|AST_CAUSE_DESTINATION_OUT_OF_ORDER| <br>|OR2_CAUSE_UNALLOCATED_NUMBER|AST_CAUSE_UNREGISTERED| <br>|OR2_CAUSE_NO_ANSWER|AST_CAUSE_NO_ANSWER| <br>|OR2_CAUSE_NORMAL_CLEARING|AST_CAUSE_NORMAL_CLEARING| <br>|OR2_CAUSE_UNSPECIFIED|AST_CAUSE_NOTDEFINED| <br> <br>h2. SIP <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 hash resolves these issues by passing this data via control frames and creating a more generic mechanism that all channel technologies can share.  This allows the channel and 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.  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=${HASHKEYS(HANGUPCAUSE)})
; 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 ${HASH(HANGUPCAUSE,${item})})

; 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.</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 will be provided that allow conversion of cause codes from channel-specific terms to Asterisk/ISDN cause codes.  This work is in progress.</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>
    </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=4&originalVersion=3">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>