Commit Graph

38 Commits

Author SHA1 Message Date
Oliver Smith 1741372556 treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I73be012c01c0108fb6951dbff91d50eb19b40c51
2021-12-14 12:52:04 +00:00
Vadim Yanitskiy 1b7b4ec7a4 trx_toolkit: use RxMsg/TxMsg instead of TRX2L1/L12TRX
I intentionally do not use 'Downlink' and 'Uplink' terms in this project
because both MS and BTS transmit and receive on the opposite directions.
A burst coming from demodulator may be a Downlink or an Uplink burst
depending on the context, so we definitely need more precise terms.

Back then when I started to work on TRX toolkit, I decided to use the
'TRX2L1' and 'L12TRX' for receive and transmit directions respectively.
Now I find them hard to read, so let's replace them with 'Rx' and 'Tx'.

Change-Id: I688f24a3c09dd7e1cc00b5530ec26c8e8cfd8f7c
Related: OS#4006, SYS#4895
2021-05-03 20:39:10 +02:00
Vadim Yanitskiy b2349bc359 trx_toolkit/data_msg.py: remove obsolete documentation
We do have TRXC/TRXD documentation in osmo-gsm-manuals repository.
These big comments are out of sync with what we have in the manuals,
so let's better remove them to avoid maintaining docs in several places.

Change-Id: I47786cf3039f712efadc85bc4e1c3ae89e79ff25
Related: OS#4006, SYS#4895
2021-05-03 20:39:10 +02:00
Vadim Yanitskiy 87c5f2c92d trx_toolkit/data_msg.py: update entries in enum Modulation
Change-Id: Ia96b263bbb162b6c40f2cf81616118cc297299a5
Related: OS#4006, SYS#4895
2021-05-03 20:39:05 +02:00
Vadim Yanitskiy bd73f0920d trx_toolkit/gsm_shared.py: s/GSM_BURST_LEN/GMSK_BURST_LEN/g
Change-Id: I7268196eb9fd822f0e7b65899e4c83c48a20ba5b
2021-04-30 22:31:40 +02:00
Vadim Yanitskiy b00601d7ee trx_toolkit/data_msg.py: add type hints to static methods
Change-Id: I06fd8bc7418700de40467fd63a08da2bc2abcea2
2021-04-08 03:20:39 +02:00
Vadim Yanitskiy c8754d47db trx_toolkit/data_msg.py: use uppercase for KNOWN_VERSIONS
Change-Id: Ie4dcc8e91115c514ace243a95a9b44a17cd976b4
Related: OS#4006, SYS#4895
2021-03-01 15:02:35 +00:00
Vadim Yanitskiy ba3e1f7c2a trx_toolkit/data_msg.py: use tuple for DATAMSG.known_versions
Change-Id: I79de5fe478297e1850d9582426888411a0189d3f
Related: OS#4006, SYS#4895
2021-03-01 15:02:35 +00:00
Vadim Yanitskiy f9938b3a54 trx_toolkit/data_msg.py: decorate abstract methods as such
Change-Id: I27fdcfdabc2b5318ab3e958d2e5446e670fe9035
Related: OS#4006, SYS#4895
2021-03-01 15:02:35 +00:00
Vadim Yanitskiy 7a31e98936 trx_toolkit/data_msg.py: convert comments into docstrings
Change-Id: I856b54fd1baca4ae0edd2aa59be6a76372cef667
Related: OS#4006, SYS#4895
2021-03-01 15:02:35 +00:00
Pau Espin 1687d3dea3 fake_trx: Implement RFMUTE TRXC cmd
Change-Id: I67d16858cd70cb0527c1da77bd3787d5e53100b4
2020-08-26 18:04:57 +02:00
Vadim Yanitskiy 270af48118 trx_toolkit: remove shebang from non-executable scripts
Change-Id: I5ddc531a4e98d4d6f8672d6ef14034fce605ba3d
2020-07-16 13:42:56 +07:00
Vadim Yanitskiy cab00398c2 trx_toolkit: cosmetic: get rid of 'i' where it is not used
Change-Id: I00126a90446e5f3fb77a46be9d7d5dbff89fa221
2020-05-22 18:48:23 +07:00
Vadim Yanitskiy 86b621b36b trx_toolkit/data_msg.py: use list comprehension for bit conversion
This approach is much better than buf.append() in terms of performance.
Consider the following bit conversion benchmark code:

  usbits = [random.randint(0, 254) for i in range(GSM_BURST_LEN)]
  ubits = [int(b > 128) for b in usbits]

  for i in range(100000):
      sbits = DATAMSG.usbit2sbit(usbits)
      assert(DATAMSG.sbit2usbit(sbits) == usbits)

      sbits = DATAMSG.ubit2sbit(ubits)
      assert(DATAMSG.sbit2ubit(sbits) == ubits)

=== Before this patch:

 59603795 function calls (59603761 primitive calls) in 11.357 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
 59200093    3.389    0.000    3.389    0.000 {method 'append' of 'list' objects}
   100000    2.212    0.000    3.062    0.000 data_msg.py:191(usbit2sbit)
   100000    1.920    0.000    2.762    0.000 data_msg.py:214(sbit2ubit)
   100000    1.835    0.000    2.677    0.000 data_msg.py:204(sbit2usbit)
   100000    1.760    0.000    2.613    0.000 data_msg.py:224(ubit2sbit)

=== After this patch:

  803794 function calls (803760 primitive calls) in 3.547 seconds

   Ordered by: internal time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   100000    1.284    0.000    1.284    0.000 data_msg.py:203(<listcomp>)
   100000    0.864    0.000    0.864    0.000 data_msg.py:193(<listcomp>)
   100000    0.523    0.000    0.523    0.000 data_msg.py:198(<listcomp>)
   100000    0.500    0.000    0.500    0.000 data_msg.py:208(<listcomp>)
        1    0.237    0.237    3.547    3.547 data_msg.py:25(<module>)
   100000    0.035    0.000    0.899    0.000 data_msg.py:191(usbit2sbit)
   100000    0.035    0.000    0.558    0.000 data_msg.py:196(sbit2usbit)
   100000    0.033    0.000    0.533    0.000 data_msg.py:206(ubit2sbit)
   100000    0.033    0.000    1.317    0.000 data_msg.py:201(sbit2ubit)

So the new implementation is ~70% faster in this case, and takes
significantly less function calls according to cProfile [1].

[1] https://docs.python.org/3.8/library/profile.html

Change-Id: I01c07160064c8107e5db7d913ac6dec6fc419945
2020-05-16 20:17:18 +00:00
Vadim Yanitskiy 5cee398277 trx_toolkit/data_msg.py: rewrite unit tests to use unittest framework
Change-Id: Ia0cc7447b193a705e994078d16f3902339219916
2019-12-31 17:03:12 +00:00
Vadim Yanitskiy 7108c28c38 trx_toolkit/data_msg.py: fix: NOPE.ind also contains C/I filed
Change-Id: I281fb7387a83fec7e097ebf8650c95713d3f70e9
2019-11-20 15:05:57 +00:00
Vadim Yanitskiy 5afc0e4cb0 trx_toolkit/data_msg.py: enrich some ValueError messages
Change-Id: Icdf0d136a9b820cfaec534e2604204da9ea42092
2019-08-29 18:02:04 +02:00
Vadim Yanitskiy 171773b3e8 trx_toolkit/data_msg.py: also print burst length in desc_hdr()
Change-Id: Ia0036cbf70a3736a7f9779e030e05221cba8add9
2019-08-29 18:02:00 +02:00
Vadim Yanitskiy 59903772fa trx_toolkit/data_msg.py: fix: make sure header version is known
Before using DATA_MSG.HDR_LEN, we need to make sure that a parsed
header version is known and supported. Otherwise we will get an
IndexError exception.

Change-Id: Ie1887aa8709da1a2a287aa58a7873e72c0b4ed33
2019-08-29 15:09:40 +02:00
Vadim Yanitskiy df86074abe trx_toolkit/data_msg.py: fix message length check in parse_msg()
Unlike DATA_MSG.HDR_LEN, the CHDR_LEN is a constant that defines
length of the common header, which is mandatory for every version.
DATA_MSG.HDR_LEN in its turn defines length of the whole header,
including the version specific fields. Thus we need to know the
header version before using it.

In DATA_MSG.parse_msg() we need to parse the common header first,
so then we know the version and length of the whole header. After
that we can safely use DATA_MSG.HDR_LEN.

Change-Id: I2809f5f96209eed64bdabf7a15575144313f7cc9
2019-08-29 15:04:28 +02:00
Vadim Yanitskiy 6af5d8da2c trx_toolkit/data_msg.py: raise exceptions from validate() methods
Raising exceptions is a Pythonic way to handle errors, which in this
particular case will help us to know *why* exactly a given message
is incorrect or incomplete.

Change-Id: Ia961f83c717066af61699c80536468392b8ce064
2019-08-27 20:30:23 +02:00
Pau Espin 2cc3392706 trx_toolkit: Fixes in TRXD documentation
Change-Id: I126a8aed6b2bac7a620e95f06ecb98642a63b5f0
2019-08-05 16:24:40 +02:00
Alexander Couzens 998ed796c3 target/*.py: shebang: use /usr/bin/env python
Use the system default python instead of a hardcoded python2
Allow to use python2 and python3.

Change-Id: Iab185759b574eff1ca1b189dcbb4e1a3eec52132
2019-07-16 22:46:12 +00:00
Vadim Yanitskiy 62825cc8eb trx_toolkit/data_msg.py: legacy flag is only for version 0x00
Since version 0x01, the burst bits are encoded as L16V,
so appending two dummy octets doesn't make sense.

Change-Id: I4d6c0bf54649d636ea6cb3fa2f37486b6619d5b3
2019-07-02 13:48:06 +07:00
Vadim Yanitskiy dce8a24a2c trx_toolkit/data_msg.py: introduce header coding version 0x01
The new version adds the following fields to the TRX2L1 message,
keeping the L12TRX message unchanged:

  +------+-----+-----+-----+--------------------+
  | RSSI | ToA | MTS | C/I | soft-bits (254..0) |
  +------+-----+-----+-----+--------------------+

  - MTS (1 octet)  - Modulation and Training Sequence info, and
  - C/I (2 octets) - Carrier-to-Interference ratio (big endian).

== Coding of MTS: Modulation and Training Sequence info

3GPP TS 45.002 version 15.1.0 defines several modulation types,
and a few sets of training sequences for each type. The most
common are GMSK and 8-PSK (which is used in EDGE).

  +-----------------+---------------------------------------+
  | 7 6 5 4 3 2 1 0 | bit numbers (value range)             |
  +-----------------+---------------------------------------+
  | . . . . . X X X | Training Sequence Code (0..7)         |
  +-----------------+---------------------------------------+
  | . X X X X . . . | Modulation, TS set number (see below) |
  +-----------------+---------------------------------------+
  | X . . . . . . . | IDLE / nope frame indication (0 or 1) |
  +-----------------+---------------------------------------+

The bit number 7 (MSB) is set to high when either nothing has been
detected, or during IDLE frames, so we can deliver noise levels,
and avoid clock gaps on the L1 side. Other bits are ignored,
and should be set to low (0) in this case.

== Coding of modulation and TS set number

GMSK has 4 sets of training sequences (see tables 5.2.3a-d),
while 8-PSK (see tables 5.2.3f-g) and the others have 2 sets.
Access and Synchronization bursts also have several synch.
sequences.

  +-----------------+---------------------------------------+
  | 7 6 5 4 3 2 1 0 | bit numbers (value range)             |
  +-----------------+---------------------------------------+
  | . 0 0 X X . . . | GMSK, 4 TS sets (0..3)                |
  +-----------------+---------------------------------------+
  | . 0 1 0 X . . . | 8-PSK, 2 TS sets (0..1)               |
  +-----------------+---------------------------------------+
  | . 0 1 1 X . . . | AQPSK, 2 TS sets (0..1)               |
  +-----------------+---------------------------------------+
  | . 1 0 0 X . . . | 16QAM, 2 TS sets (0..1)               |
  +-----------------+---------------------------------------+
  | . 1 0 1 X . . . | 32QAM, 2 TS sets (0..1)               |
  +-----------------+---------------------------------------+
  | . 1 1 1 X . . . | RESERVED (0)                          |
  +-----------------+---------------------------------------+

== C/I: Carrier-to-Interference ratio

The C/I value is computed from the training sequence of each burst,
where we can compare the "ideal" training sequence with the actual
training sequence, and then express that difference in centiBels.

Change-Id: Ie810c5a482d1c908994e8cdd32a2ea641ae7cedd
Related: OS#4006, OS#1855
2019-07-02 13:46:10 +07:00
Vadim Yanitskiy af60c1bb10 trx_toolkit/data_msg.py: implement header version coding
It may be necessary to extend the message specific header with
more information. Since this is not a TLV-based protocol, we
need to include the header format version.

  +-----------------+------------------------+
  | 7 6 5 4 3 2 1 0 | bit numbers            |
  +-----------------+------------------------+
  | X X X X . . . . | header version (0..15) |
  +-----------------+------------------------+
  | . . . . . X X X | TDMA TN (0..7)         |
  +-----------------+------------------------+
  | . . . . X . . . | RESERVED (0)           |
  +-----------------+------------------------+

Instead of prepending an additional byte, it was decided to use
4 MSB bits of the first octet, which used to be zero-initialized
due to the value range of TDMA TN. Therefore, the current header
format has implicit version 0x00.

Otherwise Wireshark (or trx_sniff.py) would need to guess the
header version, or alternatively follow the control channel
looking for the version setting command.

The reserved bit number 3 can be used in the future to extend
the TDMA TN range to (0..15), in case anybody would need
to transfer UMTS bursts.

Change-Id: Idb0377d66290eb9c15d6998a5806a84fa2e5dd02
Related: OS#4006
2019-07-01 20:05:48 +07:00
Vadim Yanitskiy 851d35c675 trx_toolkit/data_msg.py: add burst randomization helpers
Change-Id: Idf1393d3d1f04e6c60b356b797a18e6f77b23554
2019-07-01 17:39:45 +07:00
Vadim Yanitskiy 7cb120e841 trx_toolkit/data_msg.py: mark bit conversion methods as @staticmethod
Change-Id: I2f9fdd514908f186b1c6c043ee9b31c27a396900
2019-07-01 17:37:00 +07:00
Vadim Yanitskiy 696fe71ac1 trx_toolkit/data_msg.py: add basic class documentation
Change-Id: I538bc96e5e24d3b7e344e4dbe2877bf60c13c720
Related# OS#4006
2019-06-24 14:18:09 +00:00
Vadim Yanitskiy 1ff9780366 trx_toolkit/data_msg.py: inline both gen_fn() and parse_fn()
Both functions are never used outside of both gen_msg() and parse_msg().
AFAIR, they were more complicated until we started to use struct, but
now they can be easily inlined.

Change-Id: Ie64b271cf502f3df23b32f4b14a1e2b551a0f794
2019-06-24 14:18:09 +00:00
Vadim Yanitskiy 84bd7b2746 trx_toolkit/data_msg.py: drop double field initialization
Those fields are being initialized by __init__().

Change-Id: Ibf71be552a7eb5dab1d096421a8557514294683e
2019-06-24 14:18:09 +00:00
Vadim Yanitskiy 7a007e82a8 trx_toolkit/data_msg.py: tests: use random reference data
Having fn = 1024 and tn = 0 in all tests decreases the chances
to spot encoding / decoding bugs of higher or lower values.
Let's randomize the reference data before all the tests.

Change-Id: Id3c5be9faaf0bef727b975c7182098af0cec6e71
2019-06-24 14:18:09 +00:00
Vadim Yanitskiy 6e9808662f trx_toolkit/data_msg.py: fix: extend RSSI value range to [-47..-120]
Change-Id: I9fce3462db14bd273a1498762cc9293fc888b45a
2019-06-01 01:42:43 +07:00
Vadim Yanitskiy cca67cfe94 trx_toolkit/data_msg.py: fix TOA256 MIN/MAX constants
The old TOA256 range was bigger than we can actually store:

  struct.error: 'h' format requires -32768 <= number <= 32767

Change-Id: I5d4e1fea9d07f2c49f01e6644d1c0d1dc8cf4e40
2019-04-24 15:12:03 +07:00
Vadim Yanitskiy e4cddb5ef1 trx_toolkit/data_msg.py: add optional legacy message coding flag
Some transceivers (e.g. OsmoTRX) have inherited a rudiment from
OpenBTS - two dummy bytes at the end of TRX2L1 messages. Despite
they are absolutely useless, some L1 implementations, such as
trxcon and OpenBTS, still do expect them when checking
the message length.

Let's add an optional (disabled by default) argument to gen_msg(),
that would enable adding those two dummy bytes.

Change-Id: I0cf1314c399411886420176704cadd6e6d84787f
2018-12-18 05:47:11 +07:00
Vadim Yanitskiy 8b3d49bd34 trx_toolkit/data_msg.py: use struct API for fn and toa256 coding
The built-in struct module is already used for toa256 decoding,
so let's use it for toa256 encoding, and TDMA frame number
coding too - no need to (re)implement the wheel!

Change-Id: I10d2e15ac57a0524e9bc1c80ed6a0f6f5a263436
2018-12-18 05:47:11 +07:00
Vadim Yanitskiy 6bab6acee6 trx_toolkit: use generic logging module instead of print()
There are multiple advantages of using Python's logging module:

  - advanced message formatting (file name, line number, etc.),
  - multiple logging targets (e.g. stderr, file, socket),
  - logging levels (e.g. DEBUG, INFO, ERROR),
  - the pythonic way ;)

so, let's replace multiple print() calls by logging calls,
add use the following logging message format by default:

  [%(levelname)s] %(filename)s:%(lineno)d %(message)s

Examples:

  [INFO] ctrl_if_bts.py:57 Starting transceiver...
  [DEBUG] clck_gen.py:87 IND CLOCK 26826
  [DEBUG] ctrl_if_bts.py:71 Recv POWEROFF cmd
  [INFO] ctrl_if_bts.py:73 Stopping transceiver...
  [INFO] fake_trx.py:127 Shutting down...

Please note that there is no way to filter messages by logging
level yet. This is to be introduced soon, together with argparse.

Change-Id: I7fcafabafe8323b58990997a47afdd48b6d1f357
2018-12-07 05:36:20 +07:00
Vadim Yanitskiy 23914b9cf8 Rename 'fake_trx' to 'trx_toolkit'
This toolkit has branched out into several different tools for
TRX interface hacking, and creating a virtual Um-interface
(FakeTRX) is only one of its potential applications.

Change-Id: I56bcbc76b9c273d6b469a2bb68ddc46f3980e835
2018-03-13 02:10:02 +07:00