Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 1 | module GSUP_Types { |
| 2 | |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 3 | /* GSUP_Types, defining abstract TTCN-3 data types for the GSUP protocol. |
| 4 | * |
| 5 | * GSUP is a non-standard protocol used between OsmoMSC/OsmoSGSN and OsmoHLR |
| 6 | * in order to replace the complex TCAP/MAP protocol. |
| 7 | * |
| 8 | * (C) 2017 by Harald Welte <laforge@gnumonks.org> |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * Released under the terms of GNU General Public License, Version 2 or |
| 12 | * (at your option) any later version. |
| 13 | */ |
| 14 | |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 15 | import from General_Types all; |
| 16 | import from Osmocom_Types all; |
| 17 | |
| 18 | type enumerated GSUP_IEI { |
| 19 | OSMO_GSUP_IMSI_IE ('01'O), |
| 20 | OSMO_GSUP_CAUSE_IE ('02'O), |
| 21 | OSMO_GSUP_AUTH_TUPLE_IE ('03'O), |
| 22 | OSMO_GSUP_PDP_INFO_COMPL_IE ('04'O), |
| 23 | OSMO_GSUP_PDP_INFO_IE ('05'O), |
| 24 | OSMO_GSUP_CANCEL_TYPE_IE ('06'O), |
| 25 | OSMO_GSUP_FREEZE_PTMSI_IE ('07'O), |
| 26 | OSMO_GSUP_MSISDN_IE ('08'O), |
| 27 | OSMO_GSUP_HLR_NUMBER_IE ('09'O), |
| 28 | OSMO_GSUP_PDP_CONTEXT_ID_IE ('10'O), |
| 29 | OSMO_GSUP_PDP_TYPE_IE ('11'O), |
| 30 | OSMO_GSUP_ACCESS_POINT_NAME_IE ('12'O), |
| 31 | OSMO_GSUP_PDP_QOS_IE ('13'O), |
| 32 | OSMO_GSUP_CHARG_CHAR_IE ('14'O), |
| 33 | |
| 34 | OSMO_GSUP_RAND_IE ('20'O), |
| 35 | OSMO_GSUP_SRES_IE ('21'O), |
| 36 | OSMO_GSUP_KC_IE ('22'O), |
| 37 | OSMO_GSUP_IK_IE ('23'O), |
| 38 | OSMO_GSUP_CK_IE ('24'O), |
| 39 | OSMO_GSUP_AUTN_IE ('25'O), |
| 40 | OSMO_GSUP_AUTS_IE ('26'O), |
| 41 | OSMO_GSUP_RES_IE ('27'O), |
| 42 | OSMO_GSUP_CN_DOMAIN_IE ('28'O) |
| 43 | } with { variant "FIELDLENGTH(8)" }; |
| 44 | |
| 45 | type enumerated GSUP_MessageType { |
| 46 | OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST ('00000100'B), |
| 47 | OSMO_GSUP_MSGT_UPDATE_LOCATION_ERROR ('00000101'B), |
| 48 | OSMO_GSUP_MSGT_UPDATE_LOCATION_RESULT ('00000110'B), |
| 49 | |
| 50 | OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST ('00001000'B), |
| 51 | OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR ('00001001'B), |
| 52 | OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT ('00001010'B), |
| 53 | |
| 54 | OSMO_GSUP_MSGT_AUTH_FAIL_REPORT ('00001011'B), |
| 55 | |
| 56 | OSMO_GSUP_MSGT_PURGE_MS_REQUEST ('00001100'B), |
| 57 | OSMO_GSUP_MSGT_PURGE_MS_ERROR ('00001101'B), |
| 58 | OSMO_GSUP_MSGT_PURGE_MS_RESULT ('00001110'B), |
| 59 | |
| 60 | OSMO_GSUP_MSGT_INSERT_DATA_REQUEST ('00010000'B), |
| 61 | OSMO_GSUP_MSGT_INSERT_DATA_ERROR ('00010001'B), |
| 62 | OSMO_GSUP_MSGT_INSERT_DATA_RESULT ('00010010'B), |
| 63 | |
| 64 | OSMO_GSUP_MSGT_DELETE_DATA_REQUEST ('00010100'B), |
| 65 | OSMO_GSUP_MSGT_DELETE_DATA_ERROR ('00010101'B), |
| 66 | OSMO_GSUP_MSGT_DELETE_DATA_RESULT ('00010110'B), |
| 67 | |
| 68 | OSMO_GSUP_MSGT_LOCATION_CANCEL_REQUEST ('00011100'B), |
| 69 | OSMO_GSUP_MSGT_LOCATION_CANCEL_ERROR ('00011101'B), |
| 70 | OSMO_GSUP_MSGT_LOCATION_CANCEL_RESULT ('00011110'B) |
| 71 | } with { variant "FIELDLENGTH(8)" }; |
| 72 | |
| 73 | type enumerated GSUP_CancelType { |
| 74 | OSMO_GSUP_CANCEL_TYPE_UPDATE (1), |
| 75 | OSMO_GSUP_CANCEL_TYPE_WITHDRAW (2) |
| 76 | } with { variant "FIELDLENGTH(8)" }; |
| 77 | |
| 78 | type enumerated GSUP_CnDomain { |
| 79 | OSMO_GSUP_CN_DOMAIN_PS (1), |
| 80 | OSMO_GSUP_CN_DOMAIN_CS (2) |
| 81 | } with { variant "FIELDLENGTH(8)" }; |
| 82 | |
| 83 | type record GSUP_IE { |
| 84 | GSUP_IEI tag, |
| 85 | uint8_t len, |
| 86 | GSUP_IeValue val |
| 87 | } with { variant (len) "LENGTHTO(val)" |
| 88 | variant (val) "CROSSTAG(imsi, tag = OSMO_GSUP_IMSI_IE; |
| 89 | cause, tag = OSMO_GSUP_CAUSE_IE; |
| 90 | cancel_type, tag = OSMO_GSUP_CANCEL_TYPE_IE; |
Harald Welte | 77a8eba | 2018-01-22 21:22:32 +0100 | [diff] [blame] | 91 | auth_tuple, tag = OSMO_GSUP_AUTH_TUPLE_IE; |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 92 | auts, tag = OSMO_GSUP_AUTS_IE; |
| 93 | rand, tag = OSMO_GSUP_RAND_IE; |
Harald Welte | 77a8eba | 2018-01-22 21:22:32 +0100 | [diff] [blame] | 94 | sres, tag = OSMO_GSUP_SRES_IE; |
| 95 | kc, tag = OSMO_GSUP_KC_IE; |
| 96 | ik, tag = OSMO_GSUP_IK_IE; |
| 97 | ck, tag = OSMO_GSUP_CK_IE; |
| 98 | autn, tag = OSMO_GSUP_AUTN_IE; |
| 99 | res, tag = OSMO_GSUP_RES_IE; |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 100 | msisdn, tag = OSMO_GSUP_MSISDN_IE; |
| 101 | hlr_number, tag = OSMO_GSUP_HLR_NUMBER_IE; |
| 102 | cn_domain, tag = OSMO_GSUP_CN_DOMAIN_IE; |
| 103 | charg_char, tag = OSMO_GSUP_CHARG_CHAR_IE)" |
| 104 | }; |
| 105 | |
| 106 | type record of GSUP_IE GSUP_IEs; |
| 107 | |
| 108 | type union GSUP_IeValue { |
| 109 | hexstring imsi, |
| 110 | integer cause, |
| 111 | GSUP_CancelType cancel_type, |
| 112 | //boolean pdp_info_compl, |
| 113 | //boolean freeze_ptmsi, |
| 114 | GSUP_IEs pdp_info, |
| 115 | GSUP_IEs auth_tuple, |
| 116 | octetstring auts, |
| 117 | octetstring rand, |
Harald Welte | 77a8eba | 2018-01-22 21:22:32 +0100 | [diff] [blame] | 118 | octetstring sres, |
| 119 | octetstring kc, |
| 120 | octetstring ik, |
| 121 | octetstring ck, |
| 122 | octetstring autn, |
| 123 | octetstring res, |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 124 | hexstring msisdn, |
| 125 | octetstring hlr_number, |
| 126 | GSUP_CnDomain cn_domain, |
| 127 | octetstring charg_char |
| 128 | }; |
| 129 | |
| 130 | type record GSUP_PDU { |
| 131 | GSUP_MessageType msg_type, |
| 132 | GSUP_IEs ies |
| 133 | }; |
| 134 | |
| 135 | external function enc_GSUP_PDU(in GSUP_PDU msg) return octetstring |
| 136 | with { extension "prototype(convert) encode(RAW)" }; |
| 137 | |
| 138 | external function dec_GSUP_PDU(in octetstring msg) return GSUP_PDU |
| 139 | with { extension "prototype(convert) decode(RAW)" }; |
| 140 | |
Harald Welte | 2f562b1 | 2018-01-24 20:52:38 +0100 | [diff] [blame] | 141 | function f_gsup_postprocess_decoded(inout GSUP_PDU gsup) { |
| 142 | if (gsup.ies[0].tag == OSMO_GSUP_IMSI_IE) { |
| 143 | /* if last digit is 'F', then there's an odd number of digits and we must strip the F */ |
| 144 | var integer num_digits := lengthof(gsup.ies[0].val.imsi); |
| 145 | if (gsup.ies[0].val.imsi[num_digits-1] == 'F'H) { |
| 146 | gsup.ies[0].val.imsi := substr(gsup.ies[0].val.imsi, 0, num_digits-1); |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | function f_gsup_preprocess_encoded(inout GSUP_PDU gsup) { |
| 152 | if (ischosen(gsup.ies[0].val.imsi)) { |
| 153 | /* if number of digits is odd, add a 'F' as padding at the end */ |
| 154 | var integer num_digits := lengthof(gsup.ies[0].val.imsi); |
| 155 | if (num_digits rem 2 == 1) { |
| 156 | gsup.ies[0].val.imsi := gsup.ies[0].val.imsi & 'F'H; |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 161 | |
Harald Welte | 77a8eba | 2018-01-22 21:22:32 +0100 | [diff] [blame] | 162 | template GSUP_IE ts_GSUP_IE_AuthTuple2G(octetstring rand, octetstring sres, |
| 163 | octetstring kc) := { |
| 164 | tag := OSMO_GSUP_AUTH_TUPLE_IE, |
| 165 | len := 0, /* overwritten */ |
| 166 | val := { |
| 167 | auth_tuple := { |
| 168 | valueof(ts_GSUP_IE_RAND(rand)), |
| 169 | valueof(ts_GSUP_IE_SRES(sres)), |
| 170 | valueof(ts_GSUP_IE_Kc(kc)) |
| 171 | } |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | template GSUP_IE ts_GSUP_IE_AuthTuple2G3G(octetstring rand, octetstring sres, |
| 176 | octetstring kc, octetstring ik, |
| 177 | octetstring ck, octetstring autn, |
| 178 | octetstring res) := { |
| 179 | tag := OSMO_GSUP_AUTH_TUPLE_IE, |
| 180 | len := 0, /* overwritten */ |
| 181 | val := { |
| 182 | auth_tuple := { |
| 183 | valueof(ts_GSUP_IE_RAND(rand)), |
| 184 | valueof(ts_GSUP_IE_SRES(sres)), |
| 185 | valueof(ts_GSUP_IE_Kc(kc)), |
| 186 | valueof(ts_GSUP_IE_IK(ik)), |
| 187 | valueof(ts_GSUP_IE_CK(ck)), |
| 188 | valueof(ts_GSUP_IE_AUTN(autn)), |
| 189 | valueof(ts_GSUP_IE_RES(res)) |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 194 | template GSUP_PDU tr_GSUP(template GSUP_MessageType msgt := ?, template GSUP_IEs ies := *) := { |
| 195 | msg_type := msgt, |
| 196 | ies := ies |
| 197 | } |
| 198 | |
| 199 | template GSUP_PDU ts_GSUP(GSUP_MessageType msgt, GSUP_IEs ies := {}) := { |
| 200 | msg_type := msgt, |
| 201 | ies := ies |
| 202 | } |
| 203 | |
| 204 | template GSUP_PDU ts_GSUP_SAI_REQ(hexstring imsi) := |
| 205 | ts_GSUP(OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST, { valueof(ts_GSUP_IE_IMSI(imsi)) }); |
| 206 | |
Harald Welte | ef9fa87 | 2018-01-22 03:00:17 +0100 | [diff] [blame] | 207 | template GSUP_PDU tr_GSUP_SAI_REQ(template hexstring imsi) := |
| 208 | tr_GSUP(OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST, { tr_GSUP_IE_IMSI(imsi), * }); |
| 209 | |
Harald Welte | 77a8eba | 2018-01-22 21:22:32 +0100 | [diff] [blame] | 210 | template (value) GSUP_PDU ts_GSUP_SAI_RES(hexstring imsi, GSUP_IE auth_tuple) := |
| 211 | ts_GSUP(OSMO_GSUP_MSGT_SEND_AUTH_INFO_RESULT, { |
| 212 | valueof(ts_GSUP_IE_IMSI(imsi)), auth_tuple }); |
| 213 | |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 214 | template GSUP_PDU tr_GSUP_SAI_ERR(template hexstring imsi, template integer cause) := |
Harald Welte | 071ed73 | 2018-01-23 19:53:52 +0100 | [diff] [blame] | 215 | tr_GSUP(OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR, { |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 216 | tr_GSUP_IE_IMSI(imsi), tr_GSUP_IE_Cause(cause) }); |
| 217 | |
Harald Welte | 071ed73 | 2018-01-23 19:53:52 +0100 | [diff] [blame] | 218 | template GSUP_PDU ts_GSUP_SAI_ERR(hexstring imsi, integer cause) := |
| 219 | tr_GSUP(OSMO_GSUP_MSGT_SEND_AUTH_INFO_ERROR, { |
| 220 | ts_GSUP_IE_IMSI(imsi), ts_GSUP_IE_Cause(cause) }); |
| 221 | |
| 222 | |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 223 | template GSUP_PDU tr_GSUP_SAI_RES(template hexstring imsi) := |
| 224 | tr_GSUP(OSMO_GSUP_MSGT_SEND_AUTH_INFO_REQUEST, { |
| 225 | tr_GSUP_IE_IMSI(imsi), *, tr_GSUP_IE(OSMO_GSUP_AUTH_TUPLE_IE), * }); |
| 226 | |
Harald Welte | dfe94dd | 2018-01-21 13:55:22 +0100 | [diff] [blame] | 227 | template GSUP_PDU tr_GSUP_UL_REQ(template hexstring imsi) := |
| 228 | tr_GSUP(OSMO_GSUP_MSGT_UPDATE_LOCATION_REQUEST, { |
| 229 | tr_GSUP_IE_IMSI(imsi), * }); |
| 230 | |
| 231 | template GSUP_PDU ts_GSUP_UL_RES(hexstring imsi) := |
| 232 | ts_GSUP(OSMO_GSUP_MSGT_UPDATE_LOCATION_RESULT, { valueof(ts_GSUP_IE_IMSI(imsi)) }); |
| 233 | |
Harald Welte | 6ff8190 | 2018-01-21 19:09:08 +0100 | [diff] [blame] | 234 | template GSUP_PDU ts_GSUP_UL_ERR(hexstring imsi, integer cause) := |
| 235 | ts_GSUP(OSMO_GSUP_MSGT_UPDATE_LOCATION_ERROR, { |
| 236 | valueof(ts_GSUP_IE_IMSI(imsi)), valueof(ts_GSUP_IE_Cause(cause)) }); |
| 237 | |
| 238 | template GSUP_PDU ts_GSUP_ISD_REQ(hexstring imsi, hexstring msisdn) := |
| 239 | ts_GSUP(OSMO_GSUP_MSGT_INSERT_DATA_REQUEST, { |
| 240 | valueof(ts_GSUP_IE_IMSI(imsi)), valueof(ts_GSUP_IE_MSISDN(msisdn)) }); |
| 241 | |
| 242 | template GSUP_PDU tr_GSUP_ISD_RES(template hexstring imsi) := |
| 243 | tr_GSUP(OSMO_GSUP_MSGT_INSERT_DATA_RESULT, { |
Harald Welte | dfe94dd | 2018-01-21 13:55:22 +0100 | [diff] [blame] | 244 | tr_GSUP_IE_IMSI(imsi), * }); |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 245 | |
| 246 | |
| 247 | template GSUP_IE tr_GSUP_IE(template GSUP_IEI iei, template GSUP_IeValue val := ?) := { |
| 248 | tag := iei, |
| 249 | len := ?, |
| 250 | val := val |
| 251 | } |
| 252 | |
| 253 | template (value) GSUP_IE ts_GSUP_IE_IMSI(hexstring imsi) := { |
| 254 | tag := OSMO_GSUP_IMSI_IE, |
| 255 | len := 0, /* overwritten */ |
| 256 | val := { |
| 257 | imsi := imsi |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | template GSUP_IE tr_GSUP_IE_IMSI(template hexstring imsi) := { |
| 262 | tag := OSMO_GSUP_IMSI_IE, |
| 263 | len := ?, |
| 264 | val := { |
| 265 | imsi := imsi |
| 266 | } |
| 267 | } |
| 268 | |
Harald Welte | 6ff8190 | 2018-01-21 19:09:08 +0100 | [diff] [blame] | 269 | template (value) GSUP_IE ts_GSUP_IE_MSISDN(hexstring msisdn) := { |
| 270 | tag := OSMO_GSUP_MSISDN_IE, |
| 271 | len := 0, /* overwritten */ |
| 272 | val := { |
| 273 | msisdn := msisdn |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | template GSUP_IE tr_GSUP_IE_MSISDN(template hexstring msisdn) := { |
| 278 | tag := OSMO_GSUP_MSISDN_IE, |
| 279 | len := ?, |
| 280 | val := { |
| 281 | msisdn := msisdn |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 286 | template (value) GSUP_IE ts_GSUP_IE_Cause(integer cause) := { |
| 287 | tag := OSMO_GSUP_CAUSE_IE, |
| 288 | len := 0, /* overwritten */ |
| 289 | val := { |
| 290 | cause := cause |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | template GSUP_IE tr_GSUP_IE_Cause(template integer cause) := { |
| 295 | tag := OSMO_GSUP_CAUSE_IE, |
| 296 | len := ?, |
| 297 | val := { |
| 298 | cause := cause |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | template (value) GSUP_IE ts_GSUP_IE_AUTS(octetstring auts) := { |
| 303 | tag := OSMO_GSUP_AUTS_IE, |
| 304 | len := 0, /* overwritten */ |
| 305 | val := { |
| 306 | auts := auts |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | template (value) GSUP_IE ts_GSUP_IE_RAND(octetstring rand) := { |
| 311 | tag := OSMO_GSUP_RAND_IE, |
| 312 | len := 0, /* overwritten */ |
| 313 | val := { |
| 314 | rand := rand |
| 315 | } |
| 316 | } |
| 317 | |
Harald Welte | 77a8eba | 2018-01-22 21:22:32 +0100 | [diff] [blame] | 318 | template (value) GSUP_IE ts_GSUP_IE_SRES(octetstring sres) := { |
| 319 | tag := OSMO_GSUP_SRES_IE, |
| 320 | len := 0, /* overwritten */ |
| 321 | val := { |
| 322 | sres := sres |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | template (value) GSUP_IE ts_GSUP_IE_Kc(octetstring kc) := { |
| 327 | tag := OSMO_GSUP_KC_IE, |
| 328 | len := 0, /* overwritten */ |
| 329 | val := { |
| 330 | kc := kc |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | template (value) GSUP_IE ts_GSUP_IE_IK(octetstring ik) := { |
| 335 | tag := OSMO_GSUP_IK_IE, |
| 336 | len := 0, /* overwritten */ |
| 337 | val := { |
| 338 | ik := ik |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | template (value) GSUP_IE ts_GSUP_IE_CK(octetstring ck) := { |
| 343 | tag := OSMO_GSUP_CK_IE, |
| 344 | len := 0, /* overwritten */ |
| 345 | val := { |
| 346 | ck := ck |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | template (value) GSUP_IE ts_GSUP_IE_AUTN(octetstring autn) := { |
| 351 | tag := OSMO_GSUP_AUTN_IE, |
| 352 | len := 0, /* overwritten */ |
| 353 | val := { |
| 354 | autn := autn |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | template (value) GSUP_IE ts_GSUP_IE_RES(octetstring res) := { |
| 359 | tag := OSMO_GSUP_RES_IE, |
| 360 | len := 0, /* overwritten */ |
| 361 | val := { |
| 362 | res := res |
| 363 | } |
| 364 | } |
Harald Welte | df32723 | 2017-12-28 22:51:51 +0100 | [diff] [blame] | 365 | |
| 366 | |
| 367 | |
| 368 | } with { encode "RAW"; variant "FIELDORDER(msb)" } |