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