<?xml version="1.0" encoding="utf-8"?>
<rss version='2.0' xmlns:lj='http://www.livejournal.org/rss/lj/1.0/'>
	<channel>
		<title>The Corelatus Blog - Entries tagged erlang</title>
		<description>Entries tagged erlang</description>
                <link>../../</link>

	
	<item>
		<title>Erlang example code for GTH</title>
		<link>../../Erlang_example_code_for_GTH.html</link>        
		<guid isPermaLink="true">../../Erlang_example_code_for_GTH.html</guid>
                <pubDate>Sun, 1 Feb 2009 16:55:04 GMT</pubDate>
		<description>&lt;p&gt;
Years ago, I wrote a few bits of example code to help customers get
started with controlling a &lt;a
href=&quot;http://www.corelatus.com/&quot;&gt;GTH&lt;/a&gt;.  If you were kind, you&#39;d
call them minimal, e.g. the Erlang one was about 20 lines long.
&lt;/p&gt;

&lt;p&gt; None of our customers that use Erlang were very impressed by that,
so I&#39;d hand out part of the code we use to do API testing (a cut-down
XML parser and a little library to handle sockets) along with sternly
issued instructions that this was just example code and that live
systems needed something more robust. Not great, but I had other
things to do.  &lt;/p&gt;

&lt;p&gt;
I finally got around to completing and releasing a proper native
Erlang API for the GTH. No (visible) XML. It&#39;s a gen_server, so it&#39;s
well-behaved and simple enough so that you can do almost anything from
the Erlang shell, e.g. to turn on an E1:
&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&lt;/span&gt; {ok, A} &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;gth:start_link&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;synSpecial&quot;&gt;.&lt;/span&gt;
{ok, &lt;span class=&quot;synStatement&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;0.44&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&lt;/span&gt;}
&lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;gth:set&lt;/span&gt;(A, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;pcm1B&amp;quot;&lt;/span&gt;, [{&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;status&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;enabled&amp;quot;&lt;/span&gt;}])&lt;span class=&quot;synSpecial&quot;&gt;.&lt;/span&gt;
ok
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;
and put an audio file on a timeslot:
&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
&lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&lt;/span&gt; {ok, Bin} &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;file:read_file&lt;/span&gt;(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;/tmp/resample_q_alaw.raw&amp;quot;&lt;/span&gt;)&lt;span class=&quot;synSpecial&quot;&gt;.&lt;/span&gt;
{ok,&lt;span class=&quot;synStatement&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;}
&lt;span class=&quot;synConstant&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&lt;/span&gt; {ok, _ID, P_socket} &lt;span class=&quot;synStatement&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;gth:new_tcp_player&lt;/span&gt;(A, &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;1B&amp;quot;&lt;/span&gt;, &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;)&lt;span class=&quot;synSpecial&quot;&gt;.&lt;/span&gt;
{ok,&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;strp1&amp;quot;&lt;/span&gt;,#Port&lt;span class=&quot;synStatement&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;0.1097&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&lt;/span&gt;}
&lt;span class=&quot;synConstant&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;gen_tcp:send&lt;/span&gt;(P_socket, Bin)&lt;span class=&quot;synSpecial&quot;&gt;.&lt;/span&gt;
ok
&lt;span class=&quot;synConstant&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&lt;/span&gt; flush()&lt;span class=&quot;synSpecial&quot;&gt;.&lt;/span&gt;
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;
There&#39;s a direct mapping between GTH commands and function names in
the gth.erl module, e.g. the XML &amp;lt;set&amp;gt; command becomes
gth:set(). While writing the gth.erl module, I also rewrote our entire
API test suite (60 modules, 30kloc) to use the gth.erl interface. It
ended up under 20kloc. I&#39;d guess half of that reduction comes from
gth.erl being nicer to use and the other half comes from cleaning up
&quot;while I was at it&quot;.
&lt;/p&gt;

&lt;p&gt;
The code, with examples: &lt;a
href=&quot;http://www.corelatus.com/gth/api/gth_erlang_api.zip&quot;&gt;gth_erlang_api.zip&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
While writing gth.erl, I had a go at doing something similar in
Python. But that&#39;s another story.
&lt;/p&gt;
</description>
	</item>
	
	<item>
		<title>Decoding MTP-3 and ISUP</title>
		<link>../../Decoding_MTP_3_and_ISUP.html</link>        
		<guid isPermaLink="true">../../Decoding_MTP_3_and_ISUP.html</guid>
                <pubDate>Wed, 25 Mar 2009 13:55:20 GMT</pubDate>
		<description>&lt;p&gt;
  Sometimes, you want to look at the signalling on an E1 and use
  it to figure out when telephone calls start and stop. In SS7 networks,
  call setup and tear-down is done by the ISUP layer, which fits in to
  the SS7 stack like this:
&lt;/p&gt;

Layer 4: ISUP&lt;br/&gt;
Layer 3: MTP-3&lt;br/&gt;
Layer 2: MTP-2&lt;br/&gt;
Layer 1: MTP-1 (typically an 2Mbit/s E1 or a 1.5Mbit/s/T1)&lt;br/&gt;

&lt;p&gt;
  If you have a &lt;a href=&quot;http://www.corelatus.com/&quot;&gt;GTH&lt;/a&gt; connected to
  the E1 you&#39;re interested in, either via a DXC or a monitor point, the
  GTH takes care of layers one and two. That leaves MTP-3 and ISUP to
  you.
&lt;/p&gt;

&lt;p&gt;
  The easiest way to decode MTP-3 and ISUP is to let &lt;a
							href=&quot;http://www.wireshark.org/&quot;&gt;wireshark&lt;/a&gt; do it for you. There&#39;s
  a &lt;a
       href=&quot;//www.corelatus.com/gth/api/save_to_pcap/index.html&quot;&gt;note&lt;/a&gt;
  about how to do that on Corelatus&#39; official site. But this blog entry
  is about how to decode MTP-3 and ISUP yourself.
&lt;/p&gt;

&lt;h3&gt;A signal unit (packet)&lt;/h3&gt;

&lt;p&gt;
  In SS7, packets are usually called &quot;signal units&quot;. Here&#39;s what an SS7
  signal unit looks like &#39;on the wire&#39;, octet by octet, with MTP-2 and
  MTP-1 already decoded:
&lt;/p&gt;

&lt;pre&gt;
  8d c8 1f 85 02 40 00 00  35 00 01 00 21 00 0a 02
  02 08 06 01 10 12 52 55  21 0a 06 07 01 11 13 53
  55 00 6e 00
&lt;/pre&gt;

&lt;h3&gt;MTP-3&lt;/h3&gt;

&lt;p&gt; The start of the packet is the MTP-2 (ITU-T Q.703) and MTP-3
  (ITU-T Q.704) headers. These headers are easy to decode because they
  are always fixed-length:
&lt;/p&gt;

&lt;table style=&quot;height:118px;&quot; border=&quot;0&quot;&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;th&gt;Octet(s)&lt;/th&gt;
      &lt;th&gt;Value&lt;/th&gt;
      &lt;th&gt;Purpose&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;00--01&lt;/td&gt;
      &lt;td&gt;8d c8&lt;/td&gt;
      &lt;td&gt;MTP-2 sequence numbers, safe to ignore&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;02&lt;/td&gt;
      &lt;td&gt;1f&lt;/td&gt;
      &lt;td&gt;MTP-2 length indicator. Anything less than 3 is reserved for MTP-2 itself and should be discarded.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;03&lt;/td&gt;
      &lt;td&gt;85&lt;/td&gt;
      &lt;td&gt;MTP-2 SIO. The SIO tells us which &#39;service&#39; the signal unit is intended for. Q.704 sections14.2.1 and 14.2.2 tell us that anything ending in hex 5 is for ISUP.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;04--07&lt;/td&gt;
      &lt;td&gt;02 40 00 00&lt;/td&gt;
      &lt;td&gt;MTP-3 Routing label. The routing label is just a &quot;from&quot; and &quot;to&quot; address in the SS7 network. For most applications we can ignore it. Q.704 figure 3 shows what&#39;s in the routing label.&lt;/td&gt;
    &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;
  Upshot: to see calls start and stop, all we have to do for MTP-3 is:
&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Look at the length indicator (offset 2) and discard 
    any signal unit where it&#39;s less than 3.&lt;/li&gt;

  &lt;li&gt;Look at the SIO (offset 3). Discard if (SIO &amp;amp; 0x0f != 5)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;ISUP&lt;/h3&gt;

&lt;p&gt;
  The rest of the signal unit is ISUP. Annex C in ITU-T Q.767 tells us how to decode ISUP. ISUP is fiddly because there are several types of ISUP packets, because several of those types have optional fields and because some of those fields are variable length. Here are the octets we have left after removing MTP-2 and MTP-3:
&lt;/p&gt;

&lt;pre&gt;
  35 00 01 00 21 00 0a 02  
  02 08 06 01 10 12 52 55 
  21 0a 06 07 01 11 13 53 
  55 00 6e 00
&lt;/pre&gt;

&lt;p&gt;
  The first two octets are the CIC. The third octet is the Message type.
&lt;/p&gt;

&lt;p&gt; The &lt;strong&gt;CIC&lt;/strong&gt; (Q.767 C.1.2) tells us which circuit this
  call uses. All the signalling for one call has the same CIC. In ITU
  networks, it&#39;s a 12-bit value packed into the field in little-endian
  byte order. In this case CIC=0x0035. We&#39;re sniffing an E1 line, so
  C.1.2.a tells us that the lower five bits correspond to the timeslot
  (timeslot 5) and the rest identifies the E1 itself.  &lt;/p&gt;

&lt;p&gt; The &lt;strong&gt;Message Type&lt;/strong&gt; (Q.767 Table C-3) field tells us
  what sort of ISUP message this signal unit is. 0x01 is an IAM. 0x10 is
  RLC. For a minimal &quot;show me what calls are going through the system&quot;
  hack, we only need to look at the IAM (comes at the start of the call,
  contains the A and B numbers) and the RLC (sent when the call is
  finished) messages.
&lt;/p&gt;

&lt;p&gt; Now we know that the CIC=0x35, that the message is an IAM and we
  still have about a dozen octets to decode. Q.767 table C-16 tells us
  how to decode an IAM. There are some uninteresting fixed-length fields
  followed by the B number and then the A number. Look at the code (or
  Q.767, section C.3.7) if you&#39;re interested in the details. All we
  really care about is that these octets &lt;/p&gt;

&lt;pre&gt;
  06 01 10 12 52 55 21
&lt;/pre&gt;

&lt;p&gt; represent the B number: 21255512. You can see the number in the
  raw data if you skip the first three octets and swap every second
  digit.  &lt;/p&gt;

&lt;p&gt;
  Turning those ISUP steps into an algorithm to decode one signal unit:
&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Save the CIC&lt;/li&gt;
  &lt;li&gt;Is the message an IAM? Decode it as an IAM, which is fiddly.&lt;/li&gt;
  &lt;li&gt;Is the message an RLC? Just print the CIC.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt; That&#39;s all you need to do to make a simple system which prints the
  start and end of each call. To do something useful, you need to
  maintain a table of in-progress calls and match up the IAM and RLC
  messages with the same CIC. You also need to handle things like
  systems restarting.  &lt;/p&gt;

&lt;h3&gt;Further reading&lt;/h3&gt;

&lt;p&gt; The ITU now have most of their standards freely available at
  www.itu.int. So one way to learn more about MTP-3 and ISUP is to read
  the standards, e.g. all the Q-series standards about signalling are &lt;a
									 href=&quot;http://www.itu.int/rec/T-REC-Q/en&quot;&gt;here&lt;/a&gt;.  &lt;/p&gt;

&lt;h3&gt;Erlang code&lt;/h3&gt;

&lt;p&gt; Everything discussed above is implemented in the ss7_sniffer.erl
  &lt;a
     href=&quot;http://www.corelatus.com/gth/api/gth_erlang_api.zip&quot;&gt;example&lt;/a&gt;
  on corelatus.com. It makes good use of Erlang&#39;s binary syntax,
  e.g. here&#39;s the MTP-3 decoder:
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
    mtp3(&lt;span class=&quot;synStatement&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;_Sub:4&lt;/span&gt;, &lt;span class=&quot;synIdentifier&quot;&gt;Service_indicator:4&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;, &lt;span class=&quot;synStatement&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;DPC:14&lt;/span&gt;, &lt;span class=&quot;synIdentifier&quot;&gt;OPC:14&lt;/span&gt;, &lt;span class=&quot;synIdentifier&quot;&gt;SLS:4&lt;/span&gt;,
						    Rest&lt;span class=&quot;synStatement&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;synIdentifier&quot;&gt;binary&lt;/span&gt;&lt;span class=&quot;synStatement&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;) &lt;span class=&quot;synStatement&quot;&gt;-&amp;gt;&lt;/span&gt; 
	&lt;span class=&quot;synStatement&quot;&gt;case&lt;/span&gt; Service_indicator &lt;span class=&quot;synStatement&quot;&gt;of&lt;/span&gt; 
	&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;synComment&quot;&gt;% Management &lt;/span&gt;
        ignore; 
	&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;synComment&quot;&gt;% Test/maintenance &lt;/span&gt;
        ignore; 
	&lt;span class=&quot;synConstant&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;synComment&quot;&gt;% SCCP &lt;/span&gt;
        ignore; 
	&lt;span class=&quot;synConstant&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;-&amp;gt;&lt;/span&gt; 
        isup(DPC, OPC, SLS, Rest); 
	&lt;span class=&quot;synConstant&quot;&gt;9&lt;/span&gt; &lt;span class=&quot;synStatement&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;synComment&quot;&gt;% B-ISUP; similar to ISUP, but not compatible. &lt;/span&gt;
        ignore; 
	X &lt;span class=&quot;synStatement&quot;&gt;-&amp;gt;&lt;/span&gt; 
        &lt;span class=&quot;synIdentifier&quot;&gt;io:fwrite&lt;/span&gt;(&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;ignoring SU with unexpected service indicator=&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;~p\n&lt;/span&gt;&lt;span class=&quot;synConstant&quot;&gt;&amp;quot;&lt;/span&gt;, [X]) 
	&lt;span class=&quot;synStatement&quot;&gt;end&lt;/span&gt;&lt;span class=&quot;synSpecial&quot;&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
  It looks a lot like one of the examples in the original paper about
  the binary syntax.
&lt;/p&gt;

&lt;h3&gt;Python Code&lt;/h3&gt;

&lt;p&gt;
  The same thing done in Python is fairly straightforward once you
  discover the Python &#39;struct&#39; library, which is basically the same
  thing as PERL&#39;s pack/unpack. The code is in sniff_isup.py, inside the
  &lt;a href=&quot;http://www.corelatus.com/gth/api/gth_python_examples.zip&quot;&gt;GTH
    python examples&lt;/a&gt; zip.
&lt;/p&gt;

&lt;p&gt;
  It feels like I haven&#39;t discovered whatever it is python people use to
  unpack bitfields, e.g. something neater than:
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
    is_even = ((&lt;span class=&quot;synIdentifier&quot;&gt;ord&lt;/span&gt;(num[&lt;span class=&quot;synConstant&quot;&gt;1&lt;/span&gt;]) &amp;amp;amp; &lt;span class=&quot;synConstant&quot;&gt;0x80&lt;/span&gt;) == &lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;
  or, better still, a clean way to decode the MTP-3 routing label.
&lt;/p&gt;


&lt;!-- ============================== --&gt;
&lt;div class=&quot;comments&quot;&gt;
  &lt;h2&gt;Comments&lt;/h2&gt;
  &lt;h4&gt;Bartosz, 28. January 2010&lt;/h4&gt;

  &lt;p&gt;
    Hey. Just stumbled on this page while I was googling after Mtp3
    procedures. I&#39;m wondering if you have any materials that you could
    share regarding link setup - I&#39;m working on open source stacks for
    ss7. Im able to setup mtp2,3 and layer 4(signle link), now I&#39;m working
    on getting it work with more than one and frankly Qs for mtp3 are not
    very helpful.
  &lt;/p&gt;
  &lt;p&gt;
    &lt;a href=&quot;http://mobicents.org&quot;&gt;(website)&lt;/a&gt;
  &lt;/p&gt;


  &lt;!-- ============================== --&gt;
  &lt;h4&gt;Matt, 28. January 2010&lt;/h4&gt;

  &lt;p&gt;
    @Bartosz: I only really work with MTP2. My customers use MTP3, so I
    know quite a bit about it, but you probably know more. For MTP2, the
    standard is difficult to read, but comprehensive. MTP3 seems harder. I
    have a copy of &quot;Signalling in Telecommunications Networks&quot; by van
    Bosse et al, it&#39;s useful for getting started, but I always end up
    trudging through the standards.
  &lt;/p&gt;

  &lt;p&gt;
    Interesting to see someone working on an open SS7 stack. Up until now,
    I&#39;ve only been aware of openss7.org (written in C, some parts seem
    complete, the project seems to be a one-man effort).
  &lt;/p&gt;

  &lt;p&gt;
    Or: I don&#39;t think I can help much, but what you&#39;re doing looks interesting.
  &lt;/p&gt;

  &lt;p&gt;
    Matt
  &lt;/p&gt;

  &lt;!-- ============================== --&gt;
  &lt;h4&gt;Emza, September 15, 2009&lt;/h4&gt;

  &lt;p&gt;
    I found it very important but still not enough for me.  I was looking
    for ISUP MTP-3 and ISUP decoding in C or in C#(not only start and end
    singnal unit but general which includes all message types).  I would
    like to thank you but can help in my case please.
  &lt;/p&gt;

  &lt;p&gt;
    Thanks again&lt;br/&gt;
    Embza
  &lt;/p&gt;

  &lt;!-- ============================== --&gt;
  &lt;h4&gt;Matt, September 15, 2009&lt;/h4&gt;

  &lt;p&gt;
    @Emza, decoding the rest of the message types is &#39;just&#39; a matter of
    working your way through ITU-T Q.767 (ITU standards are now available
    for free at http://www.itu.int) and writing code to handle each and
    every section in the standard. Same basic idea as the messages I
    did. Doing it all is a few days of drudge work, which is why I haven&#39;t
    done it here.
  &lt;/p&gt;

  &lt;p&gt;
    About doing it in C or C#. I know nothing about C#. I work with C most
    days, though. Doing this sort of protocol decoding in C is fairly
    straightforward, but it&#39;s inevitably going to be more tedious than
    doing it in something like python, perl or erlang. In some
    applications the performance gain might be worth the extra effort.
  &lt;/p&gt;

  &lt;!-- ============================= --&gt;
  &lt;h4&gt;Meskerem David, September 15, 2009&lt;/h4&gt;

  &lt;p&gt;
    It is a great job. Keep working...
  &lt;/p&gt;

  &lt;p&gt;
    Can u please me one brief algorithm of decoding ISUP. Especially I am
    not clear how to decode the variable length parameters and the
    optional ones.
  &lt;/p&gt;

  &lt;p&gt;
    Thanks&lt;br/&gt;
    Meskerem
  &lt;/p&gt;

  &lt;!-- ============================== --&gt;
  &lt;h4&gt;Matt, September 15, 2009&lt;/h4&gt;

  &lt;p&gt;
    @Meskerem, In an IAM, the A-number and B-number parameters are
    variable length. The algorithm for finding the start is trivial, it&#39;s
    just a pointer offset. Here&#39;s what it looks like in the python example
    code:
  &lt;/p&gt;

  &lt;pre&gt;
    &lt;code&gt;

      &lt;span class=&quot;synStatement&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;isup_iam&lt;/span&gt;(_, CIC, sif):
      &lt;span class=&quot;synComment&quot;&gt;# First 5 octets can be ignored&lt;/span&gt;
      bnum_pointer = &lt;span class=&quot;synIdentifier&quot;&gt;ord&lt;/span&gt;(sif[&lt;span class=&quot;synConstant&quot;&gt;5&lt;/span&gt;])
      anum_pointer = &lt;span class=&quot;synIdentifier&quot;&gt;ord&lt;/span&gt;(sif[&lt;span class=&quot;synConstant&quot;&gt;6&lt;/span&gt;])
      bnum = sif[&lt;span class=&quot;synConstant&quot;&gt;5&lt;/span&gt; + bnum_pointer:]
      anum = sif[&lt;span class=&quot;synConstant&quot;&gt;7&lt;/span&gt; + anum_pointer:]
      &lt;span class=&quot;synIdentifier&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;synConstant&quot;&gt;&amp;quot;IAM called party: %s calling party: %s CIC=%d&amp;quot;&lt;/span&gt; &lt;span class=&quot;synSpecial&quot;&gt;\&lt;/span&gt;
      % (isup_number(bnum), isup_number(anum), CIC)

      &lt;span class=&quot;synComment&quot;&gt;# And here&#39;s how the example code figures out the length:&lt;/span&gt;

      &lt;span class=&quot;synComment&quot;&gt;# Decode an ISUP number, as per C 3.7&lt;/span&gt;
      &lt;span class=&quot;synStatement&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;synIdentifier&quot;&gt;isup_number&lt;/span&gt;(num):
      length = &lt;span class=&quot;synIdentifier&quot;&gt;ord&lt;/span&gt;(num[&lt;span class=&quot;synConstant&quot;&gt;0&lt;/span&gt;]) - &lt;span class=&quot;synConstant&quot;&gt;2&lt;/span&gt;
    
&lt;/code&gt;
  &lt;/pre&gt;

  &lt;p&gt;
    the complete code is at
    http://www.corelatus.com/gth/api/gth_python_examples.zip
  &lt;/p&gt;

  &lt;p&gt;
    (the site also has exactly the same decoding routines in Perl and Erlang)
  &lt;/p&gt;
&lt;/div&gt;

</description>
	</item>
	
        </channel>
</rss>
