blob: 3fa5fac2951b3837a5f8fb1c7458d24b60f971e3 [file] [log] [blame]
Harald Welte34b5a952019-05-27 11:54:11 +02001/* BSC Connection Handler of MSC test suite in TTCN-3
2 * (C) 2018-2019 Harald Welte <laforge@gnumonks.org>
3 * (C) 2018-2019 sysmocom - s.f.m.c. GmbH
4 * (C) 2018 Vadim Yanitskiy <axilirator@gmail.com>
5 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
Harald Weltea49e36e2018-01-21 19:29:33 +010013module BSC_ConnectionHandler {
14
Eric Wild26f4a622021-05-17 15:27:05 +020015import from TCCOpenSecurity_Functions all;
Harald Weltea49e36e2018-01-21 19:29:33 +010016import from General_Types all;
17import from Osmocom_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010018import from Native_Functions all;
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +020019import from Misc_Helpers all;
Harald Weltea49e36e2018-01-21 19:29:33 +010020import from GSM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010021import from IPL4asp_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010022import from SCCPasp_Types all;
23import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020024import from RAN_Emulation all;
Harald Weltea49e36e2018-01-21 19:29:33 +010025import from BSSMAP_Templates all;
26
Harald Welte9b751a62019-04-14 17:39:29 +020027import from RANAP_Constants all;
28import from RANAP_IEs all;
29import from RANAP_PDU_Contents all;
30import from RANAP_PDU_Descriptions all;
31import from RANAP_Templates all;
32
Harald Weltea49e36e2018-01-21 19:29:33 +010033import from GSUP_Types all;
34import from GSUP_Emulation all;
35
36import from MNCC_Types all;
37import from MNCC_Emulation all;
38
Harald Welte4aa970c2018-01-26 10:38:09 +010039import from MGCP_Types all;
40import from MGCP_Emulation all;
Harald Welteb71901a2018-01-26 19:16:05 +010041import from MGCP_Templates all;
42import from SDP_Types all;
Harald Welte4aa970c2018-01-26 10:38:09 +010043
Harald Weltea49e36e2018-01-21 19:29:33 +010044import from MobileL3_Types all;
45import from MobileL3_CommonIE_Types all;
46import from MobileL3_MM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010047import from MobileL3_CC_Types all;
Harald Weltef45efeb2018-04-09 18:19:24 +020048import from MobileL3_SMS_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010049import from L3_Templates all;
Harald Welte158a7ca2018-02-16 18:11:31 +010050import from L3_Common all;
Harald Weltea49e36e2018-01-21 19:29:33 +010051
Harald Weltef640a012018-04-14 17:49:21 +020052import from SMPP_Emulation all;
53
Philipp Maieraeb29a82018-11-08 17:40:53 +010054import from IPA_Emulation all;
55import from Osmocom_CTRL_Functions all;
56import from Osmocom_CTRL_Types all;
57import from Osmocom_CTRL_Adapter all;
58
Philipp Maierc39a9d82018-11-09 11:21:08 +010059import from TELNETasp_PortType all;
60import from Osmocom_VTY_Functions all;
61
Harald Welte4263c522018-12-06 11:56:27 +010062import from SGsAP_Emulation all;
63
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +020064import from TCCConversion_Functions { function f_strstr };
65
Harald Weltea49e36e2018-01-21 19:29:33 +010066/* this component represents a single subscriber connection */
Harald Welte6811d102019-04-14 22:23:14 +020067type component BSC_ConnHdlr extends RAN_ConnHdlr, MNCC_ConnHdlr, GSUP_ConnHdlr, MGCP_ConnHdlr, SMPP_ConnHdlr, CTRL_Adapter_CT, SGsAP_ConnHdlr {
Harald Weltea49e36e2018-01-21 19:29:33 +010068 var BSC_ConnHdlrPars g_pars;
Harald Weltea10db902018-01-27 12:44:49 +010069 timer g_Tguard := 60.0;
Philipp Maierc39a9d82018-11-09 11:21:08 +010070 port TELNETasp_PT MSCVTY;
Harald Weltea49e36e2018-01-21 19:29:33 +010071}
72
Harald Weltede371492018-01-27 23:44:41 +010073type record BSC_ConnHdlrNetworkPars {
74 OCT1 kc_support,
75 boolean expect_tmsi,
76 boolean expect_auth,
Oliver Smith1d118ff2019-07-03 10:57:35 +020077 boolean expect_ciph,
78 boolean expect_imei,
79 boolean expect_imei_early,
80 GSUP_IMEIResult check_imei_result,
81 boolean check_imei_error
Harald Weltede371492018-01-27 23:44:41 +010082}
83
Harald Weltea49e36e2018-01-21 19:29:33 +010084type record BSC_ConnHdlrPars {
85 SCCP_PAR_Address sccp_addr_own,
86 SCCP_PAR_Address sccp_addr_peer,
87 BSSMAP_IE_CellIdentifier cell_id,
Harald Welte256571e2018-01-24 18:47:19 +010088 hexstring imei,
Harald Weltea49e36e2018-01-21 19:29:33 +010089 hexstring imsi,
Harald Welte82600572018-01-21 20:54:08 +010090 hexstring msisdn,
Harald Welte256571e2018-01-24 18:47:19 +010091 OCT4 tmsi optional,
Harald Welte9de84792018-01-28 01:06:35 +010092 MobileStationClassmark1_V cm1,
Harald Welte82600572018-01-21 20:54:08 +010093 BSSMAP_IE_ClassmarkInformationType2 cm2,
Harald Welte16114282018-01-24 22:41:21 +010094 BSSMAP_IE_ClassmarkInformationType3 cm3 optional,
Harald Weltede371492018-01-27 23:44:41 +010095 AuthVector vec optional,
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +010096 BSC_ConnHdlrNetworkPars net,
Philipp Maieraeb29a82018-11-08 17:40:53 +010097 boolean send_early_cm,
98 charstring ipa_ctrl_ip,
99 integer ipa_ctrl_port,
Philipp Maier9b690e42018-12-21 11:50:03 +0100100 boolean ipa_ctrl_enable,
Philipp Maier57865482019-01-07 18:33:13 +0100101 boolean mm_info,
Philipp Maierc09a1312019-04-09 16:05:26 +0200102 boolean sgsap_enable,
Harald Weltef9abf8d2019-04-21 13:07:17 +0200103 boolean gsup_enable,
Vadim Yanitskiy2dd96612020-01-07 21:48:29 +0100104 OCT4 gsup_sid,
Harald Weltec1f937a2019-04-21 21:19:23 +0200105 integer ran_idx,
Harald Welte9b751a62019-04-14 17:39:29 +0200106 boolean use_umts_aka,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200107 boolean ran_is_geran,
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200108 boolean use_osmux,
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200109 boolean use_ipv6,
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200110 boolean verify_cell_id,
111 OCT3 common_id_last_eutran_plmn optional
Harald Weltea49e36e2018-01-21 19:29:33 +0100112};
113
Harald Welte9de84792018-01-28 01:06:35 +0100114/* get a one-octet bitmaks of supported algorithms based on Classmark information */
Eric Wild26f4a622021-05-17 15:27:05 +0200115function 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 +0100116 var BIT8 res := '00000001'B; /* A5/0 always supported */
117
118 if (cm2.a5_1 == '0'B) {
119 res := res or4b '00000010'B;
120 }
121 if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) {
122 res := res or4b '00000100'B;
123 }
124 if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) {
125 res := res or4b '00001000'B;
126 }
Eric Wild26f4a622021-05-17 15:27:05 +0200127 if (not istemplatekind(cm3, "omit")) {
128 var BSSMAP_IE_ClassmarkInformationType3 v := valueof(cm3);
129 var BIT8 tmp := oct2bit(v.classmark3ValuePart[0]) and4b '00001111'B;
130 res := res or4b (tmp << 4);
131 }
132
Harald Welte9de84792018-01-28 01:06:35 +0100133 return bit2oct(res);
134}
135
136/* determine the best algorithm available within the bit-mask */
137function f_best_alg_from_mask(OCT1 alg_in) return OCT1 {
138 var BIT8 alg := oct2bit(alg_in);
139 var BIT8 ordered_algs[8] := {
140 '10000000'B, '01000000'B, '00100000'B, '00010000'B,
141 '00001000'B, /* A5/3 */
142 '00000010'B, /* A5/1 */
143 '00000100'B, /* A5/2 */
144 '00000001'B /* A5/0 */ }
145 for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) {
146 if (alg and4b ordered_algs[i] != '00000000'B) {
147 return bit2oct(ordered_algs[i]);
148 }
149 }
150 return '00'O;
151}
152
153/* return an integer like '1' for A5/1 based on a mask (with only one bit set */
154function f_alg_from_mask(OCT1 mask_in) return integer {
155 var BIT8 mask := oct2bit(mask_in);
156 for (var integer i := 0; i < 8; i := i+1) {
157 if (mask and4b ('00000001'B << i) != '00000000'B) {
158 return i;
159 }
160 }
161 return -1;
162}
163
Eric Wild26f4a622021-05-17 15:27:05 +0200164/* return true for A5/x supported by OCT1 bitmask */
165function f_alg_supported_by_mask(OCT1 mask_in, integer whicha5) return boolean {
166 var BIT8 mask := oct2bit(mask_in);
167 if (mask and4b ('00000001'B << whicha5) != '00000000'B) {
168 return true;
169 }
170 return false;
171}
172
Harald Weltea10db902018-01-27 12:44:49 +0100173/* altstep for the global guard timer */
174private altstep as_Tguard() runs on BSC_ConnHdlr {
175 [] g_Tguard.timeout {
Daniel Willmann90829d62018-02-15 17:45:14 +0100176 setverdict(fail, "Tguard timeout");
Daniel Willmannafce8662018-07-06 23:11:32 +0200177 mtc.stop;
Harald Weltea10db902018-01-27 12:44:49 +0100178 }
179}
180
181/* init function, called as first function in new BSC_ConnHdlr */
Harald Weltead2952e2018-01-27 14:12:46 +0100182function f_init_handler(BSC_ConnHdlrPars pars, float t_guard := 60.0) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100183 /* make parameters available via component variable */
184 g_pars := pars;
185 /* Start guard timer and activate it as default */
Harald Weltead2952e2018-01-27 14:12:46 +0100186 g_Tguard.start(t_guard);
Harald Weltea10db902018-01-27 12:44:49 +0100187 activate(as_Tguard());
Harald Weltef640a012018-04-14 17:49:21 +0200188 /* Route all SMPP messages for our MSISDN to us */
189 f_create_smpp_expect(hex2str(pars.msisdn));
Philipp Maier57865482019-01-07 18:33:13 +0100190
Harald Welte4263c522018-12-06 11:56:27 +0100191 /* Route all SGs message for our IMSI to us */
Philipp Maier57865482019-01-07 18:33:13 +0100192 if (g_pars.sgsap_enable == true) {
193 f_create_sgsap_expect(pars.imsi);
194 }
Philipp Maieraeb29a82018-11-08 17:40:53 +0100195
196 if (g_pars.ipa_ctrl_enable == true) {
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100197 f_ipa_ctrl_start_client(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port);
Philipp Maieraeb29a82018-11-08 17:40:53 +0100198 }
Philipp Maierc39a9d82018-11-09 11:21:08 +0100199
200 map(self:MSCVTY, system:MSCVTY);
201 f_vty_set_prompts(MSCVTY);
202 f_vty_transceive(MSCVTY, "enable");
Harald Weltea10db902018-01-27 12:44:49 +0100203}
204
Harald Weltea49e36e2018-01-21 19:29:33 +0100205
Harald Welte6811d102019-04-14 22:23:14 +0200206/* Callback function from general RAN_Emulation whenever a connectionless
Harald Weltea49e36e2018-01-21 19:29:33 +0100207 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
208private function BscUnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200209runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Weltea49e36e2018-01-21 19:29:33 +0100210 var template PDU_BSSAP resp := omit;
211
212 log("BSSMAP_BscUnitdataCallback");
213 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200214 if (match(bssap, tr_BSSMAP_Reset(g_ran_ops.use_osmux))){
Harald Weltea49e36e2018-01-21 19:29:33 +0100215 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200216 resp := ts_BSSMAP_ResetAck(g_ran_ops.use_osmux);
Harald Weltea49e36e2018-01-21 19:29:33 +0100217 }
218
219 /* FIXME: Handle paging, etc. */
220 return resp;
221}
222
Harald Welte9b751a62019-04-14 17:39:29 +0200223private function RncUnitdataCallback(RANAP_PDU ranap)
224runs on RAN_Emulation_CT return template RANAP_PDU {
225 var template RANAP_PDU resp := omit;
226
227 log("RANAP_RncUnitdataCallback");
228 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200229 if (match(ranap, tr_RANAP_Reset())) {
Harald Welte9b751a62019-04-14 17:39:29 +0200230 log("RANAP_RncUnitdataCallback: Responding to RESET with RESET-ACK");
231 var CN_DomainIndicator dom;
232 dom := ranap.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator;
233 resp := ts_RANAP_ResetAck(dom);
234 }
235
236 /* FIXME: Handle paging, etc. */
237 return resp;
238}
239
240
Harald Welte6811d102019-04-14 22:23:14 +0200241const RanOps BSC_RanOps := {
Harald Weltea49e36e2018-01-21 19:29:33 +0100242 /* Create call-back for inbound connections from MSC (hand-over) */
Harald Welte6811d102019-04-14 22:23:14 +0200243 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Weltea49e36e2018-01-21 19:29:33 +0100244 unitdata_cb := refers(BscUnitdataCallback),
Harald Welte9b751a62019-04-14 17:39:29 +0200245 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
246 ranap_unitdata_cb := refers(RncUnitdataCallback),
247 ps_domain := false,
Harald Weltea49e36e2018-01-21 19:29:33 +0100248 decode_dtap := true,
Harald Weltea4ca4462018-02-09 00:17:14 +0100249 role_ms := true,
Harald Welte2fce7882019-04-15 11:48:05 +0200250 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200251 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200252 use_osmux := false,
Harald Weltea4ca4462018-02-09 00:17:14 +0100253 sccp_addr_local := omit,
254 sccp_addr_peer := omit
Harald Weltea49e36e2018-01-21 19:29:33 +0100255}
256
257
258private function MnccUnitdataCallback(MNCC_PDU mncc)
259runs on MNCC_Emulation_CT return template MNCC_PDU {
260 log("Ignoring MNCC", mncc);
261 return omit;
262}
263
264const MnccOps BCC_MnccOps := {
265 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
266 unitdata_cb := refers(MnccUnitdataCallback)
267}
268
269
270
Harald Welte6811d102019-04-14 22:23:14 +0200271/* Encode 'l3' and ask RAN_Emulation to create new connection with COMPL L3 INFO */
Harald Weltea49e36e2018-01-21 19:29:33 +0100272function f_bssap_compl_l3(PDU_ML3_MS_NW l3)
273runs on BSC_ConnHdlr {
274 log("Sending COMPL L3: ", l3);
275 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
276 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
277 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc))));
Harald Welte71b69332018-01-21 20:43:53 +0100278 alt {
Harald Welte6811d102019-04-14 22:23:14 +0200279 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
280 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte71b69332018-01-21 20:43:53 +0100281 setverdict(fail, "DISC.ind from SCCP");
Daniel Willmannafce8662018-07-06 23:11:32 +0200282 mtc.stop;
Harald Welte71b69332018-01-21 20:43:53 +0100283 }
284 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100285}
286
Harald Welte9b751a62019-04-14 17:39:29 +0200287/* generate Iu LAI from BSSAP CGI */
288private function f_IuLAI_from_BssmapCI(BSSMAP_IE_CellIdentifier ci) return LAI {
289 var LAI lai;
290 if (ischosen(ci.cellIdentification.cI_CGI)) {
291 lai.pLMNidentity := ci.cellIdentification.cI_CGI.mcc_mnc;
292 lai.lAC := ci.cellIdentification.cI_CGI.lac;
293 } else if (ischosen(ci.cellIdentification.cI_SAI)) {
294 lai.pLMNidentity := ci.cellIdentification.cI_SAI.mcc_mnc;
295 lai.lAC := ci.cellIdentification.cI_SAI.lac;
296 } else if (ischosen(ci.cellIdentification.ci_LAC_RNC_CI)) {
297 lai.pLMNidentity := ci.cellIdentification.ci_LAC_RNC_CI.mcc_mnc;
298 lai.lAC := ci.cellIdentification.ci_LAC_RNC_CI.lac;
299 } else {
300 mtc.stop;
301 }
302 lai.iE_Extensions := omit;
303 return lai;
304}
305
306/* like f_bssap_compl_l3() but for 3G */
307function f_ranap_initial_ue(PDU_ML3_MS_NW l3)
308runs on BSC_ConnHdlr {
309 log("Sending InitialUE: ", l3);
310 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
311 var RANAP_PDU ranap;
312 var LAI lai := f_IuLAI_from_BssmapCI(g_pars.cell_id);
313 var SAI sai := {
314 pLMNidentity := lai.pLMNidentity,
315 lAC := lai.lAC,
316 sAC := '0000'O, /* FIXME */
317 iE_Extensions := omit
318 };
319 var IuSignallingConnectionIdentifier sigc_id := int2bit(23, 24);
320 var GlobalRNC_ID grnc_id := {
321 pLMNidentity := lai.pLMNidentity,
322 rNC_ID := 2342 /* FIXME */
323 };
324
325 ranap := valueof(ts_RANAP_initialUE_CS(lai, sai, l3_enc, sigc_id, grnc_id));
326 BSSAP.send(ts_RANAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, ranap));
327 alt {
328 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
329 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
330 setverdict(fail, "DISC.ind from SCCP");
331 mtc.stop;
332 }
333 }
334}
335
Harald Weltedceacc72019-04-21 20:58:35 +0200336/* Send BSSMAP Complete L3 or RANAP Initial UE depending on 2G/3G RAN type */
337function f_cl3_or_initial_ue(PDU_ML3_MS_NW l3)
338runs on BSC_ConnHdlr {
339 if (g_pars.ran_is_geran) {
340 f_bssap_compl_l3(l3);
341 } else {
342 f_ranap_initial_ue(l3);
343 }
344}
345
Harald Welte081b19a2018-02-10 09:11:13 +0100346type enumerated EstablishType {
347 EST_TYPE_MO_CALL,
Harald Welte0bef21e2018-02-10 09:48:23 +0100348 EST_TYPE_EMERG_CALL,
Harald Weltef45efeb2018-04-09 18:19:24 +0200349 EST_TYPE_PAG_RESP,
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700350 EST_TYPE_MO_SMS,
351 EST_TYPE_SS_ACT
Harald Welte081b19a2018-02-10 09:11:13 +0100352};
353
Harald Weltea49e36e2018-01-21 19:29:33 +0100354/* helper function to fully establish a dedicated channel */
Harald Welteb9e86fa2018-04-09 18:18:31 +0200355function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL)
Harald Weltea49e36e2018-01-21 19:29:33 +0100356runs on BSC_ConnHdlr {
Harald Welte081b19a2018-02-10 09:11:13 +0100357 var PDU_ML3_MS_NW l3_info;
Harald Welteb9e86fa2018-04-09 18:18:31 +0200358 var MobileIdentityLV mi;
359
360 /* If we have a TMSI, use TMSI instead of IMSI */
361 if (ispresent(g_pars.tmsi)) {
362 mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi));
363 } else {
364 mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
365 }
366
Harald Welte081b19a2018-02-10 09:11:13 +0100367 select (etype) {
368 case (EST_TYPE_MO_CALL) {
369 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
370 }
Harald Welte0bef21e2018-02-10 09:48:23 +0100371 case (EST_TYPE_EMERG_CALL) {
372 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi));
373 }
Harald Welte081b19a2018-02-10 09:11:13 +0100374 case (EST_TYPE_PAG_RESP) {
375 l3_info := valueof(ts_PAG_RESP(mi));
376 }
Harald Weltef45efeb2018-04-09 18:19:24 +0200377 case (EST_TYPE_MO_SMS) {
378 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi));
379 }
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700380 case (EST_TYPE_SS_ACT) {
381 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi));
382 }
Harald Welte081b19a2018-02-10 09:11:13 +0100383 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100384
385 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Weltedceacc72019-04-21 20:58:35 +0200386 f_cl3_or_initial_ue(l3_info);
Harald Weltea49e36e2018-01-21 19:29:33 +0100387
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200388 f_verify_vty_lac_ci(verify_vlr := false);
389
Harald Weltede371492018-01-27 23:44:41 +0100390 f_mm_common();
Pau Espin Pedrolf8034482019-06-03 13:15:58 +0200391 if (g_pars.net.expect_ciph or not g_pars.ran_is_geran) {
Harald Welte148a7082018-01-26 18:56:43 +0100392 /* implicit CM SERVICE ACCEPT? */
393 } else {
Harald Welte0bef21e2018-02-10 09:48:23 +0100394 if (etype != EST_TYPE_PAG_RESP) {
Harald Welte081b19a2018-02-10 09:11:13 +0100395 /* explicit CM SERVICE ACCEPT */
396 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
397 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100398 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100399}
400
401/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
Harald Welte9de84792018-01-28 01:06:35 +0100402function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100403{
404 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
405 return f_build_lu(mi);
406}
Harald Welte9de84792018-01-28 01:06:35 +0100407function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100408{
409 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
410 return f_build_lu(mi);
411}
Harald Welte9de84792018-01-28 01:06:35 +0100412function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100413{
414 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
415 return f_build_lu(mi);
416}
Harald Welte9de84792018-01-28 01:06:35 +0100417private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100418{
419 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
420 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 +0100421 old_lai, mi, g_pars.cm1));
Harald Weltea49e36e2018-01-21 19:29:33 +0100422 return l3_info;
423}
424
Harald Weltea183a5d2019-05-09 13:40:52 +0200425altstep as_GSUP_SAI() runs on BSC_ConnHdlr {
426var GSUP_IE auth_tuple;
427[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)) {
428 if (g_pars.use_umts_aka) {
429 g_pars.vec := f_gen_auth_vec_3g();
430 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand,
431 g_pars.vec.sres,
432 g_pars.vec.kc,
433 g_pars.vec.ik,
434 g_pars.vec.ck,
435 g_pars.vec.autn,
436 g_pars.vec.res));
437 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
438 } else {
439 g_pars.vec := f_gen_auth_vec_2g();
440 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand,
441 g_pars.vec.sres,
442 g_pars.vec.kc));
443 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
444 }
445 }
446}
447
Harald Welte9de84792018-01-28 01:06:35 +0100448function f_mm_auth() runs on BSC_ConnHdlr
Harald Welte148a7082018-01-26 18:56:43 +0100449{
Harald Weltede371492018-01-27 23:44:41 +0100450 if (g_pars.net.expect_auth) {
Harald Weltea183a5d2019-05-09 13:40:52 +0200451 as_GSUP_SAI();
Harald Weltec1f937a2019-04-21 21:19:23 +0200452 if (g_pars.use_umts_aka) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200453 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn)));
454 var OCT4 res := substr(g_pars.vec.res, 0, 4);
455 var OCT4 xres := substr(g_pars.vec.res, 4, 4);
456 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres)));
457 } else {
Harald Weltec1f937a2019-04-21 21:19:23 +0200458 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand)));
459 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres)));
460 }
Harald Welte148a7082018-01-26 18:56:43 +0100461 }
Harald Welte9de84792018-01-28 01:06:35 +0100462}
Harald Welte148a7082018-01-26 18:56:43 +0100463
Oliver Smith1d118ff2019-07-03 10:57:35 +0200464function f_mm_imei() runs on BSC_ConnHdlr
465{
466 var PDU_DTAP_MT dtap_mt;
467 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700468 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200469
470 if (not g_pars.net.expect_imei) {
471 return
472 }
473
474 /* MSC <-> BSC: ID req/rsp for IMEI */
475 alt {
476 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEI))) {
477 mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
478 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
479 }
480 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
481 setverdict(fail, "Expected ID REQ for IMEI DTAP MT message, but got: ", dtap_mt);
482 mtc.stop;
483 }
484 }
485
486 /* MSC <-> HLR: Check IMEI req/res/err */
487 alt {
488 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
489 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
490 }
491 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
492 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
493 }
494 [] GSUP.receive(?) -> value gsup_msg {
495 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
496 g_pars.imsi, "), but got: ", gsup_msg);
497 mtc.stop;
498 }
499 }
500}
501
502function f_mm_imei_early() runs on BSC_ConnHdlr
503{
504 var PDU_DTAP_MT dtap_mt;
505 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700506 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200507
508 if (not g_pars.net.expect_imei_early) {
509 return
510 }
511
512 /* MSC <-> BSC: ID req/rsp for IMEISV */
513 alt {
514 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEISV))) {
515 mi := valueof(ts_MI_IMEISV_LV(g_pars.imei));
516 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
517 }
518 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
519 setverdict(fail, "Expected ID REQ for IMEISV DTAP MT message, but got: ", dtap_mt);
520 mtc.stop;
521 }
522 }
523
524 /* MSC <-> HLR: Check IMEI req/res/err */
525 alt {
526 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
527 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
528 }
529 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
530 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
531 }
532 [] GSUP.receive(?) -> value gsup_msg {
533 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
534 g_pars.imsi, "), but got: ", gsup_msg);
535 mtc.stop;
536 }
537 }
538}
539
Harald Welte79f1e452020-08-18 22:55:02 +0200540function f_expect_common_id() runs on BSC_ConnHdlr
541{
542 if (g_pars.ran_is_geran) {
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200543 BSSAP.receive(tr_BSSMAP_CommonId(g_pars.imsi,
544 f_tr_BSSMAP_LastUsedEUTRANPLMNId(g_pars.common_id_last_eutran_plmn)));
Harald Welte79f1e452020-08-18 22:55:02 +0200545 } else {
546 BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
547 }
548}
549
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200550/* For UMTS AKA on GERAN, calculate the specific kc from the UMTS AKA ck and ik vectors. */
551function f_auth3g_kc(AuthVector vec) return OCT8 {
Eric Wild26f4a622021-05-17 15:27:05 +0200552 var integer i;
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200553 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 +0200554 for (i := 1; i < 8; i := i + 1) {
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200555 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 +0200556 res := res & a;
557 }
558
559 return res;
560}
561
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200562function f_get_expected_encryption(
563 out template BSSMAP_IE_EncryptionInformation encryptionInformation,
564 out template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm,
565 out template BSSMAP_IE_KC128 kC128,
566 out OCT1 a5_perm_alg) runs on BSC_ConnHdlr
567{
568 var OCT1 a5_ms := f_alg_mask_from_cm(g_pars.cm2, g_pars.cm3);
569 a5_perm_alg := g_pars.net.kc_support and4b a5_ms;
570
571 if (not g_pars.net.expect_ciph) {
572 encryptionInformation := *;
573 chosenEncryptionAlgorithm := *;
574 kC128 := *;
575 return;
576 }
577
Neels Hofmeyrf6eff812021-06-23 23:29:39 +0200578 var OCT8 kc;
579 if (g_pars.use_umts_aka) {
580 kc := f_auth3g_kc(g_pars.vec);
581 } else {
582 kc := g_pars.vec.kc;
583 }
584 encryptionInformation := tr_BSSMAP_IE_EncrInfo(kc, a5_perm_alg);
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200585
586 var OCT1 chosen_alg := int2oct(f_alg_from_mask(f_best_alg_from_mask(a5_perm_alg)) + 1, 1);
587 chosenEncryptionAlgorithm := tr_BSSMAP_IE_ChosenEncryptionAlgorithm(chosen_alg);
588
589 if (g_pars.use_umts_aka and f_alg_supported_by_mask(a5_perm_alg, 4)) {
590 /* A5/4 is permitted, expecting kc128 to be present */
591 var OCT32 full_sha256 := f_calculate_HMAC_SHA256(g_pars.vec.ck & g_pars.vec.ik, '32'O, 32);
592 var OCT16 expect_kc128 := substr(full_sha256, 0, 16);
593 kC128 := tr_BSSMAP_IE_Kc128(expect_kc128);
594 } else {
595 kC128 := omit
596 }
597}
598
Eric Wild26f4a622021-05-17 15:27:05 +0200599
Harald Welte9de84792018-01-28 01:06:35 +0100600function f_mm_common() runs on BSC_ConnHdlr
601{
602 f_mm_auth();
Harald Welte9b751a62019-04-14 17:39:29 +0200603 if (g_pars.ran_is_geran) {
604 if (g_pars.net.expect_ciph) {
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200605 var template BSSMAP_IE_EncryptionInformation encryptionInformation;
606 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm;
607 var template BSSMAP_IE_KC128 kC128;
608 var OCT1 a5_perm_alg;
609 f_get_expected_encryption(encryptionInformation, chosenEncryptionAlgorithm, kC128, a5_perm_alg);
Eric Wild26f4a622021-05-17 15:27:05 +0200610
611 var PDU_BSSAP pdu;
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200612 var template PDU_BSSAP expect_ciph_mode_cmd := tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128);
Harald Welte9b751a62019-04-14 17:39:29 +0200613 alt {
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200614 [] BSSAP.receive(expect_ciph_mode_cmd) -> value pdu {
615 var OCT1 a5_chosen := f_best_alg_from_mask(a5_perm_alg);
Harald Welte9b751a62019-04-14 17:39:29 +0200616 var integer a5_nr := f_alg_from_mask(a5_chosen);
617 BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
618 }
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200619 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2) -> value pdu {
620 log("Error: Ciphering Mode Command with unexpected content. Expected: ",
621 expect_ciph_mode_cmd, " got: ", pdu);
622 setverdict(fail, "Ciphering Mode Command with unexpected content.");
Harald Welte9b751a62019-04-14 17:39:29 +0200623 mtc.stop;
624 }
Eric Wild26f4a622021-05-17 15:27:05 +0200625 [] BSSAP.receive(tr_BSSMAP_ClassmarkRequest) {
626 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3))
627 repeat;
628 }
Harald Welte9de84792018-01-28 01:06:35 +0100629 }
Harald Welte9b751a62019-04-14 17:39:29 +0200630 /* FIXME: Send the best available algorithm */
631 }
Harald Welte79f1e452020-08-18 22:55:02 +0200632 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200633 } else { /* UTRAN */
634 alt {
635 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
636 uia_key := oct2bit(g_pars.vec.ik),
637 key_sts := ?,
638 uea_algs := ?,
639 uea_key := oct2bit(g_pars.vec.ck))) {
640 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/
641 var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/
642 BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen));
Harald Welte79f1e452020-08-18 22:55:02 +0200643 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200644 }
645 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
646 setverdict(fail, "Invalid SecurityModeCommand (ciphering case)");
647 mtc.stop;
648 }
649 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
650 uia_key := oct2bit(g_pars.vec.ik),
651 key_sts := ?)) {
652 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/
653 BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
Harald Welte79f1e452020-08-18 22:55:02 +0200654 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200655 }
656 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
657 setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)");
Daniel Willmannafce8662018-07-06 23:11:32 +0200658 mtc.stop;
Harald Welte9de84792018-01-28 01:06:35 +0100659 }
660 }
Harald Welte148a7082018-01-26 18:56:43 +0100661 }
662}
663
Philipp Maier9b690e42018-12-21 11:50:03 +0100664function f_expect_mm_info() runs on BSC_ConnHdlr {
665 if (g_pars.mm_info == true) {
666 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info));
667 }
668}
669
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200670private function f_lac_ci_vty_str(BSSMAP_IE_CellIdentifier cell_id) return charstring
671{
672 return "LAC / cell ID: "
673 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.lac)) & " / "
674 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.ci));
675}
676
677/* Get an IMSI's info and verify that the g_pars.cell_id is reflected in the info.
678 * Verify both the "LAC / cell ID" in the VLR and the "LAC / cell ID" in the "Connection:" part, if any.
679 * If verify_vlr == false, then only verify the "Connection:" part, and fail if there is no "Connection:"; this is
680 * useful when a conn has been established, but the subscriber has not been authenticated, so the VLR does not yet
681 * reflect the new conn's cell ID.
682 */
683function f_verify_vty_lac_ci(boolean verify_vlr := true) runs on BSC_ConnHdlr {
684 if (not g_pars.ran_is_geran) {
685 log("Skipping f_verify_vty_lac_ci(), disabled for Iu");
686 setverdict(pass);
687 return;
688 }
689 if (not g_pars.verify_cell_id) {
690 /* Skip this verification; either the TC expects no cell id to end up being accepted, or this was
691 * disabled globally to test an older osmo-msc which doesn't store the cell id properly yet. */
692 log("Skipping f_verify_vty_lac_ci()");
693 setverdict(pass);
694 return;
695 }
696
697 var charstring vty_cmd := "show subscriber imsi " & hex2str(g_pars.imsi) & " conn";
698 var charstring result := f_vty_transceive_ret(MSCVTY, vty_cmd);
699 var charstring expect_lac_ci := "LAC / cell ID: "
700 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.lac)) & " / "
701 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.ci));
702
703 var boolean vlr_matches := false;
704 var boolean connection_present := false;
705 var boolean connection_matches := false;
706
707 /* There are two occurences of LAC / cell ID: once for the VLR record, and once for the active connection. The
708 * active connection part starts with 'Connection:'. If there is no active connection, that part is omitted.
709 * So, first find out whether there is a 'Connection:' part. Then verify the LAC / cell ID above 'Connection:'
710 * and below 'Connection:', separately.
711 */
712 var integer connection_start := f_strstr(result, "Connection:");
713 connection_present := (connection_start >= 0);
714
715 var integer lac_ci_match := f_strstr(result, expect_lac_ci);
716 if (connection_present) {
717 if (lac_ci_match > connection_start) {
718 /* The first match is below 'Connection:', so the VLR part above it did not match. */
719 vlr_matches := false;
720 connection_matches := true;
721 } else if (lac_ci_match >= 0) {
722 /* The first match is above 'Connection:', so the VLR part matches. */
723 vlr_matches := true;
724
725 /* Now find a match below 'Connection:' */
726 lac_ci_match := f_strstr(result, expect_lac_ci, connection_start);
727 connection_matches := (lac_ci_match > 0);
728 }
729 } else {
730 /* There is no 'Connection:', so a match, if any, is from the VLR part. */
731 vlr_matches := (lac_ci_match >= 0);
732 }
733
734 if (verify_vlr) {
735 if (not vlr_matches) {
736 setverdict(fail, vty_cmd, " shows mismatching LAC / cell ID in the VLR part, expecting: ",
737 expect_lac_ci, " -- got: ", result);
738 return;
739 } else {
740 log("f_verify_vty_lac_ci(): VLR record matches ", expect_lac_ci);
741 setverdict(pass);
742 }
743 }
744
745 if (connection_present) {
746 if (not connection_matches) {
747 setverdict(fail, vty_cmd, " shows mismatching LAC cell ID in the 'Connection' part, expecting: ",
748 expect_lac_ci, " -- got: ", result);
749 } else {
750 log("f_verify_vty_lac_ci(): Active connection matches ", expect_lac_ci);
751 setverdict(pass);
752 }
753 }
754
755 if (not verify_vlr and not connection_present) {
756 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);
757 }
758}
759
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100760function f_perform_lu()
Harald Weltea49e36e2018-01-21 19:29:33 +0100761runs on BSC_ConnHdlr {
762 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
763 var PDU_DTAP_MT dtap_mt;
764
765 /* tell GSUP dispatcher to send this IMSI to us */
766 f_create_gsup_expect(hex2str(g_pars.imsi));
767
768 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Welte9b751a62019-04-14 17:39:29 +0200769 if (g_pars.ran_is_geran) {
770 f_bssap_compl_l3(l3_lu);
771 if (g_pars.send_early_cm) {
772 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
773 }
774 } else {
775 f_ranap_initial_ue(l3_lu);
Harald Welte8a121b32018-01-22 03:00:41 +0100776 }
Harald Welte5c2622c2018-01-21 20:45:20 +0100777
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200778 /* at this point the conn has been established, but the subscriber has not been authenticated, so the VLR does
779 * not yet reflect this conn's cell ID. */
780 f_verify_vty_lac_ci(verify_vlr := false);
781
Oliver Smith1d118ff2019-07-03 10:57:35 +0200782 f_mm_imei_early();
Harald Weltede371492018-01-27 23:44:41 +0100783 f_mm_common();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100784 f_msc_lu_hlr();
Oliver Smith1d118ff2019-07-03 10:57:35 +0200785 f_mm_imei();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100786 f_accept_reject_lu();
787 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
788 f_expect_clear();
Harald Welte16114282018-01-24 22:41:21 +0100789
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100790 setverdict(pass);
791}
792
793function f_msc_lu_hlr() runs on BSC_ConnHdlr
794{
Harald Weltea49e36e2018-01-21 19:29:33 +0100795 /* Expect MSC to perform LU with HLR */
796 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
797 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
798 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
799 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100800}
801
802function f_accept_reject_lu() runs on BSC_ConnHdlr {
803 var PDU_DTAP_MT dtap_mt;
Harald Weltea49e36e2018-01-21 19:29:33 +0100804
805 alt {
806 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
807 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
Harald Weltede371492018-01-27 23:44:41 +0100808 if (g_pars.net.expect_tmsi) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100809 if (not ispresent(lu_acc.mobileIdentityTLV) or
810 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
811 setverdict(fail, "Expected TMSI but no TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200812 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100813 } else {
Harald Welte256571e2018-01-24 18:47:19 +0100814 g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets;
Harald Weltea49e36e2018-01-21 19:29:33 +0100815 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
816 }
817 } else {
818 if (ispresent(lu_acc.mobileIdentityTLV) and
819 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
820 setverdict(fail, "Expected no TMSI but TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200821 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100822 }
823 }
824 }
825 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
826 setverdict(fail, "Expected LU ACK, but received LU REJ");
Daniel Willmannafce8662018-07-06 23:11:32 +0200827 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100828 }
829 }
Philipp Maier9b690e42018-12-21 11:50:03 +0100830
831 /* Wait for MM-Information (if enabled) */
832 f_expect_mm_info();
Harald Weltea49e36e2018-01-21 19:29:33 +0100833 setverdict(pass);
834}
835
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100836function f_expect_lu_reject(template OCT1 cause := ?) runs on BSC_ConnHdlr {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200837 var PDU_DTAP_MT dtap_mt;
838 timer T := 5.0;
839
840 T.start;
841 alt {
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100842 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej(cause))) {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200843 setverdict(pass);
844 }
845 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
846 setverdict(fail, "Expected LU reject BSSAP message, got: ", dtap_mt);
847 }
848 [] T.timeout {
849 setverdict(fail, "Timeout waiting for LU reject");
850 }
851 }
852}
853
Harald Weltea49e36e2018-01-21 19:29:33 +0100854function f_foo() runs on BSC_ConnHdlr{
Harald Welte6811d102019-04-14 22:23:14 +0200855 /* SCCP CC handled by RAN_Emulation_CT.main() */
Harald Weltea49e36e2018-01-21 19:29:33 +0100856 /* Expect auth, if enabled */
857
858 /* TODO: ISD */
859 /* Expect encr, if enabled */
860 /* Expect encr, if enabled */
861 /* Expect ASS CMD, if chan_type != requested */
862 /* Send ASS CMPL in successful case */
863
864 /* Expect AoIP port/ip information for RTP stream */
865 /* Expect MSC-originated MGCP to our simulated MGW */
866 /* Verify Counters via CTRL */
867 /* re-configure MSC behaviour via VTY */
868}
869
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200870type record CrcxResponse {
871 integer resp, /* 1 = reply with OK, 0 = do not reply, -1 = reply with error */
872 HostName mgw_rtp_ip,
873 PortNumber mgw_rtp_port,
874 MgcpConnectionId mgcp_connection_id /* MGCP Connection ID BSS Side */
875}
876
Harald Welteb71901a2018-01-26 19:16:05 +0100877/* parameters related to a (MO?) voice call */
878type record CallParameters {
Harald Welteb71901a2018-01-26 19:16:05 +0100879 /* CC related parameters */
880 hexstring called_party, /* whom are we calling */
881 integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100882 boolean mo_call, /* For a MO call, the transaction_id was allocated by the MS,
883 important to set the TI flag properly */
Harald Welteb71901a2018-01-26 19:16:05 +0100884 BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */
Harald Welte0bef21e2018-02-10 09:48:23 +0100885 boolean emergency, /* is this an emergency call? */
Harald Welteb71901a2018-01-26 19:16:05 +0100886
887 /* MNCC related parameters */
888 uint32_t mncc_callref optional, /* call reference on the MNCC side */
889 MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200890 HostName mncc_rtp_ip optional, /* MNCC Side RTP IP */
891 PortNumber mncc_rtp_port optional, /* MNCC Side RTP port */
Harald Welteb71901a2018-01-26 19:16:05 +0100892
893 /* RTP related parameters */
894 HostName bss_rtp_ip optional, /* BSS Side RTP IP */
895 PortNumber bss_rtp_port optional, /* BSS Side RTP Port */
896 HostName mss_rtp_ip optional, /* MSS Side RTP IP */
897 PortNumber mss_rtp_port optional, /* MSS Side RTP Port */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200898 integer got_crcx_count,
899 CrcxResponse mgw_conn_1,
900 CrcxResponse mgw_conn_2,
Harald Welteb71901a2018-01-26 19:16:05 +0100901 uint7_t rtp_payload_type, /* dynamic RTP payload type */
902 charstring rtp_sdp_format, /* AMR/8000 or the like */
Philipp Maier2a98a732018-03-19 16:06:12 +0100903 boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX
904 (f_mt_call and f_mt_call) */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200905 boolean stop_after_cc_setup, /* Special case: stop call establish after CC Setup */
906 boolean ran_clear_when_alerting, /* Special case: send Clear upon CC Alerting */
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100907 boolean expect_release, /* Special case: expect call establish to cause direct CC Rel */
Harald Welteb71901a2018-01-26 19:16:05 +0100908
Philipp Maiercd668572018-03-19 16:11:52 +0100909 MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */
Harald Welteb71901a2018-01-26 19:16:05 +0100910 MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200911
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200912 boolean use_osmux, /* MSC is expected to use Osmux for this call */
913 integer got_osmux_count
Harald Welteb71901a2018-01-26 19:16:05 +0100914}
915
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200916template (value) CallParameters t_CallParams(hexstring called := '12345'H, integer tid := 0) := {
Harald Welteb71901a2018-01-26 19:16:05 +0100917 called_party := called,
918 transaction_id := tid,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100919 mo_call := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100920 bearer_cap := valueof(ts_Bcap_voice),
Harald Welte0bef21e2018-02-10 09:48:23 +0100921 emergency := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100922 mncc_callref := omit,
923 mncc_bearer_cap := valueof(ts_MNCC_bcap_voice),
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200924 mncc_rtp_ip := "42.23.11.5",
925 mncc_rtp_port := 423,
Harald Welte4017d552018-01-26 21:40:05 +0100926 bss_rtp_ip := "9.8.7.6",
927 bss_rtp_port := 9000,
Harald Welteb71901a2018-01-26 19:16:05 +0100928 mss_rtp_ip := omit,
929 mss_rtp_port := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200930 got_crcx_count := 0,
931 mgw_conn_1 := {
932 resp := 1,
933 mgw_rtp_ip := "1.1.1.1",
934 mgw_rtp_port := 10000,
935 mgcp_connection_id := '11111'H
936 },
937 mgw_conn_2 := {
938 resp := 1,
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +0200939 mgw_rtp_ip := "2.2.2.2",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200940 mgw_rtp_port := 11000,
941 mgcp_connection_id := '22222'H
942 },
Harald Welteb71901a2018-01-26 19:16:05 +0100943 rtp_payload_type := 98,
944 rtp_sdp_format := "AMR/8000",
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100945 mgw_drop_dlcx := false,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200946 stop_after_cc_setup := false,
947 ran_clear_when_alerting := false,
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100948 expect_release := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100949 mgcp_call_id := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200950 mgcp_ep := "rtpbridge/1@mgw",
951 use_osmux := false,
952 got_osmux_count := 0
Harald Welteb71901a2018-01-26 19:16:05 +0100953};
954
Harald Welte4263c522018-12-06 11:56:27 +0100955/* Allocate a call reference and send SETUP via MNCC to MSC */
956function f_mt_call_initate(inout CallParameters cpars)
Harald Welte33ec09b2018-02-10 15:34:46 +0100957runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200958 cpars.mo_call := false;
Harald Welte4263c522018-12-06 11:56:27 +0100959 cpars.mncc_callref := f_rnd_int(2147483648);
960 MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
961 hex2str(cpars.called_party), hex2str(g_pars.imsi)));
962}
Harald Welte33ec09b2018-02-10 15:34:46 +0100963
Harald Welte408a7ef2019-04-21 17:08:40 +0200964private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) :=
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200965 ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
Harald Welte408a7ef2019-04-21 17:08:40 +0200966 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200967 cpars.mgw_conn_2.mgw_rtp_port,
Harald Welte408a7ef2019-04-21 17:08:40 +0200968 { int2str(cpars.rtp_payload_type) },
969 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
970 cpars.rtp_sdp_format)),
971 valueof(ts_SDP_ptime(20)) });
972
Harald Welte4263c522018-12-06 11:56:27 +0100973/* Complete call, begin with a paging response message via BSSAP */
974function f_mt_call_complete(inout CallParameters cpars)
975runs on BSC_ConnHdlr {
Harald Welte33ec09b2018-02-10 15:34:46 +0100976 var MNCC_PDU mncc;
977 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200978 var template MgcpResponse mgcp_resp;
979 var MgcpOsmuxCID osmux_cid;
980 var PDU_BSSAP bssap;
Harald Welte33ec09b2018-02-10 15:34:46 +0100981
Harald Welte6811d102019-04-14 22:23:14 +0200982 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Welte33ec09b2018-02-10 15:34:46 +0100983
Harald Welteb9e86fa2018-04-09 18:18:31 +0200984 f_establish_fully(EST_TYPE_PAG_RESP);
Harald Welte33ec09b2018-02-10 15:34:46 +0100985
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100986 log("f_mt_call_complete 1");
987
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200988 cpars.got_osmux_count := 0;
989
Harald Welte33ec09b2018-02-10 15:34:46 +0100990 /* MS <- MSC: Expect CC SETUP */
991 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party)));
992
993 /* MS -> MSC: ALERTING */
994 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id)));
995 MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100996 log("f_mt_call_complete 2");
Harald Welte33ec09b2018-02-10 15:34:46 +0100997
Harald Welte33ec09b2018-02-10 15:34:46 +0100998 /* Create MGCP expect */
999 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1000 /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */
1001 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1002
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001003 /* First MGCP CRCX */
Harald Welte33ec09b2018-02-10 15:34:46 +01001004 MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001005 log("f_mt_call_complete 3");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001006 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1007 return;
Philipp Maier4b2692d2018-03-14 16:37:48 +01001008 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001009 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001010
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001011
Harald Welte9b751a62019-04-14 17:39:29 +02001012 if (g_pars.ran_is_geran) {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001013 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001014 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Harald Welte9b751a62019-04-14 17:39:29 +02001015
1016 interleave {
1017 /* Second MGCP CRCX (this time for MSS/CN side) */
1018 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001019 log("f_mt_call_complete 4");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001020 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1021 break;
1022 }
Harald Welte9b751a62019-04-14 17:39:29 +02001023 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001024
1025 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1026 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1027 log("f_mt_call_complete 5");
1028 }
1029
Harald Welte9b751a62019-04-14 17:39:29 +02001030 /* expect the MSC to trigger a BSSMAP ASSIGNMENT */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001031 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001032 var template BSSMAP_IE_AoIP_TransportLayerAddress tla;
Harald Welte9b751a62019-04-14 17:39:29 +02001033 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001034 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001035 log("f_mt_call_complete 6");
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001036 tla := f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port);
Harald Welte9b751a62019-04-14 17:39:29 +02001037 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
1038
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001039 if (cpars.use_osmux) {
1040 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1041 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1042 mtc.stop;
1043 }
1044 osmuxCID := valueof(ts_OsmuxCID(0));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001045 if (not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1046 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 +02001047 mtc.stop;
1048 }
1049 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1050 } else {
1051 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1052 }
1053 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001054
1055 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
Harald Welte9b751a62019-04-14 17:39:29 +02001056 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001057
1058 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1059 log("f_mt_call_complete 7");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001060 var octetstring ip;
1061 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1062 if (is_ipv6) {
1063 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1064 } else {
1065 ip := f_inet_addr(cpars.mncc_rtp_ip);
1066 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001067 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001068 is_ipv6, ip,
1069 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001070 /* payload type 3 = GSM FR */ 3));
1071 }
1072
1073 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1074 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1075 log("f_mt_call_complete 8");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001076 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 +01001077 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001078 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001079 { int2str(cpars.rtp_payload_type) },
1080 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1081 cpars.rtp_sdp_format)),
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001082 valueof(ts_SDP_ptime(20)) }));
1083 if (cpars.use_osmux) {
1084 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1085 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1086 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1087 mtc.stop;
1088 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001089 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 +02001090 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001091 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 +02001092 }
1093 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001094 }
1095
1096 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1097 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001098 var SDP_Message sdp;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001099 log("f_mt_call_complete 9");
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001100
1101 if (isvalue(mgcp_cmd.sdp)) {
1102 sdp := mgcp_cmd.sdp;
1103 if (sdp.media_list[0].media_field.ports.port_number != cpars.mncc_rtp_port) {
1104 setverdict(fail, "Wrong MDCX Connection port received, expected ", cpars.mncc_rtp_port, " and received ", sdp.media_list[0].media_field.ports.port_number)
1105 mtc.stop;
1106 }
1107 if (sdp.connection.conn_addr.addr != cpars.mncc_rtp_ip) {
1108 setverdict(fail, "Wrong MDCX Connection address received, expected ", cpars.mncc_rtp_ip, " and received ", sdp.connection.conn_addr.addr)
1109 mtc.stop;
1110 }
1111 }
1112
1113 sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1114 hex2str(cpars.mgcp_call_id), "42",
1115 cpars.mgw_conn_2.mgw_rtp_port,
1116 { int2str(cpars.rtp_payload_type) },
1117 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1118 cpars.rtp_sdp_format)),
1119 valueof(ts_SDP_ptime(20)) }));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001120 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 +01001121 }
1122
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001123 }
Harald Welte9b751a62019-04-14 17:39:29 +02001124 } else {
Harald Welte9b751a62019-04-14 17:39:29 +02001125 interleave {
1126 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001127 log("f_mt_call_complete 4.iu");
1128 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1129 break;
Harald Welte9b751a62019-04-14 17:39:29 +02001130 }
Harald Welte9b751a62019-04-14 17:39:29 +02001131 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001132
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001133 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1134 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1135 log("f_mt_call_complete 5.iu");
1136 }
1137
1138 [] BSSAP.receive(tr_RANAP_RabAssReq(?)) {
1139 log("f_mt_call_complete 6.iu");
1140 var RAB_SetupOrModifiedList l := {
1141 {
1142 {
1143 id := id_RAB_SetupOrModifiedItem,
1144 criticality := ignore,
1145 value_ := {
1146 rAB_SetupOrModifiedItem := {
1147 rAB_ID := int2bit(23, 8),
1148 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1149 iuTransportAssociation := {
1150 bindingID := '040c0000'O
1151 },
1152 dl_dataVolumes := omit,
1153 iE_Extensions := omit
1154 }
1155 }
1156 }
1157 }
1158 };
1159 BSSAP.send(ts_RANAP_RabAssResp(l));
1160
1161 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
1162 }
1163
1164 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1165 log("f_mt_call_complete 7.iu");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001166 var octetstring ip;
1167 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1168 if (is_ipv6) {
1169 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1170 } else {
1171 ip := f_inet_addr(cpars.mncc_rtp_ip);
1172 }
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001173 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001174 is_ipv6, ip,
1175 cpars.mncc_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001176 /* payload type 3 = GSM FR */ 3));
1177 }
1178
1179 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1180 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1181 log("f_mt_call_complete 8.iu");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001182 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 +01001183 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001184 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001185 { int2str(cpars.rtp_payload_type) },
1186 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1187 cpars.rtp_sdp_format)),
1188 valueof(ts_SDP_ptime(20)) }));
1189 if (cpars.use_osmux) {
1190 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1191 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1192 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1193 mtc.stop;
1194 }
1195 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
1196 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001197 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 +01001198 }
1199 MGCP.send(mgcp_resp);
1200 }
1201
1202 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1203 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1204 log("f_mt_call_complete 9.iu");
1205 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1206 hex2str(cpars.mgcp_call_id), "42",
1207 cpars.mgw_conn_2.mgw_rtp_port,
1208 { int2str(cpars.rtp_payload_type) },
1209 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1210 cpars.rtp_sdp_format)),
1211 valueof(ts_SDP_ptime(20)) }));
1212 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
1213 }
1214
Harald Welte33ec09b2018-02-10 15:34:46 +01001215 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001216 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001217
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001218 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1219 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1220 } else {
1221 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1222 mtc.stop;
1223 }
1224
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001225 log("f_mt_call_complete DONE");
Harald Welte4263c522018-12-06 11:56:27 +01001226}
1227
Harald Weltee035e3e2019-04-21 17:32:05 +02001228function f_expect_paging(boolean by_tmsi := true)
1229runs on BSC_ConnHdlr {
Harald Welte9b751a62019-04-14 17:39:29 +02001230 if (g_pars.ran_is_geran) {
1231 BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
1232 } else {
Harald Welte62113fc2019-05-09 13:04:02 +02001233 BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi)));
Harald Welte9b751a62019-04-14 17:39:29 +02001234 }
Harald Weltee035e3e2019-04-21 17:32:05 +02001235}
1236
Harald Welte4263c522018-12-06 11:56:27 +01001237function f_mt_call_establish(inout CallParameters cpars)
1238runs on BSC_ConnHdlr {
1239
1240 /* Initiate the call via MNCC */
1241 f_mt_call_initate(cpars);
1242
1243 /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
Harald Welte6811d102019-04-14 22:23:14 +02001244 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Weltee035e3e2019-04-21 17:32:05 +02001245 f_expect_paging()
Harald Welte4263c522018-12-06 11:56:27 +01001246
1247 /* Complete the call via BSSAP */
1248 f_mt_call_complete(cpars);
Harald Welte33ec09b2018-02-10 15:34:46 +01001249
Harald Welte33ec09b2018-02-10 15:34:46 +01001250 setverdict(pass);
1251}
1252
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001253/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1254 * Return true when an OK reply was sent, false otherwise.
1255 * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */
1256function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd)
1257runs on BSC_ConnHdlr
1258return boolean {
1259 var CrcxResponse conn := cpars.mgw_conn_1;
1260 if (cpars.got_crcx_count > 0) {
1261 conn := cpars.mgw_conn_2;
1262 }
1263 cpars.got_crcx_count := cpars.got_crcx_count + 1;
1264
1265 var MgcpMessage mgcp_msg := {
1266 command := mgcp_cmd
1267 }
1268 var template MgcpResponse mgcp_resp;
1269 var MgcpOsmuxCID osmux_cid;
1270 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1271 if (ispresent(cpars.mgcp_call_id)) {
1272 if (cpars.mgcp_call_id != call_id) {
1273 setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id);
1274 mtc.stop;
1275 }
1276 } else {
1277 cpars.mgcp_call_id := call_id;
1278 }
1279
1280 /* When the endpoint contains a wildcard we keep the endpoint
1281 * identifier we have set up in cpars. Otherwise we use the
1282 * endpoint name that the call agent has supplied */
1283 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1284 cpars.mgcp_ep := mgcp_cmd.line.ep;
1285 }
1286
1287 if (conn.resp == -1) {
1288 /* Reply with error */
1289 var MgcpResponse mgcp_rsp := {
1290 line := {
1291 code := "542",
1292 trans_id := mgcp_cmd.line.trans_id,
1293 string := "FORCED_FAIL"
1294 },
1295 sdp := omit
1296
1297 }
1298 var MgcpParameter mgcp_rsp_param := {
1299 code := "Z",
1300 val := cpars.mgcp_ep
1301 };
1302 mgcp_rsp.params[0] := mgcp_rsp_param;
1303 MGCP.send(mgcp_rsp);
1304 return false;
1305 }
1306
1307 if (conn.resp == 0) {
1308 /* Do not reply at all */
1309 return false;
1310 }
1311
1312 if (conn.resp != 1) {
1313 setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1");
1314 mtc.stop;
1315 }
1316
1317 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1318 hex2str(cpars.mgcp_call_id), "42",
1319 conn.mgw_rtp_port,
1320 { int2str(cpars.rtp_payload_type) },
1321 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1322 cpars.rtp_sdp_format)),
1323 valueof(ts_SDP_ptime(20)) }));
1324
1325 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1326 if (not cpars.use_osmux) {
1327 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1328 mtc.stop;
1329 }
1330 cpars.got_osmux_count := cpars.got_osmux_count + 1;
1331 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1332 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1333 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1334 if (osmux_cid != -1) {
1335 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1336 mtc.stop;
1337 }
1338
1339 osmux_cid := 0;
1340 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1341 } else {
1342 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1343 }
1344
1345 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep));
1346 MGCP.send(mgcp_resp);
1347 return true;
1348}
1349
1350
1351altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr {
1352 var MgcpCommand mgcp_cmd;
1353 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1354 log("as_optional_mgcp_crcx: rx CRCX");
1355 f_handle_crcx(cpars, mgcp_cmd);
1356
1357 /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an
1358 * CRCX is handled. */
1359 repeat;
1360 }
1361}
1362
1363private altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr {
1364 var MgcpCommand mgcp_cmd;
1365 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1366 log("as_optional_mgcp_mdcx: rx MDCX");
1367 log(mgcp_cmd);
1368 var charstring conn_id;
1369 var charstring rtp_payload_type;
1370 f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id);
1371 rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0];
1372
1373 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip,
1374 mgcp_cmd.sdp.origin.session_id, "42",
1375 mgw_rtp_port,
1376 { rtp_payload_type },
1377 { valueof(ts_SDP_ptime(20)) }));
1378 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp));
1379
1380 /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is
1381 * handled. */
1382 repeat;
1383 }
1384}
1385
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001386private altstep as_optional_mgcp_dlcx(CallParameters cpars) runs on BSC_ConnHdlr {
1387 var MgcpCommand mgcp_cmd;
1388 var boolean respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1389 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1390 log("as_optional_mgcp_dlcx: rx MGCP DLCX");
1391 if (respond_to_dlcx) {
1392 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1393 }
1394 /* Without this 'repeat', currently active other interleave and alt series exit as soon as a
1395 * DLCX is handled. */
1396 repeat;
1397 }
1398}
1399
Philipp Maier3716a5e2018-03-21 15:53:35 +01001400function f_mo_call_establish(inout CallParameters cpars)
Harald Welteb71901a2018-01-26 19:16:05 +01001401runs on BSC_ConnHdlr {
1402
Harald Welteb71901a2018-01-26 19:16:05 +01001403 var MNCC_PDU mncc;
1404 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001405 var template MgcpResponse mgcp_resp;
Philipp Maier2a98a732018-03-19 16:06:12 +01001406 var boolean respond_to_dlcx;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001407 var PDU_BSSAP bssap;
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001408 var RANAP_PDU ranap;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001409 var MgcpOsmuxCID osmux_cid;
Harald Welteb71901a2018-01-26 19:16:05 +01001410
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001411 cpars.mo_call := true;
1412
Harald Welte0bef21e2018-02-10 09:48:23 +01001413 if (cpars.emergency) {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001414 f_establish_fully(EST_TYPE_EMERG_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001415 } else {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001416 f_establish_fully(EST_TYPE_MO_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001417 }
Harald Welteb71901a2018-01-26 19:16:05 +01001418
1419 /* Create MNCC and MGCP expect */
1420 f_create_mncc_expect(hex2str(cpars.called_party));
1421 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1422
Harald Welte0bef21e2018-02-10 09:48:23 +01001423 if (cpars.emergency) {
1424 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id)));
1425 } else {
1426 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party)));
1427 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001428
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001429 if (cpars.stop_after_cc_setup) {
1430 return;
1431 }
1432
1433 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001434 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001435
1436 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 +01001437 var boolean got_mncc_setup_compl_ind := false;
1438 var boolean got_cc_connect := false;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001439
Harald Welteb71901a2018-01-26 19:16:05 +01001440 interleave {
1441 [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001442 log("f_mo_call_establish 1: rx MNCC SETUP ind");
Harald Welteb71901a2018-01-26 19:16:05 +01001443 cpars.mncc_callref := mncc.u.signal.callref;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001444 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1445 }
1446
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001447 /* First MGCP CRCX */
Harald Welteb71901a2018-01-26 19:16:05 +01001448 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001449 log("f_mo_call_establish 2: rx 1st CRCX");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001450 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1451 break;
1452 }
Philipp Maierf1e02bb2018-03-15 16:30:00 +01001453 }
1454
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001455 /* Second MGCP CRCX */
1456 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
1457 log("f_mo_call_establish 6: rx 2nd CRCX");
1458 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1459 break;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001460 }
Harald Welteb71901a2018-01-26 19:16:05 +01001461 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001462
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001463 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1464 log("f_mo_call_establish 3: rx RTP CREATE");
1465 /* Call Proceeding */
1466 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1467 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001468
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001469 /* Alerting */
1470 MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref));
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001471 }
Harald Welte9b751a62019-04-14 17:39:29 +02001472
Neels Hofmeyreccaa992019-10-15 16:42:21 +02001473 //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001474 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001475 log("f_mo_call_establish 4: rx Assignment Request");
1476 var BSSMAP_IE_AoIP_TransportLayerAddress tla;
1477 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001478 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
1479
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001480 if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass)) {
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001481 log("Expected:", tla_ass);
1482 log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer);
1483 setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE");
1484 mtc.stop;
1485 }
1486
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001487 tla := valueof(f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001488 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001489 if (cpars.use_osmux) {
1490 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1491 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1492 mtc.stop;
1493 }
1494 osmuxCID := valueof(ts_OsmuxCID(0));
1495 if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1496 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1497 mtc.stop;
1498 }
1499 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1500 } else {
1501 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1502 }
1503 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001504 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001505 [] BSSAP.receive(tr_RANAP_RabAssReq(*)) -> value ranap {
1506 log("f_mo_call_establish 4.iu: rx RANAP RAB Assignment Request");
1507 var RAB_SetupOrModifiedList l := {
1508 {
1509 {
1510 id := id_RAB_SetupOrModifiedItem,
1511 criticality := ignore,
1512 value_ := {
1513 rAB_SetupOrModifiedItem := {
1514 rAB_ID := int2bit(23, 8),
1515 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1516 iuTransportAssociation := {
1517 bindingID := '040c0000'O
1518 },
1519 dl_dataVolumes := omit,
1520 iE_Extensions := omit
1521 }
1522 }
1523 }
1524 }
1525 };
1526 BSSAP.send(ts_RANAP_RabAssResp(l));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001527 }
Harald Welte9b751a62019-04-14 17:39:29 +02001528
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001529 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1530 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1531 log("f_mo_call_establish 5: rx MDCX for the RAN side");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001532 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 +01001533 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001534 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001535 { int2str(cpars.rtp_payload_type) },
1536 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1537 cpars.rtp_sdp_format)),
1538 valueof(ts_SDP_ptime(20)) }));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001539
1540 if (cpars.use_osmux) {
1541 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1542 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1543 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1544 mtc.stop;
1545 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001546 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 +02001547 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001548 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 +02001549 }
1550 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001551 }
Harald Welte9b751a62019-04-14 17:39:29 +02001552
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001553 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {
1554 log("f_mo_call_establish 7: rx CC Alerting");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001555
1556 if (cpars.ran_clear_when_alerting) {
1557 if (g_pars.ran_is_geran) {
1558 BSSAP.send(ts_BSSMAP_ClearRequest(0));
1559 } else {
1560 BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention));
1561 }
1562 break;
1563 }
1564
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001565 cpars.mncc_callref := mncc.u.signal.callref;
1566 /* Call Proceeding */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001567 var octetstring ip;
1568 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1569 if (is_ipv6) {
1570 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1571 } else {
1572 ip := f_inet_addr(cpars.mncc_rtp_ip);
1573 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001574 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001575 is_ipv6, ip,
1576 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001577 /* payload type 3 = GSM FR */ 3));
1578 MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref));
1579 }
1580
1581 [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc {
1582 log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001583 got_mncc_setup_compl_ind := true;
1584 if (not cpars.expect_release and got_cc_connect) {
1585 break;
1586 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001587 }
1588
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001589 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) {
1590 log("f_mo_call_establish 10: rx CC CONNECT");
1591 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id)));
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001592 got_cc_connect := true;
1593 if (not cpars.expect_release and got_mncc_setup_compl_ind) {
1594 break;
1595 }
Harald Welteb71901a2018-01-26 19:16:05 +01001596 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001597
1598 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1599 log("f_mo_call_establish 11: rx CC RELEASE");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001600 if (not cpars.expect_release) {
1601 setverdict(fail, "Got unexpected CC Release");
1602 mtc.stop;
1603 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001604 f_expect_clear();
1605 break;
1606 }
1607 }
1608
1609 f_sleep(0.5);
1610 deactivate(mdcx);
1611
1612 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1613 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1614 } else {
1615 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1616 mtc.stop;
Harald Welteb71901a2018-01-26 19:16:05 +01001617 }
1618
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001619 log("f_mo_call_establish DONE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001620 setverdict(pass);
1621}
Harald Welteb71901a2018-01-26 19:16:05 +01001622
Harald Welte4c422b72019-02-17 16:27:10 +01001623function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001624runs on BSC_ConnHdlr {
1625
1626 var MobileIdentityLV mi;
1627 var MNCC_PDU mncc;
1628 var MgcpCommand mgcp_cmd;
1629 var boolean respond_to_dlcx;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001630 var boolean dlcx_contained_ci := false;
1631 var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand;
1632
1633 if (is_csfb) {
1634 t_clear := tr_BSSMAP_ClearCommandCSFB;
1635 }
1636
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001637 log("f_call_hangup 0: tx MNCC_DISC_REQ");
Harald Welteb71901a2018-01-26 19:16:05 +01001638 MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1639 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1640
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001641 log("f_call_hangup 1: rx DTAP CC DISC");
1642
Philipp Maier3716a5e2018-03-21 15:53:35 +01001643 if (release_by_ms) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001644 var BIT1 tid_remote := '1'B;
1645 if (cpars.mo_call) {
1646 tid_remote := '0'B;
1647 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001648 /* B-side (MS) Release of call */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001649 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 +01001650 MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001651 log("f_call_hangup 2: rx MNCC REL ind");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001652 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001653 log("f_call_hangup 3: rx DTAP CC REL COMPL");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001654 } else {
1655 /* A-side (PLMN) Release of call */
1656 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42))));
1657 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001658 log("f_call_hangup 4: rx DTAP CC RELEASE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001659 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
1660 }
Harald Welteb71901a2018-01-26 19:16:05 +01001661
Philipp Maier2a98a732018-03-19 16:06:12 +01001662 respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1663
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001664 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 +01001665 var default dlcx := activate(as_optional_mgcp_dlcx(cpars));
Harald Welte9b751a62019-04-14 17:39:29 +02001666
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001667 /* clearing of radio channel */
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001668 alt {
1669 [g_pars.ran_is_geran] BSSAP.receive(t_clear) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001670 log("f_call_hangup 5: rx BSSAP Clear Command");
1671 BSSAP.send(ts_BSSMAP_ClearComplete);
1672 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1673 log("f_call_hangup 6: rx SCCP DISC");
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001674 setverdict(pass);
Philipp Maier2a98a732018-03-19 16:06:12 +01001675 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001676 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) {
1677 log("f_call_hangup 5.iu: rx Iu Release Command");
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001678 BSSAP.send(ts_RANAP_IuReleaseComplete);
1679 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001680 log("f_call_hangup 6.iu: rx SCCP DISC");
1681 setverdict(pass);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001682 }
1683 }
1684
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001685 f_sleep(1.0);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001686 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1687 log("f_call_hangup 9: done");
1688
1689 deactivate(mdcx);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001690 deactivate(dlcx);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001691}
1692
1693function f_mt_call(inout CallParameters cpars)
1694runs on BSC_ConnHdlr {
1695
1696 f_mt_call_establish(cpars);
1697
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001698 log("Hold the call for some time");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001699 f_sleep(3.0);
1700
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001701 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001702 f_call_hangup(cpars, true);
1703
1704 setverdict(pass);
1705}
1706
1707function f_mo_call(inout CallParameters cpars)
1708runs on BSC_ConnHdlr {
1709
1710 f_mo_call_establish(cpars);
1711
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001712 log("Hold the call for some time");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001713 f_sleep(3.0);
1714
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001715 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001716 f_call_hangup(cpars, false);
1717
Harald Welteb71901a2018-01-26 19:16:05 +01001718 setverdict(pass);
1719}
Harald Weltea49e36e2018-01-21 19:29:33 +01001720
Daniel Willmann8b084372018-02-04 13:35:26 +01001721function f_mo_seq_dtmf_dup(inout CallParameters cpars)
1722runs on BSC_ConnHdlr {
1723
1724 timer T := 1.0;
Daniel Willmann8b084372018-02-04 13:35:26 +01001725 var MNCC_PDU mncc;
1726 var MgcpCommand mgcp_cmd;
1727 var template PDU_ML3_MS_NW dtmf_dtap;
1728
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001729 f_mo_call_establish(cpars);
Daniel Willmann8b084372018-02-04 13:35:26 +01001730
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001731 /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by
1732 * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001733
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001734 /* Find out the next NSD that will be used, from RAN emulation. */
1735 var N_Sd_Array last_n_sd := f_bssmap_last_n_sd();
1736 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 +01001737
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001738 /* Compose DTAP with this correct NSD */
Daniel Willmann8b084372018-02-04 13:35:26 +01001739 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001740
1741 /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */
1742 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001743 T.start;
1744 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001745 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
1746 log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind");
1747 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001748 [] T.timeout {
1749 setverdict(fail, "Timeout waiting for START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001750 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001751 }
1752 }
1753
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001754 /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message
1755 * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */
1756 dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2);
Daniel Willmann92f66272018-02-06 15:50:52 +01001757 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true));
Daniel Willmann8b084372018-02-04 13:35:26 +01001758 T.start;
1759 alt {
1760 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001761 setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001762 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001763 }
1764 [] T.timeout { }
1765 }
1766
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001767 /* Here the NSD should be correct again and we see a DTMF. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001768 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001769 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001770 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001771 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) {
1772 log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind");
1773 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001774 [] T.timeout {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001775 setverdict(fail, "Timeout waiting for final START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001776 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001777 }
1778 }
1779
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001780 f_call_hangup(cpars, true);
Daniel Willmann8b084372018-02-04 13:35:26 +01001781 setverdict(pass);
1782}
Harald Welte9b751a62019-04-14 17:39:29 +02001783
Harald Welte1ddc7162018-01-27 14:25:46 +01001784/* expect a clear command */
Harald Welte5946b332018-03-18 23:32:21 +01001785altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr {
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001786 var PDU_BSSAP bssap;
Harald Welte5946b332018-03-18 23:32:21 +01001787 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1788 BSSAP.send(ts_BSSMAP_ClearComplete);
1789 alt {
Harald Welte6811d102019-04-14 22:23:14 +02001790 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte5946b332018-03-18 23:32:21 +01001791 setverdict(pass);
1792 }
1793 [] BSSAP.receive {
1794 setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001795 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001796 }
1797 }
1798 }
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001799 [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap {
1800 setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001801 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001802 }
1803}
1804
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001805function f_expect_clear(float t := 5.0, boolean verify_vlr_cell_id := true) runs on BSC_ConnHdlr {
Harald Welte1ddc7162018-01-27 14:25:46 +01001806 timer T := t;
1807
1808 T.start;
1809 alt {
Harald Welte9b751a62019-04-14 17:39:29 +02001810 [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { }
1811 [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { }
Harald Welte1ddc7162018-01-27 14:25:46 +01001812 [] T.timeout {
Harald Welte5946b332018-03-18 23:32:21 +01001813 setverdict(fail, "Timeout waiting for ClearCommand/Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001814 mtc.stop;
Harald Welte1ddc7162018-01-27 14:25:46 +01001815 }
1816 }
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001817
1818 if (verify_vlr_cell_id) {
1819 /* Now the conn is gone, but the VLR reflects the cell ID */
1820 f_verify_vty_lac_ci();
1821 }
Harald Welte1ddc7162018-01-27 14:25:46 +01001822}
1823
Neels Hofmeyr0ac63152019-05-07 01:20:17 +02001824function f_create_bssmap_exp_handoverRequest(integer targetPointCode) runs on BSC_ConnHdlr {
1825 BSSAP_PROC.call(RAN_register_handoverRequest:{targetPointCode, self}) {
1826 [] BSSAP_PROC.getreply(RAN_register_handoverRequest:{?, ?}) {};
1827 }
1828}
1829
1830function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array {
1831 var N_Sd_Array last_n_sd;
1832 BSSAP_PROC.call(RAN_last_n_sd:{self, -}) {
1833 [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) {
1834 return last_n_sd;
1835 };
1836 }
1837}
1838
1839function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr {
1840 BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) {
1841 [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self});
1842 }
1843}
1844
Harald Weltef45efeb2018-04-09 18:19:24 +02001845type record SmsParametersTp {
1846 OCT1 msg_ref,
1847 TP_DA da,
1848 OCT1 pid,
1849 OCT1 dcs,
1850 integer udl,
1851 octetstring ud
1852}
1853type record SmsParametersRp {
1854 OCT1 msg_ref,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001855 RP_NumberingPlan_and_NumberDigits smsc_addr optional
Harald Weltef45efeb2018-04-09 18:19:24 +02001856}
1857type record SmsParameters {
1858 SmsParametersTp tp,
1859 SmsParametersRp rp,
1860 uint3_t tid,
1861 OCT1 dlci,
1862 uint7_t exp_rp_err optional
1863}
1864
1865template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := {
1866 tP_DA_NoPad := {
1867 tP_LengthIndicator := 0, /* overwritten */
1868 tP_NumberingPlanID := npl,
1869 tP_TypeOfNumber := ton,
1870 tp_Spare := '0'B,
1871 tP_DAValue := addr
1872 }
1873}
1874
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001875template RP_NumberingPlan_and_NumberDigits t_RP_Addr(template hexstring addr,
1876 template BIT4 npi := '0001'B,
1877 template BIT3 ton := '001'B,
1878 template BIT1 ext := '1'B) := {
1879 rP_NumberingPlanIdentification := npi,
1880 rP_TypeOfNumber := ton,
1881 rP_Ext := ext,
1882 rP_NumberDigits := addr
1883}
1884
Harald Weltef45efeb2018-04-09 18:19:24 +02001885template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := {
1886 tp := {
1887 msg_ref := '23'O,
1888 da := ts_TP_DA('0000'B, '000'B, tp_daddr),
1889 pid := '00'O,
1890 dcs := '00'O,
1891 udl := 0,
1892 ud := ''O
1893 },
1894 rp := {
1895 msg_ref := '42'O,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001896 /* We don't really need to have both SM-RP-DA/OA here, because only one IE
Vadim Yanitskiyafb15a82020-01-05 14:04:53 +01001897 * is included in MO/MT SMS, and in the most cases it's the SMSC address.
1898 * NOTE: this address is currently hard-coded by OsmoMSC. */
1899 smsc_addr := t_RP_Addr('447785016005'H)
Harald Weltef45efeb2018-04-09 18:19:24 +02001900 },
1901 tid := 0,
1902 dlci := '03'O,
1903 exp_rp_err := omit
1904}
1905
1906private altstep as_other_sms() runs on BSC_ConnHdlr {
1907 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) {
1908 setverdict(fail, "Unexpected SMS related PDU from MSC");
Daniel Willmannafce8662018-07-06 23:11:32 +02001909 mtc.stop;
Harald Weltef45efeb2018-04-09 18:19:24 +02001910 }
1911}
1912
Vadim Yanitskiy9cc019a2018-11-15 02:06:07 +07001913/* Submit a MO RP-SMMA over an already existing DTAP connection */
1914function f_mo_smma(inout SmsParameters spars)
1915runs on BSC_ConnHdlr {
1916 var template (value) RPDU_MS_SGSN rp_mo;
1917 var template (value) PDU_ML3_MS_NW l3_mo;
1918
1919 var default d := activate(as_other_sms());
1920
1921 /* just in case this is routed to SMPP.. */
1922 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1923
1924 rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref);
1925 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1926 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1927 /* receive CP-ACK for CP-DATA above */
1928 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1929
1930 deactivate(d);
1931 setverdict(pass);
1932}
1933
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001934/* Submit a MO-SMS over an already existing DTAP connection */
1935function f_mo_sms_submit(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02001936runs on BSC_ConnHdlr {
1937 var template (value) TPDU_RP_DATA_MS_SGSN tp_mo;
1938 var template (value) RPDU_MS_SGSN rp_mo;
1939 var template (value) PDU_ML3_MS_NW l3_mo;
1940
Harald Weltef45efeb2018-04-09 18:19:24 +02001941 var default d := activate(as_other_sms());
1942
Harald Weltef640a012018-04-14 17:49:21 +02001943 /* just in case this is routed to SMPP.. */
1944 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1945
Harald Weltef45efeb2018-04-09 18:19:24 +02001946 tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs,
1947 spars.tp.udl, spars.tp.ud);
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001948 rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, omit, spars.rp.smsc_addr, tp_mo);
Harald Weltef45efeb2018-04-09 18:19:24 +02001949 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1950 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1951 /* receive CP-ACK for CP-DATA above */
1952 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1953
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001954 deactivate(d);
1955 setverdict(pass);
1956}
1957
1958/* Wait RP-ACK for MO-SMS on an already existing DTAP connection */
1959function f_mo_sms_wait_rp_ack(inout SmsParameters spars)
1960runs on BSC_ConnHdlr {
1961 var template (value) PDU_ML3_MS_NW l3_mo;
1962
1963 var template TPDU_RP_DATA_SGSN_MS tp_mt;
1964 var template RPDU_SGSN_MS rp_mt;
1965 var template PDU_ML3_NW_MS l3_mt;
1966
1967 var default d := activate(as_other_sms());
1968
1969 /* just in case this is routed to SMPP.. */
1970 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1971
Harald Weltef45efeb2018-04-09 18:19:24 +02001972 if (ispresent(spars.exp_rp_err)) {
1973 /* expect an RP-ERROR message from MSC with given cause */
1974 rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err);
1975 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1976 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1977 /* send CP-ACK for CP-DATA just received */
1978 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1979 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1980 } else {
1981 /* expect RP-ACK for RP-DATA */
1982 rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref);
1983 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1984 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1985 /* send CP-ACO for CP-DATA just received */
1986 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1987 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1988 }
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001989
Harald Weltef45efeb2018-04-09 18:19:24 +02001990 deactivate(d);
1991 setverdict(pass);
1992}
1993
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001994/* Submit a MO-SMS, and wait for RP-ACK on an existing
1995 * (and authenticated, ...) DTAP connection */
1996function f_mo_sms(inout SmsParameters spars)
1997runs on BSC_ConnHdlr {
1998 f_mo_sms_submit(spars);
1999 f_mo_sms_wait_rp_ack(spars);
2000}
2001
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002002function f_mt_sms_deliver_pdu(in SmsParameters spars)
2003runs on BSC_ConnHdlr
2004return template PDU_DTAP_MT {
2005 var template TPDU_RP_DATA_SGSN_MS tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?);
2006 var template RPDU_SGSN_MS rp_mt := tr_RP_DATA_MT(?, spars.rp.smsc_addr, omit, tp_mt);
2007 var template PDU_ML3_NW_MS l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt));
2008 return tr_PDU_DTAP_MT(l3_mt, spars.dlci);
2009}
2010
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002011/* Wait for MT SMS on an already existing DTAP connection */
2012function f_mt_sms_expect(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02002013runs on BSC_ConnHdlr {
Harald Weltef45efeb2018-04-09 18:19:24 +02002014 var template (value) PDU_ML3_MS_NW l3_mo;
Harald Weltef45efeb2018-04-09 18:19:24 +02002015 var PDU_DTAP_MT dtap_mt;
2016
2017 var default d := activate(as_other_sms());
2018
2019 /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002020 BSSAP.receive(f_mt_sms_deliver_pdu(spars)) -> value dtap_mt;
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002021
Harald Weltef45efeb2018-04-09 18:19:24 +02002022 /* Extract relevant identifiers */
2023 spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio);
2024 spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference;
2025
2026 /* send CP-ACK for CP-DATA just received */
2027 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO);
2028 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2029
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002030 deactivate(d);
2031 setverdict(pass);
2032}
2033
2034/* Send RP-ACK for MT-SMS over an already existing DTAP connection */
2035function f_mt_sms_send_rp_ack(inout SmsParameters spars)
2036runs on BSC_ConnHdlr {
2037 var template (value) RPDU_MS_SGSN rp_mo;
2038 var template (value) PDU_ML3_MS_NW l3_mo;
2039 var template PDU_ML3_NW_MS l3_mt;
2040
2041 var default d := activate(as_other_sms());
2042
Harald Weltef45efeb2018-04-09 18:19:24 +02002043 /* send RP-ACK for RP-DATA */
2044 rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref);
2045 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2046 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2047
2048 /* expect CP-ACK for CP-DATA(RP-ACK) just sent */
Harald Weltee008eea2018-04-14 21:05:48 +02002049 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
Harald Weltef45efeb2018-04-09 18:19:24 +02002050 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2051
2052 deactivate(d);
2053 setverdict(pass);
2054}
2055
Vadim Yanitskiy56318522018-11-24 03:40:47 +07002056/* Send RP-ERROR for MT-SMS over an already existing DTAP connection */
2057function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause)
2058runs on BSC_ConnHdlr {
2059 var template (value) RPDU_MS_SGSN rp_mo;
2060 var template (value) PDU_ML3_MS_NW l3_mo;
2061 var template PDU_ML3_NW_MS l3_mt;
2062
2063 var default d := activate(as_other_sms());
2064
2065 /* send RP-ACK for RP-DATA */
2066 rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause);
2067 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2068 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2069
2070 /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */
2071 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
2072 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2073
2074 deactivate(d);
2075 setverdict(pass);
2076}
2077
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002078/* Wait for a MT-SMS and send RP-ACK over an already existing
2079 * (and authenticated, ...) DTAP connection */
2080function f_mt_sms(inout SmsParameters spars)
2081runs on BSC_ConnHdlr {
2082 f_mt_sms_expect(spars);
2083 f_mt_sms_send_rp_ack(spars);
2084}
Harald Weltea49e36e2018-01-21 19:29:33 +01002085
2086
Harald Weltea49e36e2018-01-21 19:29:33 +01002087}