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