Commit Graph

39 Commits

Author SHA1 Message Date
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 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
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 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 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 192a8595d0 trxcon/trx_if.c: check if trx_fsm allocation failed
Change-Id: I31c9f2a651182b258d0a4d4504365b778529715a
2019-01-17 10:53:10 +07:00
Vadim Yanitskiy ebbd601324 trxcon: register both l1ctl_fsm and trx_fsm on DSO load
Change-Id: I7111e368afa47c88ff3c610bae9044f2d5baf037
2019-01-17 10:45:56 +07:00
Vadim Yanitskiy db9198d236 trxcon/trx_if.c: add SETFH CTRL command support
The idea of SETFH command is to instruct transceiver to enable
frequency hopping mode using the following parameters:

  CMD SETFH <HSN> <MAIO> <CH1> <CH2> [... <CHN>]

Note: since the length of a CTRL command is limited to 128
symbols (BTW: why?), the amount of channels is also limited.

Change-Id: Id3d44e6a2796f1ce8523a49dedd5d484052a5c7f
2018-11-29 16:11:27 +00:00
Vadim Yanitskiy 3d62aa724e trxcon/l1ctl.c: refactor Timing Advance handling
Change-Id: I0e4f18173347e3a7cb875f95d796e8ea20bfc4bf
2018-09-07 12:18:24 +00:00
Vadim Yanitskiy 216a4888cd trxcon/trx_if.c: drop Timing Advance range limitation
Despite the correct range of Timing Advance value is [0..63],
there is a special feature in OsmocomBB which allows one to
simulate the distance between both MS and a BTS by playing
with the signal delay.

This is why a signed 'int8_t' type is used in L1CTL protocol.
No need to limit the range, just forward it to TRX.

Change-Id: I06774b315b8451bf14083da6b2849d6e8594abc8
2018-09-07 09:02:19 +00:00
Vadim Yanitskiy 5c94d87c62 trxcon/trx_if.c: drop unused SETPOWER and ADJPOWER
I am not sure we need the both control commands, as every burst
on DATA interface has a header that includes TX power.

Change-Id: Id14603e71df6dedb5a843bb3e20a320192dbca3d
2018-09-07 03:38:38 +07:00
Vadim Yanitskiy b103c0e4a3 trxcon/trx_if.c: use proper format specifiers
The '%u' format specifier should be used for unsigned values.

Change-Id: I90200581036f8ab3969dd68664688f98cd2d3618
2018-09-06 01:56:11 +07:00
Vadim Yanitskiy 93728f6ec8 trxcon: avoid arfcn / band_arfcn naming confusion
In the most cases an ARFCN value is stored together with some
flags (e.g. DL/UL flag, DCS flag), so it should be taken into
account e.g. when printing. Let's use the proper naming.

Change-Id: I0b7634c80986dbff9d0da421c6a044cd36c9fd01
2018-09-06 01:47:50 +07:00
Vadim Yanitskiy c066787fd5 host/trxcon: use integer math for ToA (Timing of Arrival)
There's no need to express ToA value as a float. Let's turn it into
an int16_t with 1/256 symbol period accuracy throughout the code to
avoid both float arithmetic as well as loosing any precision.

Inspired by Idce4178e0b1f7e940ebc22b3e2f340fcd544d4ec.

Change-Id: I99c0f38db08a530d5846c474aba352aa0b68fe86
2018-03-02 21:24:57 +07:00
Harald Welte 0d3030c764 trxcon: Fix '-i' to specify the "TRX IP address"
The command line help states '-i' is for 'TRX IP address', which is
the remote IP address at which the TRX is to be found.  Hoewever, it
was used as the local (bind) IP address of the socket used towards
the TRX.  This is my attempt at fixing this.  A more complete solution
probably allows to specify both local (bind) and remote (connect)
address, just to be clear.

Change-Id: If0252b15e9c7942687c6dc470951d777f7af651c
2018-03-01 14:42:25 +01:00
Harald Welte b1b1162019 trxcon: Define event names for osmo_fsm's
Change-Id: Id3279e99966a0ab236923c497ac0abbc9ed2c93c
2018-02-28 23:18:09 +01:00
Vadim Yanitskiy 8ed6f42772 host/trxcon: forward Timing Advance value to transceiver
The time at which the phone is allowed to transmit a burst of
traffic within a timeslot must be adjusted accordingly to prevent
collisions with adjacent users. Timing Advance (TA) is the
variable controlling this adjustment. The TA value is normally
between 0 and 63, with each step representing an advance of
one bit period (approximately 3.69 microseconds).

As trxcon doesn't perform actual burst transmission, this value
needs to be forwarded to the transceiver, which will take care
about the timings.

Change-Id: Ia8c0848827ab2b4cd7cf1efe128b28d5c06ec84e
2017-12-05 01:16:44 +07:00
Vadim Yanitskiy 0d9680e88a host/trxcon/trx_if.c: get rid of useless commands
The 'SETMAXDLY' command is used on the BTS side to limit maximal
Time of Arrival for access bursts. As we don't receive RACH
bursts on the MS side, the command is useless.

The 'SETRXGAIN' command is used on the BTS side to set initial
receive gain value for TRX. On the MS side it's possible to set
that parameter via command-line options of TRX.

Change-Id: I3e61b4b48193004cdcb241cefabb44c12db93120
2017-12-04 23:59:55 +07:00
Vadim Yanitskiy c5d9507b5d host/trxcon/trx_ic.c: use osmo_ubit2sbit() from libosmocore
No need to reimplement the existing functions...

Change-Id: Ic9b232c8561609d42dac10e6249a3e1c58c4edc1
2017-12-04 23:59:49 +07:00
Vadim Yanitskiy e8cf6c4eef host/trxcon: fix: use valid names for FSM instances
Since 8c4f5457 in libosmocore there are some limitations on FSM
and FSM instance names. This change adjusts the names of both
l1ctl_fsm and trx_fsm instances.

Change-Id: Icaaac3f51bdcfe4f7723060179b8730c3a06529b
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 5e9959cf6a host/trxcon/trx_if.c: separate logging of data messages
Change-Id: I74ebe0441aeb41c324eafb6b586b2edd9ef4fd1a
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 3641fe6123 host/trxcon: use LOGP instead of fprintf
There is no (performance) reason to use fprintf instead of LOGP.
Second one provides more useful information, such as a file name
and a line number.

Change-Id: I86dda5b3d746c7802442e4226578a06c04941721
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy f979d44a72 host/trxcon/trx_if.c: fix wrong logging category
Change-Id: I0df0205e160fd9ea5811852077db7c49cddc7e8a
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy e6acd7bd07 host/trxcon: get rid of useless TRX_EVENT_RESET_IND
Change-Id: I2aa4c000b37f64c351a806711b2d19bf27ef82bd
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 17481e2b88 host/trxcon/trx_if.c: get rid of CLCK interface
Local clock counter can be corrected using frame number values,
obtained from burst header on DATA interface.

Change-Id: I5a813e3dc1b960831343b8ecb80718291f20e80d
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy f604869944 host/trxcon: share trxcon fsm and talloc ctx via trxcon.h
Change-Id: I9ef558f84a6dc1c9b8fc394c48e108676fa169f8
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 794deea3ec host/trxcon/trx_if.c: add power measurement command
Change-Id: Ib947b60248cafad4edeb7e49c2bd3a1f81696239
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy ca5eee6e3f host/trxcon/trx_if.c: simplify response matching
Previously, we had both length and string matching of request and
response. To be able to implement commands with additional params
in the future, this change drops the length matching part.

Change-Id: Id4c50115f5f1b1da450ff8b8dcfd6ccf572d23f5
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy f437a3bebd host/trxcon/trx_if.c: use proper names for burst handlers
Change-Id: I3d36e6d80fcf6353379aa308415c306e1a256a7d
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 0f227d802b host/trxcon/trx_if.c: fix compatibility with OsmoTRX
For some reasons, OsmoTRX sends 158-byte long sequences on DATA
interface, where the latest two bytes aren't used.

Change-Id: Ie9295e9b0d8956d9e87e2ced8cca9d5e68040f88
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy ec3a1ba2e5 host/trxcon/scheduler: handle bursts from TRX interface
Change-Id: Iff15daf897f30cb98d4ec4c88b9fc259cb44ea4e
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 789040f914 host/trxcon/trx_if.c: handle clock indications
Change-Id: I333c1c44578eb62c52d2d059b798dd5feae3e444
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 423aeefc40 host/trxcon: integrate osmo-fsm framework
This change introduces the following state machines:

  - trxcon_app_fsm - main application state machine.

    This state machine handles different events, raised
    from program modules (such as trx_if.c or l1ctl.c).

  - l1ctl_link_fsm - L1CTL server state machine.

  - trx_interface_fsm - TRX interface state machine.

The program modules (such as trx_if.c or l1ctl.c) should be as
much independent from each other as possible. In other words,
one module should not call methods from another, e.g. L1CTL
handlers are not able to send any command to transceiver directly.

Instead of that, they should use shared event set to notify the
main state machine about something. Depending on current state
and received event, main state machine 'decides' what to do. This
approach would allow to easily reuse the source code almost 'as is'
anywhere outside the project.

Change-Id: I7ee6fc891abe5f775f5b7ebbf093181a97950dea
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 83a9c9ef50 host/trxcon/trx_if.c: add ECHO command
This command should be used to check transceiver availability.

Change-Id: I6af2d5e413ff7ab751cb34e1659742b0f59b6cca
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 65664d088d host/trxcon: fix NULL-pointer deference
Change-Id: Idc036d4ea32b4aa3f4841d39144ef1733414728e
2017-11-19 17:35:07 +07:00
Vadim Yanitskiy 48f2cb4b3b host/trxcon: initial release of transceiver interface
This is the second side of the 'OsmocomBB <-> SDR' bridge.
Most of source code taken from the OsmoBTS project.

Change-Id: I96fa3ada05d010f31af419a4950fd8ae2b62ef34
2017-11-19 17:35:07 +07:00