Commit Graph

90 Commits

Author SHA1 Message Date
Vadim Yanitskiy 3f4c6a8fbe coding: fix wrong n_bits_total reported for PDTCH CS2 and CS3
In gsm0503_pdtch_decode(), we decode CS2 and CS3 as if no puncturing
was employed, reordering the coded bits and setting punctured ones
to 0 manually.  Because of that, osmo_conv_decode_ber_punctured()
reports n_bits_total higher than we actually receive over the air.

Change-Id: I6b20cc450f25c48175a61da02644d66c08e22ece
Related: OS#6342, OS#6200
2024-01-31 23:10:40 +07:00
Vadim Yanitskiy 6c4be02962 coding: fix artificial bit errors for PDTCH CS2 and CS3
GPRS coding schemes CS2 and CS3 (defined in 3GPP TS 45.003 sections
5.1.2 and 5.1.3, respectively) employ so-called puncturing, which
can be described as intentional removal of coded bits.  The goal
of puncturing is to reduce the number of coded bits, so that they
fit into 4 bursts.  The receiving side recovers punctured bits,
as if they were received corrupted.

The puncturing is also used for other channel types like TCH/F9.6,
TCH/F14.4, TCH/AFS and TCH/AHS, but only for CS2 and CS3 we're
doing puncturing/depuncturing *manually*.  This explains why
we're seeing artificial bit errors only for CS2 and CS3.

gsm0503_pdtch_decode() should not be reporting punctured bits as
bit errors, fix this by using osmo_conv_decode_ber_punctured().

Change-Id: I024276d167e769396187998d881f8e7626461249
Related: OS#6342, OS#6200
2024-01-31 23:10:40 +07:00
Vadim Yanitskiy 2a72d683d3 coding: improve readability in osmo_conv_decode_ber_punctured()
Change-Id: Iaece6d0fe42f173187baa5c87fcbe3cfc60c21fc
Related: OS#6342, OS#6200
2024-01-31 23:10:35 +07:00
Vadim Yanitskiy 97374514c5 coding: fix a typo in docs for gsm0503_pdtch_decode()
Change-Id: I72e7dab116229d908add3896ecb47b59e3001f1b
2024-01-31 21:44:50 +07:00
Vadim Yanitskiy c58e4851f4 coding: gsm0503_pdtch_decode(): implement USF decoding for CS1
This patch brings decoding of the CS1 in consistency with the other
three coding schemes, for which we support decoding USF independently.

Change-Id: I61a3628741c0ac68374fc7f077cf3a07e51277c3
2023-12-08 03:35:57 +07:00
Vadim Yanitskiy 93b8eb3153 coding: clarify the USF decoding for PDCH blocks
The USF (Uplink State Flag) field is present in the MAC header of all
Downlink PDCH blocks.  It is used by the network to indicate which MS
can transmit on subsequent Uplink PDCH block(s).  This field is of a
high importance for the MS, thus the decoder API allows the caller
to obtain USF value separately from the actual data bits.

In the case of gsm0503_pdtch_decode(), if the 'usf_p' pointer is not
NULL, the USF value would be assigned for CS2/CS3/CS4 (but not CS1)
even if the CRC check fails (negative return value).  A subsequent
patch is to bring the CS1 in consistency with CS2/CS3/CS4.

In the case of gsm0503_pdtch_egprs_decode(), decoding of the USF
field separately from data bits is not implemented, and moreover
the function itself cannot be used for decoding Downlink blocks.

Change-Id: I43e8bfb4003f34766ace7c5c6080ca583ce5efbb
2023-12-08 03:27:23 +07:00
Vadim Yanitskiy ccf9aadc96 coding: fix doxygen docs for gsm0503_pdtch[_egprs]_decode()
Change-Id: I09a4c52f5704a6436eff524cd2ce5c35347aafde
2023-12-08 01:11:40 +07:00
Andreas Eversberg ebdf3dcac7 coding: gsm0503_tch_{afs,ahs}_encode(): add ability to emit BFI
Similar to Change ID Iade3310e16b906efb6892d28f474a0d15204e861, add
BFI support to TCH AFS and TCH AHS encoder.

Every BTS needs to have some graceful handling for the scenario
where it is time to send out a speech frame on TCH DL, but there is
no frame to be sent. One possible solution is to transmit dummy
FACCH, but this option is unattractive for TCH/AHS where FACCH
displaces two speech frames rather than one. A more elegant solution
is to emit a speech frame with inverted CRC6, causing the MS receiver
to declare a BFI condition to trigger substitution and muting procedure.
Setting all u(k) bits to 0 is one way to produce such an inverted-CRC
speech frame (normal TCH FR/HR CRC6 for an all-zeros frame would be
111111). This patch adds the abiliy to gsm0503_tch_{afs,ahs}_encode()
functions, indicated by payload length of 0.

See §6.2 of 3GPP TS 26.191 for substitution and muting procedure.

Related: OS#6049
Change-Id: I82ce2adf995a4b42d1f378c5819f88d773b9104a
2023-11-27 16:27:32 +00:00
Vadim Yanitskiy d739e257bb coding: gsm0503_tch_a[fh]s_encode(): make *codec const
Change-Id: I9e37a47c080cf57005e0205aa0d3cd25755a75f0
2023-11-14 11:57:19 +00:00
Vadim Yanitskiy a995269c6d coding: gsm0503_tch_a[fh]s_encode(): improve cmr/ft checks
Change-Id: If03d5b015ab1c8db56a4c67bdc8e36e260c06562
2023-11-14 11:57:19 +00:00
Pau Espin aca2c724ae Bump version: 1.8.0.252-13c29 → 1.9.0
Change-Id: I6f8eccbccb73c6c094f13f2d4bdee931cf5b9010
2023-09-12 13:15:54 +02:00
Vadim Yanitskiy fadda01f44 coding: implement encoding/decoding API for TCH/F2.4
See 3GPP TS 45.003 section 3.6.  This channel mode is a bit special,
because unlike the other CSD specific channel modes it's interleaved
over 8 (not 22!) consecutive bursts, just like TCH/FS.

Change-Id: I4685376c8deb04db670684c9ebf685ad6fc989fa
Related: OS#1572
2023-07-08 06:42:09 +07:00
Vadim Yanitskiy f8e570a20f coding: remove redundant memset()s in gsm0503_tch_fr{96,144}_encode()
Convolutional codes terminated with CONV_TERM_FLUSH (the default)
always append k-1 zeroes at the end to "flush" the encoder state.
This is the case for both TCH/F9.6 and TCH/F14.4.

Change-Id: I4a77ecb9af72b2fd4ea92c42d6748879e73d2cf2
Related: OS#1572
2023-07-08 06:05:13 +07:00
Sylvain Munaut c87c6a3a73 gsm: Improve the TCH/H2.4 coding routines
The spec isn't super clear, but basically the conv coding is done
in two blocks of 72 bits.

The way it's currently implemented isn't "wrong" in the sense it will
produce correct output given no bit errors, but it's better to do the
decoding in two blocks because this then it makes use of the fact we
know the state of the encoder after the 72 bits, which improves the
corrective ability of the code.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: Id2551ffe2a0ebfd0a6df0e1d288a6f0af7e1eda7
2023-07-07 16:06:26 +02:00
Vadim Yanitskiy 7d121cbaed coding: fix a copy-paste bug in gsm0503_tch_afs_decode_dtx()
According to 3GPP TS 45.003, section 3.9.2, the convolutional coding
is *not* employed in the case of SID_FIRST.  This is why we're using
sid_first_dummy[] in this function.

The conv[] array is not initialized in the case of AFS_SID_FIRST and
passing it to tch_amr_reassemble() is highly likely a copy-paste bug.
Pass the sid_first_dummy[] instead.

Change-Id: Ic8bfc34ce9d14821fe4e82932325f0c517d443a1
Fixes: CID#272949 "Uninitialized scalar variable"
2023-06-23 16:57:52 +07:00
Mychaela N. Falconia 6e529a2c74 coding: gsm0503_tch_{fr,hr}_encode(): add ability to emit BFI
Every BTS needs to have some graceful handling for the scenario
where it is time to send out a speech frame on TCH DL, but there is
no frame to be sent.  One possible solution is to transmit dummy
FACCH, but this option is unattractive for TCH/HS where FACCH
displaces two speech frames rather than one.  A more elegant
solution is to emit a speech frame with inverted CRC3, causing
the MS receiver to declare a BFI condition to its Rx DTX handler.
Setting all u(k) bits to 0 is one way to produce such an inverted-CRC
speech frame (normal TCH FR/HR CRC3 for an all-zeros frame would be
111), and this method is in fact what sysmoBTS PHY is observed to do.
Add the same ability to gsm0503_tch_{fr,hr}_encode() functions,
indicated by payload length of 0.

Change-Id: Iade3310e16b906efb6892d28f474a0d15204e861
2023-05-27 11:06:57 +00:00
Mychaela N. Falconia 945f6cec0f coding cosmetic: gsm0503_tch_{fr,hr}_encode(): remove extra spacing
These two functions are structured as switch statements handling
different types of input, but they also have a lot of empty spacing
lines in strange places, making them difficult to read and even more
difficult to add new functionality while maintaining the same style.
Remove those extra spaces.

Change-Id: I595a80898283d0932fb33f582347ec39a9481d1a
2023-05-27 00:41:33 +00:00
Vadim Yanitskiy b04d59e997 coding: fix _tch_csd_burst_map(): do not overwrite FACCH
As was demonstrated in the unit test [1], FACCH bitstealing does not
work as expected in conjunction CSD specific encoding functions.

The problem is in _tch_csd_burst_map(): we don't check the stealing
flags hu(B) and hl(B) and overwrite both odd and even numbered bits
unconditionally.  Even worse, we reset these stealing flags to 0.

* Do not overwrite the hu(B) and hl(B) flags.
* Copy *even* numbered bits only if hu(B) is not set.
* Copy *odd* numbered bits only if hl(B) is not set.

Change-Id: Ib5395c70e3e725469c18ff7d4c47c62ddfdbd55d
Related: [1] Idc6decec3b84981d2aab4e27caab9ad65180f945
Related: OS#1572
2023-05-26 02:48:21 +07:00
Vadim Yanitskiy b334022aba coding: implement dedicated codec API for FACCH/[FH]
Currently FACCH/[FH] encoding and decoding is implemented as part of
the gsm0503_tch_[fh]r_{en,de}code and gsm0503_tch_a[fh]s_{en,de}code
API.  This works fine for speech because one FACCH frame completely
replaces one or two speech frames, but this is not the case for CSD.

According to 3GPP TS 45.002, sections 4.2.5 and 4.3.5, for TCH data
channels FACCH does not replace data frames but disturbs some amount
of bits from them.  Therefore we need to be able to perform FACCH
encoding and decoding independently from CSD specific coding API.

Change-Id: I0c7a9c180dcafe64e6aebe53518d3d11e1f29886
Related: OS#1572
2023-05-26 02:35:11 +07:00
Vadim Yanitskiy 9a22827cf6 coding: implement TCH/F9.6, TCH/[FH]4.8, TCH/H2.4, TCH/F14.4
Implement all CSD specific channel modes, except TCH/F2.4.  All of
these modes are more or less similar to each other.  The TCH/F2.4
is more similar to TCH/FS and slightly more complicated.

FACCH/F and FACCH/H will be implemented in a follow-up change.

Change-Id: Ib482817b5f6a4e3c7299f6e0b3841143b60fc93d
Related: OS#1572
2023-05-25 19:08:53 +07:00
Vadim Yanitskiy 8fb56473aa coding: fix API doc: TCH/AFS vs TCH/AHS
Change-Id: Iaed1653c6001545f69ec6b466760f30d42bc4386
2023-05-23 19:16:39 +00:00
Vadim Yanitskiy 98431bb3f4 coding: fix API doc: TCH/H needs 6 bursts, not 8
Change-Id: Iea787ec4c3b15a74f59d45825eae03740c5d28fa
2023-05-23 19:16:39 +00:00
Mychaela N. Falconia 0e17d57495 libosmocoding.map: export gsm0503_tch_hr_decode2()
In commit 57a3b3a51f I added new function gsm0503_tch_hr_decode2(),
but I forgot to add it to libosmocoding.map - and without the latter,
osmo-bts-trx and other applications can't use the new function.
Fix that omission.

Related: OS#5688
Change-Id: I6e75ca95409b5c368e8e04d0e0aba41e0331d9e6
2023-05-23 19:02:53 +00:00
Mychaela N. Falconia 57a3b3a51f gsm0503_tch_hr_decode2(): new function, emits TS101318 format
The original design of gsm0503_tch_hr_{en,de}code() functions contains
a mistake in that a pseudo-RFC5993 format was chosen for HR codec frame
input and output, instead of "pure" (agnostic to outer RTP encoding)
form of 14 bytes.  We would like to change this design so that we can
feed pure 14-byte HR codec frames to the channel coding function and
get such frames back from the channel decoding function - however,
we cannot break libosmocoding API for existing users.  In the decoding
direction, create a new function that emits TS 101 318 format, and
turn the legacy gsm0503_tch_hr_decode() API into a wrapper function
for backward compatibility.

Related: OS#5688
Change-Id: If28ddb20789e8993b7558ca08020478615b4c708
2023-05-23 16:42:01 +00:00
Mychaela N. Falconia 8d8d5af957 gsm0503_tch_hr_encode(): accept both TS101318 and RFC5993 payloads
The original design of gsm0503_tch_hr_{en,de}code() functions contains
a mistake in that a pseudo-RFC5993 format was chosen for HR codec frame
input and output, instead of "pure" (agnostic to outer RTP encoding)
form of 14 bytes.  We would like to change this design so that we can
feed pure 14-byte HR codec frames to the channel coding function and
get such frames back from the channel decoding function - however,
we cannot break libosmocoding API for existing users.  In the encoding
direction, make the new format our preferred one, but support the
extra-octet format for backward compatibility.

Related: OS#5688
Change-Id: I13eaad366f9f68615b9e9e4a5f87396a0e9dea0f
2023-05-23 16:41:05 +00:00
Mychaela N. Falconia 920c0ed86f gsm0503_tch_hr_decode(): look at all 8 stealing bits
This function needs to look at hl and hu stealing bits in order to
decide if it should decode FACCH/H instead of TCH/HS traffic.
However, out of the 8 (in total) hl and hu bits that get set when
FACCH/H stealing takes place, the function only looked at 7 of them
- one was missed.  Fix this bug.

Change-Id: I08c4358b26d69910190f89a53b654bc58c2efea9
2023-05-23 14:06:53 +00:00
Vadim Yanitskiy 548990bf6c coding: gsm0503_tch_f96_[de]interleave() not applicable to TCH/F2.4
According to 3GPP TS 45.003, section 3.6.4, the interleaving for
TCH/F2.4 is done as specified for the TCH/FS in subclause 3.1.3.

Change-Id: I52078263cd593503a9e8f024e51e18d7b0906131
Related: OS#1572
2023-05-20 19:06:11 +07:00
Vadim Yanitskiy c0305b685a coding: use GSM_MACBLOCK_LEN gsm0503_tch_fr_decode()
Change-Id: I488ca3db1ca093d19abcfba78c1516509870715d
Related: OS#1572
2023-05-20 19:05:41 +07:00
Mychaela N. Falconia f3e4745603 coding: fix decoding of EFR triplicated bits
In GSM 05.03 channel coding for EFR, there are 4 bits out of the
244-bit EFR codec frame that are triplicated before FR-like encoding,
and the decoder needs to apply a 2-out-of-3 majority voting function
to each of these triplicated bits after the FR-like decoding step.
For one of those 4 bits, this majority voting function was wrong
in the decoder implemented in gsm0503_tch_fr_decode() - fix it.

Change-Id: I47def75cdb066ed6372df4567404cc828589ed53
2023-05-19 08:44:35 +00:00
Vadim Yanitskiy fed02e01d9 coding: fix doxygen doc for _xcch_encode_cB()
Change-Id: I09ed28bd3060b9c2c958f0f465a92af7d6bacadd
2023-05-15 16:50:08 +00:00
Vadim Yanitskiy 48c60f9771 fixup (partial revert): "coding: clean up Makefile.am"
This is a partial revert of "9dca9027 coding: clean up Makefile.am".

Even though libosmocoding does not use talloc API, it still depends on
this library indirectly via libosmo{core,codec,gsm}.  Furthermore, some
of libosmocore's header files do #include <osmocom/core/talloc.h>, and
thus #include <talloc.h> via this internal header.

Under Slackware 14.2 talloc.h header lives in /usr/include/samba-4.0,
and without $(TALLOC_CFLAGS) compilation of libmsocoding fails due
to the preprocessor failing to find this header.  The culprit is my
recent patch 9dca9027 removing $(TALLOC_CFLAGS) and $(TALLOC_LIBS).

Put $(TALLOC_CFLAGS) back to AM_CFLAGS;  it will likely be emply under
distributions having talloc.h header in the standard include dir.  The
$(TALLOC_LIBS) does not need to be resurrected because libtool will
add '-ltalloc' automatically for each libosmo*.la in LIBADD.

Change-Id: Ic1bd82159a827af21fe36bea998f8f58f732473a
Related: OS#5960
2023-03-31 05:10:52 +07:00
Vadim Yanitskiy 9dca9027b7 coding: clean up Makefile.am
* Remove TALLOC_{CFLAGS,LIBS} - talloc is not used directly
* Keep conditional ENABLE_PSEUDOTALLOC for embedded builds

Change-Id: I18f0a65a47c37989f03928f99c4687bf8007d437
2023-03-11 06:31:50 +07:00
Harald Welte c9527763c2 Makefile.am: Make libraries depend on .map files
Without this, an update to the .map file doesn't re-trigger a re-link of
the library.

Change-Id: If0ea6f41730a28b04562d45efa6ca376abaf3f6b
2023-03-06 17:07:48 +00:00
Harald Welte 6345333fb1 Interleaving for CSD
This patch adds the [de]interleaving for CSD (circuit switched data),
nominally for TCH/F 9.6, but the same is also used for TCH/F 4.8,
TCH/H 4.8, TCH/F 2.4 and TCH/F 14.4.

Related: OS#4396, OS#1572
Change-Id: I6b16c2d0d7febf3883da662b2c7fec543335de12
2023-02-27 13:34:43 +00:00
Pau Espin 0158b05337 Move libosmogsm TS 44.060 declarations under include/osmocom/gsm/
Currently there's a big mess where include dir osmocom/gprs/ is used by
both libosmogsm and libosmogb.
Most of the header files under osmocom/gprs/ are actually all the
headers of libosmogb (there's no osmocom/gb/ dir). But a couple files
are actually RLC/MAC (TS 44.060) related are are also stored in there.
Those files have no relation/use in Gb, and are actually interused with
GSM (eg System Information 13 Rest Octets).
Hence, it makes sense to have the RLC/MAC related parts inside
osmocom/gsm/ as they should be in libosmogsm (and they actually are,
see gprs_rlc.h function implemented in src/gsm/gsm48_rest_octets.c).

The fact that some libosmogsm headers were placed in osmocom/gprs
instead of osmocom/gsm already created some issues, like
libosmocore.spec.in putting "%_includedir/%name/osmocom/gprs/" under
libosmogb, which is wrong.

As a first step to fix the mess, we move the 2 RLC/MAC headers currently
under osmocom/gprs/{gprs_rlc,protocol/gsm_04_60}.h under a single header
gsm/protocol/gsm_44_060.h
The two old headers are left existing for backward compatibility and now
simply include the new libosmogsm header, plus a warning asking users to
switch to the new header so we can eventually get rid of them.
This means libosmogb depends on libosmogsm, which is fine and was
already the case beforehand (libosmogb using functions like
gsm48_encode_ra() and linking against it in src/gb/Makefile.am).

Change-Id: I70cc21bf25a7081070738abacb409ed19094c3b2
2023-02-20 12:21:30 +01:00
Pau Espin 88955fb550 Fix all references to config.h
config.h is created in $(top_buildir)/config.h.
Let's make sure all CPPFLAGS add correct -Ipath includes,
and that all code includes the correct file.

Change-Id: Ie9ea38bb009bc715b01cde4d66d181f7bec2e7bd
2023-01-18 19:04:36 +01:00
Pau Espin d4c3dc8d59 Move src/*.{c,h} to src/core/
This way we have all libosmocore.so in an own subdir instead of having
lots of files in the parent dir, which also contains subdirs to other
libraries.
This also matches the schema under include/osmocom/.

Change-Id: I6c76fafebdd5e961aed88bbecd2c16bc69d580e2
2023-01-18 17:14:06 +01:00
Vadim Yanitskiy 8fbaad6903 */Makefile.am: do not mix up AM_CFLAGS with AM_CPPFLAGS
Change-Id: I2c1d5f9c61714f487fbbe60603b2682f2c0a4c6b
2022-11-10 16:07:03 +00:00
Pau Espin a1584d237b Bump version: 1.6.0.132-0239-dirty → 1.7.0
Change-Id: Idb0d20aa4336a69cb100e140fb1fa9e7ac25b984
2022-06-28 17:00:51 +02:00
Vadim Yanitskiy b57e6392fb coding: separate gsm0503_tch_a[fh]s_decode_inband()
These functions can be re-used for parsing in-band data from DTX
specific frames like SID_FIRST, SID_UPDATE, SID_ONSET, etc.

Change-Id: I0106de7a7f87517006e323299b2dc08457d1c6cf
Related: OS#5570
2022-05-27 08:31:30 +00:00
Vadim Yanitskiy cc4213e927 coding: add gsm0503_detect_a[fh]s_dtx_frame2()
The new functions accept an additional mode_id poiner, which is
currently set for the following frames: AFS_ONSET, AHS_ONSET,
AHS_SID_FIRST_P2 with N * 16 - M bit pattern.

Also, the new API accepts soft-bits instead of hard-bits.
Converting bits from soft to hard is now performed internally.

Change-Id: Ibcac395f800bb64150c97fcdaca3523ecfc5fcee
Related: OS#5570
2022-05-27 08:31:30 +00:00
Vadim Yanitskiy d6dca0c2f9 coding: do not reset codec ID on receipt of DTX frames
Parsing of CMI/CMC/CMR from AMR's special DTX frames is currently
not implemented.  It's better to keep the old stored value rather
than resetting it to 0 every time we receive such a frame.
Add TODO comments for each DTX frame type.

Change-Id: Ic4edbb8ab873fe0bdd69a8710803628bc4f447d0
Related: OS#5570
2022-05-25 13:34:31 +00:00
Vadim Yanitskiy 7790459c8e coding: fix decoding of AHS_SID_UPDATE frames (BER ~50%)
As was demonstrated in [1], there is a TCH/AHS specific problem in
libosmocoding causing unexpected BER ~50% in decoded AHS_SID_UPDATE
frames.  The reason is that A[H]S_SID_UPDATE employs quite tricky
interleaving algorithm, which is different from the algorithm used
by normal TCH/AHS speech frames or A[F]S_SID_UPDATE frames.

An AHS_SID_UPDATE frame consists of two halves (228 bits each):

  +---------+--------------------|---------+--------------------+
  | in-band |     SID marker     | in-band |     coded data     |
  +---------+--------------------|---------+--------------------+
  | 16 bits |      212 bits      | 16 bits |      212 bits      |

The first half contains coded in-band signalling data (16 bits) and
the identification marker (212 bits), which allows to detect that
it's an AHS_SID_UPDATE.  This half is carried by even bits of the
first two bursts and odd bits of the last two bursts.

The other half also contains the in-band data (16 bits), while the
remaining 212 bits contain encoded SID_UPDATE (212 bits).  This
half is carried by even bits of the last two bursts and odd bits
of the first two bursts.

Current implementation does not use odd bits of the first two
bursts at all, so buffer cB[] in gsm0503_tch_ahs_decode_dtx()
contains only 114 out of 228 bits.

This patch changes the logic, so that gsm0503_tch_ahs_decode_dtx()
would not split AHS_SID_UPDATE onto two frames anymore like its
TCH/AFS equivalent does, but attempt to deinterleave the second
half and attempt to decode the payload immediately.

Change-Id: I8686d895e96fa0e606c1898b6574cc80a8f46983
Related: [1] I434157e2091a306c039123cea08d84bd8533c937
Related: SYS#5853
2022-05-25 13:34:31 +00:00
Vadim Yanitskiy a2bee8bc88 coding: prevent marking FACCH frames as AMR's special DTX frames
Both gsm0503_tch_a[fh]s_decode_dtx() functions accept an optional
'dtx' pointer, which is used to indicate type of a received AMR
block to the caller in DTX mode of operation.  If not NULL, it's
expected to be updated by gsm0503_detect_a[fh]s_dtx_frame() every
time one of the mentioned functions is called.

However, in case of FACCH both functions return early, so the value
of dtx remains unchanged and thus FACCH frames may be misinterpreted
as AMR's special DTX frames.  This is rather critical during the DTX
silence periods, when all special DTX frames (e.g. SID_UPDATE) are
being treated as SUB frames.  Each unsuccessful FACCH decoding
attempt will 'poison' SUB measurements, causing unexpected RxQual-
SUB values in the Uplink measurement reports.

Fix this by resetting *dtx to AMR_OTHER in the FACCH specific path.

Change-Id: I2e6f4b748c6445725211e264ab5f3f5a2712087a
Related: SYS#5853
2022-05-16 20:13:13 +03:00
Vadim Yanitskiy 71e8091c9d coding: properly handle AFS_SID_UPDATE frames in DTX mode
There are two similar values in enum gsm0503_amr_dtx_frames:

  * AFS_SID_UPDATE - precursor of SID UPDATE,
  * AFS_SID_UPDATE_CN - the actual SID UPDATE.

The former is internally used by libosmocoding to mark the current
frame as a precursor of the actual SID UPDATE frame - the later.

  +---+---+---+---+---+---+---+---+
  | _ | _ | _ | _ | a | b | c | d |  AFS_SID_UPDATE
  +---+---+---+---+---+---+---+---+
  | a | b | c | d | _ | _ | _ | _ |  AFS_SID_UPDATE_CN
  +---+---+---+---+---+---+---+---+

This is required because function gsm0503_tch_afs_decode_dtx() is
invoked by TDMA scheduler on every 4th received burst, while the
burst buffer is 8 bursts wide.

Currently, whenever gsm0503_detect_afs_dtx_frame() detects an
AFS_SID_UPDATE frame, we still attempt to decode it as a speech
or data below in gsm0503_tch_afs_decode_dtx().  This is indeed
a bug, which results in unexpected BER values:

  * expected BER 0/212,
  * actual BER 252/448.

We should return immediately once we have detected an AFS_SID_UPDATE.
This patch fixes unexpected BER-SUB values during DTXu silence periods.

Change-Id: I813081a4c0865958eee2496fe251ae17235ac842
Related: SYS#5853
2022-05-16 00:51:57 +03:00
Vadim Yanitskiy eebaccdae5 coding: use switch statement in gsm0503_tch_a[fh]s_decode_dtx()
Change-Id: Ib63b6f582b305746c3618563f2f85128fffd8e90
Related: SYS#5853
2022-05-16 00:51:57 +03:00
Vadim Yanitskiy bf2d5e9b6f coding: cosmetic: move 'dtx_prev' to the scope where it's used
Change-Id: I147f44f1c071e53febeff425a0a7837a0ff10436
Related: SYS#5853
2022-05-16 00:51:30 +03:00
Pau Espin 6c58d155eb coding: Use ARRAY_SIZE macro
Change-Id: I6b7a2a3a7be6a1d92038ff3b249e539fcd0f639e
2022-05-13 14:09:43 +02:00
Pau Espin d2737e6027 coding: Refactor function to avoid gcc false positive warn
"""
/libosmocore/src/coding/gsm0503_coding.c: In function 'osmo_conv_decode_ber_punctured':
/libosmocore/src/coding/gsm0503_coding.c:563:31: error: 'coded_len' may be used uninitialized [-Werror=maybe-uninitialized]
  563 |                 *n_bits_total = coded_len;
      |                 ~~~~~~~~~~~~~~^~~~~~~~~~~
/libosmocore/src/coding/gsm0503_coding.c:541:21: note: 'coded_len' was declared here
  541 |         int res, i, coded_len;
      |                     ^~~~~~~~~
"""

This error is really a false positive. However, it is true that the code
used to be a bit more complex than required, since the 2 later conditions
could be inside the first one.
Let's simply do early termination to simplify the function, and get rid
of the gcc warning.

Change-Id: I31ebf0c4be61daf6395d9a9fac05c7fdceb8bcb9
2022-05-13 13:07:23 +02:00
Vadim Yanitskiy f6fd0bb7f2 coding: fix comments for detect_afs_sid_{first,update,onset}
Change-Id: I42edc3caee09c1a4bebecc41e8be46914dc7f8ef
Related: SYS#5853
2022-04-28 13:03:00 +00:00