FreeCalypso > hg > gsm-net-reveng
comparison trau-decode/parse-efr.c @ 4:d9c095357c32
trau-parse: check and report EFR CRC
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 24 May 2024 09:16:35 +0000 |
parents | |
children | bf5c9fb431b8 |
comparison
equal
deleted
inserted
replaced
3:64b15810dc4c | 4:d9c095357c32 |
---|---|
1 /* | |
2 * This module implements the EFR decoding part of trau-parse. | |
3 */ | |
4 | |
5 #include <stdio.h> | |
6 #include <stdint.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <strings.h> | |
10 #include <gsm_efr.h> | |
11 #include "osmo_bits.h" | |
12 | |
13 /* | |
14 * EFR TRAU parity | |
15 * | |
16 * g(x) = x^3 + x^1 + 1 | |
17 */ | |
18 static const struct osmo_crc8gen_code gsm0860_efr_crc3 = { | |
19 .bits = 3, | |
20 .poly = 0x3, | |
21 .init = 0x0, | |
22 .remainder = 0x7, | |
23 }; | |
24 | |
25 /* re-combine EFR parity bits */ | |
26 static inline void efr_parity_bits_1(ubit_t *check_bits, const ubit_t *d_bits) | |
27 { | |
28 memcpy(check_bits + 0 , d_bits + 0, 22); | |
29 memcpy(check_bits + 22 , d_bits + 24, 3); | |
30 check_bits[25] = d_bits[28]; | |
31 } | |
32 | |
33 static inline void efr_parity_bits_2(ubit_t *check_bits, const ubit_t *d_bits) | |
34 { | |
35 memcpy(check_bits + 0 , d_bits + 42, 10); | |
36 memcpy(check_bits + 10 , d_bits + 90, 2); | |
37 } | |
38 | |
39 static inline void efr_parity_bits_3(ubit_t *check_bits, const ubit_t *d_bits) | |
40 { | |
41 memcpy(check_bits + 0 , d_bits + 98, 5); | |
42 check_bits[5] = d_bits[104]; | |
43 memcpy(check_bits + 6 , d_bits + 143, 2); | |
44 } | |
45 | |
46 static inline void efr_parity_bits_4(ubit_t *check_bits, const ubit_t *d_bits) | |
47 { | |
48 memcpy(check_bits + 0 , d_bits + 151, 10); | |
49 memcpy(check_bits + 10 , d_bits + 199, 2); | |
50 } | |
51 | |
52 static inline void efr_parity_bits_5(ubit_t *check_bits, const ubit_t *d_bits) | |
53 { | |
54 memcpy(check_bits + 0 , d_bits + 207, 5); | |
55 check_bits[5] = d_bits[213]; | |
56 memcpy(check_bits + 6 , d_bits + 252, 2); | |
57 } | |
58 | |
59 void | |
60 check_efr_crc(d_bits) | |
61 ubit_t *d_bits; | |
62 { | |
63 ubit_t check_bits[26]; | |
64 int rc1, rc2, rc3, rc4, rc5; | |
65 | |
66 efr_parity_bits_1(check_bits, d_bits); | |
67 rc1 = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 26, | |
68 d_bits + 39); | |
69 efr_parity_bits_2(check_bits, d_bits); | |
70 rc2 = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 12, | |
71 d_bits + 95); | |
72 efr_parity_bits_3(check_bits, d_bits); | |
73 rc3 = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 8, | |
74 d_bits + 148); | |
75 efr_parity_bits_4(check_bits, d_bits); | |
76 rc4 = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 12, | |
77 d_bits + 204); | |
78 efr_parity_bits_5(check_bits, d_bits); | |
79 rc5 = osmo_crc8gen_check_bits(&gsm0860_efr_crc3, check_bits, 8, | |
80 d_bits + 257); | |
81 printf(" D1=%u CRC: %s %s %s %s %s\n", d_bits[0], | |
82 rc1 ? "bad" : "good", rc2 ? "bad" : "good", | |
83 rc3 ? "bad" : "good", rc4 ? "bad" : "good", | |
84 rc5 ? "bad" : "good"); | |
85 } |