<?xml version="1.0" encoding="utf-8"?>
<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/' xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>The Corelatus Blog</title>
		<description>Mostly narrowband E1/T1 telecommunications</description>
                <link>./</link>
                <atom:link href="./index.rss" rel="self" type="application/rss+xml" />
	
	<item>
		<title>Porting C Socket Code to Windows</title>
		<link>./Porting_C_Socket_Code_to_Windows.html</link>
		<guid isPermaLink="true">./Porting_C_Socket_Code_to_Windows.html</guid>
                <pubDate>Wed, 16 Jun 2010 13:48:38 GMT</pubDate>
		<description>&lt;p&gt;
  I just ported
  the &lt;a href=&#39;http://www.corelatus.com/gth/api/gth_c_examples.zip&#39;&gt;C
  example code&lt;/a&gt; for controlling Corelatus E1/T1 hardware to Visual
  Studio 2010. Doing that was easier than expected. This first part
  of this post is about how to use that code. The second part is 
  a bit of history about what I had to do to port the code.
&lt;/p&gt;

&lt;h4&gt;Obtaining Visual Studio&lt;/h4&gt;

&lt;p&gt;Microsoft have their C/C++ compiler available for free download
  on &lt;a href=&#39;http://www.microsoft.com/express/Windows/&#39;&gt;microsoft.com&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;The install process is pretty standard for windows, if you&#39;re
  accustomed to Microsoft products, there are no surprises here.
&lt;/p&gt;


&lt;h4&gt;Compiling the code&lt;/h4&gt;

&lt;p&gt;
  &lt;ol&gt;
    &lt;li&gt;Start the &quot;Visual Studio Command Prompt&quot;. By default, that&#39;s
      in &quot;Start/Programs/Microsoft Visual Studio 2010 Express&quot;.&lt;/li&gt;

    &lt;li&gt;Navigate to the directory you unpacked
      the &lt;a href=&#39;http://www.corelatus.com/gth/api/gth_c_examples.zip&#39;&gt;sample
      code&lt;/a&gt; in. Remove any old .exe files with &#39;del *.exe&#39;.&lt;/li&gt;

    &lt;li&gt;Run &#39;nmake /f NMakefile&#39;. After a couple of seconds, you have 
        six brand-new .exe files. Here&#39;s what this step looks like:&lt;/li&gt;
  &lt;/ol&gt;

  &lt;img style=&#39;margin-left:-70px&#39; 
       src=&#39;static/visual_studio_compile.png&#39; 
       alt=&#39;screenshot of a VC compile&#39;/&gt;

  If you just wanted to see how to compile the code, &lt;b&gt;you can stop reading
  now&lt;/b&gt;. The rest of the post is just about what I had to do to make this
  work with Microsoft&#39;s compiler.
&lt;/p&gt;


&lt;h4&gt;Hurdle #1: MS nmake vs gnumake vs Visual Studio projects&lt;/h4&gt;

&lt;p&gt;
  Conclusion: I ended up using Microsoft&#39;s nmake and wrote a separate
  NMakefile for it.
&lt;/p&gt;

&lt;p&gt;
  My code gets built by &#39;make&#39;, through a Makefile. Visual Studio doesn&#39;t
  include a make program which can understand normal Makefiles, leaving
  me a choice of either using the Visual Studio IDE or using Microsoft&#39;s
  &lt;code&gt;nmake&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
  I spent half an hour trying the IDE route. When you make a new
  project, you have to choose what sort it is. &quot;CLR Console
  Application&quot; seemed closest to what I wanted to do, so I chose
  that. Maybe &quot;Makefile Project&quot; would have worked better.
  Things got increasingly confusing from there. What&#39;s a &quot;solution?&quot;
  Why are &quot;precompiled headers&quot; enabled? I just want to compile a few
  hundred lines of C. At that point, I gave up, the IDE is clearly not
  the easiest way for me to get started.
&lt;/p&gt;

&lt;p&gt;
  Next, I tried Microsoft&#39;s replacement for &lt;code&gt;make&lt;/code&gt;, called
  &lt;code&gt;nmake&lt;/code&gt;. That didn&#39;t start flawlessly either, nmake uses
  its own syntax. Initially, I thought I might be able to write one
  Makefile which both gnumake and nmake understand. But Microsoft&#39;s
  syntax seems to be too different to allow that. Oh well. The NMakefile
  is just a dozen lines or so.
&lt;/p&gt;


&lt;h4&gt;Hurdle #2: Missing header files&lt;/h4&gt;

&lt;p&gt;
  Conclusion: I used #ifdefs to include different header files when
  compiling in a win32 environment.&lt;/p&gt;

&lt;p&gt;
  Visual Studio doesn&#39;t provide some of the header files the code
  uses, e.g. there&#39;s no &#39;unistd.h&#39; and no &#39;sys/socket.h&#39;. Odd.
  Providing most of unistd.h shouldn&#39;t be too hard.
&lt;/p&gt;

&lt;p&gt;
  The point of this exercise is to get the code to compile using
  a Microsoft toolchain, so I didn&#39;t investigate using cygwin or
  mingw.
&lt;/p&gt;

&lt;p&gt;
  In the end, it turns out that I wasn&#39;t using anything from &#39;unistd.h&#39;
  which didn&#39;t get provided by something else in win32. &#39;socket.h&#39; (and
  friends) was a bit harder, but it turns out that&#39;s provided by 
  &#39;winsock2.h&#39;.
&lt;/p&gt;


&lt;h4&gt;Hurdle #3: &#39;Mostly compatible&#39; socket API&lt;/h4&gt;

&lt;p&gt;
  Conclusion: winsock2 is different to the BSD socket API, but the
  differences can be worked around with just a few changes.
&lt;/p&gt;

&lt;p&gt;
  Sockets were invented on unix, so I assumed that other OSes would
  just copy the interface. But no, not on win32. There seem to be at
  least two attempts to make a socket API for windows, called
  &#39;winsock&#39; and &#39;winsock2&#39;. The first seems to be deprecated.  The
  main problems I hit were:

  &lt;ul&gt;
    &lt;li&gt;You can&#39;t use close() on a socket, you have to use closesocket()&lt;/li&gt;
    &lt;li&gt;You can&#39;t use read() on a socket, you have to use recv()&lt;/li&gt;
    &lt;li&gt;&lt;code&gt;errno&lt;/code&gt; doesn&#39;t report socket errors, you have to
      call a special Windows Socket error reporting function.&lt;/li&gt;
  &lt;/ul&gt;

  None of those problems are hard to get around.
&lt;/p&gt;
  

&lt;h4&gt;Hurdle #4: GNU and Microsoft can&#39;t agree on function names&lt;/h4&gt;

&lt;p&gt;
  Both GNU and Microsoft have replacements for some functions which
  are prone to security problems. If you use plain &lt;code&gt;strcat()&lt;/code&gt;
  or &lt;code&gt;strcpy&lt;/code&gt;, visual studio warns about security problems.
&lt;/p&gt;

&lt;p&gt;
  Disabling the warnings would be quick but feels like cheating. So
  I looked at the &#39;less insecure&#39; alternatives. GNU call them
  &lt;code&gt;strncat&lt;/code&gt; and &lt;code&gt;strncpy&lt;/code&gt; whereas Microsoft call
  them &lt;code&gt;strcat_s&lt;/code&gt; and &lt;code&gt;strcpy_s&lt;/code&gt;. And the
  arguments are the same way around. It would have been nice if GNU
  and MS had solved this the same way, but no. Minor annoyance.
&lt;/p&gt;


&lt;h4&gt;Hurdle #5: Structure packing pragmas&lt;/h4&gt;

&lt;p&gt;
  Conclusion: Both MS and GNU understand the #pragma pack(N) syntax,
  but only GNU understands the __attribute__((__packed__)) syntax.
&lt;/p&gt;

&lt;p&gt;
  A couple of the examples (save_to_pcap.c and record.c) use
  structures to encode or decode data defined by an external
  format. For instance, here&#39;s what the wire format of a
  &#39;pcap&#39; protocol capture file looks like:

  &lt;pre&gt;
    &lt;code&gt;
      &lt;span class=&quot;synType&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;struct&lt;/span&gt; {
        &lt;span class=&quot;synType&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; magic;
        &lt;span class=&quot;synType&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;short&lt;/span&gt; major_version;
        &lt;span class=&quot;synType&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;short&lt;/span&gt; minor_version;
        &lt;span class=&quot;synType&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; GMT_to_localtime;
        &lt;span class=&quot;synType&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; sigfigs;
        &lt;span class=&quot;synType&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; snaplen;
        &lt;span class=&quot;synType&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; network;
      } PCAP_global_header;
    
&lt;/code&gt;
  &lt;/pre&gt;

  We have to tell the compiler that spacing out the fields to get
  a certain alignment isn&#39;t allowed. The recommended GNU way to
  do that is to add &lt;code&gt;__attribute__((__packed__))&lt;/code&gt; after
  the structure. The recommended Microsoft way is to add
  &lt;code&gt;#pragma pack(1)&lt;/code&gt; somewhere before the structure, and
  then remember to change the packing back again before hitting
  any code which is sensitive to performance.
&lt;/p&gt;

&lt;p&gt;
  Since this is just example code, we don&#39;t care about that last
  bit of performance, so we can just leave the packing at 1.
&lt;/p&gt;

&lt;p&gt;
  Aside: the structure above is a bit sloppy because just quietly
  assumes that an int is 32 bits and a short 16.
&lt;/p&gt;

&lt;h4&gt;Hurdle #6: Windows firewall&lt;/h4&gt;

&lt;p&gt;
  Some of the example code opens TCP sockets for listening. By default,
  the windows firewall doesn&#39;t allow that. Just click &quot;fine, ok, let
  me do this&quot;.
&lt;/p&gt;

&lt;p&gt;
  Unfortunately, that looks ugly for the user---the program will fail
  the first time you run it, and the pop-up box says &quot;publisher
  unknown&quot;.  Does anyone know how to improve on this? It&#39;d be nice if
  the user could approve the publisher, i.e. me, once, and then every
  program works.
&lt;/p&gt;

&lt;h4&gt;How long did the porting take?&lt;/h4&gt;

&lt;p&gt;
  A couple of days, including getting Visual Studio installed.
  That&#39;s for a few thousand lines of code with a bit of socket IO
  and file IO.
&lt;/p&gt;

&lt;p&gt;
  If I had to do it again, it&#39;d take an afternoon or so.
&lt;/p&gt;
</description>
	</item>
	
	<item>
		<title>Decoding UMTS (3G) Interfaces with Wireshark</title>
		<link>./Decoding_UMTS__3G__Interfaces_with_Wireshark.html</link>
		<guid isPermaLink="true">./Decoding_UMTS__3G__Interfaces_with_Wireshark.html</guid>
                <pubDate>Mon, 24 May 2010 16:46:18 GMT</pubDate>
		<description>&lt;p&gt; 
Many 3G networks use ATM on their internal interfaces, e.g. on the Iub and
Iu-PS interfaces. Those interfaces carry both control information (radio
environment information, attach/detach messages, location updates) and also
subscriber data, for instance IP traffic.
&lt;/p&gt;

&lt;p&gt;
Wireshark understands how to decode those ATM interfaces. Here&#39;s an
example of an interface sniffed by a GTH.  The interface was carrying
IP traffic over ATM on an E1 line.
&lt;/p&gt;

&lt;img alt=&#39;wireshark screenshot&#39; style=&#39;margin-left:-170px&#39; src=&#39;static/atm_llc_interface_screenshot.png&#39;/&gt;

&lt;h3&gt;How to tell the GTH to capture an ATM link&lt;/h3&gt;

&lt;p&gt;To look at a 3G network like this, you need to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Connect one of the GTH&#39;s E1 interfaces to the E1 (or T1) interface
carrying the ATM interface. You typically do that at a cross connect
panel, using a G.772 monitor point.&lt;/li&gt;

&lt;li&gt;Enable the E1 interface you connected.&lt;/li&gt;

&lt;li&gt;Tell the GTH to start decoding ATM AAL5 (and/or AAL2) on that interface&lt;/li&gt;

&lt;li&gt;Convert the captured data to the file format which wireshark understands,
  libpcap.&lt;/li&gt;

&lt;li&gt;Open the captured file in wireshark. (On unix-like operating systems,
  including OSX, you can also pipe into wireshark to get a live view of
  the capture.)&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;Taking those steps one at a time, starting with #2:&lt;/p&gt;

&lt;h4&gt;Enable the E1 interface&lt;/h4&gt;

&lt;pre&gt;
&lt;code&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;set &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;pcm3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&amp;lt;attribute &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;monitoring&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;value&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;true&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&amp;lt;/set&amp;gt;&lt;/span&gt;
&lt;/code&gt;
&lt;/pre&gt;

&lt;h4&gt;Tell GTH start decoding ATM AAL5&lt;/h4&gt;

&lt;p&gt;IP traffic on ATM is always carried in AAL5. The timeslot
arrangement is usually 1--15 + 17--31. A few sites share the E1 with
other protocols, this is called fractional ATM. The GTH can handle
either scheme.&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;new&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;atm_aal5_monitor &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;ip_addr&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;172.16.2.1&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;ip_port&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;1234&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;vpi&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;0&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;vci&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;5&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;pcm_source &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;span&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;timeslot&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;1&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;pcm_source &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;span&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;timeslot&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;2&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;pcm_source &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;span&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;timeslot&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
      ..
      &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;pcm_source &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;span&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;timeslot&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;15&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;pcm_source &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;span&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;timeslot&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;17&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
      ..
      &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;pcm_source &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;span&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;timeslot&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;31&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/fr_monitor&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/new&amp;gt;&lt;/span&gt;
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;
In this example, the VPI/VCI is 0/5. If you know the VPI/VCI in advance,
great. If you don&#39;t, the GTH can sniff traffic at the AAL0 interface and
show you which VPI/VCI are active on the link.
&lt;/p&gt;

&lt;h4&gt;Convert the captured data&lt;/h4&gt;

&lt;p&gt;GTH sends out data in a format described in
the &lt;a href=&#39;www.corelatus.com/gth/api/gth_api.pdf&#39;&gt;API manual&lt;/a&gt;.
Wireshark wants the data to be in libpcap format. save_to_pcap.erl, in
the &lt;a href=&#39;http://www.corelatus.com/gth/api/gth_erlang_api.zip&#39;&gt;sample
Erlang code for GTH&lt;/a&gt; can do the conversion, like this:
&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;save_to_pcap:from_file&lt;/span&gt;(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;/tmp/captured.raw&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;/tmp/captured.pcap&amp;quot;&lt;/span&gt;)&lt;span class=&quot;synSpecial&quot;&gt;.&lt;/span&gt;
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;
  A lazier approach is to let save_to_pcap.erl configure the GTH and
start the capture:
&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;save_to_pcap:aal5&lt;/span&gt;(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;172.16.2.7&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;3A&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synIdentifier&quot;&gt;lists:seq&lt;/span&gt;(&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;15&lt;/span&gt;) &lt;span class=&quot;synStatement&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;lists:seq&lt;/span&gt;(&lt;span class=&quot;synConstant&quot;&gt;17&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;31&lt;/span&gt;),
  {&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;5&lt;/span&gt;}, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;aal5.pcap&amp;quot;&lt;/span&gt;)&lt;span class=&quot;synSpecial&quot;&gt;.&lt;/span&gt;
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;  
  The &lt;a href=&#39;http://www.corelatus.com/gth/api/gth_c_examples.zip&#39;&gt;C version
    &lt;/a&gt;of save_to_pcap can currently only convert MTP-2, not AAL5. If
    you want it extended, send mail (address at top right).
&lt;/p&gt;


&lt;h4&gt;Start up wireshark&lt;/h4&gt;

&lt;p&gt;
Recent versions of Wireshark, e.g. 1.2.7, can decode such capture files
out of the box, without any configuration. Finished.
&lt;/p&gt;

</description>
	</item>
	
	<item>
		<title>Decoding the Gb Interface with Wireshark</title>
		<link>./Decoding_the_Gb_Interface_with_Wireshark.html</link>
		<guid isPermaLink="true">./Decoding_the_Gb_Interface_with_Wireshark.html</guid>
                <pubDate>Wed, 31 Mar 2010 22:26:29 GMT</pubDate>
		<description>&lt;p&gt; 
The Gb interface is part of the packet radio data network (GPRS) in GSM,
it sits between the BSC and the SGSN and carries subscriber data headed
to and from the internet.&lt;/p&gt;

&lt;p&gt;
Wireshark understands how to decode the Gb interface, so you can use
wireshark to look through data sniffed from a Gb interface by a
Corelatus GTH.  Here&#39;s what it looks like:
&lt;/p&gt;

&lt;img alt=&#39;wireshark screenshot&#39; style=&#39;margin-left:-170px&#39; src=&#39;static/gsm_gb_interface_screenshot.png&#39;/&gt;

&lt;h3&gt;How to tell the GTH to capture Gb&lt;/h3&gt;

&lt;p&gt;To look at a GPRS network like this, you need to do a few things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Connect one of the GTH&#39;s E1 interfaces to the E1 (or T1) interface
carrying the Gb interfaces. You typically do that at a cross connect
panel, using a G.772 monitor point.&lt;/li&gt;

&lt;li&gt;Enable the E1 interface you connected.&lt;/li&gt;

&lt;li&gt;Tell the GTH to start decoding frame relay on that interface&lt;/li&gt;

&lt;li&gt;Convert the captured data to the file format which wireshark understands,
  libpcap.&lt;/li&gt;

&lt;li&gt;Open the captured file in wireshark. (On unix-like operating systems,
  including OSX, you can also pipe into wireshark to get a live view of
  the capture.)&lt;/li&gt;

&lt;/ol&gt;

&lt;p&gt;Taking those steps one at a time, starting with #2:&lt;/p&gt;

&lt;h4&gt;Enable the E1 interface&lt;/h4&gt;

&lt;pre&gt;
&lt;code&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;set &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;pcm3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&amp;lt;attribute &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;monitoring&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;value&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;true&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&amp;lt;/set&amp;gt;&lt;/span&gt;
&lt;/code&gt;
&lt;/pre&gt;

&lt;h4&gt;Tell GTH start decoding frame relay&lt;/h4&gt;

&lt;p&gt;The Gb interface uses frame relay on E1. Different sites use
different configurations of timeslots. One common setup is to use
timeslots 1--15. Another common setup is to 1--15 + 17--31. The
GTH can handle any setup.&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;new&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;fr_monitor &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;ip_addr&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;172.16.2.1&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;ip_port&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;1234&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;pcm_source &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;span&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;timeslot&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;1&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;pcm_source &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;span&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;timeslot&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;2&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;pcm_source &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;span&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;timeslot&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
      ..
      &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;pcm_source &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;span&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;timeslot&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;15&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/fr_monitor&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/new&amp;gt;&lt;/span&gt;
&lt;/code&gt;
&lt;/pre&gt;

&lt;h4&gt;Convert the captured data&lt;/h4&gt;

&lt;p&gt;GTH sends out data in a format described in
the &lt;a href=&#39;www.corelatus.com/gth/api/gth_api.pdf&#39;&gt;API manual&lt;/a&gt;.
Wireshark wants the data to be in libpcap format. save_to_pcap.erl, in
the &lt;a href=&#39;http://www.corelatus.com/gth/api/gth_erlang_api.zip&#39;&gt;sample
Erlang code for GTH&lt;/a&gt; can do the conversion, like this:
&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;save_to_pcap:from_file&lt;/span&gt;(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;/tmp/captured.raw&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;/tmp/captured.pcap&amp;quot;&lt;/span&gt;)&lt;span class=&quot;synSpecial&quot;&gt;.&lt;/span&gt;
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;
  A lazier approach is to let save_to_pcap.erl configure the GTH and
start the capture:
&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;save_to_pcap:frame_relay&lt;/span&gt;(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;172.16.2.7&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;3A&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synIdentifier&quot;&gt;lists:seq&lt;/span&gt;(&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;,&lt;span class=&quot;synConstant&quot;&gt;15&lt;/span&gt;), &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;gprs.pcap&amp;quot;&lt;/span&gt;)&lt;span class=&quot;synSpecial&quot;&gt;.&lt;/span&gt;
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;  
  The &lt;a href=&#39;http://www.corelatus.com/gth/api/gth_c_examples.zip&#39;&gt;C version
    &lt;/a&gt;of save_to_pcap can currently only convert MTP-2, not frame
    relay. If you want it extended, send mail.
&lt;/p&gt;


&lt;h4&gt;Start up wireshark&lt;/h4&gt;

&lt;p&gt;
By default, wireshark decodes frame relay as &#39;FRF 3.2/CISCO HDLC&#39;.
That&#39;s not quite what we want. Go to Edit/Preferences/Protocols/FR
and change the encapsulation to &#39;GPRS Network Service&#39;. Now you
get full decoding.
&lt;/p&gt;

</description>
	</item>
	
	<item>
		<title>GTH &#39;C&#39; API</title>
		<link>./GTH__C__API.html</link>
		<guid isPermaLink="true">./GTH__C__API.html</guid>
                <pubDate>Wed, 20 Jan 2010 10:47:37 GMT</pubDate>
		<description>&lt;p&gt; 
This post is for people who want to use C to control a GTH. Other
languages (e.g. Erlang, Java, Python and Perl) are easier to work
with, but in some applications you want the complete control that C
gives you. 
&lt;/p&gt;

&lt;p&gt;
Corelatus provides a &lt;a href=&quot;http://www.corelatus.com/gth/api/gth_c_examples.zip&quot;&gt;
C API for GTH&lt;/a&gt;. The C API lets you control a GTH using plain C function
calls---all of the XML wire format is taken care of.
&lt;/p&gt;

&lt;p&gt;Here&#39;s an example of how to use it to record speech
on an E1/T1 timeslot, something you&#39;d typically do in a voicemail system:
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
&lt;span class=&quot;synPreProc&quot;&gt;#include &lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;gth_apilib.h&amp;quot;&lt;/span&gt;
...

  GTH_api api;                     &lt;span class=&quot;synComment&quot;&gt;// GTH_api represents one GTH API connection&lt;/span&gt;
  &lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; result;
  &lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; data_socket;
  &lt;span class=&quot;synType&quot;&gt;char&lt;/span&gt; buffer[&lt;span class=&quot;synConstant&quot;&gt;2000&lt;/span&gt;];
  &lt;span class=&quot;synType&quot;&gt;char&lt;/span&gt; job_id[MAX_JOB_ID];
  &lt;span class=&quot;synType&quot;&gt;int&lt;/span&gt; octet_count;

  result = gth_connect(&amp;amp;api, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;172.16.1.10&amp;quot;&lt;/span&gt;);    &lt;span class=&quot;synComment&quot;&gt;// Assuming the default GTH IP &lt;/span&gt;
  assert(result == &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;);

  &lt;span class=&quot;synComment&quot;&gt;// We want to record audio on the E1/T1 called &amp;quot;1A&amp;quot;, on timeslot 3.&lt;/span&gt;
  data_socket = gth_new_recorder(api, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;1A&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;, job_id);

  &lt;span class=&quot;synStatement&quot;&gt;while&lt;/span&gt; ( (octet_count = recv(data_socket, buffer, &lt;span class=&quot;synStatement&quot;&gt;sizeof&lt;/span&gt; buffer, &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;)) ) {
    &lt;span class=&quot;synComment&quot;&gt;// do whatever you want with the received data&lt;/span&gt;
  }

...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
The recording above happens in the &#39;while&#39; loop. It continues forever
(i.e. until you abort it). The audio data is bit-for-bit identical to
what was on the E1/T1 timeslot, so this can be used for recording both
voice and signalling.
&lt;/p&gt;

&lt;h3&gt;Further examples&lt;/h3&gt;

&lt;p&gt;The C API code includes further examples to:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Record audio or signalling from a timeslot to a .wav file&lt;/li&gt;
  &lt;li&gt;Play back previously recorded files&lt;/li&gt;
  &lt;li&gt;Install (upgrade) the firmware on a GTH&lt;/li&gt;
  &lt;li&gt;Monitor (sniff) SS7 MTP-2 and save the signalling to a wireshark
    (PCAP) compatible file.&lt;/li&gt;
  &lt;li&gt;Monitor CAS R2 signalling.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;Standalone Parser&lt;/h3&gt;

&lt;p&gt;Aside: the C API code includes a standalone parser for the XML
responses the GTH emits. You can use the parser without using the
rest of the API library, if you want to.
&lt;/p&gt;
</description>
	</item>
	
	<item>
		<title>New blog software</title>
		<link>./New_blog_software.html</link>
		<guid isPermaLink="true">./New_blog_software.html</guid>
                <pubDate>Tue, 19 Jan 2010 16:16:21 GMT</pubDate>
		<description>&lt;p&gt; This blog now uses
&lt;a href=&#39;http://steve.org.uk/Software/chronicle&#39;&gt;chronicle&lt;/a&gt; to
compile the blog.
&lt;/p&gt;

&lt;p&gt;Before, I used Wordpress. Wordpress is OK and mostly &#39;just works&#39;.
But, after a year, I wanted something which followed my normal
workflow, i.e. edit-compile-test-checkin-publish. It&#39;s easier for me
to write posts in emacs, build the blog with a Makefile,
version-control with git and publish via scp.
&lt;/p&gt;

&lt;p&gt;I&#39;ve made all comments go
via &lt;a href=&#39;mailto:matthias@corelatus.com?subject=blog%20comment&#39;&gt;mail&lt;/a&gt;,
comment spam was getting overwhelming.
&lt;/p&gt;
</description>
	</item>
	
	<item>
		<title>Audio power levels on E1/T1 timeslots: the digital milliwatt</title>
		<link>./Audio_power_levels_on_E1_T1_timeslots__the_digital_milliwatt.html</link>
		<guid isPermaLink="true">./Audio_power_levels_on_E1_T1_timeslots__the_digital_milliwatt.html</guid>
                <pubDate>Sat, 10 Oct 2009 21:33:52 +0200</pubDate>
		<description>&lt;p&gt;
Sometimes, you want to know when the audio on an E1/T1 timeslot has
gotten louder than some limit. In a voice mail application, that&#39;s
useful for catching mistakes such as a subscriber leaving a message
but then not hanging up the phone properly---you don&#39;t want to record
hours and hours of silence. In an IVR application, you might want to
keep an eye on the audio level so that a frustrated (shouting!)
subscriber can be forwarded to a human operator.
&lt;/p&gt;

&lt;p&gt;
GTH provides a &quot;level detector&quot; to do that sort of thing. You start a
level detector on a timeslot, give it a loudness threshold, and it&#39;ll
notify you whenever the audio on the timeslot goes over that
threshold. Here&#39;s an example command which notifies you if the power
on timeslot 13 of an E1/T1 is louder than -20dBm0:
&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;new&amp;gt;&amp;lt;level_detector &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;threshold&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;-20&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&lt;/span&gt;
     &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;pcm_source &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;span&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;2A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;timeslot&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;13&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/level_detector&amp;gt;&amp;lt;/new&amp;gt;&lt;/span&gt;
&lt;/code&gt;
&lt;/pre&gt;

The algorithm is:

&lt;ol&gt;
  &lt;li&gt;Take a 100ms block of audio (800 samples)&lt;/li&gt;
  &lt;li&gt;Square all the samples&lt;/li&gt;
  &lt;li&gt;Sum the squares&lt;/li&gt;
  &lt;li&gt;If the sum exceeds the loudness threshold, send an XML event&lt;/li&gt;
&lt;/ol&gt;

There are some details to worry about.

&lt;h3&gt;The digital milliwatt&lt;/h3&gt;

&lt;p&gt; The threshold, e.g. -20 in the example above, has to be relative
to something. The standard reference power level in telecommunications
is the milliwatt.  ITU-T G.711, table 5 and 6 defines the sequences
which represent a milliwatt:
&lt;/p&gt;

&lt;p&gt;
A-law: 34 21 21 34 b4 a1 a1 b4&lt;br/&gt;
&amp;#956;-law: 1e 0b 0b 1e 9e 8b 8b 9e&lt;br/&gt;
&lt;/p&gt;

&lt;p&gt;
Here&#39;s what a few periods of the digital milliwatt look like:
&lt;/p&gt;

&lt;img
src=&quot;static/small_linear_milliwatt.png&quot;
alt=&quot;small_linear_milliwatt&quot; title=&quot;small_linear_milliwatt&quot;/&gt;

&lt;p&gt;
In this post, the unit &#39;dBm0&#39; means power, in dB relative to the digital milliwatt, as defined by the sequences above. If you have no idea what dB means, wikipedia has a &lt;a href=&quot;http://en.wikipedia.org/wiki/Decibel&quot;&gt;decent article&lt;/a&gt;.
&lt;/p&gt;

&lt;h3&gt;What&#39;s the loudest possible sound on a timeslot?&lt;/h3&gt;

&lt;p&gt; 170 is the highest value possible in A-law encoding. It
corresponds to linear 4032. That&#39;s about 6dB louder than the digital
milliwatt.
&lt;/p&gt;

&lt;p&gt; 85 is the smallest value possible in A-law encoding. It
corresponds to linear -1. That&#39;s about 66dB softer than the digital
milliwatt.
&lt;/p&gt;

&lt;p&gt; The range -66dBm0...+6dBm0 sets an upper bound on the range of
power on a timeslot. Then there are other things which further limit
the practical range, so you&#39;re unlikely to actually use a +6dBm0
threshold in practice, but it&#39;s there if you want it.
&lt;/p&gt;

&lt;h3&gt;Is the G.711 definition the best one?&lt;/h3&gt;

&lt;p&gt;
The sequence given in G.711 is a 1kHz sine wave. The sampling rate on
E1/T1 is 8kHz, so the reference sequence can be expressed in just
eight values. That&#39;s nice, but that also leads to small errors, about
0.13dB, because of quantisation.
&lt;/p&gt;

&lt;p&gt;
ITU-T O.133 discusses that problem in detail and proposes a test
signal which specfically is &lt;b&gt;not&lt;/b&gt; 1kHz (i.e. not a submultiple of
the sampling rate). For most practical purposes, 0.13dB doesn&#39;t matter
and so the simple and robust thing to do is to use the well-defined
and well-known G.711 sequence as a reference.
&lt;/p&gt;

&lt;p&gt;
Here&#39;s what a few periods of a 1020Hz signal look like. Notice that
the samples, i.e. the red crosses, don&#39;t appear in the same spot one
period later---that way we don&#39;t get the same errors over and over
again.
&lt;/p&gt;

&lt;div class=&quot;image&quot;&gt;
&lt;img src=&quot;static/small_1020hz1.png&quot;
alt=&quot;1020Hz signal sampled at 125us intervals&quot;/&gt;
&lt;div&gt;1020Hz signal sampled at 125us intervals&lt;/div&gt;
&lt;/div&gt;

&lt;h3&gt;Testing pitfall: the .wav header&lt;/h3&gt;

&lt;p&gt; GTH &lt;em&gt;player&lt;/em&gt;s plays raw A-law or &amp;#956;-law data. If you feed
a player a .wav file in 8kHz A-law, or &amp;#956;-law if your network uses
&amp;#956;-law, there will be a very short bit of noise at the start of the
playback because the .wav header gets treated as though it were audio.
&lt;/p&gt;

&lt;p&gt; When testing level detection, especially at quiet levels, that
header noise is enough to trigger a detector. Here&#39;s a .wav of a
1000Hz sine wave at about -30dBm0: &lt;/p&gt;

&lt;pre&gt;
00000000  52 49 46 46 42 27 00 00  57 41 56 45 66 6d 74 20  |RIFFB&#39;..WAVEfmt |
00000010  12 00 00 00 06 00 01 00  40 1f 00 00 40 1f 00 00  |........@...@...|
00000020  01 00 08 00 00 00 66 61  63 74 04 00 00 00 10 27  |......fact.....&#39;|
00000030  00 00 64 61 74 61 10 27  00 00 d5 c4 f5 f1 f3 f1  |..data.&#39;........|
00000040  f5 c4 d5 44 75 71 73 71  75 44 d5 c4 f5 f1 f3 f1  |...DuqsquD......|
*
00002740  f5 c4 d5 44 75 71 73 71  75 44                    |...DuqsquD|
&lt;/pre&gt;

&lt;p&gt; The first 58 octets (bytes) are the header. If we turn that header
into a periodic signal, it&#39;s at about -8dBm0, which is fairly
loud. With the default &lt;em&gt;period&lt;/em&gt; parameter of 100ms in the level
detector, that&#39;ll cause a false level of about -11dBm0.
&lt;/p&gt;

&lt;h3&gt;The period parameter&lt;/h3&gt;

&lt;p&gt; The &lt;em&gt;level_detector&lt;/em&gt; has an optional parameter, the
period. The period sets the size of the audio block the GTH considers
when measuring the power. A short &lt;em&gt;period&lt;/em&gt; makes the GTH
responsive to sudden changes in power on the timeslot, which would be
useful in an application such as figuring out which of the people in a
conference call are currently talking. A long &lt;em&gt;period&lt;/em&gt; averages
out the power over a longer time, which is useful in deciding whether
a voicemail recording has finished.  &lt;/p&gt;

&lt;p&gt;
The default is 100ms.
&lt;/p&gt;

&lt;h3&gt;Sample files&lt;/h3&gt;

&lt;p&gt;
&lt;a href=&quot;http://blog.corelatus.com/static/milliwatt_reference_audio.zip&quot;&gt;This
.zip file&lt;/a&gt; contains sample recordings with 1kHz sine waves at 0,
-10, -20, -30, -40 and -50 dBm0. The .wav versions are useful for
listening to or importing into an audio editing program to calibrate
the level meter. The .raw versions are just plain A-law samples---you
can use them with a GTH player.
&lt;/p&gt;
</description>
	</item>
	
	<item>
		<title>How does TCP behave on an interrupted network?</title>
		<link>./How_does_TCP_behave_on_an_interrupted_network_.html</link>
		<guid isPermaLink="true">./How_does_TCP_behave_on_an_interrupted_network_.html</guid>
                <pubDate>Thu, 27 Aug 2009 23:24:22 GMT</pubDate>
		<description>&lt;p&gt;
GTH E1/T1 modules are always controlled by a general-purpose server,
usually some sort of unix machine. The server and GTH are connected by
ethernet and communicate using TCP sockets. Normally, that ethernet
connection is chosen to be simple and reliable, for instance by
putting the server and the GTH in the same rack, connected to the same
ethernet switch.
&lt;/p&gt;

&lt;p&gt;
I experimented a bit to see what happens when that network gets
interrupted. I interrupted the network in a reproduceable way by
disabling and re-enabling the server&#39;s ethernet port for a known
length of time while running a &amp;lt;recorder&amp;gt;. (A &amp;lt;recorder&amp;gt;
sends all the data, typically someone talking, from an E1 timeslot to
the server over a TCP socket, 8000 octets per second.)
&lt;/p&gt;

&lt;h3&gt;Capturing the ethernet packets&lt;/h3&gt;

&lt;p&gt;
Here&#39;s what I did to capture traffic and interrupt the ethernet:
&lt;/p&gt;

  &lt;pre&gt;
  tcpdump -w /tmp/capture.pcap -s 0 not port 22
  sudo ifconfig eth0 down; sleep 5; sudo ifconfig eth0 up
  &lt;/pre&gt;

&lt;h3&gt;A trace where traffic recovers in time to prevent an overrun&lt;/h3&gt;

&lt;p&gt;
The GTH buffers about two seconds of timeslot traffic. So a &#39;sleep&#39; of
about a second won&#39;t result in an overrun. Here&#39;s what it looks like
in wireshark:
&lt;/p&gt;

&lt;table&gt;
&lt;tr&gt;&lt;td&gt;Packet&lt;/td&gt;&lt;td&gt;Time&lt;/td&gt;&lt;td&gt;Direction&lt;/td&gt;&lt;td&gt;Flags&lt;/td&gt;&lt;td&gt;Seq. #&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;5&quot;&gt;&lt;hr /&gt;&lt;/td&gt;

&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;133 &lt;/td&gt;&lt;td&gt;  7.596 &lt;/td&gt;&lt;td&gt;  GTH -&amp;gt; server&lt;/td&gt;&lt;td&gt; [PSH, ACK] &lt;/td&gt;&lt;td&gt;59393&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;134 &lt;/td&gt;&lt;td&gt;  7.633 &lt;/td&gt;&lt;td&gt;  server -&amp;gt; GTH&lt;/td&gt;&lt;td&gt; [ACK]      &lt;/td&gt;&lt;td&gt;1    &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;135 &lt;/td&gt;&lt;td&gt;  7.724 &lt;/td&gt;&lt;td&gt;  GTH -&amp;gt; server&lt;/td&gt;&lt;td&gt; [PSH, ACK] &lt;/td&gt;&lt;td&gt;60417&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;136 &lt;/td&gt;&lt;td&gt;  7.761 &lt;/td&gt;&lt;td&gt;  server -&amp;gt; GTH&lt;/td&gt;&lt;td&gt; [ACK]      &lt;/td&gt;&lt;td&gt;1	       &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;137 &lt;/td&gt;&lt;td&gt;  7.852 &lt;/td&gt;&lt;td&gt;  GTH -&amp;gt; server&lt;/td&gt;&lt;td&gt; [PSH, ACK] &lt;/td&gt;&lt;td&gt;61441&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;138 &lt;/td&gt;&lt;td&gt;  7.889 &lt;/td&gt;&lt;td&gt;  server -&amp;gt; GTH&lt;/td&gt;&lt;td&gt; [ACK] &lt;/td&gt;&lt;td&gt;1	       &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;139 &lt;/td&gt;&lt;td&gt;  7.980 &lt;/td&gt;&lt;td&gt;  GTH -&amp;gt; server&lt;/td&gt;&lt;td&gt; [PSH, ACK] &lt;/td&gt;&lt;td&gt;62465&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;140 &lt;/td&gt;&lt;td&gt;  8.017 &lt;/td&gt;&lt;td&gt;  server -&amp;gt; GTH&lt;/td&gt;&lt;td&gt; [ACK] &lt;/td&gt;&lt;td&gt;1	       &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;141 &lt;/td&gt;&lt;td&gt;  8.108 &lt;/td&gt;&lt;td&gt;  GTH -&amp;gt; server&lt;/td&gt;&lt;td&gt; [PSH, ACK] &lt;/td&gt;&lt;td&gt;63489&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;142 &lt;/td&gt;&lt;td&gt;  8.145 &lt;/td&gt;&lt;td&gt;  server -&amp;gt; GTH&lt;/td&gt;&lt;td&gt; [ACK] &lt;/td&gt;&lt;td&gt;1	       &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;143 &lt;/td&gt;&lt;td&gt;  8.236 &lt;/td&gt;&lt;td&gt;  GTH -&amp;gt; server&lt;/td&gt;&lt;td&gt; [PSH, ACK] &lt;/td&gt;&lt;td&gt;64513&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;144 &lt;/td&gt;&lt;td&gt;  8.273 &lt;/td&gt;&lt;td&gt;  server -&amp;gt; GTH&lt;/td&gt;&lt;td&gt; [ACK] &lt;/td&gt;&lt;td&gt;1	       &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;145 &lt;/td&gt;&lt;td&gt;  8.364 &lt;/td&gt;&lt;td&gt;  GTH -&amp;gt; server&lt;/td&gt;&lt;td&gt; [PSH, ACK] &lt;/td&gt;&lt;td&gt;65537&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;146 &lt;/td&gt;&lt;td&gt;  8.401 &lt;/td&gt;&lt;td&gt;  server -&amp;gt; GTH&lt;/td&gt;&lt;td&gt; [ACK] &lt;/td&gt;&lt;td&gt;1	       &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;147 &lt;/td&gt;&lt;td&gt; 10.151 &lt;/td&gt;&lt;td&gt;  GTH -&amp;gt; server&lt;/td&gt;&lt;td&gt; [PSH, ACK] &lt;/td&gt;&lt;td&gt;66561&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;148 &lt;/td&gt;&lt;td&gt; 10.151 &lt;/td&gt;&lt;td&gt;  server -&amp;gt; GTH&lt;/td&gt;&lt;td&gt; [ACK] &lt;/td&gt;&lt;td&gt;1	       &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;149 &lt;/td&gt;&lt;td&gt; 10.151 &lt;/td&gt;&lt;td&gt;  GTH -&amp;gt; server&lt;/td&gt;&lt;td&gt; [ACK] &lt;/td&gt;&lt;td&gt;67585     &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;150 &lt;/td&gt;&lt;td&gt; 10.151 &lt;/td&gt;&lt;td&gt;  server -&amp;gt; GTH&lt;/td&gt;&lt;td&gt; [ACK] &lt;/td&gt;&lt;td&gt;1         &lt;/td&gt;&lt;/tr&gt;

&lt;/table&gt;

&lt;p&gt;
Everything up to packet 146 is normal: the GTH (172.16.2.5) sends 8000
octets every second and the server (172.16.2.1) acks them. It happens
to be in chunks of 1024 octets about eight times per second. After
packet 146, about 8.4 seconds after the capture started, the ethernet
interface went down and stayed down for 1s. The TCP stream started up
again after about 1.5s and then &#39;caught up&#39; by sending many packets in
quick succession.
&lt;/p&gt;

&lt;h3&gt;A trace where traffic didn&#39;t recover&lt;/h3&gt;

&lt;p&gt;
I took a second trace similar to the first one, except this time, I
disabled ethernet for about five seconds:
&lt;/p&gt;

&lt;pre&gt;
Packet Time     Source IP     Dest IP    SPort   DPort
----------------------------------------------------------------------
 28   1.040083  172.16.2.5 -&amp;gt; 172.16.2.1 54271 &amp;gt; 45195 [PSH, ACK] Seq=7169
 29   1.040095  172.16.2.1 -&amp;gt; 172.16.2.5 45195 &amp;gt; 54271 [ACK] Seq=1
 30   1.168065  172.16.2.5 -&amp;gt; 172.16.2.1 54271 &amp;gt; 45195 [PSH, ACK] Seq=8193
 31   1.168078  172.16.2.1 -&amp;gt; 172.16.2.5 45195 &amp;gt; 54271 [ACK] Seq=1 
 32   1.296067  172.16.2.5 -&amp;gt; 172.16.2.1 54271 &amp;gt; 45195 [PSH, ACK] Seq=9217
 33   1.296079  172.16.2.1 -&amp;gt; 172.16.2.5 45195 &amp;gt; 54271 [ACK] Seq=1 
 34   1.424068  172.16.2.5 -&amp;gt; 172.16.2.1 54271 &amp;gt; 45195 [PSH, ACK] Seq=10241
 35   1.424081  172.16.2.1 -&amp;gt; 172.16.2.5 45195 &amp;gt; 54271 [ACK] Seq=1
 36   7.782851  172.16.2.5 -&amp;gt; 172.16.2.1 54271 &amp;gt; 45195 [PSH, ACK] Seq=11265
 37   7.782863  172.16.2.1 -&amp;gt; 172.16.2.5 45195 &amp;gt; 54271 [ACK] Seq=1
 38   7.783406  172.16.2.5 -&amp;gt; 172.16.2.1 54271 &amp;gt; 45195 [ACK] Seq=12289
 39   7.783413  172.16.2.1 -&amp;gt; 172.16.2.5 45195 &amp;gt; 54271 [ACK] Seq=1
 40   7.783569  172.16.2.5 -&amp;gt; 172.16.2.1 54271 &amp;gt; 45195 [ACK] Seq=13737
...
 50   7.784962  172.16.2.5 -&amp;gt; 172.16.2.1 54271 &amp;gt; 45195 [FIN, PSH, ACK] Seq=23873
 51   7.784972  172.16.2.1 -&amp;gt; 172.16.2.5 45195 &amp;gt; 54271 [ACK] Seq=1
 52   7.785026  172.16.2.1 -&amp;gt; 172.16.2.5 45195 &amp;gt; 54271 [FIN, ACK] Seq=1
 53   7.785348  172.16.2.5 -&amp;gt; 172.16.2.1 54271 &amp;gt; 45195 [ACK] Seq=25322
&lt;/pre&gt;

&lt;p&gt; Everything is normal up to packet 35. Then, ethernet is suspended
for five seconds and TCP takes a further second to recover, which
causes a buffer overrun on the GTH (172.16.2.5). The GTH closes the
socket at packet 50 and also sends an overrun event to the application
so that it knows why the socket was closed.
&lt;/p&gt;

&lt;h3&gt;Bottom line&lt;/h3&gt;

&lt;p&gt;
GTH uses IP for control and traffic. It is important that the IP link
between the GTH and the server is simple and reliable. Ideally the GTH
and server should be in the same rack and be connected by an ethernet
switch.
&lt;/p&gt;

&lt;p&gt; It&#39;s possible for a system to survive a short interruption (less
than a second) to the ethernet traffic without pre-recorded calls
getting interrupted. For longer interruptions, all bets are off.  &lt;/p&gt;

&lt;p&gt; (Interruptions aren&#39;t the only type of network problem, e.g. radio
networks such as 802.11 can suffer significant packet loss, which can
trigger TCP congestion avoidance. But that&#39;s another
topic.) &lt;/p&gt;
</description>
	</item>
	
	<item>
		<title>Capturing SS7 with wireshark or tshark</title>
		<link>./Capturing_SS7_with_wireshark_or_tshark.html</link>
		<guid isPermaLink="true">./Capturing_SS7_with_wireshark_or_tshark.html</guid>
                <pubDate>Mon, 10 Aug 2009 20:40:39 +0200</pubDate>
		<description>&lt;p&gt;
I often use wireshark to look at SS7 signalling on E1 links. Up until
today, I&#39;ve always done that by capturing the signalling (from a GTH),
then converting the captured data to libpcap format and finally
loading the file into wireshark.
&lt;/p&gt;

&lt;p&gt;
Someone showed me a better way today: wireshark can read from a pipe
or from standard input. That lets me see and filter the packets in
wireshark in real time. Here&#39;s how to do it, using the save_to_pcap
demo program (included in &lt;a
href=&quot;http://www.corelatus.com/gth/api/gth_c_examples.zip&quot;&gt;gth_c_examples&lt;/a&gt;):
&lt;/p&gt;

&lt;pre&gt;
&gt; ./save_to_pcap gth21 1A 2A 16 - | wireshark -k -i -
capturing packets, press ^C to abort
saving capture to stdout
&lt;/pre&gt;

The same thing works for tshark:

&lt;pre&gt;
 &gt;./save_to_pcap gth21 1A 2A 16 - | tshark -V -i -
capturing packets, press ^C to abort
saving capture to stdout
Capturing on -
Frame 1 (15 bytes on wire, 15 bytes captured)
    Arrival Time: Aug 10, 2009 20:38:29.388000000
...
   Message Transfer Part Level 2
    .000 1101 = Backward sequence number: 13
    1... .... = Backward indicator bit: 1
    .011 1000 = Forward sequence number: 56
    1... .... = Forward indicator bit: 1
    ..00 0000 = Length Indicator: 0
    00.. .... = Spare: 0
...
&lt;/pre&gt;

&lt;h3&gt;A few rough edges&lt;/h3&gt;

&lt;p&gt;
Piping to wireshark/tshark works on all the *nixes, i.e. linux, BSD,
OSX, Solaris, but for some reason it doesn&#39;t work on windows. On
Windows, you have to save the pcap files and open them. I&#39;m not sure
why that is, but then again I rarely use windows, so maybe there&#39;s
some easy way around that. If someone knows, send me some mail, or
comment.
&lt;/p&gt;

&lt;p&gt;
Wireshark needs both the -i and -k switches for piping to work. That
took me a while to figure out. Seems unnecessary.
&lt;/p&gt;

&lt;p&gt;
On some older (as of August 2009) versions of wireshark, possibly in
combination with older libraries, the &quot;-i -&quot; switch doesn&#39;t work, at
least according to google, even though the tshark version works. Both
work fine for me on Debian Linux.
&lt;/p&gt;</description>
	</item>
	
	<item>
		<title>Generating DTMF using a &amp;#039;player&amp;#039; on GTH</title>
		<link>./Generating_DTMF_using_a___039_player__039__on_GTH.html</link>
		<guid isPermaLink="true">./Generating_DTMF_using_a___039_player__039__on_GTH.html</guid>
                <pubDate>Tue, 9 Jun 2009 12:31:17 +0200</pubDate>
		<description>&lt;p&gt;
The GTH can &lt;em&gt;transmit&lt;/em&gt; in-band signalling tones on a
timeslot. That&#39;s useful for testing and for building active in-band
signalling systems.
&lt;/p&gt;

&lt;h3&gt;DTMF&lt;/h3&gt;

&lt;p&gt;
The tones transmitted when the subscriber presses a number key on
fixed or mobile handset are called DTMF. Wikipedia has an &lt;a
href=&quot;http://en.wikipedia.org/wiki/DTMF&quot;&gt;article&lt;/a&gt; about it. To
generate DTMF, all we really need to know is that there are 16
possible DTMF signals, that each signal is made up of two sine waves
of particular frequencies and that sending the signal for 100ms is a
reasonable thing to do.
&lt;/p&gt;

&lt;p&gt;
Here&#39;s a .zip file with &lt;a
href=&quot;http://www.corelatus.com/~matthias/blog/dtmf_tones.zip&quot;&gt;DTMF
tones&lt;/a&gt; in it. Each file is raw ALAW data, i.e. it&#39;s ready for the
GTH to play (transmit) on a timeslot.
&lt;/p&gt;

&lt;p&gt;
The GTH has two ways of playing tones. One way is to stream the audio
data in over a TCP socket each time we want to play it. I wrote a &lt;a
href=&quot;http://blog.corelatus.com/2009/03/06/gth-audio-streaming-why-stream-over-tcp/&quot;&gt;post
about that&lt;/a&gt; earlier. The other way is to store the sample data on
the GTH and command its playback whenever it&#39;s needed. Since there&#39;s a
small number of different tones (12, or 16 if you want to use the
A/B/C/D tones as well) and the tones are short, storing them on the
GTH makes sense. To store the tone:
&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;new&amp;gt;&amp;lt;clip &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;name&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;dtmf5&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;&amp;gt;&amp;lt;/new&amp;gt;&lt;/span&gt;
(and now send the 800 byte file)
&lt;/code&gt;
&lt;/pre&gt;

to play the tone later on:

&lt;pre&gt;
&lt;code&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;new&amp;gt;&amp;lt;player&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;clip &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;clip dtmf5&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;pcm_sink &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;span&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;timeslot&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;19&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/player&amp;gt;&amp;lt;/new&amp;gt;&lt;/span&gt; 
&lt;/code&gt;
&lt;/pre&gt;

&lt;h3&gt;Sequences of tones&lt;/h3&gt;

&lt;p&gt;
Sometimes you want to transmit a sequence of DTMF tones, for instance to simulate a subscriber dialling a number. The GTH lets you start a player with a sequence of tones like this:
&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;new&amp;gt;&amp;lt;player&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;clip &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;clip dtmf5&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&amp;lt;clip &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;clip dtmf6&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&amp;lt;clip &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;clip dtmf8&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
   &lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;pcm_sink &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;span&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;3A&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt; &lt;/span&gt;&lt;span class=&quot;synType&quot;&gt;timeslot&lt;/span&gt;=&lt;span class=&quot;synConstant&quot;&gt;&#39;19&#39;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;synIdentifier&quot;&gt;&amp;lt;/player&amp;gt;&amp;lt;/new&amp;gt;&lt;/span&gt;
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;
But that isn&#39;t a valid sequence of DTMF tones. Why not? Because DTMF
expects a gap between tones. The cleanest way to handle that is to
define another clip consisting of just silence and putting it between
each tone. A good &#39;silence&#39; value on E1 lines is 0x54. 60ms (480
samples) is a reasonable length.
&lt;/p&gt;

&lt;h3&gt;Other in-band tones&lt;/h3&gt;

&lt;p&gt;
DTMF in-band signalling is used in pretty much all handsets
(telephones), mostly for dialling, but also to navigate menus in IVR
systems. But before SS7 became popular, in-band signalling in the form
of CAS and SS5 was even used to communicate call setup information
between exchanges. GTH can also generate those tones, but that can be
the subject of another post.
&lt;/p&gt;
</description>
	</item>
	
	<item>
		<title>Perl example code for GTH: SS7 ISUP decoding and playback/record</title>
		<link>./Perl_example_code_for_GTH__SS7_ISUP_decoding_and_playback_record.html</link>
		<guid isPermaLink="true">./Perl_example_code_for_GTH__SS7_ISUP_decoding_and_playback_record.html</guid>
                <pubDate>Thu, 28 May 2009 23:25:45 +0200</pubDate>
		<description>&lt;p&gt;
To help people get started, www.corelatus.com has some example code
for doing useful things with GTH units.
&lt;/p&gt;

&lt;p&gt;
Now it also has Perl example code. It does the same thing as the
python examples:
&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Enable an E1/T1 port
  &lt;/li&gt;&lt;li&gt;Start MTP-2 monitoring on a timeslot and decode SS7 ISUP (to print out when calls start and stop). I wrote a post a while back about &lt;a href=&quot;http://blog.corelatus.com/2009/03/25/decoding-mtp-3-and-isup/&quot;&gt;how to decode ISUP&lt;/a&gt;.
  &lt;/li&gt;&lt;li&gt;Dump the contents of a timeslot to a file (for later analysis)
  &lt;/li&gt;&lt;li&gt;Feed a file into a timeslot (for playback of previously captured files)
&lt;/li&gt;&lt;/ul&gt;

&lt;p&gt; It&#39;s built on top of a Perl module which provides a Perl API for a
subset of the &lt;a href=&quot;http://www.corelatus.com/gth/api/&quot;&gt;GTH API&lt;/a&gt;.
&lt;/p&gt;

&lt;h3&gt;A quick example&lt;/h3&gt;

&lt;p&gt; Here&#39;s a quick example of how it&#39;s used. We want to enable (turn
on) the first E1/T1 interface on a GTH module: &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
&lt;span class=&quot;synStatement&quot;&gt;my&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$api&lt;/span&gt; = gth_control-&amp;gt;&lt;span class=&quot;synStatement&quot;&gt;new&lt;/span&gt;(&lt;span class=&quot;synIdentifier&quot;&gt;$host&lt;/span&gt;);
&lt;span class=&quot;synIdentifier&quot;&gt;$api&lt;/span&gt;-&amp;gt;&lt;span class=&quot;synStatement&quot;&gt;send&lt;/span&gt;(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&amp;lt;set name=&#39;pcm&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;$span&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&#39;&amp;gt;&amp;lt;attribute name=&#39;mode&#39; value=&#39;E1&#39;/&amp;gt;&amp;lt;/set&amp;gt;&amp;quot;&lt;/span&gt;);
&lt;span class=&quot;synStatement&quot;&gt;defined&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;$api&lt;/span&gt;-&amp;gt;next_non_event()-&amp;gt;{ok} || &lt;span class=&quot;synStatement&quot;&gt;die&lt;/span&gt;(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;error from GTH (bogus PCM?)&amp;quot;&lt;/span&gt;);
&lt;span class=&quot;synIdentifier&quot;&gt;$api&lt;/span&gt;-&amp;gt;bye();
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;It&#39;s good for experimenting.&lt;/h3&gt;

&lt;p&gt; The Perl module the examples are based on, gth_control.pm, is at
a level which makes it useful for experiments and prototypes. To build
a full-fledged product on top of it, more work is needed.
&lt;/p&gt;

&lt;p&gt; For a start, you&#39;d probably want to move the XML generation (like
the &#39;&amp;lt;set name=...&#39; code above) out of the application code and
into the gth_control.pm module, thus making it a pure Perl interface.
&lt;/p&gt;

&lt;p&gt;
Next, you need to come up with a strategy to deal with concurrency, because being limited to recording one timeslot at a time is fine for lab work, but not fine for (say) a voicemail system.
&lt;/p&gt;

&lt;h3&gt;Download&lt;/h3&gt;

&lt;p&gt;
The zipfile of the code is linked from the bottom of the &lt;a
href=&quot;http://www.corelatus.com/gth/api/&quot;&gt;API page&lt;/a&gt;.
&lt;/p&gt;
</description>
	</item>
	
        </channel>
</rss>
