aboutsummaryrefslogtreecommitdiffstats
path: root/library/SCCP_Templates.ttcn
blob: a87ef5cf261a89ea073da318d5c96858c6ad9424 (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
/* (C) 2018 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
 * All Rights Reserved
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

module SCCP_Templates {

import from General_Types all;

import from SCCP_Types all;
import from SCCPasp_Types all;
import from SCCP_Emulation all;

/* construct a SCCP_PAR_Address with just SSN and no PC or GT */
template (value) SCCP_PAR_Address ts_SccpAddr_SSN(integer ssn) := {
	addressIndicator := {
		pointCodeIndic := '0'B,
		ssnIndicator := '1'B,
		globalTitleIndic := '0000'B,
		routingIndicator := '1'B
	},
	signPointCode := omit,
	subsystemNumber := ssn,
	globalTitle := omit
}

/* construct a SCCP_PAR_Address with just PC + SSN and no GT */
template (value) SCCP_PAR_Address ts_SccpAddr_PC_SSN(integer pc, integer ssn, octetstring sio,
							charstring sccp_srv_type) := {
	addressIndicator := {
		pointCodeIndic := '1'B,
		ssnIndicator := '1'B,
		globalTitleIndic := '0000'B,
		routingIndicator := '1'B
	},
	signPointCode := SCCP_SPC_int2bit(pc, sccp_srv_type, sio),
	subsystemNumber := ssn,
	globalTitle := omit
}

/* construct a SCCP_PAR_Address with only GT */
template (value) SCCP_PAR_Address ts_SccpAddr_GT(hexstring global_address) := {
	addressIndicator := {
		pointCodeIndic := '0'B,
		ssnIndicator := '0'B,
		globalTitleIndic := '0001'B, // NAI only
		routingIndicator := cg_route_on_GT // route on GT
	},
	signPointCode := omit,
	subsystemNumber := omit,
	globalTitle := {
		gti0001 := {
			natureOfAddress := '0000011'B,
			oddeven := '0'B,
			globalTitleAddress := global_address
		}
	}
}

/* construct a SCCP_PAR_Address with PC + SSN and GT */
template (value) SCCP_PAR_Address ts_SccpAddr_PC_GT(integer pc, octetstring sio,
						    charstring sccp_srv_type, hexstring gt_addr) := {
	addressIndicator := {
		pointCodeIndic := '1'B,
		ssnIndicator := '0'B,
		globalTitleIndic := '0001'B, // NAI only
		routingIndicator := cg_route_on_GT // route on GT
	},
	signPointCode := SCCP_SPC_int2bit(pc, sccp_srv_type, sio),
	subsystemNumber := omit,
	globalTitle := {
		gti0001 := {
			natureOfAddress := '0000011'B,
			oddeven := '0'B,
			globalTitleAddress := gt_addr
		}
	}
}

/* connection oriented SCCP */
const SCCP_param_ProtocolClass c_class2 := { class:='0010'B, messageHandling:='0000'B };//class 2

function ts_SCCP_CR(OCT3 source_lref, SCCP_PAR_Address calling, SCCP_PAR_Address called)
return template (value) PDU_SCCP {
	var SCCP_param_CPartyAddressEnc calling_enc := ConvertASPAddressToEncodedAddress_itu(calling);

	var template (value) PDU_SCCP ret := {
		connrequest := {
			messageType := cr,
			sourceLocRef := source_lref,
			protClass := c_class2,
			pointer1 := 2,
			pointer2 := 0, /* overwritten */
			calledPAddress := ConvertASPAddressToEncodedAddress_itu(called),
			optionalPart := {
				credit := omit,
				callingPAddress := {
					paramName := con_SCCP_cgPA,
					paramLength := calling_enc.paramLength, /* overwritten */
					addr := calling_enc.addr
				},
				data := omit,
				hopCounter := omit,
				importance := omit
			},
			eop := { paramName:= con_SCCP_eop }
		}
	}
	return ret;
}

template (present) PDU_SCCP tr_SCCP_CC(template (present) OCT3 source_lref,
				       template (present) OCT3 dest_lref) := {
	connconfirm := {
		messageType := cc,
		destLocRef := dest_lref,
		sourceLocRef := source_lref,
		protClass := c_class2,
		pointer1 := ?,
		optionalPart := *,
		eop := *
	}
}

private function tr_Addr(template SCCP_PAR_Address addr := *)
return template (present) SCCP_param_CPartyAddressEnc {
	if (istemplatekind(addr, "?")) {
		return ?;
	} else {
		return ConvertASPAddressToEncodedAddress_itu(valueof(addr));
	}
}

template (value) PDU_SCCP ts_SCCP_UDT(SCCP_PAR_Address calling, SCCP_PAR_Address called,
				      template (value) octetstring data,
				      template (value) BIT4 msg_hdl := '0000'B) := {
	unitdata := {
		messageType := udt,
		protClass := {'0000'B, msg_hdl},
		pointer1 := 0,  /* overwritten */
		pointer2 := 0,  /* overwritten */
		pointer3 := 0,  /* overwritten */
		calledPAddress := ConvertASPAddressToEncodedAddress_itu(called),
		callingPAddress := ConvertASPAddressToEncodedAddress_itu(calling),
		data := {
			paramLength := 0,
			data := data
		}
	}
}

template PDU_SCCP tr_SCCP_UDT(template (present) SCCP_PAR_Address calling, template (present) SCCP_PAR_Address called,
			      template octetstring data := ?,
			      template BIT4 msg_hdl := '0000'B) := {
	unitdata := {
		messageType := udt,
		protClass := {'0000'B, msg_hdl},
		pointer1 := ?,
		pointer2 := ?,
		pointer3 := ?,
		calledPAddress := tr_Addr(called),
		callingPAddress := tr_Addr(calling),
		data := {
			paramLength := ?,
			data := data
		}
	}
}

template (value) PDU_SCCP ts_SCCP_XUDT(SCCP_PAR_Address calling, SCCP_PAR_Address called,
				      template (value) octetstring data,
				      template (value) BIT4 msg_hdl := '0000'B,
				      template (value) integer hop_ctr := 16) := {
	extudata := {
		messageType := xudt,
		protClass := {'0000'B, msg_hdl},
		hopCounter := hop_ctr,
		pointer1 := 0,  /* overwritten */
		pointer2 := 0,  /* overwritten */
		pointer3 := 0,  /* overwritten */
		pointer4 := 0,  /* overwritten */
		calledPAddress := ConvertASPAddressToEncodedAddress_itu(called),
		callingPAddress := ConvertASPAddressToEncodedAddress_itu(calling),
		data := {
			paramLength := 0,
			data := data
		},
		optionalPart := omit,
		eop := omit
	}
}

template PDU_SCCP tr_SCCP_XUDT(template (present) SCCP_PAR_Address calling, template (present) SCCP_PAR_Address called,
			      template octetstring data := ?,
			      template BIT4 msg_hdl := '0000'B,
			      template integer hop_ctr := ?) := {
	extudata := {
		messageType := xudt,
		protClass := {'0000'B, msg_hdl},
		hopCounter := hop_ctr,
		pointer1 := ?,
		pointer2 := ?,
		pointer3 := ?,
		pointer4 := ?,
		calledPAddress := tr_Addr(called),
		callingPAddress := tr_Addr(calling),
		data := {
			paramLength := ?,
			data := data
		},
		optionalPart := { segmentation:= omit, importance := * } ifpresent,
		eop := { paramName:= con_SCCP_eop } ifpresent
	}
}

template (value) PDU_SCCP ts_SCCP_LUDT(SCCP_PAR_Address calling, SCCP_PAR_Address called,
				      template (value) octetstring data,
				      template (value) BIT4 msg_hdl := '0000'B,
				      template (value) integer hop_ctr := 16) := {
	longudata := {
		messageType := ludt,
		protClass := {'0000'B, msg_hdl},
		hopCounter := hop_ctr,
		pointer1 := 0,  /* overwritten */
		pointer2 := 0,  /* overwritten */
		pointer3 := 0,  /* overwritten */
		pointer4 := 0,  /* overwritten */
		calledPAddress := ConvertASPAddressToEncodedAddress_itu(called),
		callingPAddress := ConvertASPAddressToEncodedAddress_itu(calling),
		longData := {
			paramLength := 0,
			data := data
		},
		optionalPart := omit,
		eop := omit
	}
}

template PDU_SCCP tr_SCCP_LUDT(template (present) SCCP_PAR_Address calling, template (present) SCCP_PAR_Address called,
			      template octetstring data := ?,
			      template BIT4 msg_hdl := '0000'B,
			      template integer hop_ctr := ?) := {
	longudata := {
		messageType := ludt,
		protClass := {'0000'B, msg_hdl},
		hopCounter := hop_ctr,
		pointer1 := ?,
		pointer2 := ?,
		pointer3 := ?,
		pointer4 := ?,
		calledPAddress := tr_Addr(called),
		callingPAddress := tr_Addr(calling),
		longData := {
			paramLength := ?,
			data := data
		},
		optionalPart := { segmentation:= omit, importance := * } ifpresent,
		eop := { paramName:= con_SCCP_eop } ifpresent
	}
}


template PDU_SCCP tr_SCCP_IT(template (present) OCT3 source_lref := ?,
			     template (present) OCT3 dest_lref := ?) := {
	inacttest := {
		messageType := it,
		destLocRef := dest_lref,
		sourceLocRef := source_lref,
		protClass := c_class2,
		sequencingSegmenting := {
			reserved := ?,
			p_s := ?,
			more := ?,
			pr := ?
		},
		credit := ?
	}
}

template PDU_SCCP ts_SCCP_IT(template (present) OCT3 source_lref,
			     template (present) OCT3 dest_lref) := {
	inacttest := {
		messageType := it,
		destLocRef := dest_lref,
		sourceLocRef := source_lref,
		protClass := c_class2,
		/* rfc3868 3.3.11: sequencing and credit are ignored with class2 */
		sequencingSegmenting := {
			reserved := '0'B,
			p_s := '0000000'B,
			more := '0'B,
			pr := '0000000'B
		},
		credit := '00'O
	}
}

template PDU_SCCP tr_SCCP_RLSD(template (present) OCT3 source_lref := ?,
			       template (present) OCT3 dest_lref := ?,
			       template (present) SCCP_param_ReleaseCause relcause := ?) := {
	released := {
		messageType := rlsd,
		destLocRef := dest_lref,
		sourceLocRef := source_lref,
		releaseCause := relcause,
		pointer1 := ?,
		optionalPart := *,
		eop := *
	}
}

template PDU_SCCP ts_SCCP_RLC(OCT3 source_lref, OCT3 dest_lref) := {
	relcomp := {
		messageType := rlc,
		destLocRef := dest_lref,
		sourceLocRef := source_lref
	}
}

template PDU_SCCP tr_SCCP_RLC(template (present) OCT3 source_lref := ?,
			      template (present) OCT3 dest_lref := ?) := {
	relcomp := {
		messageType := rlc,
		destLocRef := dest_lref,
		sourceLocRef := source_lref
	}
}

private function f_pc_int2bit(template (present) integer pc)
return template SCMG_param_AffectedPointCode {
	if (istemplatekind(pc, "?")) {
		return ?;
	} else {
		return int2bit(valueof(pc), 16);
	}
}

template (value) PDU_SCMG_message ts_SCMG_SSA(template (value) integer ssn,
					      integer pc,
					      template (value) BIT2 smi := '00'B) := {
	messageType := sSAallowed,
	affectedSSN := ssn,
	affectedPC := int2bit(valueof(pc), 16),
	smi := {
		smi := smi,
		reserved := '000000'B
	},
	congLevel := omit
}
template (present) PDU_SCMG_message tr_SCMG_SSA(template (present) integer ssn := ?,
						template (present) integer pc := ?,
						template (present) BIT2 smi := ?) := {
	messageType := sSAallowed,
	affectedSSN := ssn,
	affectedPC := f_pc_int2bit(pc),
	smi := {
		smi := smi,
		reserved := '000000'B
	},
	congLevel := omit
}

template (value) PDU_SCMG_message ts_SCMG_SSP(template (value) integer ssn,
					      integer pc,
					      template (value) BIT2 smi := '00'B) := {
	messageType := sSPprohib,
	affectedSSN := ssn,
	affectedPC := int2bit(valueof(pc), 16),
	smi := {
		smi := smi,
		reserved := '000000'B
	},
	congLevel := omit
}
template (present) PDU_SCMG_message tr_SCMG_SSP(template (present) integer ssn := ?,
						template (present) integer pc := ?,
						template (present) BIT2 smi := ?) := {
	messageType := sSPprohib,
	affectedSSN := ssn,
	affectedPC := f_pc_int2bit(pc),
	smi := {
		smi := smi,
		reserved := '000000'B
	},
	congLevel := omit
}

template (value) PDU_SCMG_message ts_SCMG_SST(template (value) integer ssn,
					      integer pc,
					      template (value) BIT2 smi := '00'B) := {
	messageType := sSTstaTest,
	affectedSSN := ssn,
	affectedPC := int2bit(valueof(pc), 16),
	smi := {
		smi := smi,
		reserved := '000000'B
	},
	congLevel := omit
}
template (present) PDU_SCMG_message tr_SCMG_SST(template (present) integer ssn := ?,
						template (present) integer pc := ?,
						template (present) BIT2 smi := ?) := {
	messageType := sSTstaTest,
	affectedSSN := ssn,
	affectedPC := f_pc_int2bit(pc),
	smi := {
		smi := smi,
		reserved := '000000'B
	},
	congLevel := omit
}



}