Commit Graph

334 Commits

Author SHA1 Message Date
Vadim Yanitskiy bac9387bba trxcon: allocate a prim in l1sched_prim_push()
Make l1sched_prim_alloc() private and call it from l1sched_prim_push().
This makes the API more convinient, because both functions are always
used together.

Change-Id: Ia9c0170fb06efcef569e987b57ab9ab7f7c7e847
Related: OS#5599, OS#3761
2022-07-12 03:03:17 +07:00
Vadim Yanitskiy b1125910c1 trxcon: fix uint8_t used for length in l1sched_prim_alloc()
Using uint8_t makes it impossible to allocate primitives with payload
of size 255 - sizeof(struct l1sched_ts_prim) and greater.

Change-Id: Ic19b8433118798f57500119f1caf10e117e5db19
Related: OS#5599, OS#3761
2022-07-12 03:03:17 +07:00
Vadim Yanitskiy 8abb8026c2 trxcon: return prim pointer from l1sched_prim_alloc()
Returning prim pointer is more convinient from the API point of view.

Change-Id: I0fa41cf55e90d191d032bca1754941cca763b03e
Related: OS#5599, OS#3761
2022-07-12 03:02:31 +07:00
Vadim Yanitskiy 98b5895200 trxcon: rename l1sched_prim_init() to l1sched_prim_alloc()
The current function name is confusing, because l1sched_prim_init()
is not only initializing a primitive, but also allocating it on heap.
Let's use '_alloc' instead of '_init' to reflect that.

Change-Id: Ie1bebb6829ba9f640455685fcd7309b6aa442ef0
Related: OS#5599, OS#3761
2022-07-12 02:55:22 +07:00
Vadim Yanitskiy a699cc6846 trxcon: remove unused include of 'logging.h' from 'l1sched.h'
Change-Id: I52e1b93e3f1f5e52beeb17ff27c2a83e24d25a96
Related: OS#5599, OS#3761
2022-07-11 05:12:16 +07:00
Vadim Yanitskiy eff2d52e75 trxcon: merge 'sched_trx.h' and 'scheduler.h' into 'l1sched.h'
Change-Id: Ide1e3ccdf32fdc255acc943e0c0936d15cf0c680
Related: OS#5599, OS#3761
2022-07-11 05:12:16 +07:00
Vadim Yanitskiy 38373ee20f trxcon: use 'l1sched_' prefix for scheduler API
Change-Id: I370aa5084a4e3eb94168b96df94dbbee606adaab
Related: OS#5599, OS#3761
2022-07-11 05:12:16 +07:00
Vadim Yanitskiy f73db50f6b trxcon: rename 'enum trx_lchan_type' and its items
Change-Id: I76a7d9fed3d6ab47725fceb803aa16ddbfd2e1a2
Related: OS#5599, OS#3761
2022-07-09 23:56:18 +07:00
Vadim Yanitskiy 19ad5c9256 trxcon: remove '\brief' marker from the comments
This marker is not required to be present in Doxygen comments.

Change-Id: If793037e2b2bc9b708617867a4d4ddb0fa2f1ddb
2022-07-04 17:41:09 +07:00
Vadim Yanitskiy 259314abae trxcon: group *.c files into 'src' directory
Change-Id: I1a3703e48507cd51cd8198f13b993f54c44bc41e
Related: OS#5599, OS#3761
2022-07-04 17:41:09 +07:00
Vadim Yanitskiy b7335dfe79 trxcon: group header files into 'include/osmocom/bb/trxcon'
This is the first step towards the goal of moving the scheduler
into a separate library.

Change-Id: Ifa6137c239c215a3d323213ee74d34b419622be4
Related: OS#5599, OS#3761
2022-07-02 19:02:49 +07:00
Vadim Yanitskiy 57ce62f4bc trxcon: Makefile.am: fix make {dist,distcheck} targets
File '.version' must be also listed in EXTRA_DIST, otherwise I get:

  echo 0.0.0 > ../../.version-t && mv ../../.version-t ../../.version
  /bin/sh: line 1: ../../.version-t: Permission denied

Change-Id: I65f7c505f5a231bab114c45f5fdd7421601dfbc0
Related: OS#5599, OS#3761
2022-07-01 19:34:21 +07:00
Vadim Yanitskiy d75cc116e2 trxcon: Makefile.am: move versioning magic to the bottom
This is a more usual place for manually added targets.

Change-Id: I69892f8689fd7062ca26b6f1337c972b11b1906e
Related: OS#5599, OS#3761
2022-07-01 19:19:23 +07:00
Vadim Yanitskiy 2ac370830f trxcon: clarify L1CTL_DM_REL_REQ related logging
In reality, trxcon does not switch back to BCCH itself.  Neither
the firmware does, so let's correct this confusing log message.

Change-Id: Iad308ad980af4caa7d7d1b358ba7288885f96e04
2022-05-13 23:16:42 +03:00
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 2308b58250 trxcon/scheduler: unify and enrich decoding error messages
Regarding the removal of burst_mask2str() from the TCH/H handler,
it does not make sense to print it because the mask is already
shifted and an earlier logging should already contain this info.

Change-Id: I42d20e2da73c21ca366dd246244cd716c8ccb459
Related: OS#4823
2021-07-04 20:02:53 +02:00
Vadim Yanitskiy f8bc28505f trxcon/trx_if: send NOPE indications if there is no burst
In a typical setup operating on the real radio interface, it's
the duty of the transceiver (e.g. osmo-trx) to send NOPE.ind to
the L1 implementation (e.g. osmo-bts-trx).  However, in a
virtual environment for ttcn3-bts-test we use a fake transceiver,
which due to its simplicity cannot send NOPE indications itself.

The lack of queues and buffering does not allow us to implement
NOPE indications in fake_trx.py, so the easiest approach is to
generate them from trxcon.  Send TRXD PDUs without the burst bits,
and fake_trx.py will tranform them info NOPE.ind for us.

Change-Id: I1c7f1315b8ef44f651efd6a22fb5b854f65c0946
Related: SYS#5313, OS#1569
2021-06-16 15:55:38 +02:00
Vadim Yanitskiy 529d54b13a trxcon/scheduler: introduce and use struct sched_burst_req
Similar to what we do in osmo-bts-trx, group everything related to
an Uplink burst into a structure.  Pass a pointer to this structure
to the logical channel handlers.  This makes the code easier to read,
and facilitates sending NOPE indications to the transceiver
(will be introduced in the upcoming patch).

Get rid of sched_trx_handle_tx_burst(), and instead just call
sched_trx_a5_burst_enc() directly from sched_frame_clck_cb().

Change-Id: Id45b27180c233fdc42ae1ef0b195554dd299a056
Related: SYS#5313, OS#1569
2021-06-16 15:55:32 +02:00
Vadim Yanitskiy c652349b4a trxcon/scheduler: cosmetic: move TDMA frame number calculation
Change-Id: I79efdfa543d37889dc6749eb25aab4e1639749c6
2021-06-16 15:05:51 +02:00
Vadim Yanitskiy e9b0d7488f trxcon: fix legacy length expectations for TRXDv0 Rx PDUs
158 is basically: 8 + 148 + 2, where the last two are padding bytes
sent by legacy TRXDv0 transceivers.  We don't need them, so do not
drop PDUs without these leggacy padding bytes.

Change-Id: I6c0734bc4669ccde2a93940c9cf50fdbbd67cb00
2021-04-29 14:33:25 +02:00
Vadim Yanitskiy a7298e316f trxcon/scheduler: invalidate hard-coded Measurement results
This is what trxcon sends to the network before the first SACCH
block is received from the higher layers.  The indicated values
are of course invalid because they're hard-coded.

According to 3GPP TS 44.018, table 10.5.2.20.1:

  0  The measurement results are valid
  1  The measurement results are not valid

Change-Id: I7da767e146aec7cef1de71e4d735d6a02b6c5642
Related: SYS#4918
2020-11-30 16:06:48 +01:00
Vadim Yanitskiy 1ae959fe25 trxcon/scheduler: clarify the content of Measurement results
Change-Id: I26546dcbc853166e351d00260936b1b9d584ae03
2020-11-30 16:00:13 +01:00
Vadim Yanitskiy a7b6dea829 trxcon/scheduler: clarify Measurement results padding
Table 10.5.2.20.0 "Measurement Results Contents" in 3GPP TS 44.018
is clear on what should be used as padding - '0**', i.e. zeroes.

Change-Id: I4db6845c98aded10291134f416da98fd0f4f58e3
2020-11-30 14:33:07 +01:00
Pau Espin efb88bf5ff trxcon: generate coredump and exit upon SIGABRT received
Previous code relied on abort() switching sigaction to SIG_FDL +
retriggering SIGABRT in case the signal handler returns, which would
then generate the coredump + terminate the process.
However, if a SIGABRT is received from somewhere else (kill -SIGABRT),
then the process would print the talloc report and continue running,
which is not desired.

Change-Id: I6d80f3f2742d397e47f4f2970c951f2cf6d58172
Fixes: OS#4865
2020-11-25 18:44:46 +01:00
Pau Espin 581cfbeba9 trxcon: Handle signal SIGABRT
The signal handler was coded as if it was handling SIGABRT, but the
signal handler was not overwritten so it is actually used.

Change-Id: I5c597f3410fc97be138db6f3976df59f393819b6
2020-11-25 18:42:09 +01:00
Vadim Yanitskiy 082b618ea4 trxcon/l1ctl_link: use osmo_store16be() in l1ctl_link_send()
Change-Id: I96ca1c581d028a1f3c89c83a575fd8dbc9751962
2020-11-05 13:36:43 +07:00
Vadim Yanitskiy 2c0d9cdcc2 trxcon/l1ctl: fix: send confirmation for TCH mode request
Both REQ and CNF share the same message structure, so we can
cheat a bit by changing the message type and sending it back.

Change-Id: I6f403ed0506b4b1872361d9976d3186bfe514b52
Related: OS#4799
2020-10-19 21:07:26 +07:00
Harald Welte de31aa3af7 Use osmo_fd_setup() whenever applicable.
Change-Id: If9b636c295fc6b5349a54c70662f09efa616ee63
2020-10-18 23:34:46 +02:00
Harald Welte 508d8523c0 Use OSMO_FD_* instead of deprecated BSC_FD_*
Change-Id: Ibf64b18288b9109927035f650d6ef7ad9f15d688
2020-10-18 22:43:05 +02:00
Vadim Yanitskiy 39264cc3a8 fix trx_if_tx_burst(): do not drop Uplink bursts in TRX_STATE_RSP_WAIT
Some commands, such as SETTA or SETPOWER, are expected to be sent
when the transceiver is powered on.  We should not drop Uplink
bursts while waiting TRXC response.

For now it's easier to comment out the state check completely,
because the existing TRXC state machine is quite messy.

Change-Id: Iefe6030200b11b29a5790d1f4aa4070ed1d9a493
2020-10-16 23:08:38 +07: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 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 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 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 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 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
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
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
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
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
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 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
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 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
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
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
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
Vadim Yanitskiy 4dd92e2520 trxcon: introduce extended (11-bit) RACH support
According to 3GPP TS 05.03, section 5.3, two coding schemes are
specified for access bursts: one for regular 8-bit bursts,
another - for extended 11-bit packet access bursts.

According to 3GPP TS 05.02, section 5.2.7, there are two
additional training (synchronization) sequences for RACH
bursts: TS1 & TS2. By default, TS0 synch. sequence is used,
unless explicitly stated otherwise (see 3GPP TS 04.60).

According to 3GPP TS 04.60, section 11.2.5a, the EGPRS capability
can be indicated by the MS using an alternative training sequence
(i.e. TS1 or TS2) and the 11-bit RACH coding scheme.

Change-Id: I36fd20cd5502ce33c52f644ee4c22abb83350df8
2019-04-22 09:17:23 +00:00
Max e9bedd12f7 trxcon: use static helper to prepare FBSB
Use static helper to prepare l1ctl_fbsb_conf - this simplifies
fbsb-related functions and make difference between timer callback and
regular response more obvious.

Change-Id: I43832d6a912a32ea5795ed0110981e0b714a7a61
2019-03-21 16:58:56 +01:00
Max 25e17a9c7f trxcon: log FBSB timer events
Change-Id: I0168d43951494f4010df891f391ddad4b57493d7
2019-03-21 16:58:56 +01:00
Max 7f024a30a4 trxcon: use helper to add l1ctl_info_dl
Use static helpers to add l1ctl_info_dl to msgb - this simplifies
l1ctl_* routines and reduce code duplication.

Change-Id: I0b5b81f1fcd2984136e553a93735ea5456d2b3df
2019-03-21 15:46:29 +01:00
Max c53cb3ec83 trxcon: use bool for fbsb_conf_sent
It's only used as a boolean value so let's set proper type for it.

Change-Id: Iaf50cdd19ac2139ee2d625671410a486edae2999
2019-03-21 13:16:39 +01:00
Vadim Yanitskiy 803e420a4f trxcon/scheduler: clarify decoding of incomplete xCCH blocks
Inspired by Sylvain's message at #osmocom.
Change-Id: I3f499837413e1dbd0ca62229dc9cb6f0f7475a42
2019-03-10 15:32:29 +07:00
Vadim Yanitskiy 4bc4655bd6 trxcon/scheduler: count number of measurements
Instead of counting both RSSI and ToA measurements separately,
let's have a single counter in trx_lchan_state.meas struct.

Change-Id: I45454a3ac92b8cc85dd74092e4ab6eb350f20c9a
2019-02-21 17:20:36 +07:00
Vadim Yanitskiy 851039cb9b trxcon/l1ctl.c: fix memleak triggered by unsupported messages
Change-Id: I6e636afec8e45d7dc786f5f159cd5d7784d9a83b
2019-01-17 13:01:24 +00:00
Vadim Yanitskiy 65d74d9864 trxcon/trxcon.c: do not expose tall_trx_ctx
Both l1ctl_link_init() and trx_if_open() do accept 'tall_ctx' now,
so there is no need to expose the root context anymore. For
logging initialization, we can just pass a pointer.

Change-Id: I7a2231eb880a995d3296b94481a7799e6ff07489
2019-01-17 19:38:14 +07:00
Vadim Yanitskiy 030a6154a6 trxcon/l1ctl_link.c: refactor l1ctl_link_init()
The main changes are:

  - return pointer to the allocated l1ctl_link or NULL,
  - accept the talloc context as 'tall_ctx' argument.

Change-Id: I7fe1bc306494ac692c182dcfd2a2d9412929194b
2019-01-17 11:12:00 +07:00
Vadim Yanitskiy 382736448e trxcon/trx_if: refactor trx_if_open()
The main changes are:

  - return pointer to the allocated trx_instance or NULL,
  - extend debug message with TRX address and base port,
  - accept the talloc context as 'tall_ctx' argument,
  - rename goto label 'error' to 'udp_error',
  - rename argument 'port' to 'base_port'.

Change-Id: I39b24afee2f09d6a6c500cfc26ac45f206589c5c
2019-01-17 11:03:48 +07:00
Vadim Yanitskiy 1b6be6fc24 trxcon: do not include trxcon.h everywhere
Change-Id: Ia78bd6dac7ab12970838e0b1a2929a106b898d9d
2019-01-17 10:55:41 +07:00
Vadim Yanitskiy 192a8595d0 trxcon/trx_if.c: check if trx_fsm allocation failed
Change-Id: I31c9f2a651182b258d0a4d4504365b778529715a
2019-01-17 10:53:10 +07:00
Vadim Yanitskiy f6bc4c1ef8 trxcon/l1ctl_link.c: check if l1ctl_fsm allocation failed
Change-Id: Ibd9404a888f02798224238a7b9ff4ebf09f03850
2019-01-17 10:50:17 +07:00