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