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
diff --git a/src/coding/gsm0503_coding.c b/src/coding/gsm0503_coding.c
index 5badbd0..a34cd92 100644
--- a/src/coding/gsm0503_coding.c
+++ b/src/coding/gsm0503_coding.c
@@ -3298,13 +3298,23 @@
static inline void _tch_csd_burst_map(ubit_t *burst, const ubit_t *iB)
{
- for (unsigned int i = 0; i < 57; i++) {
- burst[i] |= iB[i];
- burst[59 + i] |= iB[57 + i];
+ unsigned int i;
+
+ /* hu(B): copy *even* numbered bits if not stolen by FACCH */
+ if (burst[58] == 0) {
+ for (i = 0; i < 57; i += 2)
+ burst[i] |= iB[i];
+ for (i = 58; i < 114; i += 2)
+ burst[i + 2] |= iB[i];
}
- burst[57] = 0; /* hl(B) */
- burst[58] = 0; /* hu(B) */
+ /* hl(B): copy *odd* numbered bits if not stolen by FACCH */
+ if (burst[57] == 0) {
+ for (i = 1; i < 57; i += 2)
+ burst[i] |= iB[i];
+ for (i = 57; i < 114; i += 2)
+ burst[i + 2] |= iB[i];
+ }
}
/*! Perform channel encoding of a TCH/F9.6 channel as per section 3.3.