<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/en/2172/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/display/AST/Hangup+Cause">Hangup Cause</a></h2>
<h4>Page <b>added</b> by <a href="https://wiki.asterisk.org/wiki/display/~mjordan">Matt Jordan</a>
</h4>
<br/>
<div class="notificationGreySide">
<h2><a name="HangupCause-Overview"></a>Overview</h2>
<p>The Hangup Cause family of functions and dialplan applications allow for inspection of the hangup cause codes for each channel involved in a call. This allows a dialplan writer to determine, for each channel, who hung up and for what reason(s). Note that this extends the functionality available in the <a href="/wiki/pages/createpage.action?spaceKey=AST&title=Asterisk%2BStandard%2BChannel%2BVariables&linkCreation=true&fromPageId=20189310" class="createlink">HANGUPCAUSE</a> channel variable, by allowing a calling channel to inspect all called channel's hangup causes in a variety of dialling situations.</p>
<p>Note that this feature replaces the technology specific mechanism of using the <a href="/wiki/display/AST/Function_MASTER_CHANNEL" title="Function_MASTER_CHANNEL">MASTER_CHANNEL</a> function to access a SIP channel's SIP_CAUSE, as well as extends similar functionality to a variety of other channel drivers.</p>
<h2><a name="HangupCause-DialplanFunctionsandApplications"></a>Dialplan Functions and Applications</h2>
<h3><a name="HangupCause-HANGUPCAUSEKEYSAsterisk11FunctionHANGUPCAUSEKEYS"></a><a href="/wiki/pages/createpage.action?spaceKey=AST&title=Asterisk%2B11%2BFunction_HANGUPCAUSE_KEYS&linkCreation=true&fromPageId=20189310" class="createlink">HANGUPCAUSE_KEYS</a></h3>
<p>Used to obtain a comma separated list of all channels for which hangup causes are available.</p>
<h4><a name="HangupCause-Example"></a>Example</h4>
<p>The following example shows one way of accessing the channels that have hangup cause related information after a Dial has completed. In this particular example, a parallel dial occurs to both SIP/foo and SIP/bar. A @@@ TODO: link @@@ hangup handler has been attached to the calling channel, which executes the subroutine at handler,s,1 when the channel is hung up. This queries the HANGUPCAUSE_KEYS function for the channels with hangup cause information and prints the information as a Verbose message. On the CLI, this would look something like:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">Channels with hangup cause information: SIP/bar-00000002,SIP/foo-00000001</pre>
</div></div>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">[default]
exten => s,1,NoOp()
same => n,Set(CHANNEL(hangup_handler_push)=handler,s,1)
same => n,Dial(SIP/foo&SIP/bar,10)
same => n,Hangup()
[handler]
same => s,1,NoOp()
same => n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_KEYS()})
same => n,Verbose(0, Channels with hangup cause information: ${HANGUPCAUSE_STRING})
same => n,Return()</pre>
</div></div>
<h3><a name="HangupCause-HANGUPCAUSEAsterisk11FunctionHANGUPCAUSE"></a><a href="/wiki/pages/createpage.action?spaceKey=AST&title=Asterisk%2B11%2BFunction_HANGUPCAUSE&linkCreation=true&fromPageId=20189310" class="createlink">HANGUPCAUSE</a></h3>
<p>Used to obtain hangup cause information for a specific channel. For a given channel, there are two sources of hangup cause information:</p>
<ol>
        <li>The channel technology specific hangup cause information</li>
        <li>The Asterisk hangup cause</li>
</ol>
<p>Asterisk hangup causes can be found at @@@ TODO: LINK TO TABLE @@@.</p>
<p>Note that in some cases, the hangup causes returned may not be reflected in @@@@ LINK TO TABLE @@@. For example, if a Dial to a SIP UA is cancelled by Asterisk, the SIP UA may not have returned any final responses to Asterisk. In these cases, the last known technology code will be returned by the function.</p>
<h4><a name="HangupCause-Example"></a>Example</h4>
<p>This example illustrates obtaining hangup cause information for a parallel dial to SIP/foo and SIP/bar. A @@@ TODO: link @@@ hangup handler has been attached to the calling channel, which executes the subroutine at handler,s,1 when the channel is hung up. This queries the hangup cause information using the HANGUPCAUSE_KEYS function and the HANGUPCAUSE function. The channels returned from HANGUPCAUSE_KEYS are parsed out, and each is queried for their hangup cause information. The technology specific cause code as well as the Asterisk cause code are printed to the CLI.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">[default]
exten => s,1,NoOp()
same => n,Set(CHANNEL(hangup_handler_push)=handler,s,1)
same => n,Dial(SIP/foo&SIP/bar,10)
same => n,Hangup()
[handler]
exten => s,1,NoOp()
same => n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_KEYS()})
; start loop
same => n(hu_begin),NoOp()
; check exit condition (no more array to check)
same => n,GotoIf($[${LEN(${HANGUPCAUSE_STRING})}=0]?hu_exit)
; pull the next item
same => n,Set(ARRAY(item)=${HANGUPCAUSE_STRING})
same => n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_STRING:${LEN(${item})}})
; display the channel name and cause codes
same => n,Verbose(0, Got Channel ID ${item} with Technology Cause Code ${HANGUPCAUSE(${item},tech)}, Asterisk Cause Code ${HANGUPCAUSE(${item},ast)})
; check exit condition (no more array to check)
same => n,GotoIf($[${LEN(${HANGUPCAUSE_STRING})}=0]?hu_exit)
; we still have entries to process, so strip the leading comma
same => n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_STRING:1})
; go back to the beginning of the loop
same => n,Goto(hu_begin)
same => n(hu_exit),NoOp()
same => n,Return()
same => n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_STRING:1})
same => n,Goto(hu_begin)
same => n(hu_exit),NoOp()
same => n,Return()</pre>
</div></div>
<h3><a name="HangupCause-HangupCauseClearAsterisk11ApplicationHangupCauseClear"></a><a href="/wiki/pages/createpage.action?spaceKey=AST&title=Asterisk%2B11%2BApplication_HangupCauseClear&linkCreation=true&fromPageId=20189310" class="createlink">HangupCauseClear</a></h3>
<p>Used to remove all hangup cause information currently stored.</p>
<h4><a name="HangupCause-Example"></a>Example</h4>
<p>The following example clears the hangup cause information from the channel if SIP/foo fails to answer and the Dial continues in the dialplan. The hangup handler attached to the channel will thus only report the the name of the last channel dialed.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">exten => s,1,NoOp()
same => n,Set(CHANNEL(hangup_handler_push)=handler,s,1)
same => n,Dial(SIP/foo,10)
same => n,HangupCauseClear()
same => n,Dial(SIP/bar,10)
same => n,Hangup()
[handler]
same => s,1,NoOp()
same => n,Set(HANGUPCAUSE_STRING=${HANGUPCAUSE_KEYS()})
same => n,Verbose(0, Channels with hangup cause information: ${HANGUPCAUSE_STRING})
same => n,Return()</pre>
</div></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/display/AST/Hangup+Cause">View Online</a>
|
<a href="https://wiki.asterisk.org/wiki/display/AST/Hangup+Cause?showComments=true&showCommentArea=true#addcomment">Add Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>