Moved trx utilities from apps subdirectory - the grgsm_trx app need to be updated
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt
index ec04f1f..855b2ed 100644
--- a/apps/CMakeLists.txt
+++ b/apps/CMakeLists.txt
@@ -28,6 +28,7 @@
     grgsm_livemon_headless
     grgsm_scanner
     grgsm_decode
+    grgsm_trx
     DESTINATION bin
 )
 
diff --git a/apps/grgsm_trx b/apps/grgsm_trx
new file mode 100755
index 0000000..fbc9350
--- /dev/null
+++ b/apps/grgsm_trx
@@ -0,0 +1,155 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# GR-GSM based transceiver
+#
+# (C) 2016-2017 by Vadim Yanitskiy <axilirator@gmail.com>
+#
+# All Rights Reserved
+#
+# This program 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 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import signal
+import getopt
+import sys
+
+from ctrl_if_bb import CTRLInterfaceBB
+from radio_if import RadioInterface
+from fake_pm import FakePM
+
+COPYRIGHT = \
+	"Copyright (C) 2016-2017 by Vadim Yanitskiy <axilirator@gmail.com>\n" \
+	"License GPLv2+: GNU GPL version 2 or later " \
+	"<http://gnu.org/licenses/gpl.html>\n" \
+	"This is free software: you are free to change and redistribute it.\n" \
+	"There is NO WARRANTY, to the extent permitted by law.\n"
+
+class Application:
+	# Application variables
+	remote_addr = "127.0.0.1"
+	base_port = 5700
+
+	# PHY specific
+	phy_sample_rate = 2000000
+	phy_subdev_spec = False
+	phy_gain = 30
+	phy_args = ""
+	phy_ppm = 0
+
+	def __init__(self):
+		self.print_copyright()
+		self.parse_argv()
+
+		# Set up signal handlers
+		signal.signal(signal.SIGINT, self.sig_handler)
+
+	def run(self):
+		# Init Radio interface
+		self.radio = RadioInterface(self.phy_args, self.phy_subdev_spec,
+			self.phy_sample_rate, self.phy_gain, self.phy_ppm,
+			self.remote_addr, self.base_port)
+
+		# Power measurement emulation
+		# Noise: -120 .. -105
+		# BTS: -75 .. -50
+		self.pm = FakePM(-120, -105, -75, -50)
+
+		# Init TRX CTRL interface
+		self.server = CTRLInterfaceBB(self.remote_addr,
+			self.base_port + 101, self.base_port + 1,
+			self.radio, self.pm)
+
+		print("[i] Init complete")
+
+		# Enter main loop
+		while True:
+			self.server.loop()
+
+	def shutdown(self):
+		print("[i] Shutting down...")
+		self.server.shutdown()
+		self.radio.shutdown()
+
+	def print_copyright(self):
+		print(COPYRIGHT)
+
+	def print_help(self):
+		s  = " Usage: " + sys.argv[0] + " [options]\n\n" \
+			 " Some help...\n" \
+			 "  -h --help         this text\n\n"
+
+		# TRX specific
+		s += " TRX interface specific\n" \
+			 "  -s --remote-addr  Set remote address (default 127.0.0.1)\n" \
+			 "  -p --base-port    Set base port number (default 5700)\n\n"
+
+		# PHY specific
+		s += " Radio interface specific\n" \
+			 "  -a --device-args  Set device arguments\n" \
+			 "  -s --sample-rate  Set PHY sample rate (default 2000000)\n" \
+			 "  -S --subdev-spec  Set PHY sub-device specification\n" \
+			 "  -g --gain         Set PHY gain (default 30)\n" \
+			 "     --ppm          Set PHY frequency correction (default 0)\n"
+
+		print(s)
+
+	def parse_argv(self):
+		try:
+			opts, args = getopt.getopt(sys.argv[1:],
+				"a:p:i:s:S:g:h",
+				["help", "remote-addr=", "base-port=", "device-args=",
+				"gain=", "subdev-spec=", "sample-rate=", "ppm="])
+		except getopt.GetoptError as err:
+			# Print(help and exit)
+			self.print_help()
+			print("[!] " + str(err))
+			sys.exit(2)
+
+		for o, v in opts:
+			if o in ("-h", "--help"):
+				self.print_help()
+				sys.exit(2)
+
+			# TRX specific
+			elif o in ("-i", "--remote-addr"):
+				self.remote_addr = v
+			elif o in ("-p", "--base-port"):
+				if int(v) >= 0 and int(v) <= 65535:
+					self.base_port = int(v)
+				else:
+					print("[!] The port number should be in range [0-65536]")
+					sys.exit(2)
+
+			# PHY specific
+			elif o in ("-a", "--device-args"):
+				self.phy_args = v
+			elif o in ("-g", "--gain"):
+				self.phy_gain = int(v)
+			elif o in ("-S", "--subdev-spec"):
+				self.phy_subdev_spec = v
+			elif o in ("-s", "--sample-rate"):
+				self.phy_sample_rate = int(v)
+			elif o in ("--ppm"):
+				self.phy_ppm = int(v)
+
+	def sig_handler(self, signum, frame):
+		print("Signal %d received" % signum)
+		if signum is signal.SIGINT:
+			self.shutdown()
+			sys.exit(0)
+
+if __name__ == '__main__':
+	app = Application()
+	app.run()
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index c7c7cae..0997931 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -32,6 +32,7 @@
 add_subdirectory(receiver)
 add_subdirectory(demapping)
 add_subdirectory(transmitter)
+add_subdirectory(trx)
 
 GR_PYTHON_INSTALL(
     FILES
diff --git a/python/__init__.py b/python/__init__.py
index 0a9e544..f29e154 100644
--- a/python/__init__.py
+++ b/python/__init__.py
@@ -55,6 +55,13 @@
 from gsm_bcch_ccch_demapper import gsm_bcch_ccch_demapper
 from gsm_bcch_ccch_sdcch4_demapper import gsm_bcch_ccch_sdcch4_demapper
 from gsm_sdcch8_demapper import gsm_sdcch8_demapper
+from fn_time import *
+from txtime_bursts_tagger import *
+#from ctrl_if import *
+#from ctrl_if_bb import *
+#from fake_pm import *
+#from radio_if import *
+#from udp_link import *
 
 import arfcn
 
diff --git a/python/trx/CMakeLists.txt b/python/trx/CMakeLists.txt
new file mode 100644
index 0000000..a0ad38f
--- /dev/null
+++ b/python/trx/CMakeLists.txt
@@ -0,0 +1,27 @@
+# Copyright 2011,2012 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio 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.
+#
+# GNU Radio 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 GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+
+GR_PYTHON_INSTALL(
+    FILES
+    ctrl_if_bb.py
+    ctrl_if.py
+    fake_pm.py
+    radio_if.py
+    udp_link.py DESTINATION ${GR_PYTHON_DIR}/grgsm
+)
diff --git a/python/trx/ctrl_if.py b/python/trx/ctrl_if.py
new file mode 100644
index 0000000..a9050ef
--- /dev/null
+++ b/python/trx/ctrl_if.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# GR-GSM based transceiver
+# CTRL interface implementation
+#
+# (C) 2016-2017 by Vadim Yanitskiy <axilirator@gmail.com>
+#
+# All Rights Reserved
+#
+# This program 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 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+from grgsm import UDPLink
+
+class CTRLInterface(UDPLink):
+	def handle_rx(self, data):
+		if self.verify_req(data):
+			request = self.prepare_req(data)
+			rc = self.parse_cmd(request)
+
+			if type(rc) is tuple:
+				self.send_response(request, rc[0], rc[1])
+			else:
+				self.send_response(request, rc)
+		else:
+			print("[!] Wrong data on CTRL interface")
+
+	def verify_req(self, data):
+		# Verify command signature
+		return data.startswith("CMD")
+
+	def prepare_req(self, data):
+		# Strip signature, paddings and \0
+		request = data[4:].strip().strip("\0")
+		# Split into a command and arguments
+		request = request.split(" ")
+		# Now we have something like ["TXTUNE", "941600"]
+		return request
+
+	def verify_cmd(self, request, cmd, argc):
+		# Check if requested command matches
+		if request[0] != cmd:
+			return False
+
+		# And has enough arguments
+		if len(request) - 1 != argc:
+			return False
+
+		# Check if all arguments are numeric
+		for v in request[1:]:
+			if not v.isdigit():
+				return False
+
+		return True
+
+	def send_response(self, request, response_code, params = None):
+		# Include status code, for example ["TXTUNE", "0", "941600"]
+		request.insert(1, str(response_code))
+
+		# Optionally append command specific parameters
+		if params is not None:
+			request += params
+
+		# Add the response signature, and join back to string
+		response = "RSP " + " ".join(request) + "\0"
+		# Now we have something like "RSP TXTUNE 0 941600"
+		self.send(response)
+
+	def parse_cmd(self, request):
+		raise NotImplementedError
diff --git a/python/trx/ctrl_if_bb.py b/python/trx/ctrl_if_bb.py
new file mode 100644
index 0000000..b0d54f9
--- /dev/null
+++ b/python/trx/ctrl_if_bb.py
@@ -0,0 +1,142 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# GR-GSM based transceiver
+# CTRL interface for OsmocomBB
+#
+# (C) 2016-2017 by Vadim Yanitskiy <axilirator@gmail.com>
+#
+# All Rights Reserved
+#
+# This program 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 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+from ctrl_if import CTRLInterface
+
+class CTRLInterfaceBB(CTRLInterface):
+	def __init__(self, remote_addr, remote_port, bind_port, tb, pm):
+		print("[i] Init CTRL interface")
+		CTRLInterface.__init__(self, remote_addr, remote_port, bind_port)
+
+		# Set link to the follow graph (top block)
+		self.tb = tb
+		# Power measurement
+		self.pm = pm
+
+	def shutdown(self):
+		print("[i] Shutdown CTRL interface")
+		CTRLInterface.shutdown(self)
+
+	def parse_cmd(self, request):
+		# Power control
+		if self.verify_cmd(request, "POWERON", 0):
+			print("[i] Recv POWERON CMD")
+
+			# Ensure transceiver isn't working
+			if self.tb.trx_started:
+				print("[!] Transceiver already started")
+				return -1
+
+			# Ensure transceiver is ready to start
+			if not self.tb.check_available():
+				print("[!] Transceiver isn't ready to start")
+				return -1
+
+			print("[i] Starting transceiver...")
+			self.tb.trx_started = True
+			self.tb.start()
+
+			return 0
+
+		elif self.verify_cmd(request, "POWEROFF", 0):
+			print("[i] Recv POWEROFF cmd")
+
+			# TODO: flush all buffers between blocks
+			if self.tb.trx_started:
+				print("[i] Stopping transceiver...")
+				self.tb.trx_started = False
+				self.tb.stop()
+				self.tb.wait()
+
+			return 0
+
+		elif self.verify_cmd(request, "SETRXGAIN", 1):
+			print("[i] Recv SETRXGAIN cmd")
+
+			# TODO: check gain value
+			gain = int(request[1])
+			self.tb.set_gain(gain)
+
+			return 0
+
+		# Tuning Control
+		elif self.verify_cmd(request, "RXTUNE", 1):
+			print("[i] Recv RXTUNE cmd")
+
+			# TODO: check freq range
+			freq = int(request[1]) * 1000
+			self.tb.set_fc(freq)
+
+			return 0
+
+		elif self.verify_cmd(request, "TXTUNE", 1):
+			print("[i] Recv TXTUNE cmd")
+
+			# TODO: is not implemented yet
+			return 0
+
+		# Timeslot management
+		elif self.verify_cmd(request, "SETSLOT", 2):
+			print("[i] Recv SETSLOT cmd")
+
+			# Obtain TS index
+			tn = int(request[1])
+			if tn not in range(0, 8):
+				print("[!] TS index should be in range: 0..7")
+				return -1
+
+			# Ignore timeslot type for now
+			# Value 0 means 'drop all'
+			config = -1 if int(request[2]) == 0 else tn
+
+			print("[i] Configure timeslot filter to: %s"
+				% ("drop all" if config == -1 else "TS %d" % tn))
+
+			# HACK: configure built-in timeslot filter
+			self.tb.gsm_trx_if.ts_filter_set_tn(config)
+
+			return 0
+
+		# Power measurement
+		elif self.verify_cmd(request, "MEASURE", 1):
+			print("[i] Recv MEASURE cmd")
+
+			# TODO: check freq range
+			meas_freq = int(request[1]) * 1000
+
+			# HACK: send fake low power values
+			# until actual power measurement is implemented
+			meas_dbm = str(self.pm.measure(meas_freq))
+
+			return (0, [meas_dbm])
+
+		# Misc
+		elif self.verify_cmd(request, "ECHO", 0):
+			print("[i] Recv ECHO cmd")
+			return 0
+
+		# Wrong / unknown command
+		else:
+			print("[!] Wrong request on CTRL interface")
+			return -1
diff --git a/python/trx/fake_pm.py b/python/trx/fake_pm.py
new file mode 100644
index 0000000..1d76916
--- /dev/null
+++ b/python/trx/fake_pm.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# Virtual Um-interface (fake transceiver)
+# Power measurement emulation for BB
+#
+# (C) 2017 by Vadim Yanitskiy <axilirator@gmail.com>
+#
+# All Rights Reserved
+#
+# This program 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 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+from random import randint
+
+class FakePM:
+	# Freq. list for good power level
+	bts_list = []
+
+	def __init__(self, noise_min, noise_max, bts_min, bts_max):
+		# Save power level ranges
+		self.noise_min = noise_min
+		self.noise_max = noise_max
+		self.bts_min = bts_min
+		self.bts_max = bts_max
+
+	def measure(self, bts):
+		if bts in self.bts_list:
+			return randint(self.bts_min, self.bts_max)
+		else:
+			return randint(self.noise_min, self.noise_max)
+
+	def update_bts_list(self, new_list):
+		self.bts_list = new_list
+
+	def add_bts_list(self, add_list):
+		self.bts_list += add_list
+
+	def del_bts_list(self, del_list):
+		for item in del_list:
+			if item in self.bts_list:
+				self.bts_list.remove(item)
diff --git a/python/trx/radio_if.py b/python/trx/radio_if.py
new file mode 100644
index 0000000..c162f69
--- /dev/null
+++ b/python/trx/radio_if.py
@@ -0,0 +1,175 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# GR-GSM based transceiver
+# Follow graph implementation
+#
+# (C) 2016-2017 by Vadim Yanitskiy <axilirator@gmail.com>
+#
+# All Rights Reserved
+#
+# This program 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 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import pmt
+import time
+import grgsm
+import osmosdr
+
+from math import pi
+
+from gnuradio import blocks
+from gnuradio import gr
+
+class RadioInterface(gr.top_block):
+	# PHY specific variables
+	samp_rate = 2000000
+	shiftoff = 400e3
+	subdev_spec = "" # TODO: use it
+	device_args = ""
+	fc = 941.6e6 # TODO: set ARFCN to 0?
+	gain = 30
+	ppm = 0
+
+	# Application state flags
+	trx_started = False
+	fc_set = False
+
+	def __init__(self, phy_args, phy_subdev_spec,
+				phy_sample_rate, phy_gain, phy_ppm,
+				trx_remote_addr, trx_base_port):
+		print("[i] Init Radio interface")
+
+		# TRX block specific variables
+		self.trx_remote_addr = trx_remote_addr
+		self.trx_base_port = trx_base_port
+
+		# PHY specific variables
+		self.subdev_spec = phy_subdev_spec
+		self.samp_rate = phy_sample_rate
+		self.device_args = phy_args
+		self.gain = phy_gain
+		self.ppm = phy_ppm
+
+		gr.top_block.__init__(self, "GR-GSM TRX")
+		shift_fc = self.fc - self.shiftoff
+
+		##################################################
+		# PHY Definition
+		##################################################
+		self.phy = osmosdr.source(
+			args = "numchan=%d %s" % (1, self.device_args))
+
+		self.phy.set_bandwidth(250e3 + abs(self.shiftoff), 0)
+		self.phy.set_center_freq(shift_fc, 0)
+		self.phy.set_sample_rate(self.samp_rate)
+		self.phy.set_freq_corr(self.ppm, 0)
+		self.phy.set_iq_balance_mode(2, 0)
+		self.phy.set_dc_offset_mode(2, 0)
+		self.phy.set_gain_mode(False, 0)
+		self.phy.set_gain(self.gain, 0)
+		self.phy.set_if_gain(20, 0)
+		self.phy.set_bb_gain(20, 0)
+		self.phy.set_antenna("", 0)
+
+		##################################################
+		# GR-GSM Magic
+		##################################################
+		self.blocks_rotator = blocks.rotator_cc(
+			-2 * pi * self.shiftoff / self.samp_rate)
+
+		self.gsm_input = grgsm.gsm_input(
+			ppm = self.ppm, osr = 4, fc = self.fc,
+			samp_rate_in = self.samp_rate)
+
+		self.gsm_receiver = grgsm.receiver(4, ([0]), ([]))
+
+		self.gsm_clck_ctrl = grgsm.clock_offset_control(
+			shift_fc, self.samp_rate, osr = 4)
+
+		self.gsm_trx_if = grgsm.trx(self.trx_remote_addr,
+			str(self.trx_base_port))
+
+		##################################################
+		# Connections
+		##################################################
+		self.connect((self.phy, 0), (self.blocks_rotator, 0))
+		self.connect((self.blocks_rotator, 0), (self.gsm_input, 0))
+		self.connect((self.gsm_input, 0), (self.gsm_receiver, 0))
+
+		self.msg_connect((self.gsm_receiver, 'measurements'),
+			(self.gsm_clck_ctrl, 'measurements'))
+
+		self.msg_connect((self.gsm_clck_ctrl, 'ctrl'),
+			(self.gsm_input, 'ctrl_in'))
+
+		self.msg_connect((self.gsm_receiver, 'C0'),
+			(self.gsm_trx_if, 'bursts'))
+
+	def check_available(self):
+		return self.fc_set
+
+	def shutdown(self):
+		print("[i] Shutdown Radio interface")
+		self.stop()
+		self.wait()
+
+	def get_args(self):
+		return self.args
+
+	def set_args(self, args):
+		self.args = args
+
+	def get_fc(self):
+		return self.fc
+
+	def set_fc(self, fc):
+		self.phy.set_center_freq(fc - self.shiftoff, 0)
+		self.gsm_input.set_fc(fc)
+		self.fc_set = True
+		self.fc = fc
+
+	def get_gain(self):
+		return self.gain
+
+	def set_gain(self, gain):
+		self.phy.set_gain(gain, 0)
+		self.gain = gain
+
+	def get_ppm(self):
+		return self.ppm
+
+	def set_ppm(self, ppm):
+		self.rtlsdr_source_0.set_freq_corr(ppm, 0)
+		self.ppm = ppm
+
+	def get_samp_rate(self):
+		return self.samp_rate
+
+	def set_samp_rate(self, samp_rate):
+		self.blocks_rotator.set_phase_inc(
+			-2 * pi * self.shiftoff / samp_rate)
+		self.gsm_input.set_samp_rate_in(samp_rate)
+		self.phy.set_sample_rate(samp_rate)
+		self.samp_rate = samp_rate
+
+	def get_shiftoff(self):
+		return self.shiftoff
+
+	def set_shiftoff(self, shiftoff):
+		self.blocks_rotator.set_phase_inc(
+			-2 * pi * shiftoff / self.samp_rate)
+		self.phy.set_bandwidth(250e3 + abs(shiftoff), 0)
+		self.phy.set_center_freq(self.fc - shiftoff, 0)
+		self.shiftoff = shiftoff
diff --git a/python/trx/udp_link.py b/python/trx/udp_link.py
new file mode 100644
index 0000000..0d90ec9
--- /dev/null
+++ b/python/trx/udp_link.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# GR-GSM based transceiver
+# UDP link implementation
+#
+# (C) 2017 by Vadim Yanitskiy <axilirator@gmail.com>
+#
+# All Rights Reserved
+#
+# This program 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 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+import socket
+import select
+
+class UDPLink:
+	def __init__(self, remote_addr, remote_port, bind_port):
+		self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+		self.sock.bind(('0.0.0.0', bind_port))
+		self.sock.setblocking(0)
+
+		# Save remote info
+		self.remote_addr = remote_addr
+		self.remote_port = remote_port
+
+	def loop(self):
+		r_event, w_event, x_event = select.select([self.sock], [], [])
+
+		# Check for incoming data
+		if self.sock in r_event:
+			data, addr = self.sock.recvfrom(128)
+			self.handle_rx(data.decode())
+
+	def shutdown(self):
+		self.sock.close();
+
+	def send(self, data):
+		if type(data) not in [bytearray, bytes]:
+			data = data.encode()
+
+		self.sock.sendto(data, (self.remote_addr, self.remote_port))
+
+	def handle_rx(self, data):
+		raise NotImplementedError
diff --git a/swig/grgsm_swig.i.orig b/swig/grgsm_swig.i.orig
new file mode 100644
index 0000000..888f07a
--- /dev/null
+++ b/swig/grgsm_swig.i.orig
@@ -0,0 +1,151 @@
+/* -*- c++ -*- */
+/*
+ * @file
+ * @author (C) 2014 by Piotr Krysik <ptrkrysik@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.
+ */
+
+
+#define GRGSM_API
+
+%include "gnuradio.i"			// the common stuff
+
+//load generated python docstrings
+%include "grgsm_swig_doc.i"
+
+%{
+#include "grgsm/constants.h"
+#include "grgsm/receiver/receiver.h"
+#include "grgsm/receiver/clock_offset_control.h"
+#include "grgsm/receiver/cx_channel_hopper.h"
+#include "grgsm/decoding/control_channels_decoder.h"
+#include "grgsm/decoding/tch_f_decoder.h"
+#include "grgsm/decryption/decryption.h"
+#include "grgsm/demapping/universal_ctrl_chans_demapper.h"
+#include "grgsm/demapping/tch_f_chans_demapper.h"
+#include "grgsm/flow_control/common.h"
+#include "grgsm/flow_control/burst_timeslot_splitter.h"
+#include "grgsm/flow_control/burst_sdcch_subslot_splitter.h"
+#include "grgsm/flow_control/burst_timeslot_filter.h"
+#include "grgsm/flow_control/burst_sdcch_subslot_filter.h"
+#include "grgsm/flow_control/burst_fnr_filter.h"
+#include "grgsm/flow_control/dummy_burst_filter.h"
+#include "grgsm/flow_control/uplink_downlink_splitter.h"
+#include "grgsm/misc_utils/bursts_printer.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_file_sink.h"
+#include "grgsm/misc_utils/burst_file_source.h"
+#include "grgsm/misc_utils/collect_system_info.h"
+#include "grgsm/misc_utils/extract_cmc.h"
+#include "grgsm/qa_utils/burst_sink.h"
+#include "grgsm/qa_utils/burst_source.h"
+#include "grgsm/qa_utils/message_source.h"
+#include "grgsm/qa_utils/message_sink.h"
+#include "grgsm/misc_utils/message_file_sink.h"
+#include "grgsm/misc_utils/message_file_source.h"
+#include "grgsm/misc_utils/msg_to_tag.h"
+#include "grgsm/misc_utils/controlled_fractional_resampler_cc.h"
+#include "grgsm/trx_interface/trx.h"
+%}
+
+%include "constants.i"
+
+%include "grgsm/receiver/receiver.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, receiver);
+%include "grgsm/receiver/clock_offset_control.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, clock_offset_control);
+%include "grgsm/receiver/cx_channel_hopper.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, cx_channel_hopper);
+
+%include "grgsm/decoding/control_channels_decoder.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, control_channels_decoder);
+%include "grgsm/decoding/tch_f_decoder.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, tch_f_decoder);
+
+%include "grgsm/decryption/decryption.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, decryption);
+
+%include "grgsm/demapping/universal_ctrl_chans_demapper.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, universal_ctrl_chans_demapper);
+%include "grgsm/demapping/tch_f_chans_demapper.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, tch_f_chans_demapper);
+
+%include "grgsm/flow_control/common.h"
+%include "grgsm/flow_control/burst_timeslot_splitter.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, burst_timeslot_splitter);
+%include "grgsm/flow_control/burst_sdcch_subslot_splitter.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, burst_sdcch_subslot_splitter);
+%include "grgsm/flow_control/burst_timeslot_filter.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, burst_timeslot_filter);
+%include "grgsm/flow_control/burst_sdcch_subslot_filter.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, burst_sdcch_subslot_filter);
+%include "grgsm/flow_control/burst_fnr_filter.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, burst_fnr_filter);
+%include "grgsm/flow_control/dummy_burst_filter.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, dummy_burst_filter);
+%include "grgsm/flow_control/uplink_downlink_splitter.h"
+GR_SWIG_BLOCK_MAGIC2(grgsm, uplink_downlink_splitter);
+
+
+%include "grgsm/misc_utils/bursts_printer.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, bursts_printer);
+%include "grgsm/misc_utils/burst_file_sink.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, burst_file_sink);
+%include "grgsm/misc_utils/burst_file_source.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, burst_file_source);
+%include "grgsm/misc_utils/collect_system_info.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, collect_system_info);
+%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/message_printer.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, message_printer);
+%include "grgsm/misc_utils/tmsi_dumper.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, tmsi_dumper);
+%include "grgsm/misc_utils/message_file_sink.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, message_file_sink);
+%include "grgsm/misc_utils/message_file_source.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, message_file_source);
+%include "grgsm/misc_utils/msg_to_tag.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, msg_to_tag);
+%include "grgsm/misc_utils/controlled_fractional_resampler_cc.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, controlled_fractional_resampler_cc);
+%include "grgsm/misc_utils/extract_cmc.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, extract_cmc);
+
+
+%include "grgsm/qa_utils/burst_sink.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, burst_sink);
+%include "grgsm/qa_utils/burst_source.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, burst_source);
+%include "grgsm/qa_utils/message_source.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, message_source);
+%include "grgsm/qa_utils/message_sink.h"
+GR_SWIG_BLOCK_MAGIC2(gsm, message_sink);
+<<<<<<< HEAD
+%include "grgsm/trx_interface/trx.h"
+GR_SWIG_BLOCK_MAGIC2(grgsm, trx);
+=======
+>>>>>>> development