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