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