Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 1 | /* BSC Connection Handler of MSC test suite in TTCN-3 |
| 2 | * (C) 2018-2019 Harald Welte <laforge@gnumonks.org> |
| 3 | * (C) 2018-2019 sysmocom - s.f.m.c. GmbH |
| 4 | * (C) 2018 Vadim Yanitskiy <axilirator@gmail.com> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Released under the terms of GNU General Public License, Version 2 or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 11 | */ |
| 12 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 13 | module BSC_ConnectionHandler { |
| 14 | |
| 15 | import from General_Types all; |
| 16 | import from Osmocom_Types all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 17 | import from Native_Functions all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 18 | import from GSM_Types all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 19 | import from IPL4asp_Types all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 20 | import from SCCPasp_Types all; |
| 21 | import from BSSAP_Types all; |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 22 | import from RAN_Emulation all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 23 | import from BSSMAP_Templates all; |
| 24 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 25 | import from RANAP_Constants all; |
| 26 | import from RANAP_IEs all; |
| 27 | import from RANAP_PDU_Contents all; |
| 28 | import from RANAP_PDU_Descriptions all; |
| 29 | import from RANAP_Templates all; |
| 30 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 31 | import from GSUP_Types all; |
| 32 | import from GSUP_Emulation all; |
| 33 | |
| 34 | import from MNCC_Types all; |
| 35 | import from MNCC_Emulation all; |
| 36 | |
Harald Welte | 4aa970c | 2018-01-26 10:38:09 +0100 | [diff] [blame] | 37 | import from MGCP_Types all; |
| 38 | import from MGCP_Emulation all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 39 | import from MGCP_Templates all; |
| 40 | import from SDP_Types all; |
Harald Welte | 4aa970c | 2018-01-26 10:38:09 +0100 | [diff] [blame] | 41 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 42 | import from MobileL3_Types all; |
| 43 | import from MobileL3_CommonIE_Types all; |
| 44 | import from MobileL3_MM_Types all; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 45 | import from MobileL3_CC_Types all; |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 46 | import from MobileL3_SMS_Types all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 47 | import from L3_Templates all; |
Harald Welte | 158a7ca | 2018-02-16 18:11:31 +0100 | [diff] [blame] | 48 | import from L3_Common all; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 49 | |
Harald Welte | f640a01 | 2018-04-14 17:49:21 +0200 | [diff] [blame] | 50 | import from SMPP_Emulation all; |
| 51 | |
Philipp Maier | aeb29a8 | 2018-11-08 17:40:53 +0100 | [diff] [blame] | 52 | import from IPA_Emulation all; |
| 53 | import from Osmocom_CTRL_Functions all; |
| 54 | import from Osmocom_CTRL_Types all; |
| 55 | import from Osmocom_CTRL_Adapter all; |
| 56 | |
Philipp Maier | c39a9d8 | 2018-11-09 11:21:08 +0100 | [diff] [blame] | 57 | import from TELNETasp_PortType all; |
| 58 | import from Osmocom_VTY_Functions all; |
| 59 | |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 60 | import from SGsAP_Emulation all; |
| 61 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 62 | /* this component represents a single subscriber connection */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 63 | type component BSC_ConnHdlr extends RAN_ConnHdlr, MNCC_ConnHdlr, GSUP_ConnHdlr, MGCP_ConnHdlr, SMPP_ConnHdlr, CTRL_Adapter_CT, SGsAP_ConnHdlr { |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 64 | var BSC_ConnHdlrPars g_pars; |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 65 | timer g_Tguard := 60.0; |
Philipp Maier | c39a9d8 | 2018-11-09 11:21:08 +0100 | [diff] [blame] | 66 | port TELNETasp_PT MSCVTY; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 69 | type record BSC_ConnHdlrNetworkPars { |
| 70 | OCT1 kc_support, |
| 71 | boolean expect_tmsi, |
| 72 | boolean expect_auth, |
Oliver Smith | 1d118ff | 2019-07-03 10:57:35 +0200 | [diff] [blame] | 73 | boolean expect_ciph, |
| 74 | boolean expect_imei, |
| 75 | boolean expect_imei_early, |
| 76 | GSUP_IMEIResult check_imei_result, |
| 77 | boolean check_imei_error |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 80 | type record BSC_ConnHdlrPars { |
| 81 | SCCP_PAR_Address sccp_addr_own, |
| 82 | SCCP_PAR_Address sccp_addr_peer, |
| 83 | BSSMAP_IE_CellIdentifier cell_id, |
Harald Welte | 256571e | 2018-01-24 18:47:19 +0100 | [diff] [blame] | 84 | hexstring imei, |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 85 | hexstring imsi, |
Harald Welte | 8260057 | 2018-01-21 20:54:08 +0100 | [diff] [blame] | 86 | hexstring msisdn, |
Harald Welte | 256571e | 2018-01-24 18:47:19 +0100 | [diff] [blame] | 87 | OCT4 tmsi optional, |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 88 | MobileStationClassmark1_V cm1, |
Harald Welte | 8260057 | 2018-01-21 20:54:08 +0100 | [diff] [blame] | 89 | BSSMAP_IE_ClassmarkInformationType2 cm2, |
Harald Welte | 1611428 | 2018-01-24 22:41:21 +0100 | [diff] [blame] | 90 | BSSMAP_IE_ClassmarkInformationType3 cm3 optional, |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 91 | AuthVector vec optional, |
Neels Hofmeyr | c1f105a | 2018-03-01 20:00:19 +0100 | [diff] [blame] | 92 | BSC_ConnHdlrNetworkPars net, |
Philipp Maier | aeb29a8 | 2018-11-08 17:40:53 +0100 | [diff] [blame] | 93 | boolean send_early_cm, |
| 94 | charstring ipa_ctrl_ip, |
| 95 | integer ipa_ctrl_port, |
Philipp Maier | 9b690e4 | 2018-12-21 11:50:03 +0100 | [diff] [blame] | 96 | boolean ipa_ctrl_enable, |
Philipp Maier | 5786548 | 2019-01-07 18:33:13 +0100 | [diff] [blame] | 97 | boolean mm_info, |
Philipp Maier | c09a131 | 2019-04-09 16:05:26 +0200 | [diff] [blame] | 98 | boolean sgsap_enable, |
Harald Welte | f9abf8d | 2019-04-21 13:07:17 +0200 | [diff] [blame] | 99 | boolean gsup_enable, |
Vadim Yanitskiy | 2dd9661 | 2020-01-07 21:48:29 +0100 | [diff] [blame] | 100 | OCT4 gsup_sid, |
Harald Welte | c1f937a | 2019-04-21 21:19:23 +0200 | [diff] [blame] | 101 | integer ran_idx, |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 102 | boolean use_umts_aka, |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 103 | boolean ran_is_geran, |
| 104 | boolean use_osmux |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 105 | }; |
| 106 | |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 107 | /* get a one-octet bitmaks of supported algorithms based on Classmark information */ |
| 108 | function f_alg_mask_from_cm(BSSMAP_IE_ClassmarkInformationType2 cm2) return OCT1 { |
| 109 | var BIT8 res := '00000001'B; /* A5/0 always supported */ |
| 110 | |
| 111 | if (cm2.a5_1 == '0'B) { |
| 112 | res := res or4b '00000010'B; |
| 113 | } |
| 114 | if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) { |
| 115 | res := res or4b '00000100'B; |
| 116 | } |
| 117 | if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) { |
| 118 | res := res or4b '00001000'B; |
| 119 | } |
| 120 | /* TODO: CM3 for A5/4 and beyond */ |
| 121 | return bit2oct(res); |
| 122 | } |
| 123 | |
| 124 | /* determine the best algorithm available within the bit-mask */ |
| 125 | function f_best_alg_from_mask(OCT1 alg_in) return OCT1 { |
| 126 | var BIT8 alg := oct2bit(alg_in); |
| 127 | var BIT8 ordered_algs[8] := { |
| 128 | '10000000'B, '01000000'B, '00100000'B, '00010000'B, |
| 129 | '00001000'B, /* A5/3 */ |
| 130 | '00000010'B, /* A5/1 */ |
| 131 | '00000100'B, /* A5/2 */ |
| 132 | '00000001'B /* A5/0 */ } |
| 133 | for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) { |
| 134 | if (alg and4b ordered_algs[i] != '00000000'B) { |
| 135 | return bit2oct(ordered_algs[i]); |
| 136 | } |
| 137 | } |
| 138 | return '00'O; |
| 139 | } |
| 140 | |
| 141 | /* return an integer like '1' for A5/1 based on a mask (with only one bit set */ |
| 142 | function f_alg_from_mask(OCT1 mask_in) return integer { |
| 143 | var BIT8 mask := oct2bit(mask_in); |
| 144 | for (var integer i := 0; i < 8; i := i+1) { |
| 145 | if (mask and4b ('00000001'B << i) != '00000000'B) { |
| 146 | return i; |
| 147 | } |
| 148 | } |
| 149 | return -1; |
| 150 | } |
| 151 | |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 152 | /* altstep for the global guard timer */ |
| 153 | private altstep as_Tguard() runs on BSC_ConnHdlr { |
| 154 | [] g_Tguard.timeout { |
Daniel Willmann | 90829d6 | 2018-02-15 17:45:14 +0100 | [diff] [blame] | 155 | setverdict(fail, "Tguard timeout"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 156 | mtc.stop; |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
| 160 | /* init function, called as first function in new BSC_ConnHdlr */ |
Harald Welte | ad2952e | 2018-01-27 14:12:46 +0100 | [diff] [blame] | 161 | 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] | 162 | /* make parameters available via component variable */ |
| 163 | g_pars := pars; |
| 164 | /* Start guard timer and activate it as default */ |
Harald Welte | ad2952e | 2018-01-27 14:12:46 +0100 | [diff] [blame] | 165 | g_Tguard.start(t_guard); |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 166 | activate(as_Tguard()); |
Harald Welte | f640a01 | 2018-04-14 17:49:21 +0200 | [diff] [blame] | 167 | /* Route all SMPP messages for our MSISDN to us */ |
| 168 | f_create_smpp_expect(hex2str(pars.msisdn)); |
Philipp Maier | 5786548 | 2019-01-07 18:33:13 +0100 | [diff] [blame] | 169 | |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 170 | /* Route all SGs message for our IMSI to us */ |
Philipp Maier | 5786548 | 2019-01-07 18:33:13 +0100 | [diff] [blame] | 171 | if (g_pars.sgsap_enable == true) { |
| 172 | f_create_sgsap_expect(pars.imsi); |
| 173 | } |
Philipp Maier | aeb29a8 | 2018-11-08 17:40:53 +0100 | [diff] [blame] | 174 | |
| 175 | if (g_pars.ipa_ctrl_enable == true) { |
| 176 | f_ipa_ctrl_start(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port); |
| 177 | } |
Philipp Maier | c39a9d8 | 2018-11-09 11:21:08 +0100 | [diff] [blame] | 178 | |
| 179 | map(self:MSCVTY, system:MSCVTY); |
| 180 | f_vty_set_prompts(MSCVTY); |
| 181 | f_vty_transceive(MSCVTY, "enable"); |
Harald Welte | a10db90 | 2018-01-27 12:44:49 +0100 | [diff] [blame] | 182 | } |
| 183 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 184 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 185 | /* Callback function from general RAN_Emulation whenever a connectionless |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 186 | * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */ |
| 187 | private function BscUnitdataCallback(PDU_BSSAP bssap) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 188 | runs on RAN_Emulation_CT return template PDU_BSSAP { |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 189 | var template PDU_BSSAP resp := omit; |
| 190 | |
| 191 | log("BSSMAP_BscUnitdataCallback"); |
| 192 | /* answer all RESET with RESET ACK */ |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 193 | if (match(bssap, tr_BSSMAP_Reset(g_ran_ops.use_osmux))){ |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 194 | log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK"); |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 195 | resp := ts_BSSMAP_ResetAck(g_ran_ops.use_osmux); |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /* FIXME: Handle paging, etc. */ |
| 199 | return resp; |
| 200 | } |
| 201 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 202 | private function RncUnitdataCallback(RANAP_PDU ranap) |
| 203 | runs on RAN_Emulation_CT return template RANAP_PDU { |
| 204 | var template RANAP_PDU resp := omit; |
| 205 | |
| 206 | log("RANAP_RncUnitdataCallback"); |
| 207 | /* answer all RESET with RESET ACK */ |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 208 | if (match(ranap, tr_RANAP_Reset())) { |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 209 | log("RANAP_RncUnitdataCallback: Responding to RESET with RESET-ACK"); |
| 210 | var CN_DomainIndicator dom; |
| 211 | dom := ranap.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator; |
| 212 | resp := ts_RANAP_ResetAck(dom); |
| 213 | } |
| 214 | |
| 215 | /* FIXME: Handle paging, etc. */ |
| 216 | return resp; |
| 217 | } |
| 218 | |
| 219 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 220 | const RanOps BSC_RanOps := { |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 221 | /* Create call-back for inbound connections from MSC (hand-over) */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 222 | create_cb := refers(RAN_Emulation.ExpectedCreateCallback), |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 223 | unitdata_cb := refers(BscUnitdataCallback), |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 224 | ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback), |
| 225 | ranap_unitdata_cb := refers(RncUnitdataCallback), |
| 226 | ps_domain := false, |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 227 | decode_dtap := true, |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 228 | role_ms := true, |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 229 | protocol := RAN_PROTOCOL_BSSAP, |
Pau Espin Pedrol | c6b78ff | 2019-06-06 15:58:17 +0200 | [diff] [blame] | 230 | transport := BSSAP_TRANSPORT_AoIP, |
Pau Espin Pedrol | c6a53db | 2019-05-20 19:31:47 +0200 | [diff] [blame] | 231 | use_osmux := false, |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 232 | sccp_addr_local := omit, |
| 233 | sccp_addr_peer := omit |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | |
| 237 | private function MnccUnitdataCallback(MNCC_PDU mncc) |
| 238 | runs on MNCC_Emulation_CT return template MNCC_PDU { |
| 239 | log("Ignoring MNCC", mncc); |
| 240 | return omit; |
| 241 | } |
| 242 | |
| 243 | const MnccOps BCC_MnccOps := { |
| 244 | create_cb := refers(MNCC_Emulation.ExpectedCreateCallback), |
| 245 | unitdata_cb := refers(MnccUnitdataCallback) |
| 246 | } |
| 247 | |
| 248 | |
| 249 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 250 | /* Encode 'l3' and ask RAN_Emulation to create new connection with COMPL L3 INFO */ |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 251 | function f_bssap_compl_l3(PDU_ML3_MS_NW l3) |
| 252 | runs on BSC_ConnHdlr { |
| 253 | log("Sending COMPL L3: ", l3); |
| 254 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3); |
| 255 | BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, |
| 256 | valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc)))); |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 257 | alt { |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 258 | [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {} |
| 259 | [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 260 | setverdict(fail, "DISC.ind from SCCP"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 261 | mtc.stop; |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 262 | } |
| 263 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 264 | } |
| 265 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 266 | /* generate Iu LAI from BSSAP CGI */ |
| 267 | private function f_IuLAI_from_BssmapCI(BSSMAP_IE_CellIdentifier ci) return LAI { |
| 268 | var LAI lai; |
| 269 | if (ischosen(ci.cellIdentification.cI_CGI)) { |
| 270 | lai.pLMNidentity := ci.cellIdentification.cI_CGI.mcc_mnc; |
| 271 | lai.lAC := ci.cellIdentification.cI_CGI.lac; |
| 272 | } else if (ischosen(ci.cellIdentification.cI_SAI)) { |
| 273 | lai.pLMNidentity := ci.cellIdentification.cI_SAI.mcc_mnc; |
| 274 | lai.lAC := ci.cellIdentification.cI_SAI.lac; |
| 275 | } else if (ischosen(ci.cellIdentification.ci_LAC_RNC_CI)) { |
| 276 | lai.pLMNidentity := ci.cellIdentification.ci_LAC_RNC_CI.mcc_mnc; |
| 277 | lai.lAC := ci.cellIdentification.ci_LAC_RNC_CI.lac; |
| 278 | } else { |
| 279 | mtc.stop; |
| 280 | } |
| 281 | lai.iE_Extensions := omit; |
| 282 | return lai; |
| 283 | } |
| 284 | |
| 285 | /* like f_bssap_compl_l3() but for 3G */ |
| 286 | function f_ranap_initial_ue(PDU_ML3_MS_NW l3) |
| 287 | runs on BSC_ConnHdlr { |
| 288 | log("Sending InitialUE: ", l3); |
| 289 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3); |
| 290 | var RANAP_PDU ranap; |
| 291 | var LAI lai := f_IuLAI_from_BssmapCI(g_pars.cell_id); |
| 292 | var SAI sai := { |
| 293 | pLMNidentity := lai.pLMNidentity, |
| 294 | lAC := lai.lAC, |
| 295 | sAC := '0000'O, /* FIXME */ |
| 296 | iE_Extensions := omit |
| 297 | }; |
| 298 | var IuSignallingConnectionIdentifier sigc_id := int2bit(23, 24); |
| 299 | var GlobalRNC_ID grnc_id := { |
| 300 | pLMNidentity := lai.pLMNidentity, |
| 301 | rNC_ID := 2342 /* FIXME */ |
| 302 | }; |
| 303 | |
| 304 | ranap := valueof(ts_RANAP_initialUE_CS(lai, sai, l3_enc, sigc_id, grnc_id)); |
| 305 | BSSAP.send(ts_RANAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, ranap)); |
| 306 | alt { |
| 307 | [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {} |
| 308 | [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
| 309 | setverdict(fail, "DISC.ind from SCCP"); |
| 310 | mtc.stop; |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
Harald Welte | dceacc7 | 2019-04-21 20:58:35 +0200 | [diff] [blame] | 315 | /* Send BSSMAP Complete L3 or RANAP Initial UE depending on 2G/3G RAN type */ |
| 316 | function f_cl3_or_initial_ue(PDU_ML3_MS_NW l3) |
| 317 | runs on BSC_ConnHdlr { |
| 318 | if (g_pars.ran_is_geran) { |
| 319 | f_bssap_compl_l3(l3); |
| 320 | } else { |
| 321 | f_ranap_initial_ue(l3); |
| 322 | } |
| 323 | } |
| 324 | |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 325 | type enumerated EstablishType { |
| 326 | EST_TYPE_MO_CALL, |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 327 | EST_TYPE_EMERG_CALL, |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 328 | EST_TYPE_PAG_RESP, |
Vadim Yanitskiy | 20ee5e4 | 2018-05-27 17:54:21 +0700 | [diff] [blame] | 329 | EST_TYPE_MO_SMS, |
| 330 | EST_TYPE_SS_ACT |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 331 | }; |
| 332 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 333 | /* helper function to fully establish a dedicated channel */ |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 334 | function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL) |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 335 | runs on BSC_ConnHdlr { |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 336 | var PDU_ML3_MS_NW l3_info; |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 337 | var MobileIdentityLV mi; |
| 338 | |
| 339 | /* If we have a TMSI, use TMSI instead of IMSI */ |
| 340 | if (ispresent(g_pars.tmsi)) { |
| 341 | mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi)); |
| 342 | } else { |
| 343 | mi := valueof(ts_MI_IMSI_LV(g_pars.imsi)); |
| 344 | } |
| 345 | |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 346 | select (etype) { |
| 347 | case (EST_TYPE_MO_CALL) { |
| 348 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi)); |
| 349 | } |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 350 | case (EST_TYPE_EMERG_CALL) { |
| 351 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi)); |
| 352 | } |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 353 | case (EST_TYPE_PAG_RESP) { |
| 354 | l3_info := valueof(ts_PAG_RESP(mi)); |
| 355 | } |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 356 | case (EST_TYPE_MO_SMS) { |
| 357 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi)); |
| 358 | } |
Vadim Yanitskiy | 20ee5e4 | 2018-05-27 17:54:21 +0700 | [diff] [blame] | 359 | case (EST_TYPE_SS_ACT) { |
| 360 | l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi)); |
| 361 | } |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 362 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 363 | |
| 364 | /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */ |
Harald Welte | dceacc7 | 2019-04-21 20:58:35 +0200 | [diff] [blame] | 365 | f_cl3_or_initial_ue(l3_info); |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 366 | |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 367 | f_mm_common(); |
Pau Espin Pedrol | f803448 | 2019-06-03 13:15:58 +0200 | [diff] [blame] | 368 | if (g_pars.net.expect_ciph or not g_pars.ran_is_geran) { |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 369 | /* implicit CM SERVICE ACCEPT? */ |
| 370 | } else { |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 371 | if (etype != EST_TYPE_PAG_RESP) { |
Harald Welte | 081b19a | 2018-02-10 09:11:13 +0100 | [diff] [blame] | 372 | /* explicit CM SERVICE ACCEPT */ |
| 373 | BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC)); |
| 374 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 375 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /* build a PDU_ML3_MS_NW containing a Location Update by IMSI */ |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 379 | 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] | 380 | { |
| 381 | var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi)); |
| 382 | return f_build_lu(mi); |
| 383 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 384 | 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] | 385 | { |
| 386 | var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei)); |
| 387 | return f_build_lu(mi); |
| 388 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 389 | 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] | 390 | { |
| 391 | var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi)); |
| 392 | return f_build_lu(mi); |
| 393 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 394 | 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] | 395 | { |
| 396 | var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O }; |
| 397 | 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] | 398 | old_lai, mi, g_pars.cm1)); |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 399 | return l3_info; |
| 400 | } |
| 401 | |
Harald Welte | a183a5d | 2019-05-09 13:40:52 +0200 | [diff] [blame] | 402 | altstep as_GSUP_SAI() runs on BSC_ConnHdlr { |
| 403 | var GSUP_IE auth_tuple; |
| 404 | [] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)) { |
| 405 | if (g_pars.use_umts_aka) { |
| 406 | g_pars.vec := f_gen_auth_vec_3g(); |
| 407 | auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand, |
| 408 | g_pars.vec.sres, |
| 409 | g_pars.vec.kc, |
| 410 | g_pars.vec.ik, |
| 411 | g_pars.vec.ck, |
| 412 | g_pars.vec.autn, |
| 413 | g_pars.vec.res)); |
| 414 | GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple)); |
| 415 | } else { |
| 416 | g_pars.vec := f_gen_auth_vec_2g(); |
| 417 | auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand, |
| 418 | g_pars.vec.sres, |
| 419 | g_pars.vec.kc)); |
| 420 | GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple)); |
| 421 | } |
| 422 | } |
| 423 | } |
| 424 | |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 425 | function f_mm_auth() runs on BSC_ConnHdlr |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 426 | { |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 427 | if (g_pars.net.expect_auth) { |
Harald Welte | a183a5d | 2019-05-09 13:40:52 +0200 | [diff] [blame] | 428 | as_GSUP_SAI(); |
Harald Welte | c1f937a | 2019-04-21 21:19:23 +0200 | [diff] [blame] | 429 | if (g_pars.use_umts_aka) { |
Harald Welte | c1f937a | 2019-04-21 21:19:23 +0200 | [diff] [blame] | 430 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn))); |
| 431 | var OCT4 res := substr(g_pars.vec.res, 0, 4); |
| 432 | var OCT4 xres := substr(g_pars.vec.res, 4, 4); |
| 433 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres))); |
| 434 | } else { |
Harald Welte | c1f937a | 2019-04-21 21:19:23 +0200 | [diff] [blame] | 435 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand))); |
| 436 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres))); |
| 437 | } |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 438 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 439 | } |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 440 | |
Oliver Smith | 1d118ff | 2019-07-03 10:57:35 +0200 | [diff] [blame] | 441 | function f_mm_imei() runs on BSC_ConnHdlr |
| 442 | { |
| 443 | var PDU_DTAP_MT dtap_mt; |
| 444 | var GSUP_PDU gsup_msg; |
| 445 | var MobileL3_CommonIE_Types.MobileIdentityLV mi; |
| 446 | |
| 447 | if (not g_pars.net.expect_imei) { |
| 448 | return |
| 449 | } |
| 450 | |
| 451 | /* MSC <-> BSC: ID req/rsp for IMEI */ |
| 452 | alt { |
| 453 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEI))) { |
| 454 | mi := valueof(ts_MI_IMEI_LV(g_pars.imei)); |
| 455 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi))); |
| 456 | } |
| 457 | [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt { |
| 458 | setverdict(fail, "Expected ID REQ for IMEI DTAP MT message, but got: ", dtap_mt); |
| 459 | mtc.stop; |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | /* MSC <-> HLR: Check IMEI req/res/err */ |
| 464 | alt { |
| 465 | [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) { |
| 466 | GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */)); |
| 467 | } |
| 468 | [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) { |
| 469 | GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result)); |
| 470 | } |
| 471 | [] GSUP.receive(?) -> value gsup_msg { |
| 472 | setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ", |
| 473 | g_pars.imsi, "), but got: ", gsup_msg); |
| 474 | mtc.stop; |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | function f_mm_imei_early() runs on BSC_ConnHdlr |
| 480 | { |
| 481 | var PDU_DTAP_MT dtap_mt; |
| 482 | var GSUP_PDU gsup_msg; |
| 483 | var MobileL3_CommonIE_Types.MobileIdentityLV mi; |
| 484 | |
| 485 | if (not g_pars.net.expect_imei_early) { |
| 486 | return |
| 487 | } |
| 488 | |
| 489 | /* MSC <-> BSC: ID req/rsp for IMEISV */ |
| 490 | alt { |
| 491 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEISV))) { |
| 492 | mi := valueof(ts_MI_IMEISV_LV(g_pars.imei)); |
| 493 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi))); |
| 494 | } |
| 495 | [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt { |
| 496 | setverdict(fail, "Expected ID REQ for IMEISV DTAP MT message, but got: ", dtap_mt); |
| 497 | mtc.stop; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /* MSC <-> HLR: Check IMEI req/res/err */ |
| 502 | alt { |
| 503 | [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) { |
| 504 | GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */)); |
| 505 | } |
| 506 | [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) { |
| 507 | GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result)); |
| 508 | } |
| 509 | [] GSUP.receive(?) -> value gsup_msg { |
| 510 | setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ", |
| 511 | g_pars.imsi, "), but got: ", gsup_msg); |
| 512 | mtc.stop; |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 517 | function f_mm_common() runs on BSC_ConnHdlr |
| 518 | { |
| 519 | f_mm_auth(); |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 520 | if (g_pars.ran_is_geran) { |
| 521 | if (g_pars.net.expect_ciph) { |
| 522 | var OCT1 a5_net := f_alg_mask_from_cm(g_pars.cm2); |
| 523 | var OCT1 a5_intersect := g_pars.net.kc_support and4b a5_net; |
| 524 | alt { |
| 525 | [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(a5_intersect, g_pars.vec.kc)) { |
| 526 | var OCT1 a5_chosen := f_best_alg_from_mask(a5_intersect); |
| 527 | var integer a5_nr := f_alg_from_mask(a5_chosen); |
| 528 | BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1))); |
| 529 | } |
| 530 | [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(?, g_pars.vec.kc)) { |
| 531 | setverdict(fail, "Wrong ciphering algorithm mask in CiphModCmd"); |
| 532 | mtc.stop; |
| 533 | } |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 534 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 535 | /* FIXME: Send the best available algorithm */ |
| 536 | } |
| 537 | } else { /* UTRAN */ |
| 538 | alt { |
| 539 | [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?, |
| 540 | uia_key := oct2bit(g_pars.vec.ik), |
| 541 | key_sts := ?, |
| 542 | uea_algs := ?, |
| 543 | uea_key := oct2bit(g_pars.vec.ck))) { |
| 544 | var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/ |
| 545 | var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/ |
| 546 | BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen)); |
| 547 | BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi))); |
| 548 | } |
| 549 | [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) { |
| 550 | setverdict(fail, "Invalid SecurityModeCommand (ciphering case)"); |
| 551 | mtc.stop; |
| 552 | } |
| 553 | [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?, |
| 554 | uia_key := oct2bit(g_pars.vec.ik), |
| 555 | key_sts := ?)) { |
| 556 | var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/ |
| 557 | BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen)); |
| 558 | BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi))); |
| 559 | } |
| 560 | [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) { |
| 561 | setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 562 | mtc.stop; |
Harald Welte | 9de8479 | 2018-01-28 01:06:35 +0100 | [diff] [blame] | 563 | } |
| 564 | } |
Harald Welte | 148a708 | 2018-01-26 18:56:43 +0100 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
Philipp Maier | 9b690e4 | 2018-12-21 11:50:03 +0100 | [diff] [blame] | 568 | function f_expect_mm_info() runs on BSC_ConnHdlr { |
| 569 | if (g_pars.mm_info == true) { |
| 570 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info)); |
| 571 | } |
| 572 | } |
| 573 | |
Neels Hofmeyr | c1f105a | 2018-03-01 20:00:19 +0100 | [diff] [blame] | 574 | function f_perform_lu() |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 575 | runs on BSC_ConnHdlr { |
| 576 | var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi) |
| 577 | var PDU_DTAP_MT dtap_mt; |
| 578 | |
| 579 | /* tell GSUP dispatcher to send this IMSI to us */ |
| 580 | f_create_gsup_expect(hex2str(g_pars.imsi)); |
| 581 | |
| 582 | /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */ |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 583 | if (g_pars.ran_is_geran) { |
| 584 | f_bssap_compl_l3(l3_lu); |
| 585 | if (g_pars.send_early_cm) { |
| 586 | BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3)); |
| 587 | } |
| 588 | } else { |
| 589 | f_ranap_initial_ue(l3_lu); |
Harald Welte | 8a121b3 | 2018-01-22 03:00:41 +0100 | [diff] [blame] | 590 | } |
Harald Welte | 5c2622c | 2018-01-21 20:45:20 +0100 | [diff] [blame] | 591 | |
Oliver Smith | 1d118ff | 2019-07-03 10:57:35 +0200 | [diff] [blame] | 592 | f_mm_imei_early(); |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 593 | f_mm_common(); |
Stefan Sperling | a2d59c6 | 2018-12-18 16:32:44 +0100 | [diff] [blame] | 594 | f_msc_lu_hlr(); |
Oliver Smith | 1d118ff | 2019-07-03 10:57:35 +0200 | [diff] [blame] | 595 | f_mm_imei(); |
Stefan Sperling | a2d59c6 | 2018-12-18 16:32:44 +0100 | [diff] [blame] | 596 | f_accept_reject_lu(); |
| 597 | /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */ |
| 598 | f_expect_clear(); |
Harald Welte | 1611428 | 2018-01-24 22:41:21 +0100 | [diff] [blame] | 599 | |
Stefan Sperling | a2d59c6 | 2018-12-18 16:32:44 +0100 | [diff] [blame] | 600 | setverdict(pass); |
| 601 | } |
| 602 | |
| 603 | function f_msc_lu_hlr() runs on BSC_ConnHdlr |
| 604 | { |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 605 | /* Expect MSC to perform LU with HLR */ |
| 606 | GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi)); |
| 607 | GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn)); |
| 608 | GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi)); |
| 609 | GSUP.send(ts_GSUP_UL_RES(g_pars.imsi)); |
Stefan Sperling | a2d59c6 | 2018-12-18 16:32:44 +0100 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | function f_accept_reject_lu() runs on BSC_ConnHdlr { |
| 613 | var PDU_DTAP_MT dtap_mt; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 614 | |
| 615 | alt { |
| 616 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt { |
| 617 | var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept; |
Harald Welte | de37149 | 2018-01-27 23:44:41 +0100 | [diff] [blame] | 618 | if (g_pars.net.expect_tmsi) { |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 619 | if (not ispresent(lu_acc.mobileIdentityTLV) or |
| 620 | not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) { |
| 621 | setverdict(fail, "Expected TMSI but no TMSI was allocated"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 622 | mtc.stop; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 623 | } else { |
Harald Welte | 256571e | 2018-01-24 18:47:19 +0100 | [diff] [blame] | 624 | 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] | 625 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl)); |
| 626 | } |
| 627 | } else { |
| 628 | if (ispresent(lu_acc.mobileIdentityTLV) and |
| 629 | ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) { |
| 630 | setverdict(fail, "Expected no TMSI but TMSI was allocated"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 631 | mtc.stop; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | } |
| 635 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) { |
| 636 | setverdict(fail, "Expected LU ACK, but received LU REJ"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 637 | mtc.stop; |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 638 | } |
| 639 | } |
Philipp Maier | 9b690e4 | 2018-12-21 11:50:03 +0100 | [diff] [blame] | 640 | |
| 641 | /* Wait for MM-Information (if enabled) */ |
| 642 | f_expect_mm_info(); |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 643 | setverdict(pass); |
| 644 | } |
| 645 | |
Pau Espin Pedrol | d3d54a9 | 2019-12-17 17:02:54 +0100 | [diff] [blame] | 646 | function f_expect_lu_reject(template OCT1 cause := ?) runs on BSC_ConnHdlr { |
Oliver Smith | 91bfa1c | 2019-07-19 15:01:15 +0200 | [diff] [blame] | 647 | var PDU_DTAP_MT dtap_mt; |
| 648 | timer T := 5.0; |
| 649 | |
| 650 | T.start; |
| 651 | alt { |
Pau Espin Pedrol | d3d54a9 | 2019-12-17 17:02:54 +0100 | [diff] [blame] | 652 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej(cause))) { |
Oliver Smith | 91bfa1c | 2019-07-19 15:01:15 +0200 | [diff] [blame] | 653 | setverdict(pass); |
| 654 | } |
| 655 | [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt { |
| 656 | setverdict(fail, "Expected LU reject BSSAP message, got: ", dtap_mt); |
| 657 | } |
| 658 | [] T.timeout { |
| 659 | setverdict(fail, "Timeout waiting for LU reject"); |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 664 | function f_foo() runs on BSC_ConnHdlr{ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 665 | /* SCCP CC handled by RAN_Emulation_CT.main() */ |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 666 | /* Expect auth, if enabled */ |
| 667 | |
| 668 | /* TODO: ISD */ |
| 669 | /* Expect encr, if enabled */ |
| 670 | /* Expect encr, if enabled */ |
| 671 | /* Expect ASS CMD, if chan_type != requested */ |
| 672 | /* Send ASS CMPL in successful case */ |
| 673 | |
| 674 | /* Expect AoIP port/ip information for RTP stream */ |
| 675 | /* Expect MSC-originated MGCP to our simulated MGW */ |
| 676 | /* Verify Counters via CTRL */ |
| 677 | /* re-configure MSC behaviour via VTY */ |
| 678 | } |
| 679 | |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 680 | type record CrcxResponse { |
| 681 | integer resp, /* 1 = reply with OK, 0 = do not reply, -1 = reply with error */ |
| 682 | HostName mgw_rtp_ip, |
| 683 | PortNumber mgw_rtp_port, |
| 684 | MgcpConnectionId mgcp_connection_id /* MGCP Connection ID BSS Side */ |
| 685 | } |
| 686 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 687 | /* parameters related to a (MO?) voice call */ |
| 688 | type record CallParameters { |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 689 | /* CC related parameters */ |
| 690 | hexstring called_party, /* whom are we calling */ |
| 691 | integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */ |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 692 | boolean mo_call, /* For a MO call, the transaction_id was allocated by the MS, |
| 693 | important to set the TI flag properly */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 694 | BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */ |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 695 | boolean emergency, /* is this an emergency call? */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 696 | |
| 697 | /* MNCC related parameters */ |
| 698 | uint32_t mncc_callref optional, /* call reference on the MNCC side */ |
| 699 | MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */ |
| 700 | |
| 701 | /* RTP related parameters */ |
| 702 | HostName bss_rtp_ip optional, /* BSS Side RTP IP */ |
| 703 | PortNumber bss_rtp_port optional, /* BSS Side RTP Port */ |
| 704 | HostName mss_rtp_ip optional, /* MSS Side RTP IP */ |
| 705 | PortNumber mss_rtp_port optional, /* MSS Side RTP Port */ |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 706 | integer got_crcx_count, |
| 707 | CrcxResponse mgw_conn_1, |
| 708 | CrcxResponse mgw_conn_2, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 709 | uint7_t rtp_payload_type, /* dynamic RTP payload type */ |
| 710 | charstring rtp_sdp_format, /* AMR/8000 or the like */ |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 711 | boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX |
| 712 | (f_mt_call and f_mt_call) */ |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 713 | boolean stop_after_cc_setup, /* Special case: stop call establish after CC Setup */ |
| 714 | boolean ran_clear_when_alerting, /* Special case: send Clear upon CC Alerting */ |
Neels Hofmeyr | 8df6962 | 2019-11-02 19:16:03 +0100 | [diff] [blame] | 715 | boolean expect_release, /* Special case: expect call establish to cause direct CC Rel */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 716 | |
Philipp Maier | cd66857 | 2018-03-19 16:11:52 +0100 | [diff] [blame] | 717 | MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 718 | MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */, |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 719 | |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 720 | boolean use_osmux, /* MSC is expected to use Osmux for this call */ |
| 721 | integer got_osmux_count |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 722 | } |
| 723 | |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 724 | template (value) CallParameters t_CallParams(hexstring called := '12345'H, integer tid := 0) := { |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 725 | called_party := called, |
| 726 | transaction_id := tid, |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 727 | mo_call := false, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 728 | bearer_cap := valueof(ts_Bcap_voice), |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 729 | emergency := false, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 730 | mncc_callref := omit, |
| 731 | mncc_bearer_cap := valueof(ts_MNCC_bcap_voice), |
Harald Welte | 4017d55 | 2018-01-26 21:40:05 +0100 | [diff] [blame] | 732 | bss_rtp_ip := "9.8.7.6", |
| 733 | bss_rtp_port := 9000, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 734 | mss_rtp_ip := omit, |
| 735 | mss_rtp_port := omit, |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 736 | got_crcx_count := 0, |
| 737 | mgw_conn_1 := { |
| 738 | resp := 1, |
| 739 | mgw_rtp_ip := "1.1.1.1", |
| 740 | mgw_rtp_port := 10000, |
| 741 | mgcp_connection_id := '11111'H |
| 742 | }, |
| 743 | mgw_conn_2 := { |
| 744 | resp := 1, |
| 745 | mgw_rtp_ip := "1.1.1.1", |
| 746 | mgw_rtp_port := 11000, |
| 747 | mgcp_connection_id := '22222'H |
| 748 | }, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 749 | rtp_payload_type := 98, |
| 750 | rtp_sdp_format := "AMR/8000", |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 751 | mgw_drop_dlcx := false, |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 752 | stop_after_cc_setup := false, |
| 753 | ran_clear_when_alerting := false, |
Neels Hofmeyr | 8df6962 | 2019-11-02 19:16:03 +0100 | [diff] [blame] | 754 | expect_release := false, |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 755 | mgcp_call_id := omit, |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 756 | mgcp_ep := "rtpbridge/1@mgw", |
| 757 | use_osmux := false, |
| 758 | got_osmux_count := 0 |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 759 | }; |
| 760 | |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 761 | /* Allocate a call reference and send SETUP via MNCC to MSC */ |
| 762 | function f_mt_call_initate(inout CallParameters cpars) |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 763 | runs on BSC_ConnHdlr { |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 764 | cpars.mo_call := false; |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 765 | cpars.mncc_callref := f_rnd_int(2147483648); |
| 766 | MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn), |
| 767 | hex2str(cpars.called_party), hex2str(g_pars.imsi))); |
| 768 | } |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 769 | |
Harald Welte | 408a7ef | 2019-04-21 17:08:40 +0200 | [diff] [blame] | 770 | private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) := |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 771 | ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip, |
Harald Welte | 408a7ef | 2019-04-21 17:08:40 +0200 | [diff] [blame] | 772 | hex2str(cpars.mgcp_call_id), "42", |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 773 | cpars.mgw_conn_2.mgw_rtp_port, |
Harald Welte | 408a7ef | 2019-04-21 17:08:40 +0200 | [diff] [blame] | 774 | { int2str(cpars.rtp_payload_type) }, |
| 775 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 776 | cpars.rtp_sdp_format)), |
| 777 | valueof(ts_SDP_ptime(20)) }); |
| 778 | |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 779 | /* Complete call, begin with a paging response message via BSSAP */ |
| 780 | function f_mt_call_complete(inout CallParameters cpars) |
| 781 | runs on BSC_ConnHdlr { |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 782 | var MNCC_PDU mncc; |
| 783 | var MgcpCommand mgcp_cmd; |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 784 | var template MgcpResponse mgcp_resp; |
| 785 | var MgcpOsmuxCID osmux_cid; |
| 786 | var PDU_BSSAP bssap; |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 787 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 788 | f_ran_register_imsi(g_pars.imsi, g_pars.tmsi); |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 789 | |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 790 | f_establish_fully(EST_TYPE_PAG_RESP); |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 791 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 792 | log("f_mt_call_complete 1"); |
| 793 | |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 794 | cpars.got_osmux_count := 0; |
| 795 | |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 796 | /* MS <- MSC: Expect CC SETUP */ |
| 797 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party))); |
| 798 | |
| 799 | /* MS -> MSC: ALERTING */ |
| 800 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id))); |
| 801 | MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref)); |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 802 | log("f_mt_call_complete 2"); |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 803 | |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 804 | /* Create MGCP expect */ |
| 805 | f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit}); |
| 806 | /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */ |
| 807 | MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref)); |
| 808 | |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 809 | /* First MGCP CRCX */ |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 810 | MGCP.receive(tr_CRCX) -> value mgcp_cmd { |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 811 | log("f_mt_call_complete 3"); |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 812 | if (not f_handle_crcx(cpars, mgcp_cmd)) { |
| 813 | return; |
Philipp Maier | 4b2692d | 2018-03-14 16:37:48 +0100 | [diff] [blame] | 814 | } |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 815 | } |
Neels Hofmeyr | 59e0c6f | 2019-03-06 15:21:20 +0100 | [diff] [blame] | 816 | |
Neels Hofmeyr | 59e0c6f | 2019-03-06 15:21:20 +0100 | [diff] [blame] | 817 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 818 | if (g_pars.ran_is_geran) { |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 819 | var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass := |
| 820 | tr_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.mgw_conn_1.mgw_rtp_ip), ?); |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 821 | |
| 822 | interleave { |
| 823 | /* Second MGCP CRCX (this time for MSS/CN side) */ |
| 824 | [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd { |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 825 | log("f_mt_call_complete 4"); |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 826 | if (not f_handle_crcx(cpars, mgcp_cmd)) { |
| 827 | break; |
| 828 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 829 | } |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 830 | |
| 831 | /* MSC acknowledges the MNCC_CREATE to the MNCC handler */ |
| 832 | [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) { |
| 833 | log("f_mt_call_complete 5"); |
| 834 | } |
| 835 | |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 836 | /* expect the MSC to trigger a BSSMAP ASSIGNMENT */ |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 837 | [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap { |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 838 | var template BSSMAP_IE_AoIP_TransportLayerAddress tla; |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 839 | var BSSMAP_IE_SpeechCodec codec; |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 840 | var BSSMAP_IE_Osmo_OsmuxCID osmuxCID; |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 841 | log("f_mt_call_complete 6"); |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 842 | |
| 843 | tla := valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.bss_rtp_ip), cpars.bss_rtp_port)); |
| 844 | codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR})); |
| 845 | |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 846 | if (cpars.use_osmux) { |
| 847 | if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) { |
| 848 | setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE"); |
| 849 | mtc.stop; |
| 850 | } |
| 851 | osmuxCID := valueof(ts_OsmuxCID(0)); |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 852 | if (not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) { |
| 853 | setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE. Expected ", osmuxCID, " Got ", bssap.pdu.bssmap.assignmentRequest.osmuxCID); |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 854 | mtc.stop; |
| 855 | } |
| 856 | bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID)); |
| 857 | } else { |
| 858 | bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec)); |
| 859 | } |
| 860 | BSSAP.send(bssap); |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 861 | |
| 862 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id))); |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 863 | } |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 864 | |
| 865 | [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) { |
| 866 | log("f_mt_call_complete 7"); |
| 867 | MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref, |
| 868 | /* ip 42.23.11.5 */ hex2int('42231105'H), |
| 869 | /* port 423 */ 423, |
| 870 | /* payload type 3 = GSM FR */ 3)); |
| 871 | } |
| 872 | |
| 873 | /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */ |
| 874 | [] MGCP.receive(tr_MDCX) -> value mgcp_cmd { |
| 875 | log("f_mt_call_complete 8"); |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 876 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip, |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 877 | hex2str(cpars.mgcp_call_id), "42", |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 878 | cpars.mgw_conn_2.mgw_rtp_port, |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 879 | { int2str(cpars.rtp_payload_type) }, |
| 880 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 881 | cpars.rtp_sdp_format)), |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 882 | valueof(ts_SDP_ptime(20)) })); |
| 883 | if (cpars.use_osmux) { |
| 884 | osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd); |
| 885 | if (osmux_cid != 0) { /* we expect MSC to use specific CID here */ |
| 886 | setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0"); |
| 887 | mtc.stop; |
| 888 | } |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 889 | mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp); |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 890 | } else { |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 891 | mgcp_resp := ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp); |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 892 | } |
| 893 | MGCP.send(mgcp_resp); |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */ |
| 897 | [] MGCP.receive(tr_MDCX) -> value mgcp_cmd { |
| 898 | log("f_mt_call_complete 9"); |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 899 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip, |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 900 | hex2str(cpars.mgcp_call_id), "42", |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 901 | cpars.mgw_conn_2.mgw_rtp_port, |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 902 | { int2str(cpars.rtp_payload_type) }, |
| 903 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 904 | cpars.rtp_sdp_format)), |
| 905 | valueof(ts_SDP_ptime(20)) })); |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 906 | MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp)); |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 907 | } |
| 908 | |
Neels Hofmeyr | 59e0c6f | 2019-03-06 15:21:20 +0100 | [diff] [blame] | 909 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 910 | } else { |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 911 | interleave { |
| 912 | [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd { |
Neels Hofmeyr | 8fe8a90 | 2019-11-03 05:51:03 +0100 | [diff] [blame] | 913 | log("f_mt_call_complete 4.iu"); |
| 914 | if (not f_handle_crcx(cpars, mgcp_cmd)) { |
| 915 | break; |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 916 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 917 | } |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 918 | |
Neels Hofmeyr | 8fe8a90 | 2019-11-03 05:51:03 +0100 | [diff] [blame] | 919 | /* MSC acknowledges the MNCC_CREATE to the MNCC handler */ |
| 920 | [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) { |
| 921 | log("f_mt_call_complete 5.iu"); |
| 922 | } |
| 923 | |
| 924 | [] BSSAP.receive(tr_RANAP_RabAssReq(?)) { |
| 925 | log("f_mt_call_complete 6.iu"); |
| 926 | var RAB_SetupOrModifiedList l := { |
| 927 | { |
| 928 | { |
| 929 | id := id_RAB_SetupOrModifiedItem, |
| 930 | criticality := ignore, |
| 931 | value_ := { |
| 932 | rAB_SetupOrModifiedItem := { |
| 933 | rAB_ID := int2bit(23, 8), |
| 934 | transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H), |
| 935 | iuTransportAssociation := { |
| 936 | bindingID := '040c0000'O |
| 937 | }, |
| 938 | dl_dataVolumes := omit, |
| 939 | iE_Extensions := omit |
| 940 | } |
| 941 | } |
| 942 | } |
| 943 | } |
| 944 | }; |
| 945 | BSSAP.send(ts_RANAP_RabAssResp(l)); |
| 946 | |
| 947 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id))); |
| 948 | } |
| 949 | |
| 950 | [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) { |
| 951 | log("f_mt_call_complete 7.iu"); |
| 952 | MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref, |
| 953 | /* ip 42.23.11.5 */ hex2int('42231105'H), |
| 954 | /* port 423 */ 423, |
| 955 | /* payload type 3 = GSM FR */ 3)); |
| 956 | } |
| 957 | |
| 958 | /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */ |
| 959 | [] MGCP.receive(tr_MDCX) -> value mgcp_cmd { |
| 960 | log("f_mt_call_complete 8.iu"); |
| 961 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip, |
| 962 | hex2str(cpars.mgcp_call_id), "42", |
| 963 | cpars.mgw_conn_2.mgw_rtp_port, |
| 964 | { int2str(cpars.rtp_payload_type) }, |
| 965 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 966 | cpars.rtp_sdp_format)), |
| 967 | valueof(ts_SDP_ptime(20)) })); |
| 968 | if (cpars.use_osmux) { |
| 969 | osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd); |
| 970 | if (osmux_cid != 0) { /* we expect MSC to use specific CID here */ |
| 971 | setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0"); |
| 972 | mtc.stop; |
| 973 | } |
| 974 | mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp); |
| 975 | } else { |
| 976 | mgcp_resp := ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp); |
| 977 | } |
| 978 | MGCP.send(mgcp_resp); |
| 979 | } |
| 980 | |
| 981 | /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */ |
| 982 | [] MGCP.receive(tr_MDCX) -> value mgcp_cmd { |
| 983 | log("f_mt_call_complete 9.iu"); |
| 984 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip, |
| 985 | hex2str(cpars.mgcp_call_id), "42", |
| 986 | cpars.mgw_conn_2.mgw_rtp_port, |
| 987 | { int2str(cpars.rtp_payload_type) }, |
| 988 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 989 | cpars.rtp_sdp_format)), |
| 990 | valueof(ts_SDP_ptime(20)) })); |
| 991 | MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp)); |
| 992 | } |
| 993 | |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 994 | } |
Neels Hofmeyr | 59e0c6f | 2019-03-06 15:21:20 +0100 | [diff] [blame] | 995 | } |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 996 | |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 997 | if (cpars.use_osmux == (cpars.got_osmux_count != 0)) { |
| 998 | log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count); |
| 999 | } else { |
| 1000 | setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count); |
| 1001 | mtc.stop; |
| 1002 | } |
| 1003 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1004 | log("f_mt_call_complete DONE"); |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 1005 | } |
| 1006 | |
Harald Welte | e035e3e | 2019-04-21 17:32:05 +0200 | [diff] [blame] | 1007 | function f_expect_paging(boolean by_tmsi := true) |
| 1008 | runs on BSC_ConnHdlr { |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 1009 | if (g_pars.ran_is_geran) { |
| 1010 | BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi)); |
| 1011 | } else { |
Harald Welte | 62113fc | 2019-05-09 13:04:02 +0200 | [diff] [blame] | 1012 | BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi))); |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 1013 | } |
Harald Welte | e035e3e | 2019-04-21 17:32:05 +0200 | [diff] [blame] | 1014 | } |
| 1015 | |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 1016 | function f_mt_call_establish(inout CallParameters cpars) |
| 1017 | runs on BSC_ConnHdlr { |
| 1018 | |
| 1019 | /* Initiate the call via MNCC */ |
| 1020 | f_mt_call_initate(cpars); |
| 1021 | |
| 1022 | /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1023 | f_ran_register_imsi(g_pars.imsi, g_pars.tmsi); |
Harald Welte | e035e3e | 2019-04-21 17:32:05 +0200 | [diff] [blame] | 1024 | f_expect_paging() |
Harald Welte | 4263c52 | 2018-12-06 11:56:27 +0100 | [diff] [blame] | 1025 | |
| 1026 | /* Complete the call via BSSAP */ |
| 1027 | f_mt_call_complete(cpars); |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 1028 | |
Harald Welte | 33ec09b | 2018-02-10 15:34:46 +0100 | [diff] [blame] | 1029 | setverdict(pass); |
| 1030 | } |
| 1031 | |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1032 | /* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters. |
| 1033 | * Return true when an OK reply was sent, false otherwise. |
| 1034 | * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */ |
| 1035 | function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd) |
| 1036 | runs on BSC_ConnHdlr |
| 1037 | return boolean { |
| 1038 | var CrcxResponse conn := cpars.mgw_conn_1; |
| 1039 | if (cpars.got_crcx_count > 0) { |
| 1040 | conn := cpars.mgw_conn_2; |
| 1041 | } |
| 1042 | cpars.got_crcx_count := cpars.got_crcx_count + 1; |
| 1043 | |
| 1044 | var MgcpMessage mgcp_msg := { |
| 1045 | command := mgcp_cmd |
| 1046 | } |
| 1047 | var template MgcpResponse mgcp_resp; |
| 1048 | var MgcpOsmuxCID osmux_cid; |
| 1049 | var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd); |
| 1050 | if (ispresent(cpars.mgcp_call_id)) { |
| 1051 | if (cpars.mgcp_call_id != call_id) { |
| 1052 | setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id); |
| 1053 | mtc.stop; |
| 1054 | } |
| 1055 | } else { |
| 1056 | cpars.mgcp_call_id := call_id; |
| 1057 | } |
| 1058 | |
| 1059 | /* When the endpoint contains a wildcard we keep the endpoint |
| 1060 | * identifier we have set up in cpars. Otherwise we use the |
| 1061 | * endpoint name that the call agent has supplied */ |
| 1062 | if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) { |
| 1063 | cpars.mgcp_ep := mgcp_cmd.line.ep; |
| 1064 | } |
| 1065 | |
| 1066 | if (conn.resp == -1) { |
| 1067 | /* Reply with error */ |
| 1068 | var MgcpResponse mgcp_rsp := { |
| 1069 | line := { |
| 1070 | code := "542", |
| 1071 | trans_id := mgcp_cmd.line.trans_id, |
| 1072 | string := "FORCED_FAIL" |
| 1073 | }, |
| 1074 | sdp := omit |
| 1075 | |
| 1076 | } |
| 1077 | var MgcpParameter mgcp_rsp_param := { |
| 1078 | code := "Z", |
| 1079 | val := cpars.mgcp_ep |
| 1080 | }; |
| 1081 | mgcp_rsp.params[0] := mgcp_rsp_param; |
| 1082 | MGCP.send(mgcp_rsp); |
| 1083 | return false; |
| 1084 | } |
| 1085 | |
| 1086 | if (conn.resp == 0) { |
| 1087 | /* Do not reply at all */ |
| 1088 | return false; |
| 1089 | } |
| 1090 | |
| 1091 | if (conn.resp != 1) { |
| 1092 | setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1"); |
| 1093 | mtc.stop; |
| 1094 | } |
| 1095 | |
| 1096 | var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip, |
| 1097 | hex2str(cpars.mgcp_call_id), "42", |
| 1098 | conn.mgw_rtp_port, |
| 1099 | { int2str(cpars.rtp_payload_type) }, |
| 1100 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 1101 | cpars.rtp_sdp_format)), |
| 1102 | valueof(ts_SDP_ptime(20)) })); |
| 1103 | |
| 1104 | if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) { |
| 1105 | if (not cpars.use_osmux) { |
| 1106 | setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux"); |
| 1107 | mtc.stop; |
| 1108 | } |
| 1109 | cpars.got_osmux_count := cpars.got_osmux_count + 1; |
| 1110 | /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */ |
| 1111 | osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd); |
| 1112 | log("f_handle_crcx(): got Osmux CID: ", osmux_cid); |
| 1113 | if (osmux_cid != -1) { |
| 1114 | setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1"); |
| 1115 | mtc.stop; |
| 1116 | } |
| 1117 | |
| 1118 | osmux_cid := 0; |
| 1119 | mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp); |
| 1120 | } else { |
| 1121 | mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp); |
| 1122 | } |
| 1123 | |
| 1124 | f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep)); |
| 1125 | MGCP.send(mgcp_resp); |
| 1126 | return true; |
| 1127 | } |
| 1128 | |
| 1129 | |
| 1130 | altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr { |
| 1131 | var MgcpCommand mgcp_cmd; |
| 1132 | [] MGCP.receive(tr_CRCX) -> value mgcp_cmd { |
| 1133 | log("as_optional_mgcp_crcx: rx CRCX"); |
| 1134 | f_handle_crcx(cpars, mgcp_cmd); |
| 1135 | |
| 1136 | /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an |
| 1137 | * CRCX is handled. */ |
| 1138 | repeat; |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | private altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr { |
| 1143 | var MgcpCommand mgcp_cmd; |
| 1144 | [] MGCP.receive(tr_MDCX) -> value mgcp_cmd { |
| 1145 | log("as_optional_mgcp_mdcx: rx MDCX"); |
| 1146 | log(mgcp_cmd); |
| 1147 | var charstring conn_id; |
| 1148 | var charstring rtp_payload_type; |
| 1149 | f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id); |
| 1150 | rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0]; |
| 1151 | |
| 1152 | var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip, |
| 1153 | mgcp_cmd.sdp.origin.session_id, "42", |
| 1154 | mgw_rtp_port, |
| 1155 | { rtp_payload_type }, |
| 1156 | { valueof(ts_SDP_ptime(20)) })); |
| 1157 | MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp)); |
| 1158 | |
| 1159 | /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is |
| 1160 | * handled. */ |
| 1161 | repeat; |
| 1162 | } |
| 1163 | } |
| 1164 | |
Neels Hofmeyr | 0b16bf1 | 2019-11-03 05:10:12 +0100 | [diff] [blame] | 1165 | private altstep as_optional_mgcp_dlcx(CallParameters cpars) runs on BSC_ConnHdlr { |
| 1166 | var MgcpCommand mgcp_cmd; |
| 1167 | var boolean respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx)); |
| 1168 | [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd { |
| 1169 | log("as_optional_mgcp_dlcx: rx MGCP DLCX"); |
| 1170 | if (respond_to_dlcx) { |
| 1171 | MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id)); |
| 1172 | } |
| 1173 | /* Without this 'repeat', currently active other interleave and alt series exit as soon as a |
| 1174 | * DLCX is handled. */ |
| 1175 | repeat; |
| 1176 | } |
| 1177 | } |
| 1178 | |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1179 | function f_mo_call_establish(inout CallParameters cpars) |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1180 | runs on BSC_ConnHdlr { |
| 1181 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1182 | var MNCC_PDU mncc; |
| 1183 | var MgcpCommand mgcp_cmd; |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 1184 | var template MgcpResponse mgcp_resp; |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 1185 | var boolean respond_to_dlcx; |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 1186 | var PDU_BSSAP bssap; |
Neels Hofmeyr | 0b16bf1 | 2019-11-03 05:10:12 +0100 | [diff] [blame] | 1187 | var RANAP_PDU ranap; |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 1188 | var MgcpOsmuxCID osmux_cid; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1189 | |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1190 | cpars.mo_call := true; |
| 1191 | |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 1192 | if (cpars.emergency) { |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 1193 | f_establish_fully(EST_TYPE_EMERG_CALL); |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 1194 | } else { |
Harald Welte | b9e86fa | 2018-04-09 18:18:31 +0200 | [diff] [blame] | 1195 | f_establish_fully(EST_TYPE_MO_CALL); |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 1196 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1197 | |
| 1198 | /* Create MNCC and MGCP expect */ |
| 1199 | f_create_mncc_expect(hex2str(cpars.called_party)); |
| 1200 | f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit}); |
| 1201 | |
Harald Welte | 0bef21e | 2018-02-10 09:48:23 +0100 | [diff] [blame] | 1202 | if (cpars.emergency) { |
| 1203 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id))); |
| 1204 | } else { |
| 1205 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party))); |
| 1206 | } |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1207 | |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1208 | if (cpars.stop_after_cc_setup) { |
| 1209 | return; |
| 1210 | } |
| 1211 | |
| 1212 | var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass := |
| 1213 | tr_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.mgw_conn_1.mgw_rtp_ip), ?); |
| 1214 | |
| 1215 | var default mdcx := activate(as_optional_mgcp_mdcx(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_port)); |
Neels Hofmeyr | 8df6962 | 2019-11-02 19:16:03 +0100 | [diff] [blame] | 1216 | var boolean got_mncc_setup_compl_ind := false; |
| 1217 | var boolean got_cc_connect := false; |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1218 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1219 | interleave { |
| 1220 | [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc { |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1221 | log("f_mo_call_establish 1: rx MNCC SETUP ind"); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1222 | cpars.mncc_callref := mncc.u.signal.callref; |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1223 | MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref)); |
| 1224 | } |
| 1225 | |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1226 | /* First MGCP CRCX */ |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1227 | [] MGCP.receive(tr_CRCX) -> value mgcp_cmd { |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1228 | log("f_mo_call_establish 2: rx 1st CRCX"); |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1229 | if (not f_handle_crcx(cpars, mgcp_cmd)) { |
| 1230 | break; |
| 1231 | } |
Philipp Maier | f1e02bb | 2018-03-15 16:30:00 +0100 | [diff] [blame] | 1232 | } |
| 1233 | |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1234 | /* Second MGCP CRCX */ |
| 1235 | [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd { |
| 1236 | log("f_mo_call_establish 6: rx 2nd CRCX"); |
| 1237 | if (not f_handle_crcx(cpars, mgcp_cmd)) { |
| 1238 | break; |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 1239 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1240 | } |
Neels Hofmeyr | 59e0c6f | 2019-03-06 15:21:20 +0100 | [diff] [blame] | 1241 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1242 | [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) { |
| 1243 | log("f_mo_call_establish 3: rx RTP CREATE"); |
| 1244 | /* Call Proceeding */ |
| 1245 | MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap)); |
| 1246 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id))); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1247 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1248 | /* Alerting */ |
| 1249 | MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref)); |
Neels Hofmeyr | 59e0c6f | 2019-03-06 15:21:20 +0100 | [diff] [blame] | 1250 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 1251 | |
Neels Hofmeyr | eccaa99 | 2019-10-15 16:42:21 +0200 | [diff] [blame] | 1252 | //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap |
Neels Hofmeyr | d9d835d | 2019-09-17 18:19:08 +0200 | [diff] [blame] | 1253 | [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap { |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1254 | log("f_mo_call_establish 4: rx Assignment Request"); |
| 1255 | var BSSMAP_IE_AoIP_TransportLayerAddress tla; |
| 1256 | var BSSMAP_IE_SpeechCodec codec; |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 1257 | var BSSMAP_IE_Osmo_OsmuxCID osmuxCID; |
| 1258 | |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1259 | if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass)) { |
Neels Hofmeyr | d9d835d | 2019-09-17 18:19:08 +0200 | [diff] [blame] | 1260 | log("Expected:", tla_ass); |
| 1261 | log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer); |
| 1262 | setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE"); |
| 1263 | mtc.stop; |
| 1264 | } |
| 1265 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1266 | tla := valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.bss_rtp_ip), cpars.bss_rtp_port)); |
| 1267 | codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR})); |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 1268 | if (cpars.use_osmux) { |
| 1269 | if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) { |
| 1270 | setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE"); |
| 1271 | mtc.stop; |
| 1272 | } |
| 1273 | osmuxCID := valueof(ts_OsmuxCID(0)); |
| 1274 | if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) { |
| 1275 | setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE"); |
| 1276 | mtc.stop; |
| 1277 | } |
| 1278 | bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID)); |
| 1279 | } else { |
| 1280 | bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec)); |
| 1281 | } |
| 1282 | BSSAP.send(bssap); |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1283 | } |
Neels Hofmeyr | 0b16bf1 | 2019-11-03 05:10:12 +0100 | [diff] [blame] | 1284 | [] BSSAP.receive(tr_RANAP_RabAssReq(*)) -> value ranap { |
| 1285 | log("f_mo_call_establish 4.iu: rx RANAP RAB Assignment Request"); |
| 1286 | var RAB_SetupOrModifiedList l := { |
| 1287 | { |
| 1288 | { |
| 1289 | id := id_RAB_SetupOrModifiedItem, |
| 1290 | criticality := ignore, |
| 1291 | value_ := { |
| 1292 | rAB_SetupOrModifiedItem := { |
| 1293 | rAB_ID := int2bit(23, 8), |
| 1294 | transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H), |
| 1295 | iuTransportAssociation := { |
| 1296 | bindingID := '040c0000'O |
| 1297 | }, |
| 1298 | dl_dataVolumes := omit, |
| 1299 | iE_Extensions := omit |
| 1300 | } |
| 1301 | } |
| 1302 | } |
| 1303 | } |
| 1304 | }; |
| 1305 | BSSAP.send(ts_RANAP_RabAssResp(l)); |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1306 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 1307 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1308 | /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */ |
| 1309 | [] MGCP.receive(tr_MDCX) -> value mgcp_cmd { |
| 1310 | log("f_mo_call_establish 5: rx MDCX for the RAN side"); |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1311 | var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip, |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1312 | hex2str(cpars.mgcp_call_id), "42", |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1313 | cpars.mgw_conn_2.mgw_rtp_port, |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1314 | { int2str(cpars.rtp_payload_type) }, |
| 1315 | { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type, |
| 1316 | cpars.rtp_sdp_format)), |
| 1317 | valueof(ts_SDP_ptime(20)) })); |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 1318 | |
| 1319 | if (cpars.use_osmux) { |
| 1320 | osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd); |
| 1321 | if (osmux_cid != 0) { /* we expect MSC to use specific CID here */ |
| 1322 | setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0"); |
| 1323 | mtc.stop; |
| 1324 | } |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1325 | mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp); |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 1326 | } else { |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1327 | mgcp_resp := ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp); |
Pau Espin Pedrol | a65697d | 2019-05-21 12:54:39 +0200 | [diff] [blame] | 1328 | } |
| 1329 | MGCP.send(mgcp_resp); |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1330 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 1331 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1332 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) { |
| 1333 | log("f_mo_call_establish 7: rx CC Alerting"); |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1334 | |
| 1335 | if (cpars.ran_clear_when_alerting) { |
| 1336 | if (g_pars.ran_is_geran) { |
| 1337 | BSSAP.send(ts_BSSMAP_ClearRequest(0)); |
| 1338 | } else { |
| 1339 | BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention)); |
| 1340 | } |
| 1341 | break; |
| 1342 | } |
| 1343 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1344 | cpars.mncc_callref := mncc.u.signal.callref; |
| 1345 | /* Call Proceeding */ |
| 1346 | MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref, |
| 1347 | /* ip 42.23.11.5 */ hex2int('42231105'H), |
| 1348 | /* port 423 */ 423, |
| 1349 | /* payload type 3 = GSM FR */ 3)); |
| 1350 | MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref)); |
| 1351 | } |
| 1352 | |
| 1353 | [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc { |
| 1354 | log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind"); |
Neels Hofmeyr | 8df6962 | 2019-11-02 19:16:03 +0100 | [diff] [blame] | 1355 | got_mncc_setup_compl_ind := true; |
| 1356 | if (not cpars.expect_release and got_cc_connect) { |
| 1357 | break; |
| 1358 | } |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1359 | } |
| 1360 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1361 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) { |
| 1362 | log("f_mo_call_establish 10: rx CC CONNECT"); |
| 1363 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id))); |
Neels Hofmeyr | 8df6962 | 2019-11-02 19:16:03 +0100 | [diff] [blame] | 1364 | got_cc_connect := true; |
| 1365 | if (not cpars.expect_release and got_mncc_setup_compl_ind) { |
| 1366 | break; |
| 1367 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1368 | } |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1369 | |
| 1370 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) { |
| 1371 | log("f_mo_call_establish 11: rx CC RELEASE"); |
Neels Hofmeyr | 8df6962 | 2019-11-02 19:16:03 +0100 | [diff] [blame] | 1372 | if (not cpars.expect_release) { |
| 1373 | setverdict(fail, "Got unexpected CC Release"); |
| 1374 | mtc.stop; |
| 1375 | } |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1376 | f_expect_clear(); |
| 1377 | break; |
| 1378 | } |
| 1379 | } |
| 1380 | |
| 1381 | f_sleep(0.5); |
| 1382 | deactivate(mdcx); |
| 1383 | |
| 1384 | if (cpars.use_osmux == (cpars.got_osmux_count != 0)) { |
| 1385 | log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count); |
| 1386 | } else { |
| 1387 | setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count); |
| 1388 | mtc.stop; |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1389 | } |
| 1390 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1391 | log("f_mo_call_establish DONE"); |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1392 | setverdict(pass); |
| 1393 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1394 | |
Harald Welte | 4c422b7 | 2019-02-17 16:27:10 +0100 | [diff] [blame] | 1395 | function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false) |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1396 | runs on BSC_ConnHdlr { |
| 1397 | |
| 1398 | var MobileIdentityLV mi; |
| 1399 | var MNCC_PDU mncc; |
| 1400 | var MgcpCommand mgcp_cmd; |
| 1401 | var boolean respond_to_dlcx; |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1402 | var boolean dlcx_contained_ci := false; |
| 1403 | var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand; |
| 1404 | |
| 1405 | if (is_csfb) { |
| 1406 | t_clear := tr_BSSMAP_ClearCommandCSFB; |
| 1407 | } |
| 1408 | |
Neels Hofmeyr | ba960a1 | 2019-11-02 19:17:38 +0100 | [diff] [blame] | 1409 | log("f_call_hangup 0: tx MNCC_DISC_REQ"); |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1410 | MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23)))); |
| 1411 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id))); |
| 1412 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1413 | log("f_call_hangup 1: rx DTAP CC DISC"); |
| 1414 | |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1415 | if (release_by_ms) { |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1416 | var BIT1 tid_remote := '1'B; |
| 1417 | if (cpars.mo_call) { |
| 1418 | tid_remote := '0'B; |
| 1419 | } |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1420 | /* B-side (MS) Release of call */ |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1421 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_RELEASE(cpars.transaction_id, tid_remote, '0000000'B))); |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1422 | MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref)); |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1423 | log("f_call_hangup 2: rx MNCC REL ind"); |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1424 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id))); |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1425 | log("f_call_hangup 3: rx DTAP CC REL COMPL"); |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1426 | } else { |
| 1427 | /* A-side (PLMN) Release of call */ |
| 1428 | MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42)))); |
| 1429 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))); |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1430 | log("f_call_hangup 4: rx DTAP CC RELEASE"); |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1431 | BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id))); |
| 1432 | } |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1433 | |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 1434 | respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx)); |
| 1435 | |
Neels Hofmeyr | 3c89a6b | 2019-10-15 16:54:37 +0200 | [diff] [blame] | 1436 | var default mdcx := activate(as_optional_mgcp_mdcx(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_port)); |
Neels Hofmeyr | 0b16bf1 | 2019-11-03 05:10:12 +0100 | [diff] [blame] | 1437 | var default dlcx := activate(as_optional_mgcp_dlcx(cpars)); |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 1438 | |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1439 | /* clearing of radio channel */ |
Neels Hofmeyr | 0b16bf1 | 2019-11-03 05:10:12 +0100 | [diff] [blame] | 1440 | alt { |
| 1441 | [g_pars.ran_is_geran] BSSAP.receive(t_clear) { |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1442 | log("f_call_hangup 5: rx BSSAP Clear Command"); |
| 1443 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 1444 | BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND); |
| 1445 | log("f_call_hangup 6: rx SCCP DISC"); |
Neels Hofmeyr | 0b16bf1 | 2019-11-03 05:10:12 +0100 | [diff] [blame] | 1446 | setverdict(pass); |
Philipp Maier | 2a98a73 | 2018-03-19 16:06:12 +0100 | [diff] [blame] | 1447 | } |
Neels Hofmeyr | 0b16bf1 | 2019-11-03 05:10:12 +0100 | [diff] [blame] | 1448 | [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) { |
| 1449 | log("f_call_hangup 5.iu: rx Iu Release Command"); |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1450 | BSSAP.send(ts_RANAP_IuReleaseComplete); |
| 1451 | BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND); |
Neels Hofmeyr | 0b16bf1 | 2019-11-03 05:10:12 +0100 | [diff] [blame] | 1452 | log("f_call_hangup 6.iu: rx SCCP DISC"); |
| 1453 | setverdict(pass); |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1454 | } |
| 1455 | } |
| 1456 | |
Neels Hofmeyr | 0b16bf1 | 2019-11-03 05:10:12 +0100 | [diff] [blame] | 1457 | f_sleep(1.0); |
Neels Hofmeyr | 2ca1ab4 | 2019-03-08 03:45:43 +0100 | [diff] [blame] | 1458 | f_create_mgcp_delete_ep(cpars.mgcp_ep); |
| 1459 | log("f_call_hangup 9: done"); |
| 1460 | |
| 1461 | deactivate(mdcx); |
Neels Hofmeyr | 0b16bf1 | 2019-11-03 05:10:12 +0100 | [diff] [blame] | 1462 | deactivate(dlcx); |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | function f_mt_call(inout CallParameters cpars) |
| 1466 | runs on BSC_ConnHdlr { |
| 1467 | |
| 1468 | f_mt_call_establish(cpars); |
| 1469 | |
Neels Hofmeyr | ba960a1 | 2019-11-02 19:17:38 +0100 | [diff] [blame] | 1470 | log("Hold the call for some time"); |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1471 | f_sleep(3.0); |
| 1472 | |
Neels Hofmeyr | ba960a1 | 2019-11-02 19:17:38 +0100 | [diff] [blame] | 1473 | log("Hangup"); |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1474 | f_call_hangup(cpars, true); |
| 1475 | |
| 1476 | setverdict(pass); |
| 1477 | } |
| 1478 | |
| 1479 | function f_mo_call(inout CallParameters cpars) |
| 1480 | runs on BSC_ConnHdlr { |
| 1481 | |
| 1482 | f_mo_call_establish(cpars); |
| 1483 | |
Neels Hofmeyr | ba960a1 | 2019-11-02 19:17:38 +0100 | [diff] [blame] | 1484 | log("Hold the call for some time"); |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1485 | f_sleep(3.0); |
| 1486 | |
Neels Hofmeyr | ba960a1 | 2019-11-02 19:17:38 +0100 | [diff] [blame] | 1487 | log("Hangup"); |
Philipp Maier | 3716a5e | 2018-03-21 15:53:35 +0100 | [diff] [blame] | 1488 | f_call_hangup(cpars, false); |
| 1489 | |
Harald Welte | b71901a | 2018-01-26 19:16:05 +0100 | [diff] [blame] | 1490 | setverdict(pass); |
| 1491 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 1492 | |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1493 | function f_mo_seq_dtmf_dup(inout CallParameters cpars) |
| 1494 | runs on BSC_ConnHdlr { |
| 1495 | |
| 1496 | timer T := 1.0; |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1497 | var MNCC_PDU mncc; |
| 1498 | var MgcpCommand mgcp_cmd; |
| 1499 | var template PDU_ML3_MS_NW dtmf_dtap; |
| 1500 | |
Neels Hofmeyr | 3d22e4a | 2019-10-03 04:07:47 +0200 | [diff] [blame] | 1501 | f_mo_call_establish(cpars); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1502 | |
Neels Hofmeyr | 3d22e4a | 2019-10-03 04:07:47 +0200 | [diff] [blame] | 1503 | /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by |
| 1504 | * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */ |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1505 | |
Neels Hofmeyr | 3d22e4a | 2019-10-03 04:07:47 +0200 | [diff] [blame] | 1506 | /* Find out the next NSD that will be used, from RAN emulation. */ |
| 1507 | var N_Sd_Array last_n_sd := f_bssmap_last_n_sd(); |
| 1508 | var uint2_t next_n_sd := f_next_n_sd(last_n_sd, 0 /* cc is index 0 */); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1509 | |
Neels Hofmeyr | 3d22e4a | 2019-10-03 04:07:47 +0200 | [diff] [blame] | 1510 | /* Compose DTAP with this correct NSD */ |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1511 | dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2"); |
Neels Hofmeyr | 3d22e4a | 2019-10-03 04:07:47 +0200 | [diff] [blame] | 1512 | |
| 1513 | /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */ |
| 1514 | BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false)); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1515 | T.start; |
| 1516 | alt { |
Neels Hofmeyr | 3d22e4a | 2019-10-03 04:07:47 +0200 | [diff] [blame] | 1517 | [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) { |
| 1518 | log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind"); |
| 1519 | } |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1520 | [] T.timeout { |
| 1521 | setverdict(fail, "Timeout waiting for START_DTMF_ind"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1522 | mtc.stop; |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1523 | } |
| 1524 | } |
| 1525 | |
Neels Hofmeyr | 3d22e4a | 2019-10-03 04:07:47 +0200 | [diff] [blame] | 1526 | /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message |
| 1527 | * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */ |
| 1528 | dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2); |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 1529 | BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true)); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1530 | T.start; |
| 1531 | alt { |
| 1532 | [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) { |
Neels Hofmeyr | 3d22e4a | 2019-10-03 04:07:47 +0200 | [diff] [blame] | 1533 | setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1534 | mtc.stop; |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1535 | } |
| 1536 | [] T.timeout { } |
| 1537 | } |
| 1538 | |
Neels Hofmeyr | 3d22e4a | 2019-10-03 04:07:47 +0200 | [diff] [blame] | 1539 | /* Here the NSD should be correct again and we see a DTMF. */ |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1540 | dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3"); |
Neels Hofmeyr | 3d22e4a | 2019-10-03 04:07:47 +0200 | [diff] [blame] | 1541 | BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false)); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1542 | alt { |
Neels Hofmeyr | 3d22e4a | 2019-10-03 04:07:47 +0200 | [diff] [blame] | 1543 | [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) { |
| 1544 | log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind"); |
| 1545 | } |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1546 | [] T.timeout { |
Neels Hofmeyr | 3d22e4a | 2019-10-03 04:07:47 +0200 | [diff] [blame] | 1547 | setverdict(fail, "Timeout waiting for final START_DTMF_ind"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1548 | mtc.stop; |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1549 | } |
| 1550 | } |
| 1551 | |
Neels Hofmeyr | 3d22e4a | 2019-10-03 04:07:47 +0200 | [diff] [blame] | 1552 | f_call_hangup(cpars, true); |
Daniel Willmann | 8b08437 | 2018-02-04 13:35:26 +0100 | [diff] [blame] | 1553 | setverdict(pass); |
| 1554 | } |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 1555 | |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 1556 | /* expect a clear command */ |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 1557 | altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr { |
Neels Hofmeyr | 6b468a4 | 2019-03-06 15:25:14 +0100 | [diff] [blame] | 1558 | var PDU_BSSAP bssap; |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 1559 | [] BSSAP.receive(tr_BSSMAP_ClearCommand) { |
| 1560 | BSSAP.send(ts_BSSMAP_ClearComplete); |
| 1561 | alt { |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1562 | [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 1563 | setverdict(pass); |
| 1564 | } |
| 1565 | [] BSSAP.receive { |
| 1566 | setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1567 | mtc.stop; |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 1568 | } |
| 1569 | } |
| 1570 | } |
Neels Hofmeyr | 6b468a4 | 2019-03-06 15:25:14 +0100 | [diff] [blame] | 1571 | [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap { |
| 1572 | setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1573 | mtc.stop; |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 1574 | } |
| 1575 | } |
| 1576 | |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 1577 | function f_expect_clear(float t := 5.0) runs on BSC_ConnHdlr { |
| 1578 | timer T := t; |
| 1579 | |
| 1580 | T.start; |
| 1581 | alt { |
Harald Welte | 9b751a6 | 2019-04-14 17:39:29 +0200 | [diff] [blame] | 1582 | [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { } |
| 1583 | [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { } |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 1584 | [] T.timeout { |
Harald Welte | 5946b33 | 2018-03-18 23:32:21 +0100 | [diff] [blame] | 1585 | setverdict(fail, "Timeout waiting for ClearCommand/Release"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1586 | mtc.stop; |
Harald Welte | 1ddc716 | 2018-01-27 14:25:46 +0100 | [diff] [blame] | 1587 | } |
| 1588 | } |
| 1589 | } |
| 1590 | |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1591 | function f_create_bssmap_exp_handoverRequest(integer targetPointCode) runs on BSC_ConnHdlr { |
| 1592 | BSSAP_PROC.call(RAN_register_handoverRequest:{targetPointCode, self}) { |
| 1593 | [] BSSAP_PROC.getreply(RAN_register_handoverRequest:{?, ?}) {}; |
| 1594 | } |
| 1595 | } |
| 1596 | |
| 1597 | function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array { |
| 1598 | var N_Sd_Array last_n_sd; |
| 1599 | BSSAP_PROC.call(RAN_last_n_sd:{self, -}) { |
| 1600 | [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) { |
| 1601 | return last_n_sd; |
| 1602 | }; |
| 1603 | } |
| 1604 | } |
| 1605 | |
| 1606 | function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr { |
| 1607 | BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) { |
| 1608 | [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self}); |
| 1609 | } |
| 1610 | } |
| 1611 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1612 | type record SmsParametersTp { |
| 1613 | OCT1 msg_ref, |
| 1614 | TP_DA da, |
| 1615 | OCT1 pid, |
| 1616 | OCT1 dcs, |
| 1617 | integer udl, |
| 1618 | octetstring ud |
| 1619 | } |
| 1620 | type record SmsParametersRp { |
| 1621 | OCT1 msg_ref, |
Vadim Yanitskiy | 437b5a6 | 2019-12-15 14:13:39 +0900 | [diff] [blame] | 1622 | RP_NumberingPlan_and_NumberDigits smsc_addr optional |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1623 | } |
| 1624 | type record SmsParameters { |
| 1625 | SmsParametersTp tp, |
| 1626 | SmsParametersRp rp, |
| 1627 | uint3_t tid, |
| 1628 | OCT1 dlci, |
| 1629 | uint7_t exp_rp_err optional |
| 1630 | } |
| 1631 | |
| 1632 | template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := { |
| 1633 | tP_DA_NoPad := { |
| 1634 | tP_LengthIndicator := 0, /* overwritten */ |
| 1635 | tP_NumberingPlanID := npl, |
| 1636 | tP_TypeOfNumber := ton, |
| 1637 | tp_Spare := '0'B, |
| 1638 | tP_DAValue := addr |
| 1639 | } |
| 1640 | } |
| 1641 | |
Vadim Yanitskiy | 437b5a6 | 2019-12-15 14:13:39 +0900 | [diff] [blame] | 1642 | template RP_NumberingPlan_and_NumberDigits t_RP_Addr(template hexstring addr, |
| 1643 | template BIT4 npi := '0001'B, |
| 1644 | template BIT3 ton := '001'B, |
| 1645 | template BIT1 ext := '1'B) := { |
| 1646 | rP_NumberingPlanIdentification := npi, |
| 1647 | rP_TypeOfNumber := ton, |
| 1648 | rP_Ext := ext, |
| 1649 | rP_NumberDigits := addr |
| 1650 | } |
| 1651 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1652 | template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := { |
| 1653 | tp := { |
| 1654 | msg_ref := '23'O, |
| 1655 | da := ts_TP_DA('0000'B, '000'B, tp_daddr), |
| 1656 | pid := '00'O, |
| 1657 | dcs := '00'O, |
| 1658 | udl := 0, |
| 1659 | ud := ''O |
| 1660 | }, |
| 1661 | rp := { |
| 1662 | msg_ref := '42'O, |
Vadim Yanitskiy | 437b5a6 | 2019-12-15 14:13:39 +0900 | [diff] [blame] | 1663 | /* We don't really need to have both SM-RP-DA/OA here, because only one IE |
Vadim Yanitskiy | afb15a8 | 2020-01-05 14:04:53 +0100 | [diff] [blame] | 1664 | * is included in MO/MT SMS, and in the most cases it's the SMSC address. |
| 1665 | * NOTE: this address is currently hard-coded by OsmoMSC. */ |
| 1666 | smsc_addr := t_RP_Addr('447785016005'H) |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1667 | }, |
| 1668 | tid := 0, |
| 1669 | dlci := '03'O, |
| 1670 | exp_rp_err := omit |
| 1671 | } |
| 1672 | |
| 1673 | private altstep as_other_sms() runs on BSC_ConnHdlr { |
| 1674 | [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) { |
| 1675 | setverdict(fail, "Unexpected SMS related PDU from MSC"); |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1676 | mtc.stop; |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1677 | } |
| 1678 | } |
| 1679 | |
Vadim Yanitskiy | 9cc019a | 2018-11-15 02:06:07 +0700 | [diff] [blame] | 1680 | /* Submit a MO RP-SMMA over an already existing DTAP connection */ |
| 1681 | function f_mo_smma(inout SmsParameters spars) |
| 1682 | runs on BSC_ConnHdlr { |
| 1683 | var template (value) RPDU_MS_SGSN rp_mo; |
| 1684 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 1685 | |
| 1686 | var default d := activate(as_other_sms()); |
| 1687 | |
| 1688 | /* just in case this is routed to SMPP.. */ |
| 1689 | f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue)); |
| 1690 | |
| 1691 | rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref); |
| 1692 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo)); |
| 1693 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1694 | /* receive CP-ACK for CP-DATA above */ |
| 1695 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci)); |
| 1696 | |
| 1697 | deactivate(d); |
| 1698 | setverdict(pass); |
| 1699 | } |
| 1700 | |
Vadim Yanitskiy | d4cc150 | 2018-11-12 01:46:21 +0700 | [diff] [blame] | 1701 | /* Submit a MO-SMS over an already existing DTAP connection */ |
| 1702 | function f_mo_sms_submit(inout SmsParameters spars) |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1703 | runs on BSC_ConnHdlr { |
| 1704 | var template (value) TPDU_RP_DATA_MS_SGSN tp_mo; |
| 1705 | var template (value) RPDU_MS_SGSN rp_mo; |
| 1706 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 1707 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1708 | var default d := activate(as_other_sms()); |
| 1709 | |
Harald Welte | f640a01 | 2018-04-14 17:49:21 +0200 | [diff] [blame] | 1710 | /* just in case this is routed to SMPP.. */ |
| 1711 | f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue)); |
| 1712 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1713 | tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs, |
| 1714 | spars.tp.udl, spars.tp.ud); |
Vadim Yanitskiy | 437b5a6 | 2019-12-15 14:13:39 +0900 | [diff] [blame] | 1715 | rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, omit, spars.rp.smsc_addr, tp_mo); |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1716 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo)); |
| 1717 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1718 | /* receive CP-ACK for CP-DATA above */ |
| 1719 | BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci)); |
| 1720 | |
Vadim Yanitskiy | d4cc150 | 2018-11-12 01:46:21 +0700 | [diff] [blame] | 1721 | deactivate(d); |
| 1722 | setverdict(pass); |
| 1723 | } |
| 1724 | |
| 1725 | /* Wait RP-ACK for MO-SMS on an already existing DTAP connection */ |
| 1726 | function f_mo_sms_wait_rp_ack(inout SmsParameters spars) |
| 1727 | runs on BSC_ConnHdlr { |
| 1728 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 1729 | |
| 1730 | var template TPDU_RP_DATA_SGSN_MS tp_mt; |
| 1731 | var template RPDU_SGSN_MS rp_mt; |
| 1732 | var template PDU_ML3_NW_MS l3_mt; |
| 1733 | |
| 1734 | var default d := activate(as_other_sms()); |
| 1735 | |
| 1736 | /* just in case this is routed to SMPP.. */ |
| 1737 | f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue)); |
| 1738 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1739 | if (ispresent(spars.exp_rp_err)) { |
| 1740 | /* expect an RP-ERROR message from MSC with given cause */ |
| 1741 | rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err); |
| 1742 | l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt)); |
| 1743 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)); |
| 1744 | /* send CP-ACK for CP-DATA just received */ |
| 1745 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO); |
| 1746 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1747 | } else { |
| 1748 | /* expect RP-ACK for RP-DATA */ |
| 1749 | rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref); |
| 1750 | l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt)); |
| 1751 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)); |
| 1752 | /* send CP-ACO for CP-DATA just received */ |
| 1753 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO); |
| 1754 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1755 | } |
Vadim Yanitskiy | d4cc150 | 2018-11-12 01:46:21 +0700 | [diff] [blame] | 1756 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1757 | deactivate(d); |
| 1758 | setverdict(pass); |
| 1759 | } |
| 1760 | |
Vadim Yanitskiy | d4cc150 | 2018-11-12 01:46:21 +0700 | [diff] [blame] | 1761 | /* Submit a MO-SMS, and wait for RP-ACK on an existing |
| 1762 | * (and authenticated, ...) DTAP connection */ |
| 1763 | function f_mo_sms(inout SmsParameters spars) |
| 1764 | runs on BSC_ConnHdlr { |
| 1765 | f_mo_sms_submit(spars); |
| 1766 | f_mo_sms_wait_rp_ack(spars); |
| 1767 | } |
| 1768 | |
Vadim Yanitskiy | 2159acb | 2018-11-24 02:50:29 +0700 | [diff] [blame] | 1769 | /* Wait for MT SMS on an already existing DTAP connection */ |
| 1770 | function f_mt_sms_expect(inout SmsParameters spars) |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1771 | runs on BSC_ConnHdlr { |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1772 | var template (value) PDU_ML3_MS_NW l3_mo; |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1773 | var template TPDU_RP_DATA_SGSN_MS tp_mt; |
| 1774 | var template RPDU_SGSN_MS rp_mt; |
| 1775 | var template PDU_ML3_NW_MS l3_mt; |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1776 | var PDU_DTAP_MT dtap_mt; |
| 1777 | |
| 1778 | var default d := activate(as_other_sms()); |
| 1779 | |
| 1780 | /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */ |
| 1781 | tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?); |
Vadim Yanitskiy | 04dd5f7 | 2019-12-13 15:45:44 +0900 | [diff] [blame] | 1782 | rp_mt := tr_RP_DATA_MT(?, spars.rp.smsc_addr, omit, tp_mt); |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1783 | l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt)); |
| 1784 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)) -> value dtap_mt; |
Vadim Yanitskiy | 2159acb | 2018-11-24 02:50:29 +0700 | [diff] [blame] | 1785 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1786 | /* Extract relevant identifiers */ |
| 1787 | spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio); |
| 1788 | spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference; |
| 1789 | |
| 1790 | /* send CP-ACK for CP-DATA just received */ |
| 1791 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO); |
| 1792 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1793 | |
Vadim Yanitskiy | 2159acb | 2018-11-24 02:50:29 +0700 | [diff] [blame] | 1794 | deactivate(d); |
| 1795 | setverdict(pass); |
| 1796 | } |
| 1797 | |
| 1798 | /* Send RP-ACK for MT-SMS over an already existing DTAP connection */ |
| 1799 | function f_mt_sms_send_rp_ack(inout SmsParameters spars) |
| 1800 | runs on BSC_ConnHdlr { |
| 1801 | var template (value) RPDU_MS_SGSN rp_mo; |
| 1802 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 1803 | var template PDU_ML3_NW_MS l3_mt; |
| 1804 | |
| 1805 | var default d := activate(as_other_sms()); |
| 1806 | |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1807 | /* send RP-ACK for RP-DATA */ |
| 1808 | rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref); |
| 1809 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo)); |
| 1810 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1811 | |
| 1812 | /* expect CP-ACK for CP-DATA(RP-ACK) just sent */ |
Harald Welte | e008eea | 2018-04-14 21:05:48 +0200 | [diff] [blame] | 1813 | l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT); |
Harald Welte | f45efeb | 2018-04-09 18:19:24 +0200 | [diff] [blame] | 1814 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)); |
| 1815 | |
| 1816 | deactivate(d); |
| 1817 | setverdict(pass); |
| 1818 | } |
| 1819 | |
Vadim Yanitskiy | 5631852 | 2018-11-24 03:40:47 +0700 | [diff] [blame] | 1820 | /* Send RP-ERROR for MT-SMS over an already existing DTAP connection */ |
| 1821 | function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause) |
| 1822 | runs on BSC_ConnHdlr { |
| 1823 | var template (value) RPDU_MS_SGSN rp_mo; |
| 1824 | var template (value) PDU_ML3_MS_NW l3_mo; |
| 1825 | var template PDU_ML3_NW_MS l3_mt; |
| 1826 | |
| 1827 | var default d := activate(as_other_sms()); |
| 1828 | |
| 1829 | /* send RP-ACK for RP-DATA */ |
| 1830 | rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause); |
| 1831 | l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo)); |
| 1832 | BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true)); |
| 1833 | |
| 1834 | /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */ |
| 1835 | l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT); |
| 1836 | BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)); |
| 1837 | |
| 1838 | deactivate(d); |
| 1839 | setverdict(pass); |
| 1840 | } |
| 1841 | |
Vadim Yanitskiy | 2159acb | 2018-11-24 02:50:29 +0700 | [diff] [blame] | 1842 | /* Wait for a MT-SMS and send RP-ACK over an already existing |
| 1843 | * (and authenticated, ...) DTAP connection */ |
| 1844 | function f_mt_sms(inout SmsParameters spars) |
| 1845 | runs on BSC_ConnHdlr { |
| 1846 | f_mt_sms_expect(spars); |
| 1847 | f_mt_sms_send_rp_ack(spars); |
| 1848 | } |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 1849 | |
| 1850 | |
Harald Welte | a49e36e | 2018-01-21 19:29:33 +0100 | [diff] [blame] | 1851 | } |