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