Commit Graph

167 Commits

Author SHA1 Message Date
Vadim Yanitskiy 7d06c78b37 trxcon/scheduler: add TCH/H channel support
Change-Id: Ibb2a0850692c5ff86b13b820af10b12085589e67
2018-09-16 02:12:11 +07:00
Vadim Yanitskiy 1bffe899d9 trxcon/scheduler: introduce TCH/H TDMA frame mapping helpres
Unlike xCCH, TCH/H channels are using block diagonal interleaving,
so every single burst carries 57 bits of one traffic frame, and 57
bits of another one. Moreover, unlike TCH/F where both traffic
and FACCH/F frames are interleaved over 8 bursts, a FACCH/H is
interleaved over 6 bursts, while a traffic frame is interleaved
over 4 bursts.

This is why a TCH/H burst transmission can't be initiated on
an arbitrary TDMA frame number. It shall be aligned as of
stated in GSM 05.02, clause 7, table 1.

This change introduces two basic functions:

  - sched_tchh_block_map_fn - checks if a TCH/H block transmission
    can be initiated / finished on a given frame number
    and a given channel type;

  - sched_tchh_block_dl_first_fn - calculates TDMA frame number of
    the first burst using given frame number of the last burst;

and some auxiliary wrappers to simplify the usage of
sched_tchh_block_map_fn().

Change-Id: Iaf4cb33f1b79df23f8a90c8b14ebe0cd9907fbb9
2018-09-16 02:12:09 +07:00
Vadim Yanitskiy 96419494d3 trxcon/scheduler: introduce TDMA frame math helpers
The 'normal' math operations, such as addition and substraction,
are not applicable for TDMA frame numbers because they may result
in out-of-range values.

Having TDMA frame math helpers in a single place would allow
one to avoid possible out-of-range result mistakes.

Change-Id: Ibb66ba846cc3d6c2eaa88414569e5f3751128047
2018-09-16 01:51:15 +07:00
Vadim Yanitskiy 60da22a67b trxcon/scheduler: fix: don't send BFI in GSM48_CMODE_SIGN mode
GSM48_CMODE_SIGN means 'signaling only', so we shall not send
bad frame indications in this state. Instead, it makes sense
to send dummy L2 frames like we do for xCCH channels.

Change-Id: Ie39d53522cafab265099076b3194fa96aff217ba
2018-09-15 07:51:52 +00:00
Vadim Yanitskiy 909c86df29 trxcon/scheduler.h: share FRAME_DURATION_uS definition
Change-Id: I88be6088141af6bac8d34844b71193bfef51ad31
2018-09-14 18:12:20 +07: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
Harald Welte b570cd532a trxcon: distinguish between unimplemented and unknown messages
Let's differentiate between 'expected' unimplemented messages
like L1CTL_NEIGH_PM_REQ and truly unknonw message types.

Change-Id: Id76993056fb514e6fb0242d505205316c61bb965
2018-09-07 03:37:17 +07:00
Vadim Yanitskiy 4736561b22 trxcon/l1ctl.c: fix: handle ARFCN from L1CTL_DM_EST_REQ
A BSC may allocate a dedicated channel on any ARFCN, not necessary
on the same one where a mobile station has requested this channel.

For some reason, the ARFCN info of L1CTL_DM_EST_REQ message was
not handled by trxcon. Let's fix this.

Related: OS#3526
Change-Id: I16ed5c64236c159bfa39002b05094c1f6c171f6b
2018-09-06 20:33:23 +00: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 236dfd506d trxcon/l1ctl.c: print timeslot number from L1CTL_DM_EST_REQ
Change-Id: If092743c32b7a6f5da7c8339b0f7b92ccf8a7a8b
2018-09-06 01:15:26 +07:00
Vadim Yanitskiy 535a093726 trxcon/l1ctl.c: drop meaningless 'tn > 7' checks
There is no need to check the range of timeslot number, which is
decoded from GSM 08.58 channel number (9.3.1) by applying 0x07
mask, because any result of this operation is always within
the correct range.

Change-Id: Ib84417099d303bd3ae3557f48a5c40b812c6cdfc
2018-09-06 01:07:36 +07:00
Stefan Sperling 316f22f057 trxcon/sched_clck.c: fix time delta calculations
Use osmo_clock_gettime() to read the monotonic clock instead
of gettimeofday() which could drift backwards.
This requires switching the scheduler clock from struct timeval
to struct timespec. Expand some variables to 64 bits in order
to keep types used in calculations compatible.

The previous implementation unconditionally subtracted microsecond
values from different time measurements, causing overflow if the
current measurement was taken in less of a fraction of a second
than the past measurement. Use timespecsub() for the subtraction
instead which accounts for fractions of a second correctly.

Change-Id: Ic93f90685c6d6dc28dfc4ad48c998e0eac113cf8
Related: OS#3467
2018-08-17 17:22:59 +00:00
Vadim Yanitskiy 347406cee7 trxcon/scheduler: get rid of useless lchan->rsl_mode
This field of the logical channel state structure was not used at
all as there is nothing related to A-bis / RSL in trxcon itself.

Change-Id: Iec1abf777a74cf57deadafa95e2337cba5d02842
2018-08-15 09:32:08 +07:00
Vadim Yanitskiy 7c4151ae52 trxcon/scheduler: fix: properly generate BFI for TCH/H
When relying on GSM 04.08 channel mode (GSM48_CMODE_*), one should
distinguish between Bm (full rate) and Lm (half rate) channels.

This change prevents the scheduler from generating TCH/F BFI
instead of TCH/H BFI on the corresponding channels.

Change-Id: I4547aa7f6d38637692fef8a0122e85fb52039a46
2018-08-15 08:22:14 +07:00
Vadim Yanitskiy 3cbbe81b63 trxcon/scheduler: pass lchan to sched_bad_frame_ind()
Instead of passing the information about a logical channel, it
makes sense to pass the pointer to its state where everything
is stored. This approach would allow to avoid adding more
arguments every time, e.g. in case of AMR.

Change-Id: I91fe86fef43aac68776a58c9acc37ef2a9ee8042
2018-08-15 08:20:41 +07:00
Vadim Yanitskiy 0f2b894580 trxcon/sched_prim.c: properly handle both TCH/H and FACCH/H prims
Initially it was assumed that FACCH prioritization should be done
in the same way for both TCH/F and TCH/H. Moreover, it was not
possible to confirm this, because TCH/H was (and still) not
implemented yet. But according to the specs:

  - unlike FACCH/F, FACCH/H transmissions shall be aligned
    within a multiframe, i.e. can only be initiated on
    particular frame numbers (see GSM 05.02, clause 7);

  - unlike FACCH/F, a FACCH/H frame steals two TCH/F frames;

so the TCH/H (including FACCH/H) primitives should be handled
separately from the TCH/F (including FACCH/F) primitives.

Change-Id: I9b59f60e1cbac8fb8fd557b6c67b5e376c0a6bbb
2018-08-14 06:22:04 +07:00
Vadim Yanitskiy 799f26c075 trxcon/sched_prim.c: refactor prim dequeuing logic
The previous primitive dequeuing logic (especially for TCH/F
channels) was a bit complicated, and it could not be possible
to reuse the existing code parts in the upcoming implementation
of both TCH/H and FACCH/H channels without changing anything.

In particular, this change introduces two internal functions:

  - prim_dequeue_one(), which merely dequeues a primitive
    of a given channel type (e.g. TRXC_SDCCH4_0);

  - prim_dequeue_tch(), which dequeues either a FACCH,
    or a speech TCH primitive of a given channel
    type (Lm or Bm).

So the logic of the TCH/F prim dequeuing function has become
cleaner, and the upcoming TCH/H prim dequeuing function, where
FACCH/H prioritization is more complex than FACCH/F, will
reuse the introduced functions.

Change-Id: Ib82ad2480ab1bc6b1df9576eb2bf5acbd398bf66
2018-08-14 05:46:59 +07:00
Vadim Yanitskiy 8ae0c13fa9 trxcon/sched_trx.h: add missing parentheses to PRIM_IS_*
Change-Id: Ifa7d9f806b3f18f2dfec931252f5119441b30e8a
2018-08-14 05:00:00 +07:00
Vadim Yanitskiy 488f92d8b8 trxcon: make both Valgrind and trxcon happy
Change-Id: If5c349082757bb30408477b1ef528934eded0232
2018-07-28 02:22:29 +07:00
Vadim Yanitskiy 8f6909a94f trxcon/scheduler: fix: check primitive len before encoding
We used to trust (and still doing this) the messages coming from
L1CTL interface too much, and not to check the primitive length
before passing the payload to the libosmocoding API. As was
discovered and described in OS#3415, sending a L1CTL message
(either DATA_REQ, or TRAFFIC_REQ) with an incorrect length
(lower than expected) may cause heap overflow.

Let's explicitly check a primitive before encoding, and drop it
if its length doesn't match the expected value(s).

Change-Id: I258ee9f6d0124b183b1db23a73f1e523fcea89a8
Fixes: OS#3415
2018-07-24 22:24:13 +07:00
Piotr Krysik 70a50a33cc trxcon: fix tail bits at the front of Access burst
Currently Access Burst generated by trxcon
has 8 zero bits at the beginning. According to
the 3GPP 05.02 specification (Chapter 5.2.7
Access burst) custom 8-bit extended tail bits
sequence should be used:
(BN0, BN1, BN2 ... BN7) = (0,0,1,1,1,0,1,0)

After this fix trxcon sets correct 8-bit
sequence at the front of Access burst.

Change-Id: I1f624e783de6c585d2e292965c9e5810b0a4f27d
2018-07-16 09:11:26 +02:00
Harald Welte 9abc5f7982 trxcon: Prefix SACCH fill frame with L1 header
The main problem here is that the existing implementatin missing the L1
header in this message.  A SACCH message doesn't have a 23byte LAPDm
message, but only a 21 byte LAPDm message prefixed by a 2-byte Layer1
header. So on the receiver in the BTS, right now the first two bytes of
the UL SACCH frame are misinterpreted as L1 header.

This it what causes RLL ERROR INDICATION on the Abis side, which is why
our BTS_Tests fail.

Change-Id: Id7776bf3604d0e8a32e04547e01b8bd377903272
Related: OS#3170
2018-04-15 11:09:25 +02:00
Vadim Yanitskiy 9803a35a8a host/trxcon: track talloc NULL contexts by default
In order to be able to introspect not only the root application
context, but also all other contexts, e.g. allocated within
libosmocore or other libraries, let's enable tracking the
use of NULL contexts using the corresponding talloc API.

Change-Id: Id21cd5ee340def443f7a5d0b2b8f37f41188dd87
2018-04-09 08:26:23 +00:00
Vadim Yanitskiy 60bf444718 host/trxcon: don't free root talloc context
This is useless, and prevents us from finding potential memory
leaks at exit. Let's print talloc report instead of that.

Change-Id: Ibf04942070d654e97c3ed77d69ab19e44602758c
2018-04-09 08:26:22 +00:00
Vadim Yanitskiy fa0d7c0c4f host/trxcon: use osmo_init_logging2()
The osmo_init_logging() doesn't allow to specify a talloc context
for libosmocore logging subsystem, so this is why the new version
was introduced. Let's use it.

Change-Id: I06c4a1f7f839f774bc428e89cfac30132bae904d
2018-04-09 08:26:20 +00:00
Pau Espin 00bfb39d6c trxcon/l1ctl.c: hexdump content of unhandled messages
Change-Id: Iec8fc6d49d1e35fe101960dd969de559e37a6a75
2018-04-04 17:14:26 +00:00
Harald Welte 9d90d1907b trxcon: Respect the tch_mode field of DM_EST_REQ
the initial tch_mode is not always 0 (signalling) but can very well
be directly a codec mode, if the initial activation of the channel
is in speech mode as opposed to signalling

Change-Id: I96e4c89da1165e9c5287d863e0e65d811460c606
2018-04-02 19:57:55 +02:00
Vadim Yanitskiy 96a8f288c6 trxcon/scheduler: add CHAN_IS_SACCH macro
Change-Id: I2fc90d4732433f221c628058c9812815edf9c8cb
2018-03-22 23:04:16 +07:00
Vadim Yanitskiy e05f690102 trxcon/scheduler: share lchan link identifiers
Change-Id: Ie1632f274b2ae6147a8e918ebfea60eeeb6a234c
2018-03-22 23:02:25 +07:00
Vadim Yanitskiy 02abbe5420 trxcon/sched_prim.c: fix: correct the first padding byte
According to TS 144.006, section 5.2, the first octet containing
fill bits shall be set to the binary value "00101011" == 0x2b.

Change-Id: I8f0304bf84613a2dc07cb78aff0cb8bb4c5adf6c
2018-03-22 20:54:23 +07:00
Vadim Yanitskiy 4ccb2261b1 trxcon/sched_lchan_tchf.c: always send traffic indications
We shall always send traffic frame indications, even if received
frame is incomplete or decoding was failed. This is required
for proper Measurement Reporting.

Change-Id: I99e134699796c7075299459e96b2f2d462636619
2018-03-11 17:38:29 +07:00
Vadim Yanitskiy 40e71126ab trxcon/sched_lchan_xcch.c: always send data indications
We shall always send data frame indications, even if received
frame is incomplete or decoding was failed. This is required
for proper Measurement Reporting.

Change-Id: I7beee7e797f488d04c3b59bee9501ce823717092
2018-03-11 17:38:29 +07:00
Vadim Yanitskiy 47aaf962fb trxcon/scheduler: enforce lchan handlers to set message type
Since this change, each lchan handler shall manually indicate
a type of both message indications and confirmations.

Change-Id: I02e0b87d61c127d2f6f5b9532909af78332bf707
2018-03-11 17:38:29 +07:00
Vadim Yanitskiy caebbebd16 trxcon/sched_lchan_common.c: use static memory allocation
There is no need to allocate the DL header for each new message.

Change-Id: Id7ad815c6b403f5c3d15fc02022397188f1d87fd
2018-03-11 17:38:29 +07:00
Vadim Yanitskiy 633c806a2b trxcon: clean up DATA / TRAFFIC indication API
- change 'l1ctl_tx_data_ind' symbol to 'l1ctl_tx_dt_ind' in
    order to indicate that it's used for both DATA and TRAFFIC;

  - introduce a 'traffic' flag, which is used to define either
    TRAFFIC or DATA indication type;

  - pass L2 payload and its length separately from the
    Downlink info header.

Change-Id: I9fe65ee9b2d772576b86b7bc85d53518530d1579
2018-03-11 17:38:29 +07:00
Vadim Yanitskiy ddddf9e0c4 trxcon: clean up DATA / TRAFFIC confirmation API
- change 'l1ctl_tx_data_conf' symbol to 'l1ctl_tx_dt_conf' in
    order to indicate that it's used for both DATA and TRAFFIC;

  - introduce a 'traffic' flag, which is used to define either
    TRAFFIC or DATA confirmation type;

Change-Id: Iedd569086a264dc7d8740abea5c6e5ca21e299f6
2018-03-11 17:38:29 +07:00
Vadim Yanitskiy d316b84413 trxcon/l1ctl.c: combine both DATA and TRAFFIC REQ handlers
Both functions are almost identical, and the only difference is
the message type they set. Let's combine them into a single
function and introduce a 'traffic' flag, which can be
used to define a message type.

Change-Id: I288f5d7b6cd242c4793973dcb3d2b1b6925d61a7
2018-03-11 10:34:28 +00:00
Vadim Yanitskiy eb3a1cde8c trxcon/l1ctl_link.c: allocate msgb after its length is read
Change-Id: I2b941c5ed91097c4ed2d859634bbe89f44546061
2018-03-11 10:05:48 +00:00
Vadim Yanitskiy 2136891b7b trxcon: clarify L1CTL message length field
Each L1CTL message gets its own length pushed in front before
sending. This isn't specified in the 'l1ctl_proto.h', but
assumed in the code. Let's clarify this.

Change-Id: I118d00613aeaf5ff0bad1188fa5f7450d4ca8122
2018-03-11 10:05:48 +00:00
Vadim Yanitskiy a92fd3388c trxcon: use meaningful names for L1CTL messages
There are two types of L1CTL messages: received and to be
transmitted. Let's use proper names to indicate this.

Change-Id: I7c17687579282fa389bca35dc7edbc3582e55701
2018-03-11 10:05:46 +00:00
Vadim Yanitskiy 5eae19098a trxcon/scheduler: transmit dummy frames on CBTX lchans
If at the moment of transmission there are no frames in TX buffer,
then either a dummy LAPDm frame (0x01, 0x03, 0x01, 0x2b ...) or a
silence frame (depending on a codec in use) shall be transmitted.
This is required for proper measurements on the BTS side.

Change-Id: Ie590990f2274ea476678f6b2079f90eeadab6501
2018-03-11 15:03:35 +07:00
Vadim Yanitskiy 4cf722364b trxcon/scheduler: introduce a new CBTX lchan flag
This new flag is intended to indicate that continuous burst
transmission is assumed on particular logical channel. In other
words, if a logical channel has this flag, but there is nothing
to transmit in a TX buffer, then either a dummy LAPDm frame or
a silence frame shall be sent.

Change-Id: I25fcf9eeb787ffe5378d92532439e67d7d42fa65
2018-03-11 14:59:43 +07:00
Vadim Yanitskiy c00985bf99 trxcon/sched_trx.h: clarify lchan flags meaning
Change-Id: I51b663dd16e46a4523488c3d3000922a7c3640d1
2018-03-11 14:59:43 +07:00
Vadim Yanitskiy 2778e4ef43 trxcon/sched_trx.c: fix: omit inactive logical channels
The sched_frame_clck_cb() is responsible for UL burst transmission.
Iterating over each timeslot, it chooses a proper lchan handler
according to a current frame number and a multiframe layout in use,
takes a L2 UL frame from a TX buffer, and finally calls the chosen
handler in order to to encode and transmit a taken frame.

A handler should be called only for activated logical channels...
but for some long time, there was a bug, so each lchan was
processed, including inactive ones. It's time to fix this.

Change-Id: I33e3ecc14be3ae64dfd02789c7f0970c945582c9
2018-03-11 14:59:38 +07:00
Vadim Yanitskiy f06f31fdf7 trxcon/sched_trx.c: fix: properly deallocate lchans
The llist_for_each_entry_safe() should be used instead of the
llist_for_each_entry(), because it's safe against removal
of llist entry.

Found using Valgrind's memcheck tool.

Change-Id: I65234971ec152df038c5388da537a503060c215b
2018-03-11 14:18:22 +07:00
Vadim Yanitskiy cbf818d4dc trxcon/configure.ac: add --enable-sanitize option
Change-Id: I099de726f9d67213c56d996039b4207f80a727c6
2018-03-11 14:14:51 +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