aboutsummaryrefslogtreecommitdiffstats
path: root/tests/codec_pref/codec_pref_test.c
blob: e2876e2c82f402be273218775cbdbac3a012533b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/*
 * (C) 2018 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
 * All Rights Reserved
 *
 * Author: Philipp Maier
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/osmo_bsc.h>
#include <osmocom/bsc/bsc_msc_data.h>
#include <osmocom/bsc/gsm_04_80.h>
#include <osmocom/core/application.h>
#include <osmocom/bsc/codec_pref.h>

#include <stdio.h>

void *ctx = NULL;

#define MSC_AUDIO_SUPPORT_MAX 5
#define N_CONFIG_VARIANTS 9

/* Make sure that there is some memory to put our test configuration. */
static void init_msc_config(struct bsc_msc_data *msc)
{
	unsigned int i;

	msc->audio_support = talloc_zero_array(ctx, struct gsm_audio_support *, MSC_AUDIO_SUPPORT_MAX);
	msc->audio_length = MSC_AUDIO_SUPPORT_MAX;
	for (i = 0; i < MSC_AUDIO_SUPPORT_MAX; i++) {
		msc->audio_support[i] = talloc_zero(msc->audio_support, struct gsm_audio_support);
	}
}

/* Free memory that we have used for the test configuration. */
static void free_msc_config(struct bsc_msc_data *msc)
{
	talloc_free(msc->audio_support);
}

/* The speech codec list is sent by the MS and lists the voice codec settings
 * that the MS is able to support. The BSC must select one of this codecs
 * depending on what the MSC is able to support. The following function
 * generates some realistically made up speech codec lists. */
static void make_scl_config(struct gsm0808_speech_codec_list *scl, uint8_t config_no)
{
	OSMO_ASSERT(config_no < N_CONFIG_VARIANTS);

	switch (config_no) {
	case 0:
		/* FR1 only */
		scl->codec[0].type = GSM0808_SCT_FR1;
		scl->len = 1;
		break;
	case 1:
		/* HR1 only */
		scl->codec[0].type = GSM0808_SCT_HR1;
		scl->len = 1;
		break;
	case 2:
		/* FR2 only */
		scl->codec[0].type = GSM0808_SCT_FR2;
		scl->len = 1;
		break;
	case 3:
		/* FR3 only */
		scl->codec[0].type = GSM0808_SCT_FR3;
		scl->codec[0].cfg = GSM0808_SC_CFG_DEFAULT_FR_AMR;
		scl->len = 1;
		break;
	case 4:
		/* HR3 only */
		scl->codec[0].type = GSM0808_SCT_HR3;
		scl->codec[0].cfg = GSM0808_SC_CFG_DEFAULT_HR_AMR;
		scl->len = 1;
		break;
	case 5:
		/* FR1 and HR1 */
		scl->codec[0].type = GSM0808_SCT_FR1;
		scl->codec[1].type = GSM0808_SCT_HR1;
		scl->len = 2;
		break;
	case 6:
		/* FR1, FR2 and HR1 */
		scl->codec[0].type = GSM0808_SCT_FR1;
		scl->codec[1].type = GSM0808_SCT_FR2;
		scl->codec[2].type = GSM0808_SCT_HR1;
		scl->len = 3;
		break;
	case 7:
		/* FR1, FR3 and HR3 */
		scl->codec[0].type = GSM0808_SCT_FR1;
		scl->codec[1].type = GSM0808_SCT_FR3;
		scl->codec[1].cfg = GSM0808_SC_CFG_DEFAULT_FR_AMR;
		scl->codec[2].type = GSM0808_SCT_HR3;
		scl->codec[2].cfg = GSM0808_SC_CFG_DEFAULT_HR_AMR;
		scl->len = 3;
		break;
	case 8:
		/* FR1, FR2, FR3, HR1 and HR3 */
		scl->codec[0].type = GSM0808_SCT_FR1;
		scl->codec[1].type = GSM0808_SCT_FR2;
		scl->codec[2].type = GSM0808_SCT_FR3;
		scl->codec[2].cfg = GSM0808_SC_CFG_DEFAULT_FR_AMR;
		scl->codec[3].type = GSM0808_SCT_HR1;
		scl->codec[4].type = GSM0808_SCT_HR3;
		scl->codec[4].cfg = GSM0808_SC_CFG_DEFAULT_HR_AMR;
		scl->len = 5;
		break;
	}
}

/* The channel type element which is sent to the BSC by the MSC lists all the
 * codecs that the MSC is able to support. The following function generates
 * a realistic permitted speech settings */
static void make_ct_config(struct gsm0808_channel_type *ct, uint8_t config_no)
{
	OSMO_ASSERT(config_no < N_CONFIG_VARIANTS);

	switch (config_no) {
	case 0:
		/* FR1 only */
		ct->perm_spch[0] = GSM0808_PERM_FR1;
		ct->perm_spch_len = 1;
		break;
	case 1:
		/* HR1 only */
		ct->perm_spch[0] = GSM0808_PERM_HR1;
		ct->perm_spch_len = 1;
		break;
	case 2:
		/* FR2 only */
		ct->perm_spch[0] = GSM0808_PERM_FR2;
		ct->perm_spch_len = 1;
		break;
	case 3:
		/* FR3 only */
		ct->perm_spch[0] = GSM0808_PERM_FR3;
		ct->perm_spch_len = 1;
		break;
	case 4:
		/* HR3 only */
		ct->perm_spch[0] = GSM0808_PERM_HR3;
		ct->perm_spch_len = 1;
		break;
	case 5:
		/* FR1 and HR1 */
		ct->perm_spch[0] = GSM0808_PERM_FR1;
		ct->perm_spch[1] = GSM0808_PERM_HR1;
		ct->perm_spch_len = 2;
		break;
	case 6:
		/* FR1, FR2 and HR1 */
		ct->perm_spch[0] = GSM0808_PERM_FR1;
		ct->perm_spch[1] = GSM0808_PERM_FR2;
		ct->perm_spch[2] = GSM0808_PERM_HR1;
		ct->perm_spch_len = 3;
		break;
	case 7:
		/* FR1, FR3 and HR3 */
		ct->perm_spch[0] = GSM0808_PERM_FR1;
		ct->perm_spch[1] = GSM0808_PERM_FR3;
		ct->perm_spch[2] = GSM0808_PERM_HR3;
		ct->perm_spch_len = 3;
		break;
	case 8:
		/* FR1, FR2, FR3, HR1 and HR3 */
		ct->perm_spch[0] = GSM0808_PERM_FR1;
		ct->perm_spch[1] = GSM0808_PERM_FR2;
		ct->perm_spch[2] = GSM0808_PERM_FR3;
		ct->perm_spch[3] = GSM0808_PERM_HR1;
		ct->perm_spch[4] = GSM0808_PERM_HR3;
		ct->perm_spch_len = 5;
		break;
	}
}

/* Generate some realistic MSC configuration which one also could find in the
 * real world. This configuration acts as a filter. While the MSC could in
 * theory advertise codecs more codecs as we are able to support we have to
 * make sure that only the codecs we have support for are considered. */
static void make_msc_config(struct bsc_msc_data *msc, uint8_t config_no)
{
	/* 1 = FR1/HR1
	 * 2 = FR2/HR2
	 * 3 = FR2/HR3
	 * Note: HR2 is deprecated */

	OSMO_ASSERT(config_no < N_CONFIG_VARIANTS);

	/* Setup an AMR configuration, this configuration is separate and does
	 * not influence other codecs than AMR */
	msc->amr_conf.m4_75 = 1;
	msc->amr_conf.m5_15 = 1;
	msc->amr_conf.m5_90 = 1;
	msc->amr_conf.m6_70 = 1;
	msc->amr_conf.m7_40 = 1;
	msc->amr_conf.m7_95 = 1;
	msc->amr_conf.m10_2 = 1;
	msc->amr_conf.m12_2 = 1;

	switch (config_no) {
	case 0:
		/* FR1 only */
		msc->audio_support[0]->ver = 1;
		msc->audio_support[0]->hr = 0;
		msc->audio_length = 1;
		break;
	case 1:
		/* HR1 only */
		msc->audio_support[0]->ver = 1;
		msc->audio_support[0]->hr = 1;
		msc->audio_length = 1;
		break;
	case 2:
		/* FR2 only */
		msc->audio_support[0]->ver = 2;
		msc->audio_support[0]->hr = 0;
		msc->audio_length = 1;
		break;
	case 3:
		/* FR3 only */
		msc->audio_support[0]->ver = 3;
		msc->audio_support[0]->hr = 0;
		msc->audio_length = 1;
		break;
	case 4:
		/* HR3 only */
		msc->audio_support[0]->ver = 3;
		msc->audio_support[0]->hr = 1;
		msc->audio_length = 1;
		break;
	case 5:
		/* FR1 and HR1 */
		msc->audio_support[0]->ver = 1;
		msc->audio_support[0]->hr = 0;
		msc->audio_support[1]->ver = 1;
		msc->audio_support[1]->hr = 1;
		msc->audio_length = 2;
		break;
	case 6:
		/* FR1, FR2 and HR1 */
		msc->audio_support[0]->ver = 1;
		msc->audio_support[0]->hr = 0;
		msc->audio_support[1]->ver = 2;
		msc->audio_support[1]->hr = 0;
		msc->audio_support[2]->ver = 1;
		msc->audio_support[2]->hr = 1;
		msc->audio_length = 3;
		break;
	case 7:
		/* FR1, FR3 and HR3 */
		msc->audio_support[0]->ver = 1;
		msc->audio_support[0]->hr = 0;
		msc->audio_support[1]->ver = 3;
		msc->audio_support[1]->hr = 0;
		msc->audio_support[2]->ver = 3;
		msc->audio_support[2]->hr = 1;
		msc->audio_length = 3;
		break;
	case 8:
		/* FR1, FR2, FR3, HR1 and HR3 */
		msc->audio_support[0]->ver = 1;
		msc->audio_support[0]->hr = 0;
		msc->audio_support[1]->ver = 2;
		msc->audio_support[1]->hr = 0;
		msc->audio_support[2]->ver = 3;
		msc->audio_support[2]->hr = 0;
		msc->audio_support[3]->ver = 1;
		msc->audio_support[3]->hr = 1;
		msc->audio_support[4]->ver = 3;
		msc->audio_support[4]->hr = 1;
		msc->audio_length = 5;
		break;
	}
}

/* Generate a realitically looking bts codec configuration */
static void make_bts_config(struct gsm_bts *bts, uint8_t config_no)
{
	/* Note: FR is supported by all BTSs, so there is no flag for it */

	struct gsm48_multi_rate_conf *cfg;

	OSMO_ASSERT(config_no < N_CONFIG_VARIANTS);

	bts->codec.hr = 0;
	bts->codec.efr = 0;
	bts->codec.amr = 0;
	memset(&bts->mr_full.gsm48_ie, 0, sizeof(bts->mr_full.gsm48_ie));
	memset(&bts->mr_full.gsm48_ie, 0, sizeof(bts->mr_half.gsm48_ie));

	/* Setup an AMR configuration, this configuration is separate and does
	 * not influence other codecs than AMR */
	cfg = (struct gsm48_multi_rate_conf*) &bts->mr_full.gsm48_ie;
	cfg->m4_75 = 1;
	cfg->m5_15 = 1;
	cfg->m5_90 = 1;
	cfg->m6_70 = 1;
	cfg->m7_40 = 1;
	cfg->m7_95 = 1;
	cfg->m10_2 = 1;
	cfg->m12_2 = 1;
	cfg = (struct gsm48_multi_rate_conf*) &bts->mr_half.gsm48_ie;
	cfg->m4_75 = 1;
	cfg->m5_15 = 1;
	cfg->m5_90 = 1;
	cfg->m6_70 = 1;
	cfg->m7_40 = 1;
	cfg->m7_95 = 1;
	cfg->m10_2 = 0;
	cfg->m12_2 = 0;

	switch (config_no) {
	case 0:
		/* FR1 (implicit) only */
		break;
	case 1:
		/* HR1 only (+FR implicit) */
		bts->codec.hr = 1;
		break;
	case 2:
		/* FR2 only (+FR implicit)  */
		bts->codec.efr = 1;
		break;
	case 3:
		/* FR3 only (+FR implicit) */
		bts->codec.amr = 1;
		break;
	case 4:
		/* HR3 only (+FR implicit) */
		bts->codec.amr = 1;
		break;
	case 5:
		/* FR1 (implicit) and HR1 */
		bts->codec.hr = 1;
		break;
	case 6:
		/* FR1 (implicit), FR2 and HR1 */
		bts->codec.efr = 1;
		bts->codec.hr = 1;
		break;
	case 7:
		/* FR1 (implicit), FR3 and HR3 */
		bts->codec.amr = 1;
		break;
	case 8:
		/* FR1 (implicit), FR2, FR3, HR1 and HR3 */
		bts->codec.hr = 1;
		bts->codec.efr = 1;
		bts->codec.amr = 1;
		break;
	}
}

/* Try execute match_codec_pref(), display input and output parameters */
static int test_match_codec_pref(const struct gsm0808_channel_type *ct, const struct gsm0808_speech_codec_list *scl,
				 const struct bsc_msc_data *msc, struct gsm_bts *bts)
{
	int rc;
	unsigned int i;
	bool full_rate;
	enum gsm48_chan_mode chan_mode;
	uint16_t s15_s0;

	printf("Determining channel mode and rate:\n");

	printf(" * MS: speech codec list (%u items):\n", scl->len);
	for (i = 0; i < scl->len; i++)
		printf("   codec[%u]->type=%s\n", i, gsm0808_speech_codec_type_name(scl->codec[i].type));

	printf(" * MSC: channel type permitted speech (%u items):\n", ct->perm_spch_len);
	for (i = 0; i < ct->perm_spch_len; i++)
		printf("   perm_spch[%u]=%s\n", i, gsm0808_permitted_speech_name(ct->perm_spch[i]));

	printf(" * BSS: audio support settings (%u items):\n", msc->audio_length);
	for (i = 0; i < msc->audio_length; i++)
		if (msc->audio_support[i]->hr)
			printf("   audio_support[%u]=HR%u\n", i, msc->audio_support[i]->ver);
		else
			printf("   audio_support[%u]=FR%u\n", i, msc->audio_support[i]->ver);

	printf(" * BTS: audio support settings:\n");
	printf("   (GSM-FR implicitly supported)\n");
	printf("   codec->hr=%u\n", bts->codec.hr);
	printf("   codec->efr=%u\n", bts->codec.efr);
	printf("   codec->amr=%u\n", bts->codec.amr);

	rc = match_codec_pref(&chan_mode, &full_rate, &s15_s0, ct, scl, msc, bts);
	printf(" * result: rc=%i, full_rate=%i, s15_s0=%04x, chan_mode=%s\n",
	       rc, full_rate, s15_s0, gsm48_chan_mode_name(chan_mode));

	printf("\n");

	return rc;
}

/* MS, MSC and local MSC settings are the same */
static void test_one_to_one(void)
{
	unsigned int i;
	struct gsm0808_channel_type ct_msc;
	struct gsm0808_speech_codec_list scl_ms;
	struct bsc_msc_data msc_local;
	struct gsm_bts bts_local;
	int rc;

	printf("============== test_one_to_one ==============\n\n");

	init_msc_config(&msc_local);

	for (i = 0; i < N_CONFIG_VARIANTS; i++) {
		make_msc_config(&msc_local, i);
		make_scl_config(&scl_ms, i);
		make_ct_config(&ct_msc, i);
		make_bts_config(&bts_local, i);
		rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
		OSMO_ASSERT(rc == 0);
	}

	free_msc_config(&msc_local);
}

/* Network supports all combinations, MS varies */
static void test_ms(void)
{
	unsigned int i;
	struct gsm0808_channel_type ct_msc;
	struct gsm0808_speech_codec_list scl_ms;
	struct bsc_msc_data msc_local;
	struct gsm_bts bts_local;
	int rc;

	printf("============== test_ms ==============\n\n");

	init_msc_config(&msc_local);

	make_msc_config(&msc_local, 8);
	make_ct_config(&ct_msc, 8);
	make_bts_config(&bts_local, 8);
	for (i = 0; i < N_CONFIG_VARIANTS; i++) {
		make_scl_config(&scl_ms, i);
		rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
		OSMO_ASSERT(rc == 0);
	}

	free_msc_config(&msc_local);
}

/* BSS and MS support all combinations, MSC varies */
static void test_ct(void)
{
	unsigned int i;
	struct gsm0808_channel_type ct_msc;
	struct gsm0808_speech_codec_list scl_ms;
	struct bsc_msc_data msc_local;
	struct gsm_bts bts_local;
	int rc;

	printf("============== test_ct ==============\n\n");

	init_msc_config(&msc_local);

	make_msc_config(&msc_local, 8);
	make_scl_config(&scl_ms, 8);
	make_bts_config(&bts_local, 8);
	for (i = 0; i < N_CONFIG_VARIANTS; i++) {
		make_ct_config(&ct_msc, i);
		rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
		OSMO_ASSERT(rc == 0);
	}

	free_msc_config(&msc_local);
}

/* MSC and MS support all combinations, BSS varies */
static void test_msc(void)
{
	unsigned int i;
	struct gsm0808_channel_type ct_msc;
	struct gsm0808_speech_codec_list scl_ms;
	struct bsc_msc_data msc_local;
	struct gsm_bts bts_local;
	int rc;

	printf("============== test_msc ==============\n\n");

	init_msc_config(&msc_local);

	make_ct_config(&ct_msc, 8);
	make_scl_config(&scl_ms, 8);
	make_bts_config(&bts_local, 8);
	for (i = 0; i < N_CONFIG_VARIANTS; i++) {
		make_msc_config(&msc_local, 8);
		rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
		OSMO_ASSERT(rc == 0);
	}

	free_msc_config(&msc_local);
}

/* Some mixed configurations that are supposed to work */
static void test_selected_working(void)
{
	struct gsm0808_channel_type ct_msc;
	struct gsm0808_speech_codec_list scl_ms;
	struct bsc_msc_data msc_local;
	struct gsm_bts bts_local;
	int rc;

	printf("============== test_selected_working ==============\n\n");

	init_msc_config(&msc_local);

	make_scl_config(&scl_ms, 6);
	make_ct_config(&ct_msc, 5);
	make_msc_config(&msc_local, 7);
	make_bts_config(&bts_local, 8);
	rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
	OSMO_ASSERT(rc == 0);

	make_scl_config(&scl_ms, 0);
	make_ct_config(&ct_msc, 5);
	make_msc_config(&msc_local, 7);
	make_bts_config(&bts_local, 8);
	rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
	OSMO_ASSERT(rc == 0);

	make_scl_config(&scl_ms, 1);
	make_ct_config(&ct_msc, 5);
	make_msc_config(&msc_local, 6);
	make_bts_config(&bts_local, 8);
	rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
	OSMO_ASSERT(rc == 0);

	make_scl_config(&scl_ms, 6);
	make_ct_config(&ct_msc, 5);
	make_msc_config(&msc_local, 7);
	make_bts_config(&bts_local, 4);
	rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
	OSMO_ASSERT(rc == 0);

	make_scl_config(&scl_ms, 0);
	make_ct_config(&ct_msc, 5);
	make_msc_config(&msc_local, 7);
	make_bts_config(&bts_local, 2);
	rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
	OSMO_ASSERT(rc == 0);

	make_scl_config(&scl_ms, 1);
	make_ct_config(&ct_msc, 5);
	make_msc_config(&msc_local, 6);
	make_bts_config(&bts_local, 1);
	rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
	OSMO_ASSERT(rc == 0);

	free_msc_config(&msc_local);
}

/* Some mixed configurations that can not work */
static void test_selected_non_working(void)
{
	struct gsm0808_channel_type ct_msc;
	struct gsm0808_speech_codec_list scl_ms;
	struct bsc_msc_data msc_local;
	struct gsm_bts bts_local;
	int rc;

	printf("============== test_selected_non_working ==============\n\n");

	init_msc_config(&msc_local);

	make_scl_config(&scl_ms, 1);
	make_ct_config(&ct_msc, 5);
	make_msc_config(&msc_local, 7);
	make_bts_config(&bts_local, 8);
	rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
	OSMO_ASSERT(rc == -1);

	make_scl_config(&scl_ms, 1);
	make_ct_config(&ct_msc, 5);
	make_msc_config(&msc_local, 7);
	make_bts_config(&bts_local, 8);
	rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
	OSMO_ASSERT(rc == -1);

	make_scl_config(&scl_ms, 1);
	make_ct_config(&ct_msc, 4);
	make_msc_config(&msc_local, 6);
	make_bts_config(&bts_local, 8);
	rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
	OSMO_ASSERT(rc == -1);

	make_scl_config(&scl_ms, 1);
	make_ct_config(&ct_msc, 2);
	make_msc_config(&msc_local, 7);
	make_bts_config(&bts_local, 8);
	rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
	OSMO_ASSERT(rc == -1);

	make_scl_config(&scl_ms, 1);
	make_ct_config(&ct_msc, 5);
	make_msc_config(&msc_local, 4);
	make_bts_config(&bts_local, 8);
	rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
	OSMO_ASSERT(rc == -1);

	make_scl_config(&scl_ms, 8);
	make_ct_config(&ct_msc, 4);
	make_msc_config(&msc_local, 6);
	make_bts_config(&bts_local, 7);
	rc = test_match_codec_pref(&ct_msc, &scl_ms, &msc_local, &bts_local);
	OSMO_ASSERT(rc == -1);

	free_msc_config(&msc_local);
}

/* Try execute bss_supp_codec_list(), display input and output parameters */
static void test_gen_bss_supported_codec_list(const struct bsc_msc_data *msc, struct gsm_bts *bts)
{
	unsigned int i;
	struct gsm0808_speech_codec_list scl;

	printf("Determining Codec List (BSS Supported):\n");

	printf(" * BSS: audio support settings (%u items):\n", msc->audio_length);
	for (i = 0; i < msc->audio_length; i++)
		if (msc->audio_support[i]->hr)
			printf("   audio_support[%u]=HR%u\n", i, msc->audio_support[i]->ver);
		else
			printf("   audio_support[%u]=FR%u\n", i, msc->audio_support[i]->ver);

	printf(" * BTS: audio support settings:\n");
	printf("   (GSM-FR implicitly supported)\n");
	printf("   codec->hr=%u\n", bts->codec.hr);
	printf("   codec->efr=%u\n", bts->codec.efr);
	printf("   codec->amr=%u\n", bts->codec.amr);

	gen_bss_supported_codec_list(&scl, msc, bts);

	printf(" * result: speech codec list (%u items):\n", scl.len);
	for (i = 0; i < scl.len; i++) {
		printf("   codec[%u]->type=%s", i, gsm0808_speech_codec_type_name(scl.codec[i].type));
		if (msc->audio_support[i]->ver == 3)
			printf(" S15-S0=%04x", scl.codec[i].cfg);
		printf("\n");
	}
	printf("\n");
}

/* Test gen_bss_supported_codec_list() with some mixed configurations */
static void test_gen_bss_supported_codec_list_cfgs(void)
{
	struct bsc_msc_data msc_local;
	struct gsm_bts bts_local;
	uint8_t i;
	uint8_t k;

	printf("============== test_gen_bss_supp_codec_list_cfgs ==============\n\n");
	init_msc_config(&msc_local);

	for (i = 0; i < N_CONFIG_VARIANTS; i++) {
		for (k = 0; k < N_CONFIG_VARIANTS; k++) {
			make_msc_config(&msc_local, i);
			make_bts_config(&bts_local, k);
			printf("MSC config: %u, BTS config: %u\n", i, k);
			test_gen_bss_supported_codec_list(&msc_local, &bts_local);
		}
	}

	free_msc_config(&msc_local);
}

static const struct log_info_cat log_categories[] = {
	[DMSC] = {
		  .name = "DMSC",
		  .description = "Mobile Switching Center",
		  .enabled = 1,.loglevel = LOGL_NOTICE,
		  },
};

static const struct log_info log_info = {
	.cat = log_categories,
	.num_cat = ARRAY_SIZE(log_categories),
};

int main(int argc, char **argv)
{
	ctx = talloc_named_const(NULL, 0, "codec_pref_test");
	msgb_talloc_ctx_init(ctx, 0);
	osmo_init_logging2(ctx, &log_info);

	test_one_to_one();
	test_ms();
	test_ct();
	test_msc();
	test_selected_working();
	test_selected_non_working();
	test_gen_bss_supported_codec_list_cfgs();

	printf("Testing execution completed.\n");
	talloc_free(ctx);
	return 0;
}