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

import from Osmocom_Types all;
import from BSSAP_Types all;
import from CBSP_Types all;

/* TODO: receive templates must match IEs in any arbitrary order */

/* For some reason the TTCN-3 RAW codec cannot automatically figure out the IEI
 * that it needs to set for a given union-choice (body).  So we have to explicitly
 * specify the IEI by the caller :( */
template (value) CBSP_IE ts_CBSP_IE(CBSP_IEI iei, template (value) CBSP_IE_Body body) := {
	iei := iei,
	body := body
}

template CBSP_IE tr_CBSP_IE(template CBSP_IE_Body body) := {
	iei := ?,
	body := body
}


template (value) CBSP_IE ts_CbspMsgId(template (value) uint16_t val) :=
	ts_CBSP_IE(CBSP_IEI_MSG_ID, {msg_id := val});
template CBSP_IE tr_CbspMsgId(template uint16_t val := ?) :=
	tr_CBSP_IE({msg_id := val});

template (value) CBSP_IE ts_NewSerNo(template (value) uint16_t val) :=
	ts_CBSP_IE(CBSP_IEI_NEW_SERIAL_NR, {new_ser_nr := val});
template CBSP_IE tr_NewSerNo(template uint16_t val := ?) :=
	tr_CBSP_IE({new_ser_nr := val});

template (value) CBSP_IE ts_OldSerNo(template (value) uint16_t val) :=
	ts_CBSP_IE(CBSP_IEI_OLD_SERIAL_NR, {old_ser_nr := val});
template CBSP_IE tr_OldSerNo(template uint16_t val := ?) :=
	tr_CBSP_IE({old_ser_nr := val});

template (value) CBSP_IE ts_CbspKARepPeriod(template (value) uint8_t rep_per) :=
	ts_CBSP_IE(CBSP_IEI_KEEP_ALIVE_REP_PERIOD, {keep_alive_rep_period := rep_per});
template CBSP_IE tr_CbspKARepPeriod(template uint8_t rep_per := ?) :=
	tr_CBSP_IE({keep_alive_rep_period := rep_per});

function ts_CbspChannelInd(template (omit) uint8_t val) return template (omit) CBSP_IE {
	var template (omit) CBSP_IE ie;
	if (istemplatekind(val, "omit")) {
		ie := omit;
	} else {
		ie := ts_CBSP_IE(CBSP_IEI_CHANNEL_IND, {channel_ind := val});
	}
	return ie;
}
function tr_CbspChannelInd(template uint8_t val := ?) return template CBSP_IE {
	var template CBSP_IE ie;
	if (istemplatekind(val, "omit")) {
		ie := omit;
	} else if (istemplatekind(val, "*")) {
		ie := tr_CBSP_IE({channel_ind := ?}) ifpresent;
	} else {
		ie := tr_CBSP_IE({channel_ind := val});
	}
	return ie;
}

template (value) CBSP_IE ts_CbspCause(template (value) CBSP_Cause c) :=
	ts_CBSP_IE(CBSP_IEI_CAUSE, {cause := c});
template CBSP_IE tr_CbspCause(template CBSP_Cause c := ?) :=
	tr_CBSP_IE({cause := c});

template (value) CBSP_IE ts_CbspCellList(template (value) BSSMAP_FIELD_CellIdentificationList list) :=
	ts_CBSP_IE(CBSP_IEI_CELL_LIST, {
			cell_list := {
				len := 0,
				spare1_4 := '0000'B,
				cell_id_discr := '0000'B,
				cell_id := list
			}});
template CBSP_IE tr_CbspCellList(template BSSMAP_FIELD_CellIdentificationList list := ?) :=
	tr_CBSP_IE({
			cell_list := {
				len := ?,
				spare1_4 := ?,
				cell_id_discr := ?,
				cell_id := list
			}});

template (value) CBSP_IE ts_CbspCategory(template (value) CBSP_Category cat) :=
	ts_CBSP_IE(CBSP_IEI_CATEGORY, {category := cat});
template CBSP_IE tr_CbspCategory(template CBSP_Category cat := ?) :=
	tr_CBSP_IE({category := cat});

template (value) CBSP_IE ts_CbspRepetitionPeriod(template (value) uint16_t per) :=
	ts_CBSP_IE(CBSP_IEI_REP_PERIOD, {rep_period := per});
template CBSP_IE tr_CbspRepetitionPeriod(template uint16_t per := ?) :=
	tr_CBSP_IE({rep_period := per});

template (value) CBSP_IE ts_CbspNumBcastReq(template (value) uint16_t num) :=
	ts_CBSP_IE(CBSP_IEI_NUM_BCAST_REQ, {num_bcast_req := num});
template CBSP_IE tr_CbspNumBcastReq(template uint16_t num := ?) :=
	tr_CBSP_IE({num_bcast_req := num});

template (value) CBSP_IE ts_CbspNumPages(template (value) uint8_t num) :=
	ts_CBSP_IE(CBSP_IEI_NUM_OF_PAGES, {num_of_pages := num});
template CBSP_IE tr_CbspNumPages(template uint16_t num := ?) :=
	tr_CBSP_IE({num_of_pages := num});

template (value) CBSP_IE ts_EmergencyInd(template (value) uint8_t val) :=
	ts_CBSP_IE(CBSP_IEI_EMERG_IND, {emerg_ind := val});
template CBSP_IE tr_EmergencyInd(template uint8_t val := ?) :=
	tr_CBSP_IE({emerg_ind := val});

template (value) CBSP_IE ts_WarningType(template (value) uint16_t val) :=
	ts_CBSP_IE(CBSP_IEI_WARN_TYPE, {warn_type := val});
template CBSP_IE tr_WarningType(template uint16_t val) :=
	tr_CBSP_IE({warn_type := val});

template (value) CBSP_IE ts_WarnSecInfo(template (value) octetstring payl := ''O) :=
	ts_CBSP_IE(CBSP_IEI_WARN_SEC_INFO, {warn_sec_info := payl});
template CBSP_IE tr_WarnSecInfo(template octetstring payl := ?) :=
	tr_CBSP_IE({warn_sec_info := payl});

template (value) CBSP_IE ts_WarningPeriod(template (value) uint8_t val) :=
	ts_CBSP_IE(CBSP_IEI_WARNING_PERIOD, {warning_period := val});
template CBSP_IE tr_WarningPeriod(template uint8_t val := ?) :=
	tr_CBSP_IE({warning_period := val});

template (value) CBSP_IE ts_CbspFailList(template (value) CBSP_FailureListItems items) :=
	ts_CBSP_IE(CBSP_IEI_FAILURE_LIST, {failure_list := {
						len := 0,
						list := items
				}});
template CBSP_IE tr_CbspFailList(template CBSP_FailureListItems items := ?) :=
	tr_CBSP_IE({failure_list := {
						len := ?,
						list := items
				}});

template (value) CBSP_IE ts_CbspNumComplList(template (value) CBSP_IE_NumBcastComplList list) :=
	ts_CBSP_IE(CBSP_IEI_NUM_BCAST_COMPL_LIST, {num_bcast_compl_list := list});
template CBSP_IE tr_CbspNumComplList(template CBSP_IE_NumBcastComplList list := ?) :=
	tr_CBSP_IE({num_bcast_compl_list := list});

template (value) CBSP_IE ts_CbspBcastMsgType(template (value) CBSP_BcastMsgType bi) :=
	ts_CBSP_IE(CBSP_IEI_BCAST_MSG_TYPE, {bcast_msg_type := {
			spare1_4 := '0000'B,
			msg_type := bi
		}});
template CBSP_IE tr_CbspBcastMsgType(template CBSP_BcastMsgType bi := ?) :=
	tr_CBSP_IE({bcast_msg_type := {
			spare1_4 := ?,
			msg_type := bi
		}});

template (value) CBSP_IE ts_CbspRecoveryInd(template (value) CBSP_RecoveryInd ri) :=
	ts_CBSP_IE(CBSP_IEI_RECOVERY_IND, {recovery_ind := {
			spare1_4 := '0000'B,
			recovery := ri
		}});
template CBSP_IE tr_CbspRecoveryInd(template CBSP_RecoveryInd ri) :=
	tr_CBSP_IE({recovery_ind := {
			spare1_4 := ?,
			recovery := ri
		}});

template (value) CBSP_IE ts_CbspMsgContent(template (value) octetstring payload, uint8_t user_len) :=
	ts_CBSP_IE(CBSP_IEI_MSG_CONTENT, {msg_content := {
			user_len := user_len,
			val := payload
		}});
template CBSP_IE tr_CbspMsgContent(template octetstring payload := ?, template uint8_t user_len := ?) :=
	tr_CBSP_IE({msg_content := {
			user_len := user_len,
			val := payload
		}});

template (value) CBSP_IE ts_CbspDCS(template (value) uint8_t dcs) :=
	ts_CBSP_IE(CBSP_IEI_DCS, {dcs := dcs});
template CBSP_IE tr_CbspDCS(template uint8_t dcs := ?) :=
	tr_CBSP_IE({dcs := dcs});


template (value) CBSP_PDU ts_CBSP(CBSP_MessageType msg_type, template (value) CBSP_IEs ies) := {
	msg_type := msg_type,
	len := 0, /* overwritten */
	ies := ies
}
template CBSP_PDU tr_CBSP(template CBSP_MessageType msg_type := ?, template CBSP_IEs ies := *) := {
	msg_type := msg_type,
	len := ?,
	ies := ies
}



/* 8.1.3.1 WRITE REPLACE */
function ts_CBSP_WRITE_CBS(template (value) uint16_t msg_id,
			    template (value) uint16_t new_ser_nr,
			    template (value) BSSMAP_FIELD_CellIdentificationList cell_list,
			    template (value) uint8_t channel_ind,
			    template (value) CBSP_Category category,
			    template (value) uint16_t rep_period,
			    template (value) uint16_t num_bcast_req,
			    template (value) uint8_t dcs,
			    template (value) CBSP_IEs content) return template (value) CBSP_PDU {
	var template (value) CBSP_IEs ies := {
		ts_CbspMsgId(msg_id),
		ts_NewSerNo(new_ser_nr),
		ts_CbspCellList(cell_list),
		ts_CbspChannelInd(channel_ind),
		ts_CbspCategory(category),
		ts_CbspRepetitionPeriod(rep_period),
		ts_CbspNumBcastReq(num_bcast_req),
		ts_CbspDCS(dcs),
		ts_CbspNumPages(lengthof(content))
	};
	return ts_CBSP(CBSP_MSGT_WRITE_REPLACE, valueof(ies) & valueof(content));
}
template CBSP_PDU tr_CBSP_WRITE_CBS(template uint16_t msg_id := ?, template uint16_t new_ser_nr := ?,
				    template BSSMAP_FIELD_CellIdentificationList cell_list := ?,
				    template uint8_t channel_ind := ?,
				    template CBSP_Category category := ?,
				    template uint16_t rep_period := ?,
				    template uint16_t num_bcast_req := ?,
				    template uint8_t dcs := ?,
				    template CBSP_IEs content := ?
				    ) :=
	tr_CBSP(CBSP_MSGT_WRITE_REPLACE, ({
			tr_CbspMsgId(msg_id),
			tr_NewSerNo(new_ser_nr),
			tr_CbspCellList(cell_list),
			tr_CbspChannelInd(channel_ind),
			tr_CbspCategory(category),
			tr_CbspRepetitionPeriod(rep_period),
			tr_CbspNumBcastReq(num_bcast_req),
			tr_CbspDCS(dcs),
			tr_CbspNumPages(lengthof(content)), all from content }));


function ts_CBSP_REPLACE_CBS(uint16_t msg_id, uint16_t new_ser_nr, uint16_t old_ser_nr,
			    template (value) BSSMAP_FIELD_CellIdentificationList cell_list,
			    template (value) uint8_t channel_ind,
			    template (value) CBSP_Category category,
			    template (value) uint16_t rep_period,
			    template (value) uint16_t num_bcast_req,
			    template (value) uint8_t dcs,
			    template (value) CBSP_IEs content) return template (value) CBSP_PDU {
	var template (value) CBSP_IEs ies := {
		ts_CbspMsgId(msg_id),
		ts_NewSerNo(new_ser_nr),
		ts_OldSerNo(old_ser_nr),
		ts_CbspCellList(cell_list),
		ts_CbspChannelInd(channel_ind),
		ts_CbspCategory(category),
		ts_CbspRepetitionPeriod(rep_period),
		ts_CbspNumBcastReq(num_bcast_req),
		ts_CbspDCS(dcs),
		ts_CbspNumPages(lengthof(content))
	};
	return ts_CBSP(CBSP_MSGT_WRITE_REPLACE, valueof(ies) & valueof(content));
}
template CBSP_PDU tr_CBSP_REPLACE_CBS(template uint16_t msg_id := ?, template uint16_t new_ser_nr := ?,
				      template uint16_t old_ser_nr := ?,
				      template BSSMAP_FIELD_CellIdentificationList cell_list := ?,
				      template uint8_t channel_ind := ?,
				      template CBSP_Category category := ?,
				      template uint16_t rep_period := ?,
				      template uint16_t num_bcast_req := ?,
				      template uint8_t dcs := ?,
				      template CBSP_IEs content := ?
				    ) :=
	tr_CBSP(CBSP_MSGT_WRITE_REPLACE, ({
			tr_CbspMsgId(msg_id),
			tr_NewSerNo(new_ser_nr),
			tr_OldSerNo(old_ser_nr),
			tr_CbspCellList(cell_list),
			tr_CbspChannelInd(channel_ind),
			tr_CbspCategory(category),
			tr_CbspRepetitionPeriod(rep_period),
			tr_CbspNumBcastReq(num_bcast_req),
			tr_CbspDCS(dcs),
			tr_CbspNumPages(lengthof(content)), all from content }));

template (value) CBSP_PDU ts_CBSP_WRITE_EMERG(uint16_t msg_id, uint16_t new_ser_nr,
						template (value) BSSMAP_FIELD_CellIdentificationList cell_list,
						template (value) uint8_t emerg_ind,
						template (value) uint16_t warn_type,
						template (value) uint8_t warn_per
					    ) :=
	ts_CBSP(CBSP_MSGT_WRITE_REPLACE, {
			ts_CbspMsgId(msg_id),
			ts_NewSerNo(new_ser_nr),
			ts_CbspCellList(cell_list),
			ts_EmergencyInd(emerg_ind),
			ts_WarningType(warn_type),
			ts_WarnSecInfo,
			ts_WarningPeriod(warn_per) });
template CBSP_PDU tr_CBSP_WRITE_EMERG(template uint16_t msg_id := ?, template uint16_t new_ser_nr := ?,
					template BSSMAP_FIELD_CellIdentificationList cell_list := ?,
					template uint8_t emerg_ind := ?,
					template uint16_t warn_type := ?,
					template uint16_t num_bcast_req := ?,
					template uint8_t warn_per := ?
				    ) :=
	tr_CBSP(CBSP_MSGT_WRITE_REPLACE, {
			tr_CbspMsgId(msg_id),
			tr_NewSerNo(new_ser_nr),
			tr_CbspCellList(cell_list),
			tr_EmergencyInd(emerg_ind),
			tr_WarningType(warn_type),
			tr_WarnSecInfo,
			tr_WarningPeriod(warn_per) });


template (value) CBSP_PDU ts_CBSP_REPLACE_EMERG(uint16_t msg_id, uint16_t new_ser_nr, uint16_t old_ser_nr,
						template (value) BSSMAP_FIELD_CellIdentificationList cell_list,
						template (value) uint8_t emerg_ind,
						template (value) uint16_t warn_type,
						template (value) uint16_t num_bcast_req,
						template (value) uint8_t warn_per
					    ) :=
	ts_CBSP(CBSP_MSGT_WRITE_REPLACE, {
			ts_CbspMsgId(msg_id),
			ts_NewSerNo(new_ser_nr),
			ts_OldSerNo(old_ser_nr),
			ts_CbspCellList(cell_list),
			ts_EmergencyInd(emerg_ind),
			ts_WarningType(warn_type),
			ts_WarnSecInfo,
			ts_WarningPeriod(warn_per) });
template CBSP_PDU tr_CBSP_REPLACE_EMERG(template uint16_t msg_id := ?, template uint16_t new_ser_nr := ?,
					template uint16_t old_ser_nr := ?,
					template BSSMAP_FIELD_CellIdentificationList cell_list := ?,
					template uint8_t emerg_ind := ?,
					template uint16_t warn_type := ?,
					template uint16_t num_bcast_req := ?,
					template uint8_t warn_per := ?
				    ) :=
	tr_CBSP(CBSP_MSGT_WRITE_REPLACE, {
			tr_CbspMsgId(msg_id),
			tr_NewSerNo(new_ser_nr),
			tr_OldSerNo(old_ser_nr),
			tr_CbspCellList(cell_list),
			tr_EmergencyInd(emerg_ind),
			tr_WarningType(warn_type),
			tr_WarnSecInfo,
			tr_WarningPeriod(warn_per) });

/* 8.1.3.2 WRITE-REPLACE COMPLETE */
function ts_CBSP_WRITE_CBS_COMPL(uint16_t msg_id, uint16_t new_ser_nr,
				 template (omit) BSSMAP_FIELD_CellIdentificationList cell_list,
				 template (value) uint8_t channel_ind)
return template (value) CBSP_PDU {
	var template (value) CBSP_IEs ies := {
		ts_CbspMsgId(msg_id),
		ts_NewSerNo(new_ser_nr)
	};
	if (not istemplatekind(cell_list, "omit")) {
		ies[lengthof(ies)] := ts_CbspCellList(cell_list);
	}
	ies[lengthof(ies)] := ts_CbspChannelInd(channel_ind);
	return ts_CBSP(CBSP_MSGT_WRITE_REPLACE_COMPL, ies);
}
function tr_CBSP_WRITE_CBS_COMPL(template uint16_t msg_id, template uint16_t new_ser_nr,
				 template BSSMAP_FIELD_CellIdentificationList cell_list,
				 template uint8_t channel_ind)
return template CBSP_PDU {
	var template CBSP_IEs ies := {
		tr_CbspMsgId(msg_id),
		tr_NewSerNo(new_ser_nr)
	};
	if (istemplatekind(cell_list, "*")) {
		ies[lengthof(ies)] := tr_CbspCellList ifpresent;
	} else if (istemplatekind(cell_list, "?")) {
		ies[lengthof(ies)] := tr_CbspCellList(?);
	} else if (not istemplatekind(cell_list, "omit")) {
		ies[lengthof(ies)] := tr_CbspCellList(cell_list);
	}
	if (not istemplatekind(channel_ind, "omit")) {
		ies[lengthof(ies)] := tr_CbspChannelInd(channel_ind);
	}
	return tr_CBSP(CBSP_MSGT_WRITE_REPLACE_COMPL, ies);
}


function ts_CBSP_REPLACE_CBS_COMPL(uint16_t msg_id, uint16_t new_ser_nr, uint16_t old_ser_nr,
				   template (value) CBSP_IE_NumBcastComplList compl_list,
				   template (omit) BSSMAP_FIELD_CellIdentificationList cell_list,
				   template (value) uint8_t channel_ind)
return template (value) CBSP_PDU {
	var template (value) CBSP_IEs ies := {
		ts_CbspMsgId(msg_id),
		ts_NewSerNo(new_ser_nr),
		ts_OldSerNo(old_ser_nr),
		ts_CbspNumComplList(compl_list)
	};
	if (not istemplatekind(cell_list, "omit")) {
		ies[lengthof(ies)] := ts_CbspCellList(cell_list);
	}
	ies[lengthof(ies)] := ts_CbspChannelInd(channel_ind);
	return ts_CBSP(CBSP_MSGT_WRITE_REPLACE_COMPL, ies);
}
function tr_CBSP_REPLACE_CBS_COMPL(template uint16_t msg_id, template uint16_t new_ser_nr,
				   template uint16_t old_ser_nr,
				   template CBSP_IE_NumBcastComplList compl_list,
				   template BSSMAP_FIELD_CellIdentificationList cell_list,
				   template uint8_t channel_ind)
return template CBSP_PDU {
	var template CBSP_IEs ies := {
		tr_CbspMsgId(msg_id),
		tr_NewSerNo(new_ser_nr),
		tr_OldSerNo(old_ser_nr),
		tr_CbspNumComplList(compl_list)
	};
	if (istemplatekind(cell_list, "*")) {
		ies[lengthof(ies)] := tr_CbspCellList ifpresent;
	} else if (istemplatekind(cell_list, "?")) {
		ies[lengthof(ies)] := tr_CbspCellList(?);
	} else if (not istemplatekind(cell_list, "omit")) {
		ies[lengthof(ies)] := tr_CbspCellList(cell_list);
	}
	if (not istemplatekind(channel_ind, "omit")) {
		ies[lengthof(ies)] := tr_CbspChannelInd(channel_ind);
	}
	return tr_CBSP(CBSP_MSGT_WRITE_REPLACE_COMPL, ies);
}


/* 8.1.3.3 WRITE-REPLACE FAILURE */
function ts_CBSP_WRITE_CBS_FAIL(uint16_t msg_id, uint16_t new_ser_nr,
				template (value) CBSP_FailureListItems fail_list,
				template (omit) CBSP_IE_NumBcastComplList compl_list,
				template (omit) BSSMAP_FIELD_CellIdentificationList cell_list,
				template (value) uint8_t channel_ind)
return template (value) CBSP_PDU {
	var template (value) CBSP_IEs ies := {
		ts_CbspMsgId(msg_id),
		ts_NewSerNo(new_ser_nr),
		ts_CbspFailList(fail_list)
	};
	if (not istemplatekind(compl_list, "omit")) {
		ies[lengthof(ies)] := ts_CbspNumComplList(compl_list);
	}
	if (not istemplatekind(cell_list, "omit")) {
		ies[lengthof(ies)] := ts_CbspCellList(cell_list);
	}
	ies[lengthof(ies)] := ts_CbspChannelInd(channel_ind);
	return ts_CBSP(CBSP_MSGT_WRITE_REPLACE_FAIL, ies);
}
function tr_CBSP_WRITE_CBS_FAIL(template uint16_t msg_id, template uint16_t new_ser_nr,
				template CBSP_FailureListItems fail_list,
				template CBSP_IE_NumBcastComplList compl_list,
				template BSSMAP_FIELD_CellIdentificationList cell_list,
				template uint8_t channel_ind)
return template CBSP_PDU {
	var template CBSP_IEs ies := {
		tr_CbspMsgId(msg_id),
		tr_NewSerNo(new_ser_nr),
		tr_CbspFailList(fail_list)
	};
	if (istemplatekind(compl_list, "*")) {
		//ies[lengthof(ies)] := tr_CbspNumComplList ifpresent;
	} else if (istemplatekind(compl_list, "?")) {
		ies[lengthof(ies)] := tr_CbspNumComplList(?);
	} else if (not istemplatekind(compl_list, "omit")) {
		ies[lengthof(ies)] := tr_CbspNumComplList(compl_list);
	}
	if (istemplatekind(cell_list, "*")) {
		ies[lengthof(ies)] := tr_CbspCellList ifpresent;
	} else if (istemplatekind(cell_list, "?")) {
		ies[lengthof(ies)] := tr_CbspCellList(?);
	} else if (not istemplatekind(cell_list, "omit")) {
		ies[lengthof(ies)] := tr_CbspCellList(cell_list);
	}
	if (not istemplatekind(channel_ind, "omit")) {
		ies[lengthof(ies)] := ts_CbspChannelInd(channel_ind);
	}
	return tr_CBSP(CBSP_MSGT_WRITE_REPLACE_FAIL, ies);
}


function ts_CBSP_REPLACE_CBS_FAIL(uint16_t msg_id, uint16_t new_ser_nr, uint16_t old_ser_nr,
				   template (value) CBSP_FailureListItems fail_list,
				   template (omit) CBSP_IE_NumBcastComplList compl_list,
				   template (omit) BSSMAP_FIELD_CellIdentificationList cell_list,
				   template (value) uint8_t channel_ind)
return template (value) CBSP_PDU {
	var template (value) CBSP_IEs ies := {
		ts_CbspMsgId(msg_id),
		ts_NewSerNo(new_ser_nr),
		ts_OldSerNo(old_ser_nr),
		ts_CbspFailList(fail_list)
	};
	if (not istemplatekind(compl_list, "omit")) {
		ies[lengthof(ies)] := ts_CbspNumComplList(compl_list);
	}
	if (not istemplatekind(cell_list, "omit")) {
		ies[lengthof(ies)] := ts_CbspCellList(cell_list);
	}
	ies[lengthof(ies)] := ts_CbspChannelInd(channel_ind);
	return ts_CBSP(CBSP_MSGT_WRITE_REPLACE_FAIL, ies);
}
function tr_CBSP_REPLACE_CBS_FAIL(template uint16_t msg_id, template uint16_t new_ser_nr,
				   template uint16_t old_ser_nr,
				   template CBSP_FailureListItems fail_list,
				   template CBSP_IE_NumBcastComplList compl_list,
				   template BSSMAP_FIELD_CellIdentificationList cell_list,
				   template uint8_t channel_ind)
return template CBSP_PDU {
	var template CBSP_IEs ies := {
		tr_CbspMsgId(msg_id),
		tr_NewSerNo(new_ser_nr),
		tr_OldSerNo(old_ser_nr),
		tr_CbspFailList(fail_list)
	};
	if (istemplatekind(compl_list, "*")) {
		//ies[lengthof(ies)] := tr_CbspCellList ifpresent;
	} else if (istemplatekind(compl_list, "?")) {
		ies[lengthof(ies)] := tr_CbspNumComplList(?);
	} else if (not istemplatekind(compl_list, "omit")) {
		ies[lengthof(ies)] := tr_CbspNumComplList(compl_list);
	}
	if (istemplatekind(cell_list, "*")) {
		//ies[lengthof(ies)] := tr_CbspCellList ifpresent;
	} else if (istemplatekind(cell_list, "?")) {
		ies[lengthof(ies)] := tr_CbspCellList(?);
	} else if (not istemplatekind(cell_list, "omit")) {
		ies[lengthof(ies)] := tr_CbspCellList(cell_list);
	}
	ies[lengthof(ies)] := tr_CbspChannelInd(channel_ind);
	return tr_CBSP(CBSP_MSGT_WRITE_REPLACE_FAIL, ies);
}

/* 8.1.3.4 KILL */
template (value) CBSP_PDU ts_CBSP_KILL(template (value) uint16_t msg_id,
					template (value) uint16_t old_ser_nr,
					template (value) BSSMAP_FIELD_CellIdentificationList cell_list,
					template (omit) uint8_t channel_ind) :=
	ts_CBSP(CBSP_MSGT_KILL, {
			ts_CbspMsgId(msg_id),
			ts_OldSerNo(old_ser_nr),
			ts_CbspCellList(cell_list),
			ts_CbspChannelInd(channel_ind)});
template CBSP_PDU tr_CBSP_KILL(template uint16_t msg_id := ?, template uint16_t old_ser_nr := ?,
				template BSSMAP_FIELD_CellIdentificationList cell_list := ?,
				template uint8_t channel_ind := ?) :=
	tr_CBSP(CBSP_MSGT_KILL, {
			tr_CbspMsgId(msg_id),
			tr_OldSerNo(old_ser_nr),
			tr_CbspCellList(cell_list),
			tr_CbspChannelInd(channel_ind) });

/* 8.1.3.5 KILL COMPLETE */
function ts_CBSP_KILL_COMPL(template (value) uint16_t msg_id, template (value) uint16_t old_ser_nr,
			    template (omit) CBSP_IE_NumBcastComplList compl_list,
			    template (omit) BSSMAP_FIELD_CellIdentificationList cell_list,
			    template (omit) uint8_t channel_ind)
return template (value) CBSP_PDU {
	var template (value) CBSP_IEs ies := {
		ts_CbspMsgId(msg_id),
		ts_OldSerNo(old_ser_nr)
	};
	if (not istemplatekind(compl_list, "omit")) {
		ies[lengthof(ies)] := ts_CbspNumComplList(compl_list);
	}
	if (not istemplatekind(cell_list, "omit")) {
		ies[lengthof(ies)] := ts_CbspCellList(cell_list);
	}
	if (not istemplatekind(channel_ind, "omit")) {
		ies[lengthof(ies)] := ts_CbspChannelInd(channel_ind);
	}
	return ts_CBSP(CBSP_MSGT_KILL_COMPL, ies);
}
function tr_CBSP_KILL_COMPL(template uint16_t msg_id := ?, template uint16_t old_ser_nr := ?,
			    template CBSP_IE_NumBcastComplList compl_list := ?,
			    template BSSMAP_FIELD_CellIdentificationList cell_list := ?,
			    template uint8_t channel_ind)
return template CBSP_PDU {
	var template CBSP_IEs ies := {
		tr_CbspMsgId(msg_id),
		tr_OldSerNo(old_ser_nr)
	};
	if (istemplatekind(compl_list, "*")) {
		ies[lengthof(ies)] := *;
	} else if (not istemplatekind(compl_list, "omit")) {
		ies[lengthof(ies)] := tr_CbspNumComplList(compl_list);
	}
	if (istemplatekind(cell_list, "*")) {
		ies[lengthof(ies)] := *;
	} else if (not istemplatekind(cell_list, "omit")) {
		ies[lengthof(ies)] := tr_CbspCellList(cell_list);
	}
	if (istemplatekind(channel_ind, "*")) {
		ies[lengthof(ies)] := *;
	} else if (not istemplatekind(channel_ind, "omit")) {
		ies[lengthof(ies)] := tr_CbspChannelInd(channel_ind);
	}
	return tr_CBSP(CBSP_MSGT_KILL_COMPL, ies);
}

/* 8.1.3.6 KILL FAILURE */
function ts_CBSP_KILL_FAIL(template (value) uint16_t msg_id, template (value) uint16_t old_ser_nr,
			   template (value) CBSP_FailureListItems fail_list,
			   template (omit) CBSP_IE_NumBcastComplList compl_list,
			   template (omit) BSSMAP_FIELD_CellIdentificationList cell_list,
			   template (omit) uint8_t channel_ind)
return template (value) CBSP_PDU {
	var template (value) CBSP_IEs ies := {
		ts_CbspMsgId(msg_id),
		ts_OldSerNo(old_ser_nr),
		ts_CbspFailList(fail_list)
	};
	if (not istemplatekind(compl_list, "omit")) {
		ies[lengthof(ies)] := ts_CbspNumComplList(compl_list);
	}
	if (not istemplatekind(cell_list, "omit")) {
		ies[lengthof(ies)] := ts_CbspCellList(cell_list);
	}
	if (not istemplatekind(channel_ind, "omit")) {
		ies[lengthof(ies)] := ts_CbspChannelInd(channel_ind);
	}
	return ts_CBSP(CBSP_MSGT_KILL_FAIL, ies);
}
function tr_CBSP_KILL_FAIL(template uint16_t msg_id := ?, template uint16_t old_ser_nr := ?,
			   template CBSP_FailureListItems fail_list := ?,
			   template CBSP_IE_NumBcastComplList compl_list := *,
			   template BSSMAP_FIELD_CellIdentificationList cell_list := *,
			   template uint8_t channel_ind := *)
return template CBSP_PDU {
	var template CBSP_IEs ies := {
		tr_CbspMsgId(msg_id),
		tr_OldSerNo(old_ser_nr),
		tr_CbspFailList(fail_list)
	};
	if (istemplatekind(compl_list, "*")) {
		//ies[lengthof(ies)] := tr_CbspNumComplList ifpresent;
	} else if (not istemplatekind(compl_list, "omit")) {
		ies[lengthof(ies)] := tr_CbspNumComplList(compl_list);
	}
	if (istemplatekind(compl_list, "*")) {
		//ies[lengthof(ies)] := tr_CbspCellList ifpresent;
	} else if (not istemplatekind(cell_list, "omit")) {
		ies[lengthof(ies)] := tr_CbspCellList(cell_list);
	}
	if (istemplatekind(channel_ind, "*")) {
		ies[lengthof(ies)] := tr_CbspChannelInd(?) ifpresent;
	} else if (not istemplatekind(channel_ind, "omit")) {
		ies[lengthof(ies)] := tr_CbspChannelInd(channel_ind);
	}
	return tr_CBSP(CBSP_MSGT_KILL_FAIL, ies);
}


/* 8.1.3.16 RESET */
template (value) CBSP_PDU ts_CBSP_RESET(template (value) BSSMAP_FIELD_CellIdentificationList cell_list) :=
	ts_CBSP(CBSP_MSGT_RESET, {
			ts_CbspCellList(cell_list)
		});
template CBSP_PDU tr_CBSP_RESET(template BSSMAP_FIELD_CellIdentificationList cell_list := ?) :=
	tr_CBSP(CBSP_MSGT_RESET, {
			tr_CbspCellList(cell_list)
		});

/* 8.1.3.17 RESET COMPLETE */
template (value) CBSP_PDU ts_CBSP_RESET_COMPL(template (value) BSSMAP_FIELD_CellIdentificationList cell_list) :=
	ts_CBSP(CBSP_MSGT_RESET_COMPL, {
			ts_CbspCellList(cell_list)
		});
template CBSP_PDU tr_CBSP_RESET_COMPL(template BSSMAP_FIELD_CellIdentificationList cell_list := ?) :=
	tr_CBSP(CBSP_MSGT_RESET_COMPL, {
			tr_CbspCellList(cell_list)
		});

/* 8.1.3.18 RESET FAILURE */
template (value) CBSP_PDU ts_CBSP_RESET_FAIL(template (value) BSSMAP_FIELD_CellIdentificationList cell_list,
					     template (value) CBSP_FailureListItems fail_items) :=
	ts_CBSP(CBSP_MSGT_RESET_FAIL, {
			ts_CbspFailList(fail_items),
			ts_CbspCellList(cell_list)
		});

template CBSP_PDU tr_CBSP_RESET_FAIL(template BSSMAP_FIELD_CellIdentificationList cell_list,
				     template CBSP_FailureListItems fail_items) :=
	tr_CBSP(CBSP_MSGT_RESET_FAIL, {
			tr_CbspFailList(fail_items),
			tr_CbspCellList(cell_list)
		});

/* 8.1.3.18a KEEP-ALIVE */
template (value) CBSP_PDU ts_CBSP_KEEP_ALIVE(uint8_t rep_period) :=
	ts_CBSP(CBSP_MSGT_KEEP_ALIVE, {ts_CbspKARepPeriod(rep_period)});
template CBSP_PDU tr_CBSP_KEEP_ALIVE(template uint8_t rep_period := ?) :=
	tr_CBSP(CBSP_MSGT_KEEP_ALIVE, {tr_CbspKARepPeriod(rep_period)});

/* 8.1.3.18b KEEP-ALIVE COMPLETE */
template (value) CBSP_PDU ts_CBSP_KEEP_ALIVE_COMPL :=
	ts_CBSP(CBSP_MSGT_KEEP_ALIVE_COMPL, {});
template CBSP_PDU tr_CBSP_KEEP_ALIVE_COMPL :=
	tr_CBSP(CBSP_MSGT_KEEP_ALIVE_COMPL, {});

/* 8.1.3.19 RESTART */
template (value) CBSP_PDU ts_CBSP_RESTART(template (value) BSSMAP_FIELD_CellIdentificationList cell_list,
					  template (value) CBSP_BcastMsgType msg_type,
					  template (value) CBSP_RecoveryInd rec_ind) :=
	ts_CBSP(CBSP_MSGT_RESTART, {
			ts_CbspCellList(cell_list),
			ts_CbspBcastMsgType(msg_type),
			ts_CbspRecoveryInd(rec_ind)
		});
template CBSP_PDU tr_CBSP_RESTART(template BSSMAP_FIELD_CellIdentificationList cell_list := ?,
				  template CBSP_BcastMsgType msg_type := ?,
				  template CBSP_RecoveryInd rec_ind := ?) :=
	tr_CBSP(CBSP_MSGT_RESTART, {
			tr_CbspCellList(cell_list),
			tr_CbspBcastMsgType(msg_type),
			tr_CbspRecoveryInd(rec_ind)
		});

/* 8.1.3.20 FAILURE */
template (value) CBSP_PDU ts_CBSP_FAILURE(template (value) CBSP_FailureListItems fail_list,
					  template (value) CBSP_BcastMsgType msg_type) :=
	ts_CBSP(CBSP_MSGT_FAILURE, {
			ts_CbspFailList(fail_list),
			ts_CbspBcastMsgType(msg_type)
		});
template CBSP_PDU tr_CBSP_FAILURE(template CBSP_FailureListItems fail_list := ?,
				  template CBSP_BcastMsgType msg_type := ?) :=
	tr_CBSP(CBSP_MSGT_FAILURE, {
			tr_CbspFailList(fail_list),
			tr_CbspBcastMsgType(msg_type)
		});

/* 8.1.3.21 ERROR INDICATION */
template (value) CBSP_PDU ts_CBSP_ERROR_IND(CBSP_Cause cause) :=
	ts_CBSP(CBSP_MSGT_ERROR_IND, {ts_CbspCause(cause)});
template CBSP_PDU tr_CBSP_ERROR_IND(template CBSP_Cause cause) :=
	tr_CBSP(CBSP_MSGT_ERROR_IND, {tr_CbspCause(cause), *});


function f_cbsp_find_ie(CBSP_PDU msg, CBSP_IEI iei, out CBSP_IE ret) return boolean {
	for (var integer i := 0; i < sizeof(msg.ies); i := i+1) {
		if (msg.ies[i].iei == iei) {
			ret := msg.ies[i];
			return true;
		}
	}
	return false;
}


}