HACK to make CRC4 computation work
* reverse bit-order of every input byte when computing CRC4
* reverse bit-order of CRC4 value we receive in TS0 bits
I don't really understand why, but this makes the CRC check pass.
We probably need another table if we want to avoid this.
diff --git a/src/crc4itu.c b/src/crc4itu.c
index fbefac8..b927d4b 100644
--- a/src/crc4itu.c
+++ b/src/crc4itu.c
@@ -1,4 +1,5 @@
#include <stdint.h>
+#include <osmocom/core/bits.h>
static const uint8_t crc4_table_byte[256] = {
0x0, 0x7, 0xe, 0x9, 0x5, 0x2, 0xb, 0xc, 0xa, 0xd, 0x4, 0x3, 0xf, 0x8, 0x1, 0x6,
@@ -23,6 +24,6 @@
{
crc &= 0xf;
while (len--)
- crc = crc4_table_byte[crc ^ *data++];
+ crc = crc4_table_byte[crc ^ osmo_revbytebits_8(*data++)];
return crc;
}
diff --git a/src/osmo_e1.c b/src/osmo_e1.c
index 5134965..f47e8ed 100644
--- a/src/osmo_e1.c
+++ b/src/osmo_e1.c
@@ -389,10 +389,10 @@
if (smf2)
offset = 8;
- crc |= (e1i->rx.ts0_history[0+offset] >> 7) << 3;
- crc |= (e1i->rx.ts0_history[2+offset] >> 7) << 2;
- crc |= (e1i->rx.ts0_history[4+offset] >> 7) << 1;
- crc |= (e1i->rx.ts0_history[6+offset] >> 7) << 0;
+ crc |= (e1i->rx.ts0_history[0+offset] >> 7) << 0;
+ crc |= (e1i->rx.ts0_history[2+offset] >> 7) << 1;
+ crc |= (e1i->rx.ts0_history[4+offset] >> 7) << 2;
+ crc |= (e1i->rx.ts0_history[6+offset] >> 7) << 3;
return crc;
}