Implementation of a block for extracting immediate assignments from control channel messages. Currently only printing to terminal.
diff --git a/grc/gsm_block_tree.xml b/grc/gsm_block_tree.xml
index 3952fff..94d1d82 100644
--- a/grc/gsm_block_tree.xml
+++ b/grc/gsm_block_tree.xml
@@ -43,6 +43,7 @@
       <block>gsm_burst_sink</block>
       <block>gsm_burst_source</block>
       <block>gsm_extract_system_info</block>
+      <block>gsm_extract_immediate_assignment</block>
       <block>gsm_controlled_rotator_cc</block>
       <block>gsm_controlled_const_source_f</block>
       <block>gsm_message_printer</block>
diff --git a/grc/misc_utils/CMakeLists.txt b/grc/misc_utils/CMakeLists.txt
index aa7517c..d545692 100644
--- a/grc/misc_utils/CMakeLists.txt
+++ b/grc/misc_utils/CMakeLists.txt
@@ -19,6 +19,7 @@
 
 install(FILES
     gsm_extract_system_info.xml
+    gsm_extract_immediate_assignment.xml
     gsm_controlled_rotator_cc.xml
     gsm_controlled_const_source_f.xml
     gsm_message_printer.xml
diff --git a/grc/misc_utils/gsm_extract_immediate_assignment.xml b/grc/misc_utils/gsm_extract_immediate_assignment.xml
new file mode 100644
index 0000000..0f5635b
--- /dev/null
+++ b/grc/misc_utils/gsm_extract_immediate_assignment.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<block>
+  <name>Extract immediate assignment</name>
+  <key>gsm_extract_immediate_assignment</key>
+  <import>import grgsm</import>
+  <make>grgsm.extract_immediate_assignment()</make>
+
+  <sink>
+    <name>msgs</name>
+    <type>message</type>
+  </sink>  
+</block>
diff --git a/include/grgsm/misc_utils/CMakeLists.txt b/include/grgsm/misc_utils/CMakeLists.txt
index 3d3383a..3d63d46 100644
--- a/include/grgsm/misc_utils/CMakeLists.txt
+++ b/include/grgsm/misc_utils/CMakeLists.txt
@@ -25,6 +25,7 @@
     burst_sink.h
     burst_source.h
     extract_system_info.h
+    extract_immediate_assignment.h
     controlled_rotator_cc.h
     controlled_const_source_f.h
     message_printer.h 
diff --git a/include/grgsm/misc_utils/extract_immediate_assignment.h b/include/grgsm/misc_utils/extract_immediate_assignment.h
new file mode 100644
index 0000000..74e69a4
--- /dev/null
+++ b/include/grgsm/misc_utils/extract_immediate_assignment.h
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * @file
+ * @author Roman Khassraf <rkhassraf@gmail.com>
+ * @section LICENSE
+ *
+ * Gr-gsm is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * Gr-gsm is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gr-gsm; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+
+#ifndef INCLUDED_GSM_EXTRACT_IMMEDIATE_ASSIGNMENT_H
+#define INCLUDED_GSM_EXTRACT_IMMEDIATE_ASSIGNMENT_H
+
+#include <grgsm/api.h>
+#include <gnuradio/block.h>
+
+namespace gr {
+  namespace gsm {
+
+    /*!
+     * \brief <+description of block+>
+     * \ingroup gsm
+     *
+     */
+    class GSM_API extract_immediate_assignment : virtual public gr::block
+    {
+     public:
+      typedef boost::shared_ptr<extract_immediate_assignment> sptr;
+
+      /*!
+       * \brief Return a shared_ptr to a new instance of gsm::extract_immediate_assignment.
+       *
+       * To avoid accidental use of raw pointers, gsm::extract_immediate_assignment's
+       * constructor is in a private implementation
+       * class. gsm::extract_immediate_assignment::make is the public interface for
+       * creating new instances.
+       */
+      static sptr make();
+    };
+  } // namespace gsm
+} // namespace gr
+
+#endif /* INCLUDED_GSM_EXTRACT_IMMEDIATE_ASSIGNMENT_H */
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 4a88edb..7a8cf94 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -33,6 +33,7 @@
     receiver/cx_channel_hopper_impl.cc
     misc_utils/bursts_printer_impl.cc
     misc_utils/extract_system_info_impl.cc
+    misc_utils/extract_immediate_assignment_impl.cc
     demapping/universal_ctrl_chans_demapper_impl.cc
     demapping/tch_f_chans_demapper_impl.cc
     decoding/control_channels_decoder_impl.cc
diff --git a/lib/misc_utils/extract_immediate_assignment_impl.cc b/lib/misc_utils/extract_immediate_assignment_impl.cc
new file mode 100644
index 0000000..b7df803
--- /dev/null
+++ b/lib/misc_utils/extract_immediate_assignment_impl.cc
@@ -0,0 +1,200 @@
+/* -*- c++ -*- */
+/*
+ * @file
+ * @author Roman Khassraf <rkhassraf@gmail.com>
+ * @section LICENSE
+ *
+ * Gr-gsm is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * Gr-gsm is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gr-gsm; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gnuradio/io_signature.h>
+#include <grgsm/gsmtap.h>
+#include <unistd.h>
+#include <set>
+#include <iterator>
+#include <algorithm>
+#include <iostream>
+
+#include "extract_immediate_assignment_impl.h"
+
+namespace gr {
+  namespace gsm {
+    boost::mutex extract_immediate_assignment_mutex;
+
+    void extract_immediate_assignment_impl::process_message(pmt::pmt_t msg){
+        pmt::pmt_t message_plus_header_blob = pmt::cdr(msg);
+        uint8_t * message_plus_header = (uint8_t *)pmt::blob_data(message_plus_header_blob);
+        gsmtap_hdr * header = (gsmtap_hdr *)message_plus_header;
+        uint8_t * msg_elements = (uint8_t *)(message_plus_header+sizeof(gsmtap_hdr));
+        uint32_t frame_nr = be32toh(header->frame_number);
+
+        if(msg_elements[2]==0x3f)
+        {
+            std::cout << "\n------------------------------------------------------------------\n" << std::endl;
+            std::cout << "Immediate assignment found !" << std::endl;
+            std::cout << "FrameNr: " << (unsigned)frame_nr << std::endl;
+
+            uint8_t mode = msg_elements[3] & (1 << 4);
+
+            /*
+                channel description, see table 10.23 in GSM 04.08
+
+                msg_elements[4], octet 2 in specs
+
+                5 bits channel type
+                    ignored in TBF
+                    00001   TCH/F
+                    0001T   TCH/H, subchannel/TDMA offset T
+                    001TT   SDCCH/4, subchannel/TDMA offset TT
+                    01TTT   SDCCH/8, subchannel/TDMA offset TTT
+                3 bits timeslot number TN
+            */
+            uint8_t channeltype = (msg_elements[4] >> 3);
+            uint8_t timeslot = (msg_elements[4] & 7);
+            uint8_t subchannel;
+            std::string channel_type;
+
+            std::cout << "Timeslot: " << (unsigned)timeslot << std::endl;
+
+            if (mode == 0)
+            {
+                if (channeltype >= 8)
+                {
+                    channel_type = "SDCCH/8";
+                    subchannel = (channeltype & 7);
+                }
+                else if (channeltype >= 4 && channeltype <= 7)
+                {
+                    channel_type = "SDCCH/4";
+                    subchannel = (channeltype & 3);
+                }
+                else if (channeltype >= 2 && channeltype <= 3)
+                {
+                    channel_type = "TCH/H";
+                    subchannel = (channeltype & 1);
+                }
+                else
+                {
+                    channel_type = "TCH/F";
+                    subchannel = 0;
+                }
+
+                std::cout << "Channel type: " << channel_type << std::endl;
+                std::cout << "Subchannel: " << (unsigned)subchannel << std::endl;
+            }
+            else
+            {
+                std::cout << "Channel type: " << "GPRS - Temporary Block Flow TBF" << std::endl;
+            }
+
+            /*
+                msg_elements[5], msg_elements[6] are octets 3 and 4 in specs
+
+                    3 bits training sequence (we dont process this for the moment)
+                    1 bit hopping channel H
+
+                    if H = 0:
+                        2 bit spare
+                        2 bit high part of single channel arfcn
+
+                        8 bit low part of single channel arfcn
+
+                    if H = 1:
+                        4 bit high part of MAIO
+
+                        2 bit low part of MAIO
+                        6bit HSN
+            */
+            uint8_t hopping = (msg_elements[5] >> 4) & 1;
+
+            std::cout << "Hopping: " << (unsigned)hopping << std::endl;
+
+            if (hopping)
+            {
+                uint8_t maio = (msg_elements[5] & 0xf) << 2;
+                maio |= (msg_elements[6] >> 6);
+
+                uint8_t hsn = (msg_elements[6] & 0x3f);
+
+                std::cout << "MAIO: " << (unsigned)maio << std::endl;
+                std::cout << "HSN: " << (unsigned)hsn << std::endl;
+            }
+            else
+            {
+                uint16_t arfcn = (msg_elements[5] & 3) << 8;
+                arfcn |= msg_elements[6];
+
+                std::cout << "ARFCN: " << (unsigned)arfcn << std::endl;
+            }
+
+            // request reference as ID in set, so we get only one immediate assignment per reference
+            /*
+                msg_elements[7 - 9], octets 5 - 7 in specs : request reference, maybe later
+
+                msg_elements[10]:   timing advance
+            */
+            uint8_t timing_advance = msg_elements[10];
+            std::cout << "TA: " << (unsigned)timing_advance << std::endl;
+
+            /*
+                msg_elements[11] - 20:   mobile allocation, flexible length, see 10.5.2.21
+            */
+
+            uint8_t mobile_allocation_len = msg_elements[11];
+            if (mobile_allocation_len > 0)
+            {
+                uint8_t mobile_allocation[mobile_allocation_len];
+                for (int i=0; i<mobile_allocation_len; i++)
+                {
+                    mobile_allocation[i] = msg_elements[12 + i];
+                    std::cout << "MA: " << (unsigned)mobile_allocation[i] << std::endl;
+                }
+            }
+        }
+    }
+
+    extract_immediate_assignment::sptr
+    extract_immediate_assignment::make()
+    {
+      return gnuradio::get_initial_sptr
+        (new extract_immediate_assignment_impl());
+    }
+
+    /*
+     * The private constructor
+     */
+    extract_immediate_assignment_impl::extract_immediate_assignment_impl()
+      : gr::block("extract_immediate_assignment",
+              gr::io_signature::make(0, 0, 0),
+              gr::io_signature::make(0, 0, 0))
+    {
+        message_port_register_in(pmt::mp("msgs"));
+        set_msg_handler(pmt::mp("msgs"), boost::bind(&extract_immediate_assignment_impl::process_message, this, _1));
+    }
+
+    /*
+     * Our virtual destructor.
+     */
+    extract_immediate_assignment_impl::~extract_immediate_assignment_impl()
+    {
+    }
+  } /* namespace gsm */
+} /* namespace gr */
+
diff --git a/lib/misc_utils/extract_immediate_assignment_impl.h b/lib/misc_utils/extract_immediate_assignment_impl.h
new file mode 100644
index 0000000..2bb9538
--- /dev/null
+++ b/lib/misc_utils/extract_immediate_assignment_impl.h
@@ -0,0 +1,43 @@
+/* -*- c++ -*- */
+/*
+ * @file
+ * @author Roman Khassraf <rkhassraf@gmail.com>
+ * @section LICENSE
+ *
+ * Gr-gsm is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * Gr-gsm is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gr-gsm; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GSM_EXTRACT_IMMEDIATE_ASSIGNMENT_IMPL_H
+#define INCLUDED_GSM_EXTRACT_IMMEDIATE_ASSIGNMENT_IMPL_H
+
+#include <grgsm/misc_utils/extract_immediate_assignment.h>
+
+
+namespace gr {
+  namespace gsm {
+
+    class extract_immediate_assignment_impl : public extract_immediate_assignment
+    {
+    private:
+        void process_message(pmt::pmt_t msg);
+    public:
+      extract_immediate_assignment_impl();
+      ~extract_immediate_assignment_impl();
+    };
+  } // namespace gsm
+} // namespace gr
+
+#endif /* INCLUDED_GSM_EXTRACT_IMMEDIATE_ASSIGNMENT_IMPL_H */
diff --git a/swig/grgsm_swig.i b/swig/grgsm_swig.i
index f1f37bf..79831f8 100644
--- a/swig/grgsm_swig.i
+++ b/swig/grgsm_swig.i
@@ -20,6 +20,7 @@
 #include "grgsm/misc_utils/controlled_const_source_f.h"
 #include "grgsm/misc_utils/controlled_rotator_cc.h"
 #include "grgsm/misc_utils/extract_system_info.h"
+#include "grgsm/misc_utils/extract_immediate_assignment.h"
 #include "grgsm/misc_utils/message_printer.h"
 #include "grgsm/misc_utils/tmsi_dumper.h"
 #include "grgsm/misc_utils/burst_sink.h"
@@ -55,6 +56,8 @@
 GR_SWIG_BLOCK_MAGIC2(gsm, burst_source);
 %include "grgsm/misc_utils/extract_system_info.h"
 GR_SWIG_BLOCK_MAGIC2(gsm, extract_system_info);
+%include "grgsm/misc_utils/extract_immediate_assignment.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, extract_immediate_assignment);
 %include "grgsm/misc_utils/controlled_rotator_cc.h"
 GR_SWIG_BLOCK_MAGIC2(gsm, controlled_rotator_cc);
 %include "grgsm/misc_utils/controlled_const_source_f.h"