blob: 4e736b8bb1456489bb63bf61ef131c0e351ea8d0 [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
Neels Hofmeyrf797d292021-07-27 22:33:09 +020066type port BSC_ConnHdlr_Coord_PT message
67{
68 inout charstring, CallParameters;
69} with { extension "internal" };
70
71
Harald Weltea49e36e2018-01-21 19:29:33 +010072/* this component represents a single subscriber connection */
Harald Welte6811d102019-04-14 22:23:14 +020073type 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 +010074 var BSC_ConnHdlrPars g_pars;
Harald Weltea10db902018-01-27 12:44:49 +010075 timer g_Tguard := 60.0;
Philipp Maierc39a9d82018-11-09 11:21:08 +010076 port TELNETasp_PT MSCVTY;
Neels Hofmeyrf797d292021-07-27 22:33:09 +020077 port BSC_ConnHdlr_Coord_PT COORD;
Harald Weltea49e36e2018-01-21 19:29:33 +010078}
79
Harald Weltede371492018-01-27 23:44:41 +010080type record BSC_ConnHdlrNetworkPars {
81 OCT1 kc_support,
82 boolean expect_tmsi,
83 boolean expect_auth,
Oliver Smith1d118ff2019-07-03 10:57:35 +020084 boolean expect_ciph,
85 boolean expect_imei,
86 boolean expect_imei_early,
87 GSUP_IMEIResult check_imei_result,
88 boolean check_imei_error
Harald Weltede371492018-01-27 23:44:41 +010089}
90
Harald Weltea49e36e2018-01-21 19:29:33 +010091type record BSC_ConnHdlrPars {
92 SCCP_PAR_Address sccp_addr_own,
93 SCCP_PAR_Address sccp_addr_peer,
94 BSSMAP_IE_CellIdentifier cell_id,
Harald Welte256571e2018-01-24 18:47:19 +010095 hexstring imei,
Harald Weltea49e36e2018-01-21 19:29:33 +010096 hexstring imsi,
Harald Welte82600572018-01-21 20:54:08 +010097 hexstring msisdn,
Harald Welte256571e2018-01-24 18:47:19 +010098 OCT4 tmsi optional,
Harald Welte9de84792018-01-28 01:06:35 +010099 MobileStationClassmark1_V cm1,
Harald Welte82600572018-01-21 20:54:08 +0100100 BSSMAP_IE_ClassmarkInformationType2 cm2,
Harald Welte16114282018-01-24 22:41:21 +0100101 BSSMAP_IE_ClassmarkInformationType3 cm3 optional,
Harald Weltede371492018-01-27 23:44:41 +0100102 AuthVector vec optional,
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +0200103 /* BSC_ConnectionHandler generates an auth vector in as_GSUP_SAI(). For tests that want control over which
104 * vector is used, pass vec_keep := true to not regenerate a new auth vector in as_GSUP_SAI(). */
105 boolean vec_keep,
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100106 BSC_ConnHdlrNetworkPars net,
Philipp Maieraeb29a82018-11-08 17:40:53 +0100107 boolean send_early_cm,
108 charstring ipa_ctrl_ip,
109 integer ipa_ctrl_port,
Philipp Maier9b690e42018-12-21 11:50:03 +0100110 boolean ipa_ctrl_enable,
Philipp Maier57865482019-01-07 18:33:13 +0100111 boolean mm_info,
Philipp Maierc09a1312019-04-09 16:05:26 +0200112 boolean sgsap_enable,
Harald Weltef9abf8d2019-04-21 13:07:17 +0200113 boolean gsup_enable,
Vadim Yanitskiy2dd96612020-01-07 21:48:29 +0100114 OCT4 gsup_sid,
Harald Weltec1f937a2019-04-21 21:19:23 +0200115 integer ran_idx,
Harald Welte9b751a62019-04-14 17:39:29 +0200116 boolean use_umts_aka,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200117 boolean ran_is_geran,
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200118 boolean use_osmux,
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200119 boolean use_ipv6,
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200120 boolean verify_cell_id,
121 OCT3 common_id_last_eutran_plmn optional
Harald Weltea49e36e2018-01-21 19:29:33 +0100122};
123
Harald Welte9de84792018-01-28 01:06:35 +0100124/* get a one-octet bitmaks of supported algorithms based on Classmark information */
Eric Wild26f4a622021-05-17 15:27:05 +0200125function 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 +0100126 var BIT8 res := '00000001'B; /* A5/0 always supported */
127
128 if (cm2.a5_1 == '0'B) {
129 res := res or4b '00000010'B;
130 }
131 if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) {
132 res := res or4b '00000100'B;
133 }
134 if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) {
135 res := res or4b '00001000'B;
136 }
Eric Wild26f4a622021-05-17 15:27:05 +0200137 if (not istemplatekind(cm3, "omit")) {
138 var BSSMAP_IE_ClassmarkInformationType3 v := valueof(cm3);
139 var BIT8 tmp := oct2bit(v.classmark3ValuePart[0]) and4b '00001111'B;
140 res := res or4b (tmp << 4);
141 }
142
Harald Welte9de84792018-01-28 01:06:35 +0100143 return bit2oct(res);
144}
145
146/* determine the best algorithm available within the bit-mask */
147function f_best_alg_from_mask(OCT1 alg_in) return OCT1 {
148 var BIT8 alg := oct2bit(alg_in);
149 var BIT8 ordered_algs[8] := {
150 '10000000'B, '01000000'B, '00100000'B, '00010000'B,
151 '00001000'B, /* A5/3 */
152 '00000010'B, /* A5/1 */
153 '00000100'B, /* A5/2 */
154 '00000001'B /* A5/0 */ }
155 for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) {
156 if (alg and4b ordered_algs[i] != '00000000'B) {
157 return bit2oct(ordered_algs[i]);
158 }
159 }
160 return '00'O;
161}
162
163/* return an integer like '1' for A5/1 based on a mask (with only one bit set */
164function f_alg_from_mask(OCT1 mask_in) return integer {
165 var BIT8 mask := oct2bit(mask_in);
166 for (var integer i := 0; i < 8; i := i+1) {
167 if (mask and4b ('00000001'B << i) != '00000000'B) {
168 return i;
169 }
170 }
171 return -1;
172}
173
Eric Wild26f4a622021-05-17 15:27:05 +0200174/* return true for A5/x supported by OCT1 bitmask */
175function f_alg_supported_by_mask(OCT1 mask_in, integer whicha5) return boolean {
176 var BIT8 mask := oct2bit(mask_in);
177 if (mask and4b ('00000001'B << whicha5) != '00000000'B) {
178 return true;
179 }
180 return false;
181}
182
Harald Weltea10db902018-01-27 12:44:49 +0100183/* altstep for the global guard timer */
184private altstep as_Tguard() runs on BSC_ConnHdlr {
185 [] g_Tguard.timeout {
Daniel Willmann90829d62018-02-15 17:45:14 +0100186 setverdict(fail, "Tguard timeout");
Daniel Willmannafce8662018-07-06 23:11:32 +0200187 mtc.stop;
Harald Weltea10db902018-01-27 12:44:49 +0100188 }
189}
190
191/* init function, called as first function in new BSC_ConnHdlr */
Harald Weltead2952e2018-01-27 14:12:46 +0100192function f_init_handler(BSC_ConnHdlrPars pars, float t_guard := 60.0) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100193 /* make parameters available via component variable */
194 g_pars := pars;
195 /* Start guard timer and activate it as default */
Harald Weltead2952e2018-01-27 14:12:46 +0100196 g_Tguard.start(t_guard);
Harald Weltea10db902018-01-27 12:44:49 +0100197 activate(as_Tguard());
Harald Weltef640a012018-04-14 17:49:21 +0200198 /* Route all SMPP messages for our MSISDN to us */
199 f_create_smpp_expect(hex2str(pars.msisdn));
Philipp Maier57865482019-01-07 18:33:13 +0100200
Harald Welte4263c522018-12-06 11:56:27 +0100201 /* Route all SGs message for our IMSI to us */
Philipp Maier57865482019-01-07 18:33:13 +0100202 if (g_pars.sgsap_enable == true) {
203 f_create_sgsap_expect(pars.imsi);
204 }
Philipp Maieraeb29a82018-11-08 17:40:53 +0100205
206 if (g_pars.ipa_ctrl_enable == true) {
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100207 f_ipa_ctrl_start_client(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port);
Philipp Maieraeb29a82018-11-08 17:40:53 +0100208 }
Philipp Maierc39a9d82018-11-09 11:21:08 +0100209
210 map(self:MSCVTY, system:MSCVTY);
211 f_vty_set_prompts(MSCVTY);
212 f_vty_transceive(MSCVTY, "enable");
Harald Weltea10db902018-01-27 12:44:49 +0100213}
214
Harald Weltea49e36e2018-01-21 19:29:33 +0100215
Harald Welte6811d102019-04-14 22:23:14 +0200216/* Callback function from general RAN_Emulation whenever a connectionless
Harald Weltea49e36e2018-01-21 19:29:33 +0100217 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
218private function BscUnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200219runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Weltea49e36e2018-01-21 19:29:33 +0100220 var template PDU_BSSAP resp := omit;
221
222 log("BSSMAP_BscUnitdataCallback");
223 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200224 if (match(bssap, tr_BSSMAP_Reset(g_ran_ops.use_osmux))){
Harald Weltea49e36e2018-01-21 19:29:33 +0100225 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200226 resp := ts_BSSMAP_ResetAck(g_ran_ops.use_osmux);
Harald Weltea49e36e2018-01-21 19:29:33 +0100227 }
228
229 /* FIXME: Handle paging, etc. */
230 return resp;
231}
232
Harald Welte9b751a62019-04-14 17:39:29 +0200233private function RncUnitdataCallback(RANAP_PDU ranap)
234runs on RAN_Emulation_CT return template RANAP_PDU {
235 var template RANAP_PDU resp := omit;
236
237 log("RANAP_RncUnitdataCallback");
238 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200239 if (match(ranap, tr_RANAP_Reset())) {
Harald Welte9b751a62019-04-14 17:39:29 +0200240 log("RANAP_RncUnitdataCallback: Responding to RESET with RESET-ACK");
241 var CN_DomainIndicator dom;
242 dom := ranap.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator;
243 resp := ts_RANAP_ResetAck(dom);
244 }
245
246 /* FIXME: Handle paging, etc. */
247 return resp;
248}
249
250
Harald Welte6811d102019-04-14 22:23:14 +0200251const RanOps BSC_RanOps := {
Harald Weltea49e36e2018-01-21 19:29:33 +0100252 /* Create call-back for inbound connections from MSC (hand-over) */
Harald Welte6811d102019-04-14 22:23:14 +0200253 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Weltea49e36e2018-01-21 19:29:33 +0100254 unitdata_cb := refers(BscUnitdataCallback),
Harald Welte9b751a62019-04-14 17:39:29 +0200255 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
256 ranap_unitdata_cb := refers(RncUnitdataCallback),
257 ps_domain := false,
Harald Weltea49e36e2018-01-21 19:29:33 +0100258 decode_dtap := true,
Harald Weltea4ca4462018-02-09 00:17:14 +0100259 role_ms := true,
Harald Welte2fce7882019-04-15 11:48:05 +0200260 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200261 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200262 use_osmux := false,
Eric Wild49888a62022-03-30 03:16:11 +0200263 bssap_reset_retries := 1,
Harald Weltea4ca4462018-02-09 00:17:14 +0100264 sccp_addr_local := omit,
265 sccp_addr_peer := omit
Harald Weltea49e36e2018-01-21 19:29:33 +0100266}
267
268
269private function MnccUnitdataCallback(MNCC_PDU mncc)
270runs on MNCC_Emulation_CT return template MNCC_PDU {
271 log("Ignoring MNCC", mncc);
272 return omit;
273}
274
275const MnccOps BCC_MnccOps := {
276 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
277 unitdata_cb := refers(MnccUnitdataCallback)
278}
279
280
281
Harald Welte6811d102019-04-14 22:23:14 +0200282/* Encode 'l3' and ask RAN_Emulation to create new connection with COMPL L3 INFO */
Harald Weltea49e36e2018-01-21 19:29:33 +0100283function f_bssap_compl_l3(PDU_ML3_MS_NW l3)
284runs on BSC_ConnHdlr {
285 log("Sending COMPL L3: ", l3);
286 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
287 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
288 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc))));
Harald Welte71b69332018-01-21 20:43:53 +0100289 alt {
Harald Welte6811d102019-04-14 22:23:14 +0200290 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
291 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte71b69332018-01-21 20:43:53 +0100292 setverdict(fail, "DISC.ind from SCCP");
Daniel Willmannafce8662018-07-06 23:11:32 +0200293 mtc.stop;
Harald Welte71b69332018-01-21 20:43:53 +0100294 }
295 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100296}
297
Harald Welte9b751a62019-04-14 17:39:29 +0200298/* generate Iu LAI from BSSAP CGI */
299private function f_IuLAI_from_BssmapCI(BSSMAP_IE_CellIdentifier ci) return LAI {
300 var LAI lai;
301 if (ischosen(ci.cellIdentification.cI_CGI)) {
302 lai.pLMNidentity := ci.cellIdentification.cI_CGI.mcc_mnc;
303 lai.lAC := ci.cellIdentification.cI_CGI.lac;
304 } else if (ischosen(ci.cellIdentification.cI_SAI)) {
305 lai.pLMNidentity := ci.cellIdentification.cI_SAI.mcc_mnc;
306 lai.lAC := ci.cellIdentification.cI_SAI.lac;
307 } else if (ischosen(ci.cellIdentification.ci_LAC_RNC_CI)) {
308 lai.pLMNidentity := ci.cellIdentification.ci_LAC_RNC_CI.mcc_mnc;
309 lai.lAC := ci.cellIdentification.ci_LAC_RNC_CI.lac;
310 } else {
311 mtc.stop;
312 }
313 lai.iE_Extensions := omit;
314 return lai;
315}
316
317/* like f_bssap_compl_l3() but for 3G */
318function f_ranap_initial_ue(PDU_ML3_MS_NW l3)
319runs on BSC_ConnHdlr {
320 log("Sending InitialUE: ", l3);
321 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
322 var RANAP_PDU ranap;
323 var LAI lai := f_IuLAI_from_BssmapCI(g_pars.cell_id);
324 var SAI sai := {
325 pLMNidentity := lai.pLMNidentity,
326 lAC := lai.lAC,
327 sAC := '0000'O, /* FIXME */
328 iE_Extensions := omit
329 };
330 var IuSignallingConnectionIdentifier sigc_id := int2bit(23, 24);
331 var GlobalRNC_ID grnc_id := {
332 pLMNidentity := lai.pLMNidentity,
333 rNC_ID := 2342 /* FIXME */
334 };
335
336 ranap := valueof(ts_RANAP_initialUE_CS(lai, sai, l3_enc, sigc_id, grnc_id));
337 BSSAP.send(ts_RANAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, ranap));
338 alt {
339 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
340 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
341 setverdict(fail, "DISC.ind from SCCP");
342 mtc.stop;
343 }
344 }
345}
346
Harald Weltedceacc72019-04-21 20:58:35 +0200347/* Send BSSMAP Complete L3 or RANAP Initial UE depending on 2G/3G RAN type */
348function f_cl3_or_initial_ue(PDU_ML3_MS_NW l3)
349runs on BSC_ConnHdlr {
350 if (g_pars.ran_is_geran) {
351 f_bssap_compl_l3(l3);
352 } else {
353 f_ranap_initial_ue(l3);
354 }
355}
356
Harald Welte081b19a2018-02-10 09:11:13 +0100357type enumerated EstablishType {
358 EST_TYPE_MO_CALL,
Harald Welte0bef21e2018-02-10 09:48:23 +0100359 EST_TYPE_EMERG_CALL,
Harald Weltef45efeb2018-04-09 18:19:24 +0200360 EST_TYPE_PAG_RESP,
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700361 EST_TYPE_MO_SMS,
362 EST_TYPE_SS_ACT
Harald Welte081b19a2018-02-10 09:11:13 +0100363};
364
Harald Weltea49e36e2018-01-21 19:29:33 +0100365/* helper function to fully establish a dedicated channel */
Harald Welteb9e86fa2018-04-09 18:18:31 +0200366function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL)
Harald Weltea49e36e2018-01-21 19:29:33 +0100367runs on BSC_ConnHdlr {
Harald Welte081b19a2018-02-10 09:11:13 +0100368 var PDU_ML3_MS_NW l3_info;
Harald Welteb9e86fa2018-04-09 18:18:31 +0200369 var MobileIdentityLV mi;
370
371 /* If we have a TMSI, use TMSI instead of IMSI */
372 if (ispresent(g_pars.tmsi)) {
373 mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi));
374 } else {
375 mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
376 }
377
Harald Welte081b19a2018-02-10 09:11:13 +0100378 select (etype) {
379 case (EST_TYPE_MO_CALL) {
380 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
381 }
Harald Welte0bef21e2018-02-10 09:48:23 +0100382 case (EST_TYPE_EMERG_CALL) {
383 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi));
384 }
Harald Welte081b19a2018-02-10 09:11:13 +0100385 case (EST_TYPE_PAG_RESP) {
386 l3_info := valueof(ts_PAG_RESP(mi));
387 }
Harald Weltef45efeb2018-04-09 18:19:24 +0200388 case (EST_TYPE_MO_SMS) {
389 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi));
390 }
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700391 case (EST_TYPE_SS_ACT) {
392 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi));
393 }
Harald Welte081b19a2018-02-10 09:11:13 +0100394 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100395
396 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Weltedceacc72019-04-21 20:58:35 +0200397 f_cl3_or_initial_ue(l3_info);
Harald Weltea49e36e2018-01-21 19:29:33 +0100398
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200399 f_verify_vty_lac_ci(verify_vlr := false);
400
Harald Weltede371492018-01-27 23:44:41 +0100401 f_mm_common();
Pau Espin Pedrolf8034482019-06-03 13:15:58 +0200402 if (g_pars.net.expect_ciph or not g_pars.ran_is_geran) {
Harald Welte148a7082018-01-26 18:56:43 +0100403 /* implicit CM SERVICE ACCEPT? */
404 } else {
Harald Welte0bef21e2018-02-10 09:48:23 +0100405 if (etype != EST_TYPE_PAG_RESP) {
Harald Welte081b19a2018-02-10 09:11:13 +0100406 /* explicit CM SERVICE ACCEPT */
407 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
408 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100409 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100410}
411
412/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
Harald Welte9de84792018-01-28 01:06:35 +0100413function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100414{
415 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
416 return f_build_lu(mi);
417}
Harald Welte9de84792018-01-28 01:06:35 +0100418function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100419{
420 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
421 return f_build_lu(mi);
422}
Harald Welte9de84792018-01-28 01:06:35 +0100423function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100424{
425 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
426 return f_build_lu(mi);
427}
Harald Welte9de84792018-01-28 01:06:35 +0100428private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100429{
430 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
431 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 +0100432 old_lai, mi, g_pars.cm1));
Harald Weltea49e36e2018-01-21 19:29:33 +0100433 return l3_info;
434}
435
Harald Weltea183a5d2019-05-09 13:40:52 +0200436altstep as_GSUP_SAI() runs on BSC_ConnHdlr {
437var GSUP_IE auth_tuple;
438[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)) {
439 if (g_pars.use_umts_aka) {
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +0200440 if (not g_pars.vec_keep) {
441 g_pars.vec := f_gen_auth_vec_3g();
442 }
Harald Weltea183a5d2019-05-09 13:40:52 +0200443 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand,
444 g_pars.vec.sres,
445 g_pars.vec.kc,
446 g_pars.vec.ik,
447 g_pars.vec.ck,
448 g_pars.vec.autn,
449 g_pars.vec.res));
450 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
451 } else {
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +0200452 if (not g_pars.vec_keep) {
453 g_pars.vec := f_gen_auth_vec_2g();
454 }
Harald Weltea183a5d2019-05-09 13:40:52 +0200455 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand,
456 g_pars.vec.sres,
457 g_pars.vec.kc));
458 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
459 }
460 }
461}
462
Harald Welte9de84792018-01-28 01:06:35 +0100463function f_mm_auth() runs on BSC_ConnHdlr
Harald Welte148a7082018-01-26 18:56:43 +0100464{
Harald Weltede371492018-01-27 23:44:41 +0100465 if (g_pars.net.expect_auth) {
Harald Weltea183a5d2019-05-09 13:40:52 +0200466 as_GSUP_SAI();
Harald Weltec1f937a2019-04-21 21:19:23 +0200467 if (g_pars.use_umts_aka) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200468 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn)));
469 var OCT4 res := substr(g_pars.vec.res, 0, 4);
470 var OCT4 xres := substr(g_pars.vec.res, 4, 4);
471 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres)));
472 } else {
Harald Weltec1f937a2019-04-21 21:19:23 +0200473 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand)));
474 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres)));
475 }
Harald Welte148a7082018-01-26 18:56:43 +0100476 }
Harald Welte9de84792018-01-28 01:06:35 +0100477}
Harald Welte148a7082018-01-26 18:56:43 +0100478
Oliver Smith1d118ff2019-07-03 10:57:35 +0200479function f_mm_imei() runs on BSC_ConnHdlr
480{
481 var PDU_DTAP_MT dtap_mt;
482 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700483 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200484
485 if (not g_pars.net.expect_imei) {
486 return
487 }
488
489 /* MSC <-> BSC: ID req/rsp for IMEI */
490 alt {
491 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEI))) {
492 mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
493 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
494 }
495 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
496 setverdict(fail, "Expected ID REQ for IMEI DTAP MT message, but got: ", dtap_mt);
497 mtc.stop;
498 }
499 }
500
501 /* MSC <-> HLR: Check IMEI req/res/err */
502 alt {
503 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
504 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
505 }
506 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
507 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
508 }
509 [] GSUP.receive(?) -> value gsup_msg {
510 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
511 g_pars.imsi, "), but got: ", gsup_msg);
512 mtc.stop;
513 }
514 }
515}
516
517function f_mm_imei_early() runs on BSC_ConnHdlr
518{
519 var PDU_DTAP_MT dtap_mt;
520 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700521 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200522
523 if (not g_pars.net.expect_imei_early) {
524 return
525 }
526
527 /* MSC <-> BSC: ID req/rsp for IMEISV */
528 alt {
529 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEISV))) {
530 mi := valueof(ts_MI_IMEISV_LV(g_pars.imei));
531 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
532 }
533 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
534 setverdict(fail, "Expected ID REQ for IMEISV DTAP MT message, but got: ", dtap_mt);
535 mtc.stop;
536 }
537 }
538
539 /* MSC <-> HLR: Check IMEI req/res/err */
540 alt {
541 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
542 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
543 }
544 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
545 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
546 }
547 [] GSUP.receive(?) -> value gsup_msg {
548 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
549 g_pars.imsi, "), but got: ", gsup_msg);
550 mtc.stop;
551 }
552 }
553}
554
Harald Welte79f1e452020-08-18 22:55:02 +0200555function f_expect_common_id() runs on BSC_ConnHdlr
556{
557 if (g_pars.ran_is_geran) {
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200558 BSSAP.receive(tr_BSSMAP_CommonId(g_pars.imsi,
559 f_tr_BSSMAP_LastUsedEUTRANPLMNId(g_pars.common_id_last_eutran_plmn)));
Harald Welte79f1e452020-08-18 22:55:02 +0200560 } else {
561 BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
562 }
563}
564
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200565/* For UMTS AKA on GERAN, calculate the specific kc from the UMTS AKA ck and ik vectors. */
566function f_auth3g_kc(AuthVector vec) return OCT8 {
Eric Wild26f4a622021-05-17 15:27:05 +0200567 var integer i;
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200568 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 +0200569 for (i := 1; i < 8; i := i + 1) {
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200570 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 +0200571 res := res & a;
572 }
573
574 return res;
575}
576
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200577function f_get_expected_encryption(
578 out template BSSMAP_IE_EncryptionInformation encryptionInformation,
579 out template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm,
580 out template BSSMAP_IE_KC128 kC128,
581 out OCT1 a5_perm_alg) runs on BSC_ConnHdlr
582{
583 var OCT1 a5_ms := f_alg_mask_from_cm(g_pars.cm2, g_pars.cm3);
584 a5_perm_alg := g_pars.net.kc_support and4b a5_ms;
585
586 if (not g_pars.net.expect_ciph) {
587 encryptionInformation := *;
588 chosenEncryptionAlgorithm := *;
589 kC128 := *;
590 return;
591 }
592
Neels Hofmeyrf6eff812021-06-23 23:29:39 +0200593 var OCT8 kc;
594 if (g_pars.use_umts_aka) {
595 kc := f_auth3g_kc(g_pars.vec);
596 } else {
597 kc := g_pars.vec.kc;
598 }
599 encryptionInformation := tr_BSSMAP_IE_EncrInfo(kc, a5_perm_alg);
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200600
601 var OCT1 chosen_alg := int2oct(f_alg_from_mask(f_best_alg_from_mask(a5_perm_alg)) + 1, 1);
602 chosenEncryptionAlgorithm := tr_BSSMAP_IE_ChosenEncryptionAlgorithm(chosen_alg);
603
604 if (g_pars.use_umts_aka and f_alg_supported_by_mask(a5_perm_alg, 4)) {
605 /* A5/4 is permitted, expecting kc128 to be present */
606 var OCT32 full_sha256 := f_calculate_HMAC_SHA256(g_pars.vec.ck & g_pars.vec.ik, '32'O, 32);
607 var OCT16 expect_kc128 := substr(full_sha256, 0, 16);
608 kC128 := tr_BSSMAP_IE_Kc128(expect_kc128);
609 } else {
610 kC128 := omit
611 }
612}
613
Eric Wild26f4a622021-05-17 15:27:05 +0200614
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300615private function f_mm_ciph_geran() runs on BSC_ConnHdlr
616{
617 var template BSSMAP_IE_EncryptionInformation encryptionInformation;
618 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm;
619 var template BSSMAP_IE_KC128 kC128;
620 var OCT1 a5_perm_alg;
621 var PDU_BSSAP pdu;
622
Vadim Yanitskiy172bc6e2021-12-06 17:54:57 +0300623 if (not g_pars.net.expect_ciph) {
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300624 /* There is nothing to do */
625 return;
626 }
627
628 f_get_expected_encryption(encryptionInformation, chosenEncryptionAlgorithm, kC128, a5_perm_alg);
629 alt {
630 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128)) -> value pdu {
631 var OCT1 a5_chosen := f_best_alg_from_mask(a5_perm_alg);
632 var integer a5_nr := f_alg_from_mask(a5_chosen);
633 BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
634 }
635 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2) -> value pdu {
636 log("Error: Ciphering Mode Command with unexpected content. Expected: ",
637 tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128), " got: ", pdu);
638 setverdict(fail, "Ciphering Mode Command with unexpected content.");
639 mtc.stop;
640 }
641 [] BSSAP.receive(tr_BSSMAP_ClassmarkRequest) {
642 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3))
643 repeat;
644 }
645 }
646 /* FIXME: Send the best available algorithm */
647}
648
649private function f_mm_ciph_utran() runs on BSC_ConnHdlr
650{
651 alt {
652 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
653 uia_key := oct2bit(g_pars.vec.ik),
654 key_sts := ?,
655 uea_algs := ?,
656 uea_key := oct2bit(g_pars.vec.ck))) {
657 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/
658 var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/
659 BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen));
660 }
661 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
662 setverdict(fail, "Invalid SecurityModeCommand (ciphering case)");
663 mtc.stop;
664 }
665 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
666 uia_key := oct2bit(g_pars.vec.ik),
667 key_sts := ?)) {
668 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/
669 BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
670 }
671 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
672 setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)");
673 mtc.stop;
674 }
675 }
676}
677
Harald Welte9de84792018-01-28 01:06:35 +0100678function f_mm_common() runs on BSC_ConnHdlr
679{
680 f_mm_auth();
Eric Wild26f4a622021-05-17 15:27:05 +0200681
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300682 if (g_pars.ran_is_geran) {
683 f_mm_ciph_geran();
684 } else {
685 f_mm_ciph_utran();
Harald Welte148a7082018-01-26 18:56:43 +0100686 }
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300687
688 f_expect_common_id();
Harald Welte148a7082018-01-26 18:56:43 +0100689}
690
Philipp Maier9b690e42018-12-21 11:50:03 +0100691function f_expect_mm_info() runs on BSC_ConnHdlr {
692 if (g_pars.mm_info == true) {
693 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info));
694 }
695}
696
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200697private function f_lac_ci_vty_str(BSSMAP_IE_CellIdentifier cell_id) return charstring
698{
699 return "LAC / cell ID: "
700 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.lac)) & " / "
701 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.ci));
702}
703
704/* Get an IMSI's info and verify that the g_pars.cell_id is reflected in the info.
705 * Verify both the "LAC / cell ID" in the VLR and the "LAC / cell ID" in the "Connection:" part, if any.
706 * If verify_vlr == false, then only verify the "Connection:" part, and fail if there is no "Connection:"; this is
707 * useful when a conn has been established, but the subscriber has not been authenticated, so the VLR does not yet
708 * reflect the new conn's cell ID.
709 */
710function f_verify_vty_lac_ci(boolean verify_vlr := true) runs on BSC_ConnHdlr {
711 if (not g_pars.ran_is_geran) {
712 log("Skipping f_verify_vty_lac_ci(), disabled for Iu");
713 setverdict(pass);
714 return;
715 }
716 if (not g_pars.verify_cell_id) {
717 /* Skip this verification; either the TC expects no cell id to end up being accepted, or this was
718 * disabled globally to test an older osmo-msc which doesn't store the cell id properly yet. */
719 log("Skipping f_verify_vty_lac_ci()");
720 setverdict(pass);
721 return;
722 }
723
724 var charstring vty_cmd := "show subscriber imsi " & hex2str(g_pars.imsi) & " conn";
725 var charstring result := f_vty_transceive_ret(MSCVTY, vty_cmd);
726 var charstring expect_lac_ci := "LAC / cell ID: "
727 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.lac)) & " / "
728 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.ci));
729
730 var boolean vlr_matches := false;
731 var boolean connection_present := false;
732 var boolean connection_matches := false;
733
734 /* There are two occurences of LAC / cell ID: once for the VLR record, and once for the active connection. The
735 * active connection part starts with 'Connection:'. If there is no active connection, that part is omitted.
736 * So, first find out whether there is a 'Connection:' part. Then verify the LAC / cell ID above 'Connection:'
737 * and below 'Connection:', separately.
738 */
739 var integer connection_start := f_strstr(result, "Connection:");
740 connection_present := (connection_start >= 0);
741
742 var integer lac_ci_match := f_strstr(result, expect_lac_ci);
743 if (connection_present) {
744 if (lac_ci_match > connection_start) {
745 /* The first match is below 'Connection:', so the VLR part above it did not match. */
746 vlr_matches := false;
747 connection_matches := true;
748 } else if (lac_ci_match >= 0) {
749 /* The first match is above 'Connection:', so the VLR part matches. */
750 vlr_matches := true;
751
752 /* Now find a match below 'Connection:' */
753 lac_ci_match := f_strstr(result, expect_lac_ci, connection_start);
754 connection_matches := (lac_ci_match > 0);
755 }
756 } else {
757 /* There is no 'Connection:', so a match, if any, is from the VLR part. */
758 vlr_matches := (lac_ci_match >= 0);
759 }
760
761 if (verify_vlr) {
762 if (not vlr_matches) {
763 setverdict(fail, vty_cmd, " shows mismatching LAC / cell ID in the VLR part, expecting: ",
764 expect_lac_ci, " -- got: ", result);
765 return;
766 } else {
767 log("f_verify_vty_lac_ci(): VLR record matches ", expect_lac_ci);
768 setverdict(pass);
769 }
770 }
771
772 if (connection_present) {
773 if (not connection_matches) {
774 setverdict(fail, vty_cmd, " shows mismatching LAC cell ID in the 'Connection' part, expecting: ",
775 expect_lac_ci, " -- got: ", result);
776 } else {
777 log("f_verify_vty_lac_ci(): Active connection matches ", expect_lac_ci);
778 setverdict(pass);
779 }
780 }
781
782 if (not verify_vlr and not connection_present) {
783 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);
784 }
785}
786
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100787function f_perform_lu()
Harald Weltea49e36e2018-01-21 19:29:33 +0100788runs on BSC_ConnHdlr {
789 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
790 var PDU_DTAP_MT dtap_mt;
791
792 /* tell GSUP dispatcher to send this IMSI to us */
793 f_create_gsup_expect(hex2str(g_pars.imsi));
794
795 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Welte9b751a62019-04-14 17:39:29 +0200796 if (g_pars.ran_is_geran) {
797 f_bssap_compl_l3(l3_lu);
798 if (g_pars.send_early_cm) {
799 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
800 }
801 } else {
802 f_ranap_initial_ue(l3_lu);
Harald Welte8a121b32018-01-22 03:00:41 +0100803 }
Harald Welte5c2622c2018-01-21 20:45:20 +0100804
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200805 /* at this point the conn has been established, but the subscriber has not been authenticated, so the VLR does
806 * not yet reflect this conn's cell ID. */
807 f_verify_vty_lac_ci(verify_vlr := false);
808
Oliver Smith1d118ff2019-07-03 10:57:35 +0200809 f_mm_imei_early();
Harald Weltede371492018-01-27 23:44:41 +0100810 f_mm_common();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100811 f_msc_lu_hlr();
Oliver Smith1d118ff2019-07-03 10:57:35 +0200812 f_mm_imei();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100813 f_accept_reject_lu();
814 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
815 f_expect_clear();
Harald Welte16114282018-01-24 22:41:21 +0100816
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100817 setverdict(pass);
818}
819
820function f_msc_lu_hlr() runs on BSC_ConnHdlr
821{
Harald Weltea49e36e2018-01-21 19:29:33 +0100822 /* Expect MSC to perform LU with HLR */
823 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
824 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
825 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
826 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100827}
828
829function f_accept_reject_lu() runs on BSC_ConnHdlr {
830 var PDU_DTAP_MT dtap_mt;
Harald Weltea49e36e2018-01-21 19:29:33 +0100831
832 alt {
833 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
834 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
Harald Weltede371492018-01-27 23:44:41 +0100835 if (g_pars.net.expect_tmsi) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100836 if (not ispresent(lu_acc.mobileIdentityTLV) or
837 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
838 setverdict(fail, "Expected TMSI but no TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200839 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100840 } else {
Harald Welte256571e2018-01-24 18:47:19 +0100841 g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets;
Harald Weltea49e36e2018-01-21 19:29:33 +0100842 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
843 }
844 } else {
845 if (ispresent(lu_acc.mobileIdentityTLV) and
846 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
847 setverdict(fail, "Expected no TMSI but TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200848 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100849 }
850 }
851 }
852 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
853 setverdict(fail, "Expected LU ACK, but received LU REJ");
Daniel Willmannafce8662018-07-06 23:11:32 +0200854 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100855 }
856 }
Philipp Maier9b690e42018-12-21 11:50:03 +0100857
858 /* Wait for MM-Information (if enabled) */
859 f_expect_mm_info();
Harald Weltea49e36e2018-01-21 19:29:33 +0100860 setverdict(pass);
861}
862
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100863function f_expect_lu_reject(template OCT1 cause := ?) runs on BSC_ConnHdlr {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200864 var PDU_DTAP_MT dtap_mt;
865 timer T := 5.0;
866
867 T.start;
868 alt {
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100869 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej(cause))) {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200870 setverdict(pass);
871 }
872 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
873 setverdict(fail, "Expected LU reject BSSAP message, got: ", dtap_mt);
874 }
875 [] T.timeout {
876 setverdict(fail, "Timeout waiting for LU reject");
877 }
878 }
879}
880
Harald Weltea49e36e2018-01-21 19:29:33 +0100881function f_foo() runs on BSC_ConnHdlr{
Harald Welte6811d102019-04-14 22:23:14 +0200882 /* SCCP CC handled by RAN_Emulation_CT.main() */
Harald Weltea49e36e2018-01-21 19:29:33 +0100883 /* Expect auth, if enabled */
884
885 /* TODO: ISD */
886 /* Expect encr, if enabled */
887 /* Expect encr, if enabled */
888 /* Expect ASS CMD, if chan_type != requested */
889 /* Send ASS CMPL in successful case */
890
891 /* Expect AoIP port/ip information for RTP stream */
892 /* Expect MSC-originated MGCP to our simulated MGW */
893 /* Verify Counters via CTRL */
894 /* re-configure MSC behaviour via VTY */
895}
896
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200897type record CrcxResponse {
898 integer resp, /* 1 = reply with OK, 0 = do not reply, -1 = reply with error */
899 HostName mgw_rtp_ip,
900 PortNumber mgw_rtp_port,
901 MgcpConnectionId mgcp_connection_id /* MGCP Connection ID BSS Side */
902}
903
Harald Welteb71901a2018-01-26 19:16:05 +0100904/* parameters related to a (MO?) voice call */
905type record CallParameters {
Harald Welteb71901a2018-01-26 19:16:05 +0100906 /* CC related parameters */
907 hexstring called_party, /* whom are we calling */
908 integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100909 boolean mo_call, /* For a MO call, the transaction_id was allocated by the MS,
910 important to set the TI flag properly */
Harald Welteb71901a2018-01-26 19:16:05 +0100911 BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */
Harald Welte0bef21e2018-02-10 09:48:23 +0100912 boolean emergency, /* is this an emergency call? */
Harald Welteb71901a2018-01-26 19:16:05 +0100913
914 /* MNCC related parameters */
915 uint32_t mncc_callref optional, /* call reference on the MNCC side */
916 MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200917 HostName mncc_rtp_ip optional, /* MNCC Side RTP IP */
918 PortNumber mncc_rtp_port optional, /* MNCC Side RTP port */
Harald Welteb71901a2018-01-26 19:16:05 +0100919
920 /* RTP related parameters */
921 HostName bss_rtp_ip optional, /* BSS Side RTP IP */
922 PortNumber bss_rtp_port optional, /* BSS Side RTP Port */
923 HostName mss_rtp_ip optional, /* MSS Side RTP IP */
924 PortNumber mss_rtp_port optional, /* MSS Side RTP Port */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200925 integer got_crcx_count,
926 CrcxResponse mgw_conn_1,
927 CrcxResponse mgw_conn_2,
Harald Welteb71901a2018-01-26 19:16:05 +0100928 uint7_t rtp_payload_type, /* dynamic RTP payload type */
929 charstring rtp_sdp_format, /* AMR/8000 or the like */
Philipp Maier2a98a732018-03-19 16:06:12 +0100930 boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX
931 (f_mt_call and f_mt_call) */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200932 boolean stop_after_cc_setup, /* Special case: stop call establish after CC Setup */
933 boolean ran_clear_when_alerting, /* Special case: send Clear upon CC Alerting */
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100934 boolean expect_release, /* Special case: expect call establish to cause direct CC Rel */
Harald Welteb71901a2018-01-26 19:16:05 +0100935
Philipp Maiercd668572018-03-19 16:11:52 +0100936 MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */
Harald Welteb71901a2018-01-26 19:16:05 +0100937 MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200938
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200939 boolean use_osmux, /* MSC is expected to use Osmux for this call */
940 integer got_osmux_count
Harald Welteb71901a2018-01-26 19:16:05 +0100941}
942
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200943template (value) CallParameters t_CallParams(hexstring called := '12345'H, integer tid := 0) := {
Harald Welteb71901a2018-01-26 19:16:05 +0100944 called_party := called,
945 transaction_id := tid,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100946 mo_call := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100947 bearer_cap := valueof(ts_Bcap_voice),
Harald Welte0bef21e2018-02-10 09:48:23 +0100948 emergency := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100949 mncc_callref := omit,
950 mncc_bearer_cap := valueof(ts_MNCC_bcap_voice),
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200951 mncc_rtp_ip := "42.23.11.5",
952 mncc_rtp_port := 423,
Harald Welte4017d552018-01-26 21:40:05 +0100953 bss_rtp_ip := "9.8.7.6",
954 bss_rtp_port := 9000,
Harald Welteb71901a2018-01-26 19:16:05 +0100955 mss_rtp_ip := omit,
956 mss_rtp_port := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200957 got_crcx_count := 0,
958 mgw_conn_1 := {
959 resp := 1,
960 mgw_rtp_ip := "1.1.1.1",
961 mgw_rtp_port := 10000,
962 mgcp_connection_id := '11111'H
963 },
964 mgw_conn_2 := {
965 resp := 1,
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +0200966 mgw_rtp_ip := "2.2.2.2",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200967 mgw_rtp_port := 11000,
968 mgcp_connection_id := '22222'H
969 },
Harald Welteb71901a2018-01-26 19:16:05 +0100970 rtp_payload_type := 98,
971 rtp_sdp_format := "AMR/8000",
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100972 mgw_drop_dlcx := false,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200973 stop_after_cc_setup := false,
974 ran_clear_when_alerting := false,
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100975 expect_release := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100976 mgcp_call_id := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200977 mgcp_ep := "rtpbridge/1@mgw",
978 use_osmux := false,
979 got_osmux_count := 0
Harald Welteb71901a2018-01-26 19:16:05 +0100980};
981
Neels Hofmeyrf797d292021-07-27 22:33:09 +0200982template CallParameters tr_CallParams := {
983 called_party := ?,
984 transaction_id := ?,
985 mo_call := ?,
986 bearer_cap := ?,
987 emergency := ?,
988 mncc_callref := *,
989 mncc_bearer_cap := ?,
990 mncc_rtp_ip := ?,
991 mncc_rtp_port := ?,
992 bss_rtp_ip := ?,
993 bss_rtp_port := ?,
994 mss_rtp_ip := *,
995 mss_rtp_port := *,
996 got_crcx_count := ?,
997 mgw_conn_1 := ?,
998 mgw_conn_2 := ?,
999 rtp_payload_type := ?,
1000 rtp_sdp_format := ?,
1001 mgw_drop_dlcx := ?,
1002 stop_after_cc_setup := ?,
1003 ran_clear_when_alerting := ?,
1004 expect_release := ?,
1005 mgcp_call_id := *,
1006 mgcp_ep := ?,
1007 use_osmux := ?,
1008 got_osmux_count := ?
1009};
1010
Harald Welte4263c522018-12-06 11:56:27 +01001011/* Allocate a call reference and send SETUP via MNCC to MSC */
1012function f_mt_call_initate(inout CallParameters cpars)
Harald Welte33ec09b2018-02-10 15:34:46 +01001013runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001014 cpars.mo_call := false;
Harald Welte4263c522018-12-06 11:56:27 +01001015 cpars.mncc_callref := f_rnd_int(2147483648);
1016 MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
1017 hex2str(cpars.called_party), hex2str(g_pars.imsi)));
1018}
Harald Welte33ec09b2018-02-10 15:34:46 +01001019
Harald Welte408a7ef2019-04-21 17:08:40 +02001020private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) :=
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001021 ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
Harald Welte408a7ef2019-04-21 17:08:40 +02001022 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001023 cpars.mgw_conn_2.mgw_rtp_port,
Harald Welte408a7ef2019-04-21 17:08:40 +02001024 { int2str(cpars.rtp_payload_type) },
1025 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1026 cpars.rtp_sdp_format)),
1027 valueof(ts_SDP_ptime(20)) });
1028
Harald Welte4263c522018-12-06 11:56:27 +01001029/* Complete call, begin with a paging response message via BSSAP */
1030function f_mt_call_complete(inout CallParameters cpars)
1031runs on BSC_ConnHdlr {
Harald Welte33ec09b2018-02-10 15:34:46 +01001032 var MNCC_PDU mncc;
1033 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001034 var template MgcpResponse mgcp_resp;
1035 var MgcpOsmuxCID osmux_cid;
1036 var PDU_BSSAP bssap;
Harald Welte33ec09b2018-02-10 15:34:46 +01001037
Harald Welte6811d102019-04-14 22:23:14 +02001038 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Welte33ec09b2018-02-10 15:34:46 +01001039
Harald Welteb9e86fa2018-04-09 18:18:31 +02001040 f_establish_fully(EST_TYPE_PAG_RESP);
Harald Welte33ec09b2018-02-10 15:34:46 +01001041
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001042 log("f_mt_call_complete 1");
1043
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001044 cpars.got_osmux_count := 0;
1045
Harald Welte33ec09b2018-02-10 15:34:46 +01001046 /* MS <- MSC: Expect CC SETUP */
1047 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party)));
1048
1049 /* MS -> MSC: ALERTING */
1050 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id)));
1051 MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001052 log("f_mt_call_complete 2");
Harald Welte33ec09b2018-02-10 15:34:46 +01001053
Harald Welte33ec09b2018-02-10 15:34:46 +01001054 /* Create MGCP expect */
1055 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1056 /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */
1057 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1058
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001059 /* First MGCP CRCX */
Harald Welte33ec09b2018-02-10 15:34:46 +01001060 MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001061 log("f_mt_call_complete 3");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001062 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1063 return;
Philipp Maier4b2692d2018-03-14 16:37:48 +01001064 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001065 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001066
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001067
Harald Welte9b751a62019-04-14 17:39:29 +02001068 if (g_pars.ran_is_geran) {
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001069 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass1 :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001070 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001071 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass2 :=
1072 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_2.mgw_rtp_ip, ?);
Harald Welte9b751a62019-04-14 17:39:29 +02001073
1074 interleave {
1075 /* Second MGCP CRCX (this time for MSS/CN side) */
1076 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001077 log("f_mt_call_complete 4");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001078 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1079 break;
1080 }
Harald Welte9b751a62019-04-14 17:39:29 +02001081 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001082
1083 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1084 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1085 log("f_mt_call_complete 5");
1086 }
1087
Harald Welte9b751a62019-04-14 17:39:29 +02001088 /* expect the MSC to trigger a BSSMAP ASSIGNMENT */
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001089 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, (tla_ass1, tla_ass2))) -> value bssap {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001090 var template BSSMAP_IE_AoIP_TransportLayerAddress tla;
Harald Welte9b751a62019-04-14 17:39:29 +02001091 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001092 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001093 log("f_mt_call_complete 6");
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001094 tla := f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port);
Harald Welte9b751a62019-04-14 17:39:29 +02001095 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
1096
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001097 if (cpars.use_osmux) {
1098 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1099 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1100 mtc.stop;
1101 }
1102 osmuxCID := valueof(ts_OsmuxCID(0));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001103 if (not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1104 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 +02001105 mtc.stop;
1106 }
1107 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1108 } else {
1109 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1110 }
1111 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001112
1113 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
Harald Welte9b751a62019-04-14 17:39:29 +02001114 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001115
1116 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1117 log("f_mt_call_complete 7");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001118 var octetstring ip;
1119 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1120 if (is_ipv6) {
1121 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1122 } else {
1123 ip := f_inet_addr(cpars.mncc_rtp_ip);
1124 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001125 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001126 is_ipv6, ip,
1127 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001128 /* payload type 3 = GSM FR */ 3));
1129 }
1130
1131 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1132 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1133 log("f_mt_call_complete 8");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001134 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 +01001135 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001136 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001137 { int2str(cpars.rtp_payload_type) },
1138 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1139 cpars.rtp_sdp_format)),
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001140 valueof(ts_SDP_ptime(20)) }));
1141 if (cpars.use_osmux) {
1142 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1143 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1144 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1145 mtc.stop;
1146 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001147 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 +02001148 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001149 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 +02001150 }
1151 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001152 }
1153
1154 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1155 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001156 var SDP_Message sdp;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001157 log("f_mt_call_complete 9");
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001158
1159 if (isvalue(mgcp_cmd.sdp)) {
1160 sdp := mgcp_cmd.sdp;
1161 if (sdp.media_list[0].media_field.ports.port_number != cpars.mncc_rtp_port) {
1162 setverdict(fail, "Wrong MDCX Connection port received, expected ", cpars.mncc_rtp_port, " and received ", sdp.media_list[0].media_field.ports.port_number)
1163 mtc.stop;
1164 }
1165 if (sdp.connection.conn_addr.addr != cpars.mncc_rtp_ip) {
1166 setverdict(fail, "Wrong MDCX Connection address received, expected ", cpars.mncc_rtp_ip, " and received ", sdp.connection.conn_addr.addr)
1167 mtc.stop;
1168 }
1169 }
1170
1171 sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1172 hex2str(cpars.mgcp_call_id), "42",
1173 cpars.mgw_conn_2.mgw_rtp_port,
1174 { int2str(cpars.rtp_payload_type) },
1175 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1176 cpars.rtp_sdp_format)),
1177 valueof(ts_SDP_ptime(20)) }));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001178 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 +01001179 }
1180
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001181 }
Harald Welte9b751a62019-04-14 17:39:29 +02001182 } else {
Harald Welte9b751a62019-04-14 17:39:29 +02001183 interleave {
1184 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001185 log("f_mt_call_complete 4.iu");
1186 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1187 break;
Harald Welte9b751a62019-04-14 17:39:29 +02001188 }
Harald Welte9b751a62019-04-14 17:39:29 +02001189 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001190
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001191 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1192 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1193 log("f_mt_call_complete 5.iu");
1194 }
1195
1196 [] BSSAP.receive(tr_RANAP_RabAssReq(?)) {
1197 log("f_mt_call_complete 6.iu");
1198 var RAB_SetupOrModifiedList l := {
1199 {
1200 {
1201 id := id_RAB_SetupOrModifiedItem,
1202 criticality := ignore,
1203 value_ := {
1204 rAB_SetupOrModifiedItem := {
1205 rAB_ID := int2bit(23, 8),
1206 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1207 iuTransportAssociation := {
1208 bindingID := '040c0000'O
1209 },
1210 dl_dataVolumes := omit,
1211 iE_Extensions := omit
1212 }
1213 }
1214 }
1215 }
1216 };
1217 BSSAP.send(ts_RANAP_RabAssResp(l));
1218
1219 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
1220 }
1221
1222 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1223 log("f_mt_call_complete 7.iu");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001224 var octetstring ip;
1225 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1226 if (is_ipv6) {
1227 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1228 } else {
1229 ip := f_inet_addr(cpars.mncc_rtp_ip);
1230 }
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001231 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001232 is_ipv6, ip,
1233 cpars.mncc_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001234 /* payload type 3 = GSM FR */ 3));
1235 }
1236
1237 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1238 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1239 log("f_mt_call_complete 8.iu");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001240 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 +01001241 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001242 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001243 { int2str(cpars.rtp_payload_type) },
1244 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1245 cpars.rtp_sdp_format)),
1246 valueof(ts_SDP_ptime(20)) }));
1247 if (cpars.use_osmux) {
1248 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1249 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1250 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1251 mtc.stop;
1252 }
1253 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
1254 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001255 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 +01001256 }
1257 MGCP.send(mgcp_resp);
1258 }
1259
1260 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1261 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1262 log("f_mt_call_complete 9.iu");
1263 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1264 hex2str(cpars.mgcp_call_id), "42",
1265 cpars.mgw_conn_2.mgw_rtp_port,
1266 { int2str(cpars.rtp_payload_type) },
1267 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1268 cpars.rtp_sdp_format)),
1269 valueof(ts_SDP_ptime(20)) }));
1270 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
1271 }
1272
Harald Welte33ec09b2018-02-10 15:34:46 +01001273 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001274 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001275
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001276 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1277 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1278 } else {
1279 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1280 mtc.stop;
1281 }
1282
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001283 log("f_mt_call_complete DONE");
Harald Welte4263c522018-12-06 11:56:27 +01001284}
1285
Harald Weltee035e3e2019-04-21 17:32:05 +02001286function f_expect_paging(boolean by_tmsi := true)
1287runs on BSC_ConnHdlr {
Harald Welte9b751a62019-04-14 17:39:29 +02001288 if (g_pars.ran_is_geran) {
1289 BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
1290 } else {
Harald Welte62113fc2019-05-09 13:04:02 +02001291 BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi)));
Harald Welte9b751a62019-04-14 17:39:29 +02001292 }
Harald Weltee035e3e2019-04-21 17:32:05 +02001293}
1294
Harald Welte4263c522018-12-06 11:56:27 +01001295function f_mt_call_establish(inout CallParameters cpars)
1296runs on BSC_ConnHdlr {
1297
1298 /* Initiate the call via MNCC */
1299 f_mt_call_initate(cpars);
1300
1301 /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
Harald Welte6811d102019-04-14 22:23:14 +02001302 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Weltee035e3e2019-04-21 17:32:05 +02001303 f_expect_paging()
Harald Welte4263c522018-12-06 11:56:27 +01001304
1305 /* Complete the call via BSSAP */
1306 f_mt_call_complete(cpars);
Harald Welte33ec09b2018-02-10 15:34:46 +01001307
Harald Welte33ec09b2018-02-10 15:34:46 +01001308 setverdict(pass);
1309}
1310
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001311/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1312 * Return true when an OK reply was sent, false otherwise.
1313 * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */
1314function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd)
1315runs on BSC_ConnHdlr
1316return boolean {
1317 var CrcxResponse conn := cpars.mgw_conn_1;
1318 if (cpars.got_crcx_count > 0) {
1319 conn := cpars.mgw_conn_2;
1320 }
1321 cpars.got_crcx_count := cpars.got_crcx_count + 1;
1322
1323 var MgcpMessage mgcp_msg := {
1324 command := mgcp_cmd
1325 }
1326 var template MgcpResponse mgcp_resp;
1327 var MgcpOsmuxCID osmux_cid;
1328 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1329 if (ispresent(cpars.mgcp_call_id)) {
1330 if (cpars.mgcp_call_id != call_id) {
1331 setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id);
1332 mtc.stop;
1333 }
1334 } else {
1335 cpars.mgcp_call_id := call_id;
1336 }
1337
1338 /* When the endpoint contains a wildcard we keep the endpoint
1339 * identifier we have set up in cpars. Otherwise we use the
1340 * endpoint name that the call agent has supplied */
1341 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1342 cpars.mgcp_ep := mgcp_cmd.line.ep;
1343 }
1344
1345 if (conn.resp == -1) {
1346 /* Reply with error */
1347 var MgcpResponse mgcp_rsp := {
1348 line := {
1349 code := "542",
1350 trans_id := mgcp_cmd.line.trans_id,
1351 string := "FORCED_FAIL"
1352 },
1353 sdp := omit
1354
1355 }
1356 var MgcpParameter mgcp_rsp_param := {
1357 code := "Z",
1358 val := cpars.mgcp_ep
1359 };
1360 mgcp_rsp.params[0] := mgcp_rsp_param;
1361 MGCP.send(mgcp_rsp);
1362 return false;
1363 }
1364
1365 if (conn.resp == 0) {
1366 /* Do not reply at all */
1367 return false;
1368 }
1369
1370 if (conn.resp != 1) {
1371 setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1");
1372 mtc.stop;
1373 }
1374
1375 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1376 hex2str(cpars.mgcp_call_id), "42",
1377 conn.mgw_rtp_port,
1378 { int2str(cpars.rtp_payload_type) },
1379 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1380 cpars.rtp_sdp_format)),
1381 valueof(ts_SDP_ptime(20)) }));
1382
1383 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1384 if (not cpars.use_osmux) {
1385 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1386 mtc.stop;
1387 }
1388 cpars.got_osmux_count := cpars.got_osmux_count + 1;
1389 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1390 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1391 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1392 if (osmux_cid != -1) {
1393 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1394 mtc.stop;
1395 }
1396
1397 osmux_cid := 0;
1398 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1399 } else {
1400 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1401 }
1402
1403 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep));
1404 MGCP.send(mgcp_resp);
1405 return true;
1406}
1407
1408
1409altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr {
1410 var MgcpCommand mgcp_cmd;
1411 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1412 log("as_optional_mgcp_crcx: rx CRCX");
1413 f_handle_crcx(cpars, mgcp_cmd);
1414
1415 /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an
1416 * CRCX is handled. */
1417 repeat;
1418 }
1419}
1420
1421private altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr {
1422 var MgcpCommand mgcp_cmd;
1423 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1424 log("as_optional_mgcp_mdcx: rx MDCX");
1425 log(mgcp_cmd);
1426 var charstring conn_id;
1427 var charstring rtp_payload_type;
1428 f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id);
1429 rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0];
1430
1431 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip,
1432 mgcp_cmd.sdp.origin.session_id, "42",
1433 mgw_rtp_port,
1434 { rtp_payload_type },
1435 { valueof(ts_SDP_ptime(20)) }));
1436 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp));
1437
1438 /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is
1439 * handled. */
1440 repeat;
1441 }
1442}
1443
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001444private altstep as_optional_mgcp_dlcx(CallParameters cpars) runs on BSC_ConnHdlr {
1445 var MgcpCommand mgcp_cmd;
1446 var boolean respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1447 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1448 log("as_optional_mgcp_dlcx: rx MGCP DLCX");
1449 if (respond_to_dlcx) {
1450 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1451 }
1452 /* Without this 'repeat', currently active other interleave and alt series exit as soon as a
1453 * DLCX is handled. */
1454 repeat;
1455 }
1456}
1457
Philipp Maier3716a5e2018-03-21 15:53:35 +01001458function f_mo_call_establish(inout CallParameters cpars)
Harald Welteb71901a2018-01-26 19:16:05 +01001459runs on BSC_ConnHdlr {
1460
Harald Welteb71901a2018-01-26 19:16:05 +01001461 var MNCC_PDU mncc;
1462 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001463 var template MgcpResponse mgcp_resp;
Philipp Maier2a98a732018-03-19 16:06:12 +01001464 var boolean respond_to_dlcx;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001465 var PDU_BSSAP bssap;
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001466 var RANAP_PDU ranap;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001467 var MgcpOsmuxCID osmux_cid;
Harald Welteb71901a2018-01-26 19:16:05 +01001468
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001469 cpars.mo_call := true;
1470
Harald Welte0bef21e2018-02-10 09:48:23 +01001471 if (cpars.emergency) {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001472 f_establish_fully(EST_TYPE_EMERG_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001473 } else {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001474 f_establish_fully(EST_TYPE_MO_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001475 }
Harald Welteb71901a2018-01-26 19:16:05 +01001476
1477 /* Create MNCC and MGCP expect */
1478 f_create_mncc_expect(hex2str(cpars.called_party));
1479 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1480
Harald Welte0bef21e2018-02-10 09:48:23 +01001481 if (cpars.emergency) {
1482 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id)));
1483 } else {
1484 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party)));
1485 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001486
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001487 if (cpars.stop_after_cc_setup) {
1488 return;
1489 }
1490
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001491 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass1 :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001492 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001493 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass2 :=
1494 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_2.mgw_rtp_ip, ?);
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001495
1496 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 +01001497 var boolean got_mncc_setup_compl_ind := false;
1498 var boolean got_cc_connect := false;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001499
Harald Welteb71901a2018-01-26 19:16:05 +01001500 interleave {
1501 [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001502 log("f_mo_call_establish 1: rx MNCC SETUP ind");
Harald Welteb71901a2018-01-26 19:16:05 +01001503 cpars.mncc_callref := mncc.u.signal.callref;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001504 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1505 }
1506
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001507 /* First MGCP CRCX */
Harald Welteb71901a2018-01-26 19:16:05 +01001508 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001509 log("f_mo_call_establish 2: rx 1st CRCX");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001510 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1511 break;
1512 }
Philipp Maierf1e02bb2018-03-15 16:30:00 +01001513 }
1514
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001515 /* Second MGCP CRCX */
1516 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
1517 log("f_mo_call_establish 6: rx 2nd CRCX");
1518 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1519 break;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001520 }
Harald Welteb71901a2018-01-26 19:16:05 +01001521 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001522
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001523 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1524 log("f_mo_call_establish 3: rx RTP CREATE");
1525 /* Call Proceeding */
1526 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1527 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001528
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001529 /* Alerting */
1530 MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref));
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001531 }
Harald Welte9b751a62019-04-14 17:39:29 +02001532
Neels Hofmeyreccaa992019-10-15 16:42:21 +02001533 //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001534 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001535 log("f_mo_call_establish 4: rx Assignment Request");
1536 var BSSMAP_IE_AoIP_TransportLayerAddress tla;
1537 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001538 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
1539
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001540 if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass1)
1541 and not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass2)) {
1542 log("Expected one of: 1:", tla_ass1, " 2:", tla_ass2);
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001543 log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer);
1544 setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE");
1545 mtc.stop;
1546 }
1547
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001548 tla := valueof(f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001549 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001550 if (cpars.use_osmux) {
1551 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1552 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1553 mtc.stop;
1554 }
1555 osmuxCID := valueof(ts_OsmuxCID(0));
1556 if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1557 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1558 mtc.stop;
1559 }
1560 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1561 } else {
1562 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1563 }
1564 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001565 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001566 [] BSSAP.receive(tr_RANAP_RabAssReq(*)) -> value ranap {
1567 log("f_mo_call_establish 4.iu: rx RANAP RAB Assignment Request");
1568 var RAB_SetupOrModifiedList l := {
1569 {
1570 {
1571 id := id_RAB_SetupOrModifiedItem,
1572 criticality := ignore,
1573 value_ := {
1574 rAB_SetupOrModifiedItem := {
1575 rAB_ID := int2bit(23, 8),
1576 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1577 iuTransportAssociation := {
1578 bindingID := '040c0000'O
1579 },
1580 dl_dataVolumes := omit,
1581 iE_Extensions := omit
1582 }
1583 }
1584 }
1585 }
1586 };
1587 BSSAP.send(ts_RANAP_RabAssResp(l));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001588 }
Harald Welte9b751a62019-04-14 17:39:29 +02001589
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001590 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1591 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1592 log("f_mo_call_establish 5: rx MDCX for the RAN side");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001593 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 +01001594 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001595 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001596 { int2str(cpars.rtp_payload_type) },
1597 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1598 cpars.rtp_sdp_format)),
1599 valueof(ts_SDP_ptime(20)) }));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001600
1601 if (cpars.use_osmux) {
1602 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1603 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1604 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1605 mtc.stop;
1606 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001607 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 +02001608 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001609 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 +02001610 }
1611 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001612 }
Harald Welte9b751a62019-04-14 17:39:29 +02001613
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001614 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {
1615 log("f_mo_call_establish 7: rx CC Alerting");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001616
1617 if (cpars.ran_clear_when_alerting) {
1618 if (g_pars.ran_is_geran) {
1619 BSSAP.send(ts_BSSMAP_ClearRequest(0));
1620 } else {
1621 BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention));
1622 }
1623 break;
1624 }
1625
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001626 cpars.mncc_callref := mncc.u.signal.callref;
1627 /* Call Proceeding */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001628 var octetstring ip;
1629 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1630 if (is_ipv6) {
1631 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1632 } else {
1633 ip := f_inet_addr(cpars.mncc_rtp_ip);
1634 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001635 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001636 is_ipv6, ip,
1637 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001638 /* payload type 3 = GSM FR */ 3));
1639 MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref));
1640 }
1641
1642 [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc {
1643 log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001644 got_mncc_setup_compl_ind := true;
1645 if (not cpars.expect_release and got_cc_connect) {
1646 break;
1647 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001648 }
1649
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001650 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) {
1651 log("f_mo_call_establish 10: rx CC CONNECT");
1652 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id)));
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001653 got_cc_connect := true;
1654 if (not cpars.expect_release and got_mncc_setup_compl_ind) {
1655 break;
1656 }
Harald Welteb71901a2018-01-26 19:16:05 +01001657 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001658
1659 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1660 log("f_mo_call_establish 11: rx CC RELEASE");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001661 if (not cpars.expect_release) {
1662 setverdict(fail, "Got unexpected CC Release");
1663 mtc.stop;
1664 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001665 f_expect_clear();
1666 break;
1667 }
1668 }
1669
1670 f_sleep(0.5);
1671 deactivate(mdcx);
1672
1673 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1674 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1675 } else {
1676 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1677 mtc.stop;
Harald Welteb71901a2018-01-26 19:16:05 +01001678 }
1679
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001680 log("f_mo_call_establish DONE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001681 setverdict(pass);
1682}
Harald Welteb71901a2018-01-26 19:16:05 +01001683
Harald Welte4c422b72019-02-17 16:27:10 +01001684function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001685runs on BSC_ConnHdlr {
1686
1687 var MobileIdentityLV mi;
1688 var MNCC_PDU mncc;
1689 var MgcpCommand mgcp_cmd;
1690 var boolean respond_to_dlcx;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001691 var boolean dlcx_contained_ci := false;
1692 var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand;
1693
1694 if (is_csfb) {
1695 t_clear := tr_BSSMAP_ClearCommandCSFB;
1696 }
1697
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001698 log("f_call_hangup 0: tx MNCC_DISC_REQ");
Harald Welteb71901a2018-01-26 19:16:05 +01001699 MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1700 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1701
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001702 log("f_call_hangup 1: rx DTAP CC DISC");
1703
Philipp Maier3716a5e2018-03-21 15:53:35 +01001704 if (release_by_ms) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001705 var BIT1 tid_remote := '1'B;
1706 if (cpars.mo_call) {
1707 tid_remote := '0'B;
1708 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001709 /* B-side (MS) Release of call */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001710 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 +01001711 MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001712 log("f_call_hangup 2: rx MNCC REL ind");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001713 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001714 log("f_call_hangup 3: rx DTAP CC REL COMPL");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001715 } else {
1716 /* A-side (PLMN) Release of call */
1717 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42))));
1718 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001719 log("f_call_hangup 4: rx DTAP CC RELEASE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001720 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
1721 }
Harald Welteb71901a2018-01-26 19:16:05 +01001722
Philipp Maier2a98a732018-03-19 16:06:12 +01001723 respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1724
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001725 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 +01001726 var default dlcx := activate(as_optional_mgcp_dlcx(cpars));
Harald Welte9b751a62019-04-14 17:39:29 +02001727
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001728 /* clearing of radio channel */
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001729 alt {
1730 [g_pars.ran_is_geran] BSSAP.receive(t_clear) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001731 log("f_call_hangup 5: rx BSSAP Clear Command");
1732 BSSAP.send(ts_BSSMAP_ClearComplete);
1733 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1734 log("f_call_hangup 6: rx SCCP DISC");
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001735 setverdict(pass);
Philipp Maier2a98a732018-03-19 16:06:12 +01001736 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001737 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) {
1738 log("f_call_hangup 5.iu: rx Iu Release Command");
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001739 BSSAP.send(ts_RANAP_IuReleaseComplete);
1740 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001741 log("f_call_hangup 6.iu: rx SCCP DISC");
1742 setverdict(pass);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001743 }
1744 }
1745
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001746 f_sleep(1.0);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001747 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1748 log("f_call_hangup 9: done");
1749
1750 deactivate(mdcx);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001751 deactivate(dlcx);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001752}
1753
1754function f_mt_call(inout CallParameters cpars)
1755runs on BSC_ConnHdlr {
1756
1757 f_mt_call_establish(cpars);
1758
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001759 log("Hold the call for some time");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001760 f_sleep(3.0);
1761
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001762 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001763 f_call_hangup(cpars, true);
1764
1765 setverdict(pass);
1766}
1767
1768function f_mo_call(inout CallParameters cpars)
1769runs on BSC_ConnHdlr {
1770
1771 f_mo_call_establish(cpars);
1772
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001773 log("Hold the call for some time");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001774 f_sleep(3.0);
1775
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001776 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001777 f_call_hangup(cpars, false);
1778
Harald Welteb71901a2018-01-26 19:16:05 +01001779 setverdict(pass);
1780}
Harald Weltea49e36e2018-01-21 19:29:33 +01001781
Daniel Willmann8b084372018-02-04 13:35:26 +01001782function f_mo_seq_dtmf_dup(inout CallParameters cpars)
1783runs on BSC_ConnHdlr {
1784
1785 timer T := 1.0;
Daniel Willmann8b084372018-02-04 13:35:26 +01001786 var MNCC_PDU mncc;
1787 var MgcpCommand mgcp_cmd;
1788 var template PDU_ML3_MS_NW dtmf_dtap;
1789
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001790 f_mo_call_establish(cpars);
Daniel Willmann8b084372018-02-04 13:35:26 +01001791
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001792 /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by
1793 * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001794
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001795 /* Find out the next NSD that will be used, from RAN emulation. */
1796 var N_Sd_Array last_n_sd := f_bssmap_last_n_sd();
1797 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 +01001798
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001799 /* Compose DTAP with this correct NSD */
Daniel Willmann8b084372018-02-04 13:35:26 +01001800 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001801
1802 /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */
1803 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001804 T.start;
1805 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001806 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
1807 log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind");
1808 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001809 [] T.timeout {
1810 setverdict(fail, "Timeout waiting for START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001811 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001812 }
1813 }
1814
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001815 /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message
1816 * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */
1817 dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2);
Daniel Willmann92f66272018-02-06 15:50:52 +01001818 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true));
Daniel Willmann8b084372018-02-04 13:35:26 +01001819 T.start;
1820 alt {
1821 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001822 setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001823 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001824 }
1825 [] T.timeout { }
1826 }
1827
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001828 /* Here the NSD should be correct again and we see a DTMF. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001829 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001830 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001831 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001832 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) {
1833 log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind");
1834 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001835 [] T.timeout {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001836 setverdict(fail, "Timeout waiting for final START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001837 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001838 }
1839 }
1840
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001841 f_call_hangup(cpars, true);
Daniel Willmann8b084372018-02-04 13:35:26 +01001842 setverdict(pass);
1843}
Harald Welte9b751a62019-04-14 17:39:29 +02001844
Harald Welte1ddc7162018-01-27 14:25:46 +01001845/* expect a clear command */
Harald Welte5946b332018-03-18 23:32:21 +01001846altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr {
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001847 var PDU_BSSAP bssap;
Harald Welte5946b332018-03-18 23:32:21 +01001848 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1849 BSSAP.send(ts_BSSMAP_ClearComplete);
1850 alt {
Harald Welte6811d102019-04-14 22:23:14 +02001851 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte5946b332018-03-18 23:32:21 +01001852 setverdict(pass);
1853 }
1854 [] BSSAP.receive {
1855 setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001856 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001857 }
1858 }
1859 }
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001860 [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap {
1861 setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001862 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001863 }
1864}
1865
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001866function f_expect_clear(float t := 5.0, boolean verify_vlr_cell_id := true) runs on BSC_ConnHdlr {
Harald Welte1ddc7162018-01-27 14:25:46 +01001867 timer T := t;
1868
1869 T.start;
1870 alt {
Harald Welte9b751a62019-04-14 17:39:29 +02001871 [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { }
1872 [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { }
Harald Welte1ddc7162018-01-27 14:25:46 +01001873 [] T.timeout {
Harald Welte5946b332018-03-18 23:32:21 +01001874 setverdict(fail, "Timeout waiting for ClearCommand/Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001875 mtc.stop;
Harald Welte1ddc7162018-01-27 14:25:46 +01001876 }
1877 }
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001878
1879 if (verify_vlr_cell_id) {
1880 /* Now the conn is gone, but the VLR reflects the cell ID */
1881 f_verify_vty_lac_ci();
1882 }
Harald Welte1ddc7162018-01-27 14:25:46 +01001883}
1884
Neels Hofmeyr0ac63152019-05-07 01:20:17 +02001885function f_create_bssmap_exp_handoverRequest(integer targetPointCode) runs on BSC_ConnHdlr {
1886 BSSAP_PROC.call(RAN_register_handoverRequest:{targetPointCode, self}) {
1887 [] BSSAP_PROC.getreply(RAN_register_handoverRequest:{?, ?}) {};
1888 }
1889}
1890
1891function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array {
1892 var N_Sd_Array last_n_sd;
1893 BSSAP_PROC.call(RAN_last_n_sd:{self, -}) {
1894 [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) {
1895 return last_n_sd;
1896 };
1897 }
1898}
1899
1900function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr {
1901 BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) {
1902 [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self});
1903 }
1904}
1905
Harald Weltef45efeb2018-04-09 18:19:24 +02001906type record SmsParametersTp {
1907 OCT1 msg_ref,
1908 TP_DA da,
1909 OCT1 pid,
1910 OCT1 dcs,
1911 integer udl,
1912 octetstring ud
1913}
1914type record SmsParametersRp {
1915 OCT1 msg_ref,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001916 RP_NumberingPlan_and_NumberDigits smsc_addr optional
Harald Weltef45efeb2018-04-09 18:19:24 +02001917}
1918type record SmsParameters {
1919 SmsParametersTp tp,
1920 SmsParametersRp rp,
1921 uint3_t tid,
1922 OCT1 dlci,
1923 uint7_t exp_rp_err optional
1924}
1925
1926template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := {
1927 tP_DA_NoPad := {
1928 tP_LengthIndicator := 0, /* overwritten */
1929 tP_NumberingPlanID := npl,
1930 tP_TypeOfNumber := ton,
1931 tp_Spare := '0'B,
1932 tP_DAValue := addr
1933 }
1934}
1935
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001936template RP_NumberingPlan_and_NumberDigits t_RP_Addr(template hexstring addr,
1937 template BIT4 npi := '0001'B,
1938 template BIT3 ton := '001'B,
1939 template BIT1 ext := '1'B) := {
1940 rP_NumberingPlanIdentification := npi,
1941 rP_TypeOfNumber := ton,
1942 rP_Ext := ext,
1943 rP_NumberDigits := addr
1944}
1945
Harald Weltef45efeb2018-04-09 18:19:24 +02001946template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := {
1947 tp := {
1948 msg_ref := '23'O,
1949 da := ts_TP_DA('0000'B, '000'B, tp_daddr),
1950 pid := '00'O,
1951 dcs := '00'O,
1952 udl := 0,
1953 ud := ''O
1954 },
1955 rp := {
1956 msg_ref := '42'O,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001957 /* We don't really need to have both SM-RP-DA/OA here, because only one IE
Vadim Yanitskiyafb15a82020-01-05 14:04:53 +01001958 * is included in MO/MT SMS, and in the most cases it's the SMSC address.
1959 * NOTE: this address is currently hard-coded by OsmoMSC. */
1960 smsc_addr := t_RP_Addr('447785016005'H)
Harald Weltef45efeb2018-04-09 18:19:24 +02001961 },
1962 tid := 0,
1963 dlci := '03'O,
1964 exp_rp_err := omit
1965}
1966
1967private altstep as_other_sms() runs on BSC_ConnHdlr {
1968 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) {
1969 setverdict(fail, "Unexpected SMS related PDU from MSC");
Daniel Willmannafce8662018-07-06 23:11:32 +02001970 mtc.stop;
Harald Weltef45efeb2018-04-09 18:19:24 +02001971 }
1972}
1973
Vadim Yanitskiy9cc019a2018-11-15 02:06:07 +07001974/* Submit a MO RP-SMMA over an already existing DTAP connection */
1975function f_mo_smma(inout SmsParameters spars)
1976runs on BSC_ConnHdlr {
1977 var template (value) RPDU_MS_SGSN rp_mo;
1978 var template (value) PDU_ML3_MS_NW l3_mo;
1979
1980 var default d := activate(as_other_sms());
1981
1982 /* just in case this is routed to SMPP.. */
1983 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1984
1985 rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref);
1986 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1987 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1988 /* receive CP-ACK for CP-DATA above */
1989 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1990
1991 deactivate(d);
1992 setverdict(pass);
1993}
1994
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001995/* Submit a MO-SMS over an already existing DTAP connection */
1996function f_mo_sms_submit(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02001997runs on BSC_ConnHdlr {
1998 var template (value) TPDU_RP_DATA_MS_SGSN tp_mo;
1999 var template (value) RPDU_MS_SGSN rp_mo;
2000 var template (value) PDU_ML3_MS_NW l3_mo;
2001
Harald Weltef45efeb2018-04-09 18:19:24 +02002002 var default d := activate(as_other_sms());
2003
Harald Weltef640a012018-04-14 17:49:21 +02002004 /* just in case this is routed to SMPP.. */
2005 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2006
Harald Weltef45efeb2018-04-09 18:19:24 +02002007 tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs,
2008 spars.tp.udl, spars.tp.ud);
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002009 rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, omit, spars.rp.smsc_addr, tp_mo);
Harald Weltef45efeb2018-04-09 18:19:24 +02002010 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
2011 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2012 /* receive CP-ACK for CP-DATA above */
2013 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
2014
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002015 deactivate(d);
2016 setverdict(pass);
2017}
2018
2019/* Wait RP-ACK for MO-SMS on an already existing DTAP connection */
2020function f_mo_sms_wait_rp_ack(inout SmsParameters spars)
2021runs on BSC_ConnHdlr {
2022 var template (value) PDU_ML3_MS_NW l3_mo;
2023
2024 var template TPDU_RP_DATA_SGSN_MS tp_mt;
2025 var template RPDU_SGSN_MS rp_mt;
2026 var template PDU_ML3_NW_MS l3_mt;
2027
2028 var default d := activate(as_other_sms());
2029
2030 /* just in case this is routed to SMPP.. */
2031 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2032
Harald Weltef45efeb2018-04-09 18:19:24 +02002033 if (ispresent(spars.exp_rp_err)) {
2034 /* expect an RP-ERROR message from MSC with given cause */
2035 rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err);
2036 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
2037 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2038 /* send CP-ACK for CP-DATA just received */
2039 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
2040 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2041 } else {
2042 /* expect RP-ACK for RP-DATA */
2043 rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref);
2044 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
2045 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2046 /* send CP-ACO for CP-DATA just received */
2047 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
2048 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2049 }
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002050
Harald Weltef45efeb2018-04-09 18:19:24 +02002051 deactivate(d);
2052 setverdict(pass);
2053}
2054
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002055/* Submit a MO-SMS, and wait for RP-ACK on an existing
2056 * (and authenticated, ...) DTAP connection */
2057function f_mo_sms(inout SmsParameters spars)
2058runs on BSC_ConnHdlr {
2059 f_mo_sms_submit(spars);
2060 f_mo_sms_wait_rp_ack(spars);
2061}
2062
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002063function f_mt_sms_deliver_pdu(in SmsParameters spars)
2064runs on BSC_ConnHdlr
2065return template PDU_DTAP_MT {
2066 var template TPDU_RP_DATA_SGSN_MS tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?);
2067 var template RPDU_SGSN_MS rp_mt := tr_RP_DATA_MT(?, spars.rp.smsc_addr, omit, tp_mt);
2068 var template PDU_ML3_NW_MS l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt));
2069 return tr_PDU_DTAP_MT(l3_mt, spars.dlci);
2070}
2071
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002072/* Wait for MT SMS on an already existing DTAP connection */
2073function f_mt_sms_expect(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02002074runs on BSC_ConnHdlr {
Harald Weltef45efeb2018-04-09 18:19:24 +02002075 var template (value) PDU_ML3_MS_NW l3_mo;
Harald Weltef45efeb2018-04-09 18:19:24 +02002076 var PDU_DTAP_MT dtap_mt;
2077
2078 var default d := activate(as_other_sms());
2079
2080 /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002081 BSSAP.receive(f_mt_sms_deliver_pdu(spars)) -> value dtap_mt;
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002082
Harald Weltef45efeb2018-04-09 18:19:24 +02002083 /* Extract relevant identifiers */
2084 spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio);
2085 spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference;
2086
2087 /* send CP-ACK for CP-DATA just received */
2088 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO);
2089 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2090
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002091 deactivate(d);
2092 setverdict(pass);
2093}
2094
2095/* Send RP-ACK for MT-SMS over an already existing DTAP connection */
2096function f_mt_sms_send_rp_ack(inout SmsParameters spars)
2097runs on BSC_ConnHdlr {
2098 var template (value) RPDU_MS_SGSN rp_mo;
2099 var template (value) PDU_ML3_MS_NW l3_mo;
2100 var template PDU_ML3_NW_MS l3_mt;
2101
2102 var default d := activate(as_other_sms());
2103
Harald Weltef45efeb2018-04-09 18:19:24 +02002104 /* send RP-ACK for RP-DATA */
2105 rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref);
2106 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2107 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2108
2109 /* expect CP-ACK for CP-DATA(RP-ACK) just sent */
Harald Weltee008eea2018-04-14 21:05:48 +02002110 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
Harald Weltef45efeb2018-04-09 18:19:24 +02002111 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2112
2113 deactivate(d);
2114 setverdict(pass);
2115}
2116
Vadim Yanitskiy56318522018-11-24 03:40:47 +07002117/* Send RP-ERROR for MT-SMS over an already existing DTAP connection */
2118function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause)
2119runs on BSC_ConnHdlr {
2120 var template (value) RPDU_MS_SGSN rp_mo;
2121 var template (value) PDU_ML3_MS_NW l3_mo;
2122 var template PDU_ML3_NW_MS l3_mt;
2123
2124 var default d := activate(as_other_sms());
2125
2126 /* send RP-ACK for RP-DATA */
2127 rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause);
2128 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2129 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2130
2131 /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */
2132 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
2133 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2134
2135 deactivate(d);
2136 setverdict(pass);
2137}
2138
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002139/* Wait for a MT-SMS and send RP-ACK over an already existing
2140 * (and authenticated, ...) DTAP connection */
2141function f_mt_sms(inout SmsParameters spars)
2142runs on BSC_ConnHdlr {
2143 f_mt_sms_expect(spars);
2144 f_mt_sms_send_rp_ack(spars);
2145}
Harald Weltea49e36e2018-01-21 19:29:33 +01002146
2147
Harald Weltea49e36e2018-01-21 19:29:33 +01002148}