blob: 1e37fce04110a3a2a626e2392d7dc4d7b9e333e5 [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>
4 *
5 * All Rights Reserved
6 *
Harald Weltee08da972017-11-13 01:00:26 +09007 * SPDX-License-Identifier: GPL-2.0+
8 *
Vadim Yanitskiy3262f822016-09-23 01:48:59 +07009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24#include <stdint.h>
25#include <string.h>
26
27#include <osmocom/core/bits.h>
28#include <osmocom/coding/gsm0503_mapping.h>
29
Harald Weltec6636782017-06-12 14:59:37 +020030/*! \addtogroup mapping
31 * @{
32 *
Neels Hofmeyr87e45502017-06-20 00:17:59 +020033 * GSM TS 05.03 burst mapping
Harald Weltec6636782017-06-12 14:59:37 +020034 *
35 * This module contains burst mapping routines as specified in 3GPP TS
36 * 05.03 / 45.003.
Neels Hofmeyr17518fe2017-06-20 04:35:06 +020037 *
38 * \file gsm0503_mapping.c */
Harald Weltec6636782017-06-12 14:59:37 +020039
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070040void gsm0503_xcch_burst_unmap(sbit_t *iB, const sbit_t *eB,
41 sbit_t *hl, sbit_t *hn)
42{
43 memcpy(iB, eB, 57);
44 memcpy(iB + 57, eB + 59, 57);
45
46 if (hl)
47 *hl = eB[57];
48
49 if (hn)
50 *hn = eB[58];
51}
52
Harald Welteb9946d32017-06-12 09:40:16 +020053void gsm0503_xcch_burst_map(const ubit_t *iB, ubit_t *eB, const ubit_t *hl,
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070054 const ubit_t *hn)
55{
56 memcpy(eB, iB, 57);
57 memcpy(eB + 59, iB + 57, 57);
58
59 if (hl)
60 eB[57] = *hl;
61 if (hn)
62 eB[58] = *hn;
63}
64
Harald Welteb9946d32017-06-12 09:40:16 +020065void gsm0503_tch_burst_unmap(sbit_t *iB, const sbit_t *eB, sbit_t *h, int odd)
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070066{
67 int i;
68
69 /* brainfuck: only copy even or odd bits */
70 if (iB) {
71 for (i = odd; i < 57; i += 2)
72 iB[i] = eB[i];
73 for (i = 58 - odd; i < 114; i += 2)
74 iB[i] = eB[i + 2];
75 }
76
77 if (h) {
78 if (!odd)
79 *h = eB[58];
80 else
81 *h = eB[57];
82 }
83}
84
Harald Welteb9946d32017-06-12 09:40:16 +020085void gsm0503_tch_burst_map(const ubit_t *iB, ubit_t *eB, const ubit_t *h, int odd)
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070086{
87 int i;
88
89 /* brainfuck: only copy even or odd bits */
90 if (eB) {
91 for (i = odd; i < 57; i += 2)
92 eB[i] = iB[i];
93 for (i = 58 - odd; i < 114; i += 2)
94 eB[i + 2] = iB[i];
95 }
96
97 if (h) {
98 if (!odd)
99 eB[58] = *h;
100 else
101 eB[57] = *h;
102 }
103}
104
105void gsm0503_mcs5_dl_burst_map(const ubit_t *di, ubit_t *eB,
106 const ubit_t *hi, const ubit_t *up, int B)
107{
108 int j;
109 int q[8] = { 0, 0, 0, 0, 0, 0, 0, 0, };
110
111 for (j = 0; j < 156; j++)
112 eB[j] = di[312 * B + j];
113 for (j = 156; j < 168; j++)
114 eB[j] = hi[25 * B + j - 156];
115 for (j = 168; j < 174; j++)
116 eB[j] = up[9 * B + j - 168];
117 for (j = 174; j < 176; j++)
118 eB[j] = q[2 * B + j - 174];
119 for (j = 176; j < 179; j++)
120 eB[j] = up[9 * B + j - 170];
121 for (j = 179; j < 192; j++)
122 eB[j] = hi[25 * B + j - 167];
123 for (j = 192; j < 348; j++)
124 eB[j] = di[312 * B + j - 36];
125}
126
127void gsm0503_mcs5_dl_burst_unmap(sbit_t *di, const sbit_t *eB,
128 sbit_t *hi, sbit_t *up, int B)
129{
130 int j;
131
132 for (j = 0; j < 156; j++)
133 di[312 * B + j] = eB[j];
134 for (j = 156; j < 168; j++)
135 hi[25 * B + j - 156] = eB[j];
136 for (j = 168; j < 174; j++)
137 up[9 * B + j - 168] = eB[j];
138
139 for (j = 176; j < 179; j++)
140 up[9 * B + j - 170] = eB[j];
141 for (j = 179; j < 192; j++)
142 hi[25 * B + j - 167] = eB[j];
143 for (j = 192; j < 348; j++)
144 di[312 * B + j - 36] = eB[j];
145}
146
147void gsm0503_mcs5_ul_burst_map(const ubit_t *di, ubit_t *eB,
148 const ubit_t *hi, int B)
149{
150 int j;
151
152 for (j = 0; j < 156; j++)
153 eB[j] = di[312 * B + j];
154 for (j = 156; j < 174; j++)
155 eB[j] = hi[34 * B + j - 156];
156 for (j = 174; j < 176; j++)
157 eB[j] = 0;
158 for (j = 176; j < 192; j++)
159 eB[j] = hi[34 * B + j - 158];
160 for (j = 192; j < 348; j++)
161 eB[j] = di[312 * B + j - 36];
162}
163
164void gsm0503_mcs5_ul_burst_unmap(sbit_t *di, const sbit_t *eB,
165 sbit_t *hi, int B)
166{
167 int j;
168
169 for (j = 0; j < 156; j++)
170 di[312 * B + j] = eB[j];
171 for (j = 156; j < 174; j++)
172 hi[34 * B + j - 156] = eB[j];
173 for (j = 176; j < 192; j++)
174 hi[34 * B + j - 158] = eB[j];
175 for (j = 192; j < 348; j++)
176 di[312 * B + j - 36] = eB[j];
177}
178
179void gsm0503_mcs7_dl_burst_map(const ubit_t *di, ubit_t *eB,
180 const ubit_t *hi, const ubit_t *up, int B)
181{
182 int j;
183 int q[8] = { 1, 1, 1, 0, 0, 1, 1, 1, };
184
185 for (j = 0; j < 153; j++)
186 eB[j] = di[306 * B + j];
187 for (j = 153; j < 168; j++)
188 eB[j] = hi[31 * B + j - 153];
189 for (j = 168; j < 174; j++)
190 eB[j] = up[9 * B + j - 168];
191 for (j = 174; j < 176; j++)
192 eB[j] = q[2 * B + j - 174];
193 for (j = 176; j < 179; j++)
194 eB[j] = up[9 * B + j - 170];
195 for (j = 179; j < 195; j++)
196 eB[j] = hi[31 * B + j - 164];
197 for (j = 195; j < 348; j++)
198 eB[j] = di[306 * B + j - 42];
199}
200
201void gsm0503_mcs7_dl_burst_unmap(sbit_t *di, const sbit_t *eB,
202 sbit_t *hi, sbit_t *up, int B)
203{
204 int j;
205
206 for (j = 0; j < 153; j++)
207 di[306 * B + j] = eB[j];
208 for (j = 153; j < 168; j++)
209 hi[31 * B + j - 153] = eB[j];
210 for (j = 168; j < 174; j++)
211 up[9 * B + j - 168] = eB[j];
212
213 for (j = 176; j < 179; j++)
214 up[9 * B + j - 170] = eB[j];
215 for (j = 179; j < 195; j++)
216 hi[31 * B + j - 164] = eB[j];
217 for (j = 195; j < 348; j++)
218 di[306 * B + j - 42] = eB[j];
219}
220
221void gsm0503_mcs7_ul_burst_map(const ubit_t *di, ubit_t *eB,
222 const ubit_t *hi, int B)
223{
224 int j;
225 int q[8] = { 1, 1, 1, 0, 0, 1, 1, 1, };
226
227 for (j = 0; j < 153; j++)
228 eB[j] = di[306 * B + j];
229 for (j = 153; j < 174; j++)
230 eB[j] = hi[40 * B + j - 153];
231 for (j = 174; j < 176; j++)
232 eB[j] = q[2 * B + j - 174];
233 for (j = 176; j < 195; j++)
234 eB[j] = hi[40 * B + j - 155];
235 for (j = 195; j < 348; j++)
236 eB[j] = di[306 * B + j - 42];
237}
238
239void gsm0503_mcs7_ul_burst_unmap(sbit_t *di, const sbit_t *eB,
240 sbit_t *hi, int B)
241{
242 int j;
243
244 for (j = 0; j < 153; j++)
245 di[306 * B + j] = eB[j];
246 for (j = 153; j < 174; j++)
247 hi[40 * B + j - 153] = eB[j];
248
249 for (j = 176; j < 195; j++)
250 hi[40 * B + j - 155] = eB[j];
251 for (j = 195; j < 348; j++)
252 di[306 * B + j - 42] = eB[j];
253}
254
255void gsm0503_mcs5_burst_swap(sbit_t *eB)
256{
257 sbit_t t[14];
258
259 t[0] = eB[155];
260 t[1] = eB[158];
261 t[2] = eB[161];
262 t[3] = eB[164];
263 t[4] = eB[167];
264 t[5] = eB[170];
265 t[6] = eB[173];
266 t[7] = eB[195];
267 t[8] = eB[196];
268 t[9] = eB[198];
269 t[10] = eB[199];
270 t[11] = eB[201];
271 t[12] = eB[202];
272 t[13] = eB[204];
273
274 eB[155] = eB[142];
275 eB[158] = eB[144];
276 eB[161] = eB[145];
277 eB[164] = eB[147];
278 eB[167] = eB[148];
279 eB[170] = eB[150];
280 eB[173] = eB[151];
281 eB[195] = eB[176];
282 eB[196] = eB[179];
283 eB[198] = eB[182];
284 eB[199] = eB[185];
285 eB[201] = eB[188];
286 eB[202] = eB[191];
287 eB[204] = eB[194];
288
289 eB[142] = t[0];
290 eB[144] = t[1];
291 eB[145] = t[2];
292 eB[147] = t[3];
293 eB[148] = t[4];
294 eB[150] = t[5];
295 eB[151] = t[6];
296 eB[176] = t[7];
297 eB[179] = t[8];
298 eB[182] = t[9];
299 eB[185] = t[10];
300 eB[188] = t[11];
301 eB[191] = t[12];
302 eB[194] = t[13];
303}
Harald Weltec6636782017-06-12 14:59:37 +0200304
305/*! @} */