Commit Graph

2521 Commits

Author SHA1 Message Date
Marcel `sdrfnord` McKinnon fd32afbe26 firmware/fb: Implemtented fb_bw8_line and fb_set_p(uint16_t x,uint16_t y)
Change-Id: Id8856ace2a31ba4ebcd04746e0c96c23a679cc40
2020-08-04 19:57:45 +02:00
Marcel `sdrfnord` McKinnon bedfdc9b62 firmware/abb: Wrote twl3025_power_off_now to restart the phone if the power button is pressed
I am not sure how other developers do this. There are probably better ways to
make testing faster but I kind of like it this way.

I just call the twl3025_power_off_now function when the power key is pressed.

Change-Id: I1e55910acd8584c74e5e190b3334a8cf6987f5f3
2020-08-02 16:39:39 +02:00
Vadim Yanitskiy b95a897655 firmware/layer1: fix properly apply secondary multi-frame task
When a dedicated channel is activated, in chan_nr2mf_task_mask()
we calculate a bitmask of the corresponding multi-frame tasks to
be enabled.  Three logical kinds of the multi-frame tasks exist:

  - primary (master) - the main burst processing task,
    e.g. MF_TASK_{TCH_F_ODD,SDCCH4_0,GPRS_PDTCH};
  - secondary - additional burst processing task (optional),
    e.g. MF_TASK_GPRS_PTCCH;
  - measurement - neighbour measurement task (optional),
    e.g. MF_TASK_NEIGH_{PM51,PM26E,PM26O}.

By default, the primary task is set to MF_TASK_BCCH_NORM (0x00).
Due to a mistake, the secondary task has also been set to BCCH,
so when we switch to a dedicated mode, we also enable the BCCH.

This leads to a race condition between the multi-frame tasks,
when both primary and secondary ones read bursts from the DSP
at the same time, so the firmware hangs because of that:

  nb_cmd(0) and rxnb.msg != NULL
  BURST ID 2!=0 BURST ID 3!=1

This regression was introduced together with experimental PDCH
support [1].  Let's use value -1 to indicate that the secondary
task is not set, and apply it properly.

Change-Id: I4d667b2106fd8453eac9e24019bdfb14358d75e3
Fixes: [1] I44531bbe8743c188cc5d4a6ca2a63000e41d6189
Related: OS#3155
2020-07-31 22:16:40 +07:00
Vadim Yanitskiy 92e9820966 firmware/layer1: refactor multi-frame task mask composition
Change-Id: I91780146d066c45c42b037c22cb49fd8a96e832b
2020-07-31 21:46:42 +07:00
Vadim Yanitskiy 8194febb09 layer23/mobile: implement handling of TCH test loop commands
For more information, see 3GPP TS 44.014, sections:

  - 5.1 "Single-slot TCH loops", and
  - 8 "Message definitions and contents".

This feature has nothing to do with the Mobility Management, so
let's handle GSM48_PDISC_TEST messages in the Radio Resources
layer implementation (gsm48_mm.c -> gsm48_rr.c).

Change-Id: If8efc57c7017aa8ea47b37c472d1bbb1914389ca
2020-07-31 00:48:06 +07:00
Vadim Yanitskiy 7c7632de3e firmware: add possibility to configure TCH loops in the DSP
Change-Id: Ide7b0527ad64a044977a10da4a82a8ecd1fbd8dc
2020-07-31 00:42:01 +07:00
Vadim Yanitskiy 8208a336ab layer23/mobile: fix a memory leak (msgb) in gsm48_rr_data_ind()
Change-Id: I55dcccf5b7d27d012908759954182eaec434d26b
2020-07-30 16:46:50 +07:00
Vadim Yanitskiy df2b46471d layer23/mobile: fix wrong message type in gsm48_rr_tx_rr_status()
Change-Id: I57c6a4e1e725da52c50e2a28e56627a3f3827c62
2020-07-30 16:07:27 +07:00
Vadim Yanitskiy e7e4d86f0e layer23/mobile: cosmetic: use GSM48_PDISC_TEST from gsm_04_08.h
Change-Id: Ie1f14b37f6138f5a019a25bdbc8a3531418df6c2
2020-07-29 03:58:23 +07:00
Vadim Yanitskiy 4e4babc7db trx_toolkit/data_if.py: fix: handle encoding exceptions
Change-Id: I78163d41be3a912da1dd8c0543b1c3af3a0649fa
Related: OS#4681
2020-07-27 02:58:25 +07:00
Vadim Yanitskiy 129c976c3a trx_toolkit/data_if.py: do not validate TRXD message twice
DATAMSG.gen_msg() does validete the message before encoding.

Change-Id: Ia3691b3c18778cf7a1f16c71bef5c0b2e6241190
Related: OS#4681
2020-07-27 02:25:20 +07:00
Vadim Yanitskiy d4ed09df57 Revert "trx_toolkit/transceiver.py: implement the transmit burst queue"
This reverts commit 6e1c82d298.
Unfortunately, solving one problem it introduced even more regressions.

Change-Id: If29b4f6718cbc8af18fe18a5e3eca3912e8af01e
Related: OS#4658
2020-07-22 19:59:06 +07:00
Vadim Yanitskiy 7eb355ab3e trx_toolkit/clck_gen.py: remove unused import of 'time' module
Change-Id: I40628d32409543c9f4b40b7268a4538b4671102d
2020-07-16 14:16:34 +07:00
Vadim Yanitskiy 1e20f8e042 trx_toolkit: get rid of Python2 specific workarounds
Change-Id: I16c63205c9133d964048588c25867ac7c310f951
2020-07-16 13:58:34 +07:00
Vadim Yanitskiy 49673e4073 trx_toolkit: use python3 in shebang of executable scripts
TRX Toolkit is still backwards compatible with Python2, but Python3
does much better in terms of performance.  Also, on Debian Stretch
that is used as a base for our Docker images, Python 2.7 is still
the default.  Let's require Python3 in shebang.

Change-Id: I8a1d7c59d3b5d49ec2ed94a7c77905e02134f216
2020-07-16 13:46:19 +07: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 6e1c82d298 trx_toolkit/transceiver.py: implement the transmit burst queue
In order to reflect the UL/DL delay caused by the premature burst
scheduling (a.k.a. 'fn-advance') in a virtual environment, the
Transceiver implementation now queues all to be transmitted bursts,
so they remain in the queue until the appropriate time of transmission.

The API user is supposed to call recv_data_msg() in order to obtain
a L12TRX message on the TRXD (data) inteface, so it gets queued by
this function.  Then, to ensure the timeous transmission, the user
of this implementation needs to call clck_tick() on each TDMA
frame.  Both functions are thread-safe (queue mutex).

In a multi-trx configuration, the use of queue additionally ensures
proper burst aggregation on multiple TRXD connections, so all L12TRX
messages are guaranteed to be sent in the right order, i.e. with
monolithically-increasing TDMA frame numbers.

Of course, this change increases the overall CPU usage, given that
each transceiver gets its own queue, and we need to serve them all
on every TDMA frame.  According to my measurements, when running
test cases from ttcn3-bts-test, the average load is ~50% higher
than what it used to be.  Still not significantly high, though.

Change-Id: Ie66ef9667dc8d156ad578ce324941a816c07c105
Related: OS#4658, OS#4546
2020-07-14 17:21:14 +07:00
Vadim Yanitskiy f262caca79 trx_toolkit/clck_gen.py: support optional clock handler
Change-Id: I85b2182d9835ed035cf370e45ea039ac6a7e8405
2020-07-14 17:21:10 +07:00
Vadim Yanitskiy 8d19fbef57 trx_toolkit/clck_gen.py: fix TDMA clock counter wrapping
Change-Id: I157447c7610402f6d62d2b74c9f04fcaa0bc1724
2020-07-14 17:20:14 +07:00
Vadim Yanitskiy 93beb3f5c5 trx_toolkit/clck_gen.py: call send_clck_ind() on every TDMA frame
Change-Id: I6d53e5266fa3b1f2eb55822d1c14975789b202ed
2020-07-14 17:17:38 +07:00
Vadim Yanitskiy e2aaeb59b3 trx_toolkit/fake_trx.py: move Rx burst handling to Transceiver
Change-Id: Ic1f44bfb21ac3173e9530a0a9966cd5e64b8bd48
2020-07-13 08:51:19 +00:00
Vadim Yanitskiy 37c81fea95 trx_toolkit/fake_trx.py: avoid using TRXList.__getitem__()
Running with cProfile shows that there are quite a lot calls:

  469896    0.254    0.000    0.254    0.000 trx_list.py:37(__getitem__)

Let's better avoid using it in performance critical parts.

Change-Id: I2bbc0a2af8218af0b9a02d8e16d4216cf602892a
2020-07-13 08:51:19 +00:00
Vadim Yanitskiy bb0155d0e7 trx_toolkit/burst_fwd.py: inherit trx list API from TRXList
Change-Id: I1c589888991add435d88517094c7b4a7db93cbae
2020-07-13 08:51:19 +00:00
Vadim Yanitskiy 9d24c54f82 trxcon/scheduler: reduce default Uplink burst scheduling advance
In general, premature scheduling of to be transmitted bursts
inevitably increases the time delay between Uplink and Downlink.
The more we advance TDMA frame number, the greater gets this
delay.  20 TDMA frames is definitely more than a regular
transceiver needs to pre-process a burst before transmission.

Change-Id: Ia9b142b59d95f2cd7b2394596cf72c0bcd36d711
Related: OS#4487
2020-07-13 05:00:23 +07:00
Vadim Yanitskiy d39b841059 trxcon/scheduler: check TDMA frame order, drop out of order bursts
When running together with fake_trx.py (mostly used back-end), it
is currently possible that Downlink bursts are received in a wrong
order if more than one transceiver is configured (multi-trx mode).

This is how it looks like:

  DTRXD DEBUG trx_if.c:612 RX burst tn=3 fn=629 rssi=-86 toa=0
  DSCHD DEBUG sched_lchan_tchf.c:60 Traffic received on TCH/F: fn=629 ts=3 bid=1
  DTRXD DEBUG trx_if.c:612 RX burst tn=3 fn=630 rssi=-86 toa=0
  DSCHD DEBUG sched_lchan_tchf.c:60 Traffic received on TCH/F: fn=630 ts=3 bid=2
  DTRXD DEBUG trx_if.c:612 RX burst tn=3 fn=631 rssi=-86 toa=0
  DSCHD DEBUG sched_lchan_tchf.c:60 Traffic received on TCH/F: fn=631 ts=3 bid=3

  DTRXD DEBUG trx_if.c:612 RX burst tn=3 fn=633 (!) rssi=-86 toa=0
  DSCHD NOTICE sched_trx.c:663 Substituting (!) lost TDMA frame 632 on TCH/F
  DSCHD DEBUG sched_lchan_tchf.c:60 Traffic received on TCH/F: fn=632 ts=3 bid=0
  DSCHD DEBUG sched_lchan_tchf.c:60 Traffic received on TCH/F: fn=633 ts=3 bid=1

  DTRXD DEBUG trx_if.c:612 RX burst tn=3 fn=632 (!) rssi=-86 toa=0
  DTRXD NOTICE sched_trx.c:640 Too many (>104) contiguous TDMA frames elapsed (2715647)
                               since the last processed fn=633 (current fn=632)

so here a burst with TDMA fn=633 was received earlier than a burst
with TDMA fn=632.  The burst loss detection logic considered the
latter one as lost, and substituted it with a dummy burst.  When
finally the out-of-order burst with TDMA fn=632 was received, we
got the large number of allegedly elapsed frames:

  ((632 + 2715648) - 633) % 2715648 == 2715647

Given that late bursts get substituted, the best thing we can do
is to reject them and log an error.  Passing them to the logical
channel handler (again) might lead to undefined behaviour.

Change-Id: I873c8555ea2ca190b1689227bb0fdcba87188772
Related: OS#4658, OS#4546
2020-07-12 21:43:46 +07:00
Vadim Yanitskiy bb0609ed48 trxcon/scheduler: fix subst_frame_loss(): do not compensate too much
It's not something that we should be trying to fix, if the whole
TDMA multi-frame is lost.  For some yet unknown reason, sometimes
the difference between the last processed TDMA frame number and
the current one is so huge, so trxcon eats a lot of CPU trying
to compensate nearly the whole TDMA hyper-frame:

  sched_trx.c:640 Too many (>104) contiguous TDMA frames elapsed (2715647)
                  since the last processed fn=633 (current fn=632)

Let's just print a warning and do not compensate more than one
TDMA multi-frame period corresponding to the current layout.

Change-Id: I56251d0d2f6fa19195ff105d3bdfbc22df6db8cd
2020-07-08 15:55:05 +07:00
Vadim Yanitskiy a29277278b trxcon/scheduler: subst_frame_loss(): print current TDMA fn
Change-Id: I3d769ba3cbadc19bac0b25224460af8f06d0d776
2020-07-07 04:05:50 +07:00
Vadim Yanitskiy 3fea4de64e trxcon: use libosmocore's TDMA frame number API
Depends: (libosmocore) Ic291fd3644f34964374227a191c7045d79d77e0d
Change-Id: I49a043d8483e116cf2d91820edb511846175173f
2020-06-19 20:46:45 +00:00
Vadim Yanitskiy cf72753e6a trxcon/scheduler: cosmetic: clarify lost frame counter description
Change-Id: Ied5ea8524f2ec6c324e9fd37256111d099c23e6c
2020-06-18 11:52:06 +00:00
Vadim Yanitskiy 1c0dab9c95 trxcon/scheduler: cosmetic: use enumerated type instead of uint8_t
Change-Id: Idde328d176b4cbd89c62712e4a247095dd596105
2020-06-18 11:52:06 +00:00
Vadim Yanitskiy 0d185cde40 firmware/layer1: cosmetic: add missing comma to debug print
Change-Id: Icfc403e500c24628da722ab378fba31923afd1a1
2020-06-18 11:42:03 +00:00
Vadim Yanitskiy e4d6035a9b firmware/apps/rssi: enlarge text buffer in refresh_display()
This change fixes several warnings reported by GCC 10.1.0:

  apps/rssi/main.c:238:30: warning: 'sprintf' may write a terminating
                           nul past the end of the destination
  apps/rssi/main.c:238:4: note: 'sprintf' output between 10 and 17
                          bytes into a destination of size 16

  apps/rssi/main.c:413:26: warning: '.' directive writing 1 byte into
                           a region of size between 0 and 9
  apps/rssi/main.c:413:3: note: 'sprintf' output between 10 and 20
                          bytes into a destination of size 16

Change-Id: I7980727b78f7622d792d82170f73c90ac5770397
2020-06-18 11:42:03 +00:00
Vadim Yanitskiy 55a63b1759 trxcon: use osmo_{store,load}32be() to pack / unpack TDMA fn
Change-Id: I9eff9b8e4b8ce9e0563a1ec3c485ab8b0f306491
2020-06-14 15:27:27 +07:00
Vadim Yanitskiy f8a3959cb2 trxcon: fix potential buffer overflow in l1ctl_proc_est_req_h1()
Change-Id: I10f03ca66412a4a7094b0f4a7319411d5d5818ef
2020-06-10 17:04:54 +00:00
Vadim Yanitskiy b0b42332df firmware/layer1: remove redundant l1a_*_req declarations
Both symbols are declared in 'layer1/prim.h'.

Change-Id: I36f41870bd63c70259316204ee17071853257ca4
2020-06-09 00:12:39 +07:00
Vadim Yanitskiy e7a5739ea0 firmware: fix compilation with arm-none-eabi-gcc 10.1.0
These symbols are defined, but never used:

  - struct last_rach - seems to be copy-pasted from prim_rach.c,
  - tall_msgb_ctx - already defined in libosmocore.

Change-Id: I6077c8e9b441f7848d1a4c25a8b5e1aed82f4b7d
2020-06-09 00:08:04 +07:00
Pau Espin 3ca971eb2e fake_trx: Support SETPOWER and NOMTXPOWER TRXC cmds
By default RSSI on the Rx side is computed based on transmitter's
tx power and then substracting the the Rx path loss.
If FAKE_RSSI is used, then the values in there are used instead.

A default hardcoded value of tx nominal power = 50 dBm is set to keep
old behavior of RSSI=-60dB after calculations.

Change-Id: I3ee1a32ca22c3272e66b3ca78e4f67d283844c80
2020-06-03 20:22:59 +02:00
Vadim Yanitskiy 0ed7c0ee5f trxcon: fix l1ctl_proc_est_req_h0(): convert to host byte order
L1CTL is using the network byte order, because this protocol is
spoken between different devices and architectures.  Somehow I
forgot about this while adding SETFH command back in 2018.

Change-Id: Ia2f70f0d5e35b6bf05e1fa6fb51a15c1bbe3ca4c
Related: OS#4546
2020-05-28 16:53:51 +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 0a6e083e8a trx_toolkit/data_dump.py: fix return value of parse_msg()
Jenkins build #2516 has uncovered a problem in DATADumpFile.parse_msg():

  ======================================================================
  FAIL: test_parse_empty (test_data_dump.DATADump_Test)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File "/build/src/target/trx_toolkit/test_data_dump.py",
         line 138, in test_parse_empty
      self.assertEqual(msg, False)
  AssertionError: None != False

I did a quick investigation, and figured out that this failure
happens when trying to call parse_msg() with idx == 0, because
DATADumpFile._seek2msg() basically does nothing in this case
and thus always returns True. The None itself comes from
DATADumpFile._parse_msg().

Let's ensure that DATADumpFile.parse_msg() always returns None,
even if DATADumpFile._seek2msg() fails. Also, update the unit
test, so we always test a wide range of 'idx' values.

Change-Id: Ifcfa9c5208636a0f9309f5ba8e47d282dc6a03f4
2020-05-22 18:22:32 +07:00
Vadim Yanitskiy 4f677e6ba8 trxcon: refactor trx_if_cmd_setfh(): send Rx/Tx frequencies
It would make sense to send the ARFCN list in parameters of SETFH
command, if there was a clear distinction between transceivers in
fake_trx.py, i.e. which one is an MS and which is a BTS.

Right now, every Transceiver is an abstract entity that emits
and receives bursts. So when you convert an ARFCN to a pair of
Downlink/Uplink frequencies, you don't know whether it maps
as Rx/Tx or as Tx/Rx for a given Transceiver.

Of course, we could assume that this is an MS specific feature,
and a pair of Downlink/Uplink frequencies always corresponds to
Rx/Tx, but what if some day we would need to implement and test
a similar approach for the BTS side? Also, by sending frequency
values in kHz (rather than ARFCNs) we can avoid inconsistency
with the existing RXTUNE / TXTUNE commands.

Change-Id: Ia2bf08797f1a37b56cf47945694b901f92765b58
Related: I587e4f5da67c7b7f28e010ed46b24622c31a3fdd
Related: OS#4546
2020-05-17 14:46:41 +07:00
Vadim Yanitskiy d8d71f6d24 trxcon: use buffer size macros for TRXC/TRXD messages
Change-Id: I6f2b8682c4691ed3da1bf804e302a7169f33e283
2020-05-17 14:36:32 +07:00
Vadim Yanitskiy 7ec1c1ccc8 trx_toolkit/transceiver.py: add frequency hopping support
There are two ways to implement frequency hopping:

  a) The Transceiver is configured with the hopping parameters, in
     particular HSN, MAIO, and the list of ARFCNs (channels), so the
     actual Rx/Tx frequencies are changed by the Transceiver itself
     depending on the current TDMA frame number.

  b) The L1 maintains several Transceivers (two or more), so each
     instance is assigned one dedicated RF carrier frequency, and
     hence the number of available hopping frequencies is equal to
     the number of Transceivers. In this case, it's the task of
     the L1 to commutate bursts between Transceivers (frequencies).

Variant a) is commonly known as "synthesizer frequency hopping"
whereas b) is known as "baseband frequency hopping".

For the MS side, a) is preferred, because a phone usually has only
one Transceiver (per RAT). On the other hand, b) is more suitable
for the BTS side, because it's relatively easy to implement and
there is no technical limitation on the amount of Transceivers.

FakeTRX obviously does support b) since multi-TRX feature has been
implemented, as well as a) by resolving UL/DL frequencies using a
preconfigured (by the L1) set of the hopping parameters. The later
can be enabled using the SETFH control command:

  CMD SETFH <HSN> <MAIO> <RXF1> <TXF1> [... <RXFN> <TXFN>]

where <RXFN> and <TXFN> is a pair of Rx/Tx frequencies (in kHz)
corresponding to one ARFCN the Mobile Allocation. Note that the
channel list is expected to be sorted in ascending order.

NOTE: in the current implementation, mode a) applies to the whole
Transceiver and all its timeslots, so using in for the BTS side
does not make any sense (imagine BCCH hopping together with DCCH).

Change-Id: I587e4f5da67c7b7f28e010ed46b24622c31a3fdd
2020-05-17 14:36:12 +07:00
Vadim Yanitskiy 220e60184f trx_toolkit/gsm_shared.py: implement hopping sequence generation
Based on firmware/layer1/rfch.c:rfch_hop_seq_gen() by Sylvain Munaut.

Change-Id: I9ecabfef6f5a4e4180956c6a019c386ccb1c9acd
2020-05-17 07:26:07 +00:00
Vadim Yanitskiy 2db781a5d7 trx_toolkit/rand_burst_gen.py: use list comprehension
See previous commit, TL;DR this approach is significantly faster.

Change-Id: I5dc0dda89443d2763bfae50cc402724935cc91b3
2020-05-16 20:17:18 +00: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
Harald Welte e607f7ef18 virt_phy: tweak log levels
Related: SYS#4822
Change-Id: Ia7e368cda8e016a4141b21e5219697420a503124
2020-05-15 08:58:21 +02:00
Oliver Smith 901ac89735 mobile: loopback: support EFR
Related: SYS#4924
Change-Id: I73d1f88b0865ad97b85418ff76739febf2e128a7
2020-05-05 12:22:32 +02:00
Oliver Smith 8f04fa9758 mobile: traffic req check: support EFR
L1CTL handling code should not be involved in such high level checks, so
while at it, move the check into a separate function in gsm48_rr.c and
add a length check. gsm48_rr_tx_voice() is the only caller of
l1ctl_tx_traffic_req().

Related: SYS#4924
Change-Id: Iba84f5d60ff5b1a2db8fb6af5131e185965df7c9
2020-05-05 12:22:26 +02:00
Neels Hofmeyr 3622522664 mobile: implement 'loopback' TCH frame I/O handler
Use newly added audio / loopback config vty node to provide audio
loopback from mobile app. Only FR is supported for now.

Change-Id: Icd0b8d00c855db1a6ff5e35e10c8ff67b7ad5c83
2020-05-05 12:19:58 +07:00
Neels Hofmeyr 785450c4bf mobile: add audio config, with unused audio loopback setting
The aim is to add configurable audio loopback to mobile. An existing patch on a
branch from fixeria [1] adds the audio config section. Add a reduced version of
this audio config to be compatible with the future merge.

Add the audio loopback setting, so far without functionality.
Subsequent patch adds the actual loopback.

[1] osmocom-bb branch fixeria/audio,
    patch "mobile/vty_interface.c: add new 'audio' section"
    Change-id I62cd5ef22ca2290fcafe65c78537ddbcb39fb8c6

Change-Id: Ie03e4a6c6f81ea3925266dd22e87506d722a6e1a
2020-05-05 12:02:31 +07:00
Harald Welte 3425527fb7 firmware/rfch.[ch]: Document functions + constify input arguments
Change-Id: I16d5190b3cdc997c5609b52d41203f10264b017c
2020-04-25 19:08:34 +02:00
Vadim Yanitskiy b217b9b3e5 trxcon/logging: print category, level and extended timestamp
Since we're heavily using trxcon in ttcn3-bts-test, the logging
output should contain as much information as possible. Ideally
we should introduce the VTY interface (see OS#3666) and get
logging configuration options as a bonus. But let's just use
some beneficial hard-coded defaults for now:

  - print category and level (huh, we use NOTICE everywhere?),
  - do not print category-hex (who needs it anyway?),
  - print extended timestamp, so we're in synce with other logs.

P.S. This configuration is based on my own debugging experience.

Change-Id: Ie3d259f3255d8af80e6780f850b808fa243f97b4
2020-04-09 05:13:59 +07:00
Vadim Yanitskiy 75ae23674c trx_toolkit/app_common: add options to enable time printing
Change-Id: Ie5d14a261e17af554f7132b03d58549a4831dcdb
2020-04-09 04:44:49 +07:00
Vadim Yanitskiy ec71203e79 trx_toolkit/app_common: introduce auxiliary add_log_handler()
Change-Id: Ied32764cf1c34dc7e0f746f4f085ea20168775cb
2020-04-09 04:42:45 +07:00
Vadim Yanitskiy 67c49ba664 firmware/layer1: introduce experimental PDCH support
This change implements basic (receive only) support of the PDCH
channels that are used in GPRS. Several coding schemes are
defined by 3GPP TS 45.003, however we can only do CS-1
for now, since it's basically an equivalent of xCCH.

In order to support the other schemes (CS2-4), we would need to
know how to configure the DSP (look at Freecalypso code?).

Change-Id: I44531bbe8743c188cc5d4a6ca2a63000e41d6189
2020-04-01 10:18:54 +00:00
Vadim Yanitskiy 930d7240bf trx_toolkit/trx_sniff.py: add options to filter bursts by RSSI
Change-Id: I16dd29d2f1e14e634029195599fa49a9be9219ab
2020-03-30 19:22:47 +07:00
Vadim Yanitskiy b1f0772002 trx_toolkit/trx_sniff.py: add option to ignore NOPE / IDLE indications
Change-Id: If51052af04289f10bfaefd5374049908de05319a
2020-03-30 19:20:32 +07:00
Vadim Yanitskiy bbd1edccae trx_toolkit/trx_sniff.py: pass the whole msg to burst_pass_filter()
Change-Id: I3da62249a4d62078b79ce5e79c86923e59c1e457
2020-03-30 19:00:45 +07:00
Vadim Yanitskiy 4162b27dae layer23/l1ctl: fix: do not pass PDCH and CBCH frames to LAPDm
GPRS (PDCH) and CBCH related frames have nothing to do with LAPDm.
The former uses LLC for the user-plane data, while CBCH involves
its own segmentation described in 3GPP TS 23.041 and TS 44.012.

There is currently no code for handling these kinds of frames, so
let's just send them to GSMTAP and release the memory (msgb).

Change-Id: I59b4acbe22217f8989f73b79b128a43e8bcdfa2f
Related: OS#4439
2020-03-17 18:25:04 +07:00
Vadim Yanitskiy f889e916a9 trxcon/scheduler: print TDMA statistics on lchan deactivation
Change-Id: If8688ca331a7b1f841aa21f7a5ebc9750327b90a
2020-03-16 10:32:42 +00:00
Vadim Yanitskiy d944f1d89d trxcon/scheduler: be safe against a theoretical integer overflow
As was noted by Pau Espin Pedrol, there is a theoretical chance
that lchan->tdma.num_proc would overflow, so as a consequence,
subst_frame_loss() will be unable to compensate one
(potentionally lost) Downlink burst.

On practice, given the size of unsigned long and duration of a
single TDMA frame, it would only happen once in roughly ~6 years.

  FRAME_DURATION = 4615 * 10e-6
  ULONG_MAX = 2 ** 32 - 1

  FRAME_DURATION * ULONG_MAX -> ~198212740 seconds
                             -> ~55059 hours
                             -> ~2294 days
                             -> ~6 years.

Chances are that trxcon would crash much earlier, or even GSM
would be completely forgotten after such a long time run, but
let's work this around and simply start counting from 1
if that overflow eventually happens.

Change-Id: I3d40ef09b06039a85df52af06ab38de314e1a434
2020-03-16 10:32:42 +00:00
Vadim Yanitskiy 9d3c2d047b trxcon/scheduler: do not abort on incomplete set of bursts
Change-Id: Iea2d1b75b50c2889d4766687ef4fe6ae4ea39a50
2020-03-16 10:32:42 +00:00
Vadim Yanitskiy c86ba06258 trxcon/scheduler: TCH/F: fix Downlink burst completeness check
A TCH/F or FACCH/F frame is interleaved over 8 bursts, not 4.

Change-Id: I2ee4a216a18e9b077b27887235d982481991d9c4
2020-03-16 10:32:42 +00:00
Vadim Yanitskiy d81231672f trxcon/scheduler: align Downlink reception to the first burst
It may happen that the burst reception would start from bid != 0:

  <0005> sched_trx.c:263 (Re)configure TDMA timeslot #2 as TCH/H+SACCH
  <0005> sched_trx.c:420 Activating lchan=TCH/H(0) on ts=2
  <0005> sched_trx.c:420 Activating lchan=SACCH/TH(0) on ts=2
  <0006> sched_lchan_xcch.c:96 Received incomplete data frame at fn=0 (0/104) for SACCH/TH(0)
  <0006> sched_lchan_xcch.c:106 Received bad data frame at fn=0 (0/104) for SACCH/TH(0)

so in that case, both measurement processing and the frame number
calculation would yield incorrect and/or incomplete results. The
Rx burst mask can be used to eliminate this problem.

In particular, if we shift it left instead of cleaning, it would
never be equal 0x00 after at least one burst is received. This
would allow us to skip decoding of an incomplete frame at the
beginning when the logical channel was just activated.

Note that TCH/H handler is not affected because it already uses
the strategy described above, so we keep it unchanged.

Change-Id: Ib8ddf2edd5ef84f2ab12155f7a8874c9fc56d436
Related: OS#3554
2020-03-16 10:32:42 +00:00
Vadim Yanitskiy f5fa7dbd19 trxcon/scheduler: constify Downlink burst bits where possible
Change-Id: Ib3e3a0a5b4551126b1a9439000d4438c58a6a90a
2020-03-16 10:32:42 +00:00
Vadim Yanitskiy 431dcd00f0 trxcon/scheduler: substitute lost TDMA frames on Downlink
It may happen that one or more Downlink bursts are lost on their
way to the MS due to a variety of reasons. Modern transceivers
supporting TRXDv1 protocol would substitute lost bursts with
so-called NOPE indications. Hovewer, neither fake_trx.py nor
grgsm_trx do support this feature at the moment.

We can still detect and compensate TDMA frame loss per logical
channels in the same way as it's already done in osmo-bts-trx.
In short, we should keep TDMA frame number of the last received
burst in the logical channel state, and using the appropriate
multiframe layout, check if there were any gaps between TDMA
frame number of the current burst and the stored one.

Change-Id: I3551d79796a3730565c2c70577e9d134e636f275
2020-03-16 10:32:42 +00:00
Vadim Yanitskiy 8c760f8f05 trxcon/scheduler: refactor TDMA frame number calculation
Using TDMA frame number of a burst with bid=0 is fine for xCCH,
but not for TCH and FACCH, because they use the block-diagonel
interleaving. A single block on TCH may be interleaved over
8, 4 or even 6 consecutive bursts depending on its type.

Since we now have the measurement history, we can attach TDMA
frame number to each measurement set, and then look up N-th
one when averaging the measurements in sched_trx_meas_avg().

Change-Id: I9221957297a6154edc1767a0e3753f5ee383173f
2020-03-16 10:32:42 +00:00
Harald Welte b9ab7150bf virtphy: Delay response between L1SAP_PM_REQ and L1SAP_PM_CONF
Change-Id: I443b5512c4966c232107aeb73e1fd8b83335d63d
2020-03-10 21:24:04 +01:00
Harald Welte c429e7a1d8 virtphy: Add command line arguments to set multicast netdev + TTL
This allows us to bind the multicast sockets to a given network device
and/or to set the TTL of the multicast frames and hence control their
reach in terms of number of network hops.

Change-Id: Ia74aa381a4c1921cb8c7e263842a864ea8028139
Related: OS#2966
2020-03-10 18:58:55 +01:00
Harald Welte 17a9089452 virtphy: Sync virtual_um.[ch] with osmo-bts
The files are used in both projects, and while the osmo-bts code has
evolved, this copy didn't.  Let's sync again (to libosmocore
change-Id I303f2e616d2d32b5a8005c3dcf0f5fad19ad3445).

Change-Id: I189ee28a85a6d7a7a07b062f6b07012478503e8f
Depends: libosmocore.git Ib52d22710020b56965aefcef09bde8247ace4a9c
Related: OS#2966
2020-03-10 18:58:55 +01:00
Harald Welte 419f617a3c virtphy: Fix GSMTAP ARFCN use with multi-TRX BTS
In case we get assignments to secondary TRXs, the ARFCN of that
TRX must be used, and not the serving cell BCCH ARFCN.

Change-Id: Ief6cf5816969d819ff9506be70bec9b8d0d9d9be
2020-03-09 19:35:49 +01:00
Harald Welte a42563b684 virt_phy: implement GSMTAP_CHANNEL_VOICE
GSMTAP_CHANNEL_VOICE is the mechanism by which GSMTAP can [finally!]
be used to transport circuit-switched voice codec payload, and not
just signalling.

Original patch by Neels Hofmeyr, heavily extended by Harald Welte.

Change-Id: Id72cf23b7c6587efae4cdaa7b50ab4d85b8c8d22
2020-03-09 19:35:49 +01:00
Vadim Yanitskiy 61a06f4d36 trxcon/scheduler: fix n_errors for BFI triggered by FACCH
These BFI (Bad Frame Indications) substitute speech frames stolen
by FACCH/F or FACCH/H frames, so there can be no bit errors in
something that was not even transmitted over the air interface.

Change-Id: Icdb6209f75ead6581e3c18aeee0da9831aaa272a
2020-03-08 22:50:54 +00:00
Vadim Yanitskiy 12357a7d37 trxcon/scheduler: FACCH: ensure fake measurements for BFI
According to 3GPP TS 45.003, clauses 4.2.5 and 4.3.5:

 - one FACCH/F frame steals a single speech frame,
 - one FACCH/H frame steals two speech frames.

A BFI (Bad Frame Indication) needs to be sent for each stolen
speech frame. This does not apply to CSD (data) channels though.

The BFI frames must have measurement data attached to them, and
due to their virtual nature (they do not actually come from the
air interface), the measurements must be crafted by trxcon.

Assigning a negative value to n_errors makes the code below the
'bfi' label craft fake measurement data. Otherwise, the actual
measurements belonging to the FACCH frame will be used.

Change-Id: Ia2f7c3cf7b1ef3737da6b1818cae2f001ee8768f
2020-03-08 22:50:54 +00:00
Vadim Yanitskiy 2060b5b7cc trxcon/scheduler: refactor Downlink measurement processing
So far we used to store the sums of ToA and RSSI measurements in the
logical channel state, and after decoding of a block, we did calculate
the average. This approach works fine for xCCH and PDTCH, but when it
comes to block-diagonal interleaving (which is used on TCH/F and TCH/H
channels), the results are incorrect. The problem is that a burst on
TCH may carry 57 bits of one encoded frame and 57 bits of another.

Instead of calculating the sum of measurements on the fly, let's push
them into a circular buffer (the measurement history), and keep them
there even after decoding of a block. This would allow us to calculate
the average of N last measurements depending on the interleaving type.

A single circular buffer can hold up to 8 unique measurements, so the
recent measurements would basically override the oldest ones.

Change-Id: I211ee3314f0a284112a4deddc0e93028f4a27cef
2020-03-08 22:50:54 +00:00
Vadim Yanitskiy d534d43fc1 trxcon/scheduler: TCH/H & FACCH/H: fix notes on interleaving
Change-Id: I16cdd2261b3d0d99286c30584847f93d72d02ac0
2020-03-08 22:50:54 +00:00
Vadim Yanitskiy 03f220ecae trxcon/scheduler: make TDMA_FN_INC(fn) behave like ++fn
Change-Id: I9c2fa26df54b5de836a18f09363a9221c24ae707
2020-03-08 22:50:54 +00:00
Harald Welte a1be0a6b62 cbch_sniff: Use CCCH_MODE_COMBINED_CBCH, not CCCH_MODE_COMBINED
In Change-Id Ia94ebf22a2ec439dfe1f31d703b832ae57b48ef2 we
introduced a new member to the ccch_mode enum: CCCH_MODE_COMBINED_CBCH,
which is to be used to tell the PHY if a CBCH is present on the combined
CCCH+SDCCH/4+CBCH or not (CCCH+SDCCH4).

This was implemented in trxcon + calypso firmware, but cbch_sniff has
not been updated accordingly.

Related: OS#4439
Change-Id: I429d45cfb181da4a2e767e92f1213ccd08c6d440
2020-03-07 16:25:46 +01:00
Harald Welte 90616c1eba virtphy: Don't pass CBCH to L1CTL if not requested by application
Doing so can create a number of warning messages in e.g. 'mobile'
like
<0015> lapd_core.c:1239 Unnumbered frame not allowed. (dl=0x55c632f9f220)
<0015> lapd_core.c:392 sending MDL-ERROR-IND cause 12 from state LAPD_STATE_IDLE (dl=0x55c632f9f220)
<0015> lapdm.c:481 sending MDL-ERROR-IND 12
<0001> gsm48_rr.c:4977 MDL-Error (cause 12) ignoring

Change-Id: I2cf65be5b2f879fe940e08c9f369bc1cada7b0dd
Closes: OS#4439
2020-03-07 16:25:46 +01:00
Harald Welte d32797677d virt_l1_sched_execute: talloc_free() TDMA item after unlinking it
We so far relied on it being free'd once the TDMA item is free'd,
but let's make it more explicit.  After we've unlinked it from the
list, nobody is going to reference it ever again.

Change-Id: I57a596428be10ce720e0b528ecfc44a70e3e3078
2020-03-07 10:31:48 +01:00
Harald Welte ee26ba6e60 cosmetic: Use INIT_LLIST_HEAD() and llist_add_tail()
... instead of manually re-inventing them.

Change-Id: I7e0810aa7fd1daa8f9f3e46a207589a4c6da836b
2020-03-07 10:18:18 +01:00
Neels Hofmeyr 0c77a7f4cf mobile: fix gsm_recv_voice: pull l1ctl header from TCH payload
That function encapsulates the RTP payload in an MNCC header, but the l1ctl dl
header has to be removed first to get only the RTP payload in the MNCC
structure.

Change-Id: Id6ddc9b1da43e88c5b9468d4397a39953bdf533a
2020-03-05 13:32:58 +01:00
Neels Hofmeyr bf4a026db9 remove unused func decl
Change-Id: I94c8fff1557c0ce50cc3072573ef7cda8622fb84
2020-03-05 13:32:56 +01:00
Vadim Yanitskiy 60ce345755 mobile/gsm322: fix use-after-free of cs->si reported by ASan
This pointer cs->si stores an address to the System Information of
a currently selected cell. When we release System Information,
ensure that it does not point to free()d memory.

Change-Id: Ife2ddf7274a48447a9ded9035f9dd01befaf2e6c
2020-03-01 02:22:13 +07:00
Vadim Yanitskiy c083e2ce90 layer23/l1ctl: fix NULL-pointer dereference reported by ASan
Some applications (e.g. ccch_scan) may not initialize ms->cellsel.si,
some (e.g. mobile) may need some time to initialize it. Let's assume
that 'bs_ag_blks_res' is 1 if System Information is not available.

Change-Id: Ie695d9700c01ee1e6778950a2f3c8610b69d2143
2020-03-01 02:22:13 +07:00
Vadim Yanitskiy 3f25909e10 trxcon/scheduler: print completeness of the Rx burst buffers
Change-Id: Ife9f5eabc23aa2eea08b190361e10a98e890d608
Related: OS#3554
2020-03-01 01:46:51 +07:00
Vadim Yanitskiy 2d355c2453 virt_phy/build: add configure option to build with ASan/USBan
Change-Id: I23fc4e38632c02269b3895115ba4e3171cc212d1
2020-02-27 23:46:40 +07:00
Harald Welte 938faa16e4 layer23: Terminate process if L2 socket fails/dissappears
We don't recover from this situation at all, so it's best to
terminate the process.

Change-Id: I487d18e4afe2cae9f777a30864e680b5dc821fc1
2020-02-26 00:13:04 +01:00
Pau Espin 5738e579b2 layer23: Fix build against gpsd >= 3.20
During 3.19->3.20 dev cycle, some fields were transformed from
timestamp_t or double to timespec_t. See for instance gpsd.git
f7c230fceb6d64483757f8c32afb98e6a2cb9413.

Change-Id: Ie8ba19d030b6f46f2d8afc270a732ce8c26c438f
2020-01-13 17:28:25 +01:00
Pau Espin 6970755342 layer23: Avoid sending downlink AGCH/PCH fill frames over GSMTAP
Some bits are taken from osmo-bts l1sap.c.

Change-Id: Id21e9334b620b8ab3ad404708bfd5358e3555ab6
2019-12-31 17:05:50 +00:00
Pau Espin ae431deae4 layer23: Identify AGCH from PCH on tx of GSMTAP downlink messages
Some bits are taken from osmo-bts l1sap.c

Change-Id: I0adab003a4060c9cef730e0432859659c51bd087
2019-12-31 17:05:50 +00:00
Pau Espin 750faef5ba mobile: Send correct ARFCN in UL gsmtap
Change-Id: I9f677866095413a0efeb8a336ce15a2dbca2228c
2019-12-31 17:05:50 +00:00
Vadim Yanitskiy 7a49fc31c1 trx_toolkit/data_dump.py: rewrite unit tests to use unittest framework
Change-Id: I8b934c15ba96d856aa79d10bf296d1446f043dd1
2019-12-31 17:03:12 +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
Pau Espin 4ddb2e61c7 layer23: Fix trailing whitespace
Change-Id: I295f285e5fc3cdc372723f6b4de2415a94d4979a
2019-12-20 16:47:21 +01:00
Pau Espin 5b7fc0a8cc trxcon: Use current MS Power on dummy meas reports
backpointers are added in order to access the TRX, as advised in the
existing comment.

Change-Id: I975cfc5f5d63eb32a7f8932a7f6a544c9a12233c
2019-12-04 14:41:56 +01:00
Vadim Yanitskiy 7069dfc051 trxcon/sched_trx.c: fix potential NULL-pointer dereference
Change-Id: If1ecd9f5a70fa448327c62d38d76c8443b939248
2019-12-01 13:11:42 +00:00
Harald Welte 0356e56572 Check for osmo_fsm_register() error return value
Change-Id: I3e849b7ec8a7ed610f779dac57cc0c1d1aeb1aa5
2019-12-01 13:46:06 +01:00
Vadim Yanitskiy a15fbcbdf3 trx_toolkit/clck_gen.py: drop unneeded debug print()
Change-Id: I372af77d5b0b24fa38e304b782ca5b3d0888211b
2019-11-24 02:24:42 +07:00
Vadim Yanitskiy 6b0946ee69 trx_toolkit/clck_gen.py: turn CLCKGen's thread into a daemon
If the main thread crashes, the CLCKGen's thread would never stop.
It would also happen if the main thread terminates without calling
CLCKGen.stop().  Let's prevent this by creating a daemon thread.

Change-Id: I9d41c5baa25fa0a263758414a164c1bded25e04e
2019-11-24 02:24:42 +07:00
Vadim Yanitskiy baf07c4be2 trx_toolkit/clck_gen.py: refactor CLCKGen to use a single thread
The previous approach was based on threading.Timer, so on each clock
iteration one thread spawned another new thread.  So far it worked
well, but such frequent spawning involves an additional overhead.

After this change, CLCKGen.start() allocates and starts a new thread,
that periodically sends clock indications and sleep()s during the
indication intervals.  The CLCKGen.stop() in its turn terminates
that thread and frees the memory.

Change-Id: Ibe477eb0a1ee2193c1ff16452a407be7e858b2ef
2019-11-24 02:24:34 +07:00
Vadim Yanitskiy ae8e5ad648 trx_toolkit/fake_trx.py: send NOPE.ind in case of path loss simulation
Since TRXD header version 1, we should send NOPE indications to the
L1 side in absence of TRX2L1 bursts, and IDLE indications during
IDLE TDMA frames (basically noise measurements).

This change is the first step towards the goal: if a given burst
is to be dropped due to the path loss simulation (see FAKE_DROP),
mark the carrier TRX2L1 message as NOPE.ind and send anyway.

Change-Id: Iabd0af665e3108d23a908638f943a5b689986e2c
Related: OS#3428, OS#2975
2019-11-20 15:05:57 +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 b1ae186c55 trx_toolkit/fake_trx.py: refactor L12TRX -> TRX2L1 burst transformation
The burst transformation in BurstForwarder.forward_msg() used to be
done only once, so then the resulting message was distributed over
the list of connected (and active) transceivers.

This approach limits the path loss simulation capabilities, because
a reference to the same message is passed to FakeTRX.send_data_msg().
If one transceiver changes (or removes) the burst bits, the other
transceivers would not receive the original message.

Let's do the transformation individually for each transceiver,
so the original message will always remain unchanged.

Change-Id: Ia016a3a9bb6e9f17182a7168aa5a501ae9b9978b
2019-11-20 15:05:57 +00:00
Vadim Yanitskiy 65dbd471fc mobile/gsm48_mm.h: use fixed-size integer types in packed structures
Change-Id: I54ed93c03ebe776bdc7eb761a8194da3ab0b67fb
2019-11-17 19:09:59 +07:00
Vadim Yanitskiy 62164b9eab mobile/gsm48_mm.h: mark some structures as 'packed'
In several code paths we put / push structures from 'gsm48_mm.h' into
the message buffers, so then they're unpacked by the message receivers.

The AddressSanitizer complains about unaligned pointer access and
potentially unexpected behaviour. Let's fix this by explicitly
marking those structures as 'packed'.

Change-Id: I6af7475c609b3293af708540d569fe1616fab43f
2019-11-17 18:49:11 +07:00
Vadim Yanitskiy afd5b8247f mobile/gsm48_rr.c: fix NULL-pointer dereference in gsm48_rr_check_mode()
In some cases (e.g. at start up) ms->rrlayer may not be initialized.
Let's access ms->settings directly since we already have a pointer
to struct osmocom_ms.

Change-Id: Ia9720132fcda960dcecefab9ae48398946503dc4
2019-11-17 17:46:48 +07:00
Vadim Yanitskiy 2605d96720 trx_toolkit: fix: do not use 'is' / 'is not' with string and numerical literals
Since version 3.8, Python warnins us that using the "is" and "is not"
operators with string and numerical literals is a bad idea. Let's
avoid this and use the classical '==' and '!=' operators instead.

Change-Id: Iaed86d630ac1e0b9b4f72bbf3c788e325783456d
Bug description: https://bugs.python.org/issue34850
2019-11-17 17:46:48 +07:00
Pau Espin eb0560e19e trxcon: Fix missing header for GSM_MACBLOCK_LEN
Due to recent include dependency tree change in libosmocore, trxcon
fails now to build since it uncovered it's missing a header inclusion
for a symbol it is using:

osmocom-bb/src/host/trxcon/sched_trx.h:204:20: error: ‘GSM_MACBLOCK_LEN’ undeclared here (not in a function)
  204 |   uint8_t mr_cache[GSM_MACBLOCK_LEN];
      |                    ^~~~~~~~~~~~~~~~

Change-Id: Ide22e525c106342b00171a8c08bb7265d19a651b
2019-11-05 12:52:22 +01:00
Martin Hauke a4046877c6 Fix typo: miliseconds -> milliseconds
Change-Id: I472c12fd1dfbff4ca1ead972535d735857f1c3e7
2019-10-22 14:07:31 +00:00
Martin Hauke 1f7a2ab5d3 Fix common misspellings and typos
Change-Id: I962b42871693f33b1054d43d195817e9cd84bb64
2019-10-17 08:07:39 +00:00
Vadim Yanitskiy 9731f0d322 host/trxcon: add optional GSMTAP frame logging support
This feature may be useful for our TTCN-3 testing infrastructure.
By default it's disabled, and can be enabled using command line
arguments of the main binary:

  ./trxcon -g 127.0.0.1 ...

Change-Id: Iab4128fee5f18d816830fdca6c5ebebaf7451902
2019-10-05 17:50:20 +07:00
Vadim Yanitskiy 5516b42336 trxcon/scheduler: fix handling of PTCCH logical channel
According to 3GPP TS 45.010, section 5.6.2, for packet-switched
channels the BTS shall monitor the delay of the Access Bursts
sent by the MS on PTCCH and respond with timing advance values
for all MS performing the procedure on that PDCH.

According to 3GPP TS 45.002, section 3.3.4.2, PTCCH (Packet Timing
advance control channel) is a packet dedicated channel, that is
used for continuous Timing Advance control (mentioned above).

There are two sub-types of that logical channel:

  - PTCCH/U (Uplink): used to transmit random Access Bursts
    to allow estimation of the Timing Advance for one MS in
    packet transfer mode.

  - PTCCH/D (Downlink): used by the network to transmit
    Timing Advance updates for several MS.

As per 3GPP TS 45.003, section 5.2, the coding scheme used for
PTCCH/U is the same as for PRACH as specified in subclause 5.3,
while the coding scheme used for PTCCH/D is the same as for
CS-1 as specified in subclause 5.1.1.

The way we used to handle both PTCCH/U and PTCCH/D is absolutely
wrong - it has nothing to do with xCCH coding. Instead, we need
to use rx_pdtch_fn() for Downlink and tx_rach_fn() for Uplink.

Also, since we only have a shared RSL channel number for PDCH
(Osmocom-specific RSL_CHAN_OSMO_PDCH), there should be a way
to distinguish both PDTCH and PTCCH logical channels. Let's
introduce TRX_CH_LID_PTCCH for that.

Change-Id: I2d1e9b8a66f027047f8d7bdc3f82ff9d8ebcc25e
2019-09-30 20:50:28 +07:00
Vadim Yanitskiy a2ac6d6724 trxcon/scheduler: fix comment in description of PDTCH
Change-Id: Ifd4197b64e89ae6da93ef32189f437a6e297b03f
2019-09-30 20:50:14 +07: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 5fed799df3 trx_toolkit/trx_sniff.py: also print header for incorrect messages
Change-Id: I376f1e7af46750e53305109cf4a9f64427b9960c
2019-08-27 21:13:31 +02:00
Vadim Yanitskiy 83a41a63b2 trx_toolkit/trx_sniff.py: also validate() sniffed messages
Change-Id: Ica3e4702fdabfdae0c1025b650ff32c8e85a6edf
2019-08-27 21:06:58 +02:00
Vadim Yanitskiy 78199f4f7b trx_toolkit/trx_sniff.py: print exact message parsing error
For sure, the following message is much more informative:

  Ignoring an incorrect message: Unhandled version 12

than:

  Failed to parse message, dropping...

NOTE: since the way of printing exceptions is different in both
Python versions, I had to drop Python 2 support.

Change-Id: I5fb02ce508c58ff94e47accc0ed655939eb53062
2019-08-27 21:04:47 +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
Steve Markgraf ad84c7b2f7 fw: Add support for Huawei GTM900-B modules
Both MG01GSMT and MG01GSMT hardware variants are
supported and automatically detected based on the
flash manufacturer.

Change-Id: I3a770ea93fc72c4e9b63078e253602f204b5be23
2019-08-11 13:33:30 +02:00
Steve Markgraf 8a8f9dfb08 fw/flash: Read extended ID, expose API
We now unlock the flash before reading the
extended ID (required for Spansion and Samsung
flash chips). These commands will be ignored
by Intel/ST flash chips, and this change has been
verified with all flash chips we support.

Furthermore, expose the API for reading the flash ID.

Change-Id: I3bcd71c84c8931bcd574953063737b51a41738a3
2019-08-11 13:33:30 +02:00
Steve Markgraf a94fc842d3 fw/keypad: Poll Iota powerbutton if required
This commit adds polling of the TWL3025 PWON
signal. If the powerbutton is pressed on targets
that use it (Pirelli DP-L10, Huawei GTM900-B),
a normal keypad scanning cycle is started in order
to preserve the timing, required for the 500ms
power off press duration for example.

Change-Id: I904baf40d621bd680b602b88d12ff462b3c17596
2019-08-11 13:33:29 +02:00
Steve Markgraf da7cd7408a fw/abb/twl3025: Add function to query PWON state
This allows us to detect power button presses on the Pirelli
DP-L10 and the Huawei GTM900-B module. Polling will only be
activated once the power button has been pressed and we received
the interrupt. The goal is to reduce the required amount of
TWL3025 register accesses to a minimum.

Change-Id: I31be61c8089173aed616abd1ede6c4cf5c9b6770
2019-08-11 13:33:29 +02:00
Steve Markgraf a1de51d357 fw/build: Use arm-none-eabi as default toolchain
This is what we describe in our wiki and what ships with recent
distros.

Change-Id: I70da7eeb33275fa5fff1d8a3581c384e031b12e5
2019-08-11 13:33:27 +02:00
Alexander Couzens f5afdf4c20 fb_tools/bdf_to_c.py: make it compatible with python3
This would break python2 compatibility.

Change-Id: Iaa20dd0aafa20e36186cf8dfe4d0ac9ab638f235
2019-08-09 13:33:17 +00:00
Pau Espin 2cc3392706 trx_toolkit: Fixes in TRXD documentation
Change-Id: I126a8aed6b2bac7a620e95f06ecb98642a63b5f0
2019-08-05 16:24:40 +02:00
Pau Espin 94b1dce6d1 Remove undefined param passed to logging_vty_add_cmds
Since March 15th 2017, libosmocore API logging_vty_add_cmds() had its
parameter removed (c65c5b4ea075ef6cef11fff9442ae0b15c1d6af7). However,
definition in C file doesn't contain "(void)", which means number of
parameters is undefined and thus compiler doesn't complain. Let's remove
parameters from all callers before enforcing "(void)" on it.

Change-Id: I25baaa30b097dad2fae507c5321778f43e863611
Related: OS#4138
2019-08-05 16:24:40 +02:00
Vadim Yanitskiy fe981d65da trx_toolkit/trx_sniff.py: support additional capture filter
Change-Id: I761debb2e1c411f2c6d489eac0adf32060966a4c
2019-07-24 05:44:19 +07:00
Vadim Yanitskiy 710503bc4c trx_toolkit/trx_sniff.py: support sniffing on multiple ports
Change-Id: I76b818c673b98c427b5621ddb852f947c74557d6
2019-07-24 05:44:19 +07:00
Vadim Yanitskiy e92c9cd923 trx_toolkit/trx_sniff.py: add support for reading from PCAP file
Change-Id: I8a3481fbea5f6c917ae5684d0b5b806f4a76ff78
2019-07-24 05:44:19 +07:00
Vadim Yanitskiy 7cde195e30 trx_toolkit/burst_gen.py: basic TRXD header version 1 support
Change-Id: Icd4505d211816dc80e91d65094be92f2aed856bd
2019-07-24 05:44:19 +07:00
Vadim Yanitskiy 88e1620502 trx_toolkit: fix compatibility with Python 3: 'is' vs '=='
Change-Id: I8ba05c04f206578cf61df58573c24cba1d6fba52
2019-07-24 05:44:19 +07:00
Vadim Yanitskiy d206f0cc2f trx_toolkit/rand_burst_gen.py: fix compatibility with Python 3
Change-Id: I362881af83664f94be09d40f43dfb23d18a35136
2019-07-24 05:44:19 +07:00
Vadim Yanitskiy 06e3b4fa54 trx_toolkit/trx_sniff.py: fix compatibility with Python 3
Change-Id: I9cd9b7baae31045c6495b90df2517d32772098ed
2019-07-24 02:05:35 +07:00
Harald Welte d0a8b49d51 gsm411_sms.c: Handle negative return of gsm340_gen_oa()
Change-Id: I36f56e1fbd72d9b31350dc2f8a53e763f79f4c08
Closes: CID#198533
2019-07-21 15:46:57 +00:00
Harald Welte d38ea94fab virt_phy: Fix hexdump of L1CTL SIM REQ in l1ctl_rx_sim_req()
Change-Id: I74e07e2c97bfe5d6e9c6e848ebce58ced1b197aa
Closes: CID#198538
2019-07-21 13:40:43 +00:00
Vadim Yanitskiy e6f5a88463 mobile/gsm480_ss.c: gsm480_tx_release_compl(): fix cause IE encoding
According to GSM TS 04.08, section 10.5.4.11, location and coding
standard are encoded before the cause value, not vice-versa!

Also, coding standards other than "1 1 - Standard defined for the
GSM PLMNs" shall not be used if the cause can be represented with
the GSM standardized coding.

Change-Id: Ic6abcfb9a9589f5b0c9c40def863f15ae04d0bdd
2019-07-21 16:05:28 +07:00
Harald Welte cfd28d5e29 virtphy: Handle strtok() returning NULL on first call
Change-Id: I37bfb91cf75982bfa2f75bd62d0c13859268cd93
Closes: CID#198565
2019-07-21 09:04:16 +02:00
Harald Welte cb587bb29e osmocon: Check write() return code
Change-Id: I61d8f104a4d2558fd5b6fb34c7f2fd6c13354c12
Closes: CID#198567
2019-07-21 09:02:55 +02:00
Harald Welte 58425e978d osmocon: Add missing check for fstat() return value
Change-Id: Ibef6ee00eb41e16d2ef52931f8c22562090cd1ee
Closes: CID#198570
2019-07-21 09:01:17 +02:00
Harald Welte 6b9df297dc mobile: Fix encoding of cause in gsm480_tx_release_compl()
Change-Id: Iba2ace7d82be5677d28b25f60ab0312fed76f5e5
Closes: CID#198577, CID#198576, CID#198575
2019-07-21 08:53:50 +02:00
Harald Welte a044bb6275 osmocon: Fix file descriptor + mem leak in error path
Change-Id: I42ceed662889084783dc89f4ca39c3852428d108
Closes: CID#198539
2019-07-21 08:33:06 +02:00
Harald Welte 5c2a64ca96 gsm322: Fix resource leak in gsm322_init() while reading BA
Change-Id: Id42102ab8581e247f495fb7e05dc62a6743d28c5
Closes: CID#198546
2019-07-21 08:29:34 +02:00
Harald Welte 5b759f7f1e osmocon: Fix fd leak in error path of read_file()
Change-Id: Iaae407658df184277f6e6e07d6a48d8b5c75587b
Closes: CID#198552
2019-07-21 08:12:59 +02:00
Harald Welte 7f7a7c850e osmocon: Fix out-of-bounds for partial reads in un_tool_read()
"uint8_t buf[4096]; ... &buf + 1" renders an offset of 4096, and not 1!

Change-Id: Ie1407371fe949c3d5746b9fdc32ececc9443692b
Closes: CID#198580
2019-07-21 08:05:22 +02:00
Harald Welte 4b742700a4 virtphy: Fix array out of bounds access in getL1ctlPrimName()
Closes: CID#198573
Change-Id: I6504a7ffcf961d3162e6ab2ec8f5f2016ef12cde
2019-07-21 08:01:09 +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 3d9a1d6e48 trx_toolkit/fake_trx.py: introduce a TRXC command for C/I simulation
C/I (Carrier-to-Interference ratio) is a value in cB (centiBels),
computed from the training sequence of each received burst,
by comparing the "ideal" training sequence with the received one.

This change introduces a new command similar to FAKE_TOA and FAKE_RSSI,
so it can be used by TTCN-3 test case 'TC_pcu_data_ind_lqual_cb' to
verify that the link quality measurements are delivered to the PCU.

Change-Id: I7080effbbc1022d1884c6d6f0cb580eba8e514ff
Related: OS#1855
2019-07-16 14:52:24 +07:00
Vadim Yanitskiy 13ec32d380 trx_toolkit/ctrl_if_trx.py: implement TRXD header version negotiation
Messages on DATA interface may have different header formats, defined
by a version number, which can be negotiated on the control interface.
By default, the Transceiver will use the legacy header version (0).

The header format negotiation can be initiated by the L1 using the
'SETFORMAT' command. If the requested version is not supported by
the transceiver, status code of the response message should indicate
a preferred (basically, the latest) version. The format of this
message is the following:

  L1 -> TRX: CMD SETFORMAT VER_REQ
  L1 <- TRX: RSP SETFORMAT VER_RSP VER_REQ

where:

  - VER_REQ is the requested version (suggested by the L1),
  - VER_RSP is either the applied version if matches VER_REQ,
    or a preferred version if VER_REQ is not supported.

If the transceiver indicates VER_RSP different than VER_REQ, the L1
is supposed to reinitiate the version negotiation using the suggested
VER_RSP. For example:

  L1 -> TRX: CMD SETFORMAT 2
  L1 <- TRX: RSP SETFORMAT 1 2

  L1 -> TRX: CMD SETFORMAT 1
  L1 <- TRX: RSP SETFORMAT 1 1

If no suitable VER_RSP is found, or the VER_REQ is incorrect,
the status code in the response shall be -1.

As soon as VER_RSP matches VER_REQ in the response, the process
of negotiation is complete. Changing the header version is
supposed to be done before POWERON, but can be also done after.

Change-Id: I8d441b2559863d2dbd680db371062e4f3a2f9ff9
Related: OS#4006
2019-07-16 14:52:24 +07:00
Vadim Yanitskiy ebf676597b trx_toolkit/fake_trx.py: basic TRXD version 0x01 support
Since the new TRXD header format has been introduced, FakeTRX needs
to be able to fill it correctly. In particular, the following:

  - Modulation, which can be determined from the burst length;
  - Training Sequence Code (and set), which needs to be detected
    by comparing the burst bits of L12TRX message against known
    training sequences (only GMSK and the default TS set for now);
  - C/I (Carrier-to-Interference ratio), which can be simulated
    later on, as instructed on the TRXC interface ('FAKE_CI').

The actual TRXD header version is stored in the instance of class
DATAInterface. By default (at startup), legacy version 0 is used.
The version negotiation is supposed to be performed on the TRXC
interface, and to be implemented in a follow-up change.

Different Transceivers may use different header versions, thus in
FakeTRX.send_data_msg() we need to override the original version
of the L12TRX message, and generate the corresponding PDU.

Limitations:

  - NOPE / IDLE indications are not (yet) supported;
  - TSC detection: GMSK modulation only.

Change-Id: I164f5ae4ce7694d6e324aab927a04e96d489ebd8
Related: OS#4006
2019-07-16 04:07:34 +00:00
Vadim Yanitskiy 6780e47b6c trx_toolkit/rand_burst_gen.py: use TrainingSeqGMSK and BurstType enums
Change-Id: I8a3faceae4a8d9b57d86d42600db839da073dad6
2019-07-16 04:07:34 +00:00
Vadim Yanitskiy dfa43a3892 trx_toolkit/gsm_shared.py: introduce a new enum TrainingSeqGMSK
Training Sequences are defined in 3GPP TS 45.002, and used by the
transceiver for detecting bursts. This change introduces an enum
with training sequences for GMSK for Access and Normal bursts.

This enumeration is needed for the follow-up changes that implement
TRXD header version 1 support, and can now be used by RandBurstGen.

Change-Id: If3bf102019ef53d6ee9ad230ef98bb45845b5af5
2019-07-16 04:07:34 +00:00
Alexander Couzens 1fa8e29e69 target_dsp/bin2cfile.py: make it compatible with python3
Change-Id: I2659c2e4633bd120cc6cd76942eff5b66d2057bb
2019-07-11 16:10:43 +02:00
Alexander Couzens 37575534a4 firmware/solve_envs.py: make it compatible with python3
Change-Id: I711df515012f5542de5e5008c8fe4e601609759e
2019-07-11 16:10:40 +02: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 0ded4757be trxcon/scheduer: fix: properly check rc of gsm0503_pdtch_encode()
The gsm0503_pdtch_encode() returns negative number on error,
and the amount of encoded bits in case of success.

Change-Id: I7d75141142922909330c5e86be8734bb06cd57a4
2019-06-30 17:30:11 +07:00
Vadim Yanitskiy c89047d8bc trxcon/scheduler: enrich GSM 05.03 encoding error messages
Change-Id: I35a7c5df4fc0ed2195ba721f92812874011459d9
2019-06-30 17:28:06 +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
Eric Wild 4269c4d00b trxcon/scheduler: fix bit shift in BSIC / TDMA FN calculation
Ubsan is unhappy about shifts into the sign bit of our implicitly
promoted value.

Change-Id: I4e72db1143a68064ba83668414dc3d60c0e1ad78
2019-06-24 12:55:52 +00:00
Vadim Yanitskiy 924d2412c4 trxcon/l1ctl.c: properly handle handover RACH request
During the handover the MS needs to release the existing dedicated
channel(s), establish the new one(s) as indicated by the network,
and then, depending on the synchronisation state, send one or more
HANDOVER ACCESS messages carried by Access Bursts.

In order to implement this, trxcon needs to be able to transmit
Access Bursts on any TDMA timeslot regardless of the logical
channel type and the associated handler, i.e. != TRXC_RACH.

The controlling side on L1CTL (layer23 or TTCN-3) needs to send
one or more L1CTL_RACH_REQ message(s) with properly populated
UL info header. Otherwise a regular RACH on TS0 is assumed.

Change-Id: Ia967820a536c99966ba2c60b63d2ea9edb093f46
2019-06-02 12:44:12 +00:00
Vadim Yanitskiy 91d5e5e191 trxcon/scheduler: fix: do not ignore SACCH prims with odd length
Before this patch, prim_dequeue_sacch() used to ignore SACCH primitives
with odd length (e.g. 21, when sender forgot to push 2 octets of L1
SACCH header), so neither they were transmitted, nor rejected.

As a result, they would stay in the Tx queue until a dedicated
connection is released. The only way to notice such problem
was looking at the constantly growing talloc's report.

Instead of ignoring the primitives with odd length and keeping them
in the queue, let's pass them to a logical channel handler, so they
would be dequeued and rejected with a proper logging event.

Also, to simplify further debugging, let's print the final decision
of SACCH prioritization: whether it's a Measurement Report or not.

Change-Id: I3149fa518439470b397953306209eb859c83450a
2019-06-02 04:04:08 +07: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 3655350992 trxcon/sched_mframe.c: mark all stolen CBCH UL slots as TRXC_IDLE
According to 3GPP TS 05.02, section 6.4.1, CBCH replaces
SDCCH number 2 in both V (BCCH+CCCH+SDCCH/4+SACCH/4) and
VII (SDCCH/8+SACCH/8) logical channel combinations.

Unfortunately it is not clear whether we can use stolen UL slots
for RACH or not. For now, we should mark all of them as IDLE.

Somehow TRXC_SDCCH4_2 slots were left in the definition of
combination V (combined CCCH+BCCH). This is not critical,
but may be looking confusing. Let's fix this.

Change-Id: Id30f2fac3274de3edff4ae59f77d9c9cf8059155
2019-05-31 16:51:44 +00:00
Harald Welte 49bec6c478 trxcon/trx_if.c: Dropping UL bursts is a noticeable event
Therefore we should use LOGL_ERROR instead of LOGL_DEBUG.

Change-Id: If5084feb9e847d212530b1a5985390405d91008b
2019-05-31 22:40:55 +07:00
Harald Welte fd6c211eab trxcon: Suppress POWERON to TRX if we're already powered on.
The existing logic unconditionally wants to send a POWERON command
on TRXC whenever L1CTL_FBSB_REQ is received.  That may cause some
problems when sending subsequent L1CTL_FBSB_REQ, e.g. due to signal loss.

Sending POWEROFF when transceiver is not powered on is normal though.
This can happen if trxcon is restarted while fake_trx was running.

The existing FSM state could unfortunately not been used, as it's a
mixture between the TRX connection state and the command/response state.

The current solution is just a work around. We definitely need to
introduce separate state machines for transceiver and its TRXC
interface.

Change-Id: I834e8897b95a2490811319697fc7cab6076db480
2019-05-31 22:35:31 +07:00
Vadim Yanitskiy 1a66c2991c trxcon/scheduler: move PRIM_IS[_EXT]_RACH macros to sched_trx.h
Both PRIM_IS_RACH() and PRIM_IS_EXT_RACH() macros to be used for
handover RACH detection in the follow up changes, thus we need
have them widely available. Let's also give them better names:

  PRIM_IS_EXT_RACH -> PRIM_IS_RACH11
  PRIM_IS_RACH     -> PRIM_IS_RACH8

and introduce a new generic one for checking whether a given
primitive is RACH in general (either 8-bit or 11-bit) or not.

Change-Id: Ibc39c57fda000647be1829786f6423dcf3f435cd
2019-05-30 03:59:16 +07:00
Vadim Yanitskiy 043136937a trxcon/l1ctl.c: on L1CTL_DM_EST_REQ, determine pchan_config first
It makes sense to do this first, before tuning to a different
ARFCN and changing the training sequence. Otherwise, if no
multi-frame configuration is found, trxcon would switch to
a different channel and then remain inactive there.

Change-Id: I274588ce3a9c49372b5da0629930afece46f799c
2019-05-29 18:53:31 +07:00
Vadim Yanitskiy 1efe26f41a trxcon/l1ctl.c: use #define for RSL_CHAN_RACH
Change-Id: Ifdb1703217c7540344cf6772efe812c8a786a0c2
2019-05-28 20:27:42 +07:00
Vadim Yanitskiy 08a1990272 trxcon/sched_mframe.c: do not hard-code lchan combinations
Having magic pre-calculated hex-masks gives one quite high chances
to shoot oneself in the foot, and decreases readability in general.

Let's do this pre-calculation during the compilation process, so
it's much easier to read, extend and spot potential bugs.

Change-Id: If945b3654e35c83fc0220fdd6d99c1c7a0503386
2019-05-28 19:20:38 +07:00
Vadim Yanitskiy 189da79ebb trxcon/sched_lchan_desc.c: fix missing TRX_CH_FLAG_AUTO flag
In I2fc61e1cdca4690a34e2861b9ee3b7c64ea64843 I introduced a regression.
TRXC_SDCCH4_CBCH should have TRX_CH_FLAG_AUTO, because it's a part of
GSM_PCHAN_CCCH_SDCCH4_CBCH multi-frame layout. If the controlling
side on the other end of the L1CTL link requests this particular
multi-frame layout, CBCH channel is expected to be active.

Change-Id: I3ed942106a03220417b5cb9176107af057120fbe
2019-05-28 16:22:15 +07:00
Harald Welte 27b6bb0721 virt_phy: Fix typo in log message
Change-Id: I9291957ef5d7033d46060d07f2aa0a3880612e1a
2019-05-28 06:32:34 +00:00
Harald Welte d5ff9bb1aa layer23: fix tons of compiler warnings, mostly OSMO_DEPRECATED related
Change-Id: I03918bd864c711b377a795186123c85bb6f4dc4a
2019-05-28 06:32:34 +00:00
Vadim Yanitskiy d0588f31f4 trxcon/scheduler: refactor description of TRXC_* lchans
Let's avoid fancy alignment in the description of logical channels
for the benefits of having better readability, the ability to add
more comments and fields without making it look ugly.

Also, let's get rid of field 'chan' of 'trx_lchan_desc' structure
since it's not used anywhere, and not actually needed because the
position of each lchan description is defined by its TRXC_* type.

As a bonus, let's add a human readable description to each
lchan definition, so it can be printed in the VTY some day.

Change-Id: I2fc61e1cdca4690a34e2861b9ee3b7c64ea64843
2019-05-28 07:12:09 +07:00
Vadim Yanitskiy a42f2ef127 trxcon/sched_trx.c: add missing branch for GSM_PCHAN_PDCH
PDCH channel support was introduced quite a while ago, but there
was no way to activate it via L1CTL so far. Let's fix this.

Change-Id: I3b66cab26108ab999a7fe969365ab57dc661399c
2019-05-28 07:12:09 +07:00
Vadim Yanitskiy 923c19a883 firmware/scheduler: Fix CBCH related RSL channel numbers
CBCH support in the firmware has been introduced almost at the same
time it was implemented in trxcon, and the same mistake was made
as described in Ia9a415628c659cbc2dd5dc65b875b7f935d6e211.

Despite Calypso based PHY does not support PDCH (GPRS channels),
let's avoid collisions and use the following cbits values:

  0x19 / 0b11001 - MF_TASK_SDCCH4_CBCH on GSM_DCHAN_SDCCH_4_CBCH,
  0x1a / 0b11010 - MF_TASK_SDCCH8_CBCH on GSM_DCHAN_SDCCH_8_CBCH.

Change-Id: Ibb0f90695460e6ede12016c12a0cfdf9c74dfb24
Related: OS#4027
2019-05-28 06:43:37 +07:00
Harald Welte c1e2ff6525 trxcon: Use RSL channel mode #defines from libosmogsm
Wherever possible, use #defines from libosmogsm as opposed to magic
numbers.  Using magic numbers in several places has the danger of
different programs/repositories having different views on what those
values mean.

Change-Id: I7ab4958801b3422973b67ff0452b90afa8a3f501
Related: OS#4027
Depends: libosmocore Change-Id I93e557358cf1c1b622f77f906959df7ca6d5cb12
2019-05-27 23:34:21 +02:00
Harald Welte 9ba051bae8 trxcon: Fix CBCH related RSL channel numbers
OsmoBTS, BSC and TTCN3 used cbits == 0x18 for dynamic PDCH, while
trxcon wanted to use 0x18 for CBCH on SDCCH/4.  Let's fix this and
bring everyone in agreement.

Related: OS#4027
Change-Id: Ia9a415628c659cbc2dd5dc65b875b7f935d6e211
2019-05-27 23:33:42 +02:00
Harald Welte 00513d65c8 common/sap_fsm.c: fix missing pointer dereference
sap_fsm.c: In function ‘sap_negotiate_msg_size’: sap_fsm.c:103:15:
warning: passing argument 1 of ‘__bswap_16’ makes integer from pointer
without a cast [-Wint-conversion]:

  size = ntohs((uint16_t *) param->value);
               ^~~~~~~~~~~~~~~~~~~~~~~~~

Change-Id: Ie58af6162c67ae377809b42daa897ca3f3d72af1
2019-05-23 16:02:16 +03:00
Harald Welte e6a5342272 layer23: Fix 'make distcheck'
Change-Id: Ic48e240ee1484aaa793af23c62a24d2949900b86
2019-05-22 21:39:38 +02:00
Harald Welte 808998c3f8 bcch_scan: Fix compiler warning about undefined functions
Change-Id: I435ef2032b9cefe844c37f395d9087be6af8934a
2019-05-22 21:39:38 +02:00
Vadim Yanitskiy ab7118a2aa trx_toolkit/clck_gen.py: avoid logging \0-terminator
Change-Id: I93da2e8ba9d3fda944b8171bc42e49063c925f9c
2019-05-17 19:40:31 +07:00
Vadim Yanitskiy 507781ee70 common/sim.c: add missing break to sim_apdu_resp()
Change-Id: Id5c325ffcfea8175bc5d5499a0904c0984e00349
Fixes: OS#198542
2019-05-14 20:52:39 +07:00
Vadim Yanitskiy 12a8318153 firmware/Makefile: clarify toolchain configuration include
Change-Id: I77ce68d5904ff623f10f6475309052666bab7742
2019-05-13 02:31:54 +07:00
Harald Welte 01e374d27c firmware/Makefile.inc: fix sections with overlapping VMA
Starting from [1], not only LMA but also VMA areas are now checked
for overlaps (see also [2]). This results into linking errors:

  arm-none-eabi-ld: section .text.exceptions VMA
    [000000000080001c,0000000000800037] overlaps section
    .compal.reservedram VMA [0000000000800000,00000000008000fe]
  arm-none-eabi-ld: section .text.exceptions VMA
    [000000000080001c,0000000000800037] overlaps section
    .compal.loader VMA [0000000000800000,00000000008000ff]

Let's try to work around this.

[1] https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a87dd97a2098b7e18ff2574a4e81ae521ef7e6f2
[2] https://sourceware.org/bugzilla/show_bug.cgi?id=18452

Change-Id: I098ddd33aabd7ec27981e2f09d8582f167bb649b
Fixes: OS#1917
2019-05-13 02:28:36 +07:00
Vadim Yanitskiy 0f5f76f651 trxcon/trx_if.c: use ssize_t for return value of read()
Change-Id: I4a489be6fafcd057c3edc4f3d5f76d645899f884
2019-05-09 23:53:12 +00:00
Vadim Yanitskiy 4c2d32afe6 trxcon/trx_if.c: print error message if read() call fails
Change-Id: If3aaa730c306e703d1d430a8920284aa592c999c
2019-05-09 23:53:12 +00:00
Vadim Yanitskiy 2d05901cd4 trxcon/trx_if.c: use read() call instead of recv()
According to the man page of recv(), the only difference of this
call from read() is the presence of flags. With a zero flags
argument, recv() is generally equivalent to read().

Change-Id: I6d43bbf8d52c5fbb8ee0592b7d1c1dfd2dd1548e
2019-05-09 23:53:12 +00:00
Vadim Yanitskiy 1f07f3e34a trxcon/l1ctl.c: init DL info header in l1ctl_tx_rach_conf()
Since we only set both ARFCN and TDMA frame number of the DL info
header, other fields remain uninitialized. Let's memset() them.

Change-Id: Ib39c333f1724fefa5d8bd8a2315b77a5612f7fa9
2019-05-09 22:08:42 +07:00
Vadim Yanitskiy 2d94a4b71c trxcon/l1ctl.c: pass band_arfcn to l1ctl_tx_rach_conf()
This would allow to abstract both L1CTL and TRX interfaces
from each other in the upcoming refactoring.

Change-Id: I74a23c73b03bad822272b9cfe76c2501666912b7
2019-05-09 22:01:28 +07:00