aboutsummaryrefslogtreecommitdiffstats
path: root/bts/BTS_Tests_LAPDm.ttcn
blob: 4d4a9884bbb76395bdb004ee3219ffb198578fee (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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
module BTS_Tests_LAPDm {

import from GSM_Types all;
import from Osmocom_Types all;
import from LAPDm_RAW_PT all;
import from LAPDm_Types all;
import from RSL_Types all;
import from BTS_Tests all;
import from Misc_Helpers all;

/* test that use exclusively only LAPDm over L1CTL */
type component lapdm_test_CT {
	port LAPDm_PT LAPDM;
	var lapdm_CT lapdm_component;
};

/* contrary to BTS_Tests.ttcn, we use LAPDm_PT here, a convenience wrapper
 * around L1CTL to perform encode/decode of abstract LAPDm frames */

/*********************************************************************************
 * Test using only L1CTL/LAPDm
 *********************************************************************************/

function f_lapdm_init() runs on lapdm_test_CT {
	/* create the LAPDm component */
	lapdm_component := lapdm_CT.create;
	/* connect our own LAPDM port to the LAPDM Service Provider of the LAPDm component */
	connect(self:LAPDM, lapdm_component:LAPDM_SP);
	/* connect the LAPDm compoent's lower-side port to the system L1CTL port (which is internally
	 * connected to the Unix Domain Socket test port */
	map(lapdm_component:L1CTL, system:L1CTL);

	/* start the LAPDm parallel component calling it's local function LAPDmStart */
	lapdm_component.start(LAPDmStart());
}

function f_lapdm_exit() runs on lapdm_test_CT {
	lapdm_component.stop;
	lapdm_component.done;
	unmap(lapdm_component:L1CTL, system:L1CTL);
}

/* master function establishing a dedicated radio channel (takes care of RACH/IMM.ASS handling) */
function f_establish_dcch() runs on lapdm_test_CT {
	var BCCH_tune_req tune_req := { arfcn := { false, mp_trx0_arfcn }, combined_ccch := true };
	var DCCH_establish_req est_req := { ra := 23 };

	LAPDM.send(tune_req);
	LAPDM.send(est_req);
	LAPDM.receive(DCCH_establish_res:?);
}

/* master function switching to a dedicated radio channel */
function f_switch_dcch(Arfcn arfcn, RslChannelNr chan_nr, GsmTsc tsc) runs on lapdm_test_CT {
	var BCCH_tune_req tune_req := { arfcn := arfcn, combined_ccch := true };
	var DCCH_switch_req sw_req := { arfcn, chan_nr, tsc };

	LAPDM.send(tune_req);
	LAPDM.send(sw_req);
	LAPDM.receive(DCCH_switch_res:?);
}

/* helper function releasing dedicated radio channel physically (no Um signaling!) */
function f_release_dcch() runs on lapdm_test_CT {
	var DCCH_release_req rel_req := {};
	LAPDM.send(rel_req);
}

template LAPDm_ph_data t_PH_DATA(template GsmSapi sapi, template boolean sacch, template LapdmFrame frame) := {
	sacch := sacch,
	sapi := sapi,
	lapdm := frame
}

function f_test_sabm_results_in_ua(uint8_t sapi, boolean use_sacch, octetstring payload) runs on ConnHdlr return boolean {
	var LAPDm_ph_data phd;
	var boolean result := false;
	timer T := 5.0;

	LAPDM.send(t_PH_DATA(sapi, use_sacch, ts_LAPDm_SABM(sapi, c_r:=cr_MO_CMD, p:=false, l3:=payload)));
	T.start
	alt {
		[] LAPDM.receive(t_PH_DATA(?, use_sacch, tr_LAPDm_UA(sapi, cr_MT_RSP, f:=false, l3:=payload))) { result := true; }
		[] RSL.receive {repeat;}
		[] LAPDM.receive { repeat; }
		[] T.timeout { }
	}
	LAPDM.send(t_PH_DATA(sapi, use_sacch, ts_LAPDm_RR(sapi, c_r:=cr_MT_CMD, p:=false, nr:=0)));
	return result;
}

function f_TC_sabm_ua_dcch_sapi0(charstring id) runs on ConnHdlr {
	fp_common_init();
	RSL.clear;
	LAPDM.clear;
	var default d := activate(as_ignore_background());
	if (not f_test_sabm_results_in_ua(0, false, 'FEFE'O)) {
		setverdict(fail);
	}
	setverdict(pass);
	deactivate(d);
	fp_common_fini();
}

function f_TC_sabm_ua_dcch_sapi0_nopayload(charstring id) runs on ConnHdlr {
	fp_common_init();
	RSL.clear;
	LAPDM.clear;
	var default d := activate(as_ignore_background());
	if (f_test_sabm_results_in_ua(0, false, ''O)) {
		setverdict(fail, "Initial SABM/UA must contain L3 payload but BTS accepts without");
	}
	setverdict(pass);
	deactivate(d);
	fp_common_fini();
}

function f_TC_sabm_ua_dcch_sapi3(charstring id) runs on ConnHdlr {
	fp_common_init();
	RSL.clear;
	LAPDM.clear;
	var default d := activate(as_ignore_background());
	if (f_test_sabm_results_in_ua(3, false, 'FEFE'O)) {
		setverdict(fail, "Initial SABM/UA must be on SAPI0, but BTS accepts SAPI=3");
	}
	setverdict(pass);
	deactivate(d);
	fp_common_fini();
}

function f_TC_sabm_ua_dcch_sapi4(charstring id) runs on ConnHdlr {
	fp_common_init();
	RSL.clear;
	LAPDM.clear;
	var default d := activate(as_ignore_background());
	if (f_test_sabm_results_in_ua(4, false, 'FEFE'O)) {
		setverdict(fail, "Initial SABM/UA must be on SAPI0, but BTS accepts SAPI=4");
	}
	setverdict(pass);
	deactivate(d);
	fp_common_fini();
}

testcase TC_sabm_ua_dcch_sapi0() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_sabm_ua_dcch_sapi0));
}

testcase TC_sabm_ua_dcch_sapi0_nopayload() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_sabm_ua_dcch_sapi0_nopayload));
}

testcase TC_sabm_ua_dcch_sapi3() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_sabm_ua_dcch_sapi3));
}

testcase TC_sabm_ua_dcch_sapi4() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_sabm_ua_dcch_sapi4));
}

function f_TC_sabm_contention(charstring id) runs on ConnHdlr {
	var LAPDm_ph_data phd;
	const octetstring payload := '0102030405'O;
	const GsmSapi sapi := 0;
	const boolean use_sacch := false;
	timer T := 5.0;

	fp_common_init();
	RSL.clear;
	LAPDM.clear;

	/* first frame is our real SABM */
	LAPDM.send(t_PH_DATA(sapi, use_sacch, ts_LAPDm_SABM(sapi, c_r:=cr_MO_CMD, p:=false, l3:=payload)));
	/* second frame is a SABM with different payload, which BTS has to ignore according to 8.4.1.4 */
	LAPDM.send(t_PH_DATA(sapi, use_sacch, ts_LAPDm_SABM(sapi, c_r:=cr_MO_CMD, p:=false, l3:='ABCDEF'O)));
	T.start
	alt {
		[] LAPDM.receive(t_PH_DATA(?, use_sacch, tr_LAPDm_UA(sapi, cr_MT_RSP, f:=false, l3:=payload))) { setverdict(pass); repeat; }
		[] LAPDM.receive(t_PH_DATA(?, use_sacch, tr_LAPDm_UA(sapi, cr_MT_RSP, f:=false, l3:=?))) {
			setverdict(fail, "Second SABM was responded to during contention resolution");
			}
		[] RSL.receive {repeat;}
		[] LAPDM.receive { repeat };
		[] T.timeout { }
	}

	fp_common_fini();
}

testcase TC_sabm_contention() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_sabm_contention));
}

/* we test that a re-transmitted SABM with identical payload will result in the retransmission of a
  * UA. This is required during the contention resolution procedure as specified in 8.4.1.4 */
function f_TC_sabm_retransmit(charstring id) runs on ConnHdlr {
	const octetstring payload := '00FEFEDEADBEEF'O;
	fp_common_init();
	RSL.clear;
	LAPDM.clear;
	var default d := activate(as_ignore_background());
	if (not f_test_sabm_results_in_ua(0, false, payload)) {
		setverdict(fail);
	}
	if (not f_test_sabm_results_in_ua(0, false, payload)) {
		setverdict(fail);
	}
	setverdict(pass);
	deactivate(d);
	fp_common_fini();
}

testcase TC_sabm_retransmit() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_sabm_retransmit));
}

/*********************************************************************************
 * Test using both L1CTL/LAPDm and RSL
 *********************************************************************************/

private function fp_common_init() runs on ConnHdlr
{
	/* undo what f_start_handler is doing and pull LAPDm_CT into the loop */
	unmap(self:L1CTL, system:L1CTL);
	f_lapdm_init();
	/* activate the channel on the BTS side */
	f_rsl_chan_act(g_pars.chan_mode, false, {});
	/* activate the channel on the MS side */
	f_switch_dcch({false, mp_trx0_arfcn}, g_chan_nr, 7);
}

private function fp_common_fini() runs on ConnHdlr
{
	f_release_dcch();
	f_rsl_chan_deact();
	f_lapdm_exit();
}

/* Mobile-Originated LAPDm establishment on given Link ID */
private function f_establish_mo(RslLinkId link_id) runs on ConnHdlr
{
	var integer sapi := link_id.sapi;
	var boolean is_sacch := false;
	if (link_id.c == SACCH) {
		is_sacch := true;
	}

	var octetstring l3_mo := f_rnd_octstring(5);

	/* MO Establish Request via LADPm: SAPI = 0, C = 0, P = 1, M = 0, 0 ≤ L ≤ N201.. */
	if (is_sacch) {
		/* no payload permitted, as this is not contention resolution */
		l3_mo := ''O;
		LAPDM.send(t_PH_DATA(0, is_sacch, ts_LAPDm_SABM(sapi, c_r:=cr_MO_CMD, p:=true, l3:=l3_mo)));
		RSL.receive(tr_RSL_EST_IND_NOL3(g_chan_nr, link_id));
	} else {
		LAPDM.send(t_PH_DATA(0, is_sacch, ts_LAPDm_SABM(sapi, c_r:=cr_MO_CMD, p:=true, l3:=l3_mo)));
		RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3_mo));
	}
	/* UA: SAPI = 0, R = 0, F = 1, M = 0, L = L of SABM. */
	LAPDM.receive(t_PH_DATA(0, is_sacch, tr_LAPDm_UA(sapi, cr_MT_RSP, f:=true, l3:=l3_mo)));
}

/* Verify that the BTS is re-transmitting SABM messages after T200 timeout, inspired
   by 3GPP TS 51.010-1 25.2.1.1.2.1 + 25.2.1.2.4 */
private function f_TC_sabm_retransmit_bts(charstring id) runs on ConnHdlr {
	const integer sapi := 3; /* BTS may not establish SAPI=0 outbound */
	fp_common_init();

	LAPDM.clear;
	RSL.send(ts_RSL_EST_REQ(g_chan_nr, ts_RslLinkID_DCCH(sapi)));

	timer T := 8.0;
	var integer sabm_received := 0;
	T.start;
	alt {
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_SABM(sapi, ?, ?, ''O))) {
		sabm_received := sabm_received + 1;
		repeat;
		}
	[] LAPDM.receive { repeat; }
	[] T.timeout { }
	}
	if (sabm_received == 0) {
		setverdict(fail, "No SABM observed at all!");
	} else if (sabm_received != 6) {
		setverdict(fail, "Incorrect number of SABM re-transmissions of observed: ",
			   sabm_received);
	} else {
		setverdict(pass, "Received ", sabm_received, " SABM");
	}

	fp_common_fini();
}
testcase TC_sabm_retransmit_bts() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_sabm_retransmit_bts));
}


type record LapdmNamedFrame {
	charstring name,
	LapdmFrame lapdm
};

/* Test that the BTS will ignore receipt of frames other than a UA when
 * received in response to the SABM frame, inspired from 3GPP TS 51.010-1
 * Section 25.2.1.1.2.3 */
private function f_TC_sabm_invalid_resp2(charstring id, LapdmNamedFrame err_frame) runs on ConnHdlr {
	var integer sapi := err_frame.lapdm.ab.addr.sapi;
	fp_common_init();

	/* Establish Request via RSL; Expect SABM on LAPDm side */
	LAPDM.clear;
	RSL.send(ts_RSL_EST_REQ(g_chan_nr, ts_RslLinkID_DCCH(sapi)));
	alt {
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_SABM(sapi, ?, ?, ''O)));
	[] LAPDM.receive { repeat; }
	}

	/* send erroneous response to SABM */
	LAPDM.send(t_PH_DATA(0, false, err_frame.lapdm));

	/* expect a SABM retransmission of the BTS */
	timer T := 3.0;
	T.start;
	alt {
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_SABM(sapi, ?, ?, ''O))) {
		setverdict(pass);
		}
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_UI(0, ?, ''O))) { repeat; }
	[] LAPDM.receive(t_PH_DATA(0, false, ?)) {
		setverdict(fail, "Received unexpected LAPDm frame instead of SABM after sending ",
			   err_frame.name);
		}
	[] LAPDM.receive { repeat; }
	[] T.timeout {
		setverdict(fail, "Timeout waiting for SABM retransmission after sending ",
			   err_frame.name);
		}
	}

	fp_common_fini();
}
private function f_TC_sabm_invalid_resp(charstring id) runs on ConnHdlr {
	const integer sapi := 3; /* BTS may not establish SAPI=0 outbound */
	var LapdmNamedFrame err_frame[3] := {
		{ "I", valueof(ts_LAPDm_I(sapi, c_r := cr_MO_CMD, p := true, nr := 0, ns := 0,
					  l3 := '01020304'O)) },
		{ "RR", valueof(ts_LAPDm_RR(sapi, c_r := cr_MO_CMD, p := true, nr := 0)) },
		{ "REJ" , valueof(ts_LAPDm_REJ(sapi, c_r := cr_MO_CMD, p := true, nr := 0)) }
	};
	var integer i;

	for (i := 0; i < lengthof(err_frame); i := i+1) {
		f_TC_sabm_invalid_resp2(id, err_frame[i])
	}
}
testcase TC_sabm_invalid_resp() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_sabm_invalid_resp));
}

/* Test that the BTS will not re-transmit SABM frames after receiving a DM response,
 * inspired from 3GPP TS 51.010-1 Section 25.2.1.1.3 */
private function f_TC_sabm_dm(charstring id) runs on ConnHdlr {
	const integer sapi := 3; /* BTS may not establish SAPI=0 outbound */
	fp_common_init();

	/* Establish Request via RSL; Expect SABM on LAPDm side */
	LAPDM.clear;
	RSL.send(ts_RSL_EST_REQ(g_chan_nr, ts_RslLinkID_DCCH(sapi)));
	alt {
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_SABM(sapi, ?, ?, ''O)));
	[] LAPDM.receive { repeat; }
	}

	/* send DM response to SABM */
	RSL.clear;
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_DM(sapi, c_r:=cr_MO_RSP, f:=true)));
	alt {
	[] RSL.receive(tr_RSL_REL_IND(g_chan_nr, tr_RslLinkID_DCCH(sapi)));
	[] RSL.receive { repeat; }
	}

	/* expect no SABM retransmission of the BTS */
	timer T := 3.0;
	T.start;
	alt {
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_SABM(sapi, ?, ?, ''O))) {
		setverdict(fail, "Received unexpected SABM retransmission");
		}
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_UI(0, ?, ''O))) { repeat; }
	[] LAPDM.receive(t_PH_DATA(0, false, ?)) {
		setverdict(fail, "Received unexpected LAPDm frame");
		}
	[] LAPDM.receive { repeat; }
	[] T.timeout {
		setverdict(pass);
		}
	}

	fp_common_fini();
}
testcase TC_sabm_dm() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_sabm_dm));
}

/* Test the full LAPDm establishment while simulating the loss of the initial SABM or UA
 * frame, requiring the BTS to re-transmit one SABM and then following up all the way to
 * dedicated mode; inspired by 3GPP TS 51.010-1 25.2.1.2.2  */
private function f_TC_establish_ign_first_sabm(charstring id) runs on ConnHdlr {
	const integer sapi := 3; /* BTS may not establish SAPI=0 outbound */
	var integer num_sabm := 0;
	var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(sapi));
	timer T := 3.0;

	fp_common_init();

	/* Establish Request via RSL */
	LAPDM.clear;
	RSL.send(ts_RSL_EST_REQ(g_chan_nr, link_id));
	/* Expect two SABM (retransmit) */
	T.start;
	alt {
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_SABM(sapi, ?, ?, ''O))) {
		num_sabm := num_sabm + 1;
		if (num_sabm < 2) {
			repeat;
		}
		}
	[] LAPDM.receive { repeat; }
	}

	/* send UA response to SABM */
	RSL.clear;
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_UA(sapi, c_r:=cr_MO_RSP, f:=true, l3:=''O)));
	alt {
	[] RSL.receive(tr_RSL_EST_CONF(g_chan_nr, link_id));
	[] RSL.receive { repeat; }
	}

	/* Send I frame from BTS to MS */
	var octetstring l3 := f_rnd_octstring(10);
	RSL.send(ts_RSL_DATA_REQ(g_chan_nr, link_id, l3));
	alt {
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_I(sapi, c_r:=cr_MT_CMD, p:=false,
							nr:=0, ns:=0, l3:=l3)));
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_UI(0, ?, ''O))) { repeat; }
	[] LAPDM.receive(t_PH_DATA(0, true, ?)) { repeat; }
	[] LAPDM.receive { setverdict(fail, "Unexpected LAPDm received"); }
	}
	/* Send RR frame in response */
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_RR(sapi, c_r:=cr_MO_RSP, p:=false, nr:=1)));

	/* expect idle UI Frame from BTS */
	alt {
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_UI(0, ?, ''O))) {
		setverdict(pass);
		}
	[] LAPDM.receive(t_PH_DATA(0, true, ?)) { repeat; }
	[] LAPDM.receive { setverdict(fail, "Unexpected LAPDm received"); }
	}

	fp_common_fini();
}
testcase TC_establish_ign_first_sabm() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_establish_ign_first_sabm));
}

/* ignore all SACCH frames */
private altstep as_lapdm_acch() runs on ConnHdlr {
	[] LAPDM.receive(t_PH_DATA(0, true, ?)) { repeat; }
}
/* ignore all DCCH frames */
private altstep as_lapdm_dcch() runs on ConnHdlr {
	[] LAPDM.receive(t_PH_DATA(0, false, ?)) { repeat; }
}
/* ignore all LAPDm idle frames (UI) */
private altstep as_lapdm_idle() runs on ConnHdlr {
	[] LAPDM.receive(t_PH_DATA(0, ?, tr_LAPDm_UI(?, ?, ''O))) { repeat; }
}
/* ignore all measurement reports */
private altstep as_rsl_meas_rep() runs on ConnHdlr {
	[] RSL.receive(tr_RSL_MEAS_RES(g_chan_nr)) { repeat; }
}
/* fail if we receive an RSL ERROR IND */
private altstep as_rsl_fail_err() runs on ConnHdlr {
	var RSL_Message rx_rsl;
	[] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, ?, ?)) {
		setverdict(fail, "Received RSL ERROR IND ", rx_rsl);
	}
}
/* all of the above */
private altstep as_ignore_background(boolean want_dcch := true, boolean ignore_rsl_errors := false) runs on ConnHdlr {
	[want_dcch] as_lapdm_acch();
	[not want_dcch] as_lapdm_dcch();
	[] as_lapdm_idle();
	[] as_rsl_meas_rep();
	[not ignore_rsl_errors] as_rsl_fail_err();
	[ignore_rsl_errors] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, ?, ?)) { repeat;}
}

/* Test the operation of Layer 2 sequence numbering.
 * dedicated mode; inspired by 3GPP TS 51.010-1 25.2.2.1  */
private function f_TC_iframe_seq_and_ack(charstring id) runs on ConnHdlr {
	const integer sapi := 0;
	var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(sapi));
	var octetstring l3 := f_rnd_octstring(18);
	var default d;
	timer T := 3.0;

	fp_common_init();

	/* some common altstep for meas res and other background noise */
	d := activate(as_ignore_background());
	RSL.clear;
	LAPDM.clear;

	f_establish_mo(link_id);

	var integer last_ns_rx := 0;

	for (var integer i := 0; i < 10; i := i+1) {
		var octetstring l3_mo := f_rnd_octstring(12);
		var octetstring l3_mt := f_rnd_octstring(12);
		var LAPDm_ph_data pd;

		log("Starting iteration ", i);
		/* MT I frame */
		RSL.send(ts_RSL_DATA_REQ(g_chan_nr, link_id, l3_mt));
		alt {
		/* SAPI = 0, R = 1, F = 0, M = 0, L = 0. */
		[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_RR(sapi, c_r:=cr_MT_RSP, p:=false,
								 nr:=i mod 8))) {
			log("Ignoring RR in iteration ", i);
			repeat;
			}
		/* SAPI = 0, C = 1, P = 0, M = 0, 0 ≤ L ≤ N201. */
		[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_I(sapi, c_r:=cr_MT_CMD, p:=false,
								nr:=i mod 8, ns:=i mod 8,
								l3:=l3_mt))) -> value pd {
			last_ns_rx := pd.lapdm.ab.ctrl.i.n_s;
			}
		}
		/* respond with MO I-frame: SAPI = 0, C = 0, P = 0, M = 0, 0 <= L <= N201. */
		LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=false,
							  nr:=(last_ns_rx+1)mod 8,
							  ns:=i mod 8, l3 := l3_mo)));
		RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3_mo));
	}
	log("Completed iteration");

	deactivate(d);
	fp_common_fini();
}
testcase TC_iframe_seq_and_ack() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_iframe_seq_and_ack));
}

/* To test that the BTS is able to respond to I frames whilst in the timer recovery state.
 * Inspired by 3GPP TS 51.010-1 25.2.2.2  */

/*
  1) The BTS is brought into the multiple frame established state
  2) The MS sends an L3 Request asking for IMEI to the MS.
  3) The BTS shall respond with a RR frame though this may be incorporated with
     the L3 Response I frame.  The MS does not respond to the I frame.
  4) The BTS shall wait for expiry of timer T200 and then repeat the I frame but
     with the P bit set to 1.
  5) The MS then sends a valid L3 Request I frame asking for IMEI which
     does not acknowledge receipt of the I frame from the BTS.
On the FACCH the BTS may send an RR frame acknowledging the I frame.
  6) The BTS shall repeat the I frame, this frame will acknowledge receipt of
     the second I frame from the MS.
  7) The MS then acknowledges receipt of the MS I frame by sending a RR frame.
  8) The BTS shall send the next I frame. The MS acknowledges this I frame.
*/
private function f_TC_iframe_timer_recovery(charstring id) runs on ConnHdlr {
	const integer sapi := 0;
	var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(sapi));
	var default d;
	timer T := 3.0;

	fp_common_init();

	/* some common altstep for meas res and other background noise */
	d := activate(as_ignore_background());
	RSL.clear;
	LAPDM.clear;

	var octetstring l3_mo := f_rnd_octstring(12);
	var octetstring l3_mt := f_rnd_octstring(12);

	/*  1) The BTS is brought into the multiple frame established state */

	/* MO Establish Request via LADPm: SAPI = 0, C = 0, P = 1, M = 0, 0 ≤ L ≤ N201.. */
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_SABM(sapi, c_r:=cr_MO_CMD, p:=true, l3:=l3_mo)));
	RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3_mo));
	/* UA: SAPI = 0, R = 0, F = 1, M = 0, L = L of SABM. */
	LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_UA(sapi, cr_MT_RSP, f:=true, l3:=l3_mo)));

	/* 2) The MS sends an L3 Request to the BTS */
	l3_mo := f_rnd_octstring(18);
	/* SAPI = 0, C = 1, P = 0, M = 0, 0 ≤ L ≤ N201, N(S) = 0, N(R) = 0.  * */
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=false,
						  nr:=0, ns:=0, l3:=l3_mo)));
	RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3_mo));
	/* 3) The BTS shall respond with a RR frame though this may be incorporated with
	   the L3 Response I frame.  The MS does not respond to the I frame. */
	RSL.send(ts_RSL_DATA_REQ(g_chan_nr, link_id, l3_mt));
	alt {
	/* SAPI = 0, R = 1, F = 0, M = 0, L = 0, N(R) = 1. */
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_RR(sapi, c_r:=cr_MT_RSP, p:=false, nr:=1))) {
		repeat;
		}
	/* SAPI = 0, C = 0, P = 0, M = 0, 0 ≤ L ≤ N201, N(R) = 1, N(S) = 0 */
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_I(sapi, c_r:=cr_MT_CMD, p:=false,
							nr:=1, ns:=0, l3:=l3_mt)));
	}

	/* 4) The BTS shall wait for expiry of timer T200 and then repeat the I frame but
	      with the P bit set to 1. */
	/* SAPI = 0, C = 0, P = 1, M = 0, 0 ≤ L ≤ N201, N(R) = 1, N(S) = 0. * */
	LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_I(sapi, c_r:=cr_MT_CMD, p:=true,
						     nr:=1, ns:=0, l3:=l3_mt)));

	/* 5) The MS then sends a valid L3 Request I frame asking for IMEI which
	      does not acknowledge receipt of the I frame from the BTS. */
	/* SAPI = 0, C = 1, P = 0, M = 0, 0 ≤ L ≤ N201, N(S) = 1, N(R) = 0.  * */
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=false,
						  nr:=0, ns:=1, l3 := l3_mo)));
	RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3_mo));
	alt {
	/* On the FACCH the BTS may send an RR frame acknowledging the I frame. */
	/* SAPI = 0, R = 1, F = 0, M = 0, L = 0, N(R) = 2. */
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_RR(sapi, c_r:=cr_MT_RSP, p:=false, nr:=2))) {
		repeat;
		}
	/* 6) The BTS shall repeat the I frame, this frame will acknowledge
	      receipt of the second I frame from the MS. */
	/* SAPI = 0, C = 0, P = 1, M = 0, 0 ≤ L ≤ N201, N(R) = 2, N(S) = 0. * */
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_I(sapi, c_r:=cr_MT_CMD, p:=true,
						     nr:=2, ns:=0, l3:=l3_mt)));
	}

	/* 7) The MS then acknowledges receipt of the BTS I frame by sending a RR * frame. */
	/* SAPI = 0, R = 0, F = 1, 0, M = 0, L = 0, N(R) = 1 */
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_RR(sapi, c_r:=cr_MO_RSP, p:=true, nr:=1)));

	/* 8) The BTS shall send the next I frame. The MS acknowledges this I frame. */
	l3_mt := f_rnd_octstring(16);
	RSL.send(ts_RSL_DATA_REQ(g_chan_nr, link_id, l3_mt));
	/* SAPI = 0, C = 0, P = 0, M = 0, 0 ≤ L ≤ N201, N(R) = 2, N(S) = 1 */
	LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_I(sapi, c_r:=cr_MT_CMD, p:=false,
						     nr:=2, ns:=1, l3:=l3_mt)));
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_RR(sapi, c_r:=cr_MO_RSP, p:=true, nr:=2)));

	deactivate(d);
	fp_common_fini();
}
testcase TC_iframe_timer_recovery() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_iframe_timer_recovery));
}

/* 25.2.6.1  ns sequence error
sends wrong N(S), expects REJ, sends wrong N(S) with P=1, expects REJ with F=1 */
private function f_TC_ns_seq_error(charstring id) runs on ConnHdlr {
	const integer sapi := 0;
	var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(sapi));
	var default d;
	timer T := 3.0;

	fp_common_init();

	/* some common altstep for meas res and other background noise */
	d := activate(as_ignore_background(ignore_rsl_errors := true));
	RSL.clear;
	LAPDM.clear;

	var octetstring l3_mo := f_rnd_octstring(12);
	var octetstring l3_mt := f_rnd_octstring(12);

	/*  1) The BTS is brought into the multiple frame established state */

	/* MO Establish Request via LADPm: SAPI = 0, C = 0, P = 1, M = 0, 0 ≤ L ≤ N201.. */
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_SABM(sapi, c_r:=cr_MO_CMD, p:=true, l3:=l3_mo)));
	RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3_mo));
	/* UA: SAPI = 0, R = 0, F = 1, M = 0, L = L of SABM. */
	LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_UA(sapi, cr_MT_RSP, f:=true, l3:=l3_mo)));

	/* 2) The MS sends an L3 Request to the BTS */
	l3_mo := f_rnd_octstring(18);
	/* SAPI = 0, C = 1, P = 0, M = 0, 0 ≤ L ≤ N201, N(S) = 0, N(R) = 0.  * */
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=false,
						  nr:=0, ns:=0, l3:=l3_mo)));
	RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3_mo));
	/* 3) The BTS shall respond with a RR frame though this may be incorporated with
	   the L3 Response I frame. */
	RSL.send(ts_RSL_DATA_REQ(g_chan_nr, link_id, l3_mt));
	alt {
	/* SAPI = 0, R = 1, F = 0, M = 0, L = 0, N(R) = 1. */
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_RR(sapi, c_r:=cr_MT_RSP, p:=false, nr:=1))) {
		repeat;
		}
	/* SAPI = 0, C = 0, P = 0, M = 0, 0 ≤ L ≤ N201, N(R) = 1, N(S) = 0 */
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_I(sapi, c_r:=cr_MT_CMD, p:=false,
							nr:=1, ns:=0, l3:=l3_mt)));
	}

	/* 4) The MS shall then send an I frame containing Identity Request with incorrect N(S)
	but correctly acknowledging the MS's I frame; P bit set to zero.  */
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=false,
						  nr:=1, ns:=0, l3:=l3_mo)));

	/* no rsl data ind  due to wrong ns */

	/* The BTS shall send a REJ frame. */
	timer T1 := 2.0;
	T1.start;
	alt{
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_REJ(sapi, c_r:=cr_MT_RSP, p:=false, nr:=1)));
	[] T1.timeout{ setverdict(fail, "Missing first REJ")}
	}

	f_sleep(2.0); // T200

	/* The MS shall, after T200, send another I frame with incorrect N(S), P bit set to 1 this time. */
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=true,
						  nr:=1, ns:=0, l3:=l3_mo)));

	/* The BTS shall respond with a REJ, F bit set to 1. */
	T1.start;
	alt{
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_REJ(sapi, c_r:=cr_MT_RSP, p:=true, nr:=1)));
	[] T1.timeout{ setverdict(fail, "Missing second REJ")}
	}

	deactivate(d);
	fp_common_fini();
	setverdict(pass);
}

testcase TC_ns_seq_error() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_ns_seq_error));
}

/* 25.2.6.2 nr sequence error */
private function f_TC_nr_seq_error(charstring id) runs on ConnHdlr {
	const integer sapi := 0;
	var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(sapi));
	var default d;
	var integer n201 := 20;
	if (link_id.c == SACCH) {
		n201 := 18;
	}

	fp_common_init();

	/* some common altstep for meas res and other background noise */
	d := activate(as_ignore_background(ignore_rsl_errors := true));
	RSL.clear;
	LAPDM.clear;

	var octetstring l3_mo := f_rnd_octstring(12);
	var octetstring l3_mt := f_rnd_octstring(12);

	/*  1) The BTS is brought into the multiple frame established state */

	/* MO Establish Request via LADPm: SAPI = 0, C = 0, P = 1, M = 0, 0 ≤ L ≤ N201.. */
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_SABM(sapi, c_r:=cr_MO_CMD, p:=true, l3:=l3_mo)));
	RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3_mo));
	/* UA: SAPI = 0, R = 0, F = 1, M = 0, L = L of SABM. */
	LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_UA(sapi, cr_MT_RSP, f:=true, l3:=l3_mo)));

	/* 2) The MS shall send an I frame containing an information field of length N201 and an
	 incorrect receive sequence number. */
	l3_mo := f_rnd_octstring(n201);
	/* SAPI = 0, C = 1, P = 0, M = 0,  L = N201, N(S) = 0, N(R) = 1.  * */
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=false,
						  nr:=1, ns:=0, l3:=l3_mo)));

	/* The BTS may: a)   send a DISC frame within N200×T200; */
	/* DISC SAPI = 0, C = 0, P = 1, M = 0, L = 0. */
	timer T1 := 2.0;
	T1.start;
	alt{
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_DISC(sapi, c_r:=cr_MT_CMD, p:=true)));
	[] T1.timeout{ setverdict(fail, "Missing DISC from BTS")}
	}

	/* a) the MS shall respond with a UA frame.
	SAPI = 0, R = 0, F = 1, M = 0, L = 0. */
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_UA(sapi, c_r:=cr_MO_CMD, f:=true, l3:=l3_mo)));

	deactivate(d);
	fp_common_fini();
	setverdict(pass);
}

testcase TC_nr_seq_error() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_nr_seq_error));
}

private function f_TC_rec_invalid_frame_txrx(integer sapi, LapdmFrame x, integer line_nr) runs on ConnHdlr {
	LAPDM.send(t_PH_DATA(0, false, x));
	f_sleep(2.0); // T200
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_RR(sapi, c_r:=cr_MO_CMD, p:=true, nr:=0)));
	timer T1 := 2.0;
	T1.start;
	alt {
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_RR(sapi, c_r:=cr_MT_RSP, p:=true , nr := 0))) { T1.stop; }
	[] T1.timeout{ Misc_Helpers.f_shutdown(__BFILE__, line_nr, fail, "Missing LAPDm_RR RSP"); }
	}
}

/* 25.2.7     Test on receipt of invalid frames
sends a bunch of different invalid frames, expects the BTS to ignore all of them */
private function f_TC_rec_invalid_frame(charstring id) runs on ConnHdlr {
	const integer sapi := 0;
	var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(sapi));
	var default d;
	timer T := 3.0;

	fp_common_init();

	/* some common altstep for meas res and other background noise */
	d := activate(as_ignore_background(ignore_rsl_errors := true));
	RSL.clear;
	LAPDM.clear;

	var octetstring l3_mo := f_rnd_octstring(12);
	var octetstring l3_mt := f_rnd_octstring(12);

	/*  1) The BTS is brought into the multiple frame established state */

	/* MO Establish Request via LADPm: SAPI = 0, C = 0, P = 1, M = 0, 0 ≤ L ≤ N201.. */
	LAPDM.send(t_PH_DATA(0, false, ts_LAPDm_SABM(sapi, c_r:=cr_MO_CMD, p:=true, l3:=l3_mo)));
	T.start
	alt {
	[] RSL.receive(tr_RSL_EST_IND(g_chan_nr, link_id, l3_mo)) {}
	[] T.timeout{ Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Missing RSL EST IND"); }
	}
	alt {
	/* UA: SAPI = 0, R = 0, F = 1, M = 0, L = L of SABM. */
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_UA(sapi, cr_MT_RSP, f:=true, l3:=l3_mo))) { T.stop; }
	[] T.timeout{ Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Missing LAPDm UA RSP"); }
	}

	/* 1: One RR frame: SAPI = 0, R = 0, F = 0, M = 0, L > 0, N(R) = 1.
	RR frame with the Length indicator greater than zero and a faulty N(R); */
	var LapdmFrame x:= valueof(ts_LAPDm_RR(sapi, c_r:=cr_MO_CMD, p:=false, nr:=1));
	x.ab.payload := f_rnd_octstring(5);
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 3: One REJ frame: SAPI = 0, R = 0, F = 0, M = 0, L = 0, N(R) = 1, EA = 0.
	EJ frame with the EA bit set to zero and a faulty N(R); */
	x:= valueof(ts_LAPDm_REJ(sapi, c_r:=cr_MO_CMD, p:=false, nr:=1));
	x.ab.addr.ea := false;
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 4: One SABM frame: SAPI = 0, C = 1, P = 1, M = 0, L = 0, EL = 0.
	SABM frame with the EL bit set to zero; */
	l3_mo := ''O;
	x:= valueof(ts_LAPDm_SABM(sapi, c_r:=cr_MO_CMD, p:=true, l3:=l3_mo));
	x.ab.el := 0;
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 5: One DM frame: SAPI = 0, R = 0, F = 1, M = 0, L > 0.
	DM frame with the Length indicator greater than zero;*/
	x:= valueof(ts_LAPDm_DM(sapi, c_r:=cr_MO_CMD, f:=true));
	x.ab.payload := f_rnd_octstring(5);
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 6: One DISC frame: SAPI = 0, C = 1, P = 1, M = 1, L = 0.
	DISC frame with the M bit set to 1; */
	x:= valueof(ts_LAPDm_DISC(sapi, c_r:=cr_MO_CMD, p:=true));
	x.ab.m := true;
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 7: One UA frame: SAPI = 0, R = 0, F = 0, M = 0, L = 0, EA = 0.
	UA frame with the EA bit set to zero*/
	x:= valueof(ts_LAPDm_UA(sapi, c_r:=cr_MO_CMD, f:=false, l3:=''O));
	x.ab.addr.ea := false;
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 8: One I frame: SAPI = 0, C = 1, P = 0, M = 0, L > N201, N(R) = 0, N(S) = 6.
	I frame with the Length indicator greater than N201;*/
	x:= valueof(ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=true, nr := 0, ns := 6, l3 := f_rnd_octstring(25)))
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 9: One I frame: SAPI = 0, C = 1, P = 0, M = 1, L < N201, N(R) = 0, N(S) = 7.
	I frame with the M bit set to 1 and the Length indicator less than N201;*/
	x:= valueof(ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=true, nr := 0, ns := 7, l3 := f_rnd_octstring(5)))
	x.ab.m := true;
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 10: One RR frame: SAPI = 0, C = 1, P = 1, M = 0, L = 0, N(R) = 0. */
	x:= valueof(ts_LAPDm_RR(sapi, c_r:=cr_MO_CMD, p:=true, nr:=0));
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);

	/* command frames with correct Address and Length indicator field and a non-implemented control field */
	/* 12: One command frame with Control Field = xxx1 1101. */
	x:= valueof(ts_LAPDm_RR(sapi, c_r:=cr_MO_CMD, p:=false, nr:=1));
	x.ab.ctrl.other := bit2int('00011101'B);
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 13: One command frame with Control field = xxx1 1011. */
	x:= valueof(ts_LAPDm_RR(sapi, c_r:=cr_MO_CMD, p:=false, nr:=1));
	x.ab.ctrl.other := bit2int('00011011'B);
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 14: One command frame with Control field = xxx1 0111. */
	x:= valueof(ts_LAPDm_RR(sapi, c_r:=cr_MO_CMD, p:=false, nr:=1));
	x.ab.ctrl.other := bit2int('00010001'B);
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 15: One command frame with Control field = 01x1 1111. */
	x:= valueof(ts_LAPDm_RR(sapi, c_r:=cr_MO_CMD, p:=false, nr:=1));
	x.ab.ctrl.other := bit2int('01011111'B);
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 16: One command frame with Control field = 1xx1 1111. */
	x:= valueof(ts_LAPDm_RR(sapi, c_r:=cr_MO_CMD, p:=false, nr:=1));
	x.ab.ctrl.other := bit2int('10011111'B);
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 17: One command frame with Control field = 0011 0011. */
	x:= valueof(ts_LAPDm_RR(sapi, c_r:=cr_MO_CMD, p:=false, nr:=1));
	x.ab.ctrl.other := bit2int('00110011'B);
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);
	/* 18: One command frame with Control field = 1xx1 0011. */
	x:= valueof(ts_LAPDm_RR(sapi, c_r:=cr_MO_CMD, p:=false, nr:=1));
	x.ab.ctrl.other := bit2int('10010011'B);
	f_TC_rec_invalid_frame_txrx(0, x, __LINE__);

	deactivate(d);
	fp_common_fini();
	setverdict(pass);
}

testcase TC_rec_invalid_frame() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	pars.t_guard := 60.0;
	f_testmatrix_each_chan(pars, refers(f_TC_rec_invalid_frame));
}

type record LapdmDlConfig {
	integer n201,
	integer t200
};

type record LapdmDlState {
	integer v_s,
	integer v_a,
	integer v_r
};

template (value) LapdmDlState t_init_LapdmDlState := {
	v_s := 0,
	v_a := 0,
	v_r := 0
}

private function inc_mod8(inout integer v)
{
	v := (v + 1) mod 8;
}

private function f_lapdm_transceive_mo(inout LapdmDlState dls, RslLinkId link_id, octetstring l3)
runs on ConnHdlr {
	var LAPDm_ph_data pd;
	var integer offset := 0;
	var integer n201 := 20;
	var boolean is_sacch := false;
	if (link_id.c == SACCH) {
		n201 := 18;
		is_sacch := true;
	}

	while (offset < lengthof(l3)) {
		var integer remain_len := lengthof(l3) - offset;
		var integer seg_len := remain_len;
		if (remain_len > n201) {
			seg_len := n201;
		}
		var octetstring segment := substr(l3, offset, seg_len);
		var boolean more;
		if (offset + lengthof(segment) < lengthof(l3)) {
			more := true;
		} else {
			more := false;
		}
		/* send the next segment */
		LAPDM.send(t_PH_DATA(0, is_sacch,
				     ts_LAPDm_I(link_id.sapi, c_r:=cr_MO_CMD, p:=false,
						nr:=dls.v_a, ns:=dls.v_s, l3:=segment, m:=more)));
		inc_mod8(dls.v_s);
		offset := offset + lengthof(segment);

		/* wait for it to be acknowledged */
		alt {
		[] LAPDM.receive(t_PH_DATA(0, is_sacch, tr_LAPDm_RR(link_id.sapi, c_r:=cr_MT_RSP,
								    p:=false, nr:=(dls.v_s) mod 8)));
		[] as_ignore_background(not is_sacch);
		[] LAPDM.receive(t_PH_DATA(0, is_sacch, ?)) -> value pd {
			setverdict(fail, "received unexpected LAPDm ", pd);
			repeat;
			}
		[] LAPDM.receive(t_PH_DATA(0, ?, ?)) { repeat; }
		[offset < lengthof(l3)] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, ?)) {
			setverdict(fail, "received RSL DATA IND before message complete");
			}
		}
	}

	timer T := 1.0;
	T.start;
	alt {
	[] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3)) {
		setverdict(pass);
		}
	[] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, ?)) {
		setverdict(fail, "Received RSL DATA IND with wrong payload");
		}
	[] T.timeout {
		setverdict(fail, "Timeout waiting for RSL DATA IND of de-segmented message");
		}
	}
}

/* Section 5.8.5 of TS 04.06 */
const integer c_TS0406_MAX_L3_OCTETS := 251;

/* test segmentation and de-segmentation (concatenation) of a large message in uplink
 * on specified SAPI/channel */
private function f_TC_segm_concat(charstring id, RslLinkId link_id) runs on ConnHdlr {
	var integer sapi := link_id.sapi;
	var boolean is_sacch := false;
	if (link_id.c == SACCH) {
		is_sacch := true;
	}
	var default d;
	timer T := 3.0;

	fp_common_init();

	/* some common altstep for meas res and other background noise */
	d := activate(as_ignore_background(not is_sacch));
	RSL.clear;
	LAPDM.clear;

	f_establish_mo(link_id);

	var octetstring l3_mo := f_rnd_octstring(c_TS0406_MAX_L3_OCTETS);

	deactivate(d);

	var LapdmDlState dls := valueof(t_init_LapdmDlState);
	f_lapdm_transceive_mo(dls, link_id, l3_mo);

	fp_common_fini();
}
private function f_TC_segm_concat_dcch(charstring id) runs on ConnHdlr {
	f_TC_segm_concat(id, valueof(ts_RslLinkID_DCCH(0)));
}
private function f_TC_segm_concat_sacch(charstring id) runs on ConnHdlr {
	f_TC_segm_concat(id, link_id :=valueof(ts_RslLinkID_SACCH(0)));
}
/* test mobile-originated segmentation/de-segmentation on DCCH */
testcase TC_segm_concat_dcch() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_segm_concat_dcch));
}
/* test mobile-originated segmentation/de-segmentation on SACCH */
testcase TC_segm_concat_sacch() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_segm_concat_sacch));
}

/* TS 04.06 Section 5.8.2.1 */
private function f_n200_by_chan_nr(RslChannelNr chan_nr, RslLinkId link_id) return integer {
	/* SACCH irrespective of physical channel type */
	if (match(link_id, tr_RslLinkID_SACCH(?))) {
		return 5;
	}
	/* DCCH below */
	select (chan_nr) {
	case (t_RslChanNr_SDCCH4(?, ?)) { return 23; }
	case (t_RslChanNr_SDCCH8(?, ?)) { return 23; }
	case (t_RslChanNr_Bm(?)) { return 34; }
	case (t_RslChanNr_Lm(?, ?)) { return 29; }
	}
	setverdict(fail, "Unknown chan_nr ", chan_nr, " or link_id ", link_id);
	return -1;
}

/* Test if there are exactly N200+1 transmissions of I frames; inspired by 25.2.4.1 */
private function f_TC_t200_n200(charstring id) runs on ConnHdlr {
	var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
	var integer sapi := link_id.sapi;
	var boolean is_sacch := false;
	if (link_id.c == SACCH) {
		is_sacch := true;
	}
	var integer n200 := f_n200_by_chan_nr(g_chan_nr, link_id);
	var integer num_retrans := 0;
	timer T := 3.0;
	var default d;

	fp_common_init();

	/* some common altstep for meas res and other background noise */
	d := activate(as_ignore_background(true));
	RSL.clear;
	LAPDM.clear;

	f_establish_mo(link_id);

	var octetstring l3_mt := f_rnd_octstring(20);
	RSL.send(ts_RSL_DATA_REQ(g_chan_nr, link_id, l3_mt));
	/* first transmission, P = 0 */
	LAPDM.receive(t_PH_DATA(0, is_sacch, tr_LAPDm_I(sapi, c_r:=cr_MT_CMD, p:=false,
							nr:=0, ns:=0, l3:=l3_mt)));
	deactivate(d);

	alt {
	/* re-transmission, P = 1 */
	[] LAPDM.receive(t_PH_DATA(0, is_sacch,
				tr_LAPDm_I(sapi, c_r:=cr_MT_CMD, p:=true, nr:=0, ns:=0, l3:=l3_mt))) {
		num_retrans := num_retrans + 1;
		if (num_retrans < n200) {
			repeat;
		} else if (num_retrans == n200) {
			T.start; /* wait for some more time if there are more retransmissions */
			repeat;
		} else {
			/* break */
		}
		}
	[] LAPDM.receive(t_PH_DATA(0, false, tr_LAPDm_I(sapi, ?, ?, ?, ?, ?))) {
		setverdict(fail, "Received unexpected I frame");
		}
	[not is_sacch] as_lapdm_acch();
	[is_sacch] as_lapdm_dcch();
	[] as_lapdm_idle();
	[] as_rsl_meas_rep();
	[num_retrans == n200] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, '01'O)) {
		/* break */
		}
	[] T.timeout {
		setverdict(fail, "Missing RSL RLL ERROR INDICATION");
		}
	}

	if (num_retrans == n200) {
		setverdict(pass, "Received ", num_retrans, " on channel ", g_chan_nr, " link ", link_id);
	} else if (num_retrans < n200) {
		setverdict(fail, "Too few retransmissions (", num_retrans, "); N200=", n200,
			   " on channel ", g_chan_nr, " link ", link_id);
	}

	fp_common_fini();
}
testcase TC_t200_n200() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_t200_n200));
}

/* Ensure BTS repeats RR frame after retransmitting I frame to emulate RR loss;
   Inspired by TS 51.010-1 25.2.4.3 */
private function f_TC_rr_response_frame_loss(charstring id) runs on ConnHdlr {
	var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
	var integer sapi := link_id.sapi;
	var boolean is_sacch := false;
	if (link_id.c == SACCH) {
		is_sacch := true;
	}
	timer T := 3.0;
	var default d;

	fp_common_init();

	/* some common altstep for meas res and other background noise */
	d := activate(as_ignore_background(true));
	RSL.clear;
	LAPDM.clear;

	f_establish_mo(link_id);

	var octetstring l3_mo := f_rnd_octstring(10);
	/* Send an I frame to the BTS: SAPI = 0, C = 1, P = 0, M = 0, L = 3, N(S) = 0, N(R) = 0 */
	LAPDM.send(t_PH_DATA(0, is_sacch, ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=false, nr:=0, ns:=0,
						     l3:=l3_mo)));
	RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3_mo));
	/* SAPI = 0, R = 1, F = 0, M = 0, L = 0, N(R) = 1. */
	LAPDM.receive(t_PH_DATA(0, is_sacch, tr_LAPDm_RR(sapi, c_r:=cr_MT_RSP, p:=false, nr:=1)));

	/* Re-send I frame: SAPI = 0, C = 1, P = 1, M = 0, L = 3, N(S) = 0, N(R) = 0. */
	LAPDM.send(t_PH_DATA(0, is_sacch, ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=true, nr:=0, ns:=0,
						     l3:=l3_mo)));

	T.start;
	alt {
	/* RR: SAPI = 0, R = 1, F = 1, M = 0, L = 0, N(R) = 1. */
	[] LAPDM.receive(t_PH_DATA(0, is_sacch, tr_LAPDm_RR(sapi, c_r:=cr_MT_RSP, p:=true, nr:=1))) {
		setverdict(pass);
		}
	/* REJ: SAPI = 0, R = 1, F = 1, M = 0, L = 0, N(R) = 1. */
	[] LAPDM.receive(t_PH_DATA(0, is_sacch, tr_LAPDm_REJ(sapi, c_r:=cr_MT_RSP, p:=true, nr:=1))) {
		setverdict(pass);
		}
	[] T.timeout {
		setverdict(fail, "Timeout waiting for RR or REJ");
		}
	}

	deactivate(d);

	fp_common_fini();
}
testcase TC_rr_response_frame_loss() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_rr_response_frame_loss));
}

/* Ensure BTS ignores I frames with wrong C/R bit; Inspired by TS 51.010-1 25.2.5.1 */
private function f_TC_incorrect_cr(charstring id) runs on ConnHdlr {
	var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
	var integer sapi := link_id.sapi;
	var boolean is_sacch := false;
	if (link_id.c == SACCH) {
		is_sacch := true;
	}
	timer T := 3.0;
	var default d;

	fp_common_init();

	/* some common altstep for meas res and other background noise */
	d := activate(as_ignore_background(true));
	RSL.clear;
	LAPDM.clear;

	f_establish_mo(link_id);

	var octetstring l3_mo := f_rnd_octstring(10);
	/* Send an I frame to the BTS: SAPI = 0, C = 0, P = 1, M = 0, L = 3, N(S) = 0, N(R) = 0 */
	LAPDM.send(t_PH_DATA(0, is_sacch, ts_LAPDm_I(sapi, c_r:=cr_MO_RSP, p:=true, nr:=0, ns:=0,
						     l3:=l3_mo)));
	T.start;
	alt {
	[] RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3_mo)) {
		setverdict(fail, "BTS didn't ignore I frame with wrong C/R bit");
		}
	[] RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, '0C'O)) {
		repeat;
		}
	/* ensure BTS still sends idle frames */
	[] as_lapdm_idle() {
		setverdict(pass, "still sending idle frames");
		}
	[] T.timeout {}
	}

	/* Send RR command P=1 */
	LAPDM.send(t_PH_DATA(0, is_sacch, ts_LAPDm_RR(sapi, c_r:=cr_MO_CMD, p:=true, nr:=0)));

	/* The BTS shall respond with a RR response, F bit set to 1. */
	LAPDM.receive(t_PH_DATA(0, is_sacch, tr_LAPDm_RR(sapi, c_r:=cr_MT_RSP, p:=true, nr:=0)));

	deactivate(d);

	fp_common_fini();
}
testcase TC_incorrect_cr() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_incorrect_cr));
}

/* test that the BTS will take no action when it receives an SABM frame with the C bit set wrong (R)
   Inspired by TS 51.010-1 25.2.5.2 */
private function f_TC_sabm_incorrect_c(charstring id) runs on ConnHdlr {
	var RslLinkId link_id := valueof(ts_RslLinkID_DCCH(0));
	var integer sapi := link_id.sapi;
	var boolean is_sacch := false;
	if (link_id.c == SACCH) {
		is_sacch := true;
	}
	timer T := 3.0;
	var default d;

	fp_common_init();

	/* some common altstep for meas res and other background noise */
	d := activate(as_ignore_background(true));
	RSL.clear;
	LAPDM.clear;

	f_establish_mo(link_id);

	/* Send I-frame SAPI = 0, C = 1, P = 0, M = 0, L = 3, N(S) = 0, N(R) = 0 */
	var octetstring l3_mo := '010203'O;
	LAPDM.send(t_PH_DATA(0, is_sacch, ts_LAPDm_I(sapi, c_r:=cr_MO_CMD, p:=false, nr:=0, ns:=0,
						     l3:=l3_mo)));
	/* Expect RR SAPI = 0, R = 1, F = 0, M = 0, L = 0, N(R) = 1 */
	LAPDM.receive(t_PH_DATA(0, is_sacch, tr_LAPDm_RR(sapi, c_r:=cr_MT_RSP, p:=false, nr:=1)));
	RSL.receive(tr_RSL_DATA_IND(g_chan_nr, link_id, l3_mo));
	/* Send SABM SAPI = 0, C = 0, P = 1, M = 0, L = 0 */
	LAPDM.send(t_PH_DATA(0, is_sacch, ts_LAPDm_SABM(sapi, c_r:=cr_MO_RSP, p:=true, l3:=''O)));
	/* Expect RSL ERR IND */
	RSL.receive(tr_RSL_ERROR_IND(g_chan_nr, link_id, '0C'O));
	/* Expect fill frame C = 0, P = 0, M = 0, L = 0 */
	LAPDM.receive(t_PH_DATA(0, is_sacch, tr_LAPDm_UI(0, ?, ''O)));
	/* Send RR command (P=1) SAPI = 0, C = 1, P = 1, M = 0, L = 0, N(R) = 0 */
	LAPDM.send(t_PH_DATA(0, is_sacch, ts_LAPDm_RR(sapi, c_r:=cr_MO_CMD, p:=true, nr:=0)));
	/* Expect RR response (F=1) SAPI = 0, R = 1, F = 1, M = 0, L = 0, N(R) = 1 */
	LAPDM.receive(t_PH_DATA(0, is_sacch, tr_LAPDm_RR(sapi, c_r:=cr_MT_RSP, p:=true, nr:=1)));

	deactivate(d);

	fp_common_fini();
}
testcase TC_sabm_incorrect_c() runs on test_CT {
	var ConnHdlrPars pars := valueof(t_Pars(t_RslChanNr_Bm(1), ts_RSL_ChanMode_SIGN));
	f_testmatrix_each_chan(pars, refers(f_TC_sabm_incorrect_c));
}

control {
	execute(TC_sabm_ua_dcch_sapi0());
	execute(TC_sabm_ua_dcch_sapi0_nopayload());
	execute(TC_sabm_ua_dcch_sapi3());
	execute(TC_sabm_ua_dcch_sapi4());
	execute(TC_sabm_contention());
	execute(TC_sabm_retransmit());
	execute(TC_sabm_retransmit_bts());
	execute(TC_sabm_invalid_resp());
	execute(TC_sabm_dm());
	execute(TC_establish_ign_first_sabm());
	execute(TC_iframe_seq_and_ack());
	execute(TC_iframe_timer_recovery());
	execute(TC_ns_seq_error());
	execute(TC_nr_seq_error());
	execute(TC_rec_invalid_frame());
	execute(TC_segm_concat_dcch());
	execute(TC_segm_concat_sacch());
	execute(TC_t200_n200());
	execute(TC_rr_response_frame_loss());
	execute(TC_incorrect_cr());
	execute(TC_sabm_incorrect_c());
}

}