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