<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Moy Blog &#187; voip</title>
	<atom:link href="http://www.moythreads.com/wordpress/category/voip/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.moythreads.com/wordpress</link>
	<description>Abandon All Hope, Ye Who Read This Blog</description>
	<lastBuildDate>Sat, 26 Dec 2009 06:38:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Sangoma Tapping solution for Asterisk</title>
		<link>http://www.moythreads.com/wordpress/2009/09/26/sangoma-tapping-solution-for-asterisk/</link>
		<comments>http://www.moythreads.com/wordpress/2009/09/26/sangoma-tapping-solution-for-asterisk/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 02:49:22 +0000</pubDate>
		<dc:creator>moy</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[sangoma]]></category>

		<guid isPermaLink="false">http://www.moythreads.com/wordpress/?p=68</guid>
		<description><![CDATA[Sangoma has offered a tapping device for T1/E1 lines for quite some time now. This physical tapping works by installing a PN 633 Tap Connection Adapter, which looks like this:
 
As you can see, you will receive the line from the CPE and plug it into the PN 633 and then plug the line from [...]]]></description>
			<content:encoded><![CDATA[<p>Sangoma has offered a <a href="http://en.wikipedia.org/wiki/Telephone_tapping" target="_blank">tapping</a> device for <a href="http://en.wikipedia.org/wiki/T-carrier" target="_blank">T1</a>/<a href="http://en.wikipedia.org/wiki/E-carrier" target="_blank">E1</a> lines for quite some time now. This physical tapping works by installing a PN 633 Tap Connection Adapter, which looks like this:</p>
<p> <img src="http://www.moythreads.com/moythreads_images/tapping/open_tap2.jpg" alt="Sangoma Tapping" /></p>
<p>As you can see, you will receive the line from the CPE and plug it into the PN 633 and then plug the line from the NET too. At the other side of the adapter you can pull out 2 cables and connect them to your box with Sangoma boards specially configured in <a href="http://en.wikipedia.org/wiki/High_impedance" target="_blank">high impedance mode</a>, which basically means will be passive and not affect the behavior of your PRI link, passively will be monitoring the E1/T1 link. </p>
<p>As you can tell from the image, there is also 2 cables involved for a single link, this means that you need an A102 card to monitor just 1 E1/T1 link, because one port is used for tx from the <a href="http://en.wikipedia.org/wiki/Customer-premises_equipment" target="_blank">CPE</a> and the other for tx from the <a href="http://en.wikipedia.org/wiki/Telephone_company" target="_blank">NET</a>. Until today, it was not possible to use <a href="http://www.asterisk.org/" target="_blank">Asterisk</a> because Asterisk assumes each card port is meant to send and receive data for a circuit, Asterisk was meant to be an active component of the circuit, not a passive element.</p>
<p>Now Asterisk can do that. I just submitted 2 patches to Digium&#8217;s bug tracker. One for LibPRI, the library that takes care of the <a href="http://en.wikipedia.org/wiki/Link_Access_Procedures,_D_channel" target="_blank">Q921</a> and <a href="http://en.wikipedia.org/wiki/Q.931" target="_blank">Q931</a> signaling and the other for chan_dahdi.c, the Asterisk channel driver used to connect it to PSTN circuits.</p>
<p>LibPRI needed to be modified because it does a lot of state machine checking when receiving a Q921/Q931 frame, for example, if receives a Q931 message &#8220;PROCEEDING&#8221;, is going to check that a call was already in place and a SETUP message was previously sent, when working as a passive element in the circuit no state checks should be done, we just need to decode the message and return a meaningful telephony event to Asterisk (like a RING event when the SETUP message is seen on the line).</p>
<p><a href="https://issues.asterisk.org/view.php?id=15970" target="_blank">https://issues.asterisk.org/view.php?id=15970</a></p>
<p>The most important change is this:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">pri_event <span style="color: #339933;">*</span>pri_read_event<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> pri <span style="color: #339933;">*</span>pri<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        <span style="color: #993333;">char</span> buf<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1024</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> res<span style="color: #339933;">;</span>
        res <span style="color: #339933;">=</span> pri<span style="color: #339933;">-&gt;</span>read_func <span style="color: #339933;">?</span> pri<span style="color: #339933;">-&gt;</span>read_func<span style="color: #009900;">&#40;</span>pri<span style="color: #339933;">,</span> buf<span style="color: #339933;">,</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>buf<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #808080; font-style: italic;">/* this check should be at some routine in q921.c */</span>
        <span style="color: #808080; font-style: italic;">/* at least 4 bytes of Q921 and at check buf[4] for Q931 Network packet */</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>res <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">5</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span>buf<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000dd;">8</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        res <span style="color: #339933;">=</span> q931_read_event<span style="color: #009900;">&#40;</span>pri<span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>q931_h<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>buf <span style="color: #339933;">+</span> <span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> res <span style="color: #339933;">-</span> <span style="color: #0000dd;">4</span> <span style="color: #339933;">-</span> <span style="color: #0000dd;">2</span> <span style="color: #808080; font-style: italic;">/* remove 4 bytes of Q921 h and 2 of CRC */</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>res <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>res <span style="color: #339933;">&amp;</span> Q931_RES_HAVEEVENT<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #339933;">&amp;</span>pri<span style="color: #339933;">-&gt;</span>ev<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* here we trust receiving q931 only (no maintenance or anything else)*/</span>
<span style="color: #993333;">int</span> q931_read_event<span style="color: #009900;">&#40;</span><span style="color: #993333;">struct</span> pri <span style="color: #339933;">*</span>ctrl<span style="color: #339933;">,</span> q931_h <span style="color: #339933;">*</span>h<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> len<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
        q931_mh <span style="color: #339933;">*</span>mh<span style="color: #339933;">;</span>
        q931_call <span style="color: #339933;">*</span>c<span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> cref<span style="color: #339933;">;</span>
        <span style="color: #993333;">int</span> missingmand<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//q931_dump(ctrl, h, len, 0);</span>
&nbsp;
        mh <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>q931_mh <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>h<span style="color: #339933;">-&gt;</span>contents <span style="color: #339933;">+</span> h<span style="color: #339933;">-&gt;</span>crlen<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        cref <span style="color: #339933;">=</span> q931_cr<span style="color: #009900;">&#40;</span>h<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        c <span style="color: #339933;">=</span> q931_getcall<span style="color: #009900;">&#40;</span>ctrl<span style="color: #339933;">,</span> cref <span style="color: #339933;">&amp;</span> <span style="color: #208080;">0x7FFF</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>c<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                pri_error<span style="color: #009900;">&#40;</span>ctrl<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Unable to locate call %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> cref<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>prepare_to_handle_q931_message<span style="color: #009900;">&#40;</span>ctrl<span style="color: #339933;">,</span> mh<span style="color: #339933;">,</span> c<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        missingmand <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>q931_process_ies<span style="color: #009900;">&#40;</span>ctrl<span style="color: #339933;">,</span> h<span style="color: #339933;">,</span> len<span style="color: #339933;">,</span> mh<span style="color: #339933;">,</span> c<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>missingmand<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> post_handle_q931_message<span style="color: #009900;">&#40;</span>ctrl<span style="color: #339933;">,</span> mh<span style="color: #339933;">,</span> c<span style="color: #339933;">,</span> missingmand<span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The rest is pretty much just modify post_handle_q931_message to skip state machine checking when invoked with the last parameter as 0, which is only done from q931_read_event, that is the passive q931 processing routine I added.</p>
<p>Asterisk needed to be modified because it needs to correlate that a RING event received, let&#8217;s say in span 1 and channel 1, is probably going to be related to a PROGRESS message in span 2 channel 1 (which is the other side of the connection replying to the SETUP Q931 message). Furthermore, once the PROGRESS message is received, Asterisk must launch a regular channel and then create a DAHDI conference (using DAHDI pseudo channels) to mix the audio transmitted by the CPE and NET and return this mixed audio as a single frame to any Asterisk application reading from the channel.</p>
<p><a href="https://issues.asterisk.org/view.php?id=15971" target="_blank">https://issues.asterisk.org/view.php?id=15971</a></p>
<p>Some interesting code snippet of the changes to Asterisk is where I create the DAHDI conference to do the audio mixing, which is later retrieved by the core via the channel driver interface interface dahdi_read().</p>
<p>This is done during dahdi_new() routine, when creating the new Asterisk channel.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">-&gt;</span>tappingpeer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #993333;">struct</span> dahdi_confinfo dahdic <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
                <span style="color: #808080; font-style: italic;">/* create the mixing conference
                 * some DAHDI_SETCONF interface rules to keep in mind
                 * confno == -1 means create new conference with the given confmode
                 * confno and confmode == 0 means remove the channel from its conference */</span>
                dahdic.<span style="color: #202020;">chan</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* means use current channel (the one the fd belongs to)*/</span>
                dahdic.<span style="color: #202020;">confno</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* -1 means create new conference */</span>
                dahdic.<span style="color: #202020;">confmode</span> <span style="color: #339933;">=</span> DAHDI_CONF_CONFMON <span style="color: #339933;">|</span> DAHDI_CONF_LISTENER <span style="color: #339933;">|</span> DAHDI_CONF_PSEUDO_LISTENER<span style="color: #339933;">;</span>
                fd <span style="color: #339933;">=</span> dahdi_open<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/dev/dahdi/pseudo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>fd <span style="color: #339933;">&lt;</span> <span style="color: #0000dd;">0</span> <span style="color: #339933;">||</span> ioctl<span style="color: #009900;">&#40;</span>fd<span style="color: #339933;">,</span> DAHDI_SETCONF<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>dahdic<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        ast_log<span style="color: #009900;">&#40;</span>LOG_ERROR<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Unable to create dahdi conference for tapping<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        ast_hangup<span style="color: #009900;">&#40;</span>tmp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        i<span style="color: #339933;">-&gt;</span>owner <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                i<span style="color: #339933;">-&gt;</span>tappingconf <span style="color: #339933;">=</span> dahdic.<span style="color: #202020;">confno</span><span style="color: #339933;">;</span>
                i<span style="color: #339933;">-&gt;</span>tappingfd <span style="color: #339933;">=</span> fd<span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #808080; font-style: italic;">/* add both parties to the conference */</span>
                dahdic.<span style="color: #202020;">chan</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
                dahdic.<span style="color: #202020;">confno</span> <span style="color: #339933;">=</span> i<span style="color: #339933;">-&gt;</span>tappingconf<span style="color: #339933;">;</span>
                dahdic.<span style="color: #202020;">confmode</span> <span style="color: #339933;">=</span> DAHDI_CONF_CONF <span style="color: #339933;">|</span> DAHDI_CONF_TALKER<span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ioctl<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">-&gt;</span>subs<span style="color: #009900;">&#91;</span>SUB_REAL<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">dfd</span><span style="color: #339933;">,</span> DAHDI_SETCONF<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>dahdic<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        ast_log<span style="color: #009900;">&#40;</span>LOG_ERROR<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Unable to add chan to conference for tapping devices: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> strerror<span style="color: #009900;">&#40;</span>errno<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        ast_hangup<span style="color: #009900;">&#40;</span>tmp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        i<span style="color: #339933;">-&gt;</span>owner <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                dahdic.<span style="color: #202020;">chan</span> <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
                dahdic.<span style="color: #202020;">confno</span> <span style="color: #339933;">=</span> i<span style="color: #339933;">-&gt;</span>tappingconf<span style="color: #339933;">;</span>
                dahdic.<span style="color: #202020;">confmode</span> <span style="color: #339933;">=</span> DAHDI_CONF_CONF <span style="color: #339933;">|</span> DAHDI_CONF_TALKER<span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ioctl<span style="color: #009900;">&#40;</span>i<span style="color: #339933;">-&gt;</span>tappingpeer<span style="color: #339933;">-&gt;</span>subs<span style="color: #009900;">&#91;</span>SUB_REAL<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">dfd</span><span style="color: #339933;">,</span> DAHDI_SETCONF<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>dahdic<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        ast_log<span style="color: #009900;">&#40;</span>LOG_ERROR<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Unable to add peer chan to conference for tapping devices: %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> strerror<span style="color: #009900;">&#40;</span>errno<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        ast_hangup<span style="color: #009900;">&#40;</span>tmp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        i<span style="color: #339933;">-&gt;</span>owner <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
                        <span style="color: #b1b100;">return</span> NULL<span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                ast_log<span style="color: #009900;">&#40;</span>LOG_DEBUG<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Created tapping conference %d with fd %d between dahdi chans %d and %d for ast channel %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>
                                i<span style="color: #339933;">-&gt;</span>tappingconf<span style="color: #339933;">,</span>
                                i<span style="color: #339933;">-&gt;</span>tappingfd<span style="color: #339933;">,</span>
                                i<span style="color: #339933;">-&gt;</span>channel<span style="color: #339933;">,</span>
                                i<span style="color: #339933;">-&gt;</span>tappingpeer<span style="color: #339933;">-&gt;</span>channel<span style="color: #339933;">,</span>
                                tmp<span style="color: #339933;">-&gt;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                i<span style="color: #339933;">-&gt;</span>tappingpeer<span style="color: #339933;">-&gt;</span>owner <span style="color: #339933;">=</span> i<span style="color: #339933;">-&gt;</span>owner<span style="color: #339933;">;</span>
       <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Later we sent the Asterisk channel to the dial plan.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">                <span style="color: #808080; font-style: italic;">/* from now on, reading from the conference has the mix of both tapped channels, we can now launch the pbx thread */</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>ast_pbx_start<span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> AST_PBX_SUCCESS<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        ast_log<span style="color: #009900;">&#40;</span>LOG_ERROR<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Failed to launch PBX thread for passive channel %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> c<span style="color: #339933;">-&gt;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        ast_hangup<span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span></pre></div></div>

<p>And finally when the Asterisk core requests a frame from chan_dahdi we return the mixed audio.</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">       <span style="color: #808080; font-style: italic;">/* if we have a tap peer we must read the mixed audio */</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>p<span style="color: #339933;">-&gt;</span>tappingpeer<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #808080; font-style: italic;">/* passive channel reading */</span>
                <span style="color: #808080; font-style: italic;">/* first read from the 2 involved dahdi channels just to consume their frames */</span>
                res <span style="color: #339933;">=</span> read<span style="color: #009900;">&#40;</span>p<span style="color: #339933;">-&gt;</span>subs<span style="color: #009900;">&#91;</span>idx<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">dfd</span><span style="color: #339933;">,</span> readbuf<span style="color: #339933;">,</span> p<span style="color: #339933;">-&gt;</span>subs<span style="color: #009900;">&#91;</span>idx<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">linear</span> <span style="color: #339933;">?</span> READ_SIZE <span style="color: #339933;">*</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">:</span> READ_SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                CHECK_READ_RESULT<span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                res <span style="color: #339933;">=</span> read<span style="color: #009900;">&#40;</span>p<span style="color: #339933;">-&gt;</span>tappingpeer<span style="color: #339933;">-&gt;</span>subs<span style="color: #009900;">&#91;</span>idx<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">dfd</span><span style="color: #339933;">,</span> readbuf<span style="color: #339933;">,</span> p<span style="color: #339933;">-&gt;</span>subs<span style="color: #009900;">&#91;</span>idx<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">linear</span> <span style="color: #339933;">?</span> READ_SIZE <span style="color: #339933;">*</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">:</span> READ_SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                CHECK_READ_RESULT<span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #808080; font-style: italic;">/* now read the mixed audio that will be returned to the core */</span>
                res <span style="color: #339933;">=</span> read<span style="color: #009900;">&#40;</span>p<span style="color: #339933;">-&gt;</span>tappingfd<span style="color: #339933;">,</span> readbuf<span style="color: #339933;">,</span> p<span style="color: #339933;">-&gt;</span>subs<span style="color: #009900;">&#91;</span>idx<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">linear</span> <span style="color: #339933;">?</span> READ_SIZE <span style="color: #339933;">*</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">:</span> READ_SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #808080; font-style: italic;">/* no tapping peer, normal reading */</span>
                res <span style="color: #339933;">=</span> read<span style="color: #009900;">&#40;</span>p<span style="color: #339933;">-&gt;</span>subs<span style="color: #009900;">&#91;</span>idx<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">dfd</span><span style="color: #339933;">,</span> readbuf<span style="color: #339933;">,</span> p<span style="color: #339933;">-&gt;</span>subs<span style="color: #009900;">&#91;</span>idx<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">linear</span> <span style="color: #339933;">?</span> READ_SIZE <span style="color: #339933;">*</span> <span style="color: #0000dd;">2</span> <span style="color: #339933;">:</span> READ_SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Finally, you can use regular dial plan Asterisk rules to <a href="http://www.voip-info.org/wiki/index.php?page=Asterisk+cmd+Record" target="_blank">Record()</a> the conversation, <a href="http://www.voip-info.org/wiki/view/Asterisk+cmd+Dial" target="_blank">Dial()</a> to someone interested in auditing the call etc. Of course, any audio transmitted to this passive channel will be dropped, therefore using applications like Playback() in this channels just don&#8217;t make sense, you can still do it though, but all the audio will be silently dropped. Also remember this is a regular channel (that just happens to ignore any transmitted media or signaling), therefore you can still retrieve the ANI, DNID etc.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>from-pstn<span style="color: #7a0874; font-weight: bold;">&#93;</span>
exten =<span style="color: #000000; font-weight: bold;">&gt;</span> s,<span style="color: #000000;">1</span>,Answer<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
;exten =<span style="color: #000000; font-weight: bold;">&gt;</span> s,n,Dial<span style="color: #7a0874; font-weight: bold;">&#40;</span>SIP<span style="color: #000000; font-weight: bold;">/</span>moy<span style="color: #7a0874; font-weight: bold;">&#41;</span>
exten =<span style="color: #000000; font-weight: bold;">&gt;</span> s,n,Record<span style="color: #7a0874; font-weight: bold;">&#40;</span>advanced-recording<span style="color: #000000; font-weight: bold;">%</span>d:wav<span style="color: #7a0874; font-weight: bold;">&#41;</span>
exten =<span style="color: #000000; font-weight: bold;">&gt;</span> s,n,Hangup<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
exten =<span style="color: #000000; font-weight: bold;">&gt;</span> _X.,<span style="color: #000000;">1</span>,Goto<span style="color: #7a0874; font-weight: bold;">&#40;</span>s,<span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>The configuration required is minimal. Sangoma board configuration is <a href="http://wiki.sangoma.com/sangoma-tap-system" target="_blank">described here</a>. It&#8217;s not much different than configuring a regular T1/E1 link though. In the Asterisk side, you just have to specify the parameter &#8220;tappingpeerpos=next&#8221; or &#8220;tappingpeerpos=prev&#8221; in chan_dahdi.conf to specify which is the peer tapping span for the current span. If you set &#8220;tappingpeerpos=no&#8221; or any other value for that matter, tapping will be disabled for that span (and then will be a regular active span). </p>
<p>I have the code already in 3 branches. One branch for libpri and 2 branches for Asterisk, one based on trunk and the other in Asterisk 1.6.2, keep in mind that the one from 1.6.2 has a slightly different configuration at this point, the parameter to enable tapping is &#8220;passive=yes&#8221;, this does not let you specify if the peer tapping device is the next or previous one, therefore assumes your tapping spans always start at an even number (0, 2, 4 etc), I will change that soon, hopefully &#8230;</p>
<p><a href="http://svn.digium.com/svn/asterisk/team/moy/dahdi-tap-trunk" target="_blank">http://svn.digium.com/svn/asterisk/team/moy/dahdi-tap-trunk</a><br />
<a href="http://svn.digium.com/svn/asterisk/team/moy/dahdi-tap-1.6.2" target="_blank">http://svn.digium.com/svn/asterisk/team/moy/dahdi-tap-1.6.2</a><br />
<a href="http://svn.digium.com/svn/libpri/team/moy/tap-1.4" target="_blank">http://svn.digium.com/svn/libpri/team/moy/tap-1.4</a></p>
<p>Now everytime a new call is detected you will receive a call that you can send wherever you want <img src='http://www.moythreads.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moythreads.com/wordpress/2009/09/26/sangoma-tapping-solution-for-asterisk/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>OpenR2 and OpenZap now integrated &#8211; MFCR2 support for FreeSWITCH</title>
		<link>http://www.moythreads.com/wordpress/2009/08/21/openr2-and-openzap-now-integrated-mfcr2-support-for-freeswitch/</link>
		<comments>http://www.moythreads.com/wordpress/2009/08/21/openr2-and-openzap-now-integrated-mfcr2-support-for-freeswitch/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 22:20:30 +0000</pubDate>
		<dc:creator>moy</dc:creator>
				<category><![CDATA[freeswitch]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[openr2]]></category>

		<guid isPermaLink="false">http://www.moythreads.com/wordpress/2009/08/21/openr2-and-openzap-now-integrated-mfcr2-support-for-freeswitch/</guid>
		<description><![CDATA[After putting this off by several weeks, I finally spent some quality time working in getting to work OpenZAP with OpenR2. The result is now available in the openzap project svn trunk:
http://svn.openzap.org/svn/openzap/trunk/
I also created some basic documentation about how to set it up: http://wiki.freeswitch.org/wiki/OpenZAP_OpenR2
This means that from now on FreeSWITCH will support MFC-R2 signaling with [...]]]></description>
			<content:encoded><![CDATA[<p>After putting this off by several weeks, I finally spent some quality time working in getting to work OpenZAP with OpenR2. The result is now available in the openzap project svn trunk:</p>
<p><a href="http://svn.openzap.org/svn/openzap/trunk/" target="_blank">http://svn.openzap.org/svn/openzap/trunk/</a></p>
<p>I also created some basic documentation about how to set it up: <a href="http://wiki.freeswitch.org/wiki/OpenZAP_OpenR2" target="_blank">http://wiki.freeswitch.org/wiki/OpenZAP_OpenR2</a></p>
<p>This means that from now on FreeSWITCH will support MFC-R2 signaling with the same stack that Asterisk is using since 1.6.2</p>
<p>I still need to do some work on the documentation and lots of stress testing, but you can start playing with it and bugging me if it does not work <img src='http://www.moythreads.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.moythreads.com/wordpress/2009/08/21/openr2-and-openzap-now-integrated-mfcr2-support-for-freeswitch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Back from ClueCon 2009 in Chicago</title>
		<link>http://www.moythreads.com/wordpress/2009/08/09/back-from-cluecon-2009-in-chicago/</link>
		<comments>http://www.moythreads.com/wordpress/2009/08/09/back-from-cluecon-2009-in-chicago/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 19:36:24 +0000</pubDate>
		<dc:creator>moy</dc:creator>
				<category><![CDATA[freeswitch]]></category>
		<category><![CDATA[sangoma]]></category>
		<category><![CDATA[voip]]></category>

		<guid isPermaLink="false">http://www.moythreads.com/wordpress/2009/08/09/back-from-cluecon-2009-in-chicago/</guid>
		<description><![CDATA[I attended ClueCon 2009 in Chicago the past week to present &#8220;FreeSWITCH modules for Asterisk Developers&#8221;, where I discussed FreeSWITCH internals and interfaces from an Asterisk developer point of view (particularly my point of view).
The power point presentation can be found here:  FreeSWITCH modules for Asterisk Developers

The presentation will show you the key internal [...]]]></description>
			<content:encoded><![CDATA[<p>I attended ClueCon 2009 in Chicago the past week to present &#8220;FreeSWITCH modules for Asterisk Developers&#8221;, where I discussed FreeSWITCH internals and interfaces from an Asterisk developer point of view (particularly my point of view).</p>
<p>The power point presentation can be found here:  <a href="http://www.moythreads.com/congresos/cluecon2009/freeswitch_modules_for_asterisk_devs.ppt" target="_blank">FreeSWITCH modules for Asterisk Developers</a></p>
<p><img src="http://www.moythreads.com/chicago.jpg" alt="Chicago" /></p>
<p>The presentation will show you the key internal data structures and call flow when making a two-leg call in FreeSWITCH and Asterisk between SIP and PRI protocols. And of course, how to write modules for both telephony engines.</p>
<p>After the talk some people approached me to ask some particular questions, it seems the interest in creating FreeSWITCH modules and applications on top of it is increasing, it&#8217;s definitely going to be interesting what happens in the next years, the future of FreeSWITCH really looks promising.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moythreads.com/wordpress/2009/08/09/back-from-cluecon-2009-in-chicago/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>About the Asterisk development model</title>
		<link>http://www.moythreads.com/wordpress/2009/06/02/about-the-asterisk-development-model/</link>
		<comments>http://www.moythreads.com/wordpress/2009/06/02/about-the-asterisk-development-model/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 16:57:49 +0000</pubDate>
		<dc:creator>moy</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[freeswitch]]></category>

		<guid isPermaLink="false">http://www.moythreads.com/wordpress/2009/06/02/about-the-asterisk-development-model/</guid>
		<description><![CDATA[This post is my opinion regarding to 
http://lists.digium.com/pipermail/asterisk-dev/2009-March/037262.html (English)
http://www.saghul.net/blog/2009/03/18/sobre-el-modelo-de-desarrollo-de-asterisk/ (Spanish)
For those not involved in the Asterisk users and/or developers community, it all comes down to users complaining about Asterisk reliability and the new  (1.6) development model that will allow new features to be introduced in dot releases which (they say) will make it worst. [...]]]></description>
			<content:encoded><![CDATA[<p>This post is my opinion regarding to </p>
<p><a href="http://lists.digium.com/pipermail/asterisk-dev/2009-March/037262.html" target="_blank">http://lists.digium.com/pipermail/asterisk-dev/2009-March/037262.html</a> (English)</p>
<p><a href="http://www.saghul.net/blog/2009/03/18/sobre-el-modelo-de-desarrollo-de-asterisk/" target="_blank">http://www.saghul.net/blog/2009/03/18/sobre-el-modelo-de-desarrollo-de-asterisk/</a> (Spanish)</p>
<p>For those not involved in the Asterisk users and/or developers community, it all comes down to users complaining about Asterisk reliability and the new  (1.6) development model that will allow new features to be introduced in dot releases which (they say) will make it worst. Telephony systems are damn critical. Users are used to see their computer crash (yeah, even Linux users, not that often but it happens). But telephony lines are very reliable circuits (basically because they&#8217;re very simple in nature and have been around a long time). Asterisk started a revolution and I don&#8217;t think anyone can deny that, it has brought a lot of flexibility to telephony systems, but that revolution comes of course with a cost. </p>
<p>I started playing with Asterisk at the beginning of 2004, I&#8217;ve seen segfaults, deadlocks and all kind of funny behaviours here and there. Sometimes a brand new release of Asterisk has basic functionality broken (like originate calls from the manager). That&#8217;s true as well, it can be said that Asterisk, out of the box, is not reliable (scalability is another beast I don&#8217;t want to talk about now), and naturally users don&#8217;t like that.</p>
<p>Having said that, I need to clarify what I mean by &#8220;reliable&#8221;. In this context, by reliable I mean, if you take 1.4.N release, deploy applications on top of it and then you blindly upgrade from 1.4.N to 1.4.(N+1) WITHOUT TESTING and put it in production expecting it to just work, well, good luck with that, and enjoy your new job flipping burgers at McDonalds. That is, Asterisk is not reliable for users who are not willing to put some effort when upgrading. Asterisk is a complex beast (and built on top of somewhat still shaky core), the Asterisk developers had been doing a great job improving the core, however, nasty hacks like <a href="http://www.moythreads.com/wordpress/2006/09/01/asterisk-masquerade/" target="_blank">masquerade</a> are still there.</p>
<p>I don&#8217;t have problems with Asterisk being criticized, that&#8217;s what it will make it better in the end. I do have a problem though with all that people that are nothing but leeches of the community. Here is the kind of user I have a problem with:</p>
<p>1. They typically just ask questions in the mailing list, never spend time helping other users.<br />
2. They download for free Asterisk and expect it to work out-of-the-box for their particular (profit) purpose without spending time not even doing their homework, testing their particular scenarios etc.<br />
3. They bitch about Digium not fixing bugs in the bug-tracker, bugs that according to them are so damn critical to their business that they not even put a bounty on the voip-info wiki or in the asterisk-biz mailing list for someone to fix it.<br />
4. They do not download beta releases or release candidates, they just wait for the &#8220;stable&#8221; release and again, expect things to magically work for them to profit.</p>
<p>In short, they don&#8217;t want to spend a single cent, nor spend some time out of their busy life, all they expect is their life to be free of problems and cash big bucks. One common argument for these users is that they are not developers and cannot help, that&#8217;s just bs, there is other ways to help and in the end you can always spend some of your free-asterisk-based business revenue to place bounties for the development of test beds or whatever you feel is needed to improve Asterisk.</p>
<p>At the end, I agree Asterisk development has to improve. But Digium does not has unlimited resources, and is already paying for a big team of development creating Asterisk and you can download it for free. Being free is not an excuse for lacking quality, but just think, there is limited resources and Digium is allocating those resources where it makes sense for its business. Type &#8220;core show warranty&#8221; in your Asterisk CLI and tell me what your warranty is.</p>
<p>In the other hand, those leech-users should know that not only users, but also some developers are unhappy with the development model (but different arguments than leech-users had). That&#8217;s why <a href="http://www.callweaver.org/" target="_blank">CallWeaver</a> was born, and not only that. The biggest example I like to use of one of the foundations of open source (if you don&#8217;t like it, then fix it) is the <a href="http://www.freeswitch.org/" target="_blank">FreeSwitch</a> project. </p>
<p>The <a href="http://www.freeswitch.org/" target="_blank">FreeSwitch</a> project was born out of the discontent (to put it nicely) of one of the top developers of Asterisk: Anthony Minessale II, he complains a lot about Asterisk, yeah, but he also did a lot more for Asterisk than anyone else I know of beyond Mark himself and just a couple of the top developers of Asterisk. So, yes, from my perspective in some way he has earned the right to talk shit about Asterisk, because he knows it, he has proposed solutions and he has actually brought solutions: <a href="http://www.freeswitch.org/" target="_blank">FreeSwitch</a>. FreeSwitch has brought some serious competition to Asterisk (sorry, but let&#8217;s be serious, CallWeaver and Yate had never been close to match Asterisk functionality and usage, let alone GNU Bayonne).</p>
<p>FreeSwitch, from my perspective has solved many of the core problems that Asterisk has, it also solves the licensing issues (it&#8217;s MPL) and it&#8217;s developer friendly (since there is no business driving force yet behind it and you can get an svn branch right away). Probably FreeSwitch is not a short-term solution for those who are already hooked into Asterisk business, but in any case, at this point I don&#8217;t think there is short-term solutions for the problems Asterisk users complain about, it&#8217;s gonna cost ya baby, one way or another, and from my perspective that is the way is supposed to be.</p>
<p>In the end, Olle Johansson did quite good being the first in reply to that post and resumed the situation, which is not simple, but one thing is for sure, the community has to stop bitching and start doing. Well, I really don&#8217;t care if you keep bitching as long as you fucking do something else to make the situation better.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moythreads.com/wordpress/2009/06/02/about-the-asterisk-development-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Manual de Asterisk</title>
		<link>http://www.moythreads.com/wordpress/2009/05/21/manual-de-asterisk/</link>
		<comments>http://www.moythreads.com/wordpress/2009/05/21/manual-de-asterisk/#comments</comments>
		<pubDate>Thu, 21 May 2009 19:11:14 +0000</pubDate>
		<dc:creator>moy</dc:creator>
				<category><![CDATA[asterisk]]></category>

		<guid isPermaLink="false">http://www.moythreads.com/wordpress/2009/05/21/manual-de-asterisk/</guid>
		<description><![CDATA[Solo quiero publicar un manual de Asterisk que escribi hace muchos aÃ±os, los conceptos siguen siendo los mismos y las configuraciones tambiÃ©n, tal vez uno que otro comando cambio de nombre. Habia perdido el manual pero recientemente alguien en el MSN me pregunto por el manual y luego lo encontramos en el blog de pablasso. [...]]]></description>
			<content:encoded><![CDATA[<p>Solo quiero publicar un manual de Asterisk que escribi hace muchos aÃ±os, los conceptos siguen siendo los mismos y las configuraciones tambiÃ©n, tal vez uno que otro comando cambio de nombre. Habia perdido el manual pero recientemente alguien en el MSN me pregunto por el manual y luego lo encontramos en el blog de <a href="http://www.pablasso.com/" target="_blank">pablasso</a>. Solo cambie el e-mail de contacto, asi que sigue siendo el mismo viejo manual, pero no del todo inÃºtil <img src='http://www.moythreads.com/wordpress/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p><a href="http://www.moythreads.com/manual_de_asterisk.pdf" target="_blank">Manual de Asterisk</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.moythreads.com/wordpress/2009/05/21/manual-de-asterisk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why does Asterisk consume 100% CPU?</title>
		<link>http://www.moythreads.com/wordpress/2009/05/06/why-does-asterisk-consume-100-cpu/</link>
		<comments>http://www.moythreads.com/wordpress/2009/05/06/why-does-asterisk-consume-100-cpu/#comments</comments>
		<pubDate>Wed, 06 May 2009 17:25:08 +0000</pubDate>
		<dc:creator>moy</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.moythreads.com/wordpress/2009/05/06/why-does-asterisk-consume-100-cpu/</guid>
		<description><![CDATA[I don&#8217;t know  
But people has asked me this a couple of times lately and my answer is always &#8220;I don&#8217;t know&#8221;. However ps can give you more information about it. In fact, this works for any application you have and you want to debug why is going crazy.
First, check which thread (Asterisk is [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know <img src='http://www.moythreads.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>But people has asked me this a couple of times lately and my answer is always &#8220;I don&#8217;t know&#8221;. However ps can give you more information about it. In fact, this works for any application you have and you want to debug why is going crazy.</p>
<p>First, check which thread (Asterisk is a multi threaded application) is going crazy.</p>
<p># ps -LlFm -p `pidof asterisk`</p>
<p>That should show you the % of CPU being used by each Asterisk thread in the column named &#8220;C&#8221;, then write down the LWP colum value for the thread you are interested on. (LWP is a light weight process number, roughly speaking, the thread id). Now that you have the thread id, you need to know what that thread is doing.</p>
<p># pstack `pidof asterisk` > /tmp/asterisk.stack.txt</p>
<p>That will cause the asterisk process to dump the stack state to the /tmp/asterisk.stack.txt file. If you don&#8217;t have the pstack command google for it, I think in CentOS is as easy as yum install pstack.</p>
<p>Then open the file and search for the LWP that you just wrote down. Hopefully you will find some hints that let you know how to avoid it or at least a lot more information to post in bugs.digium.com</p>
<p>UPDATE:<br />
One of the guys who asked this question later told me what he found:</p>
<p>Thread 10 (Thread 0&#215;41d8f940 (LWP 3406)):<br />
#0  0&#215;00000033ce2ca436 in poll () from /lib64/libc.so.6<br />
#1  0&#215;00000000004933c0 in ast_io_wait ()<br />
#2  0&#215;00002aaabd9510cd in network_thread ()<br />
#3  0&#215;00000000004f8b2c in dummy_start ()<br />
#4  0&#215;00000033cee06367 in start_thread () from /lib64/libpthread.so.0<br />
#5  0&#215;00000033ce2d2f7d in clone () from /lib64/libc.so.6 </p>
<p>A quick grep -rI &#8220;network_thread&#8221; in the Asterisk source code reveals this function belongs to chan_iax.c, disabling chan_iax.so in modules.conf is a good workaround to his problem, however further debugging would be needed to determine why the monitor thread is looping like that. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.moythreads.com/wordpress/2009/05/06/why-does-asterisk-consume-100-cpu/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Cluecon 2009</title>
		<link>http://www.moythreads.com/wordpress/2009/05/05/cluecon-2009/</link>
		<comments>http://www.moythreads.com/wordpress/2009/05/05/cluecon-2009/#comments</comments>
		<pubDate>Tue, 05 May 2009 21:40:09 +0000</pubDate>
		<dc:creator>moy</dc:creator>
				<category><![CDATA[freeswitch]]></category>
		<category><![CDATA[voip]]></category>

		<guid isPermaLink="false">http://www.moythreads.com/wordpress/2009/05/05/cluecon-2009/</guid>
		<description><![CDATA[I will be speaking at ClueCon this year. The talk will be about writing FreeSwitch modules and how the development process compares to writing modules for Asterisk in terms of APIs. If you are interested in learning how to write modules for Asterisk and/or Freeswitch, this is your chance!
The full schedule is still being prepared [...]]]></description>
			<content:encoded><![CDATA[<p>I will be speaking at ClueCon this year. The talk will be about writing <a href ="http://www.freeswitch.org/" target="_blank">FreeSwitch</a> modules and how the development process compares to writing modules for <a href="http://www.asterisk.org/" target="_blank">Asterisk</a> in terms of APIs. If you are interested in learning how to write modules for Asterisk and/or Freeswitch, this is your chance!</p>
<p>The full schedule is still being prepared so be sure to check the site later when it&#8217;s done.</p>
<p>I could not decide which banner to use here, so I decided to put 3 I really liked <img src='http://www.moythreads.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  &#8230; if you use any open source telephony application, support developers by attending or at least putting one of these banners on your site. </p>
<p><a href="http://www.cluecon.com/" target="_blank"><img src="http://files.freeswitch.org/cluecon_2009/image/CC_2009_Joinus.png"></a></p>
<p><a href="http://www.cluecon.com/" target="_blank"><img src="http://files.freeswitch.org/cluecon_2009/image/CC_2009_250x250.png"></a></p>
<p><a href="http://www.cluecon.com/" target="_blank"><img src="http://files.freeswitch.org/cluecon_2009/image/CC_2009_banner2.png"></a></p>
<p>From the ClueCon site:<br />
ClueCon &#8211; is an annual 3-Day Telephony User and Developer Conference bringing together the entire spectrum of Telephony from TDM circuits to VoIP and everything in between. The presentations and discussions will cover several open source telephony applications such as Asterisk/Callweaver, OpenSIPS/Kamailio (formerly OpenSER), Bayonne, YATE and FreeSWITCH. Other great projects that will be discussed include OPAL and Woomera.</p>
<p>More funny banners at: <a href="http://files.freeswitch.org/cluecon_2009/" target="_blank">http://files.freeswitch.org/cluecon_2009/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.moythreads.com/wordpress/2009/05/05/cluecon-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MFC-R2 support in Asterisk trunk</title>
		<link>http://www.moythreads.com/wordpress/2009/03/17/mfc-r2-support-in-asterisk-trunk/</link>
		<comments>http://www.moythreads.com/wordpress/2009/03/17/mfc-r2-support-in-asterisk-trunk/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 04:40:47 +0000</pubDate>
		<dc:creator>moy</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[openr2]]></category>

		<guid isPermaLink="false">http://www.moythreads.com/wordpress/2009/03/17/mfc-r2-support-in-asterisk-trunk/</guid>
		<description><![CDATA[I am glad to announce that MFC-R2 support has been merged into Asterisk trunk. Today I just got an e-mail from Russell, the team lead of the Asterisk development team confirming the merge and that the upcoming version Asterisk 1.6.2 will be the first one having built-in support for this signalling.
More details in the following [...]]]></description>
			<content:encoded><![CDATA[<p>I am glad to announce that MFC-R2 support has been merged into Asterisk trunk. Today I just got an e-mail from <a href="http://www.russellbryant.net/blog/" target="_blank">Russell</a>, the team lead of the Asterisk development team confirming the merge and that the upcoming version Asterisk 1.6.2 will be the first one having built-in support for this signalling.</p>
<p>More details in the following commit: <a href="http://lists.digium.com/pipermail/asterisk-commits/2009-March/031735.html" target="_blank">http://lists.digium.com/pipermail/asterisk-commits/2009-March/031735.html</a> </p>
<p>I want to thank all the people that supported the development of OpenR2 with code, testing and build infrastructure. Particularly thanks to:</p>
<p><a href="http://www.neocenter.com.mx/" target="_blank">Neocenter</a>, company located at MÃ©xico, Distrito Federal, that supported the development of OpenR2 from the very beginning, even when I myself was not even sure it could work. Thanks Octavio, Pop and Alejandro.</p>
<p><a href="http://www.sangoma.com/" target="_blank">Sangoma Technologies</a> For their sponsorship during all this time.</p>
<p><a href="http://www.digium.com/" target="_blank">Digium Inc</a> for creating Asterisk.</p>
<p><a href="http://blog.alexandrealencar.net/" target="_blank">Alexandre Alencar</a> for all his contributions to the project in different areas.</p>
<p>There is obviously more people that has contributed, you all know who you are <img src='http://www.moythreads.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.moythreads.com/wordpress/2009/03/17/mfc-r2-support-in-asterisk-trunk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>G729A and G723.1 support for FreeSwitch</title>
		<link>http://www.moythreads.com/wordpress/2009/02/08/g729a-and-g7231-support-for-freeswitch/</link>
		<comments>http://www.moythreads.com/wordpress/2009/02/08/g729a-and-g7231-support-for-freeswitch/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 07:36:16 +0000</pubDate>
		<dc:creator>moy</dc:creator>
				<category><![CDATA[freeswitch]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.moythreads.com/wordpress/2009/02/08/g729a-and-g7231-support-for-freeswitch/</guid>
		<description><![CDATA[
.comment { color: #999999; font-style: italic; }
.pre { color: #000099; }
.string { color: #009900; }
.char { color: #009900; }
.float { color: #996600; }
.int { color: #999900; }
.bool { color: #000000; font-weight: bold; }
.type { color: #FF6633; }
.flow { color: #FF0000; }
.keyword { color: #990000; }
.operator { color: #663300; font-weight: bold; }

The past weekend I spent [...]]]></description>
			<content:encoded><![CDATA[<style type="text/css">
.comment { color: #999999; font-style: italic; }
.pre { color: #000099; }
.string { color: #009900; }
.char { color: #009900; }
.float { color: #996600; }
.int { color: #999900; }
.bool { color: #000000; font-weight: bold; }
.type { color: #FF6633; }
.flow { color: #FF0000; }
.keyword { color: #990000; }
.operator { color: #663300; font-weight: bold; }
</style>
<p>The past weekend I spent some time writing a module for the <a href="http://www.freeswitch.org/" target="_blank">FreeSwitch</a> project in order to support the <a href="http://en.wikipedia.org/wiki/G.729a" target="_blank">G729A codec</a> in it. This codec is patent encumbered, however, my target was not to do this in software, but just create the software interface for FreeSwitch to talk with a PCI card manufactured by <a href="http://www.digium.com/">Digium</a> that does the transcoding for G729A and <a href="http://en.wikipedia.org/wiki/G.723.1" target="_blank">G723.1</a> .</p>
<p><a href="http://www.digium.com/en/products/voice/tc400b.php" target="_blank">This is the data sheet for the TC400B board.</a> The programming interfaces to access the encoders and decoders is not documented (or at least I could not find any documentation), but it&#8217;s enough to have available the source code for the module in <a href="http://www.asterisk.org/" target="_blank">Asterisk</a> that uses that very same board.</p>
<p>This board expose its available encoders to the <a href="http://www.voip-info.org/wiki/view/DAHDI" target="_blank">DAHDI</a> / <a href="http://www.voip-info.org/wiki/view/Zaptel" target="_blank">Zaptel</a> core driver, which in turn exposes all transcoders registered by the boards through the Linux filesystem in /dev/dahdi/transcode or /dev/zap/transcode, depending on whether you have Zaptel or DAHDI drivers.</p>
<p>Here I want to explain the few interfaces required to use this board.</p>
<p>The first thing you usually want to do is verify that there is encoders and decoders available. This is done through an <a href="http://en.wikipedia.org/wiki/Ioctl">ioctl</a> to request the information about the availability of these transcoders. </p>
<pre>
<span class="keyword">        struct</span> dahdi_transcoder_info info<span class="operator"> = {</span><span class="int">0</span><span class="operator">};</span>

        fd<span class="operator"> =</span> open<span class="operator">(</span><span class="string">"/dev/dahdi/transcode"</span><span class="operator">,</span> O_RDWR<span class="operator">);</span><span class="flow">
        if</span><span class="operator"> (</span>fd<span class="operator"> &lt;</span><span class="int"> 0</span><span class="operator">) {</span>

                fprintf<span class="operator">(</span>stderr<span class="operator">,</span><span class="string"> "Failed to open dahdi transcode device\n"</span><span class="operator">);</span>
                exit<span class="operator">(</span><span class="int">1</span><span class="operator">);
        }</span><span class="flow">
        for</span><span class="operator"> (</span>info<span class="operator">.</span>tcnum<span class="operator"> =</span><span class="int"> 0</span><span class="operator">; !(</span>res<span class="operator"> =</span> ioctl<span class="operator">(</span>fd<span class="operator">,</span> DAHDI_TC_GETINFO<span class="operator">, &amp;</span>info<span class="operator">));</span> info<span class="operator">.</span>tcnum<span class="operator">++) {</span>

                printf<span class="operator">(</span><span class="string">"Found transcoder '%s', numchannels = %d, dstfmts = %d, srcfmts = %d.\n"</span><span class="operator">,</span> info<span class="operator">.</span>name<span class="operator">,</span>
                                info<span class="operator">.</span>numchannels<span class="operator">,</span> info<span class="operator">.</span>dstfmts<span class="operator">,</span> info<span class="operator">.</span>srcfmts<span class="operator">);
        }</span>

        close<span class="operator">(</span>fd<span class="operator">);</span>
</pre>
<p>The driver will let you know the number of encoders, decoders and the source and destiny formats. The formats masks can be found in /usr/include/dahdi/kernel.h. In future versions that may change, I discussed this with one of the DAHDI developers, since I think that this should be in dahdi/user.h and not in kernel.h given that is a user space interface.</p>
<p>Once you know which transcoders are available you can request an encoder or decoder, or both.</p>
<pre><span class="type">        int</span> encoder_fd<span class="operator">,</span> decoder_fd<span class="operator">;</span><span class="keyword">

        struct</span> dahdi_transcoder_formats g729_encoder<span class="operator">;</span><span class="keyword">
        struct</span> dahdi_transcoder_formats g729_decoder<span class="operator">;</span>

        g729_encoder<span class="operator">.</span>srcfmt<span class="operator"> =</span> DAHDI_FORMAT_ULAW<span class="operator">;</span>

        g729_encoder<span class="operator">.</span>dstfmt<span class="operator"> =</span> DAHDI_FORMAT_G729A<span class="operator">;</span>

        g729_decoder<span class="operator">.</span>srcfmt<span class="operator"> =</span> DAHDI_FORMAT_G729A<span class="operator">;</span>

        g729_decoder<span class="operator">.</span>dstfmt<span class="operator"> =</span> DAHDI_FORMAT_ULAW<span class="operator">;</span>

        encoder_fd<span class="operator"> =</span> open<span class="operator">(</span><span class="string">"/dev/dahdi/transcode"</span><span class="operator">,</span> O_RDWR<span class="operator">);</span><span class="flow">

        if</span><span class="operator"> (</span>encoder_fd<span class="operator"> &lt;</span><span class="int"> 0</span><span class="operator">) {</span>
                printf<span class="operator">(</span><span class="string">"Failed to open transcode device\n"</span><span class="operator">);</span>
                exit<span class="operator">(</span><span class="int">1</span><span class="operator">);
        }</span><span class="flow">
        if</span><span class="operator"> (</span>ioctl<span class="operator">(</span>fd<span class="operator">,</span> DAHDI_TC_ALLOCATE<span class="operator">, &amp;</span>g729_encoder<span class="operator">)) {</span>

                printf<span class="operator">(</span><span class="string">"Failed to allocate encoder\n"</span><span class="operator">);</span>
                close<span class="operator">(</span>encoder_fd<span class="operator">);</span>
                exit<span class="operator">(</span><span class="int">1</span><span class="operator">);
        }</span>

        decoder_fd<span class="operator"> =</span> open<span class="operator">(</span><span class="string">"/dev/dahdi/transcode"</span><span class="operator">,</span> O_RDWR<span class="operator">);</span><span class="flow">
        if</span><span class="operator"> (</span>decoder_fd<span class="operator"> &lt;</span><span class="int"> 0</span><span class="operator">) {</span>

                printf<span class="operator">(</span><span class="string">"Failed to open transcode device\n"</span><span class="operator">);</span>
                exit<span class="operator">(</span><span class="int">1</span><span class="operator">);
        }</span><span class="flow">
        if</span><span class="operator"> (</span>ioctl<span class="operator">(</span>fd<span class="operator">,</span> DAHDI_TC_ALLOCATE<span class="operator">, &amp;</span>g729_decoder<span class="operator">)) {</span>

                printf<span class="operator">(</span><span class="string">"Failed to allocate decoder\n"</span><span class="operator">);</span>
                close<span class="operator">(</span>fd<span class="operator">);</span>
                exit<span class="operator">(</span><span class="int">1</span><span class="operator">);
        }</span>
</pre>
<p>Finally, once allocated, you just have to write chunks of ulaw data and read chunks of decoded g729 data and viceversa. You can choose whether the device will accept ulaw or alaw to g729 or g723 manipulating the srcfmt and dstfmt members of dahdi_transcoder_formats. Just remember that ulaw or alaw encoded data requires 8 times more bytes than g729 encoded data, therefore if you write a frame of 20ms of alaw (160 bytes for a sampling rate of 8000hz) you will read just 20 bytes of g729 encoded data, of course, the same apply when you decode a g729 frame or for g723 (for which alaw and ulaw requires 12 times more space). </p>
<p>The module is <a href="http://www.moythreads.com/mod_dahdi_codec.c" target="_blank">available here</a> under the MPL license. Also, the module was just commited to trunk yesterday in the Freeswitch SVN repository. I want to thank to <a href="http://www.voiceway.ca/" target="_blank">Voiceway</a> for sponsoring the module and <a href="http://www.neocenter.com.mx/" target="_blank">Neocenter</a> for providing the hardware to test it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.moythreads.com/wordpress/2009/02/08/g729a-and-g7231-support-for-freeswitch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New astunicall release</title>
		<link>http://www.moythreads.com/wordpress/2008/11/30/new-astunicall-release/</link>
		<comments>http://www.moythreads.com/wordpress/2008/11/30/new-astunicall-release/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 21:05:03 +0000</pubDate>
		<dc:creator>moy</dc:creator>
				<category><![CDATA[asterisk]]></category>

		<guid isPermaLink="false">http://www.moythreads.com/wordpress/2008/11/30/new-astunicall-release/</guid>
		<description><![CDATA[I just released a new astunicall package and chan_unicall driver for Asterisk 1.6, you can get it as usual from:
http://www.moythreads.com/astunicall/downloads/
]]></description>
			<content:encoded><![CDATA[<p>I just released a new astunicall package and chan_unicall driver for Asterisk 1.6, you can get it as usual from:</p>
<p><a href="http://www.moythreads.com/astunicall/downloads/" target="_blank">http://www.moythreads.com/astunicall/downloads/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.moythreads.com/wordpress/2008/11/30/new-astunicall-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
