blob: 056a3c0080212b35d8ef8e400785cc856e282c39 [file] [log] [blame]
Harald Welte34b5a952019-05-27 11:54:11 +02001/* 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 Weltea49e36e2018-01-21 19:29:33 +010013module BSC_ConnectionHandler {
14
Eric Wild26f4a622021-05-17 15:27:05 +020015import from TCCOpenSecurity_Functions all;
Harald Weltea49e36e2018-01-21 19:29:33 +010016import from General_Types all;
17import from Osmocom_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010018import from Native_Functions all;
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +020019import from Misc_Helpers all;
Harald Weltea49e36e2018-01-21 19:29:33 +010020import from GSM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010021import from IPL4asp_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010022import from SCCPasp_Types all;
23import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020024import from RAN_Emulation all;
Harald Weltea49e36e2018-01-21 19:29:33 +010025import from BSSMAP_Templates all;
26
Harald Welte9b751a62019-04-14 17:39:29 +020027import from RANAP_Constants all;
28import from RANAP_IEs all;
29import from RANAP_PDU_Contents all;
30import from RANAP_PDU_Descriptions all;
31import from RANAP_Templates all;
32
Harald Weltea49e36e2018-01-21 19:29:33 +010033import from GSUP_Types all;
Pau Espin Pedrol8f1403a2024-01-18 20:08:43 +010034import from GSUP_Templates all;
Harald Weltea49e36e2018-01-21 19:29:33 +010035import from GSUP_Emulation all;
36
37import from MNCC_Types all;
38import from MNCC_Emulation all;
39
Harald Welte4aa970c2018-01-26 10:38:09 +010040import from MGCP_Types all;
41import from MGCP_Emulation all;
Harald Welteb71901a2018-01-26 19:16:05 +010042import from MGCP_Templates all;
43import from SDP_Types all;
Pau Espin Pedrol1158cc62024-03-21 17:21:35 +010044import from SDP_Templates all;
Harald Welte4aa970c2018-01-26 10:38:09 +010045
Harald Weltea49e36e2018-01-21 19:29:33 +010046import from MobileL3_Types all;
47import from MobileL3_CommonIE_Types all;
48import from MobileL3_MM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010049import from MobileL3_CC_Types all;
Harald Weltef45efeb2018-04-09 18:19:24 +020050import from MobileL3_SMS_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010051import from L3_Templates all;
Harald Welte158a7ca2018-02-16 18:11:31 +010052import from L3_Common all;
Harald Weltea49e36e2018-01-21 19:29:33 +010053
Harald Weltef640a012018-04-14 17:49:21 +020054import from SMPP_Emulation all;
55
Philipp Maieraeb29a82018-11-08 17:40:53 +010056import from IPA_Emulation all;
57import from Osmocom_CTRL_Functions all;
58import from Osmocom_CTRL_Types all;
59import from Osmocom_CTRL_Adapter all;
60
Philipp Maierc39a9d82018-11-09 11:21:08 +010061import from TELNETasp_PortType all;
62import from Osmocom_VTY_Functions all;
63
Harald Welte4263c522018-12-06 11:56:27 +010064import from SGsAP_Emulation all;
65
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +020066import from TCCConversion_Functions { function f_strstr };
67
Neels Hofmeyrf797d292021-07-27 22:33:09 +020068type port BSC_ConnHdlr_Coord_PT message
69{
70 inout charstring, CallParameters;
71} with { extension "internal" };
72
73
Harald Weltea49e36e2018-01-21 19:29:33 +010074/* this component represents a single subscriber connection */
Harald Welte6811d102019-04-14 22:23:14 +020075type component BSC_ConnHdlr extends RAN_ConnHdlr, MNCC_ConnHdlr, GSUP_ConnHdlr, MGCP_ConnHdlr, SMPP_ConnHdlr, CTRL_Adapter_CT, SGsAP_ConnHdlr {
Harald Weltea49e36e2018-01-21 19:29:33 +010076 var BSC_ConnHdlrPars g_pars;
Harald Weltea10db902018-01-27 12:44:49 +010077 timer g_Tguard := 60.0;
Philipp Maierc39a9d82018-11-09 11:21:08 +010078 port TELNETasp_PT MSCVTY;
Neels Hofmeyrf797d292021-07-27 22:33:09 +020079 port BSC_ConnHdlr_Coord_PT COORD;
Harald Weltea49e36e2018-01-21 19:29:33 +010080}
81
Harald Weltede371492018-01-27 23:44:41 +010082type record BSC_ConnHdlrNetworkPars {
Neels Hofmeyre860fc42022-10-05 01:15:54 +020083 /* Bitmask of expected A5 levels; in Ciphering, will expect use of the highest A5 remaining after masking this
84 * with A5 supported by the MS */
Harald Weltede371492018-01-27 23:44:41 +010085 OCT1 kc_support,
Neels Hofmeyre860fc42022-10-05 01:15:54 +020086 /* osmo-msc VTY cfg under 'network': If a test wants to temporarily modify auth and encr config, this is the
87 * original config to return to for this test (is *not* sent to vty before the test, but maybe it should).
88 * For example: { "authentication optional", "encryption a5 0 3" } */
89 rof_charstring net_config,
90 /* expect_attach_success == true: expect Location Updating / CM Service Request to succeed.
91 * expect_attach_success == false: expect the MSC to reject LU / CM Service. */
92 boolean expect_attach_success,
93 /* expect_tmsi == true: expect MSC to allocate a new TMSI.
94 * expect_tmsi == false: expect no TMSI to be assigned, operate with IMSI Mobile Identity. */
Harald Weltede371492018-01-27 23:44:41 +010095 boolean expect_tmsi,
Neels Hofmeyre860fc42022-10-05 01:15:54 +020096 /* expect_auth == true overrides expect_auth_attempt == false */
97 boolean expect_auth_attempt,
98 /* hlr_has_auth_info has an effect only when (expect_auth_attempt or expect_auth) == true.
99 * hlr_has_auth_info == false means the HLR responds to Send Auth Info Request with a NACK. */
100 boolean hlr_has_auth_info,
Harald Weltede371492018-01-27 23:44:41 +0100101 boolean expect_auth,
Oliver Smith1d118ff2019-07-03 10:57:35 +0200102 boolean expect_ciph,
103 boolean expect_imei,
104 boolean expect_imei_early,
105 GSUP_IMEIResult check_imei_result,
106 boolean check_imei_error
Harald Weltede371492018-01-27 23:44:41 +0100107}
108
Harald Weltea49e36e2018-01-21 19:29:33 +0100109type record BSC_ConnHdlrPars {
110 SCCP_PAR_Address sccp_addr_own,
111 SCCP_PAR_Address sccp_addr_peer,
112 BSSMAP_IE_CellIdentifier cell_id,
Harald Welte256571e2018-01-24 18:47:19 +0100113 hexstring imei,
Harald Weltea49e36e2018-01-21 19:29:33 +0100114 hexstring imsi,
Harald Welte82600572018-01-21 20:54:08 +0100115 hexstring msisdn,
Harald Welte256571e2018-01-24 18:47:19 +0100116 OCT4 tmsi optional,
Harald Welte9de84792018-01-28 01:06:35 +0100117 MobileStationClassmark1_V cm1,
Harald Welte82600572018-01-21 20:54:08 +0100118 BSSMAP_IE_ClassmarkInformationType2 cm2,
Harald Welte16114282018-01-24 22:41:21 +0100119 BSSMAP_IE_ClassmarkInformationType3 cm3 optional,
Harald Weltede371492018-01-27 23:44:41 +0100120 AuthVector vec optional,
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +0200121 /* BSC_ConnectionHandler generates an auth vector in as_GSUP_SAI(). For tests that want control over which
122 * vector is used, pass vec_keep := true to not regenerate a new auth vector in as_GSUP_SAI(). */
123 boolean vec_keep,
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100124 BSC_ConnHdlrNetworkPars net,
Philipp Maieraeb29a82018-11-08 17:40:53 +0100125 boolean send_early_cm,
126 charstring ipa_ctrl_ip,
127 integer ipa_ctrl_port,
Philipp Maier9b690e42018-12-21 11:50:03 +0100128 boolean ipa_ctrl_enable,
Philipp Maier57865482019-01-07 18:33:13 +0100129 boolean mm_info,
Philipp Maierc09a1312019-04-09 16:05:26 +0200130 boolean sgsap_enable,
Harald Weltef9abf8d2019-04-21 13:07:17 +0200131 boolean gsup_enable,
Vadim Yanitskiy2dd96612020-01-07 21:48:29 +0100132 OCT4 gsup_sid,
Harald Weltec1f937a2019-04-21 21:19:23 +0200133 integer ran_idx,
Harald Welte9b751a62019-04-14 17:39:29 +0200134 boolean use_umts_aka,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200135 boolean ran_is_geran,
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200136 boolean use_osmux,
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200137 boolean use_ipv6,
Oliver Smith44424db2023-08-22 13:54:09 +0200138 boolean use_csd,
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200139 boolean verify_cell_id,
140 OCT3 common_id_last_eutran_plmn optional
Harald Weltea49e36e2018-01-21 19:29:33 +0100141};
142
Harald Welte9de84792018-01-28 01:06:35 +0100143/* get a one-octet bitmaks of supported algorithms based on Classmark information */
Eric Wild26f4a622021-05-17 15:27:05 +0200144function f_alg_mask_from_cm(BSSMAP_IE_ClassmarkInformationType2 cm2, template (omit) BSSMAP_IE_ClassmarkInformationType3 cm3 := omit) return OCT1 {
Harald Welte9de84792018-01-28 01:06:35 +0100145 var BIT8 res := '00000001'B; /* A5/0 always supported */
146
147 if (cm2.a5_1 == '0'B) {
148 res := res or4b '00000010'B;
149 }
150 if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) {
151 res := res or4b '00000100'B;
152 }
153 if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) {
154 res := res or4b '00001000'B;
155 }
Eric Wild26f4a622021-05-17 15:27:05 +0200156 if (not istemplatekind(cm3, "omit")) {
157 var BSSMAP_IE_ClassmarkInformationType3 v := valueof(cm3);
158 var BIT8 tmp := oct2bit(v.classmark3ValuePart[0]) and4b '00001111'B;
159 res := res or4b (tmp << 4);
160 }
161
Harald Welte9de84792018-01-28 01:06:35 +0100162 return bit2oct(res);
163}
164
165/* determine the best algorithm available within the bit-mask */
166function f_best_alg_from_mask(OCT1 alg_in) return OCT1 {
167 var BIT8 alg := oct2bit(alg_in);
168 var BIT8 ordered_algs[8] := {
169 '10000000'B, '01000000'B, '00100000'B, '00010000'B,
170 '00001000'B, /* A5/3 */
171 '00000010'B, /* A5/1 */
172 '00000100'B, /* A5/2 */
173 '00000001'B /* A5/0 */ }
174 for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) {
175 if (alg and4b ordered_algs[i] != '00000000'B) {
176 return bit2oct(ordered_algs[i]);
177 }
178 }
179 return '00'O;
180}
181
182/* return an integer like '1' for A5/1 based on a mask (with only one bit set */
183function f_alg_from_mask(OCT1 mask_in) return integer {
184 var BIT8 mask := oct2bit(mask_in);
185 for (var integer i := 0; i < 8; i := i+1) {
186 if (mask and4b ('00000001'B << i) != '00000000'B) {
187 return i;
188 }
189 }
190 return -1;
191}
192
Eric Wild26f4a622021-05-17 15:27:05 +0200193/* return true for A5/x supported by OCT1 bitmask */
194function f_alg_supported_by_mask(OCT1 mask_in, integer whicha5) return boolean {
195 var BIT8 mask := oct2bit(mask_in);
196 if (mask and4b ('00000001'B << whicha5) != '00000000'B) {
197 return true;
198 }
199 return false;
200}
201
Harald Weltea10db902018-01-27 12:44:49 +0100202/* altstep for the global guard timer */
203private altstep as_Tguard() runs on BSC_ConnHdlr {
204 [] g_Tguard.timeout {
Daniel Willmann90829d62018-02-15 17:45:14 +0100205 setverdict(fail, "Tguard timeout");
Daniel Willmannafce8662018-07-06 23:11:32 +0200206 mtc.stop;
Harald Weltea10db902018-01-27 12:44:49 +0100207 }
208}
209
210/* init function, called as first function in new BSC_ConnHdlr */
Harald Weltead2952e2018-01-27 14:12:46 +0100211function f_init_handler(BSC_ConnHdlrPars pars, float t_guard := 60.0) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100212 /* make parameters available via component variable */
213 g_pars := pars;
214 /* Start guard timer and activate it as default */
Harald Weltead2952e2018-01-27 14:12:46 +0100215 g_Tguard.start(t_guard);
Harald Weltea10db902018-01-27 12:44:49 +0100216 activate(as_Tguard());
Harald Weltef640a012018-04-14 17:49:21 +0200217 /* Route all SMPP messages for our MSISDN to us */
218 f_create_smpp_expect(hex2str(pars.msisdn));
Philipp Maier57865482019-01-07 18:33:13 +0100219
Harald Welte4263c522018-12-06 11:56:27 +0100220 /* Route all SGs message for our IMSI to us */
Philipp Maier57865482019-01-07 18:33:13 +0100221 if (g_pars.sgsap_enable == true) {
222 f_create_sgsap_expect(pars.imsi);
223 }
Philipp Maieraeb29a82018-11-08 17:40:53 +0100224
225 if (g_pars.ipa_ctrl_enable == true) {
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100226 f_ipa_ctrl_start_client(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port);
Philipp Maieraeb29a82018-11-08 17:40:53 +0100227 }
Philipp Maierc39a9d82018-11-09 11:21:08 +0100228
229 map(self:MSCVTY, system:MSCVTY);
230 f_vty_set_prompts(MSCVTY);
231 f_vty_transceive(MSCVTY, "enable");
Harald Weltea10db902018-01-27 12:44:49 +0100232}
233
Harald Weltea49e36e2018-01-21 19:29:33 +0100234
Harald Welte6811d102019-04-14 22:23:14 +0200235/* Callback function from general RAN_Emulation whenever a connectionless
Harald Weltea49e36e2018-01-21 19:29:33 +0100236 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
237private function BscUnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200238runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Weltea49e36e2018-01-21 19:29:33 +0100239 var template PDU_BSSAP resp := omit;
240
241 log("BSSMAP_BscUnitdataCallback");
242 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200243 if (match(bssap, tr_BSSMAP_Reset(g_ran_ops.use_osmux))){
Harald Weltea49e36e2018-01-21 19:29:33 +0100244 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200245 resp := ts_BSSMAP_ResetAck(g_ran_ops.use_osmux);
Harald Weltea49e36e2018-01-21 19:29:33 +0100246 }
247
248 /* FIXME: Handle paging, etc. */
249 return resp;
250}
251
Harald Welte9b751a62019-04-14 17:39:29 +0200252private function RncUnitdataCallback(RANAP_PDU ranap)
253runs on RAN_Emulation_CT return template RANAP_PDU {
254 var template RANAP_PDU resp := omit;
255
256 log("RANAP_RncUnitdataCallback");
257 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200258 if (match(ranap, tr_RANAP_Reset())) {
Harald Welte9b751a62019-04-14 17:39:29 +0200259 log("RANAP_RncUnitdataCallback: Responding to RESET with RESET-ACK");
260 var CN_DomainIndicator dom;
261 dom := ranap.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator;
262 resp := ts_RANAP_ResetAck(dom);
263 }
264
265 /* FIXME: Handle paging, etc. */
266 return resp;
267}
268
269
Harald Welte6811d102019-04-14 22:23:14 +0200270const RanOps BSC_RanOps := {
Harald Weltea49e36e2018-01-21 19:29:33 +0100271 /* Create call-back for inbound connections from MSC (hand-over) */
Harald Welte6811d102019-04-14 22:23:14 +0200272 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Weltea49e36e2018-01-21 19:29:33 +0100273 unitdata_cb := refers(BscUnitdataCallback),
Harald Welte9b751a62019-04-14 17:39:29 +0200274 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
275 ranap_unitdata_cb := refers(RncUnitdataCallback),
276 ps_domain := false,
Harald Weltea49e36e2018-01-21 19:29:33 +0100277 decode_dtap := true,
Harald Weltea4ca4462018-02-09 00:17:14 +0100278 role_ms := true,
Harald Welte2fce7882019-04-15 11:48:05 +0200279 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200280 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200281 use_osmux := false,
Eric Wild49888a62022-03-30 03:16:11 +0200282 bssap_reset_retries := 1,
Harald Weltea4ca4462018-02-09 00:17:14 +0100283 sccp_addr_local := omit,
284 sccp_addr_peer := omit
Harald Weltea49e36e2018-01-21 19:29:33 +0100285}
286
287
288private function MnccUnitdataCallback(MNCC_PDU mncc)
289runs on MNCC_Emulation_CT return template MNCC_PDU {
290 log("Ignoring MNCC", mncc);
291 return omit;
292}
293
294const MnccOps BCC_MnccOps := {
295 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
296 unitdata_cb := refers(MnccUnitdataCallback)
297}
298
299
300
Harald Welte6811d102019-04-14 22:23:14 +0200301/* Encode 'l3' and ask RAN_Emulation to create new connection with COMPL L3 INFO */
Harald Weltea49e36e2018-01-21 19:29:33 +0100302function f_bssap_compl_l3(PDU_ML3_MS_NW l3)
303runs on BSC_ConnHdlr {
304 log("Sending COMPL L3: ", l3);
305 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
306 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
307 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc))));
Harald Welte71b69332018-01-21 20:43:53 +0100308 alt {
Harald Welte6811d102019-04-14 22:23:14 +0200309 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
310 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte71b69332018-01-21 20:43:53 +0100311 setverdict(fail, "DISC.ind from SCCP");
Daniel Willmannafce8662018-07-06 23:11:32 +0200312 mtc.stop;
Harald Welte71b69332018-01-21 20:43:53 +0100313 }
314 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100315}
316
Harald Welte9b751a62019-04-14 17:39:29 +0200317/* generate Iu LAI from BSSAP CGI */
318private function f_IuLAI_from_BssmapCI(BSSMAP_IE_CellIdentifier ci) return LAI {
319 var LAI lai;
320 if (ischosen(ci.cellIdentification.cI_CGI)) {
321 lai.pLMNidentity := ci.cellIdentification.cI_CGI.mcc_mnc;
322 lai.lAC := ci.cellIdentification.cI_CGI.lac;
323 } else if (ischosen(ci.cellIdentification.cI_SAI)) {
324 lai.pLMNidentity := ci.cellIdentification.cI_SAI.mcc_mnc;
325 lai.lAC := ci.cellIdentification.cI_SAI.lac;
326 } else if (ischosen(ci.cellIdentification.ci_LAC_RNC_CI)) {
327 lai.pLMNidentity := ci.cellIdentification.ci_LAC_RNC_CI.mcc_mnc;
328 lai.lAC := ci.cellIdentification.ci_LAC_RNC_CI.lac;
329 } else {
330 mtc.stop;
331 }
332 lai.iE_Extensions := omit;
333 return lai;
334}
335
336/* like f_bssap_compl_l3() but for 3G */
337function f_ranap_initial_ue(PDU_ML3_MS_NW l3)
338runs on BSC_ConnHdlr {
339 log("Sending InitialUE: ", l3);
340 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
341 var RANAP_PDU ranap;
342 var LAI lai := f_IuLAI_from_BssmapCI(g_pars.cell_id);
343 var SAI sai := {
344 pLMNidentity := lai.pLMNidentity,
345 lAC := lai.lAC,
346 sAC := '0000'O, /* FIXME */
347 iE_Extensions := omit
348 };
349 var IuSignallingConnectionIdentifier sigc_id := int2bit(23, 24);
350 var GlobalRNC_ID grnc_id := {
351 pLMNidentity := lai.pLMNidentity,
352 rNC_ID := 2342 /* FIXME */
353 };
354
355 ranap := valueof(ts_RANAP_initialUE_CS(lai, sai, l3_enc, sigc_id, grnc_id));
356 BSSAP.send(ts_RANAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, ranap));
357 alt {
358 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
359 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
360 setverdict(fail, "DISC.ind from SCCP");
361 mtc.stop;
362 }
363 }
364}
365
Harald Weltedceacc72019-04-21 20:58:35 +0200366/* Send BSSMAP Complete L3 or RANAP Initial UE depending on 2G/3G RAN type */
367function f_cl3_or_initial_ue(PDU_ML3_MS_NW l3)
368runs on BSC_ConnHdlr {
369 if (g_pars.ran_is_geran) {
370 f_bssap_compl_l3(l3);
371 } else {
372 f_ranap_initial_ue(l3);
373 }
374}
375
Harald Welte081b19a2018-02-10 09:11:13 +0100376type enumerated EstablishType {
377 EST_TYPE_MO_CALL,
Harald Welte0bef21e2018-02-10 09:48:23 +0100378 EST_TYPE_EMERG_CALL,
Harald Weltef45efeb2018-04-09 18:19:24 +0200379 EST_TYPE_PAG_RESP,
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700380 EST_TYPE_MO_SMS,
Oliver Smith92b280c2023-04-20 13:13:23 +0200381 EST_TYPE_SS_ACT,
Andreas Eversberg5ada75d2023-07-27 16:24:38 +0200382 EST_TYPE_MO_CSD,
383 EST_TYPE_VGCS,
384 EST_TYPE_VBS
Harald Welte081b19a2018-02-10 09:11:13 +0100385};
386
Harald Weltea49e36e2018-01-21 19:29:33 +0100387/* helper function to fully establish a dedicated channel */
Harald Welteb9e86fa2018-04-09 18:18:31 +0200388function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL)
Harald Weltea49e36e2018-01-21 19:29:33 +0100389runs on BSC_ConnHdlr {
Harald Welte081b19a2018-02-10 09:11:13 +0100390 var PDU_ML3_MS_NW l3_info;
Harald Welteb9e86fa2018-04-09 18:18:31 +0200391 var MobileIdentityLV mi;
392
393 /* If we have a TMSI, use TMSI instead of IMSI */
394 if (ispresent(g_pars.tmsi)) {
395 mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi));
396 } else {
397 mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
398 }
399
Harald Welte081b19a2018-02-10 09:11:13 +0100400 select (etype) {
401 case (EST_TYPE_MO_CALL) {
402 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
403 }
Oliver Smith92b280c2023-04-20 13:13:23 +0200404 case (EST_TYPE_MO_CSD) {
405 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
406 }
Harald Welte0bef21e2018-02-10 09:48:23 +0100407 case (EST_TYPE_EMERG_CALL) {
408 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi));
409 }
Harald Welte081b19a2018-02-10 09:11:13 +0100410 case (EST_TYPE_PAG_RESP) {
411 l3_info := valueof(ts_PAG_RESP(mi));
412 }
Harald Weltef45efeb2018-04-09 18:19:24 +0200413 case (EST_TYPE_MO_SMS) {
414 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi));
415 }
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700416 case (EST_TYPE_SS_ACT) {
417 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi));
418 }
Andreas Eversberg5ada75d2023-07-27 16:24:38 +0200419 case (EST_TYPE_VGCS) {
420 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_VGCS, mi));
421 }
422 case (EST_TYPE_VBS) {
423 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_VBS, mi));
424 }
Harald Welte081b19a2018-02-10 09:11:13 +0100425 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100426
427 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Weltedceacc72019-04-21 20:58:35 +0200428 f_cl3_or_initial_ue(l3_info);
Harald Weltea49e36e2018-01-21 19:29:33 +0100429
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200430 f_verify_vty_lac_ci(verify_vlr := false);
431
Harald Weltede371492018-01-27 23:44:41 +0100432 f_mm_common();
Pau Espin Pedrolf8034482019-06-03 13:15:58 +0200433 if (g_pars.net.expect_ciph or not g_pars.ran_is_geran) {
Harald Welte148a7082018-01-26 18:56:43 +0100434 /* implicit CM SERVICE ACCEPT? */
435 } else {
Harald Welte0bef21e2018-02-10 09:48:23 +0100436 if (etype != EST_TYPE_PAG_RESP) {
Harald Welte081b19a2018-02-10 09:11:13 +0100437 /* explicit CM SERVICE ACCEPT */
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200438 if (g_pars.net.expect_attach_success) {
439 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
440 } else {
441 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_REJ));
442 }
Harald Welte081b19a2018-02-10 09:11:13 +0100443 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100444 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100445}
446
447/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
Harald Welte9de84792018-01-28 01:06:35 +0100448function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100449{
450 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
451 return f_build_lu(mi);
452}
Harald Welte9de84792018-01-28 01:06:35 +0100453function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100454{
455 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
456 return f_build_lu(mi);
457}
Harald Welte9de84792018-01-28 01:06:35 +0100458function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100459{
460 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
461 return f_build_lu(mi);
462}
Harald Welte9de84792018-01-28 01:06:35 +0100463private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100464{
465 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
466 var PDU_ML3_MS_NW l3_info := valueof(ts_ML3_MO_LU_Req(valueof(ts_ML3_IE_LuType_Attach),
Harald Welte9de84792018-01-28 01:06:35 +0100467 old_lai, mi, g_pars.cm1));
Harald Weltea49e36e2018-01-21 19:29:33 +0100468 return l3_info;
469}
470
Harald Weltea183a5d2019-05-09 13:40:52 +0200471altstep as_GSUP_SAI() runs on BSC_ConnHdlr {
472var GSUP_IE auth_tuple;
473[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)) {
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200474 if (g_pars.net.hlr_has_auth_info) {
475 if (g_pars.use_umts_aka) {
476 if (not g_pars.vec_keep) {
477 g_pars.vec := f_gen_auth_vec_3g();
478 }
479 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand,
480 g_pars.vec.sres,
481 g_pars.vec.kc,
482 g_pars.vec.ik,
483 g_pars.vec.ck,
484 g_pars.vec.autn,
485 g_pars.vec.res));
486 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
487 } else {
488 if (not g_pars.vec_keep) {
489 g_pars.vec := f_gen_auth_vec_2g();
490 }
491 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand,
492 g_pars.vec.sres,
493 g_pars.vec.kc));
494 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +0200495 }
Harald Weltea183a5d2019-05-09 13:40:52 +0200496 } else {
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200497 log("XXX ts_GSUP_SAI_ERR");
498 /* HLR knows the IMSI but has no authentication info; osmo-hlr responds with GMM_CAUSE_IMSI_UNKNOWN=2 in
499 * this case, for SAI this merely means there is no auth entry for this IMSI. */
500 GSUP.send(ts_GSUP_SAI_ERR(g_pars.imsi, 2));
Harald Weltea183a5d2019-05-09 13:40:52 +0200501 }
502 }
503}
504
Harald Welte9de84792018-01-28 01:06:35 +0100505function f_mm_auth() runs on BSC_ConnHdlr
Harald Welte148a7082018-01-26 18:56:43 +0100506{
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200507 if (g_pars.net.expect_auth or g_pars.net.expect_auth_attempt) {
Harald Weltea183a5d2019-05-09 13:40:52 +0200508 as_GSUP_SAI();
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200509 }
510 if (g_pars.net.expect_auth) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200511 if (g_pars.use_umts_aka) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200512 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn)));
513 var OCT4 res := substr(g_pars.vec.res, 0, 4);
514 var OCT4 xres := substr(g_pars.vec.res, 4, 4);
515 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres)));
516 } else {
Harald Weltec1f937a2019-04-21 21:19:23 +0200517 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand)));
518 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres)));
519 }
Harald Welte148a7082018-01-26 18:56:43 +0100520 }
Harald Welte9de84792018-01-28 01:06:35 +0100521}
Harald Welte148a7082018-01-26 18:56:43 +0100522
Oliver Smith1d118ff2019-07-03 10:57:35 +0200523function f_mm_imei() runs on BSC_ConnHdlr
524{
525 var PDU_DTAP_MT dtap_mt;
526 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700527 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200528
529 if (not g_pars.net.expect_imei) {
530 return
531 }
532
533 /* MSC <-> BSC: ID req/rsp for IMEI */
534 alt {
535 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEI))) {
536 mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
537 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
538 }
539 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
540 setverdict(fail, "Expected ID REQ for IMEI DTAP MT message, but got: ", dtap_mt);
541 mtc.stop;
542 }
543 }
544
545 /* MSC <-> HLR: Check IMEI req/res/err */
546 alt {
547 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
548 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
549 }
550 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
551 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
552 }
553 [] GSUP.receive(?) -> value gsup_msg {
554 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
555 g_pars.imsi, "), but got: ", gsup_msg);
556 mtc.stop;
557 }
558 }
559}
560
561function f_mm_imei_early() runs on BSC_ConnHdlr
562{
563 var PDU_DTAP_MT dtap_mt;
564 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700565 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200566
567 if (not g_pars.net.expect_imei_early) {
568 return
569 }
570
571 /* MSC <-> BSC: ID req/rsp for IMEISV */
572 alt {
573 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEISV))) {
574 mi := valueof(ts_MI_IMEISV_LV(g_pars.imei));
575 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
576 }
577 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
578 setverdict(fail, "Expected ID REQ for IMEISV DTAP MT message, but got: ", dtap_mt);
579 mtc.stop;
580 }
581 }
582
583 /* MSC <-> HLR: Check IMEI req/res/err */
584 alt {
585 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
586 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
587 }
588 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
589 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
590 }
591 [] GSUP.receive(?) -> value gsup_msg {
592 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
593 g_pars.imsi, "), but got: ", gsup_msg);
594 mtc.stop;
595 }
596 }
597}
598
Harald Welte79f1e452020-08-18 22:55:02 +0200599function f_expect_common_id() runs on BSC_ConnHdlr
600{
601 if (g_pars.ran_is_geran) {
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200602 BSSAP.receive(tr_BSSMAP_CommonId(g_pars.imsi,
603 f_tr_BSSMAP_LastUsedEUTRANPLMNId(g_pars.common_id_last_eutran_plmn)));
Harald Welte79f1e452020-08-18 22:55:02 +0200604 } else {
605 BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
606 }
607}
608
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200609/* For UMTS AKA on GERAN, calculate the specific kc from the UMTS AKA ck and ik vectors. */
610function f_auth3g_kc(AuthVector vec) return OCT8 {
Eric Wild26f4a622021-05-17 15:27:05 +0200611 var integer i;
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200612 var octetstring res := vec.ck[0] xor4b vec.ck[0 + 8] xor4b vec.ik[0] xor4b vec.ik[0 + 8];
Eric Wild26f4a622021-05-17 15:27:05 +0200613 for (i := 1; i < 8; i := i + 1) {
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200614 var octetstring a := vec.ck[i] xor4b vec.ck[i + 8] xor4b vec.ik[i] xor4b vec.ik[i + 8];
Eric Wild26f4a622021-05-17 15:27:05 +0200615 res := res & a;
616 }
617
618 return res;
619}
620
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200621function f_get_expected_encryption(
622 out template BSSMAP_IE_EncryptionInformation encryptionInformation,
623 out template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm,
624 out template BSSMAP_IE_KC128 kC128,
625 out OCT1 a5_perm_alg) runs on BSC_ConnHdlr
626{
627 var OCT1 a5_ms := f_alg_mask_from_cm(g_pars.cm2, g_pars.cm3);
628 a5_perm_alg := g_pars.net.kc_support and4b a5_ms;
629
630 if (not g_pars.net.expect_ciph) {
631 encryptionInformation := *;
632 chosenEncryptionAlgorithm := *;
633 kC128 := *;
634 return;
635 }
636
Neels Hofmeyrf6eff812021-06-23 23:29:39 +0200637 var OCT8 kc;
638 if (g_pars.use_umts_aka) {
639 kc := f_auth3g_kc(g_pars.vec);
640 } else {
641 kc := g_pars.vec.kc;
642 }
643 encryptionInformation := tr_BSSMAP_IE_EncrInfo(kc, a5_perm_alg);
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200644
645 var OCT1 chosen_alg := int2oct(f_alg_from_mask(f_best_alg_from_mask(a5_perm_alg)) + 1, 1);
646 chosenEncryptionAlgorithm := tr_BSSMAP_IE_ChosenEncryptionAlgorithm(chosen_alg);
647
648 if (g_pars.use_umts_aka and f_alg_supported_by_mask(a5_perm_alg, 4)) {
649 /* A5/4 is permitted, expecting kc128 to be present */
650 var OCT32 full_sha256 := f_calculate_HMAC_SHA256(g_pars.vec.ck & g_pars.vec.ik, '32'O, 32);
651 var OCT16 expect_kc128 := substr(full_sha256, 0, 16);
652 kC128 := tr_BSSMAP_IE_Kc128(expect_kc128);
653 } else {
654 kC128 := omit
655 }
656}
657
Eric Wild26f4a622021-05-17 15:27:05 +0200658
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300659private function f_mm_ciph_geran() runs on BSC_ConnHdlr
660{
661 var template BSSMAP_IE_EncryptionInformation encryptionInformation;
662 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm;
663 var template BSSMAP_IE_KC128 kC128;
664 var OCT1 a5_perm_alg;
665 var PDU_BSSAP pdu;
666
Vadim Yanitskiy172bc6e2021-12-06 17:54:57 +0300667 if (not g_pars.net.expect_ciph) {
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300668 /* There is nothing to do */
669 return;
670 }
671
672 f_get_expected_encryption(encryptionInformation, chosenEncryptionAlgorithm, kC128, a5_perm_alg);
673 alt {
674 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128)) -> value pdu {
675 var OCT1 a5_chosen := f_best_alg_from_mask(a5_perm_alg);
676 var integer a5_nr := f_alg_from_mask(a5_chosen);
677 BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
678 }
679 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2) -> value pdu {
680 log("Error: Ciphering Mode Command with unexpected content. Expected: ",
681 tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128), " got: ", pdu);
682 setverdict(fail, "Ciphering Mode Command with unexpected content.");
683 mtc.stop;
684 }
685 [] BSSAP.receive(tr_BSSMAP_ClassmarkRequest) {
686 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3))
687 repeat;
688 }
689 }
690 /* FIXME: Send the best available algorithm */
691}
692
693private function f_mm_ciph_utran() runs on BSC_ConnHdlr
694{
695 alt {
696 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
697 uia_key := oct2bit(g_pars.vec.ik),
698 key_sts := ?,
699 uea_algs := ?,
700 uea_key := oct2bit(g_pars.vec.ck))) {
701 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/
702 var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/
703 BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen));
704 }
705 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
706 setverdict(fail, "Invalid SecurityModeCommand (ciphering case)");
707 mtc.stop;
708 }
709 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
710 uia_key := oct2bit(g_pars.vec.ik),
711 key_sts := ?)) {
712 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/
713 BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
714 }
715 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
716 setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)");
717 mtc.stop;
718 }
719 }
720}
721
Harald Welte9de84792018-01-28 01:06:35 +0100722function f_mm_common() runs on BSC_ConnHdlr
723{
724 f_mm_auth();
Eric Wild26f4a622021-05-17 15:27:05 +0200725
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300726 if (g_pars.ran_is_geran) {
727 f_mm_ciph_geran();
728 } else {
729 f_mm_ciph_utran();
Harald Welte148a7082018-01-26 18:56:43 +0100730 }
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300731
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200732 if (not g_pars.net.expect_attach_success) {
733 return;
734 }
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300735 f_expect_common_id();
Harald Welte148a7082018-01-26 18:56:43 +0100736}
737
Philipp Maier9b690e42018-12-21 11:50:03 +0100738function f_expect_mm_info() runs on BSC_ConnHdlr {
739 if (g_pars.mm_info == true) {
740 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info));
741 }
742}
743
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200744private function f_lac_ci_vty_str(BSSMAP_IE_CellIdentifier cell_id) return charstring
745{
746 return "LAC / cell ID: "
747 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.lac)) & " / "
748 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.ci));
749}
750
751/* Get an IMSI's info and verify that the g_pars.cell_id is reflected in the info.
752 * Verify both the "LAC / cell ID" in the VLR and the "LAC / cell ID" in the "Connection:" part, if any.
753 * If verify_vlr == false, then only verify the "Connection:" part, and fail if there is no "Connection:"; this is
754 * useful when a conn has been established, but the subscriber has not been authenticated, so the VLR does not yet
755 * reflect the new conn's cell ID.
756 */
757function f_verify_vty_lac_ci(boolean verify_vlr := true) runs on BSC_ConnHdlr {
758 if (not g_pars.ran_is_geran) {
759 log("Skipping f_verify_vty_lac_ci(), disabled for Iu");
760 setverdict(pass);
761 return;
762 }
763 if (not g_pars.verify_cell_id) {
764 /* Skip this verification; either the TC expects no cell id to end up being accepted, or this was
765 * disabled globally to test an older osmo-msc which doesn't store the cell id properly yet. */
766 log("Skipping f_verify_vty_lac_ci()");
767 setverdict(pass);
768 return;
769 }
770
771 var charstring vty_cmd := "show subscriber imsi " & hex2str(g_pars.imsi) & " conn";
772 var charstring result := f_vty_transceive_ret(MSCVTY, vty_cmd);
773 var charstring expect_lac_ci := "LAC / cell ID: "
774 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.lac)) & " / "
775 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.ci));
776
777 var boolean vlr_matches := false;
778 var boolean connection_present := false;
779 var boolean connection_matches := false;
780
781 /* There are two occurences of LAC / cell ID: once for the VLR record, and once for the active connection. The
782 * active connection part starts with 'Connection:'. If there is no active connection, that part is omitted.
783 * So, first find out whether there is a 'Connection:' part. Then verify the LAC / cell ID above 'Connection:'
784 * and below 'Connection:', separately.
785 */
786 var integer connection_start := f_strstr(result, "Connection:");
787 connection_present := (connection_start >= 0);
788
789 var integer lac_ci_match := f_strstr(result, expect_lac_ci);
790 if (connection_present) {
791 if (lac_ci_match > connection_start) {
792 /* The first match is below 'Connection:', so the VLR part above it did not match. */
793 vlr_matches := false;
794 connection_matches := true;
795 } else if (lac_ci_match >= 0) {
796 /* The first match is above 'Connection:', so the VLR part matches. */
797 vlr_matches := true;
798
799 /* Now find a match below 'Connection:' */
800 lac_ci_match := f_strstr(result, expect_lac_ci, connection_start);
801 connection_matches := (lac_ci_match > 0);
802 }
803 } else {
804 /* There is no 'Connection:', so a match, if any, is from the VLR part. */
805 vlr_matches := (lac_ci_match >= 0);
806 }
807
808 if (verify_vlr) {
809 if (not vlr_matches) {
810 setverdict(fail, vty_cmd, " shows mismatching LAC / cell ID in the VLR part, expecting: ",
811 expect_lac_ci, " -- got: ", result);
812 return;
813 } else {
814 log("f_verify_vty_lac_ci(): VLR record matches ", expect_lac_ci);
815 setverdict(pass);
816 }
817 }
818
819 if (connection_present) {
820 if (not connection_matches) {
821 setverdict(fail, vty_cmd, " shows mismatching LAC cell ID in the 'Connection' part, expecting: ",
822 expect_lac_ci, " -- got: ", result);
823 } else {
824 log("f_verify_vty_lac_ci(): Active connection matches ", expect_lac_ci);
825 setverdict(pass);
826 }
827 }
828
829 if (not verify_vlr and not connection_present) {
Neels Hofmeyra250d7e2024-03-26 03:51:59 +0100830 /* If the Compl L3 was done by TMSI, the VLR has no IMSI until the ID Request / Response for IMSI has
831 * been answered. So if verify_vlr == false, a "missing" connection is one of the expected scenarios. */
832 setverdict(pass);
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200833 }
834}
835
Vadim Yanitskiy8d0d7af2024-05-10 15:14:43 +0200836function f_perform_lu(template (omit) MobileIdentityLV use_mi := omit,
837 boolean expect_clear := true)
Harald Weltea49e36e2018-01-21 19:29:33 +0100838runs on BSC_ConnHdlr {
Neels Hofmeyr392de2d2024-03-25 04:21:48 +0100839 var MobileIdentityLV mi;
840 if (istemplatekind(use_mi, "omit")) {
841 mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
842 } else {
843 mi := valueof(use_mi);
844 }
845 var PDU_ML3_MS_NW l3_lu := f_build_lu(mi);
Harald Weltea49e36e2018-01-21 19:29:33 +0100846 var PDU_DTAP_MT dtap_mt;
847
848 /* tell GSUP dispatcher to send this IMSI to us */
849 f_create_gsup_expect(hex2str(g_pars.imsi));
850
851 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Welte9b751a62019-04-14 17:39:29 +0200852 if (g_pars.ran_is_geran) {
853 f_bssap_compl_l3(l3_lu);
854 if (g_pars.send_early_cm) {
855 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
856 }
857 } else {
858 f_ranap_initial_ue(l3_lu);
Harald Welte8a121b32018-01-22 03:00:41 +0100859 }
Harald Welte5c2622c2018-01-21 20:45:20 +0100860
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200861 /* at this point the conn has been established, but the subscriber has not been authenticated, so the VLR does
862 * not yet reflect this conn's cell ID. */
863 f_verify_vty_lac_ci(verify_vlr := false);
864
Oliver Smith1d118ff2019-07-03 10:57:35 +0200865 f_mm_imei_early();
Harald Weltede371492018-01-27 23:44:41 +0100866 f_mm_common();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100867 f_msc_lu_hlr();
Oliver Smith1d118ff2019-07-03 10:57:35 +0200868 f_mm_imei();
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200869 as_accept_reject_lu(g_pars.net.expect_attach_success);
Vadim Yanitskiy8d0d7af2024-05-10 15:14:43 +0200870
871 /* there could be pending SMS or other common procedures by the MSC */
872 if (expect_clear) {
873 f_expect_clear(verify_vlr_cell_id := g_pars.net.expect_attach_success);
874 }
Harald Welte16114282018-01-24 22:41:21 +0100875
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100876 setverdict(pass);
877}
878
879function f_msc_lu_hlr() runs on BSC_ConnHdlr
880{
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200881 if (not g_pars.net.expect_attach_success) {
882 return;
883 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100884 /* Expect MSC to perform LU with HLR */
885 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
886 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
887 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
888 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100889}
890
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200891altstep as_accept_reject_lu(boolean expect_accept := true) runs on BSC_ConnHdlr {
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100892 var PDU_DTAP_MT dtap_mt;
Harald Weltea49e36e2018-01-21 19:29:33 +0100893
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200894 [expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
Harald Weltea49e36e2018-01-21 19:29:33 +0100895 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
Harald Weltede371492018-01-27 23:44:41 +0100896 if (g_pars.net.expect_tmsi) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100897 if (not ispresent(lu_acc.mobileIdentityTLV) or
898 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
899 setverdict(fail, "Expected TMSI but no TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200900 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100901 } else {
Harald Welte256571e2018-01-24 18:47:19 +0100902 g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets;
Harald Weltea49e36e2018-01-21 19:29:33 +0100903 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
904 }
905 } else {
906 if (ispresent(lu_acc.mobileIdentityTLV) and
907 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
908 setverdict(fail, "Expected no TMSI but TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200909 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100910 }
911 }
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200912
913 /* Wait for MM-Information (if enabled) */
914 f_expect_mm_info();
915 setverdict(pass);
916 }
917 [expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100918 setverdict(fail, "Expected LU ACK, but received LU REJ");
Daniel Willmannafce8662018-07-06 23:11:32 +0200919 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100920 }
Philipp Maier9b690e42018-12-21 11:50:03 +0100921
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200922 [not expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
923 setverdict(pass);
924 }
925 [not expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
926 setverdict(fail, "Expected LU REJ, but received LU ACK");
927 mtc.stop;
928 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100929}
930
Vadim Yanitskiy3c88c352024-04-02 21:21:51 +0700931function f_expect_lu_reject(template OCT1 cause := ?, float Tval := 5.0) runs on BSC_ConnHdlr {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200932 var PDU_DTAP_MT dtap_mt;
Vadim Yanitskiy3c88c352024-04-02 21:21:51 +0700933 timer T;
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200934
Vadim Yanitskiy3c88c352024-04-02 21:21:51 +0700935 T.start(Tval);
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200936 alt {
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100937 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej(cause))) {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200938 setverdict(pass);
939 }
940 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
941 setverdict(fail, "Expected LU reject BSSAP message, got: ", dtap_mt);
942 }
943 [] T.timeout {
944 setverdict(fail, "Timeout waiting for LU reject");
945 }
946 }
947}
948
Harald Weltea49e36e2018-01-21 19:29:33 +0100949function f_foo() runs on BSC_ConnHdlr{
Harald Welte6811d102019-04-14 22:23:14 +0200950 /* SCCP CC handled by RAN_Emulation_CT.main() */
Harald Weltea49e36e2018-01-21 19:29:33 +0100951 /* Expect auth, if enabled */
952
953 /* TODO: ISD */
954 /* Expect encr, if enabled */
955 /* Expect encr, if enabled */
956 /* Expect ASS CMD, if chan_type != requested */
957 /* Send ASS CMPL in successful case */
958
959 /* Expect AoIP port/ip information for RTP stream */
960 /* Expect MSC-originated MGCP to our simulated MGW */
961 /* Verify Counters via CTRL */
962 /* re-configure MSC behaviour via VTY */
963}
964
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200965type record CrcxResponse {
966 integer resp, /* 1 = reply with OK, 0 = do not reply, -1 = reply with error */
967 HostName mgw_rtp_ip,
968 PortNumber mgw_rtp_port,
969 MgcpConnectionId mgcp_connection_id /* MGCP Connection ID BSS Side */
970}
971
Harald Welteb71901a2018-01-26 19:16:05 +0100972/* parameters related to a (MO?) voice call */
973type record CallParameters {
Harald Welteb71901a2018-01-26 19:16:05 +0100974 /* CC related parameters */
975 hexstring called_party, /* whom are we calling */
976 integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100977 boolean mo_call, /* For a MO call, the transaction_id was allocated by the MS,
978 important to set the TI flag properly */
Harald Welteb71901a2018-01-26 19:16:05 +0100979 BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */
Harald Welte0bef21e2018-02-10 09:48:23 +0100980 boolean emergency, /* is this an emergency call? */
Oliver Smith92b280c2023-04-20 13:13:23 +0200981 boolean csd, /* is this a circuit switched data call? */
Harald Welteb71901a2018-01-26 19:16:05 +0100982
983 /* MNCC related parameters */
984 uint32_t mncc_callref optional, /* call reference on the MNCC side */
985 MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200986 HostName mncc_rtp_ip optional, /* MNCC Side RTP IP */
987 PortNumber mncc_rtp_port optional, /* MNCC Side RTP port */
Harald Welteb71901a2018-01-26 19:16:05 +0100988
989 /* RTP related parameters */
990 HostName bss_rtp_ip optional, /* BSS Side RTP IP */
991 PortNumber bss_rtp_port optional, /* BSS Side RTP Port */
992 HostName mss_rtp_ip optional, /* MSS Side RTP IP */
993 PortNumber mss_rtp_port optional, /* MSS Side RTP Port */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200994 integer got_crcx_count,
995 CrcxResponse mgw_conn_1,
996 CrcxResponse mgw_conn_2,
Harald Welteb71901a2018-01-26 19:16:05 +0100997 uint7_t rtp_payload_type, /* dynamic RTP payload type */
998 charstring rtp_sdp_format, /* AMR/8000 or the like */
Philipp Maier2a98a732018-03-19 16:06:12 +0100999 boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX
1000 (f_mt_call and f_mt_call) */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001001 boolean stop_after_cc_setup, /* Special case: stop call establish after CC Setup */
1002 boolean ran_clear_when_alerting, /* Special case: send Clear upon CC Alerting */
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001003 boolean expect_release, /* Special case: expect call establish to cause direct CC Rel */
Harald Welteb71901a2018-01-26 19:16:05 +01001004
Philipp Maiercd668572018-03-19 16:11:52 +01001005 MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */
Harald Welteb71901a2018-01-26 19:16:05 +01001006 MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001007
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001008 boolean use_osmux, /* MSC is expected to use Osmux for this call */
1009 integer got_osmux_count
Harald Welteb71901a2018-01-26 19:16:05 +01001010}
1011
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001012template (value) CallParameters t_CallParams(hexstring called := '12345'H, integer tid := 0) := {
Harald Welteb71901a2018-01-26 19:16:05 +01001013 called_party := called,
1014 transaction_id := tid,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001015 mo_call := false,
Harald Welteb71901a2018-01-26 19:16:05 +01001016 bearer_cap := valueof(ts_Bcap_voice),
Harald Welte0bef21e2018-02-10 09:48:23 +01001017 emergency := false,
Oliver Smithf89620d2023-06-21 18:21:25 +02001018 csd := false,
Harald Welteb71901a2018-01-26 19:16:05 +01001019 mncc_callref := omit,
1020 mncc_bearer_cap := valueof(ts_MNCC_bcap_voice),
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001021 mncc_rtp_ip := "42.23.11.5",
1022 mncc_rtp_port := 423,
Harald Welte4017d552018-01-26 21:40:05 +01001023 bss_rtp_ip := "9.8.7.6",
1024 bss_rtp_port := 9000,
Harald Welteb71901a2018-01-26 19:16:05 +01001025 mss_rtp_ip := omit,
1026 mss_rtp_port := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001027 got_crcx_count := 0,
1028 mgw_conn_1 := {
1029 resp := 1,
1030 mgw_rtp_ip := "1.1.1.1",
1031 mgw_rtp_port := 10000,
1032 mgcp_connection_id := '11111'H
1033 },
1034 mgw_conn_2 := {
1035 resp := 1,
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001036 mgw_rtp_ip := "2.2.2.2",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001037 mgw_rtp_port := 11000,
1038 mgcp_connection_id := '22222'H
1039 },
Harald Welteb71901a2018-01-26 19:16:05 +01001040 rtp_payload_type := 98,
1041 rtp_sdp_format := "AMR/8000",
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001042 mgw_drop_dlcx := false,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001043 stop_after_cc_setup := false,
1044 ran_clear_when_alerting := false,
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001045 expect_release := false,
Harald Welteb71901a2018-01-26 19:16:05 +01001046 mgcp_call_id := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001047 mgcp_ep := "rtpbridge/1@mgw",
1048 use_osmux := false,
1049 got_osmux_count := 0
Harald Welteb71901a2018-01-26 19:16:05 +01001050};
1051
Neels Hofmeyrf797d292021-07-27 22:33:09 +02001052template CallParameters tr_CallParams := {
1053 called_party := ?,
1054 transaction_id := ?,
1055 mo_call := ?,
1056 bearer_cap := ?,
1057 emergency := ?,
Oliver Smithf89620d2023-06-21 18:21:25 +02001058 csd := ?,
Neels Hofmeyrf797d292021-07-27 22:33:09 +02001059 mncc_callref := *,
1060 mncc_bearer_cap := ?,
1061 mncc_rtp_ip := ?,
1062 mncc_rtp_port := ?,
1063 bss_rtp_ip := ?,
1064 bss_rtp_port := ?,
1065 mss_rtp_ip := *,
1066 mss_rtp_port := *,
1067 got_crcx_count := ?,
1068 mgw_conn_1 := ?,
1069 mgw_conn_2 := ?,
1070 rtp_payload_type := ?,
1071 rtp_sdp_format := ?,
1072 mgw_drop_dlcx := ?,
1073 stop_after_cc_setup := ?,
1074 ran_clear_when_alerting := ?,
1075 expect_release := ?,
1076 mgcp_call_id := *,
1077 mgcp_ep := ?,
1078 use_osmux := ?,
1079 got_osmux_count := ?
1080};
1081
Harald Welte4263c522018-12-06 11:56:27 +01001082/* Allocate a call reference and send SETUP via MNCC to MSC */
Oliver Smith97dc91f2023-05-31 13:53:21 +02001083function f_mt_call_initiate(inout CallParameters cpars)
Harald Welte33ec09b2018-02-10 15:34:46 +01001084runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001085 cpars.mo_call := false;
Harald Welte4263c522018-12-06 11:56:27 +01001086 cpars.mncc_callref := f_rnd_int(2147483648);
Oliver Smithc1dd36a2023-05-31 13:52:24 +02001087
Harald Welte4263c522018-12-06 11:56:27 +01001088 MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
Oliver Smith8cf75ab2023-06-21 16:19:51 +02001089 hex2str(cpars.called_party), hex2str(g_pars.imsi),
1090 cpars.mncc_bearer_cap));
Harald Welte4263c522018-12-06 11:56:27 +01001091}
Harald Welte33ec09b2018-02-10 15:34:46 +01001092
Harald Welte408a7ef2019-04-21 17:08:40 +02001093private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) :=
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001094 ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
Harald Welte408a7ef2019-04-21 17:08:40 +02001095 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001096 cpars.mgw_conn_2.mgw_rtp_port,
Harald Welte408a7ef2019-04-21 17:08:40 +02001097 { int2str(cpars.rtp_payload_type) },
1098 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1099 cpars.rtp_sdp_format)),
1100 valueof(ts_SDP_ptime(20)) });
1101
Harald Welte4263c522018-12-06 11:56:27 +01001102/* Complete call, begin with a paging response message via BSSAP */
1103function f_mt_call_complete(inout CallParameters cpars)
1104runs on BSC_ConnHdlr {
Harald Welte33ec09b2018-02-10 15:34:46 +01001105 var MNCC_PDU mncc;
1106 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001107 var template MgcpResponse mgcp_resp;
1108 var MgcpOsmuxCID osmux_cid;
1109 var PDU_BSSAP bssap;
Harald Welte33ec09b2018-02-10 15:34:46 +01001110
Harald Welte6811d102019-04-14 22:23:14 +02001111 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Welte33ec09b2018-02-10 15:34:46 +01001112
Harald Welteb9e86fa2018-04-09 18:18:31 +02001113 f_establish_fully(EST_TYPE_PAG_RESP);
Harald Welte33ec09b2018-02-10 15:34:46 +01001114
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001115 log("f_mt_call_complete 1");
1116
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001117 cpars.got_osmux_count := 0;
1118
Harald Welte33ec09b2018-02-10 15:34:46 +01001119 /* MS <- MSC: Expect CC SETUP */
1120 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party)));
1121
1122 /* MS -> MSC: ALERTING */
1123 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id)));
1124 MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001125 log("f_mt_call_complete 2");
Harald Welte33ec09b2018-02-10 15:34:46 +01001126
Harald Welte33ec09b2018-02-10 15:34:46 +01001127 /* Create MGCP expect */
1128 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1129 /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */
1130 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1131
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001132 /* First MGCP CRCX */
Harald Welte33ec09b2018-02-10 15:34:46 +01001133 MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001134 log("f_mt_call_complete 3");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001135 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1136 return;
Philipp Maier4b2692d2018-03-14 16:37:48 +01001137 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001138 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001139
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001140
Harald Welte9b751a62019-04-14 17:39:29 +02001141 if (g_pars.ran_is_geran) {
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001142 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass1 :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001143 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001144 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass2 :=
1145 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_2.mgw_rtp_ip, ?);
Harald Welte9b751a62019-04-14 17:39:29 +02001146
1147 interleave {
1148 /* Second MGCP CRCX (this time for MSS/CN side) */
1149 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001150 log("f_mt_call_complete 4");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001151 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1152 break;
1153 }
Harald Welte9b751a62019-04-14 17:39:29 +02001154 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001155
1156 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1157 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1158 log("f_mt_call_complete 5");
1159 }
1160
Harald Welte9b751a62019-04-14 17:39:29 +02001161 /* expect the MSC to trigger a BSSMAP ASSIGNMENT */
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001162 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, (tla_ass1, tla_ass2))) -> value bssap {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001163 var template BSSMAP_IE_AoIP_TransportLayerAddress tla;
Harald Welte9b751a62019-04-14 17:39:29 +02001164 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001165 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001166 log("f_mt_call_complete 6");
Oliver Smith90f31bb2023-08-23 13:31:35 +02001167
1168 if (cpars.csd and not match(bssap.pdu.bssmap.assignmentRequest.codecList.codecElements,
1169 {ts_CodecCSData})) {
1170 setverdict(fail, "MSC sent Assignment Request with unexpected codec list for CSD ",
1171 bssap.pdu.bssmap.assignmentRequest.codecList);
1172 mtc.stop;
1173 }
1174
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001175 tla := f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port);
Oliver Smith90f31bb2023-08-23 13:31:35 +02001176
1177 if (cpars.csd) {
1178 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecCSData}));
1179 } else {
1180 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
1181 }
Harald Welte9b751a62019-04-14 17:39:29 +02001182
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001183 if (cpars.use_osmux) {
1184 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1185 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1186 mtc.stop;
1187 }
1188 osmuxCID := valueof(ts_OsmuxCID(0));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001189 if (not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1190 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE. Expected ", osmuxCID, " Got ", bssap.pdu.bssmap.assignmentRequest.osmuxCID);
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001191 mtc.stop;
1192 }
1193 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1194 } else {
1195 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1196 }
1197 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001198
1199 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
Harald Welte9b751a62019-04-14 17:39:29 +02001200 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001201
1202 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1203 log("f_mt_call_complete 7");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001204 var octetstring ip;
1205 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1206 if (is_ipv6) {
1207 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1208 } else {
1209 ip := f_inet_addr(cpars.mncc_rtp_ip);
1210 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001211 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001212 is_ipv6, ip,
1213 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001214 /* payload type 3 = GSM FR */ 3));
1215 }
1216
1217 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1218 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1219 log("f_mt_call_complete 8");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001220 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_1.mgw_rtp_ip, cpars.mgw_conn_1.mgw_rtp_ip,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001221 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001222 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001223 { int2str(cpars.rtp_payload_type) },
1224 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1225 cpars.rtp_sdp_format)),
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001226 valueof(ts_SDP_ptime(20)) }));
1227 if (cpars.use_osmux) {
1228 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1229 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1230 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1231 mtc.stop;
1232 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001233 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001234 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001235 mgcp_resp := ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, sdp);
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001236 }
1237 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001238 }
1239
1240 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1241 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001242 var SDP_Message sdp;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001243 log("f_mt_call_complete 9");
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001244
1245 if (isvalue(mgcp_cmd.sdp)) {
1246 sdp := mgcp_cmd.sdp;
1247 if (sdp.media_list[0].media_field.ports.port_number != cpars.mncc_rtp_port) {
1248 setverdict(fail, "Wrong MDCX Connection port received, expected ", cpars.mncc_rtp_port, " and received ", sdp.media_list[0].media_field.ports.port_number)
1249 mtc.stop;
1250 }
1251 if (sdp.connection.conn_addr.addr != cpars.mncc_rtp_ip) {
1252 setverdict(fail, "Wrong MDCX Connection address received, expected ", cpars.mncc_rtp_ip, " and received ", sdp.connection.conn_addr.addr)
1253 mtc.stop;
1254 }
1255 }
1256
1257 sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1258 hex2str(cpars.mgcp_call_id), "42",
1259 cpars.mgw_conn_2.mgw_rtp_port,
1260 { int2str(cpars.rtp_payload_type) },
1261 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1262 cpars.rtp_sdp_format)),
1263 valueof(ts_SDP_ptime(20)) }));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001264 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001265 }
1266
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001267 }
Harald Welte9b751a62019-04-14 17:39:29 +02001268 } else {
Harald Welte9b751a62019-04-14 17:39:29 +02001269 interleave {
1270 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001271 log("f_mt_call_complete 4.iu");
1272 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1273 break;
Harald Welte9b751a62019-04-14 17:39:29 +02001274 }
Harald Welte9b751a62019-04-14 17:39:29 +02001275 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001276
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001277 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1278 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1279 log("f_mt_call_complete 5.iu");
1280 }
1281
1282 [] BSSAP.receive(tr_RANAP_RabAssReq(?)) {
1283 log("f_mt_call_complete 6.iu");
1284 var RAB_SetupOrModifiedList l := {
1285 {
1286 {
1287 id := id_RAB_SetupOrModifiedItem,
1288 criticality := ignore,
1289 value_ := {
1290 rAB_SetupOrModifiedItem := {
1291 rAB_ID := int2bit(23, 8),
1292 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1293 iuTransportAssociation := {
1294 bindingID := '040c0000'O
1295 },
1296 dl_dataVolumes := omit,
1297 iE_Extensions := omit
1298 }
1299 }
1300 }
1301 }
1302 };
1303 BSSAP.send(ts_RANAP_RabAssResp(l));
1304
1305 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
1306 }
1307
1308 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1309 log("f_mt_call_complete 7.iu");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001310 var octetstring ip;
1311 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1312 if (is_ipv6) {
1313 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1314 } else {
1315 ip := f_inet_addr(cpars.mncc_rtp_ip);
1316 }
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001317 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001318 is_ipv6, ip,
1319 cpars.mncc_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001320 /* payload type 3 = GSM FR */ 3));
1321 }
1322
1323 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1324 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1325 log("f_mt_call_complete 8.iu");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001326 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_1.mgw_rtp_ip, cpars.mgw_conn_1.mgw_rtp_ip,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001327 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001328 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001329 { int2str(cpars.rtp_payload_type) },
1330 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1331 cpars.rtp_sdp_format)),
1332 valueof(ts_SDP_ptime(20)) }));
1333 if (cpars.use_osmux) {
1334 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1335 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1336 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1337 mtc.stop;
1338 }
1339 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
1340 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001341 mgcp_resp := ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, sdp);
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001342 }
1343 MGCP.send(mgcp_resp);
1344 }
1345
1346 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1347 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1348 log("f_mt_call_complete 9.iu");
1349 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1350 hex2str(cpars.mgcp_call_id), "42",
1351 cpars.mgw_conn_2.mgw_rtp_port,
1352 { int2str(cpars.rtp_payload_type) },
1353 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1354 cpars.rtp_sdp_format)),
1355 valueof(ts_SDP_ptime(20)) }));
1356 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
1357 }
1358
Harald Welte33ec09b2018-02-10 15:34:46 +01001359 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001360 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001361
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001362 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1363 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1364 } else {
1365 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1366 mtc.stop;
1367 }
1368
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001369 log("f_mt_call_complete DONE");
Harald Welte4263c522018-12-06 11:56:27 +01001370}
1371
Vadim Yanitskiy53f2be62024-04-14 19:48:39 +07001372/* expect BSSMAP/RANAP Paging for any IMSI and/or TMSI */
1373altstep as_paging_any()
1374runs on BSC_ConnHdlr {
1375 [g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_Paging(?, *));
1376 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_Paging(?, ?));
1377}
1378
1379/* expect BSSMAP/RANAP Paging for registered IMSI and the given TMSI */
1380altstep as_paging_tmsi(template OCT4 tmsi := *)
1381runs on BSC_ConnHdlr {
1382 [g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi, tmsi));
1383 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi)));
1384}
1385
1386/* convenience wrapper for as_paging_tmsi() using g_pars.tmsi */
1387altstep as_paging()
1388runs on BSC_ConnHdlr {
1389 [] as_paging_tmsi(g_pars.tmsi);
1390}
1391
1392/* expect BSSMAP/RANAP Paging for registered IMSI and the given TMSI
1393 * fail on BSSMAP/RANAP Paging for non-matching IMSI/TMSI
1394 * wait up to Tval seconds before declaring timeout */
Vadim Yanitskiyeb81ca42024-04-14 18:55:02 +07001395function f_expect_paging_tmsi(template OCT4 tmsi := *, float Tval := 4.0)
Harald Weltee035e3e2019-04-21 17:32:05 +02001396runs on BSC_ConnHdlr {
Vadim Yanitskiyeb81ca42024-04-14 18:55:02 +07001397 timer T;
1398
1399 T.start(Tval);
1400 alt {
Vadim Yanitskiy53f2be62024-04-14 19:48:39 +07001401 [] as_paging_tmsi(tmsi) { setverdict(pass); }
1402 [] as_paging_any() {
Vadim Yanitskiyeb81ca42024-04-14 18:55:02 +07001403 setverdict(fail, "Paging message doesn't match expectations");
1404 mtc.stop;
1405 }
1406 [] T.timeout {
1407 setverdict(fail, "Timeout waiting for paging");
1408 mtc.stop;
1409 }
Harald Welte9b751a62019-04-14 17:39:29 +02001410 }
Harald Weltee035e3e2019-04-21 17:32:05 +02001411}
1412
Vadim Yanitskiy53f2be62024-04-14 19:48:39 +07001413/* convenience wrapper for f_expect_paging_tmsi() using g_pars.tmsi */
Vadim Yanitskiyeb81ca42024-04-14 18:55:02 +07001414function f_expect_paging(float Tval := 4.0)
Neels Hofmeyr1af4b0f2024-03-26 03:33:54 +01001415runs on BSC_ConnHdlr {
Vadim Yanitskiyeb81ca42024-04-14 18:55:02 +07001416 f_expect_paging_tmsi(g_pars.tmsi, Tval);
Neels Hofmeyr1af4b0f2024-03-26 03:33:54 +01001417}
1418
Harald Welte4263c522018-12-06 11:56:27 +01001419function f_mt_call_establish(inout CallParameters cpars)
1420runs on BSC_ConnHdlr {
1421
1422 /* Initiate the call via MNCC */
Oliver Smith97dc91f2023-05-31 13:53:21 +02001423 f_mt_call_initiate(cpars);
Harald Welte4263c522018-12-06 11:56:27 +01001424
1425 /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
Harald Welte6811d102019-04-14 22:23:14 +02001426 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Weltee035e3e2019-04-21 17:32:05 +02001427 f_expect_paging()
Harald Welte4263c522018-12-06 11:56:27 +01001428
1429 /* Complete the call via BSSAP */
1430 f_mt_call_complete(cpars);
Harald Welte33ec09b2018-02-10 15:34:46 +01001431
Harald Welte33ec09b2018-02-10 15:34:46 +01001432 setverdict(pass);
1433}
1434
Neels Hofmeyrc47ce852023-03-06 17:16:50 +01001435function f_call_keep_open(inout CallParameters cpars, float open_time := 5.0)
1436runs on BSC_ConnHdlr {
1437 log("Hold the call for some time");
1438
1439 timer T := open_time;
1440 T.start;
1441 alt {
1442 [] MNCC.receive(tr_MNCC_DISC_ind(cpars.mncc_callref));
1443 [] MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
1444 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1445 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
1446 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1447 [] BSSAP.receive(tr_BSSMAP_ClearCommand);
1448 [] BSSAP.receive(tr_BSSMAP_ClearCommandCSFB);
1449 [] BSSAP.receive(tr_RANAP_IuReleaseCommand(?));
1450
1451 [] T.timeout {
1452 log("Call stayed open for ", open_time, " seconds, all is well.")
1453 setverdict(pass);
1454 return;
1455 }
1456 }
1457
1458 setverdict(fail, "An unexpected release event disconnected the active call prematurely");
1459 mtc.stop;
1460}
1461
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001462/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1463 * Return true when an OK reply was sent, false otherwise.
1464 * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */
1465function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd)
1466runs on BSC_ConnHdlr
1467return boolean {
1468 var CrcxResponse conn := cpars.mgw_conn_1;
1469 if (cpars.got_crcx_count > 0) {
1470 conn := cpars.mgw_conn_2;
1471 }
1472 cpars.got_crcx_count := cpars.got_crcx_count + 1;
1473
1474 var MgcpMessage mgcp_msg := {
1475 command := mgcp_cmd
1476 }
1477 var template MgcpResponse mgcp_resp;
1478 var MgcpOsmuxCID osmux_cid;
1479 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1480 if (ispresent(cpars.mgcp_call_id)) {
1481 if (cpars.mgcp_call_id != call_id) {
1482 setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id);
1483 mtc.stop;
1484 }
1485 } else {
1486 cpars.mgcp_call_id := call_id;
1487 }
1488
1489 /* When the endpoint contains a wildcard we keep the endpoint
1490 * identifier we have set up in cpars. Otherwise we use the
1491 * endpoint name that the call agent has supplied */
1492 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1493 cpars.mgcp_ep := mgcp_cmd.line.ep;
1494 }
1495
1496 if (conn.resp == -1) {
1497 /* Reply with error */
1498 var MgcpResponse mgcp_rsp := {
1499 line := {
1500 code := "542",
1501 trans_id := mgcp_cmd.line.trans_id,
1502 string := "FORCED_FAIL"
1503 },
1504 sdp := omit
1505
1506 }
1507 var MgcpParameter mgcp_rsp_param := {
1508 code := "Z",
1509 val := cpars.mgcp_ep
1510 };
1511 mgcp_rsp.params[0] := mgcp_rsp_param;
1512 MGCP.send(mgcp_rsp);
1513 return false;
1514 }
1515
1516 if (conn.resp == 0) {
1517 /* Do not reply at all */
1518 return false;
1519 }
1520
1521 if (conn.resp != 1) {
1522 setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1");
1523 mtc.stop;
1524 }
1525
1526 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1527 hex2str(cpars.mgcp_call_id), "42",
1528 conn.mgw_rtp_port,
1529 { int2str(cpars.rtp_payload_type) },
1530 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1531 cpars.rtp_sdp_format)),
1532 valueof(ts_SDP_ptime(20)) }));
1533
1534 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1535 if (not cpars.use_osmux) {
1536 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1537 mtc.stop;
1538 }
1539 cpars.got_osmux_count := cpars.got_osmux_count + 1;
1540 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1541 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1542 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1543 if (osmux_cid != -1) {
1544 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1545 mtc.stop;
1546 }
1547
1548 osmux_cid := 0;
1549 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1550 } else {
1551 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1552 }
1553
1554 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep));
1555 MGCP.send(mgcp_resp);
1556 return true;
1557}
1558
1559
1560altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr {
1561 var MgcpCommand mgcp_cmd;
1562 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1563 log("as_optional_mgcp_crcx: rx CRCX");
1564 f_handle_crcx(cpars, mgcp_cmd);
1565
1566 /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an
1567 * CRCX is handled. */
1568 repeat;
1569 }
1570}
1571
Andreas Eversberg1733de32023-07-27 16:27:05 +02001572altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001573 var MgcpCommand mgcp_cmd;
1574 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1575 log("as_optional_mgcp_mdcx: rx MDCX");
1576 log(mgcp_cmd);
1577 var charstring conn_id;
1578 var charstring rtp_payload_type;
1579 f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id);
1580 rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0];
1581
1582 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip,
1583 mgcp_cmd.sdp.origin.session_id, "42",
1584 mgw_rtp_port,
1585 { rtp_payload_type },
1586 { valueof(ts_SDP_ptime(20)) }));
1587 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp));
1588
1589 /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is
1590 * handled. */
1591 repeat;
1592 }
1593}
1594
Andreas Eversberg1733de32023-07-27 16:27:05 +02001595altstep as_optional_mgcp_dlcx(CallParameters cpars) runs on BSC_ConnHdlr {
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001596 var MgcpCommand mgcp_cmd;
1597 var boolean respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1598 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1599 log("as_optional_mgcp_dlcx: rx MGCP DLCX");
1600 if (respond_to_dlcx) {
1601 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1602 }
1603 /* Without this 'repeat', currently active other interleave and alt series exit as soon as a
1604 * DLCX is handled. */
1605 repeat;
1606 }
1607}
1608
Philipp Maier3716a5e2018-03-21 15:53:35 +01001609function f_mo_call_establish(inout CallParameters cpars)
Harald Welteb71901a2018-01-26 19:16:05 +01001610runs on BSC_ConnHdlr {
1611
Harald Welteb71901a2018-01-26 19:16:05 +01001612 var MNCC_PDU mncc;
1613 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001614 var template MgcpResponse mgcp_resp;
Philipp Maier2a98a732018-03-19 16:06:12 +01001615 var boolean respond_to_dlcx;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001616 var PDU_BSSAP bssap;
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001617 var RANAP_PDU ranap;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001618 var MgcpOsmuxCID osmux_cid;
Harald Welteb71901a2018-01-26 19:16:05 +01001619
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001620 cpars.mo_call := true;
1621
Harald Welte0bef21e2018-02-10 09:48:23 +01001622 if (cpars.emergency) {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001623 f_establish_fully(EST_TYPE_EMERG_CALL);
Oliver Smith92b280c2023-04-20 13:13:23 +02001624 } else if (cpars.csd) {
1625 f_establish_fully(EST_TYPE_MO_CSD);
Harald Welte0bef21e2018-02-10 09:48:23 +01001626 } else {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001627 f_establish_fully(EST_TYPE_MO_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001628 }
Harald Welteb71901a2018-01-26 19:16:05 +01001629
1630 /* Create MNCC and MGCP expect */
1631 f_create_mncc_expect(hex2str(cpars.called_party));
1632 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1633
Harald Welte0bef21e2018-02-10 09:48:23 +01001634 if (cpars.emergency) {
1635 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id)));
1636 } else {
Oliver Smith9c417f22023-07-07 13:25:11 +02001637 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party,
1638 cpars.bearer_cap)));
Harald Welte0bef21e2018-02-10 09:48:23 +01001639 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001640
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001641 if (cpars.stop_after_cc_setup) {
1642 return;
1643 }
1644
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001645 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass1 :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001646 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001647 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass2 :=
1648 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_2.mgw_rtp_ip, ?);
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001649
1650 var default mdcx := activate(as_optional_mgcp_mdcx(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_port));
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001651 var boolean got_mncc_setup_compl_ind := false;
1652 var boolean got_cc_connect := false;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001653
Harald Welteb71901a2018-01-26 19:16:05 +01001654 interleave {
1655 [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001656 log("f_mo_call_establish 1: rx MNCC SETUP ind");
Harald Welteb71901a2018-01-26 19:16:05 +01001657 cpars.mncc_callref := mncc.u.signal.callref;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001658 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1659 }
1660
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001661 /* First MGCP CRCX */
Harald Welteb71901a2018-01-26 19:16:05 +01001662 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001663 log("f_mo_call_establish 2: rx 1st CRCX");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001664 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1665 break;
1666 }
Philipp Maierf1e02bb2018-03-15 16:30:00 +01001667 }
1668
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001669 /* Second MGCP CRCX */
1670 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
1671 log("f_mo_call_establish 6: rx 2nd CRCX");
1672 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1673 break;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001674 }
Harald Welteb71901a2018-01-26 19:16:05 +01001675 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001676
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001677 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1678 log("f_mo_call_establish 3: rx RTP CREATE");
1679 /* Call Proceeding */
1680 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1681 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001682
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001683 /* Alerting */
1684 MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref));
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001685 }
Harald Welte9b751a62019-04-14 17:39:29 +02001686
Neels Hofmeyreccaa992019-10-15 16:42:21 +02001687 //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001688 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001689 log("f_mo_call_establish 4: rx Assignment Request");
1690 var BSSMAP_IE_AoIP_TransportLayerAddress tla;
1691 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001692 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
1693
Oliver Smithd6c90062023-05-08 15:20:20 +02001694 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer)) {
1695 setverdict(fail, "MSC sent Assignment Request without AoIP Transport Layer IE");
1696 mtc.stop;
1697 }
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001698 if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass1)
1699 and not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass2)) {
1700 log("Expected one of: 1:", tla_ass1, " 2:", tla_ass2);
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001701 log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer);
1702 setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE");
1703 mtc.stop;
1704 }
1705
Oliver Smith90f31bb2023-08-23 13:31:35 +02001706 if (cpars.csd and not match(bssap.pdu.bssmap.assignmentRequest.codecList.codecElements,
1707 {ts_CodecCSData})) {
1708 setverdict(fail, "MSC sent Assignment Request with unexpected codec list for CSD ",
1709 bssap.pdu.bssmap.assignmentRequest.codecList);
1710 mtc.stop;
1711 }
1712
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001713 tla := valueof(f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port));
Oliver Smith90f31bb2023-08-23 13:31:35 +02001714
1715 if (cpars.csd) {
1716 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecCSData}));
1717 } else {
1718 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
1719 }
1720
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001721 if (cpars.use_osmux) {
1722 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1723 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1724 mtc.stop;
1725 }
1726 osmuxCID := valueof(ts_OsmuxCID(0));
1727 if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1728 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1729 mtc.stop;
1730 }
1731 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1732 } else {
1733 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1734 }
1735 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001736 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001737 [] BSSAP.receive(tr_RANAP_RabAssReq(*)) -> value ranap {
1738 log("f_mo_call_establish 4.iu: rx RANAP RAB Assignment Request");
1739 var RAB_SetupOrModifiedList l := {
1740 {
1741 {
1742 id := id_RAB_SetupOrModifiedItem,
1743 criticality := ignore,
1744 value_ := {
1745 rAB_SetupOrModifiedItem := {
1746 rAB_ID := int2bit(23, 8),
1747 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1748 iuTransportAssociation := {
1749 bindingID := '040c0000'O
1750 },
1751 dl_dataVolumes := omit,
1752 iE_Extensions := omit
1753 }
1754 }
1755 }
1756 }
1757 };
1758 BSSAP.send(ts_RANAP_RabAssResp(l));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001759 }
Harald Welte9b751a62019-04-14 17:39:29 +02001760
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001761 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1762 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1763 log("f_mo_call_establish 5: rx MDCX for the RAN side");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001764 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_1.mgw_rtp_ip, cpars.mgw_conn_1.mgw_rtp_ip,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001765 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001766 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001767 { int2str(cpars.rtp_payload_type) },
1768 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1769 cpars.rtp_sdp_format)),
1770 valueof(ts_SDP_ptime(20)) }));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001771
1772 if (cpars.use_osmux) {
1773 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1774 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1775 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1776 mtc.stop;
1777 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001778 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001779 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001780 mgcp_resp := ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, sdp);
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001781 }
1782 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001783 }
Harald Welte9b751a62019-04-14 17:39:29 +02001784
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001785 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {
1786 log("f_mo_call_establish 7: rx CC Alerting");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001787
1788 if (cpars.ran_clear_when_alerting) {
1789 if (g_pars.ran_is_geran) {
1790 BSSAP.send(ts_BSSMAP_ClearRequest(0));
1791 } else {
1792 BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention));
1793 }
1794 break;
1795 }
1796
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001797 cpars.mncc_callref := mncc.u.signal.callref;
1798 /* Call Proceeding */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001799 var octetstring ip;
1800 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1801 if (is_ipv6) {
1802 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1803 } else {
1804 ip := f_inet_addr(cpars.mncc_rtp_ip);
1805 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001806 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001807 is_ipv6, ip,
1808 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001809 /* payload type 3 = GSM FR */ 3));
1810 MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref));
1811 }
1812
1813 [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc {
1814 log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001815 got_mncc_setup_compl_ind := true;
1816 if (not cpars.expect_release and got_cc_connect) {
1817 break;
1818 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001819 }
1820
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001821 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) {
1822 log("f_mo_call_establish 10: rx CC CONNECT");
1823 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id)));
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001824 got_cc_connect := true;
1825 if (not cpars.expect_release and got_mncc_setup_compl_ind) {
1826 break;
1827 }
Harald Welteb71901a2018-01-26 19:16:05 +01001828 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001829
1830 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1831 log("f_mo_call_establish 11: rx CC RELEASE");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001832 if (not cpars.expect_release) {
1833 setverdict(fail, "Got unexpected CC Release");
1834 mtc.stop;
1835 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001836 f_expect_clear();
1837 break;
1838 }
1839 }
1840
1841 f_sleep(0.5);
1842 deactivate(mdcx);
1843
1844 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1845 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1846 } else {
1847 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1848 mtc.stop;
Harald Welteb71901a2018-01-26 19:16:05 +01001849 }
1850
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001851 log("f_mo_call_establish DONE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001852 setverdict(pass);
1853}
Harald Welteb71901a2018-01-26 19:16:05 +01001854
Harald Welte4c422b72019-02-17 16:27:10 +01001855function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001856runs on BSC_ConnHdlr {
1857
1858 var MobileIdentityLV mi;
1859 var MNCC_PDU mncc;
1860 var MgcpCommand mgcp_cmd;
1861 var boolean respond_to_dlcx;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001862 var boolean dlcx_contained_ci := false;
1863 var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand;
1864
1865 if (is_csfb) {
1866 t_clear := tr_BSSMAP_ClearCommandCSFB;
1867 }
1868
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001869 log("f_call_hangup 0: tx MNCC_DISC_REQ");
Harald Welteb71901a2018-01-26 19:16:05 +01001870 MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1871 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1872
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001873 log("f_call_hangup 1: rx DTAP CC DISC");
1874
Philipp Maier3716a5e2018-03-21 15:53:35 +01001875 if (release_by_ms) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001876 var BIT1 tid_remote := '1'B;
1877 if (cpars.mo_call) {
1878 tid_remote := '0'B;
1879 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001880 /* B-side (MS) Release of call */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001881 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_RELEASE(cpars.transaction_id, tid_remote, '0000000'B)));
Philipp Maier3716a5e2018-03-21 15:53:35 +01001882 MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001883 log("f_call_hangup 2: rx MNCC REL ind");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001884 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001885 log("f_call_hangup 3: rx DTAP CC REL COMPL");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001886 } else {
1887 /* A-side (PLMN) Release of call */
1888 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42))));
1889 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
Oliver Smith6f546a92023-07-10 15:03:31 +02001890 log("f_call_hangup 2.a: rx DTAP CC RELEASE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001891 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
Oliver Smith6f546a92023-07-10 15:03:31 +02001892 log("f_call_hangup 3.a: rx MNCC REL cnf");
1893 MNCC.receive(tr_MNCC_REL_cnf(cpars.mncc_callref, cause := *));
Philipp Maier3716a5e2018-03-21 15:53:35 +01001894 }
Harald Welteb71901a2018-01-26 19:16:05 +01001895
Philipp Maier2a98a732018-03-19 16:06:12 +01001896 respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1897
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001898 var default mdcx := activate(as_optional_mgcp_mdcx(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_port));
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001899 var default dlcx := activate(as_optional_mgcp_dlcx(cpars));
Harald Welte9b751a62019-04-14 17:39:29 +02001900
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001901 /* clearing of radio channel */
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001902 alt {
1903 [g_pars.ran_is_geran] BSSAP.receive(t_clear) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001904 log("f_call_hangup 5: rx BSSAP Clear Command");
1905 BSSAP.send(ts_BSSMAP_ClearComplete);
1906 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1907 log("f_call_hangup 6: rx SCCP DISC");
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001908 setverdict(pass);
Philipp Maier2a98a732018-03-19 16:06:12 +01001909 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001910 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) {
1911 log("f_call_hangup 5.iu: rx Iu Release Command");
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001912 BSSAP.send(ts_RANAP_IuReleaseComplete);
1913 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001914 log("f_call_hangup 6.iu: rx SCCP DISC");
1915 setverdict(pass);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001916 }
1917 }
1918
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001919 f_sleep(1.0);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001920 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1921 log("f_call_hangup 9: done");
1922
1923 deactivate(mdcx);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001924 deactivate(dlcx);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001925}
1926
Oliver Smith98e24bc2023-07-07 12:36:59 +02001927function f_mt_call(inout CallParameters cpars, float open_time := 5.0)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001928runs on BSC_ConnHdlr {
1929
1930 f_mt_call_establish(cpars);
1931
Oliver Smith98e24bc2023-07-07 12:36:59 +02001932 f_call_keep_open(cpars, open_time);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001933
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001934 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001935 f_call_hangup(cpars, true);
1936
Oliver Smith3a33e552023-07-06 11:55:12 +02001937 /* Unregister the IMSI that was registered in f_mt_call_establish */
1938 f_ran_unregister_imsi(g_pars.imsi);
1939
Philipp Maier3716a5e2018-03-21 15:53:35 +01001940 setverdict(pass);
1941}
1942
Oliver Smith98e24bc2023-07-07 12:36:59 +02001943function f_mo_call(inout CallParameters cpars, float open_time := 5.0)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001944runs on BSC_ConnHdlr {
1945
1946 f_mo_call_establish(cpars);
1947
Oliver Smith98e24bc2023-07-07 12:36:59 +02001948 f_call_keep_open(cpars, open_time);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001949
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001950 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001951 f_call_hangup(cpars, false);
1952
Harald Welteb71901a2018-01-26 19:16:05 +01001953 setverdict(pass);
1954}
Harald Weltea49e36e2018-01-21 19:29:33 +01001955
Daniel Willmann8b084372018-02-04 13:35:26 +01001956function f_mo_seq_dtmf_dup(inout CallParameters cpars)
1957runs on BSC_ConnHdlr {
1958
1959 timer T := 1.0;
Daniel Willmann8b084372018-02-04 13:35:26 +01001960 var MNCC_PDU mncc;
1961 var MgcpCommand mgcp_cmd;
1962 var template PDU_ML3_MS_NW dtmf_dtap;
1963
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001964 f_mo_call_establish(cpars);
Daniel Willmann8b084372018-02-04 13:35:26 +01001965
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001966 /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by
1967 * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001968
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001969 /* Find out the next NSD that will be used, from RAN emulation. */
1970 var N_Sd_Array last_n_sd := f_bssmap_last_n_sd();
1971 var uint2_t next_n_sd := f_next_n_sd(last_n_sd, 0 /* cc is index 0 */);
Daniel Willmann8b084372018-02-04 13:35:26 +01001972
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001973 /* Compose DTAP with this correct NSD */
Daniel Willmann8b084372018-02-04 13:35:26 +01001974 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001975
1976 /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */
1977 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001978 T.start;
1979 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001980 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
1981 log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind");
1982 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001983 [] T.timeout {
1984 setverdict(fail, "Timeout waiting for START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001985 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001986 }
1987 }
1988
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001989 /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message
1990 * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */
1991 dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2);
Daniel Willmann92f66272018-02-06 15:50:52 +01001992 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true));
Daniel Willmann8b084372018-02-04 13:35:26 +01001993 T.start;
1994 alt {
1995 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001996 setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001997 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001998 }
1999 [] T.timeout { }
2000 }
2001
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02002002 /* Here the NSD should be correct again and we see a DTMF. */
Daniel Willmann8b084372018-02-04 13:35:26 +01002003 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02002004 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01002005 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02002006 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) {
2007 log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind");
2008 }
Daniel Willmann8b084372018-02-04 13:35:26 +01002009 [] T.timeout {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02002010 setverdict(fail, "Timeout waiting for final START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02002011 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01002012 }
2013 }
2014
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02002015 f_call_hangup(cpars, true);
Daniel Willmann8b084372018-02-04 13:35:26 +01002016 setverdict(pass);
2017}
Harald Welte9b751a62019-04-14 17:39:29 +02002018
Vadim Yanitskiyb3e42cf2024-03-27 16:23:30 +07002019/* expect a clear command (for GERAN only!) */
Vadim Yanitskiy7093a5d2024-03-27 16:10:25 +07002020altstep as_clear_cmd_compl_disc() runs on BSC_ConnHdlr {
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01002021 var PDU_BSSAP bssap;
Harald Welte5946b332018-03-18 23:32:21 +01002022 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
2023 BSSAP.send(ts_BSSMAP_ClearComplete);
2024 alt {
Harald Welte6811d102019-04-14 22:23:14 +02002025 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte5946b332018-03-18 23:32:21 +01002026 setverdict(pass);
2027 }
2028 [] BSSAP.receive {
2029 setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02002030 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01002031 }
2032 }
2033 }
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01002034 [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap {
2035 setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02002036 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01002037 }
2038}
2039
Vadim Yanitskiyb3e42cf2024-03-27 16:23:30 +07002040/* expect a BSSMAP Clear Command (for GERAN) or an Iu-ReleaseCommand (for UTRAN) */
2041altstep as_expect_clear() runs on BSC_ConnHdlr {
2042 [g_pars.ran_is_geran] as_clear_cmd_compl_disc();
2043 [not g_pars.ran_is_geran] as_iu_release_compl_disc();
2044}
2045
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02002046function f_expect_clear(float t := 5.0, boolean verify_vlr_cell_id := true) runs on BSC_ConnHdlr {
Harald Welte1ddc7162018-01-27 14:25:46 +01002047 timer T := t;
2048
2049 T.start;
2050 alt {
Vadim Yanitskiyb3e42cf2024-03-27 16:23:30 +07002051 [] as_expect_clear() {
2052 if (verify_vlr_cell_id) {
2053 /* Now the conn is gone, but the VLR reflects the cell ID */
2054 f_verify_vty_lac_ci();
2055 }
2056 }
Harald Welte1ddc7162018-01-27 14:25:46 +01002057 [] T.timeout {
Harald Welte5946b332018-03-18 23:32:21 +01002058 setverdict(fail, "Timeout waiting for ClearCommand/Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02002059 mtc.stop;
Harald Welte1ddc7162018-01-27 14:25:46 +01002060 }
2061 }
2062}
2063
Andreas Eversberge5a6ef12023-07-28 10:45:20 +02002064function f_create_bssmap_exp_n_connect(integer targetPointCode) runs on BSC_ConnHdlr {
2065 BSSAP_PROC.call(RAN_register_n_connect:{targetPointCode, self}) {
2066 [] BSSAP_PROC.getreply(RAN_register_n_connect:{?, ?}) {};
Neels Hofmeyr0ac63152019-05-07 01:20:17 +02002067 }
2068}
2069
2070function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array {
2071 var N_Sd_Array last_n_sd;
2072 BSSAP_PROC.call(RAN_last_n_sd:{self, -}) {
2073 [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) {
2074 return last_n_sd;
2075 };
2076 }
2077}
2078
2079function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr {
2080 BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) {
2081 [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self});
2082 }
2083}
2084
Harald Weltef45efeb2018-04-09 18:19:24 +02002085type record SmsParametersTp {
2086 OCT1 msg_ref,
2087 TP_DA da,
2088 OCT1 pid,
2089 OCT1 dcs,
2090 integer udl,
2091 octetstring ud
2092}
2093type record SmsParametersRp {
2094 OCT1 msg_ref,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002095 RP_NumberingPlan_and_NumberDigits smsc_addr optional
Harald Weltef45efeb2018-04-09 18:19:24 +02002096}
2097type record SmsParameters {
2098 SmsParametersTp tp,
2099 SmsParametersRp rp,
2100 uint3_t tid,
2101 OCT1 dlci,
2102 uint7_t exp_rp_err optional
2103}
2104
2105template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := {
2106 tP_DA_NoPad := {
2107 tP_LengthIndicator := 0, /* overwritten */
2108 tP_NumberingPlanID := npl,
2109 tP_TypeOfNumber := ton,
2110 tp_Spare := '0'B,
2111 tP_DAValue := addr
2112 }
2113}
2114
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002115template RP_NumberingPlan_and_NumberDigits t_RP_Addr(template hexstring addr,
2116 template BIT4 npi := '0001'B,
2117 template BIT3 ton := '001'B,
2118 template BIT1 ext := '1'B) := {
2119 rP_NumberingPlanIdentification := npi,
2120 rP_TypeOfNumber := ton,
2121 rP_Ext := ext,
2122 rP_NumberDigits := addr
2123}
2124
Harald Weltef45efeb2018-04-09 18:19:24 +02002125template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := {
2126 tp := {
2127 msg_ref := '23'O,
2128 da := ts_TP_DA('0000'B, '000'B, tp_daddr),
2129 pid := '00'O,
2130 dcs := '00'O,
2131 udl := 0,
2132 ud := ''O
2133 },
2134 rp := {
2135 msg_ref := '42'O,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002136 /* We don't really need to have both SM-RP-DA/OA here, because only one IE
Vadim Yanitskiyafb15a82020-01-05 14:04:53 +01002137 * is included in MO/MT SMS, and in the most cases it's the SMSC address.
2138 * NOTE: this address is currently hard-coded by OsmoMSC. */
2139 smsc_addr := t_RP_Addr('447785016005'H)
Harald Weltef45efeb2018-04-09 18:19:24 +02002140 },
2141 tid := 0,
2142 dlci := '03'O,
2143 exp_rp_err := omit
2144}
2145
2146private altstep as_other_sms() runs on BSC_ConnHdlr {
2147 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) {
2148 setverdict(fail, "Unexpected SMS related PDU from MSC");
Daniel Willmannafce8662018-07-06 23:11:32 +02002149 mtc.stop;
Harald Weltef45efeb2018-04-09 18:19:24 +02002150 }
2151}
2152
Vadim Yanitskiy9cc019a2018-11-15 02:06:07 +07002153/* Submit a MO RP-SMMA over an already existing DTAP connection */
2154function f_mo_smma(inout SmsParameters spars)
2155runs on BSC_ConnHdlr {
2156 var template (value) RPDU_MS_SGSN rp_mo;
2157 var template (value) PDU_ML3_MS_NW l3_mo;
2158
2159 var default d := activate(as_other_sms());
2160
2161 /* just in case this is routed to SMPP.. */
2162 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2163
2164 rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref);
2165 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
2166 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2167 /* receive CP-ACK for CP-DATA above */
2168 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
2169
2170 deactivate(d);
2171 setverdict(pass);
2172}
2173
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002174/* Submit a MO-SMS over an already existing DTAP connection */
2175function f_mo_sms_submit(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02002176runs on BSC_ConnHdlr {
2177 var template (value) TPDU_RP_DATA_MS_SGSN tp_mo;
2178 var template (value) RPDU_MS_SGSN rp_mo;
2179 var template (value) PDU_ML3_MS_NW l3_mo;
2180
Harald Weltef45efeb2018-04-09 18:19:24 +02002181 var default d := activate(as_other_sms());
2182
Harald Weltef640a012018-04-14 17:49:21 +02002183 /* just in case this is routed to SMPP.. */
2184 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2185
Harald Weltef45efeb2018-04-09 18:19:24 +02002186 tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs,
2187 spars.tp.udl, spars.tp.ud);
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002188 rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, omit, spars.rp.smsc_addr, tp_mo);
Harald Weltef45efeb2018-04-09 18:19:24 +02002189 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
2190 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2191 /* receive CP-ACK for CP-DATA above */
2192 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
2193
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002194 deactivate(d);
2195 setverdict(pass);
2196}
2197
2198/* Wait RP-ACK for MO-SMS on an already existing DTAP connection */
2199function f_mo_sms_wait_rp_ack(inout SmsParameters spars)
2200runs on BSC_ConnHdlr {
2201 var template (value) PDU_ML3_MS_NW l3_mo;
2202
2203 var template TPDU_RP_DATA_SGSN_MS tp_mt;
2204 var template RPDU_SGSN_MS rp_mt;
2205 var template PDU_ML3_NW_MS l3_mt;
2206
2207 var default d := activate(as_other_sms());
2208
2209 /* just in case this is routed to SMPP.. */
2210 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2211
Harald Weltef45efeb2018-04-09 18:19:24 +02002212 if (ispresent(spars.exp_rp_err)) {
2213 /* expect an RP-ERROR message from MSC with given cause */
2214 rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err);
2215 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
2216 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2217 /* send CP-ACK for CP-DATA just received */
2218 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
2219 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2220 } else {
2221 /* expect RP-ACK for RP-DATA */
2222 rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref);
2223 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
2224 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2225 /* send CP-ACO for CP-DATA just received */
2226 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
2227 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2228 }
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002229
Harald Weltef45efeb2018-04-09 18:19:24 +02002230 deactivate(d);
2231 setverdict(pass);
2232}
2233
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002234/* Submit a MO-SMS, and wait for RP-ACK on an existing
2235 * (and authenticated, ...) DTAP connection */
2236function f_mo_sms(inout SmsParameters spars)
2237runs on BSC_ConnHdlr {
2238 f_mo_sms_submit(spars);
2239 f_mo_sms_wait_rp_ack(spars);
2240}
2241
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002242function f_mt_sms_deliver_pdu(in SmsParameters spars)
2243runs on BSC_ConnHdlr
2244return template PDU_DTAP_MT {
2245 var template TPDU_RP_DATA_SGSN_MS tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?);
2246 var template RPDU_SGSN_MS rp_mt := tr_RP_DATA_MT(?, spars.rp.smsc_addr, omit, tp_mt);
2247 var template PDU_ML3_NW_MS l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt));
2248 return tr_PDU_DTAP_MT(l3_mt, spars.dlci);
2249}
2250
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002251/* Wait for MT SMS on an already existing DTAP connection */
2252function f_mt_sms_expect(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02002253runs on BSC_ConnHdlr {
Harald Weltef45efeb2018-04-09 18:19:24 +02002254 var template (value) PDU_ML3_MS_NW l3_mo;
Harald Weltef45efeb2018-04-09 18:19:24 +02002255 var PDU_DTAP_MT dtap_mt;
2256
2257 var default d := activate(as_other_sms());
2258
2259 /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002260 BSSAP.receive(f_mt_sms_deliver_pdu(spars)) -> value dtap_mt;
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002261
Harald Weltef45efeb2018-04-09 18:19:24 +02002262 /* Extract relevant identifiers */
2263 spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio);
2264 spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference;
2265
2266 /* send CP-ACK for CP-DATA just received */
2267 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO);
2268 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2269
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002270 deactivate(d);
2271 setverdict(pass);
2272}
2273
2274/* Send RP-ACK for MT-SMS over an already existing DTAP connection */
2275function f_mt_sms_send_rp_ack(inout SmsParameters spars)
2276runs on BSC_ConnHdlr {
2277 var template (value) RPDU_MS_SGSN rp_mo;
2278 var template (value) PDU_ML3_MS_NW l3_mo;
2279 var template PDU_ML3_NW_MS l3_mt;
2280
2281 var default d := activate(as_other_sms());
2282
Harald Weltef45efeb2018-04-09 18:19:24 +02002283 /* send RP-ACK for RP-DATA */
2284 rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref);
2285 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2286 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2287
2288 /* expect CP-ACK for CP-DATA(RP-ACK) just sent */
Harald Weltee008eea2018-04-14 21:05:48 +02002289 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
Harald Weltef45efeb2018-04-09 18:19:24 +02002290 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2291
2292 deactivate(d);
2293 setverdict(pass);
2294}
2295
Vadim Yanitskiy56318522018-11-24 03:40:47 +07002296/* Send RP-ERROR for MT-SMS over an already existing DTAP connection */
2297function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause)
2298runs on BSC_ConnHdlr {
2299 var template (value) RPDU_MS_SGSN rp_mo;
2300 var template (value) PDU_ML3_MS_NW l3_mo;
2301 var template PDU_ML3_NW_MS l3_mt;
2302
2303 var default d := activate(as_other_sms());
2304
2305 /* send RP-ACK for RP-DATA */
2306 rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause);
2307 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2308 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2309
2310 /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */
2311 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
2312 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2313
2314 deactivate(d);
2315 setverdict(pass);
2316}
2317
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002318/* Wait for a MT-SMS and send RP-ACK over an already existing
2319 * (and authenticated, ...) DTAP connection */
2320function f_mt_sms(inout SmsParameters spars)
2321runs on BSC_ConnHdlr {
2322 f_mt_sms_expect(spars);
2323 f_mt_sms_send_rp_ack(spars);
2324}
Harald Weltea49e36e2018-01-21 19:29:33 +01002325
2326
Harald Weltea49e36e2018-01-21 19:29:33 +01002327}