blob: cf4e8467a23d012190eec6a850779145629bef1e [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;
34import from GSUP_Emulation all;
35
36import from MNCC_Types all;
37import from MNCC_Emulation all;
38
Harald Welte4aa970c2018-01-26 10:38:09 +010039import from MGCP_Types all;
40import from MGCP_Emulation all;
Harald Welteb71901a2018-01-26 19:16:05 +010041import from MGCP_Templates all;
42import from SDP_Types all;
Harald Welte4aa970c2018-01-26 10:38:09 +010043
Harald Weltea49e36e2018-01-21 19:29:33 +010044import from MobileL3_Types all;
45import from MobileL3_CommonIE_Types all;
46import from MobileL3_MM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010047import from MobileL3_CC_Types all;
Harald Weltef45efeb2018-04-09 18:19:24 +020048import from MobileL3_SMS_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010049import from L3_Templates all;
Harald Welte158a7ca2018-02-16 18:11:31 +010050import from L3_Common all;
Harald Weltea49e36e2018-01-21 19:29:33 +010051
Harald Weltef640a012018-04-14 17:49:21 +020052import from SMPP_Emulation all;
53
Philipp Maieraeb29a82018-11-08 17:40:53 +010054import from IPA_Emulation all;
55import from Osmocom_CTRL_Functions all;
56import from Osmocom_CTRL_Types all;
57import from Osmocom_CTRL_Adapter all;
58
Philipp Maierc39a9d82018-11-09 11:21:08 +010059import from TELNETasp_PortType all;
60import from Osmocom_VTY_Functions all;
61
Harald Welte4263c522018-12-06 11:56:27 +010062import from SGsAP_Emulation all;
63
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +020064import from TCCConversion_Functions { function f_strstr };
65
Harald Weltea49e36e2018-01-21 19:29:33 +010066/* this component represents a single subscriber connection */
Harald Welte6811d102019-04-14 22:23:14 +020067type 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 +010068 var BSC_ConnHdlrPars g_pars;
Harald Weltea10db902018-01-27 12:44:49 +010069 timer g_Tguard := 60.0;
Philipp Maierc39a9d82018-11-09 11:21:08 +010070 port TELNETasp_PT MSCVTY;
Harald Weltea49e36e2018-01-21 19:29:33 +010071}
72
Harald Weltede371492018-01-27 23:44:41 +010073type record BSC_ConnHdlrNetworkPars {
74 OCT1 kc_support,
75 boolean expect_tmsi,
76 boolean expect_auth,
Oliver Smith1d118ff2019-07-03 10:57:35 +020077 boolean expect_ciph,
78 boolean expect_imei,
79 boolean expect_imei_early,
80 GSUP_IMEIResult check_imei_result,
81 boolean check_imei_error
Harald Weltede371492018-01-27 23:44:41 +010082}
83
Harald Weltea49e36e2018-01-21 19:29:33 +010084type record BSC_ConnHdlrPars {
85 SCCP_PAR_Address sccp_addr_own,
86 SCCP_PAR_Address sccp_addr_peer,
87 BSSMAP_IE_CellIdentifier cell_id,
Harald Welte256571e2018-01-24 18:47:19 +010088 hexstring imei,
Harald Weltea49e36e2018-01-21 19:29:33 +010089 hexstring imsi,
Harald Welte82600572018-01-21 20:54:08 +010090 hexstring msisdn,
Harald Welte256571e2018-01-24 18:47:19 +010091 OCT4 tmsi optional,
Harald Welte9de84792018-01-28 01:06:35 +010092 MobileStationClassmark1_V cm1,
Harald Welte82600572018-01-21 20:54:08 +010093 BSSMAP_IE_ClassmarkInformationType2 cm2,
Harald Welte16114282018-01-24 22:41:21 +010094 BSSMAP_IE_ClassmarkInformationType3 cm3 optional,
Harald Weltede371492018-01-27 23:44:41 +010095 AuthVector vec optional,
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +020096 /* BSC_ConnectionHandler generates an auth vector in as_GSUP_SAI(). For tests that want control over which
97 * vector is used, pass vec_keep := true to not regenerate a new auth vector in as_GSUP_SAI(). */
98 boolean vec_keep,
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +010099 BSC_ConnHdlrNetworkPars net,
Philipp Maieraeb29a82018-11-08 17:40:53 +0100100 boolean send_early_cm,
101 charstring ipa_ctrl_ip,
102 integer ipa_ctrl_port,
Philipp Maier9b690e42018-12-21 11:50:03 +0100103 boolean ipa_ctrl_enable,
Philipp Maier57865482019-01-07 18:33:13 +0100104 boolean mm_info,
Philipp Maierc09a1312019-04-09 16:05:26 +0200105 boolean sgsap_enable,
Harald Weltef9abf8d2019-04-21 13:07:17 +0200106 boolean gsup_enable,
Vadim Yanitskiy2dd96612020-01-07 21:48:29 +0100107 OCT4 gsup_sid,
Harald Weltec1f937a2019-04-21 21:19:23 +0200108 integer ran_idx,
Harald Welte9b751a62019-04-14 17:39:29 +0200109 boolean use_umts_aka,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200110 boolean ran_is_geran,
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200111 boolean use_osmux,
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200112 boolean use_ipv6,
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200113 boolean verify_cell_id,
114 OCT3 common_id_last_eutran_plmn optional
Harald Weltea49e36e2018-01-21 19:29:33 +0100115};
116
Harald Welte9de84792018-01-28 01:06:35 +0100117/* get a one-octet bitmaks of supported algorithms based on Classmark information */
Eric Wild26f4a622021-05-17 15:27:05 +0200118function 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 +0100119 var BIT8 res := '00000001'B; /* A5/0 always supported */
120
121 if (cm2.a5_1 == '0'B) {
122 res := res or4b '00000010'B;
123 }
124 if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) {
125 res := res or4b '00000100'B;
126 }
127 if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) {
128 res := res or4b '00001000'B;
129 }
Eric Wild26f4a622021-05-17 15:27:05 +0200130 if (not istemplatekind(cm3, "omit")) {
131 var BSSMAP_IE_ClassmarkInformationType3 v := valueof(cm3);
132 var BIT8 tmp := oct2bit(v.classmark3ValuePart[0]) and4b '00001111'B;
133 res := res or4b (tmp << 4);
134 }
135
Harald Welte9de84792018-01-28 01:06:35 +0100136 return bit2oct(res);
137}
138
139/* determine the best algorithm available within the bit-mask */
140function f_best_alg_from_mask(OCT1 alg_in) return OCT1 {
141 var BIT8 alg := oct2bit(alg_in);
142 var BIT8 ordered_algs[8] := {
143 '10000000'B, '01000000'B, '00100000'B, '00010000'B,
144 '00001000'B, /* A5/3 */
145 '00000010'B, /* A5/1 */
146 '00000100'B, /* A5/2 */
147 '00000001'B /* A5/0 */ }
148 for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) {
149 if (alg and4b ordered_algs[i] != '00000000'B) {
150 return bit2oct(ordered_algs[i]);
151 }
152 }
153 return '00'O;
154}
155
156/* return an integer like '1' for A5/1 based on a mask (with only one bit set */
157function f_alg_from_mask(OCT1 mask_in) return integer {
158 var BIT8 mask := oct2bit(mask_in);
159 for (var integer i := 0; i < 8; i := i+1) {
160 if (mask and4b ('00000001'B << i) != '00000000'B) {
161 return i;
162 }
163 }
164 return -1;
165}
166
Eric Wild26f4a622021-05-17 15:27:05 +0200167/* return true for A5/x supported by OCT1 bitmask */
168function f_alg_supported_by_mask(OCT1 mask_in, integer whicha5) return boolean {
169 var BIT8 mask := oct2bit(mask_in);
170 if (mask and4b ('00000001'B << whicha5) != '00000000'B) {
171 return true;
172 }
173 return false;
174}
175
Harald Weltea10db902018-01-27 12:44:49 +0100176/* altstep for the global guard timer */
177private altstep as_Tguard() runs on BSC_ConnHdlr {
178 [] g_Tguard.timeout {
Daniel Willmann90829d62018-02-15 17:45:14 +0100179 setverdict(fail, "Tguard timeout");
Daniel Willmannafce8662018-07-06 23:11:32 +0200180 mtc.stop;
Harald Weltea10db902018-01-27 12:44:49 +0100181 }
182}
183
184/* init function, called as first function in new BSC_ConnHdlr */
Harald Weltead2952e2018-01-27 14:12:46 +0100185function f_init_handler(BSC_ConnHdlrPars pars, float t_guard := 60.0) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100186 /* make parameters available via component variable */
187 g_pars := pars;
188 /* Start guard timer and activate it as default */
Harald Weltead2952e2018-01-27 14:12:46 +0100189 g_Tguard.start(t_guard);
Harald Weltea10db902018-01-27 12:44:49 +0100190 activate(as_Tguard());
Harald Weltef640a012018-04-14 17:49:21 +0200191 /* Route all SMPP messages for our MSISDN to us */
192 f_create_smpp_expect(hex2str(pars.msisdn));
Philipp Maier57865482019-01-07 18:33:13 +0100193
Harald Welte4263c522018-12-06 11:56:27 +0100194 /* Route all SGs message for our IMSI to us */
Philipp Maier57865482019-01-07 18:33:13 +0100195 if (g_pars.sgsap_enable == true) {
196 f_create_sgsap_expect(pars.imsi);
197 }
Philipp Maieraeb29a82018-11-08 17:40:53 +0100198
199 if (g_pars.ipa_ctrl_enable == true) {
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100200 f_ipa_ctrl_start_client(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port);
Philipp Maieraeb29a82018-11-08 17:40:53 +0100201 }
Philipp Maierc39a9d82018-11-09 11:21:08 +0100202
203 map(self:MSCVTY, system:MSCVTY);
204 f_vty_set_prompts(MSCVTY);
205 f_vty_transceive(MSCVTY, "enable");
Harald Weltea10db902018-01-27 12:44:49 +0100206}
207
Harald Weltea49e36e2018-01-21 19:29:33 +0100208
Harald Welte6811d102019-04-14 22:23:14 +0200209/* Callback function from general RAN_Emulation whenever a connectionless
Harald Weltea49e36e2018-01-21 19:29:33 +0100210 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
211private function BscUnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200212runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Weltea49e36e2018-01-21 19:29:33 +0100213 var template PDU_BSSAP resp := omit;
214
215 log("BSSMAP_BscUnitdataCallback");
216 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200217 if (match(bssap, tr_BSSMAP_Reset(g_ran_ops.use_osmux))){
Harald Weltea49e36e2018-01-21 19:29:33 +0100218 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200219 resp := ts_BSSMAP_ResetAck(g_ran_ops.use_osmux);
Harald Weltea49e36e2018-01-21 19:29:33 +0100220 }
221
222 /* FIXME: Handle paging, etc. */
223 return resp;
224}
225
Harald Welte9b751a62019-04-14 17:39:29 +0200226private function RncUnitdataCallback(RANAP_PDU ranap)
227runs on RAN_Emulation_CT return template RANAP_PDU {
228 var template RANAP_PDU resp := omit;
229
230 log("RANAP_RncUnitdataCallback");
231 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200232 if (match(ranap, tr_RANAP_Reset())) {
Harald Welte9b751a62019-04-14 17:39:29 +0200233 log("RANAP_RncUnitdataCallback: Responding to RESET with RESET-ACK");
234 var CN_DomainIndicator dom;
235 dom := ranap.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator;
236 resp := ts_RANAP_ResetAck(dom);
237 }
238
239 /* FIXME: Handle paging, etc. */
240 return resp;
241}
242
243
Harald Welte6811d102019-04-14 22:23:14 +0200244const RanOps BSC_RanOps := {
Harald Weltea49e36e2018-01-21 19:29:33 +0100245 /* Create call-back for inbound connections from MSC (hand-over) */
Harald Welte6811d102019-04-14 22:23:14 +0200246 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Weltea49e36e2018-01-21 19:29:33 +0100247 unitdata_cb := refers(BscUnitdataCallback),
Harald Welte9b751a62019-04-14 17:39:29 +0200248 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
249 ranap_unitdata_cb := refers(RncUnitdataCallback),
250 ps_domain := false,
Harald Weltea49e36e2018-01-21 19:29:33 +0100251 decode_dtap := true,
Harald Weltea4ca4462018-02-09 00:17:14 +0100252 role_ms := true,
Harald Welte2fce7882019-04-15 11:48:05 +0200253 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200254 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200255 use_osmux := false,
Harald Weltea4ca4462018-02-09 00:17:14 +0100256 sccp_addr_local := omit,
257 sccp_addr_peer := omit
Harald Weltea49e36e2018-01-21 19:29:33 +0100258}
259
260
261private function MnccUnitdataCallback(MNCC_PDU mncc)
262runs on MNCC_Emulation_CT return template MNCC_PDU {
263 log("Ignoring MNCC", mncc);
264 return omit;
265}
266
267const MnccOps BCC_MnccOps := {
268 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
269 unitdata_cb := refers(MnccUnitdataCallback)
270}
271
272
273
Harald Welte6811d102019-04-14 22:23:14 +0200274/* Encode 'l3' and ask RAN_Emulation to create new connection with COMPL L3 INFO */
Harald Weltea49e36e2018-01-21 19:29:33 +0100275function f_bssap_compl_l3(PDU_ML3_MS_NW l3)
276runs on BSC_ConnHdlr {
277 log("Sending COMPL L3: ", l3);
278 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
279 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
280 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc))));
Harald Welte71b69332018-01-21 20:43:53 +0100281 alt {
Harald Welte6811d102019-04-14 22:23:14 +0200282 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
283 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte71b69332018-01-21 20:43:53 +0100284 setverdict(fail, "DISC.ind from SCCP");
Daniel Willmannafce8662018-07-06 23:11:32 +0200285 mtc.stop;
Harald Welte71b69332018-01-21 20:43:53 +0100286 }
287 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100288}
289
Harald Welte9b751a62019-04-14 17:39:29 +0200290/* generate Iu LAI from BSSAP CGI */
291private function f_IuLAI_from_BssmapCI(BSSMAP_IE_CellIdentifier ci) return LAI {
292 var LAI lai;
293 if (ischosen(ci.cellIdentification.cI_CGI)) {
294 lai.pLMNidentity := ci.cellIdentification.cI_CGI.mcc_mnc;
295 lai.lAC := ci.cellIdentification.cI_CGI.lac;
296 } else if (ischosen(ci.cellIdentification.cI_SAI)) {
297 lai.pLMNidentity := ci.cellIdentification.cI_SAI.mcc_mnc;
298 lai.lAC := ci.cellIdentification.cI_SAI.lac;
299 } else if (ischosen(ci.cellIdentification.ci_LAC_RNC_CI)) {
300 lai.pLMNidentity := ci.cellIdentification.ci_LAC_RNC_CI.mcc_mnc;
301 lai.lAC := ci.cellIdentification.ci_LAC_RNC_CI.lac;
302 } else {
303 mtc.stop;
304 }
305 lai.iE_Extensions := omit;
306 return lai;
307}
308
309/* like f_bssap_compl_l3() but for 3G */
310function f_ranap_initial_ue(PDU_ML3_MS_NW l3)
311runs on BSC_ConnHdlr {
312 log("Sending InitialUE: ", l3);
313 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
314 var RANAP_PDU ranap;
315 var LAI lai := f_IuLAI_from_BssmapCI(g_pars.cell_id);
316 var SAI sai := {
317 pLMNidentity := lai.pLMNidentity,
318 lAC := lai.lAC,
319 sAC := '0000'O, /* FIXME */
320 iE_Extensions := omit
321 };
322 var IuSignallingConnectionIdentifier sigc_id := int2bit(23, 24);
323 var GlobalRNC_ID grnc_id := {
324 pLMNidentity := lai.pLMNidentity,
325 rNC_ID := 2342 /* FIXME */
326 };
327
328 ranap := valueof(ts_RANAP_initialUE_CS(lai, sai, l3_enc, sigc_id, grnc_id));
329 BSSAP.send(ts_RANAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, ranap));
330 alt {
331 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
332 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
333 setverdict(fail, "DISC.ind from SCCP");
334 mtc.stop;
335 }
336 }
337}
338
Harald Weltedceacc72019-04-21 20:58:35 +0200339/* Send BSSMAP Complete L3 or RANAP Initial UE depending on 2G/3G RAN type */
340function f_cl3_or_initial_ue(PDU_ML3_MS_NW l3)
341runs on BSC_ConnHdlr {
342 if (g_pars.ran_is_geran) {
343 f_bssap_compl_l3(l3);
344 } else {
345 f_ranap_initial_ue(l3);
346 }
347}
348
Harald Welte081b19a2018-02-10 09:11:13 +0100349type enumerated EstablishType {
350 EST_TYPE_MO_CALL,
Harald Welte0bef21e2018-02-10 09:48:23 +0100351 EST_TYPE_EMERG_CALL,
Harald Weltef45efeb2018-04-09 18:19:24 +0200352 EST_TYPE_PAG_RESP,
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700353 EST_TYPE_MO_SMS,
354 EST_TYPE_SS_ACT
Harald Welte081b19a2018-02-10 09:11:13 +0100355};
356
Harald Weltea49e36e2018-01-21 19:29:33 +0100357/* helper function to fully establish a dedicated channel */
Harald Welteb9e86fa2018-04-09 18:18:31 +0200358function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL)
Harald Weltea49e36e2018-01-21 19:29:33 +0100359runs on BSC_ConnHdlr {
Harald Welte081b19a2018-02-10 09:11:13 +0100360 var PDU_ML3_MS_NW l3_info;
Harald Welteb9e86fa2018-04-09 18:18:31 +0200361 var MobileIdentityLV mi;
362
363 /* If we have a TMSI, use TMSI instead of IMSI */
364 if (ispresent(g_pars.tmsi)) {
365 mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi));
366 } else {
367 mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
368 }
369
Harald Welte081b19a2018-02-10 09:11:13 +0100370 select (etype) {
371 case (EST_TYPE_MO_CALL) {
372 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
373 }
Harald Welte0bef21e2018-02-10 09:48:23 +0100374 case (EST_TYPE_EMERG_CALL) {
375 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi));
376 }
Harald Welte081b19a2018-02-10 09:11:13 +0100377 case (EST_TYPE_PAG_RESP) {
378 l3_info := valueof(ts_PAG_RESP(mi));
379 }
Harald Weltef45efeb2018-04-09 18:19:24 +0200380 case (EST_TYPE_MO_SMS) {
381 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi));
382 }
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700383 case (EST_TYPE_SS_ACT) {
384 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi));
385 }
Harald Welte081b19a2018-02-10 09:11:13 +0100386 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100387
388 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Weltedceacc72019-04-21 20:58:35 +0200389 f_cl3_or_initial_ue(l3_info);
Harald Weltea49e36e2018-01-21 19:29:33 +0100390
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200391 f_verify_vty_lac_ci(verify_vlr := false);
392
Harald Weltede371492018-01-27 23:44:41 +0100393 f_mm_common();
Pau Espin Pedrolf8034482019-06-03 13:15:58 +0200394 if (g_pars.net.expect_ciph or not g_pars.ran_is_geran) {
Harald Welte148a7082018-01-26 18:56:43 +0100395 /* implicit CM SERVICE ACCEPT? */
396 } else {
Harald Welte0bef21e2018-02-10 09:48:23 +0100397 if (etype != EST_TYPE_PAG_RESP) {
Harald Welte081b19a2018-02-10 09:11:13 +0100398 /* explicit CM SERVICE ACCEPT */
399 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
400 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100401 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100402}
403
404/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
Harald Welte9de84792018-01-28 01:06:35 +0100405function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100406{
407 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
408 return f_build_lu(mi);
409}
Harald Welte9de84792018-01-28 01:06:35 +0100410function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100411{
412 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
413 return f_build_lu(mi);
414}
Harald Welte9de84792018-01-28 01:06:35 +0100415function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100416{
417 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
418 return f_build_lu(mi);
419}
Harald Welte9de84792018-01-28 01:06:35 +0100420private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100421{
422 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
423 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 +0100424 old_lai, mi, g_pars.cm1));
Harald Weltea49e36e2018-01-21 19:29:33 +0100425 return l3_info;
426}
427
Harald Weltea183a5d2019-05-09 13:40:52 +0200428altstep as_GSUP_SAI() runs on BSC_ConnHdlr {
429var GSUP_IE auth_tuple;
430[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)) {
431 if (g_pars.use_umts_aka) {
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +0200432 if (not g_pars.vec_keep) {
433 g_pars.vec := f_gen_auth_vec_3g();
434 }
Harald Weltea183a5d2019-05-09 13:40:52 +0200435 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand,
436 g_pars.vec.sres,
437 g_pars.vec.kc,
438 g_pars.vec.ik,
439 g_pars.vec.ck,
440 g_pars.vec.autn,
441 g_pars.vec.res));
442 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
443 } else {
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +0200444 if (not g_pars.vec_keep) {
445 g_pars.vec := f_gen_auth_vec_2g();
446 }
Harald Weltea183a5d2019-05-09 13:40:52 +0200447 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand,
448 g_pars.vec.sres,
449 g_pars.vec.kc));
450 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
451 }
452 }
453}
454
Harald Welte9de84792018-01-28 01:06:35 +0100455function f_mm_auth() runs on BSC_ConnHdlr
Harald Welte148a7082018-01-26 18:56:43 +0100456{
Harald Weltede371492018-01-27 23:44:41 +0100457 if (g_pars.net.expect_auth) {
Harald Weltea183a5d2019-05-09 13:40:52 +0200458 as_GSUP_SAI();
Harald Weltec1f937a2019-04-21 21:19:23 +0200459 if (g_pars.use_umts_aka) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200460 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn)));
461 var OCT4 res := substr(g_pars.vec.res, 0, 4);
462 var OCT4 xres := substr(g_pars.vec.res, 4, 4);
463 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres)));
464 } else {
Harald Weltec1f937a2019-04-21 21:19:23 +0200465 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand)));
466 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres)));
467 }
Harald Welte148a7082018-01-26 18:56:43 +0100468 }
Harald Welte9de84792018-01-28 01:06:35 +0100469}
Harald Welte148a7082018-01-26 18:56:43 +0100470
Oliver Smith1d118ff2019-07-03 10:57:35 +0200471function f_mm_imei() runs on BSC_ConnHdlr
472{
473 var PDU_DTAP_MT dtap_mt;
474 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700475 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200476
477 if (not g_pars.net.expect_imei) {
478 return
479 }
480
481 /* MSC <-> BSC: ID req/rsp for IMEI */
482 alt {
483 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEI))) {
484 mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
485 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
486 }
487 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
488 setverdict(fail, "Expected ID REQ for IMEI DTAP MT message, but got: ", dtap_mt);
489 mtc.stop;
490 }
491 }
492
493 /* MSC <-> HLR: Check IMEI req/res/err */
494 alt {
495 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
496 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
497 }
498 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
499 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
500 }
501 [] GSUP.receive(?) -> value gsup_msg {
502 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
503 g_pars.imsi, "), but got: ", gsup_msg);
504 mtc.stop;
505 }
506 }
507}
508
509function f_mm_imei_early() runs on BSC_ConnHdlr
510{
511 var PDU_DTAP_MT dtap_mt;
512 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700513 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200514
515 if (not g_pars.net.expect_imei_early) {
516 return
517 }
518
519 /* MSC <-> BSC: ID req/rsp for IMEISV */
520 alt {
521 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEISV))) {
522 mi := valueof(ts_MI_IMEISV_LV(g_pars.imei));
523 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
524 }
525 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
526 setverdict(fail, "Expected ID REQ for IMEISV DTAP MT message, but got: ", dtap_mt);
527 mtc.stop;
528 }
529 }
530
531 /* MSC <-> HLR: Check IMEI req/res/err */
532 alt {
533 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
534 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
535 }
536 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
537 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
538 }
539 [] GSUP.receive(?) -> value gsup_msg {
540 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
541 g_pars.imsi, "), but got: ", gsup_msg);
542 mtc.stop;
543 }
544 }
545}
546
Harald Welte79f1e452020-08-18 22:55:02 +0200547function f_expect_common_id() runs on BSC_ConnHdlr
548{
549 if (g_pars.ran_is_geran) {
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200550 BSSAP.receive(tr_BSSMAP_CommonId(g_pars.imsi,
551 f_tr_BSSMAP_LastUsedEUTRANPLMNId(g_pars.common_id_last_eutran_plmn)));
Harald Welte79f1e452020-08-18 22:55:02 +0200552 } else {
553 BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
554 }
555}
556
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200557/* For UMTS AKA on GERAN, calculate the specific kc from the UMTS AKA ck and ik vectors. */
558function f_auth3g_kc(AuthVector vec) return OCT8 {
Eric Wild26f4a622021-05-17 15:27:05 +0200559 var integer i;
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200560 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 +0200561 for (i := 1; i < 8; i := i + 1) {
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200562 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 +0200563 res := res & a;
564 }
565
566 return res;
567}
568
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200569function f_get_expected_encryption(
570 out template BSSMAP_IE_EncryptionInformation encryptionInformation,
571 out template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm,
572 out template BSSMAP_IE_KC128 kC128,
573 out OCT1 a5_perm_alg) runs on BSC_ConnHdlr
574{
575 var OCT1 a5_ms := f_alg_mask_from_cm(g_pars.cm2, g_pars.cm3);
576 a5_perm_alg := g_pars.net.kc_support and4b a5_ms;
577
578 if (not g_pars.net.expect_ciph) {
579 encryptionInformation := *;
580 chosenEncryptionAlgorithm := *;
581 kC128 := *;
582 return;
583 }
584
Neels Hofmeyrf6eff812021-06-23 23:29:39 +0200585 var OCT8 kc;
586 if (g_pars.use_umts_aka) {
587 kc := f_auth3g_kc(g_pars.vec);
588 } else {
589 kc := g_pars.vec.kc;
590 }
591 encryptionInformation := tr_BSSMAP_IE_EncrInfo(kc, a5_perm_alg);
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200592
593 var OCT1 chosen_alg := int2oct(f_alg_from_mask(f_best_alg_from_mask(a5_perm_alg)) + 1, 1);
594 chosenEncryptionAlgorithm := tr_BSSMAP_IE_ChosenEncryptionAlgorithm(chosen_alg);
595
596 if (g_pars.use_umts_aka and f_alg_supported_by_mask(a5_perm_alg, 4)) {
597 /* A5/4 is permitted, expecting kc128 to be present */
598 var OCT32 full_sha256 := f_calculate_HMAC_SHA256(g_pars.vec.ck & g_pars.vec.ik, '32'O, 32);
599 var OCT16 expect_kc128 := substr(full_sha256, 0, 16);
600 kC128 := tr_BSSMAP_IE_Kc128(expect_kc128);
601 } else {
602 kC128 := omit
603 }
604}
605
Eric Wild26f4a622021-05-17 15:27:05 +0200606
Harald Welte9de84792018-01-28 01:06:35 +0100607function f_mm_common() runs on BSC_ConnHdlr
608{
609 f_mm_auth();
Harald Welte9b751a62019-04-14 17:39:29 +0200610 if (g_pars.ran_is_geran) {
611 if (g_pars.net.expect_ciph) {
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200612 var template BSSMAP_IE_EncryptionInformation encryptionInformation;
613 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm;
614 var template BSSMAP_IE_KC128 kC128;
615 var OCT1 a5_perm_alg;
616 f_get_expected_encryption(encryptionInformation, chosenEncryptionAlgorithm, kC128, a5_perm_alg);
Eric Wild26f4a622021-05-17 15:27:05 +0200617
618 var PDU_BSSAP pdu;
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200619 var template PDU_BSSAP expect_ciph_mode_cmd := tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128);
Harald Welte9b751a62019-04-14 17:39:29 +0200620 alt {
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200621 [] BSSAP.receive(expect_ciph_mode_cmd) -> value pdu {
622 var OCT1 a5_chosen := f_best_alg_from_mask(a5_perm_alg);
Harald Welte9b751a62019-04-14 17:39:29 +0200623 var integer a5_nr := f_alg_from_mask(a5_chosen);
624 BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
625 }
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200626 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2) -> value pdu {
627 log("Error: Ciphering Mode Command with unexpected content. Expected: ",
628 expect_ciph_mode_cmd, " got: ", pdu);
629 setverdict(fail, "Ciphering Mode Command with unexpected content.");
Harald Welte9b751a62019-04-14 17:39:29 +0200630 mtc.stop;
631 }
Eric Wild26f4a622021-05-17 15:27:05 +0200632 [] BSSAP.receive(tr_BSSMAP_ClassmarkRequest) {
633 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3))
634 repeat;
635 }
Harald Welte9de84792018-01-28 01:06:35 +0100636 }
Harald Welte9b751a62019-04-14 17:39:29 +0200637 /* FIXME: Send the best available algorithm */
638 }
Harald Welte79f1e452020-08-18 22:55:02 +0200639 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200640 } else { /* UTRAN */
641 alt {
642 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
643 uia_key := oct2bit(g_pars.vec.ik),
644 key_sts := ?,
645 uea_algs := ?,
646 uea_key := oct2bit(g_pars.vec.ck))) {
647 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/
648 var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/
649 BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen));
Harald Welte79f1e452020-08-18 22:55:02 +0200650 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200651 }
652 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
653 setverdict(fail, "Invalid SecurityModeCommand (ciphering case)");
654 mtc.stop;
655 }
656 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
657 uia_key := oct2bit(g_pars.vec.ik),
658 key_sts := ?)) {
659 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/
660 BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
Harald Welte79f1e452020-08-18 22:55:02 +0200661 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200662 }
663 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
664 setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)");
Daniel Willmannafce8662018-07-06 23:11:32 +0200665 mtc.stop;
Harald Welte9de84792018-01-28 01:06:35 +0100666 }
667 }
Harald Welte148a7082018-01-26 18:56:43 +0100668 }
669}
670
Philipp Maier9b690e42018-12-21 11:50:03 +0100671function f_expect_mm_info() runs on BSC_ConnHdlr {
672 if (g_pars.mm_info == true) {
673 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info));
674 }
675}
676
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200677private function f_lac_ci_vty_str(BSSMAP_IE_CellIdentifier cell_id) return charstring
678{
679 return "LAC / cell ID: "
680 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.lac)) & " / "
681 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.ci));
682}
683
684/* Get an IMSI's info and verify that the g_pars.cell_id is reflected in the info.
685 * Verify both the "LAC / cell ID" in the VLR and the "LAC / cell ID" in the "Connection:" part, if any.
686 * If verify_vlr == false, then only verify the "Connection:" part, and fail if there is no "Connection:"; this is
687 * useful when a conn has been established, but the subscriber has not been authenticated, so the VLR does not yet
688 * reflect the new conn's cell ID.
689 */
690function f_verify_vty_lac_ci(boolean verify_vlr := true) runs on BSC_ConnHdlr {
691 if (not g_pars.ran_is_geran) {
692 log("Skipping f_verify_vty_lac_ci(), disabled for Iu");
693 setverdict(pass);
694 return;
695 }
696 if (not g_pars.verify_cell_id) {
697 /* Skip this verification; either the TC expects no cell id to end up being accepted, or this was
698 * disabled globally to test an older osmo-msc which doesn't store the cell id properly yet. */
699 log("Skipping f_verify_vty_lac_ci()");
700 setverdict(pass);
701 return;
702 }
703
704 var charstring vty_cmd := "show subscriber imsi " & hex2str(g_pars.imsi) & " conn";
705 var charstring result := f_vty_transceive_ret(MSCVTY, vty_cmd);
706 var charstring expect_lac_ci := "LAC / cell ID: "
707 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.lac)) & " / "
708 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.ci));
709
710 var boolean vlr_matches := false;
711 var boolean connection_present := false;
712 var boolean connection_matches := false;
713
714 /* There are two occurences of LAC / cell ID: once for the VLR record, and once for the active connection. The
715 * active connection part starts with 'Connection:'. If there is no active connection, that part is omitted.
716 * So, first find out whether there is a 'Connection:' part. Then verify the LAC / cell ID above 'Connection:'
717 * and below 'Connection:', separately.
718 */
719 var integer connection_start := f_strstr(result, "Connection:");
720 connection_present := (connection_start >= 0);
721
722 var integer lac_ci_match := f_strstr(result, expect_lac_ci);
723 if (connection_present) {
724 if (lac_ci_match > connection_start) {
725 /* The first match is below 'Connection:', so the VLR part above it did not match. */
726 vlr_matches := false;
727 connection_matches := true;
728 } else if (lac_ci_match >= 0) {
729 /* The first match is above 'Connection:', so the VLR part matches. */
730 vlr_matches := true;
731
732 /* Now find a match below 'Connection:' */
733 lac_ci_match := f_strstr(result, expect_lac_ci, connection_start);
734 connection_matches := (lac_ci_match > 0);
735 }
736 } else {
737 /* There is no 'Connection:', so a match, if any, is from the VLR part. */
738 vlr_matches := (lac_ci_match >= 0);
739 }
740
741 if (verify_vlr) {
742 if (not vlr_matches) {
743 setverdict(fail, vty_cmd, " shows mismatching LAC / cell ID in the VLR part, expecting: ",
744 expect_lac_ci, " -- got: ", result);
745 return;
746 } else {
747 log("f_verify_vty_lac_ci(): VLR record matches ", expect_lac_ci);
748 setverdict(pass);
749 }
750 }
751
752 if (connection_present) {
753 if (not connection_matches) {
754 setverdict(fail, vty_cmd, " shows mismatching LAC cell ID in the 'Connection' part, expecting: ",
755 expect_lac_ci, " -- got: ", result);
756 } else {
757 log("f_verify_vty_lac_ci(): Active connection matches ", expect_lac_ci);
758 setverdict(pass);
759 }
760 }
761
762 if (not verify_vlr and not connection_present) {
763 setverdict(fail, "f_verify_vty_lac_ci(verify_vlr := false) called, which requires an active connection, but there is no 'Connection:' part to verify in ", result);
764 }
765}
766
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100767function f_perform_lu()
Harald Weltea49e36e2018-01-21 19:29:33 +0100768runs on BSC_ConnHdlr {
769 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
770 var PDU_DTAP_MT dtap_mt;
771
772 /* tell GSUP dispatcher to send this IMSI to us */
773 f_create_gsup_expect(hex2str(g_pars.imsi));
774
775 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Welte9b751a62019-04-14 17:39:29 +0200776 if (g_pars.ran_is_geran) {
777 f_bssap_compl_l3(l3_lu);
778 if (g_pars.send_early_cm) {
779 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
780 }
781 } else {
782 f_ranap_initial_ue(l3_lu);
Harald Welte8a121b32018-01-22 03:00:41 +0100783 }
Harald Welte5c2622c2018-01-21 20:45:20 +0100784
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200785 /* at this point the conn has been established, but the subscriber has not been authenticated, so the VLR does
786 * not yet reflect this conn's cell ID. */
787 f_verify_vty_lac_ci(verify_vlr := false);
788
Oliver Smith1d118ff2019-07-03 10:57:35 +0200789 f_mm_imei_early();
Harald Weltede371492018-01-27 23:44:41 +0100790 f_mm_common();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100791 f_msc_lu_hlr();
Oliver Smith1d118ff2019-07-03 10:57:35 +0200792 f_mm_imei();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100793 f_accept_reject_lu();
794 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
795 f_expect_clear();
Harald Welte16114282018-01-24 22:41:21 +0100796
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100797 setverdict(pass);
798}
799
800function f_msc_lu_hlr() runs on BSC_ConnHdlr
801{
Harald Weltea49e36e2018-01-21 19:29:33 +0100802 /* Expect MSC to perform LU with HLR */
803 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
804 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
805 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
806 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100807}
808
809function f_accept_reject_lu() runs on BSC_ConnHdlr {
810 var PDU_DTAP_MT dtap_mt;
Harald Weltea49e36e2018-01-21 19:29:33 +0100811
812 alt {
813 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
814 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
Harald Weltede371492018-01-27 23:44:41 +0100815 if (g_pars.net.expect_tmsi) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100816 if (not ispresent(lu_acc.mobileIdentityTLV) or
817 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
818 setverdict(fail, "Expected TMSI but no TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200819 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100820 } else {
Harald Welte256571e2018-01-24 18:47:19 +0100821 g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets;
Harald Weltea49e36e2018-01-21 19:29:33 +0100822 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
823 }
824 } else {
825 if (ispresent(lu_acc.mobileIdentityTLV) and
826 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
827 setverdict(fail, "Expected no TMSI but TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200828 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100829 }
830 }
831 }
832 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
833 setverdict(fail, "Expected LU ACK, but received LU REJ");
Daniel Willmannafce8662018-07-06 23:11:32 +0200834 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100835 }
836 }
Philipp Maier9b690e42018-12-21 11:50:03 +0100837
838 /* Wait for MM-Information (if enabled) */
839 f_expect_mm_info();
Harald Weltea49e36e2018-01-21 19:29:33 +0100840 setverdict(pass);
841}
842
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100843function f_expect_lu_reject(template OCT1 cause := ?) runs on BSC_ConnHdlr {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200844 var PDU_DTAP_MT dtap_mt;
845 timer T := 5.0;
846
847 T.start;
848 alt {
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100849 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej(cause))) {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200850 setverdict(pass);
851 }
852 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
853 setverdict(fail, "Expected LU reject BSSAP message, got: ", dtap_mt);
854 }
855 [] T.timeout {
856 setverdict(fail, "Timeout waiting for LU reject");
857 }
858 }
859}
860
Harald Weltea49e36e2018-01-21 19:29:33 +0100861function f_foo() runs on BSC_ConnHdlr{
Harald Welte6811d102019-04-14 22:23:14 +0200862 /* SCCP CC handled by RAN_Emulation_CT.main() */
Harald Weltea49e36e2018-01-21 19:29:33 +0100863 /* Expect auth, if enabled */
864
865 /* TODO: ISD */
866 /* Expect encr, if enabled */
867 /* Expect encr, if enabled */
868 /* Expect ASS CMD, if chan_type != requested */
869 /* Send ASS CMPL in successful case */
870
871 /* Expect AoIP port/ip information for RTP stream */
872 /* Expect MSC-originated MGCP to our simulated MGW */
873 /* Verify Counters via CTRL */
874 /* re-configure MSC behaviour via VTY */
875}
876
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200877type record CrcxResponse {
878 integer resp, /* 1 = reply with OK, 0 = do not reply, -1 = reply with error */
879 HostName mgw_rtp_ip,
880 PortNumber mgw_rtp_port,
881 MgcpConnectionId mgcp_connection_id /* MGCP Connection ID BSS Side */
882}
883
Harald Welteb71901a2018-01-26 19:16:05 +0100884/* parameters related to a (MO?) voice call */
885type record CallParameters {
Harald Welteb71901a2018-01-26 19:16:05 +0100886 /* CC related parameters */
887 hexstring called_party, /* whom are we calling */
888 integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100889 boolean mo_call, /* For a MO call, the transaction_id was allocated by the MS,
890 important to set the TI flag properly */
Harald Welteb71901a2018-01-26 19:16:05 +0100891 BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */
Harald Welte0bef21e2018-02-10 09:48:23 +0100892 boolean emergency, /* is this an emergency call? */
Harald Welteb71901a2018-01-26 19:16:05 +0100893
894 /* MNCC related parameters */
895 uint32_t mncc_callref optional, /* call reference on the MNCC side */
896 MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200897 HostName mncc_rtp_ip optional, /* MNCC Side RTP IP */
898 PortNumber mncc_rtp_port optional, /* MNCC Side RTP port */
Harald Welteb71901a2018-01-26 19:16:05 +0100899
900 /* RTP related parameters */
901 HostName bss_rtp_ip optional, /* BSS Side RTP IP */
902 PortNumber bss_rtp_port optional, /* BSS Side RTP Port */
903 HostName mss_rtp_ip optional, /* MSS Side RTP IP */
904 PortNumber mss_rtp_port optional, /* MSS Side RTP Port */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200905 integer got_crcx_count,
906 CrcxResponse mgw_conn_1,
907 CrcxResponse mgw_conn_2,
Harald Welteb71901a2018-01-26 19:16:05 +0100908 uint7_t rtp_payload_type, /* dynamic RTP payload type */
909 charstring rtp_sdp_format, /* AMR/8000 or the like */
Philipp Maier2a98a732018-03-19 16:06:12 +0100910 boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX
911 (f_mt_call and f_mt_call) */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200912 boolean stop_after_cc_setup, /* Special case: stop call establish after CC Setup */
913 boolean ran_clear_when_alerting, /* Special case: send Clear upon CC Alerting */
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100914 boolean expect_release, /* Special case: expect call establish to cause direct CC Rel */
Harald Welteb71901a2018-01-26 19:16:05 +0100915
Philipp Maiercd668572018-03-19 16:11:52 +0100916 MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */
Harald Welteb71901a2018-01-26 19:16:05 +0100917 MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200918
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200919 boolean use_osmux, /* MSC is expected to use Osmux for this call */
920 integer got_osmux_count
Harald Welteb71901a2018-01-26 19:16:05 +0100921}
922
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200923template (value) CallParameters t_CallParams(hexstring called := '12345'H, integer tid := 0) := {
Harald Welteb71901a2018-01-26 19:16:05 +0100924 called_party := called,
925 transaction_id := tid,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100926 mo_call := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100927 bearer_cap := valueof(ts_Bcap_voice),
Harald Welte0bef21e2018-02-10 09:48:23 +0100928 emergency := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100929 mncc_callref := omit,
930 mncc_bearer_cap := valueof(ts_MNCC_bcap_voice),
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200931 mncc_rtp_ip := "42.23.11.5",
932 mncc_rtp_port := 423,
Harald Welte4017d552018-01-26 21:40:05 +0100933 bss_rtp_ip := "9.8.7.6",
934 bss_rtp_port := 9000,
Harald Welteb71901a2018-01-26 19:16:05 +0100935 mss_rtp_ip := omit,
936 mss_rtp_port := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200937 got_crcx_count := 0,
938 mgw_conn_1 := {
939 resp := 1,
940 mgw_rtp_ip := "1.1.1.1",
941 mgw_rtp_port := 10000,
942 mgcp_connection_id := '11111'H
943 },
944 mgw_conn_2 := {
945 resp := 1,
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +0200946 mgw_rtp_ip := "2.2.2.2",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200947 mgw_rtp_port := 11000,
948 mgcp_connection_id := '22222'H
949 },
Harald Welteb71901a2018-01-26 19:16:05 +0100950 rtp_payload_type := 98,
951 rtp_sdp_format := "AMR/8000",
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100952 mgw_drop_dlcx := false,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200953 stop_after_cc_setup := false,
954 ran_clear_when_alerting := false,
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100955 expect_release := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100956 mgcp_call_id := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200957 mgcp_ep := "rtpbridge/1@mgw",
958 use_osmux := false,
959 got_osmux_count := 0
Harald Welteb71901a2018-01-26 19:16:05 +0100960};
961
Harald Welte4263c522018-12-06 11:56:27 +0100962/* Allocate a call reference and send SETUP via MNCC to MSC */
963function f_mt_call_initate(inout CallParameters cpars)
Harald Welte33ec09b2018-02-10 15:34:46 +0100964runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200965 cpars.mo_call := false;
Harald Welte4263c522018-12-06 11:56:27 +0100966 cpars.mncc_callref := f_rnd_int(2147483648);
967 MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
968 hex2str(cpars.called_party), hex2str(g_pars.imsi)));
969}
Harald Welte33ec09b2018-02-10 15:34:46 +0100970
Harald Welte408a7ef2019-04-21 17:08:40 +0200971private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) :=
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200972 ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
Harald Welte408a7ef2019-04-21 17:08:40 +0200973 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200974 cpars.mgw_conn_2.mgw_rtp_port,
Harald Welte408a7ef2019-04-21 17:08:40 +0200975 { int2str(cpars.rtp_payload_type) },
976 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
977 cpars.rtp_sdp_format)),
978 valueof(ts_SDP_ptime(20)) });
979
Harald Welte4263c522018-12-06 11:56:27 +0100980/* Complete call, begin with a paging response message via BSSAP */
981function f_mt_call_complete(inout CallParameters cpars)
982runs on BSC_ConnHdlr {
Harald Welte33ec09b2018-02-10 15:34:46 +0100983 var MNCC_PDU mncc;
984 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200985 var template MgcpResponse mgcp_resp;
986 var MgcpOsmuxCID osmux_cid;
987 var PDU_BSSAP bssap;
Harald Welte33ec09b2018-02-10 15:34:46 +0100988
Harald Welte6811d102019-04-14 22:23:14 +0200989 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Welte33ec09b2018-02-10 15:34:46 +0100990
Harald Welteb9e86fa2018-04-09 18:18:31 +0200991 f_establish_fully(EST_TYPE_PAG_RESP);
Harald Welte33ec09b2018-02-10 15:34:46 +0100992
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100993 log("f_mt_call_complete 1");
994
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200995 cpars.got_osmux_count := 0;
996
Harald Welte33ec09b2018-02-10 15:34:46 +0100997 /* MS <- MSC: Expect CC SETUP */
998 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party)));
999
1000 /* MS -> MSC: ALERTING */
1001 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id)));
1002 MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001003 log("f_mt_call_complete 2");
Harald Welte33ec09b2018-02-10 15:34:46 +01001004
Harald Welte33ec09b2018-02-10 15:34:46 +01001005 /* Create MGCP expect */
1006 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1007 /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */
1008 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1009
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001010 /* First MGCP CRCX */
Harald Welte33ec09b2018-02-10 15:34:46 +01001011 MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001012 log("f_mt_call_complete 3");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001013 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1014 return;
Philipp Maier4b2692d2018-03-14 16:37:48 +01001015 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001016 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001017
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001018
Harald Welte9b751a62019-04-14 17:39:29 +02001019 if (g_pars.ran_is_geran) {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001020 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001021 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Harald Welte9b751a62019-04-14 17:39:29 +02001022
1023 interleave {
1024 /* Second MGCP CRCX (this time for MSS/CN side) */
1025 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001026 log("f_mt_call_complete 4");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001027 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1028 break;
1029 }
Harald Welte9b751a62019-04-14 17:39:29 +02001030 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001031
1032 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1033 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1034 log("f_mt_call_complete 5");
1035 }
1036
Harald Welte9b751a62019-04-14 17:39:29 +02001037 /* expect the MSC to trigger a BSSMAP ASSIGNMENT */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001038 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001039 var template BSSMAP_IE_AoIP_TransportLayerAddress tla;
Harald Welte9b751a62019-04-14 17:39:29 +02001040 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001041 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001042 log("f_mt_call_complete 6");
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001043 tla := f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port);
Harald Welte9b751a62019-04-14 17:39:29 +02001044 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
1045
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001046 if (cpars.use_osmux) {
1047 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1048 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1049 mtc.stop;
1050 }
1051 osmuxCID := valueof(ts_OsmuxCID(0));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001052 if (not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1053 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 +02001054 mtc.stop;
1055 }
1056 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1057 } else {
1058 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1059 }
1060 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001061
1062 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
Harald Welte9b751a62019-04-14 17:39:29 +02001063 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001064
1065 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1066 log("f_mt_call_complete 7");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001067 var octetstring ip;
1068 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1069 if (is_ipv6) {
1070 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1071 } else {
1072 ip := f_inet_addr(cpars.mncc_rtp_ip);
1073 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001074 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001075 is_ipv6, ip,
1076 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001077 /* payload type 3 = GSM FR */ 3));
1078 }
1079
1080 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1081 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1082 log("f_mt_call_complete 8");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001083 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 +01001084 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001085 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001086 { int2str(cpars.rtp_payload_type) },
1087 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1088 cpars.rtp_sdp_format)),
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001089 valueof(ts_SDP_ptime(20)) }));
1090 if (cpars.use_osmux) {
1091 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1092 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1093 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1094 mtc.stop;
1095 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001096 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 +02001097 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001098 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 +02001099 }
1100 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001101 }
1102
1103 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1104 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001105 var SDP_Message sdp;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001106 log("f_mt_call_complete 9");
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001107
1108 if (isvalue(mgcp_cmd.sdp)) {
1109 sdp := mgcp_cmd.sdp;
1110 if (sdp.media_list[0].media_field.ports.port_number != cpars.mncc_rtp_port) {
1111 setverdict(fail, "Wrong MDCX Connection port received, expected ", cpars.mncc_rtp_port, " and received ", sdp.media_list[0].media_field.ports.port_number)
1112 mtc.stop;
1113 }
1114 if (sdp.connection.conn_addr.addr != cpars.mncc_rtp_ip) {
1115 setverdict(fail, "Wrong MDCX Connection address received, expected ", cpars.mncc_rtp_ip, " and received ", sdp.connection.conn_addr.addr)
1116 mtc.stop;
1117 }
1118 }
1119
1120 sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1121 hex2str(cpars.mgcp_call_id), "42",
1122 cpars.mgw_conn_2.mgw_rtp_port,
1123 { int2str(cpars.rtp_payload_type) },
1124 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1125 cpars.rtp_sdp_format)),
1126 valueof(ts_SDP_ptime(20)) }));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001127 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 +01001128 }
1129
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001130 }
Harald Welte9b751a62019-04-14 17:39:29 +02001131 } else {
Harald Welte9b751a62019-04-14 17:39:29 +02001132 interleave {
1133 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001134 log("f_mt_call_complete 4.iu");
1135 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1136 break;
Harald Welte9b751a62019-04-14 17:39:29 +02001137 }
Harald Welte9b751a62019-04-14 17:39:29 +02001138 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001139
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001140 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1141 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1142 log("f_mt_call_complete 5.iu");
1143 }
1144
1145 [] BSSAP.receive(tr_RANAP_RabAssReq(?)) {
1146 log("f_mt_call_complete 6.iu");
1147 var RAB_SetupOrModifiedList l := {
1148 {
1149 {
1150 id := id_RAB_SetupOrModifiedItem,
1151 criticality := ignore,
1152 value_ := {
1153 rAB_SetupOrModifiedItem := {
1154 rAB_ID := int2bit(23, 8),
1155 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1156 iuTransportAssociation := {
1157 bindingID := '040c0000'O
1158 },
1159 dl_dataVolumes := omit,
1160 iE_Extensions := omit
1161 }
1162 }
1163 }
1164 }
1165 };
1166 BSSAP.send(ts_RANAP_RabAssResp(l));
1167
1168 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
1169 }
1170
1171 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1172 log("f_mt_call_complete 7.iu");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001173 var octetstring ip;
1174 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1175 if (is_ipv6) {
1176 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1177 } else {
1178 ip := f_inet_addr(cpars.mncc_rtp_ip);
1179 }
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001180 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001181 is_ipv6, ip,
1182 cpars.mncc_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001183 /* payload type 3 = GSM FR */ 3));
1184 }
1185
1186 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1187 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1188 log("f_mt_call_complete 8.iu");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001189 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 +01001190 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001191 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001192 { int2str(cpars.rtp_payload_type) },
1193 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1194 cpars.rtp_sdp_format)),
1195 valueof(ts_SDP_ptime(20)) }));
1196 if (cpars.use_osmux) {
1197 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1198 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1199 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1200 mtc.stop;
1201 }
1202 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
1203 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001204 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 +01001205 }
1206 MGCP.send(mgcp_resp);
1207 }
1208
1209 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1210 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1211 log("f_mt_call_complete 9.iu");
1212 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1213 hex2str(cpars.mgcp_call_id), "42",
1214 cpars.mgw_conn_2.mgw_rtp_port,
1215 { int2str(cpars.rtp_payload_type) },
1216 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1217 cpars.rtp_sdp_format)),
1218 valueof(ts_SDP_ptime(20)) }));
1219 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
1220 }
1221
Harald Welte33ec09b2018-02-10 15:34:46 +01001222 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001223 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001224
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001225 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1226 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1227 } else {
1228 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1229 mtc.stop;
1230 }
1231
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001232 log("f_mt_call_complete DONE");
Harald Welte4263c522018-12-06 11:56:27 +01001233}
1234
Harald Weltee035e3e2019-04-21 17:32:05 +02001235function f_expect_paging(boolean by_tmsi := true)
1236runs on BSC_ConnHdlr {
Harald Welte9b751a62019-04-14 17:39:29 +02001237 if (g_pars.ran_is_geran) {
1238 BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
1239 } else {
Harald Welte62113fc2019-05-09 13:04:02 +02001240 BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi)));
Harald Welte9b751a62019-04-14 17:39:29 +02001241 }
Harald Weltee035e3e2019-04-21 17:32:05 +02001242}
1243
Harald Welte4263c522018-12-06 11:56:27 +01001244function f_mt_call_establish(inout CallParameters cpars)
1245runs on BSC_ConnHdlr {
1246
1247 /* Initiate the call via MNCC */
1248 f_mt_call_initate(cpars);
1249
1250 /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
Harald Welte6811d102019-04-14 22:23:14 +02001251 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Weltee035e3e2019-04-21 17:32:05 +02001252 f_expect_paging()
Harald Welte4263c522018-12-06 11:56:27 +01001253
1254 /* Complete the call via BSSAP */
1255 f_mt_call_complete(cpars);
Harald Welte33ec09b2018-02-10 15:34:46 +01001256
Harald Welte33ec09b2018-02-10 15:34:46 +01001257 setverdict(pass);
1258}
1259
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001260/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1261 * Return true when an OK reply was sent, false otherwise.
1262 * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */
1263function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd)
1264runs on BSC_ConnHdlr
1265return boolean {
1266 var CrcxResponse conn := cpars.mgw_conn_1;
1267 if (cpars.got_crcx_count > 0) {
1268 conn := cpars.mgw_conn_2;
1269 }
1270 cpars.got_crcx_count := cpars.got_crcx_count + 1;
1271
1272 var MgcpMessage mgcp_msg := {
1273 command := mgcp_cmd
1274 }
1275 var template MgcpResponse mgcp_resp;
1276 var MgcpOsmuxCID osmux_cid;
1277 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1278 if (ispresent(cpars.mgcp_call_id)) {
1279 if (cpars.mgcp_call_id != call_id) {
1280 setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id);
1281 mtc.stop;
1282 }
1283 } else {
1284 cpars.mgcp_call_id := call_id;
1285 }
1286
1287 /* When the endpoint contains a wildcard we keep the endpoint
1288 * identifier we have set up in cpars. Otherwise we use the
1289 * endpoint name that the call agent has supplied */
1290 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1291 cpars.mgcp_ep := mgcp_cmd.line.ep;
1292 }
1293
1294 if (conn.resp == -1) {
1295 /* Reply with error */
1296 var MgcpResponse mgcp_rsp := {
1297 line := {
1298 code := "542",
1299 trans_id := mgcp_cmd.line.trans_id,
1300 string := "FORCED_FAIL"
1301 },
1302 sdp := omit
1303
1304 }
1305 var MgcpParameter mgcp_rsp_param := {
1306 code := "Z",
1307 val := cpars.mgcp_ep
1308 };
1309 mgcp_rsp.params[0] := mgcp_rsp_param;
1310 MGCP.send(mgcp_rsp);
1311 return false;
1312 }
1313
1314 if (conn.resp == 0) {
1315 /* Do not reply at all */
1316 return false;
1317 }
1318
1319 if (conn.resp != 1) {
1320 setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1");
1321 mtc.stop;
1322 }
1323
1324 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1325 hex2str(cpars.mgcp_call_id), "42",
1326 conn.mgw_rtp_port,
1327 { int2str(cpars.rtp_payload_type) },
1328 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1329 cpars.rtp_sdp_format)),
1330 valueof(ts_SDP_ptime(20)) }));
1331
1332 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1333 if (not cpars.use_osmux) {
1334 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1335 mtc.stop;
1336 }
1337 cpars.got_osmux_count := cpars.got_osmux_count + 1;
1338 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1339 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1340 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1341 if (osmux_cid != -1) {
1342 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1343 mtc.stop;
1344 }
1345
1346 osmux_cid := 0;
1347 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1348 } else {
1349 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1350 }
1351
1352 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep));
1353 MGCP.send(mgcp_resp);
1354 return true;
1355}
1356
1357
1358altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr {
1359 var MgcpCommand mgcp_cmd;
1360 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1361 log("as_optional_mgcp_crcx: rx CRCX");
1362 f_handle_crcx(cpars, mgcp_cmd);
1363
1364 /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an
1365 * CRCX is handled. */
1366 repeat;
1367 }
1368}
1369
1370private altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr {
1371 var MgcpCommand mgcp_cmd;
1372 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1373 log("as_optional_mgcp_mdcx: rx MDCX");
1374 log(mgcp_cmd);
1375 var charstring conn_id;
1376 var charstring rtp_payload_type;
1377 f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id);
1378 rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0];
1379
1380 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip,
1381 mgcp_cmd.sdp.origin.session_id, "42",
1382 mgw_rtp_port,
1383 { rtp_payload_type },
1384 { valueof(ts_SDP_ptime(20)) }));
1385 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp));
1386
1387 /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is
1388 * handled. */
1389 repeat;
1390 }
1391}
1392
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001393private altstep as_optional_mgcp_dlcx(CallParameters cpars) runs on BSC_ConnHdlr {
1394 var MgcpCommand mgcp_cmd;
1395 var boolean respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1396 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1397 log("as_optional_mgcp_dlcx: rx MGCP DLCX");
1398 if (respond_to_dlcx) {
1399 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1400 }
1401 /* Without this 'repeat', currently active other interleave and alt series exit as soon as a
1402 * DLCX is handled. */
1403 repeat;
1404 }
1405}
1406
Philipp Maier3716a5e2018-03-21 15:53:35 +01001407function f_mo_call_establish(inout CallParameters cpars)
Harald Welteb71901a2018-01-26 19:16:05 +01001408runs on BSC_ConnHdlr {
1409
Harald Welteb71901a2018-01-26 19:16:05 +01001410 var MNCC_PDU mncc;
1411 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001412 var template MgcpResponse mgcp_resp;
Philipp Maier2a98a732018-03-19 16:06:12 +01001413 var boolean respond_to_dlcx;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001414 var PDU_BSSAP bssap;
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001415 var RANAP_PDU ranap;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001416 var MgcpOsmuxCID osmux_cid;
Harald Welteb71901a2018-01-26 19:16:05 +01001417
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001418 cpars.mo_call := true;
1419
Harald Welte0bef21e2018-02-10 09:48:23 +01001420 if (cpars.emergency) {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001421 f_establish_fully(EST_TYPE_EMERG_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001422 } else {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001423 f_establish_fully(EST_TYPE_MO_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001424 }
Harald Welteb71901a2018-01-26 19:16:05 +01001425
1426 /* Create MNCC and MGCP expect */
1427 f_create_mncc_expect(hex2str(cpars.called_party));
1428 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1429
Harald Welte0bef21e2018-02-10 09:48:23 +01001430 if (cpars.emergency) {
1431 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id)));
1432 } else {
1433 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party)));
1434 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001435
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001436 if (cpars.stop_after_cc_setup) {
1437 return;
1438 }
1439
1440 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001441 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001442
1443 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 +01001444 var boolean got_mncc_setup_compl_ind := false;
1445 var boolean got_cc_connect := false;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001446
Harald Welteb71901a2018-01-26 19:16:05 +01001447 interleave {
1448 [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001449 log("f_mo_call_establish 1: rx MNCC SETUP ind");
Harald Welteb71901a2018-01-26 19:16:05 +01001450 cpars.mncc_callref := mncc.u.signal.callref;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001451 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1452 }
1453
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001454 /* First MGCP CRCX */
Harald Welteb71901a2018-01-26 19:16:05 +01001455 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001456 log("f_mo_call_establish 2: rx 1st CRCX");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001457 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1458 break;
1459 }
Philipp Maierf1e02bb2018-03-15 16:30:00 +01001460 }
1461
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001462 /* Second MGCP CRCX */
1463 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
1464 log("f_mo_call_establish 6: rx 2nd CRCX");
1465 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1466 break;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001467 }
Harald Welteb71901a2018-01-26 19:16:05 +01001468 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001469
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001470 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1471 log("f_mo_call_establish 3: rx RTP CREATE");
1472 /* Call Proceeding */
1473 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1474 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001475
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001476 /* Alerting */
1477 MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref));
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001478 }
Harald Welte9b751a62019-04-14 17:39:29 +02001479
Neels Hofmeyreccaa992019-10-15 16:42:21 +02001480 //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001481 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001482 log("f_mo_call_establish 4: rx Assignment Request");
1483 var BSSMAP_IE_AoIP_TransportLayerAddress tla;
1484 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001485 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
1486
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001487 if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass)) {
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001488 log("Expected:", tla_ass);
1489 log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer);
1490 setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE");
1491 mtc.stop;
1492 }
1493
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001494 tla := valueof(f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001495 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001496 if (cpars.use_osmux) {
1497 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1498 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1499 mtc.stop;
1500 }
1501 osmuxCID := valueof(ts_OsmuxCID(0));
1502 if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1503 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1504 mtc.stop;
1505 }
1506 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1507 } else {
1508 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1509 }
1510 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001511 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001512 [] BSSAP.receive(tr_RANAP_RabAssReq(*)) -> value ranap {
1513 log("f_mo_call_establish 4.iu: rx RANAP RAB Assignment Request");
1514 var RAB_SetupOrModifiedList l := {
1515 {
1516 {
1517 id := id_RAB_SetupOrModifiedItem,
1518 criticality := ignore,
1519 value_ := {
1520 rAB_SetupOrModifiedItem := {
1521 rAB_ID := int2bit(23, 8),
1522 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1523 iuTransportAssociation := {
1524 bindingID := '040c0000'O
1525 },
1526 dl_dataVolumes := omit,
1527 iE_Extensions := omit
1528 }
1529 }
1530 }
1531 }
1532 };
1533 BSSAP.send(ts_RANAP_RabAssResp(l));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001534 }
Harald Welte9b751a62019-04-14 17:39:29 +02001535
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001536 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1537 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1538 log("f_mo_call_establish 5: rx MDCX for the RAN side");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001539 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 +01001540 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001541 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001542 { int2str(cpars.rtp_payload_type) },
1543 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1544 cpars.rtp_sdp_format)),
1545 valueof(ts_SDP_ptime(20)) }));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001546
1547 if (cpars.use_osmux) {
1548 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1549 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1550 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1551 mtc.stop;
1552 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001553 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 +02001554 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001555 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 +02001556 }
1557 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001558 }
Harald Welte9b751a62019-04-14 17:39:29 +02001559
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001560 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {
1561 log("f_mo_call_establish 7: rx CC Alerting");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001562
1563 if (cpars.ran_clear_when_alerting) {
1564 if (g_pars.ran_is_geran) {
1565 BSSAP.send(ts_BSSMAP_ClearRequest(0));
1566 } else {
1567 BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention));
1568 }
1569 break;
1570 }
1571
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001572 cpars.mncc_callref := mncc.u.signal.callref;
1573 /* Call Proceeding */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001574 var octetstring ip;
1575 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1576 if (is_ipv6) {
1577 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1578 } else {
1579 ip := f_inet_addr(cpars.mncc_rtp_ip);
1580 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001581 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001582 is_ipv6, ip,
1583 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001584 /* payload type 3 = GSM FR */ 3));
1585 MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref));
1586 }
1587
1588 [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc {
1589 log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001590 got_mncc_setup_compl_ind := true;
1591 if (not cpars.expect_release and got_cc_connect) {
1592 break;
1593 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001594 }
1595
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001596 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) {
1597 log("f_mo_call_establish 10: rx CC CONNECT");
1598 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id)));
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001599 got_cc_connect := true;
1600 if (not cpars.expect_release and got_mncc_setup_compl_ind) {
1601 break;
1602 }
Harald Welteb71901a2018-01-26 19:16:05 +01001603 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001604
1605 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1606 log("f_mo_call_establish 11: rx CC RELEASE");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001607 if (not cpars.expect_release) {
1608 setverdict(fail, "Got unexpected CC Release");
1609 mtc.stop;
1610 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001611 f_expect_clear();
1612 break;
1613 }
1614 }
1615
1616 f_sleep(0.5);
1617 deactivate(mdcx);
1618
1619 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1620 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1621 } else {
1622 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1623 mtc.stop;
Harald Welteb71901a2018-01-26 19:16:05 +01001624 }
1625
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001626 log("f_mo_call_establish DONE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001627 setverdict(pass);
1628}
Harald Welteb71901a2018-01-26 19:16:05 +01001629
Harald Welte4c422b72019-02-17 16:27:10 +01001630function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001631runs on BSC_ConnHdlr {
1632
1633 var MobileIdentityLV mi;
1634 var MNCC_PDU mncc;
1635 var MgcpCommand mgcp_cmd;
1636 var boolean respond_to_dlcx;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001637 var boolean dlcx_contained_ci := false;
1638 var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand;
1639
1640 if (is_csfb) {
1641 t_clear := tr_BSSMAP_ClearCommandCSFB;
1642 }
1643
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001644 log("f_call_hangup 0: tx MNCC_DISC_REQ");
Harald Welteb71901a2018-01-26 19:16:05 +01001645 MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1646 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1647
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001648 log("f_call_hangup 1: rx DTAP CC DISC");
1649
Philipp Maier3716a5e2018-03-21 15:53:35 +01001650 if (release_by_ms) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001651 var BIT1 tid_remote := '1'B;
1652 if (cpars.mo_call) {
1653 tid_remote := '0'B;
1654 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001655 /* B-side (MS) Release of call */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001656 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 +01001657 MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001658 log("f_call_hangup 2: rx MNCC REL ind");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001659 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001660 log("f_call_hangup 3: rx DTAP CC REL COMPL");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001661 } else {
1662 /* A-side (PLMN) Release of call */
1663 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42))));
1664 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001665 log("f_call_hangup 4: rx DTAP CC RELEASE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001666 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
1667 }
Harald Welteb71901a2018-01-26 19:16:05 +01001668
Philipp Maier2a98a732018-03-19 16:06:12 +01001669 respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1670
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001671 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 +01001672 var default dlcx := activate(as_optional_mgcp_dlcx(cpars));
Harald Welte9b751a62019-04-14 17:39:29 +02001673
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001674 /* clearing of radio channel */
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001675 alt {
1676 [g_pars.ran_is_geran] BSSAP.receive(t_clear) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001677 log("f_call_hangup 5: rx BSSAP Clear Command");
1678 BSSAP.send(ts_BSSMAP_ClearComplete);
1679 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1680 log("f_call_hangup 6: rx SCCP DISC");
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001681 setverdict(pass);
Philipp Maier2a98a732018-03-19 16:06:12 +01001682 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001683 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) {
1684 log("f_call_hangup 5.iu: rx Iu Release Command");
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001685 BSSAP.send(ts_RANAP_IuReleaseComplete);
1686 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001687 log("f_call_hangup 6.iu: rx SCCP DISC");
1688 setverdict(pass);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001689 }
1690 }
1691
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001692 f_sleep(1.0);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001693 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1694 log("f_call_hangup 9: done");
1695
1696 deactivate(mdcx);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001697 deactivate(dlcx);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001698}
1699
1700function f_mt_call(inout CallParameters cpars)
1701runs on BSC_ConnHdlr {
1702
1703 f_mt_call_establish(cpars);
1704
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001705 log("Hold the call for some time");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001706 f_sleep(3.0);
1707
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001708 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001709 f_call_hangup(cpars, true);
1710
1711 setverdict(pass);
1712}
1713
1714function f_mo_call(inout CallParameters cpars)
1715runs on BSC_ConnHdlr {
1716
1717 f_mo_call_establish(cpars);
1718
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001719 log("Hold the call for some time");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001720 f_sleep(3.0);
1721
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001722 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001723 f_call_hangup(cpars, false);
1724
Harald Welteb71901a2018-01-26 19:16:05 +01001725 setverdict(pass);
1726}
Harald Weltea49e36e2018-01-21 19:29:33 +01001727
Daniel Willmann8b084372018-02-04 13:35:26 +01001728function f_mo_seq_dtmf_dup(inout CallParameters cpars)
1729runs on BSC_ConnHdlr {
1730
1731 timer T := 1.0;
Daniel Willmann8b084372018-02-04 13:35:26 +01001732 var MNCC_PDU mncc;
1733 var MgcpCommand mgcp_cmd;
1734 var template PDU_ML3_MS_NW dtmf_dtap;
1735
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001736 f_mo_call_establish(cpars);
Daniel Willmann8b084372018-02-04 13:35:26 +01001737
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001738 /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by
1739 * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001740
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001741 /* Find out the next NSD that will be used, from RAN emulation. */
1742 var N_Sd_Array last_n_sd := f_bssmap_last_n_sd();
1743 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 +01001744
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001745 /* Compose DTAP with this correct NSD */
Daniel Willmann8b084372018-02-04 13:35:26 +01001746 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001747
1748 /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */
1749 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001750 T.start;
1751 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001752 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
1753 log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind");
1754 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001755 [] T.timeout {
1756 setverdict(fail, "Timeout waiting for START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001757 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001758 }
1759 }
1760
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001761 /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message
1762 * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */
1763 dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2);
Daniel Willmann92f66272018-02-06 15:50:52 +01001764 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true));
Daniel Willmann8b084372018-02-04 13:35:26 +01001765 T.start;
1766 alt {
1767 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001768 setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001769 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001770 }
1771 [] T.timeout { }
1772 }
1773
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001774 /* Here the NSD should be correct again and we see a DTMF. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001775 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001776 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001777 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001778 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) {
1779 log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind");
1780 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001781 [] T.timeout {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001782 setverdict(fail, "Timeout waiting for final START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001783 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001784 }
1785 }
1786
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001787 f_call_hangup(cpars, true);
Daniel Willmann8b084372018-02-04 13:35:26 +01001788 setverdict(pass);
1789}
Harald Welte9b751a62019-04-14 17:39:29 +02001790
Harald Welte1ddc7162018-01-27 14:25:46 +01001791/* expect a clear command */
Harald Welte5946b332018-03-18 23:32:21 +01001792altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr {
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001793 var PDU_BSSAP bssap;
Harald Welte5946b332018-03-18 23:32:21 +01001794 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1795 BSSAP.send(ts_BSSMAP_ClearComplete);
1796 alt {
Harald Welte6811d102019-04-14 22:23:14 +02001797 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte5946b332018-03-18 23:32:21 +01001798 setverdict(pass);
1799 }
1800 [] BSSAP.receive {
1801 setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001802 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001803 }
1804 }
1805 }
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001806 [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap {
1807 setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001808 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001809 }
1810}
1811
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001812function f_expect_clear(float t := 5.0, boolean verify_vlr_cell_id := true) runs on BSC_ConnHdlr {
Harald Welte1ddc7162018-01-27 14:25:46 +01001813 timer T := t;
1814
1815 T.start;
1816 alt {
Harald Welte9b751a62019-04-14 17:39:29 +02001817 [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { }
1818 [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { }
Harald Welte1ddc7162018-01-27 14:25:46 +01001819 [] T.timeout {
Harald Welte5946b332018-03-18 23:32:21 +01001820 setverdict(fail, "Timeout waiting for ClearCommand/Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001821 mtc.stop;
Harald Welte1ddc7162018-01-27 14:25:46 +01001822 }
1823 }
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001824
1825 if (verify_vlr_cell_id) {
1826 /* Now the conn is gone, but the VLR reflects the cell ID */
1827 f_verify_vty_lac_ci();
1828 }
Harald Welte1ddc7162018-01-27 14:25:46 +01001829}
1830
Neels Hofmeyr0ac63152019-05-07 01:20:17 +02001831function f_create_bssmap_exp_handoverRequest(integer targetPointCode) runs on BSC_ConnHdlr {
1832 BSSAP_PROC.call(RAN_register_handoverRequest:{targetPointCode, self}) {
1833 [] BSSAP_PROC.getreply(RAN_register_handoverRequest:{?, ?}) {};
1834 }
1835}
1836
1837function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array {
1838 var N_Sd_Array last_n_sd;
1839 BSSAP_PROC.call(RAN_last_n_sd:{self, -}) {
1840 [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) {
1841 return last_n_sd;
1842 };
1843 }
1844}
1845
1846function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr {
1847 BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) {
1848 [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self});
1849 }
1850}
1851
Harald Weltef45efeb2018-04-09 18:19:24 +02001852type record SmsParametersTp {
1853 OCT1 msg_ref,
1854 TP_DA da,
1855 OCT1 pid,
1856 OCT1 dcs,
1857 integer udl,
1858 octetstring ud
1859}
1860type record SmsParametersRp {
1861 OCT1 msg_ref,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001862 RP_NumberingPlan_and_NumberDigits smsc_addr optional
Harald Weltef45efeb2018-04-09 18:19:24 +02001863}
1864type record SmsParameters {
1865 SmsParametersTp tp,
1866 SmsParametersRp rp,
1867 uint3_t tid,
1868 OCT1 dlci,
1869 uint7_t exp_rp_err optional
1870}
1871
1872template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := {
1873 tP_DA_NoPad := {
1874 tP_LengthIndicator := 0, /* overwritten */
1875 tP_NumberingPlanID := npl,
1876 tP_TypeOfNumber := ton,
1877 tp_Spare := '0'B,
1878 tP_DAValue := addr
1879 }
1880}
1881
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001882template RP_NumberingPlan_and_NumberDigits t_RP_Addr(template hexstring addr,
1883 template BIT4 npi := '0001'B,
1884 template BIT3 ton := '001'B,
1885 template BIT1 ext := '1'B) := {
1886 rP_NumberingPlanIdentification := npi,
1887 rP_TypeOfNumber := ton,
1888 rP_Ext := ext,
1889 rP_NumberDigits := addr
1890}
1891
Harald Weltef45efeb2018-04-09 18:19:24 +02001892template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := {
1893 tp := {
1894 msg_ref := '23'O,
1895 da := ts_TP_DA('0000'B, '000'B, tp_daddr),
1896 pid := '00'O,
1897 dcs := '00'O,
1898 udl := 0,
1899 ud := ''O
1900 },
1901 rp := {
1902 msg_ref := '42'O,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001903 /* We don't really need to have both SM-RP-DA/OA here, because only one IE
Vadim Yanitskiyafb15a82020-01-05 14:04:53 +01001904 * is included in MO/MT SMS, and in the most cases it's the SMSC address.
1905 * NOTE: this address is currently hard-coded by OsmoMSC. */
1906 smsc_addr := t_RP_Addr('447785016005'H)
Harald Weltef45efeb2018-04-09 18:19:24 +02001907 },
1908 tid := 0,
1909 dlci := '03'O,
1910 exp_rp_err := omit
1911}
1912
1913private altstep as_other_sms() runs on BSC_ConnHdlr {
1914 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) {
1915 setverdict(fail, "Unexpected SMS related PDU from MSC");
Daniel Willmannafce8662018-07-06 23:11:32 +02001916 mtc.stop;
Harald Weltef45efeb2018-04-09 18:19:24 +02001917 }
1918}
1919
Vadim Yanitskiy9cc019a2018-11-15 02:06:07 +07001920/* Submit a MO RP-SMMA over an already existing DTAP connection */
1921function f_mo_smma(inout SmsParameters spars)
1922runs on BSC_ConnHdlr {
1923 var template (value) RPDU_MS_SGSN rp_mo;
1924 var template (value) PDU_ML3_MS_NW l3_mo;
1925
1926 var default d := activate(as_other_sms());
1927
1928 /* just in case this is routed to SMPP.. */
1929 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1930
1931 rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref);
1932 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1933 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1934 /* receive CP-ACK for CP-DATA above */
1935 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1936
1937 deactivate(d);
1938 setverdict(pass);
1939}
1940
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001941/* Submit a MO-SMS over an already existing DTAP connection */
1942function f_mo_sms_submit(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02001943runs on BSC_ConnHdlr {
1944 var template (value) TPDU_RP_DATA_MS_SGSN tp_mo;
1945 var template (value) RPDU_MS_SGSN rp_mo;
1946 var template (value) PDU_ML3_MS_NW l3_mo;
1947
Harald Weltef45efeb2018-04-09 18:19:24 +02001948 var default d := activate(as_other_sms());
1949
Harald Weltef640a012018-04-14 17:49:21 +02001950 /* just in case this is routed to SMPP.. */
1951 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1952
Harald Weltef45efeb2018-04-09 18:19:24 +02001953 tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs,
1954 spars.tp.udl, spars.tp.ud);
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001955 rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, omit, spars.rp.smsc_addr, tp_mo);
Harald Weltef45efeb2018-04-09 18:19:24 +02001956 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1957 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1958 /* receive CP-ACK for CP-DATA above */
1959 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1960
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001961 deactivate(d);
1962 setverdict(pass);
1963}
1964
1965/* Wait RP-ACK for MO-SMS on an already existing DTAP connection */
1966function f_mo_sms_wait_rp_ack(inout SmsParameters spars)
1967runs on BSC_ConnHdlr {
1968 var template (value) PDU_ML3_MS_NW l3_mo;
1969
1970 var template TPDU_RP_DATA_SGSN_MS tp_mt;
1971 var template RPDU_SGSN_MS rp_mt;
1972 var template PDU_ML3_NW_MS l3_mt;
1973
1974 var default d := activate(as_other_sms());
1975
1976 /* just in case this is routed to SMPP.. */
1977 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1978
Harald Weltef45efeb2018-04-09 18:19:24 +02001979 if (ispresent(spars.exp_rp_err)) {
1980 /* expect an RP-ERROR message from MSC with given cause */
1981 rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err);
1982 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1983 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1984 /* send CP-ACK for CP-DATA just received */
1985 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1986 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1987 } else {
1988 /* expect RP-ACK for RP-DATA */
1989 rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref);
1990 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1991 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1992 /* send CP-ACO for CP-DATA just received */
1993 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1994 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1995 }
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001996
Harald Weltef45efeb2018-04-09 18:19:24 +02001997 deactivate(d);
1998 setverdict(pass);
1999}
2000
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002001/* Submit a MO-SMS, and wait for RP-ACK on an existing
2002 * (and authenticated, ...) DTAP connection */
2003function f_mo_sms(inout SmsParameters spars)
2004runs on BSC_ConnHdlr {
2005 f_mo_sms_submit(spars);
2006 f_mo_sms_wait_rp_ack(spars);
2007}
2008
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002009function f_mt_sms_deliver_pdu(in SmsParameters spars)
2010runs on BSC_ConnHdlr
2011return template PDU_DTAP_MT {
2012 var template TPDU_RP_DATA_SGSN_MS tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?);
2013 var template RPDU_SGSN_MS rp_mt := tr_RP_DATA_MT(?, spars.rp.smsc_addr, omit, tp_mt);
2014 var template PDU_ML3_NW_MS l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt));
2015 return tr_PDU_DTAP_MT(l3_mt, spars.dlci);
2016}
2017
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002018/* Wait for MT SMS on an already existing DTAP connection */
2019function f_mt_sms_expect(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02002020runs on BSC_ConnHdlr {
Harald Weltef45efeb2018-04-09 18:19:24 +02002021 var template (value) PDU_ML3_MS_NW l3_mo;
Harald Weltef45efeb2018-04-09 18:19:24 +02002022 var PDU_DTAP_MT dtap_mt;
2023
2024 var default d := activate(as_other_sms());
2025
2026 /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002027 BSSAP.receive(f_mt_sms_deliver_pdu(spars)) -> value dtap_mt;
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002028
Harald Weltef45efeb2018-04-09 18:19:24 +02002029 /* Extract relevant identifiers */
2030 spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio);
2031 spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference;
2032
2033 /* send CP-ACK for CP-DATA just received */
2034 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO);
2035 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2036
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002037 deactivate(d);
2038 setverdict(pass);
2039}
2040
2041/* Send RP-ACK for MT-SMS over an already existing DTAP connection */
2042function f_mt_sms_send_rp_ack(inout SmsParameters spars)
2043runs on BSC_ConnHdlr {
2044 var template (value) RPDU_MS_SGSN rp_mo;
2045 var template (value) PDU_ML3_MS_NW l3_mo;
2046 var template PDU_ML3_NW_MS l3_mt;
2047
2048 var default d := activate(as_other_sms());
2049
Harald Weltef45efeb2018-04-09 18:19:24 +02002050 /* send RP-ACK for RP-DATA */
2051 rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref);
2052 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2053 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2054
2055 /* expect CP-ACK for CP-DATA(RP-ACK) just sent */
Harald Weltee008eea2018-04-14 21:05:48 +02002056 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
Harald Weltef45efeb2018-04-09 18:19:24 +02002057 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2058
2059 deactivate(d);
2060 setverdict(pass);
2061}
2062
Vadim Yanitskiy56318522018-11-24 03:40:47 +07002063/* Send RP-ERROR for MT-SMS over an already existing DTAP connection */
2064function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause)
2065runs on BSC_ConnHdlr {
2066 var template (value) RPDU_MS_SGSN rp_mo;
2067 var template (value) PDU_ML3_MS_NW l3_mo;
2068 var template PDU_ML3_NW_MS l3_mt;
2069
2070 var default d := activate(as_other_sms());
2071
2072 /* send RP-ACK for RP-DATA */
2073 rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause);
2074 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2075 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2076
2077 /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */
2078 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
2079 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2080
2081 deactivate(d);
2082 setverdict(pass);
2083}
2084
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002085/* Wait for a MT-SMS and send RP-ACK over an already existing
2086 * (and authenticated, ...) DTAP connection */
2087function f_mt_sms(inout SmsParameters spars)
2088runs on BSC_ConnHdlr {
2089 f_mt_sms_expect(spars);
2090 f_mt_sms_send_rp_ack(spars);
2091}
Harald Weltea49e36e2018-01-21 19:29:33 +01002092
2093
Harald Weltea49e36e2018-01-21 19:29:33 +01002094}