Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 1 | module BSC_ConnectionHandler { |
| 2 | |
| 3 | import from General_Types all; |
| 4 | import from Osmocom_Types all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 5 | import from Native_Functions all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 6 | import from GSM_Types all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 7 | import from IPL4asp_Types all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 8 | import from SCCPasp_Types all; |
| 9 | import from BSSAP_Types all; |
| 10 | import from BSSMAP_Emulation all; |
| 11 | import from BSSMAP_Templates all; |
| 12 | |
| 13 | import from GSUP_Types all; |
| 14 | import from GSUP_Emulation all; |
| 15 | |
| 16 | import from MNCC_Types all; |
| 17 | import from MNCC_Emulation all; |
| 18 | |
Harald Welte | 4aa970c | 2018-01-26 10:38:09 +0100 | [diff] [blame] | 19 | import from MGCP_Types all; |
| 20 | import from MGCP_Emulation all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 21 | import from MGCP_Templates all; |
| 22 | import from SDP_Types all; |
Harald Welte | 4aa970c | 2018-01-26 10:38:09 +0100 | [diff] [blame] | 23 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 24 | import from MobileL3_Types all; |
| 25 | import from MobileL3_CommonIE_Types all; |
| 26 | import from MobileL3_MM_Types all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 27 | import from MobileL3_CC_Types all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 28 | import from L3_Templates all; |
Harald Welte | 158a7ca | 2018-02-16 18:11:31 +0100 | [diff] [blame] | 29 | import from L3_Common all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 30 | |
| 31 | /* this component represents a single subscriber connection */ |
Harald Welte | 4aa970c | 2018-01-26 10:38:09 +0100 | [diff] [blame] | 32 | type component BSC_ConnHdlr extends BSSAP_ConnHdlr, MNCC_ConnHdlr, GSUP_ConnHdlr, MGCP_ConnHdlr { |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 33 | var BSC_ConnHdlrPars g_pars; |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 34 | timer g_Tguard := 60.0; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 35 | } |
| 36 | |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 37 | type record BSC_ConnHdlrNetworkPars { |
| 38 | OCT1 kc_support, |
| 39 | boolean expect_tmsi, |
| 40 | boolean expect_auth, |
| 41 | boolean expect_ciph |
| 42 | } |
| 43 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 44 | type record BSC_ConnHdlrPars { |
| 45 | SCCP_PAR_Address sccp_addr_own, |
| 46 | SCCP_PAR_Address sccp_addr_peer, |
| 47 | BSSMAP_IE_CellIdentifier cell_id, |
Harald Welte | 256571e | 2018-01-24 18:47:19 +0100 | [diff] [blame] | 48 | hexstring imei, |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 49 | hexstring imsi, |
Harald Welte | 8260057 | 2018-01-21 20:54:08 +0100 | [diff] [blame] | 50 | hexstring msisdn, |
Harald Welte | 256571e | 2018-01-24 18:47:19 +0100 | [diff] [blame] | 51 | OCT4 tmsi optional, |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 52 | MobileStationClassmark1_V cm1, |
Harald Welte | 8260057 | 2018-01-21 20:54:08 +0100 | [diff] [blame] | 53 | BSSMAP_IE_ClassmarkInformationType2 cm2, |
Harald Welte | 1611428 | 2018-01-24 22:41:21 +0100 | [diff] [blame] | 54 | BSSMAP_IE_ClassmarkInformationType3 cm3 optional, |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 55 | AuthVector vec optional, |
Neels Hofmeyr | c1f105a | 2018-03-01 20:00:19 +0100 | [diff] [blame] | 56 | BSC_ConnHdlrNetworkPars net, |
| 57 | boolean send_early_cm |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 58 | }; |
| 59 | |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 60 | /* get a one-octet bitmaks of supported algorithms based on Classmark information */ |
| 61 | function f_alg_mask_from_cm(BSSMAP_IE_ClassmarkInformationType2 cm2) return OCT1 { |
| 62 | var BIT8 res := '00000001'B; /* A5/0 always supported */ |
| 63 | |
| 64 | if (cm2.a5_1 == '0'B) { |
| 65 | res := res or4b '00000010'B; |
| 66 | } |
| 67 | if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) { |
| 68 | res := res or4b '00000100'B; |
| 69 | } |
| 70 | if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) { |
| 71 | res := res or4b '00001000'B; |
| 72 | } |
| 73 | /* TODO: CM3 for A5/4 and beyond */ |
| 74 | return bit2oct(res); |
| 75 | } |
| 76 | |
| 77 | /* determine the best algorithm available within the bit-mask */ |
| 78 | function f_best_alg_from_mask(OCT1 alg_in) return OCT1 { |
| 79 | var BIT8 alg := oct2bit(alg_in); |
| 80 | var BIT8 ordered_algs[8] := { |
| 81 | '10000000'B, '01000000'B, '00100000'B, '00010000'B, |
| 82 | '00001000'B, /* A5/3 */ |
| 83 | '00000010'B, /* A5/1 */ |
| 84 | '00000100'B, /* A5/2 */ |
| 85 | '00000001'B /* A5/0 */ } |
| 86 | for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) { |
| 87 | if (alg and4b ordered_algs[i] != '00000000'B) { |
| 88 | return bit2oct(ordered_algs[i]); |
| 89 | } |
| 90 | } |
| 91 | return '00'O; |
| 92 | } |
| 93 | |
| 94 | /* return an integer like '1' for A5/1 based on a mask (with only one bit set */ |
| 95 | function f_alg_from_mask(OCT1 mask_in) return integer { |
| 96 | var BIT8 mask := oct2bit(mask_in); |
| 97 | for (var integer i := 0; i < 8; i := i+1) { |
| 98 | if (mask and4b ('00000001'B << i) != '00000000'B) { |
| 99 | return i; |
| 100 | } |
| 101 | } |
| 102 | return -1; |
| 103 | } |
| 104 | |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 105 | /* altstep for the global guard timer */ |
| 106 | private altstep as_Tguard() runs on BSC_ConnHdlr { |
| 107 | [] g_Tguard.timeout { |
Daniel Willmann | 90829d6 | 2018-02-15 17:45:14 +0100 | [diff] [blame] | 108 | setverdict(fail, "Tguard timeout"); |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 109 | self.stop; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /* init function, called as first function in new BSC_ConnHdlr */ |
Harald Welte | ad2952e | 2018-01-27 14:12:46 +0100 | [diff] [blame] | 114 | function f_init_handler(BSC_ConnHdlrPars pars, float t_guard := 60.0) runs on BSC_ConnHdlr { |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 115 | /* make parameters available via component variable */ |
| 116 | g_pars := pars; |
| 117 | /* Start guard timer and activate it as default */ |
Harald Welte | ad2952e | 2018-01-27 14:12:46 +0100 | [diff] [blame] | 118 | g_Tguard.start(t_guard); |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 119 | activate(as_Tguard()); |
| 120 | } |
| 121 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 122 | |
| 123 | /* Callback function from general BSSMAP_Emulation whenever a connectionless |
| 124 | * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */ |
| 125 | private function BscUnitdataCallback(PDU_BSSAP bssap) |
| 126 | runs on BSSMAP_Emulation_CT return template PDU_BSSAP { |
| 127 | var template PDU_BSSAP resp := omit; |
| 128 | |
| 129 | log("BSSMAP_BscUnitdataCallback"); |
| 130 | /* answer all RESET with RESET ACK */ |
| 131 | if (match(bssap, tr_BSSMAP_Reset)){ |
| 132 | log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK"); |
| 133 | resp := ts_BSSMAP_ResetAck; |
| 134 | } |
| 135 | |
| 136 | /* FIXME: Handle paging, etc. */ |
| 137 | return resp; |
| 138 | } |
| 139 | |
| 140 | const BssmapOps BSC_BssmapOps := { |
| 141 | /* Create call-back for inbound connections from MSC (hand-over) */ |
| 142 | create_cb := refers(BSSMAP_Emulation.ExpectedCreateCallback), |
| 143 | unitdata_cb := refers(BscUnitdataCallback), |
| 144 | decode_dtap := true, |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 145 | role_ms := true, |
| 146 | sccp_addr_local := omit, |
| 147 | sccp_addr_peer := omit |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | |
| 151 | private function MnccUnitdataCallback(MNCC_PDU mncc) |
| 152 | runs on MNCC_Emulation_CT return template MNCC_PDU { |
| 153 | log("Ignoring MNCC", mncc); |
| 154 | return omit; |
| 155 | } |
| 156 | |
| 157 | const MnccOps BCC_MnccOps := { |
| 158 | create_cb := refers(MNCC_Emulation.ExpectedCreateCallback), |
| 159 | unitdata_cb := refers(MnccUnitdataCallback) |
| 160 | } |
| 161 | |
| 162 | |
| 163 | |
| 164 | template BSSAP_Conn_Req ts_BSSAP_Conn_Req(SCCP_PAR_Address peer, SCCP_PAR_Address own, PDU_BSSAP bssap) := { |
| 165 | addr_peer := peer, |
| 166 | addr_own := own, |
| 167 | bssap := bssap |
| 168 | }; |
| 169 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 170 | /* Encode 'l3' and ask BSSMAP_Emulation to create new connection with COMPL L3 INFO */ |
| 171 | function f_bssap_compl_l3(PDU_ML3_MS_NW l3) |
| 172 | runs on BSC_ConnHdlr { |
| 173 | log("Sending COMPL L3: ", l3); |
| 174 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3); |
| 175 | BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, |
| 176 | valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc)))); |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 177 | alt { |
| 178 | [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {} |
| 179 | [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
| 180 | setverdict(fail, "DISC.ind from SCCP"); |
| 181 | self.stop; |
| 182 | } |
| 183 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 184 | } |
| 185 | |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 186 | type enumerated EstablishType { |
| 187 | EST_TYPE_MO_CALL, |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 188 | EST_TYPE_EMERG_CALL, |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 189 | EST_TYPE_PAG_RESP |
| 190 | }; |
| 191 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 192 | /* helper function to fully establish a dedicated channel */ |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 193 | function f_establish_fully(MobileIdentityLV mi, EstablishType etype := EST_TYPE_MO_CALL) |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 194 | runs on BSC_ConnHdlr { |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 195 | var PDU_ML3_MS_NW l3_info; |
| 196 | select (etype) { |
| 197 | case (EST_TYPE_MO_CALL) { |
| 198 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi)); |
| 199 | } |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 200 | case (EST_TYPE_EMERG_CALL) { |
| 201 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi)); |
| 202 | } |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 203 | case (EST_TYPE_PAG_RESP) { |
| 204 | l3_info := valueof(ts_PAG_RESP(mi)); |
| 205 | } |
| 206 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 207 | |
| 208 | /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */ |
| 209 | f_bssap_compl_l3(l3_info); |
| 210 | |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 211 | f_mm_common(); |
| 212 | if (g_pars.net.expect_ciph) { |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 213 | /* implicit CM SERVICE ACCEPT? */ |
| 214 | } else { |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 215 | if (etype != EST_TYPE_PAG_RESP) { |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 216 | /* explicit CM SERVICE ACCEPT */ |
| 217 | BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC)); |
| 218 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 219 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /* build a PDU_ML3_MS_NW containing a Location Update by IMSI */ |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 223 | function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 224 | { |
| 225 | var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi)); |
| 226 | return f_build_lu(mi); |
| 227 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 228 | function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW |
Harald Welte | ba7b6d9 | 2018-01-23 21:32:34 +0100 | [diff] [blame] | 229 | { |
| 230 | var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei)); |
| 231 | return f_build_lu(mi); |
| 232 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 233 | function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW |
Harald Welte | ba7b6d9 | 2018-01-23 21:32:34 +0100 | [diff] [blame] | 234 | { |
| 235 | var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi)); |
| 236 | return f_build_lu(mi); |
| 237 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 238 | private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 239 | { |
| 240 | var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O }; |
| 241 | var PDU_ML3_MS_NW l3_info := valueof(ts_ML3_MO_LU_Req(valueof(ts_ML3_IE_LuType_Attach), |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 242 | old_lai, mi, g_pars.cm1)); |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 243 | return l3_info; |
| 244 | } |
| 245 | |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 246 | function f_mm_auth() runs on BSC_ConnHdlr |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 247 | { |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 248 | if (g_pars.net.expect_auth) { |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 249 | g_pars.vec := f_gen_auth_vec_2g(); |
| 250 | var GSUP_IE auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand, |
| 251 | g_pars.vec.sres, |
| 252 | g_pars.vec.kc)); |
| 253 | GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)); |
| 254 | GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple)); |
| 255 | |
| 256 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand))); |
| 257 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres))); |
| 258 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 259 | } |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 260 | |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 261 | function f_mm_common() runs on BSC_ConnHdlr |
| 262 | { |
| 263 | f_mm_auth(); |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 264 | if (g_pars.net.expect_ciph) { |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 265 | var OCT1 a5_net := f_alg_mask_from_cm(g_pars.cm2); |
| 266 | var OCT1 a5_intersect := g_pars.net.kc_support and4b a5_net; |
| 267 | alt { |
| 268 | [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(a5_intersect, g_pars.vec.kc)) { |
| 269 | var OCT1 a5_chosen := f_best_alg_from_mask(a5_intersect); |
| 270 | var integer a5_nr := f_alg_from_mask(a5_chosen); |
| 271 | BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1))); |
| 272 | } |
| 273 | [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(?, g_pars.vec.kc)) { |
| 274 | setverdict(fail, "Wrong ciphering algorithm mask in CiphModCmd"); |
| 275 | self.stop; |
| 276 | } |
| 277 | } |
| 278 | /* FIXME: Send the best available algorithm */ |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 279 | } |
| 280 | } |
| 281 | |
Neels Hofmeyr | c1f105a | 2018-03-01 20:00:19 +0100 | [diff] [blame] | 282 | function f_perform_lu() |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 283 | runs on BSC_ConnHdlr { |
| 284 | var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi) |
| 285 | var PDU_DTAP_MT dtap_mt; |
| 286 | |
| 287 | /* tell GSUP dispatcher to send this IMSI to us */ |
| 288 | f_create_gsup_expect(hex2str(g_pars.imsi)); |
| 289 | |
| 290 | /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */ |
| 291 | f_bssap_compl_l3(l3_lu); |
| 292 | |
Neels Hofmeyr | c1f105a | 2018-03-01 20:00:19 +0100 | [diff] [blame] | 293 | if (g_pars.send_early_cm) { |
Harald Welte | 8a121b3 | 2018-01-22 03:00:41 +0100 | [diff] [blame] | 294 | BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3)); |
| 295 | } |
Harald Welte | 5c2622c | 2018-01-21 20:45:20 +0100 | [diff] [blame] | 296 | |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 297 | f_mm_common(); |
Harald Welte | 1611428 | 2018-01-24 22:41:21 +0100 | [diff] [blame] | 298 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 299 | /* Expect MSC to perform LU with HLR */ |
| 300 | GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi)); |
| 301 | GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn)); |
| 302 | GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi)); |
| 303 | GSUP.send(ts_GSUP_UL_RES(g_pars.imsi)); |
| 304 | |
| 305 | alt { |
| 306 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt { |
| 307 | var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept; |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 308 | if (g_pars.net.expect_tmsi) { |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 309 | if (not ispresent(lu_acc.mobileIdentityTLV) or |
| 310 | not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) { |
| 311 | setverdict(fail, "Expected TMSI but no TMSI was allocated"); |
| 312 | self.stop; |
| 313 | } else { |
Harald Welte | 256571e | 2018-01-24 18:47:19 +0100 | [diff] [blame] | 314 | g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 315 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl)); |
| 316 | } |
| 317 | } else { |
| 318 | if (ispresent(lu_acc.mobileIdentityTLV) and |
| 319 | ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) { |
| 320 | setverdict(fail, "Expected no TMSI but TMSI was allocated"); |
| 321 | self.stop; |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) { |
| 326 | setverdict(fail, "Expected LU ACK, but received LU REJ"); |
| 327 | self.stop; |
| 328 | } |
| 329 | } |
| 330 | /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */ |
| 331 | BSSAP.receive(tr_BSSMAP_ClearCommand); |
| 332 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 333 | BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND); |
| 334 | setverdict(pass); |
| 335 | } |
| 336 | |
| 337 | function f_foo() runs on BSC_ConnHdlr{ |
| 338 | /* SCCP CC handled by BSSMAP_Emulation_CT.main() */ |
| 339 | /* Expect auth, if enabled */ |
| 340 | |
| 341 | /* TODO: ISD */ |
| 342 | /* Expect encr, if enabled */ |
| 343 | /* Expect encr, if enabled */ |
| 344 | /* Expect ASS CMD, if chan_type != requested */ |
| 345 | /* Send ASS CMPL in successful case */ |
| 346 | |
| 347 | /* Expect AoIP port/ip information for RTP stream */ |
| 348 | /* Expect MSC-originated MGCP to our simulated MGW */ |
| 349 | /* Verify Counters via CTRL */ |
| 350 | /* re-configure MSC behaviour via VTY */ |
| 351 | } |
| 352 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 353 | /* parameters related to a (MO?) voice call */ |
| 354 | type record CallParameters { |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 355 | /* CC related parameters */ |
| 356 | hexstring called_party, /* whom are we calling */ |
| 357 | integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */ |
| 358 | BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */ |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 359 | boolean emergency, /* is this an emergency call? */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 360 | |
| 361 | /* MNCC related parameters */ |
| 362 | uint32_t mncc_callref optional, /* call reference on the MNCC side */ |
| 363 | MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */ |
| 364 | |
| 365 | /* RTP related parameters */ |
| 366 | HostName bss_rtp_ip optional, /* BSS Side RTP IP */ |
| 367 | PortNumber bss_rtp_port optional, /* BSS Side RTP Port */ |
| 368 | HostName mss_rtp_ip optional, /* MSS Side RTP IP */ |
| 369 | PortNumber mss_rtp_port optional, /* MSS Side RTP Port */ |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 370 | HostName mgw_rtp_ip_bss, /* BSS-facing MGW RTP IP */ |
| 371 | PortNumber mgw_rtp_port_bss, /* BSS-facing MGW RTP Port */ |
| 372 | HostName mgw_rtp_ip_mss, /* MSS-facing MGW RTP IP */ |
| 373 | PortNumber mgw_rtp_port_mss, /* MSS-facing MGW RTP Port */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 374 | uint7_t rtp_payload_type, /* dynamic RTP payload type */ |
| 375 | charstring rtp_sdp_format, /* AMR/8000 or the like */ |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 376 | boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX |
| 377 | (f_mt_call and f_mt_call) */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 378 | |
Philipp Maier | cd66857 | 2018-03-19 16:11:52 +0100 | [diff] [blame] | 379 | MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 380 | MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */, |
| 381 | MgcpConnectionId mgcp_connection_id_bss, /* MGCP Connection ID BSS Side */ |
| 382 | MgcpConnectionId mgcp_connection_id_mss /* MGCP Connection ID MSS Side */ |
| 383 | } |
| 384 | |
| 385 | template (value) CallParameters t_CallParams(hexstring called, integer tid) := { |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 386 | called_party := called, |
| 387 | transaction_id := tid, |
| 388 | bearer_cap := valueof(ts_Bcap_voice), |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 389 | emergency := false, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 390 | mncc_callref := omit, |
| 391 | mncc_bearer_cap := valueof(ts_MNCC_bcap_voice), |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 392 | bss_rtp_ip := "9.8.7.6", |
| 393 | bss_rtp_port := 9000, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 394 | mss_rtp_ip := omit, |
| 395 | mss_rtp_port := omit, |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 396 | mgw_rtp_ip_bss := "1.1.1.1", |
| 397 | mgw_rtp_port_bss := 10000, |
| 398 | mgw_rtp_ip_mss := "1.1.1.1", |
| 399 | mgw_rtp_port_mss := 11000, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 400 | rtp_payload_type := 98, |
| 401 | rtp_sdp_format := "AMR/8000", |
| 402 | mgcp_call_id := omit, |
| 403 | mgcp_ep := omit, |
| 404 | mgcp_connection_id_bss := '0'H,// |
| 405 | mgcp_connection_id_mss := '0'H // |
| 406 | }; |
| 407 | |
| 408 | |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 409 | function f_mt_call(inout CallParameters cpars) |
| 410 | runs on BSC_ConnHdlr { |
| 411 | |
| 412 | var MobileIdentityLV mi; |
| 413 | var MNCC_PDU mncc; |
| 414 | var MgcpCommand mgcp_cmd; |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 415 | var boolean respond_to_dlcx; |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 416 | |
| 417 | f_bssmap_register_imsi(g_pars.imsi, g_pars.tmsi); |
| 418 | |
| 419 | /* Allocate a call reference and send SETUP via MNCC to MSC */ |
| 420 | cpars.mncc_callref := f_rnd_int(2147483648); |
| 421 | MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn), |
| 422 | hex2str(cpars.called_party), hex2str(g_pars.imsi))); |
| 423 | /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */ |
| 424 | BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi)); |
| 425 | |
| 426 | /* If we have a TMSI, use TMSI instead of IMSI */ |
| 427 | if (ispresent(g_pars.tmsi)) { |
| 428 | mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi)); |
| 429 | } else { |
| 430 | mi := valueof(ts_MI_IMSI_LV(g_pars.imsi)); |
| 431 | } |
| 432 | f_establish_fully(mi, EST_TYPE_PAG_RESP); |
| 433 | |
| 434 | /* MS <- MSC: Expect CC SETUP */ |
| 435 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party))); |
| 436 | |
| 437 | /* MS -> MSC: ALERTING */ |
| 438 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id))); |
| 439 | MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref)); |
| 440 | |
| 441 | |
| 442 | /* Create MGCP expect */ |
| 443 | f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit}); |
| 444 | /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */ |
| 445 | MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref)); |
| 446 | |
| 447 | /* First MGCP CRCX (for BSS/RAN side) */ |
| 448 | MGCP.receive(tr_CRCX) -> value mgcp_cmd { |
| 449 | cpars.mgcp_call_id := f_MgcpCmd_extract_call_id(mgcp_cmd); |
Philipp Maier | 4b2692d | 2018-03-14 16:37:48 +0100 | [diff] [blame] | 450 | |
| 451 | /* When the endpoint contains a wildcard we keep the endpoint |
| 452 | * identifier we have set up in cpars. Otherwise we use the |
| 453 | * endpoint name that the call agent has supplied */ |
| 454 | if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) { |
| 455 | cpars.mgcp_ep := mgcp_cmd.line.ep; |
| 456 | } |
| 457 | |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 458 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_rtp_ip_bss, cpars.mgw_rtp_ip_bss, |
| 459 | hex2str(cpars.mgcp_call_id), "42", |
| 460 | cpars.mgw_rtp_port_bss, |
| 461 | { int2str(cpars.rtp_payload_type) }, |
| 462 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 463 | cpars.rtp_sdp_format)), |
| 464 | valueof(ts_SDP_ptime(20)) })); |
Philipp Maier | 4b2692d | 2018-03-14 16:37:48 +0100 | [diff] [blame] | 465 | var template MgcpResponse mgcp_resp; |
| 466 | mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_bss, sdp); |
| 467 | f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep)); |
| 468 | MGCP.send(mgcp_resp); |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 469 | } |
| 470 | /* Second MGCP CRCX (this time for MSS/CN side) */ |
| 471 | MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd { |
| 472 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_rtp_ip_mss, cpars.mgw_rtp_ip_mss, |
| 473 | hex2str(cpars.mgcp_call_id), "42", |
| 474 | cpars.mgw_rtp_port_mss, |
| 475 | { int2str(cpars.rtp_payload_type) }, |
| 476 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 477 | cpars.rtp_sdp_format)), |
| 478 | valueof(ts_SDP_ptime(20)) })); |
| 479 | MGCP.send(ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_mss, sdp)); |
| 480 | /* MSC acknowledges the MNCC_CREATE to the MNCC handler */ |
| 481 | MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)); |
| 482 | } |
| 483 | |
| 484 | /* expect the MSC to trigger a BSSMAP ASSIGNMENT */ |
| 485 | var BSSMAP_IE_AoIP_TransportLayerAddress tla_ass := |
| 486 | valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.mgw_rtp_ip_bss),cpars.mgw_rtp_port_bss)); |
| 487 | BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) { |
| 488 | var BSSMAP_IE_AoIP_TransportLayerAddress tla; |
| 489 | tla := valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.bss_rtp_ip), cpars.bss_rtp_port)); |
| 490 | BSSAP.send(ts_BSSMAP_AssignmentComplete(omit, tla)); |
| 491 | } |
| 492 | |
| 493 | /* MS -> MSC: ALERTING */ |
| 494 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id))); |
| 495 | MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)); |
| 496 | |
| 497 | /* FIXME */ |
| 498 | f_sleep(3.0); |
| 499 | |
| 500 | /* Hangup by "A" side */ |
| 501 | MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23)))); |
| 502 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id))); |
| 503 | |
| 504 | if (false) { |
| 505 | /* A-side (PLMN) Release of call */ |
| 506 | MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42)))); |
| 507 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))); |
| 508 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id))); |
| 509 | } else { |
| 510 | /* B-side (MS) Release of call */ |
| 511 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_RELEASE(cpars.transaction_id, '1'B, '0000000'B))); |
| 512 | MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref)); |
| 513 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id))); |
| 514 | } |
| 515 | |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 516 | respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx)); |
| 517 | |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 518 | /* clearing of radio channel */ |
| 519 | interleave { |
| 520 | [] BSSAP.receive(tr_BSSMAP_ClearCommand) { |
| 521 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 522 | BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND); |
| 523 | } |
| 524 | [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd { |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 525 | if (respond_to_dlcx) { |
| 526 | /* TODO: For one or all connections on EP? */ |
| 527 | MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id)); |
| 528 | f_create_mgcp_delete_ep(cpars.mgcp_ep); |
| 529 | } |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | setverdict(pass); |
| 533 | } |
| 534 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 535 | function f_mo_call(inout CallParameters cpars) |
| 536 | runs on BSC_ConnHdlr { |
| 537 | |
| 538 | var MobileIdentityLV mi; |
| 539 | var MNCC_PDU mncc; |
| 540 | var MgcpCommand mgcp_cmd; |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 541 | var boolean respond_to_dlcx; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 542 | |
| 543 | /* If we have a TMSI, use TMSI instead of IMSI */ |
| 544 | if (ispresent(g_pars.tmsi)) { |
| 545 | mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi)); |
| 546 | } else { |
| 547 | mi := valueof(ts_MI_IMSI_LV(g_pars.imsi)); |
| 548 | } |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 549 | if (cpars.emergency) { |
| 550 | f_establish_fully(mi, EST_TYPE_EMERG_CALL); |
| 551 | } else { |
| 552 | f_establish_fully(mi, EST_TYPE_MO_CALL); |
| 553 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 554 | |
| 555 | /* Create MNCC and MGCP expect */ |
| 556 | f_create_mncc_expect(hex2str(cpars.called_party)); |
| 557 | f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit}); |
| 558 | |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 559 | if (cpars.emergency) { |
| 560 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id))); |
| 561 | } else { |
| 562 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party))); |
| 563 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 564 | interleave { |
| 565 | [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc { |
| 566 | cpars.mncc_callref := mncc.u.signal.callref; |
| 567 | /* Call Proceeding */ |
| 568 | MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap)); |
| 569 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id))); |
| 570 | }; |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 571 | /* First MGCP CRCX (for BSS/RAN side) */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 572 | [] MGCP.receive(tr_CRCX) -> value mgcp_cmd { |
| 573 | cpars.mgcp_call_id := f_MgcpCmd_extract_call_id(mgcp_cmd); |
Philipp Maier | f1e02bb | 2018-03-15 16:30:00 +0100 | [diff] [blame] | 574 | |
| 575 | /* When the endpoint contains a wildcard we keep the endpoint |
| 576 | * identifier we have set up in cpars. Otherwise we use the |
| 577 | * endpoint name that the call agent has supplied */ |
| 578 | if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) { |
| 579 | cpars.mgcp_ep := mgcp_cmd.line.ep; |
| 580 | } |
| 581 | |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 582 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_rtp_ip_bss, cpars.mgw_rtp_ip_bss, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 583 | hex2str(cpars.mgcp_call_id), "42", |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 584 | cpars.mgw_rtp_port_bss, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 585 | { int2str(cpars.rtp_payload_type) }, |
| 586 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 587 | cpars.rtp_sdp_format)), |
| 588 | valueof(ts_SDP_ptime(20)) })); |
Philipp Maier | f1e02bb | 2018-03-15 16:30:00 +0100 | [diff] [blame] | 589 | |
| 590 | var template MgcpResponse mgcp_resp; |
| 591 | mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_bss, sdp); |
| 592 | f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep)); |
| 593 | MGCP.send(mgcp_resp); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 594 | } |
| 595 | } |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 596 | /* Second MGCP CRCX (this time for MSS/CN side) */ |
| 597 | MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd { |
| 598 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_rtp_ip_mss, cpars.mgw_rtp_ip_mss, |
| 599 | hex2str(cpars.mgcp_call_id), "42", |
| 600 | cpars.mgw_rtp_port_mss, |
| 601 | { int2str(cpars.rtp_payload_type) }, |
| 602 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 603 | cpars.rtp_sdp_format)), |
| 604 | valueof(ts_SDP_ptime(20)) })); |
| 605 | MGCP.send(ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgcp_connection_id_mss, sdp)); |
| 606 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 607 | |
| 608 | /* Alerting */ |
| 609 | MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref)); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 610 | |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 611 | var BSSMAP_IE_AoIP_TransportLayerAddress tla_ass := |
| 612 | valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.mgw_rtp_ip_bss),cpars.mgw_rtp_port_bss)); |
| 613 | interleave { |
| 614 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {} |
| 615 | /* expect AoIP IP/Port to match what we returned in CRCX_ACK above */ |
| 616 | [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) { |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 617 | var BSSMAP_IE_AoIP_TransportLayerAddress tla; |
| 618 | tla := valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.bss_rtp_ip), cpars.bss_rtp_port)); |
| 619 | BSSAP.send(ts_BSSMAP_AssignmentComplete(omit, tla)); |
| 620 | } |
| 621 | } |
| 622 | |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 623 | /* Answer. MNCC_SETUP_RSP -> CONNECT to MS; CONNECT_ACK from MS */ |
| 624 | MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref)); |
| 625 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))); |
| 626 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id))); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 627 | |
| 628 | f_sleep(3.0); |
| 629 | |
| 630 | /* Hangup by "B" side */ |
| 631 | MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23)))); |
| 632 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id))); |
| 633 | |
| 634 | /* Release of call */ |
| 635 | MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42)))); |
| 636 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))); |
| 637 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id))); |
| 638 | |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 639 | respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx)); |
| 640 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 641 | /* clearing of radio channel */ |
| 642 | interleave { |
| 643 | [] BSSAP.receive(tr_BSSMAP_ClearCommand) { |
| 644 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 645 | BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND); |
| 646 | } |
| 647 | [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd { |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 648 | if (respond_to_dlcx) { |
| 649 | /* TODO: For one or all connections on EP? */ |
| 650 | MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id)); |
| 651 | f_create_mgcp_delete_ep(cpars.mgcp_ep); |
| 652 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 653 | } |
| 654 | } |
| 655 | setverdict(pass); |
| 656 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 657 | |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 658 | function f_mo_seq_dtmf_dup(inout CallParameters cpars) |
| 659 | runs on BSC_ConnHdlr { |
| 660 | |
| 661 | timer T := 1.0; |
| 662 | var MobileIdentityLV mi; |
| 663 | var MNCC_PDU mncc; |
| 664 | var MgcpCommand mgcp_cmd; |
| 665 | var template PDU_ML3_MS_NW dtmf_dtap; |
| 666 | |
| 667 | /* If we have a TMSI, use TMSI instead of IMSI */ |
| 668 | if (ispresent(g_pars.tmsi)) { |
| 669 | mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi)); |
| 670 | } else { |
| 671 | mi := valueof(ts_MI_IMSI_LV(g_pars.imsi)); |
| 672 | } |
| 673 | f_establish_fully(mi); |
| 674 | |
| 675 | /* Create MNCC and MGCP expect */ |
| 676 | f_create_mncc_expect(hex2str(cpars.called_party)); |
| 677 | f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit}); |
| 678 | |
| 679 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party))); |
| 680 | MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc; |
| 681 | cpars.mncc_callref := mncc.u.signal.callref; |
| 682 | |
| 683 | /* Send DTMF */ |
| 684 | dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2"); |
| 685 | dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(2, 2); |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 686 | BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true)); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 687 | T.start; |
| 688 | alt { |
| 689 | [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {} |
| 690 | [] T.timeout { |
| 691 | setverdict(fail, "Timeout waiting for START_DTMF_ind"); |
| 692 | self.stop; |
| 693 | } |
| 694 | } |
| 695 | |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 696 | BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true)); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 697 | T.start; |
| 698 | alt { |
| 699 | [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) { |
| 700 | setverdict(fail, "Received duplicate START_DTMF_ind"); |
| 701 | self.stop; |
| 702 | } |
| 703 | [] T.timeout { } |
| 704 | } |
| 705 | |
| 706 | dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3"); |
| 707 | dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(3, 2); |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 708 | BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true)); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 709 | alt { |
| 710 | [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) { } |
| 711 | [] T.timeout { |
| 712 | setverdict(fail, "Received duplicate START_DTMF_ind"); |
| 713 | self.stop; |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | setverdict(pass); |
| 718 | } |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 719 | /* expect a clear command */ |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 720 | altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr { |
| 721 | [] BSSAP.receive(tr_BSSMAP_ClearCommand) { |
| 722 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 723 | alt { |
| 724 | [] BSSAP.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
| 725 | setverdict(pass); |
| 726 | } |
| 727 | [] BSSAP.receive { |
| 728 | setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release"); |
| 729 | self.stop; |
| 730 | } |
| 731 | } |
| 732 | } |
| 733 | [] BSSAP.receive { |
| 734 | setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand"); |
| 735 | self.stop; |
| 736 | } |
| 737 | } |
| 738 | |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 739 | function f_expect_clear(float t := 5.0) runs on BSC_ConnHdlr { |
| 740 | timer T := t; |
| 741 | |
| 742 | T.start; |
| 743 | alt { |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 744 | [] as_clear_cmd_compl_disc(t) { } |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 745 | [] T.timeout { |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 746 | setverdict(fail, "Timeout waiting for ClearCommand/Release"); |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 747 | self.stop; |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 752 | |
| 753 | |
| 754 | |
| 755 | } |
| 756 | |
| 757 | |