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