Stefan Sperling | c307e68 | 2018-06-14 15:15:46 +0200 | [diff] [blame] | 1 | /* (C) 2018 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
| 2 | * All Rights Reserved |
| 3 | * |
| 4 | * Released under the terms of GNU General Public License, Version 2 or |
| 5 | * (at your option) any later version. |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0-or-later |
Stefan Sperling | c307e68 | 2018-06-14 15:15:46 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | module SCCP_Templates { |
| 11 | |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 12 | import from General_Types all; |
| 13 | |
Stefan Sperling | c307e68 | 2018-06-14 15:15:46 +0200 | [diff] [blame] | 14 | import from SCCP_Types all; |
| 15 | import from SCCPasp_Types all; |
| 16 | import from SCCP_Emulation all; |
| 17 | |
Harald Welte | aed9f94 | 2021-05-13 21:54:58 +0200 | [diff] [blame] | 18 | /* construct a SCCP_PAR_Address with just SSN and no PC or GT */ |
| 19 | template (value) SCCP_PAR_Address ts_SccpAddr_SSN(integer ssn) := { |
| 20 | addressIndicator := { |
| 21 | pointCodeIndic := '0'B, |
| 22 | ssnIndicator := '1'B, |
| 23 | globalTitleIndic := '0000'B, |
| 24 | routingIndicator := '1'B |
| 25 | }, |
| 26 | signPointCode := omit, |
| 27 | subsystemNumber := ssn, |
| 28 | globalTitle := omit |
| 29 | } |
| 30 | |
Stefan Sperling | c307e68 | 2018-06-14 15:15:46 +0200 | [diff] [blame] | 31 | /* construct a SCCP_PAR_Address with just PC + SSN and no GT */ |
| 32 | template (value) SCCP_PAR_Address ts_SccpAddr_PC_SSN(integer pc, integer ssn, octetstring sio, |
| 33 | charstring sccp_srv_type) := { |
| 34 | addressIndicator := { |
| 35 | pointCodeIndic := '1'B, |
| 36 | ssnIndicator := '1'B, |
| 37 | globalTitleIndic := '0000'B, |
| 38 | routingIndicator := '1'B |
| 39 | }, |
| 40 | signPointCode := SCCP_SPC_int2bit(pc, sccp_srv_type, sio), |
| 41 | subsystemNumber := ssn, |
| 42 | globalTitle := omit |
| 43 | } |
| 44 | |
| 45 | /* construct a SCCP_PAR_Address with only GT */ |
| 46 | template (value) SCCP_PAR_Address ts_SccpAddr_GT(hexstring global_address) := { |
| 47 | addressIndicator := { |
| 48 | pointCodeIndic := '0'B, |
| 49 | ssnIndicator := '0'B, |
| 50 | globalTitleIndic := '0001'B, // NAI only |
| 51 | routingIndicator := cg_route_on_GT // route on GT |
| 52 | }, |
| 53 | signPointCode := omit, |
| 54 | subsystemNumber := omit, |
| 55 | globalTitle := { |
| 56 | gti0001 := { |
| 57 | natureOfAddress := '0000011'B, |
| 58 | oddeven := '0'B, |
| 59 | globalTitleAddress := global_address |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 64 | /* construct a SCCP_PAR_Address with PC + SSN and GT */ |
| 65 | template (value) SCCP_PAR_Address ts_SccpAddr_PC_GT(integer pc, octetstring sio, |
| 66 | charstring sccp_srv_type, hexstring gt_addr) := { |
| 67 | addressIndicator := { |
| 68 | pointCodeIndic := '1'B, |
| 69 | ssnIndicator := '0'B, |
| 70 | globalTitleIndic := '0001'B, // NAI only |
| 71 | routingIndicator := cg_route_on_GT // route on GT |
| 72 | }, |
| 73 | signPointCode := SCCP_SPC_int2bit(pc, sccp_srv_type, sio), |
| 74 | subsystemNumber := omit, |
| 75 | globalTitle := { |
| 76 | gti0001 := { |
| 77 | natureOfAddress := '0000011'B, |
| 78 | oddeven := '0'B, |
| 79 | globalTitleAddress := gt_addr |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 84 | /* connection oriented SCCP */ |
| 85 | const SCCP_param_ProtocolClass c_class2 := { class:='0010'B, messageHandling:='0000'B };//class 2 |
| 86 | |
| 87 | function ts_SCCP_CR(OCT3 source_lref, SCCP_PAR_Address calling, SCCP_PAR_Address called) |
| 88 | return template (value) PDU_SCCP { |
| 89 | var SCCP_param_CPartyAddressEnc calling_enc := ConvertASPAddressToEncodedAddress_itu(calling); |
| 90 | |
| 91 | var template (value) PDU_SCCP ret := { |
| 92 | connrequest := { |
| 93 | messageType := cr, |
| 94 | sourceLocRef := source_lref, |
| 95 | protClass := c_class2, |
| 96 | pointer1 := 2, |
| 97 | pointer2 := 0, /* overwritten */ |
| 98 | calledPAddress := ConvertASPAddressToEncodedAddress_itu(called), |
| 99 | optionalPart := { |
| 100 | credit := omit, |
| 101 | callingPAddress := { |
| 102 | paramName := con_SCCP_cgPA, |
| 103 | paramLength := calling_enc.paramLength, /* overwritten */ |
| 104 | addr := calling_enc.addr |
| 105 | }, |
| 106 | data := omit, |
| 107 | hopCounter := omit, |
| 108 | importance := omit |
| 109 | }, |
| 110 | eop := { paramName:= con_SCCP_eop } |
| 111 | } |
| 112 | } |
| 113 | return ret; |
| 114 | } |
| 115 | |
Pau Espin Pedrol | 2748679 | 2023-10-30 18:13:20 +0100 | [diff] [blame] | 116 | template (present) PDU_SCCP tr_SCCP_CR(template (present) OCT3 source_lref := ?, |
| 117 | template (present) SCCP_PAR_Address called := ?, |
| 118 | template (present) SCCP_PAR_Address calling := ?) := { |
| 119 | connrequest := { |
| 120 | messageType := cr, |
| 121 | sourceLocRef := source_lref, |
| 122 | protClass := c_class2, |
| 123 | pointer1 := ?, |
| 124 | pointer2 := ?, |
| 125 | calledPAddress := tr_Addr(called), |
| 126 | optionalPart := { |
| 127 | credit := omit, |
| 128 | callingPAddress := tr_Addr_opt(calling), |
| 129 | data := omit, |
| 130 | hopCounter := *, |
| 131 | importance := * |
| 132 | }, |
| 133 | eop := * |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | template (value) PDU_SCCP ts_SCCP_CC(OCT3 source_lref, OCT3 dest_lref) := { |
| 138 | connconfirm := { |
| 139 | messageType := cc, |
| 140 | destLocRef := dest_lref, |
| 141 | sourceLocRef := source_lref, |
| 142 | protClass := c_class2, |
| 143 | pointer1 := 0, /* overwritten */ |
| 144 | optionalPart := omit, |
| 145 | eop := { paramName:= con_SCCP_eop } |
| 146 | } |
| 147 | } |
| 148 | |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 149 | template (present) PDU_SCCP tr_SCCP_CC(template (present) OCT3 source_lref, |
| 150 | template (present) OCT3 dest_lref) := { |
| 151 | connconfirm := { |
| 152 | messageType := cc, |
| 153 | destLocRef := dest_lref, |
| 154 | sourceLocRef := source_lref, |
| 155 | protClass := c_class2, |
| 156 | pointer1 := ?, |
| 157 | optionalPart := *, |
| 158 | eop := * |
| 159 | } |
| 160 | } |
| 161 | |
Harald Welte | 2eb30d4 | 2021-05-13 21:54:26 +0200 | [diff] [blame] | 162 | private function tr_Addr(template SCCP_PAR_Address addr := *) |
| 163 | return template (present) SCCP_param_CPartyAddressEnc { |
| 164 | if (istemplatekind(addr, "?")) { |
| 165 | return ?; |
| 166 | } else { |
| 167 | return ConvertASPAddressToEncodedAddress_itu(valueof(addr)); |
| 168 | } |
| 169 | } |
| 170 | |
Pau Espin Pedrol | 2748679 | 2023-10-30 18:13:20 +0100 | [diff] [blame] | 171 | private function tr_Addr_opt(template SCCP_PAR_Address addr := *) |
| 172 | return template SCCP_param_CPartyAddressEnc_opt { |
| 173 | if (istemplatekind(addr, "omit")) { |
| 174 | return omit; |
| 175 | } else if (istemplatekind(addr, "*")) { |
| 176 | return *; |
| 177 | } else if (istemplatekind(addr, "?")) { |
| 178 | return ?; |
| 179 | } else { |
| 180 | var SCCP_param_CPartyAddressEnc enc := ConvertASPAddressToEncodedAddress_itu(valueof(addr)); |
| 181 | var SCCP_param_CPartyAddressEnc_opt enc_opt := { |
| 182 | paramName := con_SCCP_cgPA, |
| 183 | paramLength := enc.paramLength, /* overwritten */ |
| 184 | addr := enc.addr |
| 185 | }; |
| 186 | return enc_opt; |
| 187 | } |
| 188 | } |
| 189 | |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 190 | template (value) PDU_SCCP ts_SCCP_UDT(SCCP_PAR_Address calling, SCCP_PAR_Address called, |
| 191 | template (value) octetstring data, |
| 192 | template (value) BIT4 msg_hdl := '0000'B) := { |
| 193 | unitdata := { |
| 194 | messageType := udt, |
| 195 | protClass := {'0000'B, msg_hdl}, |
| 196 | pointer1 := 0, /* overwritten */ |
| 197 | pointer2 := 0, /* overwritten */ |
| 198 | pointer3 := 0, /* overwritten */ |
| 199 | calledPAddress := ConvertASPAddressToEncodedAddress_itu(called), |
| 200 | callingPAddress := ConvertASPAddressToEncodedAddress_itu(calling), |
| 201 | data := { |
| 202 | paramLength := 0, |
| 203 | data := data |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | |
Harald Welte | 2eb30d4 | 2021-05-13 21:54:26 +0200 | [diff] [blame] | 208 | template PDU_SCCP tr_SCCP_UDT(template (present) SCCP_PAR_Address calling, template (present) SCCP_PAR_Address called, |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 209 | template octetstring data := ?, |
| 210 | template BIT4 msg_hdl := '0000'B) := { |
| 211 | unitdata := { |
| 212 | messageType := udt, |
| 213 | protClass := {'0000'B, msg_hdl}, |
| 214 | pointer1 := ?, |
| 215 | pointer2 := ?, |
| 216 | pointer3 := ?, |
Harald Welte | 2eb30d4 | 2021-05-13 21:54:26 +0200 | [diff] [blame] | 217 | calledPAddress := tr_Addr(called), |
| 218 | callingPAddress := tr_Addr(calling), |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 219 | data := { |
Harald Welte | e92cc66 | 2021-02-10 19:37:13 +0100 | [diff] [blame] | 220 | paramLength := ?, |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 221 | data := data |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
Harald Welte | 4038d4c | 2021-10-26 14:37:54 +0200 | [diff] [blame] | 226 | template (value) PDU_SCCP ts_SCCP_XUDT(SCCP_PAR_Address calling, SCCP_PAR_Address called, |
| 227 | template (value) octetstring data, |
| 228 | template (value) BIT4 msg_hdl := '0000'B, |
| 229 | template (value) integer hop_ctr := 16) := { |
| 230 | extudata := { |
| 231 | messageType := xudt, |
| 232 | protClass := {'0000'B, msg_hdl}, |
| 233 | hopCounter := hop_ctr, |
| 234 | pointer1 := 0, /* overwritten */ |
| 235 | pointer2 := 0, /* overwritten */ |
| 236 | pointer3 := 0, /* overwritten */ |
| 237 | pointer4 := 0, /* overwritten */ |
| 238 | calledPAddress := ConvertASPAddressToEncodedAddress_itu(called), |
| 239 | callingPAddress := ConvertASPAddressToEncodedAddress_itu(calling), |
| 240 | data := { |
| 241 | paramLength := 0, |
| 242 | data := data |
| 243 | }, |
| 244 | optionalPart := omit, |
| 245 | eop := omit |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | template PDU_SCCP tr_SCCP_XUDT(template (present) SCCP_PAR_Address calling, template (present) SCCP_PAR_Address called, |
| 250 | template octetstring data := ?, |
| 251 | template BIT4 msg_hdl := '0000'B, |
| 252 | template integer hop_ctr := ?) := { |
| 253 | extudata := { |
| 254 | messageType := xudt, |
| 255 | protClass := {'0000'B, msg_hdl}, |
| 256 | hopCounter := hop_ctr, |
| 257 | pointer1 := ?, |
| 258 | pointer2 := ?, |
| 259 | pointer3 := ?, |
| 260 | pointer4 := ?, |
| 261 | calledPAddress := tr_Addr(called), |
| 262 | callingPAddress := tr_Addr(calling), |
| 263 | data := { |
| 264 | paramLength := ?, |
| 265 | data := data |
| 266 | }, |
| 267 | optionalPart := { segmentation:= omit, importance := * } ifpresent, |
| 268 | eop := { paramName:= con_SCCP_eop } ifpresent |
| 269 | } |
| 270 | } |
| 271 | |
Pau Espin Pedrol | 0c613ab | 2023-09-19 14:39:34 +0200 | [diff] [blame] | 272 | template (value) PDU_SCCP ts_SCCP_LUDT(SCCP_PAR_Address calling, SCCP_PAR_Address called, |
| 273 | template (value) octetstring data, |
| 274 | template (value) BIT4 msg_hdl := '0000'B, |
| 275 | template (value) integer hop_ctr := 16) := { |
| 276 | longudata := { |
| 277 | messageType := ludt, |
| 278 | protClass := {'0000'B, msg_hdl}, |
| 279 | hopCounter := hop_ctr, |
| 280 | pointer1 := 0, /* overwritten */ |
| 281 | pointer2 := 0, /* overwritten */ |
| 282 | pointer3 := 0, /* overwritten */ |
| 283 | pointer4 := 0, /* overwritten */ |
| 284 | calledPAddress := ConvertASPAddressToEncodedAddress_itu(called), |
| 285 | callingPAddress := ConvertASPAddressToEncodedAddress_itu(calling), |
| 286 | longData := { |
| 287 | paramLength := 0, |
| 288 | data := data |
| 289 | }, |
| 290 | optionalPart := omit, |
| 291 | eop := omit |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | template PDU_SCCP tr_SCCP_LUDT(template (present) SCCP_PAR_Address calling, template (present) SCCP_PAR_Address called, |
| 296 | template octetstring data := ?, |
| 297 | template BIT4 msg_hdl := '0000'B, |
| 298 | template integer hop_ctr := ?) := { |
| 299 | longudata := { |
| 300 | messageType := ludt, |
| 301 | protClass := {'0000'B, msg_hdl}, |
| 302 | hopCounter := hop_ctr, |
| 303 | pointer1 := ?, |
| 304 | pointer2 := ?, |
| 305 | pointer3 := ?, |
| 306 | pointer4 := ?, |
| 307 | calledPAddress := tr_Addr(called), |
| 308 | callingPAddress := tr_Addr(calling), |
| 309 | longData := { |
| 310 | paramLength := ?, |
| 311 | data := data |
| 312 | }, |
| 313 | optionalPart := { segmentation:= omit, importance := * } ifpresent, |
| 314 | eop := { paramName:= con_SCCP_eop } ifpresent |
| 315 | } |
| 316 | } |
| 317 | |
Harald Welte | 4038d4c | 2021-10-26 14:37:54 +0200 | [diff] [blame] | 318 | |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 319 | template PDU_SCCP tr_SCCP_IT(template (present) OCT3 source_lref := ?, |
| 320 | template (present) OCT3 dest_lref := ?) := { |
| 321 | inacttest := { |
| 322 | messageType := it, |
| 323 | destLocRef := dest_lref, |
| 324 | sourceLocRef := source_lref, |
| 325 | protClass := c_class2, |
| 326 | sequencingSegmenting := { |
| 327 | reserved := ?, |
| 328 | p_s := ?, |
| 329 | more := ?, |
| 330 | pr := ? |
| 331 | }, |
| 332 | credit := ? |
| 333 | } |
| 334 | } |
| 335 | |
Pau Espin Pedrol | e30d543 | 2020-01-21 13:47:32 +0100 | [diff] [blame] | 336 | template PDU_SCCP ts_SCCP_IT(template (present) OCT3 source_lref, |
| 337 | template (present) OCT3 dest_lref) := { |
| 338 | inacttest := { |
| 339 | messageType := it, |
| 340 | destLocRef := dest_lref, |
| 341 | sourceLocRef := source_lref, |
| 342 | protClass := c_class2, |
| 343 | /* rfc3868 3.3.11: sequencing and credit are ignored with class2 */ |
| 344 | sequencingSegmenting := { |
| 345 | reserved := '0'B, |
| 346 | p_s := '0000000'B, |
| 347 | more := '0'B, |
| 348 | pr := '0000000'B |
| 349 | }, |
| 350 | credit := '00'O |
| 351 | } |
| 352 | } |
| 353 | |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 354 | template PDU_SCCP tr_SCCP_RLSD(template (present) OCT3 source_lref := ?, |
| 355 | template (present) OCT3 dest_lref := ?, |
| 356 | template (present) SCCP_param_ReleaseCause relcause := ?) := { |
| 357 | released := { |
| 358 | messageType := rlsd, |
| 359 | destLocRef := dest_lref, |
| 360 | sourceLocRef := source_lref, |
| 361 | releaseCause := relcause, |
| 362 | pointer1 := ?, |
| 363 | optionalPart := *, |
| 364 | eop := * |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | template PDU_SCCP ts_SCCP_RLC(OCT3 source_lref, OCT3 dest_lref) := { |
| 369 | relcomp := { |
| 370 | messageType := rlc, |
| 371 | destLocRef := dest_lref, |
| 372 | sourceLocRef := source_lref |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | template PDU_SCCP tr_SCCP_RLC(template (present) OCT3 source_lref := ?, |
| 377 | template (present) OCT3 dest_lref := ?) := { |
| 378 | relcomp := { |
| 379 | messageType := rlc, |
| 380 | destLocRef := dest_lref, |
| 381 | sourceLocRef := source_lref |
| 382 | } |
| 383 | } |
| 384 | |
Harald Welte | 24f921b | 2021-02-10 19:37:45 +0100 | [diff] [blame] | 385 | private function f_pc_int2bit(template (present) integer pc) |
| 386 | return template SCMG_param_AffectedPointCode { |
| 387 | if (istemplatekind(pc, "?")) { |
| 388 | return ?; |
| 389 | } else { |
| 390 | return int2bit(valueof(pc), 16); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | template (value) PDU_SCMG_message ts_SCMG_SSA(template (value) integer ssn, |
| 395 | integer pc, |
| 396 | template (value) BIT2 smi := '00'B) := { |
| 397 | messageType := sSAallowed, |
| 398 | affectedSSN := ssn, |
| 399 | affectedPC := int2bit(valueof(pc), 16), |
| 400 | smi := { |
| 401 | smi := smi, |
| 402 | reserved := '000000'B |
| 403 | }, |
| 404 | congLevel := omit |
| 405 | } |
| 406 | template (present) PDU_SCMG_message tr_SCMG_SSA(template (present) integer ssn := ?, |
| 407 | template (present) integer pc := ?, |
| 408 | template (present) BIT2 smi := ?) := { |
| 409 | messageType := sSAallowed, |
| 410 | affectedSSN := ssn, |
| 411 | affectedPC := f_pc_int2bit(pc), |
| 412 | smi := { |
| 413 | smi := smi, |
| 414 | reserved := '000000'B |
| 415 | }, |
| 416 | congLevel := omit |
| 417 | } |
| 418 | |
| 419 | template (value) PDU_SCMG_message ts_SCMG_SSP(template (value) integer ssn, |
| 420 | integer pc, |
| 421 | template (value) BIT2 smi := '00'B) := { |
| 422 | messageType := sSPprohib, |
| 423 | affectedSSN := ssn, |
| 424 | affectedPC := int2bit(valueof(pc), 16), |
| 425 | smi := { |
| 426 | smi := smi, |
| 427 | reserved := '000000'B |
| 428 | }, |
| 429 | congLevel := omit |
| 430 | } |
| 431 | template (present) PDU_SCMG_message tr_SCMG_SSP(template (present) integer ssn := ?, |
| 432 | template (present) integer pc := ?, |
| 433 | template (present) BIT2 smi := ?) := { |
| 434 | messageType := sSPprohib, |
| 435 | affectedSSN := ssn, |
| 436 | affectedPC := f_pc_int2bit(pc), |
| 437 | smi := { |
| 438 | smi := smi, |
| 439 | reserved := '000000'B |
| 440 | }, |
| 441 | congLevel := omit |
| 442 | } |
| 443 | |
| 444 | template (value) PDU_SCMG_message ts_SCMG_SST(template (value) integer ssn, |
| 445 | integer pc, |
| 446 | template (value) BIT2 smi := '00'B) := { |
| 447 | messageType := sSTstaTest, |
| 448 | affectedSSN := ssn, |
| 449 | affectedPC := int2bit(valueof(pc), 16), |
| 450 | smi := { |
| 451 | smi := smi, |
| 452 | reserved := '000000'B |
| 453 | }, |
| 454 | congLevel := omit |
| 455 | } |
| 456 | template (present) PDU_SCMG_message tr_SCMG_SST(template (present) integer ssn := ?, |
| 457 | template (present) integer pc := ?, |
| 458 | template (present) BIT2 smi := ?) := { |
| 459 | messageType := sSTstaTest, |
| 460 | affectedSSN := ssn, |
| 461 | affectedPC := f_pc_int2bit(pc), |
| 462 | smi := { |
| 463 | smi := smi, |
| 464 | reserved := '000000'B |
| 465 | }, |
| 466 | congLevel := omit |
| 467 | } |
| 468 | |
| 469 | |
Harald Welte | 0db4413 | 2019-10-17 11:09:05 +0200 | [diff] [blame] | 470 | |
Stefan Sperling | c307e68 | 2018-06-14 15:15:46 +0200 | [diff] [blame] | 471 | } |