summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-08-03 19:51:57 +0600
committerVadim Yanitskiy <axilirator@gmail.com>2017-10-23 22:05:49 +0330
commit405dd5f51552f11c5387c4241b9bedbcb0974a1e (patch)
tree07a492bbc8d87b789dda8b1ed9b29efe55f39b2c
parent18c1d3c093edea8559d8733b9b42555e6f142118 (diff)
fake_trx: separate DataInterface from burst_gen.py
-rwxr-xr-xsrc/target/fake_trx/burst_gen.py82
-rw-r--r--src/target/fake_trx/data_if.py107
2 files changed, 108 insertions, 81 deletions
diff --git a/src/target/fake_trx/burst_gen.py b/src/target/fake_trx/burst_gen.py
index fb50ea3..f8f924c 100755
--- a/src/target/fake_trx/burst_gen.py
+++ b/src/target/fake_trx/burst_gen.py
@@ -28,8 +28,8 @@ import getopt
import select
import sys
-from udp_link import UDPLink
from rand_burst_gen import RandBurstGen
+from data_if import DATAInterface
COPYRIGHT = \
"Copyright (C) 2017 by Vadim Yanitskiy <axilirator@gmail.com>\n" \
@@ -38,86 +38,6 @@ COPYRIGHT = \
"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 DATAInterface(UDPLink):
- # GSM PHY definitions
- GSM_HYPERFRAME = 2048 * 26 * 51
-
- def send_l1_msg(self, burst,
- tn = None, fn = None, rssi = None):
- # Generate random timeslot index if not preset
- if tn is None:
- tn = random.randint(0, 7)
-
- # Generate random frame number if not preset
- if fn is None:
- fn = random.randint(0, self.GSM_HYPERFRAME)
-
- # Generate random RSSI if not preset
- if rssi is None:
- rssi = -random.randint(-75, -50)
-
- # Prepare a buffer for header and burst
- buf = []
-
- # Put timeslot index
- buf.append(tn)
-
- # Put frame number
- buf.append((fn >> 24) & 0xff)
- buf.append((fn >> 16) & 0xff)
- buf.append((fn >> 8) & 0xff)
- buf.append((fn >> 0) & 0xff)
-
- # Put RSSI
- buf.append(rssi)
-
- # HACK: put fake TOA value
- buf += [0x00] * 2
-
- # Put burst
- buf += burst
-
- # Put two unused bytes
- buf += [0x00] * 2
-
- # Send message
- self.send(bytearray(buf))
-
- def send_trx_msg(self, burst,
- tn = None, fn = None, pwr = None):
- # Generate random timeslot index if not preset
- if tn is None:
- tn = random.randint(0, 7)
-
- # Generate random frame number if not preset
- if fn is None:
- fn = random.randint(0, self.GSM_HYPERFRAME)
-
- # Generate random power level if not preset
- if pwr is None:
- pwr = random.randint(0, 34)
-
- # Prepare a buffer for header and burst
- buf = []
-
- # Put timeslot index
- buf.append(tn)
-
- # Put frame number
- buf.append((fn >> 24) & 0xff)
- buf.append((fn >> 16) & 0xff)
- buf.append((fn >> 8) & 0xff)
- buf.append((fn >> 0) & 0xff)
-
- # Put transmit power level
- buf.append(pwr)
-
- # Put burst
- buf += burst
-
- # Send message
- self.send(bytearray(buf))
-
class Application:
# Application variables
remote_addr = "127.0.0.1"
diff --git a/src/target/fake_trx/data_if.py b/src/target/fake_trx/data_if.py
new file mode 100644
index 0000000..315281c
--- /dev/null
+++ b/src/target/fake_trx/data_if.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# Simple tool to send custom messages via TRX DATA interface,
+# which may be also useful for fuzzing and testing
+#
+# (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 random
+
+from udp_link import UDPLink
+
+class DATAInterface(UDPLink):
+ # GSM PHY definitions
+ GSM_HYPERFRAME = 2048 * 26 * 51
+
+ def send_l1_msg(self, burst,
+ tn = None, fn = None, rssi = None):
+ # Generate random timeslot index if not preset
+ if tn is None:
+ tn = random.randint(0, 7)
+
+ # Generate random frame number if not preset
+ if fn is None:
+ fn = random.randint(0, self.GSM_HYPERFRAME)
+
+ # Generate random RSSI if not preset
+ if rssi is None:
+ rssi = -random.randint(-75, -50)
+
+ # Prepare a buffer for header and burst
+ buf = []
+
+ # Put timeslot index
+ buf.append(tn)
+
+ # Put frame number
+ buf.append((fn >> 24) & 0xff)
+ buf.append((fn >> 16) & 0xff)
+ buf.append((fn >> 8) & 0xff)
+ buf.append((fn >> 0) & 0xff)
+
+ # Put RSSI
+ buf.append(rssi)
+
+ # HACK: put fake TOA value
+ buf += [0x00] * 2
+
+ # Put burst
+ buf += burst
+
+ # Put two unused bytes
+ buf += [0x00] * 2
+
+ # Send message
+ self.send(bytearray(buf))
+
+ def send_trx_msg(self, burst,
+ tn = None, fn = None, pwr = None):
+ # Generate random timeslot index if not preset
+ if tn is None:
+ tn = random.randint(0, 7)
+
+ # Generate random frame number if not preset
+ if fn is None:
+ fn = random.randint(0, self.GSM_HYPERFRAME)
+
+ # Generate random power level if not preset
+ if pwr is None:
+ pwr = random.randint(0, 34)
+
+ # Prepare a buffer for header and burst
+ buf = []
+
+ # Put timeslot index
+ buf.append(tn)
+
+ # Put frame number
+ buf.append((fn >> 24) & 0xff)
+ buf.append((fn >> 16) & 0xff)
+ buf.append((fn >> 8) & 0xff)
+ buf.append((fn >> 0) & 0xff)
+
+ # Put transmit power level
+ buf.append(pwr)
+
+ # Put burst
+ buf += burst
+
+ # Send message
+ self.send(bytearray(buf))