diff options
author | Harald Welte <laforge@gnumonks.org> | 2018-05-11 20:48:31 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2018-05-11 20:48:31 +0200 |
commit | 9bd2c9ffe7cf82c5d0a12406db018717d9b78858 (patch) | |
tree | 9e5700f3f5444aedc217ccab745882ef147a94fa | |
parent | d3941c6a982f67fa0012bde2a317bd6d6da0e98f (diff) |
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.
-rw-r--r-- | src/crc4itu.c | 3 | ||||
-rw-r--r-- | src/osmo_e1.c | 8 |
2 files changed, 6 insertions, 5 deletions
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 @@ uint8_t crc4itu(uint8_t crc, const uint8_t *data, unsigned int len) { 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 @@ static uint8_t crc4_from_ts0_hist(struct osmo_e1_instance *e1i, bool smf2) 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; } |