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