blob: 2a9a6781271ae5a2eb862f33b966121da7cfac50 [file] [log] [blame]
Holger Hans Peter Freytherbc5dcb12012-10-11 08:25:36 +02001/* Subchan Demux syncing test */
2
3/* (C) 2012 by Holger Hans Peter Freyther
Tobias Engelbcb95312012-10-12 12:12:07 +02004 * (C) 2012 by Tobias Engel
Holger Hans Peter Freytherbc5dcb12012-10-11 08:25:36 +02005 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#include <osmocom/abis/subchan_demux.h>
24#include <osmocom/core/utils.h>
25
26#include <stdio.h>
27#include <string.h>
28
Tobias Engelbcb95312012-10-12 12:12:07 +020029static uint8_t test_frames[] =
30{
31 /* (transmission order is from left to right) */
32 /* Frame 1 */
33 0, 0, 0, 0, 0, 0, 0, 0, /* sync header: 16 bits zero... */
34 0, 0, 0, 0, 0, 0, 0, 0,
35 1, 0, 1, 0, 0, 0, 1, 1, /* ... and 1 bit one (on the left) */
36 1, 1, 1, 1, 1, 1, 1, 1,
37 1, 1, 1, 1, 1, 1, 1, 1,
38 1, 1, 1, 1, 1, 1, 1, 1,
39 1, 1, 1, 1, 1, 1, 1, 1,
40 1, 1, 1, 1, 1, 1, 1, 1,
41 1, 0, 1, 1, 1, 1, 1, 1,
42 1, 1, 1, 1, 1, 1, 1, 1,
43 1, 1, 1, 1, 1, 1, 1, 1,
44 1, 1, 1, 1, 1, 1, 1, 1,
45 1, 1, 1, 1, 1, 1, 1, 1,
46 1, 1, 1, 1, 1, 1, 1, 1,
47 1, 1, 1, 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, 1, 1, 1, 1, 0,
88 1, 1, 1, 1, 1, 1, 1, 0,
89 1, 1, 1, 1, 1, 1, 1, 0,
90 1, 1, 1, 1, 1, 1, 1, 0,
91 1, 0, 1, 1, 1, 1, 1, 1,
92 1, 1, 1, 1, 1, 1, 1, 0,
93 1, 1, 1, 1, 1, 1, 1, 0,
94 1, 1, 1, 1, 1, 1, 1, 0,
95 1, 1, 1, 1, 1, 1, 1, 0,
96 1, 1, 1, 1, 1, 1, 1, 0,
97 1, 1, 1, 1, 1, 1, 1, 0,
98 1, 1, 1, 1, 1, 1, 1, 0,
99 1, 1, 1, 1, 1, 1, 1, 0,
100 1, 0, 1, 1, 1, 1, 1, 1,
101 1, 1, 1, 1, 1, 1, 1, 0,
102 1, 1, 1, 1, 1, 1, 1, 0,
103 1, 1, 1, 1, 1, 1, 1, 0,
104 1, 1, 1, 1, 1, 1, 1, 0,
105 1, 1, 1, 1, 1, 1, 1, 0,
106 1, 1, 1, 1, 1, 1, 1, 0,
107 1, 1, 1, 1, 1, 1, 1, 0,
108 1, 1, 1, 1, 1, 1, 1, 0,
109 1, 0, 1, 1, 1, 1, 1, 1,
110 1, 1, 1, 1, 1, 1, 1, 0,
111 1, 1, 1, 1, 1, 1, 1, 0,
112 1, 1, 1, 1, 1, 1, 1, 0,
113 1, 1, 1, 1, 1, 1, 1, 0, /* <== This zero-bit could be mistaken for
114 being the start of the sync header if there
115 is no check for the following one bit */
116 /* Frame 3 */
117 0, 0, 0, 0, 0, 0, 0, 0,
118 0, 0, 0, 0, 0, 0, 0, 0,
119 1, 0, 1, 0, 0, 0, 1, 1,
120 1, 1, 1, 1, 1, 1, 1, 1,
121 1, 1, 1, 1, 1, 1, 1, 0,
122 1, 1, 1, 1, 1, 1, 1, 0,
123 1, 1, 1, 1, 1, 1, 1, 0,
124 1, 1, 1, 1, 1, 1, 1, 0,
125 1, 0, 1, 1, 1, 1, 1, 0,
126 1, 1, 1, 1, 1, 1, 1, 0,
127 1, 1, 1, 1, 1,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1, 1, 1, 0,
168 1, 1, 1, 1, 1, 1, 1, 0,
169 1, 1, 1, 1, 1, 1, 1, 0,
170 1, 1, 1, 1, 1, 1, 1, 0,
171 1, 1, 1, 1, 1, 1, 1, 0,
172 1, 1, 1, 1, 1, 1, 1, 0,
173 1, 1, 1, 1, 1, 1, 1, 0,
174 1, 1, 1, 1, 1, 1, 1, 0,
175 1, 0, 1, 1, 1, 1, 1, 1,
176 1, 1, 1, 1, 1, 1, 1, 0,
177 1, 1, 1, 1, 1, 1, 1, 0,
178 1, 1, 1, 1, 1, 1, 1, 0,
179 1, 1, 1, 1, 1, 1, 1, 0,
180 1, 1, 1, 1, 1, 1, 1, 0,
181 1, 1, 1, 1, 1, 1, 1, 0,
182 1, 1, 1, 1, 1, 1, 1, 0,
183 1, 1, 1, 1, 1, 1, 1, 0,
184 1, 0, 1, 1, 1, 1, 1, 1,
185 1, 1, 1, 1, 1, 1, 1, 0,
186 1, 1, 1, 1, 1, 1, 1, 0,
187 1, 1, 1, 1, 1, 1, 1, 0,
188 1, 1, 1, 1, 1, 1, 1, 0,
189 1, 1, 1, 1, 1, 1, 1, 0,
190 1, 1, 1, 1, 1, 1, 1, 0,
191 1, 1, 1, 1, 1, 1, 1, 0,
192 1, 1, 1, 1, 1, 1, 1, 0,
193 1, 0, 1, 1, 1, 1, 1, 1,
194 1, 1, 1, 1, 1, 1, 1, 0,
195 1, 1, 1, 1, 1, 1, 1, 0,
196 1, 1, 1, 1, 1, 1, 1, 0,
197 1, 1, 1, 1, 1, 1, 1, 0,
198};
199
200
201
Holger Hans Peter Freytherbc5dcb12012-10-11 08:25:36 +0200202static int data_cb(struct subch_demux *demux, int ch, uint8_t *data, int len, void *p)
203{
204 printf("DATA_CB Channel(%d): %s\n",
205 ch, osmo_hexdump(data, len));
206 return 0;
207}
208
209static void test_csd(void)
210{
Tobias Engelbcb95312012-10-12 12:12:07 +0200211 int i;
212 uint8_t muxbyte;
Holger Hans Peter Freytherbc5dcb12012-10-11 08:25:36 +0200213 struct subch_demux demux;
214 memset(&demux, 0, sizeof(demux));
215 subch_demux_init(&demux);
216
Tobias Engelbcb95312012-10-12 12:12:07 +0200217 demux.chan_activ = 1;
Holger Hans Peter Freytherbc5dcb12012-10-11 08:25:36 +0200218 demux.out_cb = data_cb;
219
220 /* Push data into the demuxer and see what happens. */
221 printf("Testing the csd sync.\n");
222
Tobias Engelbcb95312012-10-12 12:12:07 +0200223 for(i = 0; i < sizeof(test_frames); i += 2) {
224
225 muxbyte = 0;
226 muxbyte |= test_frames[i];
227 muxbyte |= (test_frames[i+1] << 1);
228
229 subch_demux_in(&demux, &muxbyte, 1);
230 }
231
Holger Hans Peter Freytherbc5dcb12012-10-11 08:25:36 +0200232}
233
234int main(int argc, char **argv)
235{
236 printf("Testing the subchannel demux.\n");
237
238 /* run the tests */
239 test_csd();
240
241 printf("No crashes.\n");
242 return 0;
243}