aboutsummaryrefslogtreecommitdiffstats
path: root/library/BSSMAP_Templates.ttcn
blob: adfcc9e20843f4651bf418f73c63b84fad8b5a6f (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
module BSSMAP_Templates {

/* BSSMAP Templates, building on top of BSSAP_Types from Ericsson.
 *
 * (C) 2017 by Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 */

import from General_Types all;
import from Osmocom_Types all;
import from GSM_Types all;
import from BSSAP_Types all;

type integer BssmapCause;
type integer SpeechVersion;
type integer Channel;
type integer ChannelMode;
type octetstring oldToNewBSSIEs;

/* 48.008 3.2.2.5 - this actually belongs to BSSAP_Types.ttcn */
type enumerated myBSSMAP_Cause {
	/* 000 / 001: Normal event */
	GSM0808_CAUSE_RADIO_INTERFACE_MESSAGE_FAILURE			('0000000'B),
	GSM0808_CAUSE_RADIO_INTERFACE_FAILURE				('0000001'B),
	GSM0808_CAUSE_UPLINK_QUALITY					('0000010'B),
	GSM0808_CAUSE_UPLINK_STRENGTH					('0000011'B),
	GSM0808_CAUSE_DOWNLINK_QUALITY					('0000100'B),
	GSM0808_CAUSE_DOWNLINK_STRENGTH					('0000101'B),
	GSM0808_CAUSE_DISTANCE						('0000110'B),
	GSM0808_CAUSE_O_AND_M_INTERVENTION				('0000111'B),
	GSM0808_CAUSE_RESPONSE_TO_MSC_INVOCATION			('0001000'B),
	GSM0808_CAUSE_CALL_CONTROL					('0001001'B),
	GSM0808_CAUSE_RADIO_INTERFACE_FAILURE_REVERSION			('0001010'B),
	GSM0808_CAUSE_HANDOVER_SUCCESSFUL				('0001011'B),
	GSM0808_CAUSE_BETTER_CELL					('0001100'B),
	GSM0808_CAUSE_DIRECTED_RETRY					('0001101'B),
	GSM0808_CAUSE_JOINED_GROUP_CALL_CHANNEL				('0001110'B),
	GSM0808_CAUSE_TRAFFIC						('0001111'B),
	GSM0808_CAUSE_REDUCE_LOAD_IN_SERVING_CELL			('0010000'B),
	GSM0808_CAUSE_TRAFFIC_LOAD_IN_TGT_HIGHER_THAN_IN_SRC_CELL	('0010001'B),
	GSM0808_CAUSE_RELOCATION_TRIGGERED				('0010010'B),
	GSM0808_CAUSE_REQUSTED_OPT_NOT_AUTHORISED			('0010100'B),
	GSM0808_CAUSE_ALT_CHAN_CONFIG_REQUESTED				('0010101'B),
	GSM0808_CAUSE_RESP_TO_INT_HO_ENQ_MSG				('0010110'B),
	GSM0808_CAUSE_INT_HO_ENQUIRY_REJECT				('0010111'B),
	GSM0808_CAUSE_REDUNDANCY_LEVEL_NOT_ADEQUATE			('0011000'B),
	/* reserved */
	/* 010: Resource unavailable */
	GSM0808_CAUSE_EQUIPMENT_FAILURE					('0100000'B),
	GSM0808_CAUSE_NO_RADIO_RESOURCE_AVAILABLE			('0100001'B),
	GSM0808_CAUSE_RQSTED_TERRESTRIAL_RESOURCE_UNAVAILABLE		('0100010'B),
	GSM0808_CAUSE_CCCH_OVERLOAD					('0100011'B),
	GSM0808_CAUSE_PROCESSOR_OVERLOAD				('0100100'B),
	GSM0808_CAUSE_BSS_NOT_EQUIPPED					('0100101'B),
	GSM0808_CAUSE_MS_NOT_EQUIPPED					('0100110'B),
	GSM0808_CAUSE_INVALID_CELL					('0100111'B),
	GSM0808_CAUSE_TRAFFIC_LOAD					('0101000'B),
	GSM0808_CAUSE_PREEMPTION					('0101001'B),
	GSM0808_CAUSE_DTM_HO_SGSN_FAILURE				('0101010'B),
	GSM0808_CAUSE_DTM_HO_PS_ALLOC_FAILURE				('0101011'B),
	/* reserved */
	/* 011: Service or option not available, but implemented */
	GSM0808_CAUSE_RQSTED_TRANSCODING_RATE_ADAPTION_UNAVAILABLE	('0110000'B),
	GSM0808_CAUSE_CIRCUIT_POOL_MISMATCH				('0110001'B),
	GSM0808_CAUSE_SWITCH_CIRCUIT_POOL				('0110010'B),
	GSM0808_CAUSE_RQSTED_SPEECH_VERSION_UNAVAILABLE			('0110011'B),
	GSM0808_CAUSE_LSA_NOT_ALLOWED					('0110100'B),
	GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_UNAVAIL			('0110101'B),
	GSM0808_CAUSE_REQ_A_IF_TYPE_UNAVAIL				('0110110'B),
	GSM0808_CAUSE_INVALID_CSG_CELL					('0110111'B),
	/* reserved */
	/* 100: Service or option not implemented or currently disabled */
	GSM0808_CAUSE_REQ_REDUND_LEVEL_NOT_AVAIL			('0111111'B),
	GSM0808_CAUSE_CIPHERING_ALGORITHM_NOT_SUPPORTED			('1000000'B),
	GSM0808_CAUSE_GERAN_IU_MODE_FAILURE				('1000001'B),
	GSM0808_CAUSE_INC_RELOC_NOT_SUPP_DT_PUESBINE_FEATURE		('1000010'B),
	GSM0808_CAUSE_ACCESS_RESTRICTED_DUE_TO_SHARED_NETWORKS		('1000011'B),
	GSM0808_CAUSE_REQ_CODEC_TYPE_OR_CONFIG_NOT_SUPP			('1000100'B),
	GSM0808_CAUSE_REQ_A_IF_TYPE_NOT_SUPP				('1000101'B),
	GSM0808_CAUSE_REQ_REDUND_LVL_NOT_SUPP				('1000110'B),
	/* reserved */
	/* 101: Invalid message */
	GSM0808_CAUSE_TERRESTRIAL_CIRCUIT_ALREADY_ALLOCATED		('1010000'B),
	GSM0808_CAUSE_INVALID_MESSAGE_CONTENTS				('1010001'B),
	GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING		('1010010'B),
	GSM0808_CAUSE_INCORRECT_VALUE					('1010011'B),
	GSM0808_CAUSE_UNKNOWN_MESSAGE_TYPE				('1010100'B),
	GSM0808_CAUSE_UNKNOWN_INFORMATION_ELEMENT			('1010101'B),
	GSM0808_CAUSE_DTM_HO_INVALID_PS_IND				('1010110'B),
	GSM0808_CAUSE_CALL_ID_ALREADY_ALLOC				('1010111'B),
	/* reserved */
	/* 110: protocol error */
	GSM0808_CAUSE_PROTOCOL_ERROR_BETWEEN_BSS_AND_MSC		('1100000'B),
	GSM0808_CAUSE_VGCS_VBS_CALL_NON_EXISTANT			('1100001'B),
	GSM0808_CAUSE_DTM_HO_TIMER_EXPIRY				('1100010'B)
} with { variant "FIELDLENGTH(7)" };

template PDU_BSSAP ts_BSSAP_BSSMAP := {
	discriminator := '0'B,
	spare := '0000000'B,
	dlci := omit,
	lengthIndicator := 0,	/* overwritten by codec */
	pdu := {
		bssmap := ?
	}
}

template PDU_BSSAP tr_BSSAP_BSSMAP := {
	discriminator := '0'B,
	spare := '0000000'B,
	dlci := *,
	lengthIndicator := ?,
	pdu := {
		bssmap := ?
	}
}

template PDU_BSSAP ts_BSSAP_DTAP(octetstring dtap, template OCT1 dlci := omit) := {
	discriminator := '1'B,
	spare := '0000000'B,
	dlci := dlci,
	lengthIndicator := 0,	/* overwritten by codec */
	pdu := {
		dtap := dtap
	}
}

template PDU_BSSAP tr_BSSAP_DTAP := {
	discriminator := '1'B,
	spare := '0000000'B,
	dlci := *,
	lengthIndicator := ?,
	pdu := {
		dtap := ?
	}
}

template (value) BSSMAP_IE_Cause ts_BSSMAP_IE_Cause(BssmapCause val) := {
	elementIdentifier := '04'O,
	lengthIndicator := 0,
	causeValue := int2bit(val, 7),
	extensionCauseValue := '0'B,
	spare1 := omit
}

template (value) BSSMAP_IE_SpeechVersion ts_BSSMAP_IE_SpeechVersion(SpeechVersion val) := {
	elementIdentifier := '40'O,
	speechVersionIdentifier := int2bit(val, 7),
	spare1_1 := '0'B
}

template (value) BSSMAP_IE_CurrentChannelType1 ts_BSSMAP_IE_CurrentChannelType1(Channel c, ChannelMode cm) := {
	elementIdentifier := '31'O,
	channel := int2bit(c, 4),
	channelMode := int2bit(cm, 4)
}

template (value) BSSMAP_IE_OldToNewBSSInfo ts_BSSMAP_IE_OldToNewBSSInfo(oldToNewBSSIEs val) := {
	elementIdentifier := '3A'O,
	lengthIndicator := 0,	/* overwritten by codec */
	oldToNewBSSIEs := val
}

template (value) PDU_BSSAP ts_BSSMAP_Reset(BssmapCause cause) modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			reset := {
				messageType := '30'O,
				cause := ts_BSSMAP_IE_Cause(cause),
				a_InterfaceSelectorForReset := omit
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_Reset modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			reset := {
				messageType := '30'O,
				cause := ?,
				a_InterfaceSelectorForReset := *
			}
		}
	}
}

template (value) PDU_BSSAP ts_BSSMAP_ResetAck modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			resetAck := {
				messageType := '31'O,
				a_InterfaceSelectorForReset := omit
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_ResetAck modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			resetAck := {
				messageType := '31'O,
				a_InterfaceSelectorForReset := *
			}
		}
	}
}

template BSSMAP_IE_CellIdentifier ts_BSSMAP_IE_CellID := {
	elementIdentifier := '05'O,
	lengthIndicator := 0,
	cellIdentifierDiscriminator := '0000'B,
	spare1_4 := '0000'B,
	cellIdentification := ?
}

type uint16_t BssmapLAC;
type uint16_t BssmapCI;

template BSSMAP_IE_CellIdentifier ts_CellId_CGI(hexstring mcc, hexstring mnc, BssmapLAC lac, BssmapCI ci)
modifies ts_BSSMAP_IE_CellID := {
	cellIdentification := {
		cI_CGI := ts_BSSMAP_CI_CGI(mcc, mnc, lac, ci)
	}
}

template BSSMAP_IE_CellIdentifier ts_CellID_LAC_CI(BssmapLAC lac, BssmapCI ci)
modifies ts_BSSMAP_IE_CellID := {
	cellIdentification := {
		cI_LAC_CI := {
			lac := int2oct(lac, 2),
			ci := int2oct(ci, 2)
		}
	}
}

template BSSMAP_IE_CellIdentifier ts_CellId_CI(BssmapCI ci)
modifies ts_BSSMAP_IE_CellID := {
	cellIdentification := {
		cI_CI := int2oct(ci, 2)
	}
}

template BSSMAP_IE_CellIdentifier ts_CellId_none
modifies ts_BSSMAP_IE_CellID := {
	cellIdentification := {
		cI_noCell := ''O
	}
}


template BSSMAP_IE_Layer3Information ts_BSSMAP_IE_L3Info(octetstring l3info) := {
	elementIdentifier := '17'O,
	lengthIndicator := 0,
	layer3info := l3info
}

template BSSMAP_IE_Layer3Information tr_BSSMAP_IE_L3Info(template octetstring l3info) := {
	elementIdentifier := '17'O,
	lengthIndicator := ?,
	layer3info := l3info
}


template PDU_BSSAP ts_BSSMAP_ComplL3(BSSMAP_IE_CellIdentifier cell_id, octetstring l3_info)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			completeLayer3Information := {
				messageType := '57'O,
				cellIdentifier := cell_id,
				layer3Information := ts_BSSMAP_IE_L3Info(l3_info),
				chosenChannel := omit,
				lSAIdentifier := omit,
				aPDU := omit,
				codecList := omit,
				redirectAttemptFlag := omit,
				sendSequenceNumber := omit,
				iMSI := omit
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_ComplL3(template octetstring l3_info := ?,
				     template BSSMAP_IE_CellIdentifier cell_id := ?)
modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			completeLayer3Information := {
				messageType := '57'O,
				cellIdentifier := cell_id,
				layer3Information := tr_BSSMAP_IE_L3Info(l3_info),
				chosenChannel := *,
				lSAIdentifier := *,
				aPDU := *,
				codecList := *,
				redirectAttemptFlag := *,
				sendSequenceNumber := *,
				iMSI := *
			}
		}
	}
}

template BSSMAP_IE_CellIdentifierList ts_BSSMAP_IE_CidList(BSSMAP_FIELD_CellIdentificationList cid_list) := {
	elementIdentifier := '1A'O,
	lengthIndicator := 0, /* overwritten */
	cellIdentifierDiscriminator := '0000'B, /* overwritten */
	spare1_4 := '0000'B,
	cellIdentificationList := cid_list
}

template PDU_BSSAP ts_BSSMAP_HandoReq(BssmapCause cause, BSSMAP_FIELD_CellIdentificationList cid_list)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			handoverRequired := {
				messageType := '11'O,
				cause := ts_BSSMAP_IE_Cause(cause),
				responseRequest := omit,
				cellIdentifierList := ts_BSSMAP_IE_CidList(cid_list),
				circuitPoolList := omit,
				currentChannelType1 := omit,
				speechVersion := omit,
				queueingIndicator := omit,
				oldToNewBSSInfo := omit,
				sourceToTargetRNCTransparentInfo := omit,
				sourceToTargetRNCTransparentInfoCDMA := omit,
				gERANClassmark := omit,
				talkerPriority := omit,
				speechCodec := omit,
				cSG_Identifier := omit
			}
		}
	}
}

const OCT1 ChRate_ANY := '00'O;
const OCT1 ChRate_TCHF	:= '08'O;
const OCT1 ChRate_TCHH	:= '09'O;
const OCT1 ChRate_TCHForH_Fpref := '0A'O;
const OCT1 ChRate_TCHForH_Hpref := '0B'O;
const OCT1 ChRate_TCHForH_Fpref_nochg := '1A'O;
const OCT1 ChRate_TCHForH_Hpref_nochg := '1B'O;
const OCT1 ChRate_TCHForH := '0F'O;
const OCT1 ChRate_TCHForH_nochg := '1F'O;

const OCT1 Spdi_TCHF_FR  := '01'O;
const OCT1 Spdi_TCHF_EFR := '11'O;
const OCT1 Spdi_TCHF_AMR := '21'O;
const OCT1 Spdi_TCHH_HR  := '05'O;
const OCT1 Spdi_TCHH_AMR := '25'O;

template (value) BSSMAP_IE_ChannelType ts_BSSMAP_IE_ChannelType := {
	elementIdentifier := '0B'O,	/* overwritten */
	lengthIndicator := 0,		/* overwritten */
	speechOrDataIndicator := '0001'B,	/* speech */
	spare1_4 := '0000'B,
	channelRateAndType := ChRate_TCHF,
	speechId_DataIndicator := Spdi_TCHF_FR
}

template (value) BSSMAP_IE_ChannelType ts_BSSMAP_IE_ChannelTypeCTM modifies ts_BSSMAP_IE_ChannelType := {
	speechOrDataIndicator := '0100'B	/* speech + CTM */
}

template (value) BSSMAP_IE_ChannelType ts_BSSMAP_IE_ChannelTypeCSD := {
	elementIdentifier := '0B'O,	/* overwritten */
	lengthIndicator := 0,		/* overwritten */
	speechOrDataIndicator := '0010'B,	/* data */
	spare1_4 := '0000'B,
	channelRateAndType := ChRate_TCHF,
	speechId_DataIndicator := '10'O	/* 9600 bps / transparent */
}

template (value) BSSMAP_IE_ChannelType ts_BSSMAP_IE_ChannelTypeSIGNAL := {
	elementIdentifier := '0B'O,	/* overwritten */
	lengthIndicator := 0,		/* overwritten */
	speechOrDataIndicator := '0011'B,	/* data */
	spare1_4 := '0000'B,
	channelRateAndType := ChRate_ANY,
	speechId_DataIndicator := '00'O	/* spare */
}

template (value) BSSMAP_IE_EncryptionInformation ts_BSSMAP_IE_EncrInfo(OCT8 kc, OCT1 algs := '05'O) := {
	elementIdentifier := '0A'O,
	lengthIndicator := 0,	/* overwritten */
	permittedAlgorithms := algs,
	key := kc
}

template BSSMAP_IE_EncryptionInformation tr_BSSMAP_IE_EncrInfo(template OCT8 kc := ?, template OCT1 algs := ?) := {
	elementIdentifier := '0A'O,
	lengthIndicator := ?,	/* overwritten */
	permittedAlgorithms := algs,
	key := kc
}



template (value) BSSMAP_IE_CircuitIdentityCode ts_BSSMAP_IE_CIC(uint11_t span, uint5_t ts) := {
	elementIdentifier := '01'O,	/* overwritten */
	cicHigh := bit2oct(substr(int2bit(span, 11) << 5, 0, 8)),
	cicLow := bit2oct((substr(int2bit(span, 11), 8, 3) << 5) & int2bit(ts, 5))
}

template (value) BSSMAP_IE_AoIP_TransportLayerAddress ts_BSSMAP_IE_AoIP_TLA(BSSMAP_FIELD_IPAddress addr,
									    uint16_t udp_port,
									    integer len) := {
	elementIdentifier := '7C'O,
	lengthIndicator := len, /* overwritten */
	ipAddress := addr,
	uDPPortValue := udp_port
}
template (value) BSSMAP_IE_AoIP_TransportLayerAddress ts_BSSMAP_IE_AoIP_TLA4(OCT4 ip, uint16_t pt) :=
							ts_BSSMAP_IE_AoIP_TLA({ipv4:=ip}, pt, 6);
template (value) BSSMAP_IE_AoIP_TransportLayerAddress ts_BSSMAP_IE_AoIP_TLA6(OCT16 ip, uint16_t pt) :=
							ts_BSSMAP_IE_AoIP_TLA({ipv6:=ip}, pt, 18);

template (value) BSSMAP_IE_KC128 ts_BSSMAP_IE_Kc128(OCT16 kc128) := {
	elementIdentifier := '83'O,
	kC128_Value := kc128
}

/* 3.2.2.103 */
template (value) BSSMAP_FIELD_CodecElement ts_CodecBase := {
	codecType := GSM_FR,
	tF := '0'B,
	pT := '0'B,
	pI := '0'B,
	fI := '1'B,
	extendedCodecType := omit,
	s0_7 := omit,
	s8_15 := omit
}
template (value) BSSMAP_FIELD_CodecElement ts_CodecFR modifies ts_CodecBase := {
	codecType := GSM_FR
}
template (value) BSSMAP_FIELD_CodecElement ts_CodecEFR modifies ts_CodecBase := {
	codecType := GSM_EFR
}
template (value) BSSMAP_FIELD_CodecElement ts_CodecHR modifies ts_CodecBase := {
	codecType := GSM_HR
}
template (value) BSSMAP_FIELD_CodecElement ts_CodecAMR_F modifies ts_CodecBase := {
	codecType := FR_AMR,
	s0_7 :=  '11111111'B,
	s8_15 := '01010111'B	/* S11, S13 and S15 are reserved and coded with zeroes */
}
template (value) BSSMAP_FIELD_CodecElement ts_CodecAMR_H modifies ts_CodecBase := {
	codecType := HR_AMR,
	s0_7 :=  '00111111'B,
	s8_15 := '00000111'B	/* S6 - S7 and S11 – S15 are reserved and coded with zeroes */
}
template BSSMAP_IE_SpeechCodecList ts_BSSMAP_IE_CodecList(template BSSMAP_FIELD_CodecElements elem) := {
	elementIdentifier := '7D'O,
	lengthIndicator := 0, /* overwritten */
	codecElements := valueof(elem)
}

template PDU_BSSAP
ts_BSSMAP_AssignmentReq(template BSSMAP_IE_CircuitIdentityCode cic := omit,
			template BSSMAP_IE_AoIP_TransportLayerAddress aoip := omit)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			assignmentRequest := {
				messageType :='01'O,	/* overwritten */
				channelType := ts_BSSMAP_IE_ChannelType,
				layer3HeaderInfo := omit,
				priority := omit,
				circuitIdentityCode := cic,
				downLinkDTX_Flag := omit,
				interferenceBandToBeUsed := omit,
				classmarkInformationType2 := omit,
				groupCallReference := omit,
				talkerFlag := omit,
				configurationEvolutionIndication := omit,
				lsaAccesControlSuppression := omit,
				serviceHandover := omit,
				encryptionInformation := omit,
				talkerPriority := omit,
				aoIPTransportLayer := aoip,
				codecList := omit,
				callIdentifier := omit,
				kC128 := omit,
				globalCallReference := omit,
				lCLS_Configuration := omit,
				lCLS_ConnectionStatusControl := omit,
				lCLS_CorrelationNotNeeded := omit
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_AssignmentReq(template BSSMAP_IE_CircuitIdentityCode cic := *,
					   template BSSMAP_IE_AoIP_TransportLayerAddress aoip := *)
modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			assignmentRequest := {
				messageType :='01'O,	/* overwritten */
				channelType := ?,
				layer3HeaderInfo := *,
				priority := *,
				circuitIdentityCode := cic,
				downLinkDTX_Flag := *,
				interferenceBandToBeUsed := *,
				classmarkInformationType2 := *,
				groupCallReference := *,
				talkerFlag := *,
				configurationEvolutionIndication := *,
				lsaAccesControlSuppression := *,
				serviceHandover := *,
				encryptionInformation := *,
				talkerPriority := *,
				aoIPTransportLayer := aoip,
				codecList := *,
				callIdentifier := *,
				kC128 := *,
				globalCallReference := *,
				lCLS_Configuration := *,
				lCLS_ConnectionStatusControl := *,
				lCLS_CorrelationNotNeeded := *
			}
		}
	}
}

template PDU_BSSAP
ts_BSSMAP_AssignmentComplete(template BSSMAP_IE_CircuitIdentityCode cic := omit,
			     template BSSMAP_IE_AoIP_TransportLayerAddress aoip := omit)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			assignmentComplete := {
				messageType :='02'O,	/* overwritten */
				rR_Cause := omit,
				circuitIdentityCode := cic,
				cellIdentifier := omit,
				chosenChannel := omit,
				chosenEncryptionAlgorithm := omit,
				circuitPool := omit,
				speechVersion := omit,
				lSAIdentifier := omit,
				talkerPriority := omit,
				aoIPTransportLayer := aoip,
				speechCodec := omit,
				codecList := omit,
				lCLS_BSS_Status := omit
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_AssignmentComplete(template BSSMAP_IE_CircuitIdentityCode cic := *,
						template BSSMAP_IE_AoIP_TransportLayerAddress aoip := *)
modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			assignmentComplete := {
				messageType := '02'O,	/* overwritten */
				rR_Cause := *,
				circuitIdentityCode := cic,
				cellIdentifier := *,
				chosenChannel := *,
				chosenEncryptionAlgorithm := *,
				circuitPool := *,
				speechVersion := *,
				lSAIdentifier := *,
				talkerPriority := *,
				aoIPTransportLayer := aoip,
				speechCodec := *,
				codecList := *,
				lCLS_BSS_Status := *
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_AssignmentFail modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			assignmentFailure := {
				messageType := '03'O,	/* overwritten */
				rR_Cause := *,
				circuitPool := *,
				circuitPoolList := *,
				talkerPriority := *,
				codecList := *
			}
		}
	}
}


template (value) PDU_BSSAP ts_BSSMAP_ClearCommand(BssmapCause cause)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			clearCommand := {
				messageType := '20'O,	/* overwritten */
				layer3HeaderInfo := omit,
				cause := ts_BSSMAP_IE_Cause(cause),
				cSFB_Indication := omit
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_ClearCommand modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			clearCommand := {
				messageType := '20'O,	/* overwritten */
				layer3HeaderInfo := *,
				cause := ?,
				cSFB_Indication := *
			}
		}
	}
}

template (value) PDU_BSSAP ts_BSSMAP_ClearComplete
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			clearComplete := {
				messageType := '21'O	/* overwritten */
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_ClearComplete modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			clearComplete := {
				messageType := '21'O
			}
		}
	}
}

template (value) PDU_BSSAP ts_BSSMAP_ClearRequest(BssmapCause cause)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			clearRequest := {
				messageType := '22'O,	/* overwritten */
				cause := ts_BSSMAP_IE_Cause(cause)
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_ClearRequest modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			clearRequest := {
				messageType := '22'O,	/* overwritten */
				cause := ?
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_HandoverRequired modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			handoverRequired := {
				messageType := '11'O
			}
		}
	}
}

template (value) PDU_BSSAP ts_BSSMAP_HandoverCommand(octetstring layer3info)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			handoverCommand := {
				messageType := '13'O,
				layer3Information := {
					elementIdentifier := '17'O,
					lengthIndicator := 0,
					layer3info := layer3info
				},
				cellIdentifier := omit,
				newBSSToOldBSSInfo := omit,
				talkerPriority := omit
			}
		}
	}
}

template PDU_BSSAP ts_BSSMAP_HandoverRequest(
		template BSSMAP_IE_CircuitIdentityCode cic := omit,
		template BSSMAP_IE_AoIP_TransportLayerAddress aoip_tla := omit,
		template BSSMAP_IE_CellIdentifier cell_id_target := ts_CellID_LAC_CI(1, 0),
		template BSSMAP_IE_CellIdentifier cell_id_source := ts_CellID_LAC_CI(1, 1)
		)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			handoverRequest := {
				messageType := '10'O,
				channelType := ts_BSSMAP_IE_ChannelType,
				encryptionInformation :=
					ts_BSSMAP_IE_EncrInfo('0000000000000000'O,'01'O),
				classmarkInformationType := {
					classmarkInformationType1 := {
						elementIdentifier := '1D'O,
						rf_PowerCapability := '000'B,
						a5_1 := '0'B,
						esind := '0'B,
						revisionLevel := '10'B,
						spare1_1 := '0'B
					}
					},
				cellIdentifierSource := cell_id_source,
				priority := omit,
				circuitIdentityCode := cic,
				downLinkDTX_Flag := omit,
				cellIdentifierTarget := cell_id_target,
				interferenceBandToBeUsed := omit,
				cause := omit,
				classmarkInformationType3 := omit,
				currentChannelType1 := omit,
				speechVersion := omit,
				groupCallReference := omit,
				talkerFlag := omit,
				configurationEvolutionIndication := omit,
				chosenEncryptionAlgorithm := omit,
				oldToNewBSSInfo := omit,
				lSAInformation := omit,
				lSAAccessControlSuppression := omit,
				serviceHandover := omit,
				iMSI_bssmap := omit,
				sourceToTargetRNCTransparentInfo := omit,
				sourceToTargetRNCTransparentInfoCDMA := omit,
				sNAAccessInformation := omit,
				talkerPriority := omit,
				aoIPTransportLayer := aoip_tla,
				codecList := omit,
				callIdentifier := omit,
				kC128 := omit,
				globalCallReference := omit,
				lCLS_Configuration := omit,
				connectionStatusControl := omit
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_HandoverRequestAcknowledge(template octetstring layer3info)
modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			handoverRequestAck := {
				messageType := '12'O,
				layer3Information := {
					elementIdentifier := '17'O,
					lengthIndicator := ?,
					layer3info := layer3info
				}
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_HandoverDetect
modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			handoverDetect := {
				messageType := '1B'O,
				talkerPriority := *
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_HandoverComplete
modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			handoverComplete := {
				messageType := '14'O,
				rR_Cause := *,
				talkerPriority := *,
				speechCodec := *,
				codecList := *,
				chosenEncryptionAlgorithm := *,
				chosenChannel := *,
				lCLS_BSS_Status := *
			}
		}
	}
}

template BSSMAP_IE_IMSI ts_BSSMAP_Imsi(hexstring imsi_digits) := {
	elementIdentifier := '08'O,
	lengthIndicator := 0, /* overwritten */
	typeOfIdentity := '001'B, /* IMSI */
	oddEvenIndicator := f_hex_is_odd_length(imsi_digits),
	digits := imsi_digits
}

template BSSMAP_IE_IMSI tr_BSSMAP_Imsi(template hexstring imsi_digits) := {
	elementIdentifier := '08'O,
	lengthIndicator := ?, /* overwritten */
	typeOfIdentity := '001'B, /* IMSI */
	oddEvenIndicator := ?,
	digits := imsi_digits
}

template BSSMAP_FIELD_CellIdentificationList ts_BSSMAP_CIL_noCell := {
	cIl_noCell := ''O
}

private function f_enc_mcc_mnc(GsmMcc mcc, GsmMnc mnc) return OCT3 {
	if (lengthof(mnc) == 2) {
		return hex2oct(mcc[1] & mcc[0] & 'F'H & mcc[2] & mnc[1] & mnc[0]);
	} else {
		return hex2oct(mcc[1] & mcc[0] & mnc[2] & mcc[2] & mnc[1] & mnc[0]);
	}
}

template BSSMAP_FIELD_CellIdentification_CGI ts_BSSMAP_CI_CGI(GsmMcc mcc, GsmMnc mnc, GsmLac lac, GsmCellId ci) := {
	mcc_mnc := f_enc_mcc_mnc(mcc, mnc),
	lac := int2oct(lac, 2),
	ci := int2oct(ci, 2)
}

template BSSMAP_FIELD_CellIdentification_LAC_CI ts_BSSMAP_CI_LAC_CI(GsmLac lac, GsmCellId ci) := {
	lac := int2oct(lac, 2),
	ci := int2oct(ci, 2)
}

template BSSMAP_FIELD_CellIdentification_LAI ts_BSSMAP_CI_LAI(GsmMcc mcc, GsmMnc mnc, GsmLac lac) := {
	mcc_mnc := f_enc_mcc_mnc(mcc, mnc),
	lac := int2oct(lac, 2)
}

template OCT2 ts_BSSMAP_CI_CI(GsmCellId ci) := int2oct(ci, 2);
template OCT2 ts_BSSMAP_CI_LAC(GsmLac lac) := int2oct(lac, 2);

template BSSMAP_FIELD_CellIdentification_PLMN_LAC_RNC
ts_BSSMAP_CI_PLMN_LAC_RNC(GsmMcc mcc, GsmMnc mnc, GsmLac lac, uint16_t rnc_id) := {
	mcc_mnc := f_enc_mcc_mnc(mcc, mnc),
	lac := int2oct(lac, 2),
	rncId := int2oct(rnc_id, 2)
}

template BSSMAP_FIELD_CellIdentification_LAC_RNC ts_BSSMAP_CI_LAC_RNC(GsmLac lac, uint16_t rnc_id) := {
	lac := int2oct(lac, 2),
	rncId := int2oct(rnc_id, 2)
}

template BSSMAP_IE_ChannelNeeded ts_BSSMAP_IE_ChanNeeded(BIT2 chneed) := {
	elementIdentifier := '24'O,
	channel := chneed,
	spare := '000000'B
}

template BSSMAP_IE_TMSI ts_BSSMAP_IE_TMSI(OCT4 tmsi) := {
	elementIdentifier := '09'O,
	lengthIndicator := 4,
	tmsiOctets := tmsi
};

template BSSMAP_IE_TMSI tr_BSSMAP_IE_TMSI(template OCT4 tmsi) := {
	elementIdentifier := '09'O,
	lengthIndicator := 4,
	tmsiOctets := tmsi
};

private function f_tmsi_or_omit(template OCT4 tmsi) return template BSSMAP_IE_TMSI {
	var template BSSMAP_IE_TMSI ret;
	if (ispresent(tmsi)) {
		ret := ts_BSSMAP_IE_TMSI(valueof(tmsi));
	} else {
		ret := omit;
	}
	return ret;
}

template PDU_BSSAP ts_BSSMAP_Paging(hexstring imsi_digits,
					template BSSMAP_FIELD_CellIdentificationList cid_list,
					template OCT4 tmsi := omit,
					template BSSMAP_IE_ChannelNeeded chneed := omit)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			paging := {
				messageType := '52'O,
				iMSI := ts_BSSMAP_Imsi(imsi_digits),
				tMSI := f_tmsi_or_omit(tmsi),
				cellIdentifierList := ts_BSSMAP_IE_CidList(valueof(cid_list)),
				channelNeeded := chneed,
				eMLPP_Priority := omit,
				pagingInformation := omit /* only VGCS/VBS flag */
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_Paging(template hexstring imsi_digits := ?,
					template OCT4 tmsi := *,
					template BSSMAP_IE_ChannelNeeded chneed := *)
modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			paging := {
				messageType := '52'O,
				iMSI := tr_BSSMAP_Imsi(imsi_digits),
				tMSI := tr_BSSMAP_IE_TMSI(tmsi) ifpresent,
				cellIdentifierList := ?,
				channelNeeded := chneed,
				eMLPP_Priority := omit,
				pagingInformation := omit /* only VGCS/VBS flag */
			}
		}
	}
}


template PDU_BSSAP ts_BSSMAP_CipherModeCmd(OCT1 alg, OCT8 key)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			cipherModeCommand := {
				messageType := '53'O,
				layer3HeaderInfo := omit,
				encryptionInformation := ts_BSSMAP_IE_EncrInfo(key, alg),
				cipherResponseMode := omit,
				kC128 := omit
			}
		}
	}
}

template PDU_BSSAP ts_BSSMAP_CipherModeCmdKc128(OCT1 alg, OCT8 key, OCT16 kc128)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			cipherModeCommand := {
				messageType := '53'O,
				layer3HeaderInfo := omit,
				encryptionInformation := ts_BSSMAP_IE_EncrInfo(key, alg),
				cipherResponseMode := omit,
				kC128 := { '83'O, kc128 }
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_CipherModeCmd(template OCT1 alg, template OCT8 key)
modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			cipherModeCommand := {
				messageType := '53'O,
				layer3HeaderInfo := *,
				encryptionInformation := tr_BSSMAP_IE_EncrInfo(key, alg),
				cipherResponseMode := *,
				kC128 := *
			}
		}
	}
}

template PDU_BSSAP ts_BSSMAP_CipherModeCompl(OCT1 alg)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			cipherModeComplete := {
				messageType := '55'O,
				layer3MessageContents := omit,
				chosenEncryptionAlgorithm := {
					elementIdentifier := '2C'O,
					algorithmIdentifier := alg
				}
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_CipherModeCompl(template OCT1 alg := ?) modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			cipherModeComplete := {
				messageType := '55'O,
				layer3MessageContents := *,
				chosenEncryptionAlgorithm := {
					elementIdentifier := '2C'O,
					algorithmIdentifier := alg
				}
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_CipherModeRej modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			cipherModeReject := {
				messageType := '59'O,
				cause  := ?
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_ClassmarkReq modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			classmarkRequest := {
				messageType := '58'O,
				talkerPriority := *
			}
		}
	}
}

template BSSMAP_IE_ClassmarkInformationType2 ts_CM2_default := {
	elementIdentifier := '12'O,
	lengthIndicator := 0,	/* overwritten */
	/* CM1 */
	rf_PowerCapability := '010'B,	/* class3 */
	a5_1 := '0'B,			/* supported */
	esind := '1'B,			/* early classmark supported */
	revisionLevel := '10'B,		/* R99 */
	spare1_1 := '0'B,
	/* CM2 */
	fc := '1'B,			/* E-GSM support */
	vgcs := '0'B,
	vbs := '0'B,
	sm_Capability := '1'B,
	ss_ScreenIndicator := '00'B,
	ps_Capability := '1'B,
	spare2_1 := '0'B,
	classmarkInformationType2_oct5 := {
		a5_2 := '0'B,		/* not available */
		a5_3 := '1'B,		/* available */
		cmsp := '0'B,		/* not supported */
		solsa := '0'B,		/* not suported */
		ucs2 := '0'B,		/* GSM alphabet preferred */
		lcsvacap := '0'B,	/* not supported */
		spare := '0'B,
		cm3 := '0'B		/* no CM3 */
	}
}

template PDU_BSSAP ts_BSSMAP_ClassmarkUpd(template BSSMAP_IE_ClassmarkInformationType2 cm2 := ts_CM2_default,
					  template BSSMAP_IE_ClassmarkInformationType3 cm3 := omit)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			classmarkUpdate := {
				messageType := '54'O,
				classmarkInformationType2 := cm2,
				classmarkInformationType3 := cm3,
				talkerPriority := omit
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_ClassmarkUpd(template BSSMAP_IE_ClassmarkInformationType2 cm2 := *,
					  template BSSMAP_IE_ClassmarkInformationType3 cm3 := *)
modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			classmarkUpdate := {
				messageType := '54'O,
				classmarkInformationType2 := cm2,
				classmarkInformationType3 := cm3,
				talkerPriority := *
			}
		}
	}
}

template PDU_BSSAP ts_BSSMAP_ClassmarkRequest
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			classmarkRequest := {
				messageType := '58'O,
				talkerPriority := omit
			}
		}
	}
}

/* return Layer3 octetstring inside BSSAP PDU */
function f_bssap_extract_l3(PDU_BSSAP bssap) return template octetstring {
	if (ischosen(bssap.pdu.bssmap)) {
		var PDU_BSSMAP bssmap := bssap.pdu.bssmap;
		if (ischosen(bssmap.completeLayer3Information)) {
			return bssmap.completeLayer3Information.layer3Information.layer3info;
		} else if (ischosen(bssmap.handoverRequestAck)) {
			return bssmap.handoverRequestAck.layer3Information.layer3info;
		} else if (ischosen(bssmap.handoverCommand)) {
			return bssmap.handoverCommand.layer3Information.layer3info;
		} else if (ischosen(bssmap.uplinkRequest)) {
			return bssmap.uplinkRequest.layer3Information.layer3info;
		} else if (ischosen(bssmap.uplinkRequestConfirmation)) {
			return bssmap.uplinkRequestConfirmation.layer3Information.layer3info;
		} else if (ischosen(bssmap.uplinkApplicationData)) {
			return bssmap.uplinkApplicationData.layer3Information.layer3info;
		} else if (ischosen(bssmap.rerouteCommand)) {
			return bssmap.rerouteCommand.initialLayer3Information.layer3info;
		} else {
			return omit;
		}
	} else {
		return bssap.pdu.dtap;
	}
}

/* TS 29.205 B.2.1.9 */
template (value) GlobalCallReferenceValue ts_GCR(octetstring net_id, OCT2 node_id, OCT5 cref_id) := {
	networkIDLengthIndicator := 0, /* overwritten */
	networkID := net_id,
	nodeIDLengthIndicator := 0, /* overwritten */
	nodeID := node_id,
	callReferenceIDLengthIndicator := 0, /* overwritten */
	callReferenceID := cref_id
}
template GlobalCallReferenceValue tr_GCR(template octetstring net_id,
				    template OCT2 node_id,
				    template OCT5 cref_id) := {
	networkIDLengthIndicator := ?,
	networkID := net_id,
	nodeIDLengthIndicator := ?,
	nodeID := node_id,
	callReferenceIDLengthIndicator := ?,
	callReferenceID := cref_id
}

/* TS 47.008 3.2.2.115 */
template (value) BSSMAP_IE_GlobalCallReference ts_BSSMAP_IE_GCR(template (value) GlobalCallReferenceValue gcr) := {
	elementIdentifier := '89'O,
	lengthIndicator := 0, /* overwritten */
	globalCallReferenceValue := gcr
}
template BSSMAP_IE_GlobalCallReference tr_BSSMAP_IE_GCR(template GlobalCallReferenceValue gcr) := {
	elementIdentifier := '89'O,
	lengthIndicator := ?,
	globalCallReferenceValue := gcr
}

/* TS 48.008 3.2.2.116 */
const BIT4 LCLS_CFG_both_way := '0000'B;
const BIT4 LCLS_CFG_both_way_and_bicast_UL := '0001'B;
const BIT4 LCLS_CFG_both_way_and_send_DL := '0010'B;
const BIT4 LCLS_CFG_both_way_and_send_DL_block_local_DL := '0011'B;
const BIT4 LCLS_CFG_both_way_and_bicast_UL_send_DL := '0100'B;
const BIT4 LCLS_CFG_both_way_and_bicast_UL_send_DL_block_local_DL := '0101'B;

template (value) BSSMAP_IE_LCLS_Configuration ts_BSSMAP_IE_LclsCfg(BIT4 cfg_val) := {
	elementIdentifier := '8A'O,
	lCLS_ConfigurationValue := cfg_val,
	spare := '0000'B
}
template BSSMAP_IE_LCLS_Configuration tr_BSSMAP_IE_LclsCfg(template BIT4 cfg_val) := {
	elementIdentifier := '8A'O,
	lCLS_ConfigurationValue := cfg_val,
	spare := '0000'B
}

/* TS 48.008 3.2.2.117 */
const BIT4 LCLS_CSC_connect := '0000'B;
const BIT4 LCLS_CSC_do_not_connect := '0001'B;
const BIT4 LCLS_CSC_release_lcls := '0010'B;
const BIT4 LCLS_CSC_bicast_UL_at_handover := '0011'B;
const BIT4 LCLS_CSC_bicast_UL_and_recv_DL_at_handover := '0100'B;

template (value) BSSMAP_IE_LCLS_ConnectionStatusControl ts_BSSMAP_IE_LclsCsc(BIT4 csc) := {
	elementIdentifier := '8B'O,
	lCLS_ConnectionStatusControlValue := csc,
	spare := '0000'B
}
template BSSMAP_IE_LCLS_ConnectionStatusControl tr_BSSMAP_IE_LclsCsc(template BIT4 csc) := {
	elementIdentifier := '8B'O,
	lCLS_ConnectionStatusControlValue := csc,
	spare := '0000'B
}

/* TS 48.008 3.2.2.119 */
const BIT4 LCLS_STS_not_yet_ls := '0000'B;
const BIT4 LCLS_STS_not_possible_ls := '0001'B;
const BIT4 LCLS_STS_no_longer_ls := '0010'B;
const BIT4 LCLS_STS_req_lcls_not_supp := '0011'B;
const BIT4 LCLS_STS_locally_switched := '0100'B;

template (value) BSSMAP_IE_LCLS_BSS_Status ts_BSSMAP_IE_LclsSts(BIT4 sts) := {
	elementIdentifier := '8D'O,
	lCLS_BSS_StatusValue := sts,
	spare := '0000'B
}
template BSSMAP_IE_LCLS_BSS_Status tr_BSSMAP_IE_LclsSts(template BIT4 sts) := {
	elementIdentifier := '8D'O,
	lCLS_BSS_StatusValue := sts,
	spare := '0000'B
}

/* TS 48.008 3.2.1.91 */
template (value) PDU_BSSAP ts_BSSMAP_LclsConnCtrl(template (omit) BSSMAP_IE_LCLS_Configuration cfg,
						  template (omit) BSSMAP_IE_LCLS_ConnectionStatusControl csc) modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			lCLS_ConnectControl := {
				messageType := '74'O,
				lCLS_Configuration := cfg,
				lCLS_ConnectionStatusControl := csc
			}
		}
	}
}
template PDU_BSSAP tr_BSSMAP_LclsConnCtrl(template BSSMAP_IE_LCLS_Configuration cfg,
					  template BSSMAP_IE_LCLS_ConnectionStatusControl csc)
modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			lCLS_ConnectControl := {
				messageType := '74'O,
				lCLS_Configuration := cfg,
				lCLS_ConnectionStatusControl := csc
			}
		}
	}
}

/* TS 48.008 3.2.1.92 */
template (value) PDU_BSSAP ts_BSSMAP_LclsConnCtrlAck(template (value) BSSMAP_IE_LCLS_BSS_Status sts)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			lCLS_connectControlAck := {
				messageType := '75'O,
				lCLS_BSS_Status := sts
			}
		}
	}
}
template PDU_BSSAP tr_BSSMAP_LclsConnCtrlAck(template BSSMAP_IE_LCLS_BSS_Status sts)
modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			lCLS_connectControlAck := {
				messageType := '75'O,
				lCLS_BSS_Status := sts
			}
		}
	}
}

/* TS 48.008 3.2.1.93 */
template (value) PDU_BSSAP ts_BSSMAP_LclsNotification(template (omit) BSSMAP_IE_LCLS_BSS_Status sts,
						      template (omit) BSSMAP_IE_LCLS_BreakRequest brq)
modifies ts_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			lCLS_Notification := {
				messageType := '76'O,
				lCLS_BSS_Status := sts,
				lCLS_BreakRequest := brq
			}
		}
	}
}
template PDU_BSSAP tr_BSSMAP_LclsNotification(template BSSMAP_IE_LCLS_BSS_Status sts,
					      template BSSMAP_IE_LCLS_BreakRequest brq)
modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			lCLS_Notification := {
				messageType := '76'O,
				lCLS_BSS_Status := sts,
				lCLS_BreakRequest := brq
			}
		}
	}
}

template PDU_BSSAP tr_BSSMAP_LclsNotificationSts(BIT4 sts)
modifies tr_BSSAP_BSSMAP := {
	pdu := {
		bssmap := {
			lCLS_Notification := {
				messageType := '76'O,
				lCLS_BSS_Status := tr_BSSMAP_IE_LclsSts(sts),
				lCLS_BreakRequest := omit
			}
		}
	}
}




} with { encode "RAW" };