blob: 61d4fdc6785b153efeb3340a6fceadcc392a81ef [file] [log] [blame]
Vadim Yanitskiy3262f822016-09-23 01:48:59 +07001/*
2 * (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
3 * (C) 2016 by Tom Tsou <tom.tsou@ettus.com>
Harald Weltec6636782017-06-12 14:59:37 +02004 * (C) 2017 by Hrald Welte <laforge@gnumonks.org>
Vadim Yanitskiy3262f822016-09-23 01:48:59 +07005 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#include <stdint.h>
24#include <string.h>
25
26#include <osmocom/core/bits.h>
27#include <osmocom/coding/gsm0503_tables.h>
28#include <osmocom/coding/gsm0503_interleaving.h>
29
Harald Weltec6636782017-06-12 14:59:37 +020030/*! \addtogroup interleaving
31 * @{
32 * \brief GSM TS 05.03 interleaving
33 *
34 * This module contains interleaving / de-interleaving routines for
35 * various channel types, as defined in 3GPP TS 05.03 / 45.003
36 */
37
38/*! \file gsm0503_interleaving.c */
39
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070040/*
41 * GSM xCCH interleaving and burst mapping
42 *
43 * Interleaving:
44 *
45 * Given 456 coded input bits, form 4 blocks of 114 bits:
46 *
47 * i(B, j) = c(n, k) k = 0, ..., 455
48 * n = 0, ..., N, N + 1, ...
49 * B = B_0 + 4n + (k mod 4)
50 * j = 2(49k mod 57) + ((k mod 8) div 4)
51 *
52 * Mapping on Burst:
53 *
54 * e(B, j) = i(B, j)
55 * e(B, 59 + j) = i(B, 57 + j) j = 0, ..., 56
56 * e(B, 57) = h_l(B)
57 * e(B, 58) = h_n(B)
58 *
59 * Where hl(B) and hn(B) are bits in burst B indicating flags.
60 */
61
Harald Weltec6636782017-06-12 14:59:37 +020062/*! \brief De-Interleave burst bits according to TS 05.03 4.1.4
63 * \param[out] cB caller-allocated output buffer for 456 soft coded bits
64 * \param[in] iB 456 soft input bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070065void gsm0503_xcch_deinterleave(sbit_t *cB, const sbit_t *iB)
66{
67 int j, k, B;
68
69 for (k = 0; k < 456; k++) {
70 B = k & 3;
71 j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
72 cB[k] = iB[B * 114 + j];
73 }
74}
75
Harald Weltec6636782017-06-12 14:59:37 +020076/*! \brief Interleave burst bits according to TS 05.03 4.1.4
77 * \param[out] iB caller-allocated output buffer for 456 soft interleaved bits
78 * \param[in] cB 456 soft input coded bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070079void gsm0503_xcch_interleave(ubit_t *cB, ubit_t *iB)
80{
81 int j, k, B;
82
83 for (k = 0; k < 456; k++) {
84 B = k & 3;
85 j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
86 iB[B * 114 + j] = cB[k];
87 }
88}
89
Harald Weltec6636782017-06-12 14:59:37 +020090/*! \brief De-Interleave MCS1 DL burst bits according to TS 05.03 5.1.5.1.5
91 * \param[out] u caller-allocated output buffer for 12 soft coded bits
92 * \param[out] hc caller-allocated output buffer for 68 soft coded bits
93 * \param[out] dc caller-allocated output buffer for 372 soft coded bits
94 * \param[in] iB 452 interleaved soft input bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070095void gsm0503_mcs1_dl_deinterleave(sbit_t *u, sbit_t *hc,
96 sbit_t *dc, const sbit_t *iB)
97{
98 int k;
99 sbit_t c[452];
100 sbit_t cp[456];
101
102 gsm0503_xcch_deinterleave(cp, iB);
103
104 for (k = 0; k < 25; k++)
105 c[k] = cp[k];
106 for (k = 26; k < 82; k++)
107 c[k - 1] = cp[k];
108 for (k = 83; k < 139; k++)
109 c[k - 2] = cp[k];
110 for (k = 140; k < 424; k++)
111 c[k - 3] = cp[k];
112 for (k = 425; k < 456; k++)
113 c[k - 4] = cp[k];
114
115 if (u) {
116 for (k = 0; k < 12; k++)
117 u[k] = c[k];
118 }
119
120 if (hc) {
121 for (k = 12; k < 80; k++)
122 hc[k - 12] = c[k];
123 }
124
125 if (dc) {
126 for (k = 80; k < 452; k++)
127 dc[k - 80] = c[k];
128 }
129}
130
Harald Weltec6636782017-06-12 14:59:37 +0200131/*! \brief Interleave MCS1 DL burst bits according to TS 05.03 5.1.5.1.5
132 * \param[in] up 12 input soft coded bits (usf)
133 * \param[in] hc 68 input soft coded bits (header)
134 * \param[in] dc 372 input soft bits (data)
135 * \param[out] iB 456 interleaved soft output bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700136void gsm0503_mcs1_dl_interleave(const ubit_t *up, const ubit_t *hc,
137 const ubit_t *dc, ubit_t *iB)
138{
139 int k;
140 ubit_t c[452];
141 ubit_t cp[456];
142
143 for (k = 0; k < 12; k++)
144 c[k] = up[k];
145 for (k = 12; k < 80; k++)
146 c[k] = hc[k - 12];
147 for (k = 80; k < 452; k++)
148 c[k] = dc[k - 80];
149
150 for (k = 0; k < 25; k++)
151 cp[k] = c[k];
152 for (k = 26; k < 82; k++)
153 cp[k] = c[k - 1];
154 for (k = 83; k < 139; k++)
155 cp[k] = c[k - 2];
156 for (k = 140; k < 424; k++)
157 cp[k] = c[k - 3];
158 for (k = 425; k < 456; k++)
159 cp[k] = c[k - 4];
160
161 cp[25] = 0;
162 cp[82] = 0;
163 cp[139] = 0;
164 cp[424] = 0;
165
166 gsm0503_xcch_interleave(cp, iB);
167}
168
Harald Weltec6636782017-06-12 14:59:37 +0200169/*! \brief Interleave MCS1 UL burst bits according to TS 05.03 5.1.5.2.4
170 * \param[out] hc caller-allocated output buffer for 80 soft coded header bits
171 * \param[out] dc caller-allocated output buffer for 372 soft coded data bits
172 * \param[in] iB 456 interleaved soft input bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700173void gsm0503_mcs1_ul_deinterleave(sbit_t *hc, sbit_t *dc, const sbit_t *iB)
174{
175 int k;
176 sbit_t c[452];
177 sbit_t cp[456];
178
179 gsm0503_xcch_deinterleave(cp, iB);
180
181 for (k = 0; k < 25; k++)
182 c[k] = cp[k];
183 for (k = 26; k < 82; k++)
184 c[k - 1] = cp[k];
185 for (k = 83; k < 139; k++)
186 c[k - 2] = cp[k];
187 for (k = 140; k < 424; k++)
188 c[k - 3] = cp[k];
189 for (k = 425; k < 456; k++)
190 c[k - 4] = cp[k];
191
192 if (hc) {
193 for (k = 0; k < 80; k++)
194 hc[k] = c[k];
195 }
196
197 if (dc) {
198 for (k = 80; k < 452; k++)
199 dc[k - 80] = c[k];
200 }
201}
202
Harald Weltec6636782017-06-12 14:59:37 +0200203/*! \brief Interleave MCS1 DL burst bits according to TS 05.03 5.1.5.2.4
204 * \param[in] hc 80 input coded bits (header)
205 * \param[in] dc 372 input bits (data)
206 * \param[out] iB 456 interleaved output bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700207void gsm0503_mcs1_ul_interleave(const ubit_t *hc, const ubit_t *dc, ubit_t *iB)
208{
209 int k;
210 ubit_t c[452];
211 ubit_t cp[456];
212
213 for (k = 0; k < 80; k++)
214 c[k] = hc[k];
215 for (k = 80; k < 452; k++)
216 c[k] = dc[k - 80];
217
218 for (k = 0; k < 25; k++)
219 cp[k] = c[k];
220 for (k = 26; k < 82; k++)
221 cp[k] = c[k - 1];
222 for (k = 83; k < 139; k++)
223 cp[k] = c[k - 2];
224 for (k = 140; k < 424; k++)
225 cp[k] = c[k - 3];
226 for (k = 425; k < 456; k++)
227 cp[k] = c[k - 4];
228
229 cp[25] = 0;
230 cp[82] = 0;
231 cp[139] = 0;
232 cp[424] = 0;
233
234 gsm0503_xcch_interleave(cp, iB);
235}
236
Harald Weltec6636782017-06-12 14:59:37 +0200237/*! \brief Interleave MCS5 UL burst bits according to TS 05.03 5.1.9.2.4
238 * \param[in] hc 136 soft coded header input bits
239 * \param[in] dc 1248 soft coded data input bits
240 * \param[out] hi 136 interleaved header output bits
241 * \param[out] di 1248 interleaved data output bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700242void gsm0503_mcs5_ul_interleave(const ubit_t *hc, const ubit_t *dc,
243 ubit_t *hi, ubit_t *di)
244{
245 int j, k;
246
247 /* Header */
248 for (k = 0; k < 136; k++) {
249 j = 34 * (k % 4) + 2 * (11 * k % 17) + k % 8 / 4;
250 hi[j] = hc[k];
251 }
252
253 /* Data */
254 for (k = 0; k < 1248; k++) {
255 j = gsm0503_interleave_mcs5[k];
256 di[j] = dc[k];
257 }
258}
259
Harald Weltec6636782017-06-12 14:59:37 +0200260/*! \brief De-Interleave MCS5 UL burst bits according to TS 05.03 5.1.9.2.4
261 * \param[out] hc caller-allocated output buffer for 136 soft coded header bits
262 * \param[out] dc caller-allocated output buffer for 1248 soft coded data bits
263 * \param[in] iB interleaved soft input bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700264void gsm0503_mcs5_ul_deinterleave(sbit_t *hc, sbit_t *dc,
265 const sbit_t *hi, const sbit_t *di)
266{
267 int j, k;
268
269 /* Header */
270 if (hc) {
271 for (k = 0; k < 136; k++) {
272 j = 34 * (k % 4) + 2 * (11 * k % 17) + k % 8 / 4;
273 hc[k] = hi[j];
274 }
275 }
276
277 /* Data */
278 if (dc) {
279 for (k = 0; k < 1248; k++) {
280 j = gsm0503_interleave_mcs5[k];
281 dc[k] = di[j];
282 }
283 }
284}
285
Harald Weltec6636782017-06-12 14:59:37 +0200286/*! \brief Interleave MCS5 DL burst bits according to TS 05.03 5.1.9.1.5
287 * \param[in] hc 100 soft coded header input bits
288 * \param[in] dc 1248 soft coded data input bits
289 * \param[out] hi 100 interleaved header output bits
290 * \param[out] di 1248 interleaved data output bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700291void gsm0503_mcs5_dl_interleave(const ubit_t *hc, const ubit_t *dc,
292 ubit_t *hi, ubit_t *di)
293{
294 int j, k;
295
296 /* Header */
297 for (k = 0; k < 100; k++) {
298 j = 25 * (k % 4) + ((17 * k) % 25);
299 hi[j] = hc[k];
300 }
301
302 /* Data */
303 for (k = 0; k < 1248; k++) {
304 j = gsm0503_interleave_mcs5[k];
305 di[j] = dc[k];
306 }
307}
308
Harald Weltec6636782017-06-12 14:59:37 +0200309/*! \brief De-Interleave MCS5 UL burst bits according to TS 05.03 5.1.9.1.5
310 * \param[out] hc caller-allocated output buffer for 100 soft coded header bits
311 * \param[out] dc caller-allocated output buffer for 1248 soft coded data bits
312 * \param[in] iB interleaved soft input bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700313void gsm0503_mcs5_dl_deinterleave(sbit_t *hc, sbit_t *dc,
314 const sbit_t *hi, const sbit_t *di)
315{
316 int j, k;
317
318 /* Header */
319 if (hc) {
320 for (k = 0; k < 100; k++) {
321 j = 25 * (k % 4) + ((17 * k) % 25);
322 hc[k] = hi[j];
323 }
324 }
325
326 /* Data */
327 if (dc) {
328 for (k = 0; k < 1248; k++) {
329 j = gsm0503_interleave_mcs5[k];
330 dc[k] = di[j];
331 }
332 }
333}
334
Harald Weltec6636782017-06-12 14:59:37 +0200335/*! \brief Interleave MCS7 DL burst bits according to TS 05.03 5.1.11.1.5
336 * \param[in] hc 124 soft coded header input bits
337 * \param[in] c1 612 soft coded data input bits
338 * \param[in] c2 612 soft coded data input bits
339 * \param[out] hi 124 interleaved header output bits
340 * \param[out] di 1224 interleaved data output bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700341void gsm0503_mcs7_dl_interleave(const ubit_t *hc, const ubit_t *c1,
342 const ubit_t *c2, ubit_t *hi, ubit_t *di)
343{
344 int j, k;
345 ubit_t dc[1224];
346
347 /* Header */
348 for (k = 0; k < 124; k++) {
349 j = 31 * (k % 4) + ((17 * k) % 31);
350 hi[j] = hc[k];
351 }
352
353 memcpy(&dc[0], c1, 612);
354 memcpy(&dc[612], c2, 612);
355
356 /* Data */
357 for (k = 0; k < 1224; k++) {
358 j = 306 * (k % 4) + 3 * (44 * k % 102 + k / 4 % 2) +
359 (k + 2 - k / 408) % 3;
360 di[j] = dc[k];
361 }
362}
363
Harald Weltec6636782017-06-12 14:59:37 +0200364/*! \brief De-Interleave MCS7 DL burst bits according to TS 05.03 5.1.11.1.5
365 * \param[out] hc caller-allocated output buffer for 124 soft coded header bits
366 * \param[out] c1 caller-allocated output buffer for 612 soft coded data bits
367 * \param[out] c2 caller-allocated output buffer for 612 soft coded data bits
368 * \param[in] hi interleaved soft input header bits
369 * \param[in] di interleaved soft input data bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700370void gsm0503_mcs7_dl_deinterleave(sbit_t *hc, sbit_t *c1, sbit_t *c2,
371 const sbit_t *hi, const sbit_t *di)
372{
373 int j, k;
374 ubit_t dc[1224];
375
376 /* Header */
377 if (hc) {
378 for (k = 0; k < 124; k++) {
379 j = 31 * (k % 4) + ((17 * k) % 31);
380 hc[k] = hi[j];
381 }
382 }
383
384 /* Data */
385 if (c1 && c2) {
386 for (k = 0; k < 1224; k++) {
387 j = 306 * (k % 4) + 3 * (44 * k % 102 + k / 4 % 2) +
388 (k + 2 - k / 408) % 3;
389 dc[k] = di[j];
390 }
391
392 memcpy(c1, &dc[0], 612);
393 memcpy(c2, &dc[612], 612);
394 }
395}
396
Harald Weltec6636782017-06-12 14:59:37 +0200397/*! \brief Interleave MCS7 UL burst bits according to TS 05.03 5.1.11.2.4
398 * \param[in] hc 124 soft coded header input bits
399 * \param[in] c1 612 soft coded data input bits
400 * \param[in] c2 612 soft coded data input bits
401 * \param[out] hi 124 interleaved header output bits
402 * \param[out] di 1224 interleaved data output bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700403void gsm0503_mcs7_ul_interleave(const ubit_t *hc, const ubit_t *c1,
404 const ubit_t *c2, ubit_t *hi, ubit_t *di)
405{
406 int j, k;
407 ubit_t dc[1224];
408
409 /* Header */
410 for (k = 0; k < 160; k++) {
411 j = 40 * (k % 4) + 2 * (13 * (k / 8) % 20) + k % 8 / 4;
412 hi[j] = hc[k];
413 }
414
415 memcpy(&dc[0], c1, 612);
416 memcpy(&dc[612], c2, 612);
417
418 /* Data */
419 for (k = 0; k < 1224; k++) {
420 j = 306 * (k % 4) + 3 * (44 * k % 102 + k / 4 % 2) +
421 (k + 2 - k / 408) % 3;
422 di[j] = dc[k];
423 }
424}
425
Harald Weltec6636782017-06-12 14:59:37 +0200426/*! \brief De-Interleave MCS7 UL burst bits according to TS 05.03 5.1.11.2.4
427 * \param[out] hc caller-allocated output buffer for 160 soft coded header bits
428 * \param[out] c1 caller-allocated output buffer for 612 soft coded data bits
429 * \param[out] c2 caller-allocated output buffer for 612 soft coded data bits
430 * \param[in] hi interleaved soft input header bits
431 * \param[in] di interleaved soft input data bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700432void gsm0503_mcs7_ul_deinterleave(sbit_t *hc, sbit_t *c1, sbit_t *c2,
433 const sbit_t *hi, const sbit_t *di)
434{
435 int j, k;
436 ubit_t dc[1224];
437
438 /* Header */
439 if (hc) {
440 for (k = 0; k < 160; k++) {
441 j = 40 * (k % 4) + 2 * (13 * (k / 8) % 20) + k % 8 / 4;
442 hc[k] = hi[j];
443 }
444 }
445
446 /* Data */
447 if (c1 && c2) {
448 for (k = 0; k < 1224; k++) {
449 j = 306 * (k % 4) + 3 * (44 * k % 102 + k / 4 % 2) +
450 (k + 2 - k / 408) % 3;
451 dc[k] = di[j];
452 }
453
454 memcpy(c1, &dc[0], 612);
455 memcpy(c2, &dc[612], 612);
456 }
457}
458
Harald Weltec6636782017-06-12 14:59:37 +0200459/*! \brief Interleave MCS8 UL burst bits according to TS 05.03 5.1.12.2.4
460 * \param[in] hc 160 soft coded header input bits
461 * \param[in] c1 612 soft coded data input bits
462 * \param[in] c2 612 soft coded data input bits
463 * \param[out] hi 160 interleaved header output bits
464 * \param[out] di 1224 interleaved data output bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700465void gsm0503_mcs8_ul_interleave(const ubit_t *hc, const ubit_t *c1,
466 const ubit_t *c2, ubit_t *hi, ubit_t *di)
467{
468 int j, k;
469 ubit_t dc[1224];
470
471 /* Header */
472 for (k = 0; k < 160; k++) {
473 j = 40 * (k % 4) + 2 * (13 * (k / 8) % 20) + k % 8 / 4;
474 hi[j] = hc[k];
475 }
476
477 memcpy(&dc[0], c1, 612);
478 memcpy(&dc[612], c2, 612);
479
480 /* Data */
481 for (k = 0; k < 1224; k++) {
482 j = 306 * (2 * (k / 612) + (k % 2)) +
483 3 * (74 * k % 102 + k / 2 % 2) + (k + 2 - k / 204) % 3;
484 di[j] = dc[k];
485 }
486}
487
Harald Weltec6636782017-06-12 14:59:37 +0200488
489/*! \brief De-Interleave MCS8 UL burst bits according to TS 05.03 5.1.12.2.4
490 * \param[out] hc caller-allocated output buffer for 160 soft coded header bits
491 * \param[out] c1 caller-allocated output buffer for 612 soft coded data bits
492 * \param[out] c2 caller-allocated output buffer for 612 soft coded data bits
493 * \param[in] hi interleaved soft input header bits
494 * \param[in] di interleaved soft input data bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700495void gsm0503_mcs8_ul_deinterleave(sbit_t *hc, sbit_t *c1, sbit_t *c2,
496 const sbit_t *hi, const sbit_t *di)
497{
498 int j, k;
499 ubit_t dc[1224];
500
501 /* Header */
502 if (hc) {
503 for (k = 0; k < 160; k++) {
504 j = 40 * (k % 4) + 2 * (13 * (k / 8) % 20) + k % 8 / 4;
505 hc[k] = hi[j];
506 }
507 }
508
509 /* Data */
510 if (c1 && c2) {
511 for (k = 0; k < 1224; k++) {
512 j = 306 * (2 * (k / 612) + (k % 2)) +
513 3 * (74 * k % 102 + k / 2 % 2) + (k + 2 - k / 204) % 3;
514 dc[k] = di[j];
515 }
516
517 memcpy(c1, &dc[0], 612);
518 memcpy(c2, &dc[612], 612);
519 }
520}
521
Harald Weltec6636782017-06-12 14:59:37 +0200522/*! \brief Interleave MCS8 DL burst bits according to TS 05.03 5.1.12.1.5
523 * \param[in] hc 124 soft coded header input bits
524 * \param[in] c1 612 soft coded data input bits
525 * \param[in] c2 612 soft coded data input bits
526 * \param[out] hi 124 interleaved header output bits
527 * \param[out] di 1224 interleaved data output bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700528void gsm0503_mcs8_dl_interleave(const ubit_t *hc, const ubit_t *c1,
529 const ubit_t *c2, ubit_t *hi, ubit_t *di)
530{
531 int j, k;
532 ubit_t dc[1224];
533
534 /* Header */
535 for (k = 0; k < 124; k++) {
536 j = 31 * (k % 4) + ((17 * k) % 31);
537 hi[j] = hc[k];
538 }
539
540 memcpy(&dc[0], c1, 612);
541 memcpy(&dc[612], c2, 612);
542
543 /* Data */
544 for (k = 0; k < 1224; k++) {
545 j = 306 * (2 * (k / 612) + (k % 2)) +
546 3 * (74 * k % 102 + k / 2 % 2) + (k + 2 - k / 204) % 3;
547 di[j] = dc[k];
548 }
549}
550
Harald Weltec6636782017-06-12 14:59:37 +0200551/*! \brief De-Interleave MCS8 DL burst bits according to TS 05.03 5.1.12.1.5
552 * \param[out] hc caller-allocated output buffer for 124 soft coded header bits
553 * \param[out] c1 caller-allocated output buffer for 612 soft coded data bits
554 * \param[out] c2 caller-allocated output buffer for 612 soft coded data bits
555 * \param[in] hi interleaved soft input header bits
556 * \param[in] di interleaved soft input data bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700557void gsm0503_mcs8_dl_deinterleave(sbit_t *hc, sbit_t *c1, sbit_t *c2,
558 const sbit_t *hi, const sbit_t *di)
559{
560 int j, k;
561 ubit_t dc[1224];
562
563 /* Header */
564 if (hc) {
565 for (k = 0; k < 124; k++) {
566 j = 31 * (k % 4) + ((17 * k) % 31);
567 hc[k] = hi[j];
568 }
569 }
570
571 /* Data */
572 if (c1 && c2) {
573 for (k = 0; k < 1224; k++) {
574 j = 306 * (2 * (k / 612) + (k % 2)) +
575 3 * (74 * k % 102 + k / 2 % 2) + (k + 2 - k / 204) % 3;
576 dc[k] = di[j];
577 }
578
579 memcpy(c1, &dc[0], 612);
580 memcpy(c2, &dc[612], 612);
581 }
582}
583
584/*
585 * GSM TCH FR/EFR/AFS interleaving and burst mapping
586 *
587 * Interleaving:
588 *
589 * Given 456 coded input bits, form 8 blocks of 114 bits,
590 * where even bits of the first 4 blocks and odd bits of the last 4 blocks
591 * are used:
592 *
593 * i(B, j) = c(n, k) k = 0, ..., 455
594 * n = 0, ..., N, N + 1, ...
595 * B = B_0 + 4n + (k mod 8)
596 * j = 2(49k mod 57) + ((k mod 8) div 4)
597 *
598 * Mapping on Burst:
599 *
600 * e(B, j) = i(B, j)
601 * e(B, 59 + j) = i(B, 57 + j) j = 0, ..., 56
602 * e(B, 57) = h_l(B)
603 * e(B, 58) = h_n(B)
604 *
605 * Where hl(B) and hn(B) are bits in burst B indicating flags.
606 */
607
Harald Weltec6636782017-06-12 14:59:37 +0200608/*! \brief GSM TCH FR/EFR/AFS De-Interleaving and burst mapping
609 * \param[out] cB caller-allocated buffer for 456 unpacked output bits
610 * \param[in] iB 456 unpacked interleaved input bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700611void gsm0503_tch_fr_deinterleave(sbit_t *cB, sbit_t *iB)
612{
613 int j, k, B;
614
615 for (k = 0; k < 456; k++) {
616 B = k & 7;
617 j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
618 cB[k] = iB[B * 114 + j];
619 }
620}
621
Harald Weltec6636782017-06-12 14:59:37 +0200622/*! \brief GSM TCH FR/EFR/AFS Interleaving and burst mapping
623 * \param[in] cB caller-allocated buffer for 456 unpacked input bits
624 * \param[out] iB 456 unpacked interleaved output bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700625void gsm0503_tch_fr_interleave(ubit_t *cB, ubit_t *iB)
626{
627 int j, k, B;
628
629 for (k = 0; k < 456; k++) {
630 B = k & 7;
631 j = 2 * ((49 * k) % 57) + ((k & 7) >> 2);
632 iB[B * 114 + j] = cB[k];
633 }
634}
635
636/*
637 * GSM TCH HR/AHS interleaving and burst mapping
638 *
639 * Interleaving:
640 *
641 * Given 288 coded input bits, form 4 blocks of 114 bits,
642 * where even bits of the first 2 blocks and odd bits of the last 2 blocks
643 * are used:
644 *
645 * i(B, j) = c(n, k) k = 0, ..., 227
646 * n = 0, ..., N, N + 1, ...
647 * B = B_0 + 2n + b
648 * j, b = table[k];
649 *
650 * Mapping on Burst:
651 *
652 * e(B, j) = i(B, j)
653 * e(B, 59 + j) = i(B, 57 + j) j = 0, ..., 56
654 * e(B, 57) = h_l(B)
655 * e(B, 58) = h_n(B)
656 *
657 * Where hl(B) and hn(B) are bits in burst B indicating flags.
658 */
659
Harald Weltec6636782017-06-12 14:59:37 +0200660/*! \brief GSM TCH HR/AHS De-Interleaving and burst mapping
661 * \param[out] cB caller-allocated buffer for 228 unpacked output bits
662 * \param[in] iB 228 unpacked interleaved input bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700663void gsm0503_tch_hr_deinterleave(sbit_t *cB, sbit_t *iB)
664{
665 int j, k, B;
666
667 for (k = 0; k < 228; k++) {
668 B = gsm0503_tch_hr_interleaving[k][1];
669 j = gsm0503_tch_hr_interleaving[k][0];
670 cB[k] = iB[B * 114 + j];
671 }
672}
673
Harald Weltec6636782017-06-12 14:59:37 +0200674/*! \brief GSM TCH HR/AHS Interleaving and burst mapping
675 * \param[in] cB caller-allocated buffer for 228 unpacked input bits
676 * \param[out] iB 228 unpacked interleaved output bits */
Vadim Yanitskiy3262f822016-09-23 01:48:59 +0700677void gsm0503_tch_hr_interleave(ubit_t *cB, ubit_t *iB)
678{
679 int j, k, B;
680
681 for (k = 0; k < 228; k++) {
682 B = gsm0503_tch_hr_interleaving[k][1];
683 j = gsm0503_tch_hr_interleaving[k][0];
684 iB[B * 114 + j] = cB[k];
685 }
686}
Harald Weltec6636782017-06-12 14:59:37 +0200687
688/*! @} */