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