blob: 04acfd070125275b24bdbbf5712c01c34af22695 [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.
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070018 */
19
20#include <stdint.h>
21#include <string.h>
22
23#include <osmocom/core/bits.h>
24#include <osmocom/coding/gsm0503_mapping.h>
25
Harald Weltec6636782017-06-12 14:59:37 +020026/*! \addtogroup mapping
27 * @{
28 *
Neels Hofmeyr87e45502017-06-20 00:17:59 +020029 * GSM TS 05.03 burst mapping
Harald Weltec6636782017-06-12 14:59:37 +020030 *
31 * This module contains burst mapping routines as specified in 3GPP TS
32 * 05.03 / 45.003.
Neels Hofmeyr17518fe2017-06-20 04:35:06 +020033 *
34 * \file gsm0503_mapping.c */
Harald Weltec6636782017-06-12 14:59:37 +020035
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070036void gsm0503_xcch_burst_unmap(sbit_t *iB, const sbit_t *eB,
37 sbit_t *hl, sbit_t *hn)
38{
39 memcpy(iB, eB, 57);
40 memcpy(iB + 57, eB + 59, 57);
41
42 if (hl)
43 *hl = eB[57];
44
45 if (hn)
46 *hn = eB[58];
47}
48
Harald Welteb9946d32017-06-12 09:40:16 +020049void gsm0503_xcch_burst_map(const ubit_t *iB, ubit_t *eB, const ubit_t *hl,
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070050 const ubit_t *hn)
51{
52 memcpy(eB, iB, 57);
53 memcpy(eB + 59, iB + 57, 57);
54
55 if (hl)
56 eB[57] = *hl;
57 if (hn)
58 eB[58] = *hn;
59}
60
Harald Welteb9946d32017-06-12 09:40:16 +020061void gsm0503_tch_burst_unmap(sbit_t *iB, const sbit_t *eB, sbit_t *h, int odd)
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070062{
63 int i;
64
65 /* brainfuck: only copy even or odd bits */
66 if (iB) {
67 for (i = odd; i < 57; i += 2)
68 iB[i] = eB[i];
69 for (i = 58 - odd; i < 114; i += 2)
70 iB[i] = eB[i + 2];
71 }
72
73 if (h) {
74 if (!odd)
75 *h = eB[58];
76 else
77 *h = eB[57];
78 }
79}
80
Harald Welteb9946d32017-06-12 09:40:16 +020081void gsm0503_tch_burst_map(const ubit_t *iB, ubit_t *eB, const ubit_t *h, int odd)
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070082{
83 int i;
84
85 /* brainfuck: only copy even or odd bits */
86 if (eB) {
87 for (i = odd; i < 57; i += 2)
88 eB[i] = iB[i];
89 for (i = 58 - odd; i < 114; i += 2)
90 eB[i + 2] = iB[i];
Maxe1a511b2017-12-28 17:06:30 +010091 if (h)
92 eB[odd ? 57 : 58] = *h;
Vadim Yanitskiy3262f822016-09-23 01:48:59 +070093 }
94}
95
96void gsm0503_mcs5_dl_burst_map(const ubit_t *di, ubit_t *eB,
97 const ubit_t *hi, const ubit_t *up, int B)
98{
99 int j;
100 int q[8] = { 0, 0, 0, 0, 0, 0, 0, 0, };
101
102 for (j = 0; j < 156; j++)
103 eB[j] = di[312 * B + j];
104 for (j = 156; j < 168; j++)
105 eB[j] = hi[25 * B + j - 156];
106 for (j = 168; j < 174; j++)
107 eB[j] = up[9 * B + j - 168];
108 for (j = 174; j < 176; j++)
109 eB[j] = q[2 * B + j - 174];
110 for (j = 176; j < 179; j++)
111 eB[j] = up[9 * B + j - 170];
112 for (j = 179; j < 192; j++)
113 eB[j] = hi[25 * B + j - 167];
114 for (j = 192; j < 348; j++)
115 eB[j] = di[312 * B + j - 36];
116}
117
118void gsm0503_mcs5_dl_burst_unmap(sbit_t *di, const sbit_t *eB,
119 sbit_t *hi, sbit_t *up, int B)
120{
121 int j;
122
123 for (j = 0; j < 156; j++)
124 di[312 * B + j] = eB[j];
125 for (j = 156; j < 168; j++)
126 hi[25 * B + j - 156] = eB[j];
127 for (j = 168; j < 174; j++)
128 up[9 * B + j - 168] = eB[j];
129
130 for (j = 176; j < 179; j++)
131 up[9 * B + j - 170] = eB[j];
132 for (j = 179; j < 192; j++)
133 hi[25 * B + j - 167] = eB[j];
134 for (j = 192; j < 348; j++)
135 di[312 * B + j - 36] = eB[j];
136}
137
138void gsm0503_mcs5_ul_burst_map(const ubit_t *di, ubit_t *eB,
139 const ubit_t *hi, int B)
140{
141 int j;
142
143 for (j = 0; j < 156; j++)
144 eB[j] = di[312 * B + j];
145 for (j = 156; j < 174; j++)
146 eB[j] = hi[34 * B + j - 156];
147 for (j = 174; j < 176; j++)
148 eB[j] = 0;
149 for (j = 176; j < 192; j++)
150 eB[j] = hi[34 * B + j - 158];
151 for (j = 192; j < 348; j++)
152 eB[j] = di[312 * B + j - 36];
153}
154
155void gsm0503_mcs5_ul_burst_unmap(sbit_t *di, const sbit_t *eB,
156 sbit_t *hi, int B)
157{
158 int j;
159
160 for (j = 0; j < 156; j++)
161 di[312 * B + j] = eB[j];
162 for (j = 156; j < 174; j++)
163 hi[34 * B + j - 156] = eB[j];
164 for (j = 176; j < 192; j++)
165 hi[34 * B + j - 158] = eB[j];
166 for (j = 192; j < 348; j++)
167 di[312 * B + j - 36] = eB[j];
168}
169
170void gsm0503_mcs7_dl_burst_map(const ubit_t *di, ubit_t *eB,
171 const ubit_t *hi, const ubit_t *up, int B)
172{
173 int j;
174 int q[8] = { 1, 1, 1, 0, 0, 1, 1, 1, };
175
176 for (j = 0; j < 153; j++)
177 eB[j] = di[306 * B + j];
178 for (j = 153; j < 168; j++)
179 eB[j] = hi[31 * B + j - 153];
180 for (j = 168; j < 174; j++)
181 eB[j] = up[9 * B + j - 168];
182 for (j = 174; j < 176; j++)
183 eB[j] = q[2 * B + j - 174];
184 for (j = 176; j < 179; j++)
185 eB[j] = up[9 * B + j - 170];
186 for (j = 179; j < 195; j++)
187 eB[j] = hi[31 * B + j - 164];
188 for (j = 195; j < 348; j++)
189 eB[j] = di[306 * B + j - 42];
190}
191
192void gsm0503_mcs7_dl_burst_unmap(sbit_t *di, const sbit_t *eB,
193 sbit_t *hi, sbit_t *up, int B)
194{
195 int j;
196
197 for (j = 0; j < 153; j++)
198 di[306 * B + j] = eB[j];
199 for (j = 153; j < 168; j++)
200 hi[31 * B + j - 153] = eB[j];
201 for (j = 168; j < 174; j++)
202 up[9 * B + j - 168] = eB[j];
203
204 for (j = 176; j < 179; j++)
205 up[9 * B + j - 170] = eB[j];
206 for (j = 179; j < 195; j++)
207 hi[31 * B + j - 164] = eB[j];
208 for (j = 195; j < 348; j++)
209 di[306 * B + j - 42] = eB[j];
210}
211
212void gsm0503_mcs7_ul_burst_map(const ubit_t *di, ubit_t *eB,
213 const ubit_t *hi, int B)
214{
215 int j;
216 int q[8] = { 1, 1, 1, 0, 0, 1, 1, 1, };
217
218 for (j = 0; j < 153; j++)
219 eB[j] = di[306 * B + j];
220 for (j = 153; j < 174; j++)
221 eB[j] = hi[40 * B + j - 153];
222 for (j = 174; j < 176; j++)
223 eB[j] = q[2 * B + j - 174];
224 for (j = 176; j < 195; j++)
225 eB[j] = hi[40 * B + j - 155];
226 for (j = 195; j < 348; j++)
227 eB[j] = di[306 * B + j - 42];
228}
229
230void gsm0503_mcs7_ul_burst_unmap(sbit_t *di, const sbit_t *eB,
231 sbit_t *hi, int B)
232{
233 int j;
234
235 for (j = 0; j < 153; j++)
236 di[306 * B + j] = eB[j];
237 for (j = 153; j < 174; j++)
238 hi[40 * B + j - 153] = eB[j];
239
240 for (j = 176; j < 195; j++)
241 hi[40 * B + j - 155] = eB[j];
242 for (j = 195; j < 348; j++)
243 di[306 * B + j - 42] = eB[j];
244}
245
246void gsm0503_mcs5_burst_swap(sbit_t *eB)
247{
248 sbit_t t[14];
249
250 t[0] = eB[155];
251 t[1] = eB[158];
252 t[2] = eB[161];
253 t[3] = eB[164];
254 t[4] = eB[167];
255 t[5] = eB[170];
256 t[6] = eB[173];
257 t[7] = eB[195];
258 t[8] = eB[196];
259 t[9] = eB[198];
260 t[10] = eB[199];
261 t[11] = eB[201];
262 t[12] = eB[202];
263 t[13] = eB[204];
264
265 eB[155] = eB[142];
266 eB[158] = eB[144];
267 eB[161] = eB[145];
268 eB[164] = eB[147];
269 eB[167] = eB[148];
270 eB[170] = eB[150];
271 eB[173] = eB[151];
272 eB[195] = eB[176];
273 eB[196] = eB[179];
274 eB[198] = eB[182];
275 eB[199] = eB[185];
276 eB[201] = eB[188];
277 eB[202] = eB[191];
278 eB[204] = eB[194];
279
280 eB[142] = t[0];
281 eB[144] = t[1];
282 eB[145] = t[2];
283 eB[147] = t[3];
284 eB[148] = t[4];
285 eB[150] = t[5];
286 eB[151] = t[6];
287 eB[176] = t[7];
288 eB[179] = t[8];
289 eB[182] = t[9];
290 eB[185] = t[10];
291 eB[188] = t[11];
292 eB[191] = t[12];
293 eB[194] = t[13];
294}
Harald Weltec6636782017-06-12 14:59:37 +0200295
296/*! @} */