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