FreeCalypso > hg > ice1-trau-tester
annotate ater/out_frame.c @ 36:e4a0b4a61649
top Makefile: add pcm-br
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 28 Aug 2024 05:02:29 +0000 |
parents | bacc590ec839 |
children |
rev | line source |
---|---|
21
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Here we implement our TRAU-UL bit filling function. |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * This code is based on trau_rtp_conv.c in libosmo-abis. |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdint.h> |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdbool.h> |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <osmocom/core/bits.h> |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <osmocom/core/crc8gen.h> |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <osmocom/trau/trau_frame.h> |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include "out_frame.h" |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 /* this corresponds to the bit-lengths of the individual codec |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 * parameters as indicated in Table 1.1 of TS 46.010 */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 static const uint8_t gsm_fr_map[] = { |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 6, 6, 5, 5, 4, 4, 3, 3, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 7, 2, 2, 6, 3, 3, 3, 3, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 3, 3, 3, 3, 3, 3, 3, 3, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 3, 7, 2, 2, 6, 3, 3, 3, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 3, 3, 3, 3, 3, 3, 3, 3, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 3, 3, 7, 2, 2, 6, 3, 3, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 3, 3, 3, 3, 3, 3, 3, 3, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 3, 3, 3, 7, 2, 2, 6, 3, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 3, 3, 3, 3, 3, 3, 3, 3, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 3, 3, 3, 3 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 }; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 /* |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 * EFR TRAU parity |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 * |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 * g(x) = x^3 + x^1 + 1 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 static const struct osmo_crc8gen_code gsm0860_efr_crc3 = { |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 .bits = 3, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 .poly = 0x3, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 .init = 0x0, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 .remainder = 0x7, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 }; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 /* re-combine EFR parity bits */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 static inline void efr_parity_bits_1(ubit_t *check_bits, const ubit_t *d_bits) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 { |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 memcpy(check_bits + 0 , d_bits + 0, 22); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 memcpy(check_bits + 22 , d_bits + 24, 3); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 check_bits[25] = d_bits[28]; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 static inline void efr_parity_bits_2(ubit_t *check_bits, const ubit_t *d_bits) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 { |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 memcpy(check_bits + 0 , d_bits + 42, 10); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 memcpy(check_bits + 10 , d_bits + 90, 2); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 static inline void efr_parity_bits_3(ubit_t *check_bits, const ubit_t *d_bits) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 { |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 memcpy(check_bits + 0 , d_bits + 98, 5); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 check_bits[5] = d_bits[104]; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 memcpy(check_bits + 6 , d_bits + 143, 2); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 static inline void efr_parity_bits_4(ubit_t *check_bits, const ubit_t *d_bits) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 { |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 memcpy(check_bits + 0 , d_bits + 151, 10); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 memcpy(check_bits + 10 , d_bits + 199, 2); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 static inline void efr_parity_bits_5(ubit_t *check_bits, const ubit_t *d_bits) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 { |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 memcpy(check_bits + 0 , d_bits + 207, 5); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 check_bits[5] = d_bits[213]; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 memcpy(check_bits + 6 , d_bits + 252, 2); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 static void fill_data_fr(const uint8_t *data, struct osmo_trau_frame *tf) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 { |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 int i, j, k, l, o; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 /* reassemble d-bits */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 i = 0; /* counts bits */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 j = 4; /* counts input bits */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 k = gsm_fr_map[0]-1; /* current number bit in element */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 l = 0; /* counts element bits */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 o = 0; /* offset output bits */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 while (i < 260) { |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 tf->d_bits[k+o] = (data[j/8] >> (7-(j%8))) & 1; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 /* to avoid out-of-bounds access in gsm_fr_map[++l] */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 if (i == 259) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 break; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 if (--k < 0) { |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 o += gsm_fr_map[l]; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 k = gsm_fr_map[++l]-1; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 i++; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 j++; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 } |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 |
22
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
102 static void invert_crc3(ubit_t *crc) |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
103 { |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
104 crc[0] = !crc[0]; |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
105 crc[1] = !crc[1]; |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
106 crc[2] = !crc[2]; |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
107 } |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
108 |
21
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 static void fill_data_efr(const uint8_t *data, struct osmo_trau_frame *tf) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 { |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 int i, j; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 ubit_t check_bits[26]; |
22
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
113 uint8_t crc_inv; |
21
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 /* reassemble d-bits */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 tf->d_bits[0] = 1; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 for (i = 1, j = 4; i < 39; i++, j++) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 efr_parity_bits_1(check_bits, tf->d_bits); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 26, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 tf->d_bits + 39); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 for (i = 42, j = 42; i < 95; i++, j++) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 efr_parity_bits_2(check_bits, tf->d_bits); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 12, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 tf->d_bits + 95); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 for (i = 98, j = 95; i < 148; i++, j++) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 efr_parity_bits_3(check_bits, tf->d_bits); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 8, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 tf->d_bits + 148); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 for (i = 151, j = 145; i < 204; i++, j++) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 efr_parity_bits_4(check_bits, tf->d_bits); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 12, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 tf->d_bits + 204); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 for (i = 207, j = 198; i < 257; i++, j++) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 tf->d_bits[i] = (data[j/8] >> (7-(j%8))) & 1; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 efr_parity_bits_5(check_bits, tf->d_bits); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 osmo_crc8gen_set_bits(&gsm0860_efr_crc3, check_bits, 8, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 tf->d_bits + 257); |
22
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
142 |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
143 /* inverted CRC option */ |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
144 crc_inv = data[31]; |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
145 if (crc_inv & 0x80) |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
146 invert_crc3(tf->d_bits + 39); |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
147 if (crc_inv & 0x40) |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
148 invert_crc3(tf->d_bits + 95); |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
149 if (crc_inv & 0x20) |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
150 invert_crc3(tf->d_bits + 148); |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
151 if (crc_inv & 0x10) |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
152 invert_crc3(tf->d_bits + 204); |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
153 if (crc_inv & 0x08) |
bacc590ec839
ater: implement EFR CRC inversion option
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
154 invert_crc3(tf->d_bits + 257); |
21
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 } |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 void trau_frame_from_record(const uint8_t *rec, bool is_efr, |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 struct osmo_trau_frame *tf) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 { |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 if (is_efr) |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 fill_data_efr(rec, tf); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 else |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 fill_data_fr(rec, tf); |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 /* set BFI and SID flags */ |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 tf->c_bits[11] = (rec[33] & 0x80) >> 7; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 tf->c_bits[12] = (rec[33] & 0x02) >> 1; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 tf->c_bits[13] = (rec[33] & 0x01) >> 0; |
2ee910aa03c3
ater: implement TRAU frame filling
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 } |