diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2017-08-03 19:51:57 +0600 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2017-11-19 17:35:07 +0700 |
commit | a59edfbd4062705266b300fe23cdf4d06b2a8671 (patch) | |
tree | 754c35ab02b5f730f25945aea7dc17a03180b1e0 /src | |
parent | 1e9501671a73ba19ec7e21db7ca7dadc8a2ebff7 (diff) |
fake_trx: separate DataInterface from burst_gen.py
Change-Id: I325cf2ae59ef8834c2ddfb67206eede44d1e0acf
Diffstat (limited to 'src')
-rwxr-xr-x | src/target/fake_trx/burst_gen.py | 82 | ||||
-rw-r--r-- | src/target/fake_trx/data_if.py | 107 |
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 fb50ea3b..f8f924c5 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 00000000..315281cd --- /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)) |