<?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; sangoma</title>
	<atom:link href="http://www.moythreads.com/wordpress/category/sangoma/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>Sun, 01 Jan 2012 19:20:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Astricon 2010</title>
		<link>http://www.moythreads.com/wordpress/2010/10/28/astricon-2010/</link>
		<comments>http://www.moythreads.com/wordpress/2010/10/28/astricon-2010/#comments</comments>
		<pubDate>Thu, 28 Oct 2010 05:20:01 +0000</pubDate>
		<dc:creator>moy</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[sangoma]]></category>

		<guid isPermaLink="false">http://www.moythreads.com/wordpress/?p=121</guid>
		<description><![CDATA[Today (or yesterday, since it is already 1:08am), I spoke at Astricon about the PRI passive call recording feature I developed the last year. Presentation in PDF and PPT available here: http://www.moythreads.com/congresos/astricon2010/asterisk-pri-passive-recording.pdf http://www.moythreads.com/congresos/astricon2010/asterisk-pri-passive-recording.ppt]]></description>
			<content:encoded><![CDATA[<p>Today (or yesterday, since it is already 1:08am), I spoke at Astricon about the PRI passive call recording feature I developed the last year. </p>
<p><img src="http://www.moythreads.com/moythreads_images/astricon2010.jpg" alt="astricon2010" /></p>
<p>Presentation in PDF and PPT available here:</p>
<p><a href="http://www.moythreads.com/congresos/astricon2010/asterisk-pri-passive-recording.pdf">http://www.moythreads.com/congresos/astricon2010/asterisk-pri-passive-recording.pdf</a></p>
<p><a href="http://www.moythreads.com/congresos/astricon2010/asterisk-pri-passive-recording.ppt">http://www.moythreads.com/congresos/astricon2010/asterisk-pri-passive-recording.ppt</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.moythreads.com/wordpress/2010/10/28/astricon-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>24</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 [...]]]></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>Sangoma cards compared to Digium&#8217;s</title>
		<link>http://www.moythreads.com/wordpress/2009/06/22/sangoma-cards-compared-to-digiums/</link>
		<comments>http://www.moythreads.com/wordpress/2009/06/22/sangoma-cards-compared-to-digiums/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 14:48:28 +0000</pubDate>
		<dc:creator>moy</dc:creator>
				<category><![CDATA[sangoma]]></category>

		<guid isPermaLink="false">http://www.moythreads.com/wordpress/2009/06/22/sangoma-cards-compared-to-digiums/</guid>
		<description><![CDATA[I am by no means a hardware guy, but found this article interesting to compare the evolution of telephony boards by Sangoma and Digium: http://www.halokwadrat.pl/sangoma-vs.-digium.html]]></description>
			<content:encoded><![CDATA[<p>I am by no means a hardware guy, but found this article interesting to compare the evolution of telephony boards by Sangoma and Digium: <a href="http://www.halokwadrat.pl/sangoma-vs.-digium.html" target="_blank">http://www.halokwadrat.pl/sangoma-vs.-digium.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.moythreads.com/wordpress/2009/06/22/sangoma-cards-compared-to-digiums/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

