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