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