blob: 0dd9e8469ac68ab46cc5335f41222d790ab11161 [file] [log] [blame]
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +01001/*
2 * (C) 2012 by Holger Hans Peter Freyther
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20
21#include <osmocom/gsm/gsm0808.h>
Philipp Maier22401432017-03-24 17:59:26 +010022#include <osmocom/gsm/gsm0808_utils.h>
23#include <osmocom/gsm/protocol/gsm_08_08.h>
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010024
25#include <stdio.h>
26#include <stdlib.h>
Philipp Maier22401432017-03-24 17:59:26 +010027#include <sys/socket.h>
28#include <netinet/in.h>
29#include <arpa/inet.h>
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010030
31#define VERIFY(msg, data, len) \
32 if (msgb_l3len(msg) != len) { \
33 printf("%s:%d Length don't match: %d vs. %d. %s\n", \
Holger Hans Peter Freytherfdb46672015-11-09 16:32:43 +000034 __func__, __LINE__, msgb_l3len(msg), (int) len, \
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010035 osmo_hexdump(msg->l3h, msgb_l3len(msg))); \
36 abort(); \
37 } else if (memcmp(msg->l3h, data, len) != 0) { \
38 printf("%s:%d didn't match: got: %s\n", \
39 __func__, __LINE__, \
40 osmo_hexdump(msg->l3h, msgb_l3len(msg))); \
41 abort(); \
42 }
43
Philipp Maierfa896ab2017-03-27 16:55:32 +020044/* Setup a fake codec list for testing */
45static void setup_codec_list(struct gsm0808_speech_codec_list *scl)
46{
47 memset(scl, 0, sizeof(*scl));
48
49 scl->codec[0].pi = true;
50 scl->codec[0].tf = true;
51 scl->codec[0].type = 0xab;
52 scl->codec[0].type_extended = true;
53 scl->codec[0].cfg_present = true;
54 scl->codec[0].cfg = 0xcdef;
55
56 scl->codec[1].fi = true;
57 scl->codec[1].pt = true;
58 scl->codec[1].type = 0x05;
59
60 scl->codec[2].fi = true;
61 scl->codec[2].tf = true;
62 scl->codec[2].type = 0xf2;
63 scl->codec[2].type_extended = true;
64
65 scl->len = 3;
66}
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +010067
68static void test_create_layer3(void)
69{
70 static const uint8_t res[] = {
71 0x00, 0x0e, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62,
72 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23 };
73 struct msgb *msg, *in_msg;
74 printf("Testing creating Layer3\n");
75
76 in_msg = msgb_alloc_headroom(512, 128, "foo");
77 in_msg->l3h = in_msg->data;
78 msgb_v_put(in_msg, 0x23);
79
80 msg = gsm0808_create_layer3(in_msg, 0x1122, 0x2244, 0x3366, 0x4488);
81 VERIFY(msg, res, ARRAY_SIZE(res));
82 msgb_free(msg);
83 msgb_free(in_msg);
84}
85
Philipp Maierfa896ab2017-03-27 16:55:32 +020086static void test_create_layer3_aoip()
87{
88 static const uint8_t res[] = {
89 0x00, 0x17, 0x57, 0x05, 0x08, 0x00, 0x77, 0x62,
90 0x83, 0x33, 0x66, 0x44, 0x88, 0x17, 0x01, 0x23,
91 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, 0x5f, 0xab, 0xcd, 0xef,
92 0xa5, 0x9f, 0xf2
93 };
94
95 struct msgb *msg, *in_msg;
96 struct gsm0808_speech_codec_list sc_list;
97 printf("Testing creating Layer3 (AoIP)\n");
98
99 setup_codec_list(&sc_list);
100
101 in_msg = msgb_alloc_headroom(512, 128, "foo");
102 in_msg->l3h = in_msg->data;
103 msgb_v_put(in_msg, 0x23);
104
105 msg =
106 gsm0808_create_layer3_aoip(in_msg, 0x1122, 0x2244, 0x3366, 0x4488,
107 &sc_list);
108 VERIFY(msg, res, ARRAY_SIZE(res));
109
110 msgb_free(msg);
111 msgb_free(in_msg);
112}
113
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100114static void test_create_reset()
115{
116 static const uint8_t res[] = { 0x00, 0x04, 0x30, 0x04, 0x01, 0x20 };
117 struct msgb *msg;
118
119 printf("Testing creating Reset\n");
120 msg = gsm0808_create_reset();
121 VERIFY(msg, res, ARRAY_SIZE(res));
122 msgb_free(msg);
123}
124
125static void test_create_clear_command()
126{
127 static const uint8_t res[] = { 0x20, 0x04, 0x01, 0x23 };
128 struct msgb *msg;
129
130 printf("Testing creating Clear Command\n");
131 msg = gsm0808_create_clear_command(0x23);
132 VERIFY(msg, res, ARRAY_SIZE(res));
133 msgb_free(msg);
134}
135
136static void test_create_clear_complete()
137{
138 static const uint8_t res[] = { 0x00, 0x01, 0x21 };
139 struct msgb *msg;
140
141 printf("Testing creating Clear Complete\n");
142 msg = gsm0808_create_clear_complete();
143 VERIFY(msg, res, ARRAY_SIZE(res));
144 msgb_free(msg);
145}
146
147static void test_create_cipher_complete()
148{
149 static const uint8_t res1[] = {
150 0x00, 0x08, 0x55, 0x20, 0x03, 0x23, 0x42, 0x21, 0x2c, 0x04 };
151 static const uint8_t res2[] = { 0x00, 0x03, 0x55, 0x2c, 0x04};
152 struct msgb *l3, *msg;
153
154 printf("Testing creating Cipher Complete\n");
155 l3 = msgb_alloc_headroom(512, 128, "l3h");
156 l3->l3h = l3->data;
157 msgb_v_put(l3, 0x23);
158 msgb_v_put(l3, 0x42);
159 msgb_v_put(l3, 0x21);
160
161 /* with l3 data */
162 msg = gsm0808_create_cipher_complete(l3, 4);
163 VERIFY(msg, res1, ARRAY_SIZE(res1));
164 msgb_free(msg);
165
166 /* with l3 data but short */
167 l3->len -= 1;
168 l3->tail -= 1;
169 msg = gsm0808_create_cipher_complete(l3, 4);
170 VERIFY(msg, res2, ARRAY_SIZE(res2));
171 msgb_free(msg);
172
173 /* without l3 data */
174 msg = gsm0808_create_cipher_complete(NULL, 4);
175 VERIFY(msg, res2, ARRAY_SIZE(res2));
176 msgb_free(msg);
177
178
179 msgb_free(l3);
180}
181
182static void test_create_cipher_reject()
183{
184 static const uint8_t res[] = { 0x00, 0x02, 0x59, 0x23 };
185 struct msgb *msg;
186
187 printf("Testing creating Cipher Reject\n");
188 msg = gsm0808_create_cipher_reject(0x23);
189 VERIFY(msg, res, ARRAY_SIZE(res));
190 msgb_free(msg);
191}
192
193static void test_create_cm_u()
194{
Harald Welte07b625d2012-01-23 10:02:58 +0100195 static const uint8_t res[] = {
196 0x00, 0x07, 0x54, 0x12, 0x01, 0x23, 0x13, 0x01, 0x42 };
197 static const uint8_t res2o[] = {
198 0x00, 0x04, 0x54, 0x12, 0x01, 0x23 };
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100199 struct msgb *msg;
Harald Welte07b625d2012-01-23 10:02:58 +0100200 const uint8_t cm2 = 0x23;
201 const uint8_t cm3 = 0x42;
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100202
203 printf("Testing creating CM U\n");
Harald Welte07b625d2012-01-23 10:02:58 +0100204 msg = gsm0808_create_classmark_update(&cm2, 1, &cm3, 1);
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100205 VERIFY(msg, res, ARRAY_SIZE(res));
Harald Welte07b625d2012-01-23 10:02:58 +0100206
207 msg = gsm0808_create_classmark_update(&cm2, 1, NULL, 0);
208 VERIFY(msg, res2o, ARRAY_SIZE(res2o));
209
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100210 msgb_free(msg);
211}
212
213static void test_create_sapi_reject()
214{
215 static const uint8_t res[] = { 0x00, 0x03, 0x25, 0x03, 0x25 };
216 struct msgb *msg;
217
218 printf("Testing creating SAPI Reject\n");
219 msg = gsm0808_create_sapi_reject(3);
220 VERIFY(msg, res, ARRAY_SIZE(res));
221 msgb_free(msg);
222}
223
224static void test_create_ass_compl()
225{
226 static const uint8_t res1[] = {
227 0x00, 0x09, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c,
228 0x11, 0x40, 0x22 };
229 static const uint8_t res2[] = {
230 0x00, 0x07, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11};
231 struct msgb *msg;
232
233 printf("Testing creating Assignment Complete\n");
234 msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0x22);
235 VERIFY(msg, res1, ARRAY_SIZE(res1));
236 msgb_free(msg);
237
238 msg = gsm0808_create_assignment_completed(0x23, 0x42, 0x11, 0);
239 VERIFY(msg, res2, ARRAY_SIZE(res2));
240 msgb_free(msg);
241}
242
Philipp Maierfa896ab2017-03-27 16:55:32 +0200243static void test_create_ass_compl_aoip()
244{
245 struct sockaddr_storage ss;
246 struct sockaddr_in sin;
247 struct gsm0808_speech_codec sc;
248 struct gsm0808_speech_codec_list sc_list;
249 static const uint8_t res[] =
250 { 0x00, 0x1d, 0x02, 0x15, 0x23, 0x21, 0x42, 0x2c, 0x11, 0x40, 0x22,
251 GSM0808_IE_AOIP_TRASP_ADDR, 0x06, 0xc0, 0xa8, 0x64, 0x17, 0x04,
252 0xd2, GSM0808_IE_SPEECH_CODEC, 0x01, 0x9a,
253 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, 0x5f, 0xab, 0xcd, 0xef, 0xa5,
254 0x9f, 0xf2 };
255 struct msgb *msg;
256
257 memset(&sin, 0, sizeof(sin));
258 sin.sin_family = AF_INET;
259 sin.sin_port = htons(1234);
260 inet_aton("192.168.100.23", &sin.sin_addr);
261
262 memset(&ss, 0, sizeof(ss));
263 memcpy(&ss, &sin, sizeof(sin));
264
265 memset(&sc, 0, sizeof(sc));
266 sc.fi = true;
267 sc.tf = true;
268 sc.type = 0x0a;
269
270 setup_codec_list(&sc_list);
271
272 printf("Testing creating Assignment Complete (AoIP)\n");
273 msg = gsm0808_create_ass_compl(0x23, 0x42, 0x11, 0x22,
274 &ss, &sc, &sc_list);
275 VERIFY(msg, res, ARRAY_SIZE(res));
276 msgb_free(msg);
277}
278
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100279static void test_create_ass_fail()
280{
281 static const uint8_t res1[] = { 0x00, 0x04, 0x03, 0x04, 0x01, 0x23 };
282 static const uint8_t res2[] = {
283 0x00, 0x06, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02};
284 uint8_t rr_res = 2;
285 struct msgb *msg;
286
287 printf("Testing creating Assignment Failure\n");
288 msg = gsm0808_create_assignment_failure(0x23, NULL);
289 VERIFY(msg, res1, ARRAY_SIZE(res1));
290 msgb_free(msg);
291
292 msg = gsm0808_create_assignment_failure(0x23, &rr_res);
293 VERIFY(msg, res2, ARRAY_SIZE(res2));
294 msgb_free(msg);
295}
296
Philipp Maierfa896ab2017-03-27 16:55:32 +0200297static void test_create_ass_fail_aoip()
298{
299 static const uint8_t res1[] =
300 { 0x00, 0x0d, 0x03, 0x04, 0x01, 0x23, GSM0808_IE_SPEECH_CODEC_LIST,
301 0x07, 0x5f, 0xab, 0xcd, 0xef, 0xa5, 0x9f, 0xf2 };
302 static const uint8_t res2[] =
303 { 0x00, 0x0f, 0x03, 0x04, 0x01, 0x23, 0x15, 0x02,
304 GSM0808_IE_SPEECH_CODEC_LIST, 0x07, 0x5f, 0xab,
305 0xcd, 0xef, 0xa5, 0x9f, 0xf2 };
306 uint8_t rr_res = 2;
307 struct msgb *msg;
308 struct gsm0808_speech_codec_list sc_list;
309
310 setup_codec_list(&sc_list);
311
312 printf("Testing creating Assignment Failure (AoIP)\n");
313 msg = gsm0808_create_ass_fail(0x23, NULL, &sc_list);
314 VERIFY(msg, res1, ARRAY_SIZE(res1));
315 msgb_free(msg);
316
317 msg = gsm0808_create_ass_fail(0x23, &rr_res, &sc_list);
318 VERIFY(msg, res2, ARRAY_SIZE(res2));
319 msgb_free(msg);
320}
321
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100322static void test_create_clear_rqst()
323{
324 static const uint8_t res[] = { 0x00, 0x04, 0x22, 0x04, 0x01, 0x23 };
325 struct msgb *msg;
326
327 printf("Testing creating Clear Request\n");
328 msg = gsm0808_create_clear_rqst(0x23);
329 VERIFY(msg, res, ARRAY_SIZE(res));
330 msgb_free(msg);
331}
332
333static void test_create_dtap()
334{
335 static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
336 struct msgb *msg, *l3;
337
338 printf("Testing creating DTAP\n");
339 l3 = msgb_alloc_headroom(512, 128, "test");
340 l3->l3h = l3->data;
341 msgb_v_put(l3, 0x23);
342 msgb_v_put(l3, 0x42);
343
344 msg = gsm0808_create_dtap(l3, 0x3);
345 VERIFY(msg, res, ARRAY_SIZE(res));
346 msgb_free(msg);
347 msgb_free(l3);
348}
349
350static void test_prepend_dtap()
351{
352 static const uint8_t res[] = { 0x01, 0x03, 0x02, 0x23, 0x42 };
353 struct msgb *in_msg;
354
355 printf("Testing prepend DTAP\n");
356
357 in_msg = msgb_alloc_headroom(512, 128, "test");
358 msgb_v_put(in_msg, 0x23);
359 msgb_v_put(in_msg, 0x42);
360
361 gsm0808_prepend_dtap_header(in_msg, 0x3);
362 in_msg->l3h = in_msg->data;
363 VERIFY(in_msg, res, ARRAY_SIZE(res));
364 msgb_free(in_msg);
365}
366
Philipp Maier22401432017-03-24 17:59:26 +0100367static void test_enc_dec_aoip_trasp_addr_v4()
368{
369 struct sockaddr_storage enc_addr;
370 struct sockaddr_storage dec_addr;
371 struct sockaddr_in enc_addr_in;
372 struct msgb *msg;
373 uint8_t rc_enc;
374 int rc_dec;
375
376 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
377 enc_addr_in.sin_family = AF_INET;
378 enc_addr_in.sin_port = htons(1234);
379 inet_aton("255.0.255.255", &enc_addr_in.sin_addr);
380
381 memset(&enc_addr, 0, sizeof(enc_addr));
382 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
383
384 msg = msgb_alloc(1024, "output buffer");
385 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
386 OSMO_ASSERT(rc_enc == 8);
387 rc_dec =
388 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
389 OSMO_ASSERT(rc_dec == 6);
390 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
391
392 msgb_free(msg);
393}
394
395static void test_enc_dec_aoip_trasp_addr_v6()
396{
397 struct sockaddr_storage enc_addr;
398 struct sockaddr_storage dec_addr;
399 struct sockaddr_in6 enc_addr_in;
400 struct msgb *msg;
401 uint8_t rc_enc;
402 int rc_dec;
403
404 memset(&enc_addr_in, 0, sizeof(enc_addr_in));
405 enc_addr_in.sin6_family = AF_INET6;
406 enc_addr_in.sin6_port = htons(4567);
407 inet_pton(AF_INET6, "2001:0db8:85a3:08d3:1319:8a2e:0370:7344",
408 &enc_addr_in.sin6_addr);
409
410 memset(&enc_addr, 0, sizeof(enc_addr));
411 memcpy(&enc_addr, &enc_addr_in, sizeof(enc_addr_in));
412
413 msg = msgb_alloc(1024, "output buffer");
414 rc_enc = gsm0808_enc_aoip_trasp_addr(msg, &enc_addr);
415 OSMO_ASSERT(rc_enc == 20);
416 rc_dec =
417 gsm0808_dec_aoip_trasp_addr(&dec_addr, msg->data + 2, msg->len - 2);
418 OSMO_ASSERT(rc_dec == 18);
419 OSMO_ASSERT(memcmp(&enc_addr, &dec_addr, sizeof(enc_addr)) == 0);
420
421 msgb_free(msg);
422}
423
Philipp Maier6f725d62017-03-24 18:03:17 +0100424static void test_gsm0808_enc_dec_speech_codec()
425{
426 struct gsm0808_speech_codec enc_sc;
427 struct gsm0808_speech_codec dec_sc;
428 struct msgb *msg;
429 uint8_t rc_enc;
430 int rc_dec;
431
432 memset(&enc_sc, 0, sizeof(enc_sc));
433 enc_sc.fi = true;
434 enc_sc.pt = true;
435 enc_sc.type = 0x05;
436
437 msg = msgb_alloc(1024, "output buffer");
438 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
439 OSMO_ASSERT(rc_enc == 3);
440
441 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
442 OSMO_ASSERT(rc_dec == 1);
443
444 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
445
446 msgb_free(msg);
447}
448
449
450static void test_gsm0808_enc_dec_speech_codec_ext_with_cfg()
451{
452 struct gsm0808_speech_codec enc_sc;
453 struct gsm0808_speech_codec dec_sc;
454 struct msgb *msg;
455 uint8_t rc_enc;
456 int rc_dec;
457
458 enc_sc.pi = true;
459 enc_sc.tf = true;
460 enc_sc.type = 0xab;
461 enc_sc.type_extended = true;
462 enc_sc.cfg_present = true;
463 enc_sc.cfg = 0xcdef;
464
465 msg = msgb_alloc(1024, "output buffer");
466 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
467 OSMO_ASSERT(rc_enc == 6);
468
469 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
470 OSMO_ASSERT(rc_dec == 4);
471
472 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
473
474 msgb_free(msg);
475}
476
477static void test_gsm0808_enc_dec_speech_codec_ext()
478{
479 struct gsm0808_speech_codec enc_sc;
480 struct gsm0808_speech_codec dec_sc;
481 struct msgb *msg;
482 uint8_t rc_enc;
483 int rc_dec;
484
485 enc_sc.fi = true;
486 enc_sc.tf = true;
487 enc_sc.type = 0xf2;
488 enc_sc.type_extended = true;
489 enc_sc.cfg_present = false;
490 enc_sc.cfg = 0x0000;
491
492 msg = msgb_alloc(1024, "output buffer");
493 rc_enc = gsm0808_enc_speech_codec(msg, &enc_sc);
494 OSMO_ASSERT(rc_enc == 4);
495
496 rc_dec = gsm0808_dec_speech_codec(&dec_sc, msg->data + 2, msg->len - 2);
497 OSMO_ASSERT(rc_dec == 2);
498
499 OSMO_ASSERT(memcmp(&enc_sc, &dec_sc, sizeof(enc_sc)) == 0);
500
501 msgb_free(msg);
502}
503
504static void test_gsm0808_enc_dec_speech_codec_list()
505{
506 struct gsm0808_speech_codec_list enc_scl;
507 struct gsm0808_speech_codec_list dec_scl;
508 struct msgb *msg;
509 uint8_t rc_enc;
510 int rc_dec;
511
512 memset(&enc_scl, 0, sizeof(enc_scl));
513
514 enc_scl.codec[0].pi = true;
515 enc_scl.codec[0].tf = true;
516 enc_scl.codec[0].type = 0xab;
517 enc_scl.codec[0].type_extended = true;
518 enc_scl.codec[0].cfg_present = true;
519 enc_scl.codec[0].cfg = 0xcdef;
520
521 enc_scl.codec[1].fi = true;
522 enc_scl.codec[1].pt = true;
523 enc_scl.codec[1].type = 0x05;
524
525 enc_scl.codec[2].fi = true;
526 enc_scl.codec[2].tf = true;
527 enc_scl.codec[2].type = 0xf2;
528 enc_scl.codec[2].type_extended = true;
529
530 enc_scl.len = 3;
531
532 msg = msgb_alloc(1024, "output buffer");
533 rc_enc = gsm0808_enc_speech_codec_list(msg, &enc_scl);
534 OSMO_ASSERT(rc_enc == 9);
535
536 rc_dec = gsm0808_dec_speech_codec_list(&dec_scl, msg->data + 2, msg->len - 2);
537 OSMO_ASSERT(rc_dec == 7);
538
539 OSMO_ASSERT(memcmp(&enc_scl, &dec_scl, sizeof(enc_scl)) == 0);
540
541 msgb_free(msg);
542}
543
Philipp Maiere0c65302017-03-28 17:05:40 +0200544static void test_gsm0808_enc_dec_channel_type()
545{
546 struct gsm0808_channel_type enc_ct;
547 struct gsm0808_channel_type dec_ct;
548 struct msgb *msg;
549 uint8_t ct_enc_expected[] = { GSM0808_IE_CHANNEL_TYPE,
550 0x04, 0x01, 0x0b, 0xa1, 0x25
551 };
552 uint8_t rc_enc;
553 int rc_dec;
554
555 memset(&enc_ct, 0, sizeof(enc_ct));
556 enc_ct.ch_indctr = GSM0808_CHAN_SPEECH;
557 enc_ct.ch_rate_type = GSM0808_SPEECH_HALF_PREF;
558 enc_ct.perm_spch[0] = GSM0808_PERM_FR3;
559 enc_ct.perm_spch[1] = GSM0808_PERM_HR3;
560 enc_ct.perm_spch_len = 2;
561
562 msg = msgb_alloc(1024, "output buffer");
563 rc_enc = gsm0808_enc_channel_type(msg, &enc_ct);
564 OSMO_ASSERT(rc_enc == 6);
565 OSMO_ASSERT(memcmp(ct_enc_expected, msg->data, msg->len) == 0);
566
567 rc_dec = gsm0808_dec_channel_type(&dec_ct, msg->data + 2, msg->len - 2);
568 OSMO_ASSERT(rc_dec == 4);
569 OSMO_ASSERT(memcmp(&enc_ct, &dec_ct, sizeof(enc_ct)) == 0);
570
571 msgb_free(msg);
572}
573
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100574int main(int argc, char **argv)
575{
576 printf("Testing generation of GSM0808 messages\n");
577 test_create_layer3();
Philipp Maierfa896ab2017-03-27 16:55:32 +0200578 test_create_layer3_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100579 test_create_reset();
580 test_create_clear_command();
581 test_create_clear_complete();
582 test_create_cipher_complete();
583 test_create_cipher_reject();
584 test_create_cm_u();
585 test_create_sapi_reject();
586 test_create_ass_compl();
Philipp Maierfa896ab2017-03-27 16:55:32 +0200587 test_create_ass_compl_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100588 test_create_ass_fail();
Philipp Maierfa896ab2017-03-27 16:55:32 +0200589 test_create_ass_fail_aoip();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100590 test_create_clear_rqst();
591 test_create_dtap();
592 test_prepend_dtap();
Philipp Maier22401432017-03-24 17:59:26 +0100593 test_enc_dec_aoip_trasp_addr_v4();
594 test_enc_dec_aoip_trasp_addr_v6();
Philipp Maier6f725d62017-03-24 18:03:17 +0100595 test_gsm0808_enc_dec_speech_codec();
596 test_gsm0808_enc_dec_speech_codec_ext();
597 test_gsm0808_enc_dec_speech_codec_ext_with_cfg();
598 test_gsm0808_enc_dec_speech_codec_list();
Philipp Maiere0c65302017-03-28 17:05:40 +0200599 test_gsm0808_enc_dec_channel_type();
Holger Hans Peter Freyther97510812012-01-22 13:36:52 +0100600
601 printf("Done\n");
602 return EXIT_SUCCESS;
603}