summaryrefslogtreecommitdiffstats
path: root/src/target/fake_trx/ctrl_if.py
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-07-10 19:39:06 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2017-10-23 22:05:49 +0330
commit663dce62608205c56d2bca4717fd9640753c0dc3 (patch)
treef261a0347dc9451ebae921058fb268bae583cda0 /src/target/fake_trx/ctrl_if.py
parent63c86222b55bbbc06ecefbd5c73abda2251eca9e (diff)
target/fake_trx: initial release of virtual transceiver
This is a set of tools for creating a virtual Um-interface between OsmocomBB and OsmoBTS. It may be extremely useful for testing and development of GSM stack, including both sides (MS and BTS). This software implements OsmoTRX (Osmocom's fork of OpenBTS transceiver) style clock (CLCK), control (CTRL) and data interfaces. So, OsmoBTS source code doesn't require any modifications, while for OsmocomBB you will need to use a new application - trxcon, which can be found in the 'fixeria/sdr_phy' branch until one is merged to master. Brief description of available applications: - fake_trx.py - main application, that allows to connect both OsmocomBB and OsmoBTS without actual RF hardware. Currently only a single MS may work with a single BTS. - clck_gen.py - a peripheral tool aimed to emulate TDMA frame clock generator. Could be used for testing and clock synchronization of multiple applications. It should be noted, that one relays on generic system timer (via Python), so a random clock jitter takes place. - ctrl_cmd.py - another peripheral tool, which could be used for sending CTRL commands directly in manual mode, and also for application fuzzing. Change-Id: Ib1fb80682002ac85a72fa6abef459a4c44f4ab97
Diffstat (limited to 'src/target/fake_trx/ctrl_if.py')
-rw-r--r--src/target/fake_trx/ctrl_if.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/target/fake_trx/ctrl_if.py b/src/target/fake_trx/ctrl_if.py
new file mode 100644
index 00000000..a87c4c49
--- /dev/null
+++ b/src/target/fake_trx/ctrl_if.py
@@ -0,0 +1,74 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# Virtual Um-interface (fake 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 udp_link import UDPLink
+
+class CTRLInterface(UDPLink):
+ def handle_rx(self, data):
+ # print(data)
+ if self.verify_req(data):
+ request = self.prepare_req(data)
+ rc = self.parse_cmd(request)
+ 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):
+ # Include status code, for example ["TXTUNE", "0", "941600"]
+ request.insert(1, str(response_code))
+ # 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