blob: 9218c760f05b1e65f173e7f3ad4c332e348a43db [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
15import from General_Types all;
16import from Osmocom_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010017import from Native_Functions all;
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +020018import from Misc_Helpers all;
Harald Weltea49e36e2018-01-21 19:29:33 +010019import from GSM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010020import from IPL4asp_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010021import from SCCPasp_Types all;
22import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020023import from RAN_Emulation all;
Harald Weltea49e36e2018-01-21 19:29:33 +010024import from BSSMAP_Templates all;
25
Harald Welte9b751a62019-04-14 17:39:29 +020026import from RANAP_Constants all;
27import from RANAP_IEs all;
28import from RANAP_PDU_Contents all;
29import from RANAP_PDU_Descriptions all;
30import from RANAP_Templates all;
31
Harald Weltea49e36e2018-01-21 19:29:33 +010032import from GSUP_Types all;
33import from GSUP_Emulation all;
34
35import from MNCC_Types all;
36import from MNCC_Emulation all;
37
Harald Welte4aa970c2018-01-26 10:38:09 +010038import from MGCP_Types all;
39import from MGCP_Emulation all;
Harald Welteb71901a2018-01-26 19:16:05 +010040import from MGCP_Templates all;
41import from SDP_Types all;
Harald Welte4aa970c2018-01-26 10:38:09 +010042
Harald Weltea49e36e2018-01-21 19:29:33 +010043import from MobileL3_Types all;
44import from MobileL3_CommonIE_Types all;
45import from MobileL3_MM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010046import from MobileL3_CC_Types all;
Harald Weltef45efeb2018-04-09 18:19:24 +020047import from MobileL3_SMS_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010048import from L3_Templates all;
Harald Welte158a7ca2018-02-16 18:11:31 +010049import from L3_Common all;
Harald Weltea49e36e2018-01-21 19:29:33 +010050
Harald Weltef640a012018-04-14 17:49:21 +020051import from SMPP_Emulation all;
52
Philipp Maieraeb29a82018-11-08 17:40:53 +010053import from IPA_Emulation all;
54import from Osmocom_CTRL_Functions all;
55import from Osmocom_CTRL_Types all;
56import from Osmocom_CTRL_Adapter all;
57
Philipp Maierc39a9d82018-11-09 11:21:08 +010058import from TELNETasp_PortType all;
59import from Osmocom_VTY_Functions all;
60
Harald Welte4263c522018-12-06 11:56:27 +010061import from SGsAP_Emulation all;
62
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +020063import from TCCConversion_Functions { function f_strstr };
64
Harald Welte79f1e452020-08-18 22:55:02 +020065modulepar {
66 boolean mp_expect_common_id := true;
67}
68
Harald Weltea49e36e2018-01-21 19:29:33 +010069/* this component represents a single subscriber connection */
Harald Welte6811d102019-04-14 22:23:14 +020070type 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 +010071 var BSC_ConnHdlrPars g_pars;
Harald Weltea10db902018-01-27 12:44:49 +010072 timer g_Tguard := 60.0;
Philipp Maierc39a9d82018-11-09 11:21:08 +010073 port TELNETasp_PT MSCVTY;
Harald Weltea49e36e2018-01-21 19:29:33 +010074}
75
Harald Weltede371492018-01-27 23:44:41 +010076type record BSC_ConnHdlrNetworkPars {
77 OCT1 kc_support,
78 boolean expect_tmsi,
79 boolean expect_auth,
Oliver Smith1d118ff2019-07-03 10:57:35 +020080 boolean expect_ciph,
81 boolean expect_imei,
82 boolean expect_imei_early,
83 GSUP_IMEIResult check_imei_result,
84 boolean check_imei_error
Harald Weltede371492018-01-27 23:44:41 +010085}
86
Harald Weltea49e36e2018-01-21 19:29:33 +010087type record BSC_ConnHdlrPars {
88 SCCP_PAR_Address sccp_addr_own,
89 SCCP_PAR_Address sccp_addr_peer,
90 BSSMAP_IE_CellIdentifier cell_id,
Harald Welte256571e2018-01-24 18:47:19 +010091 hexstring imei,
Harald Weltea49e36e2018-01-21 19:29:33 +010092 hexstring imsi,
Harald Welte82600572018-01-21 20:54:08 +010093 hexstring msisdn,
Harald Welte256571e2018-01-24 18:47:19 +010094 OCT4 tmsi optional,
Harald Welte9de84792018-01-28 01:06:35 +010095 MobileStationClassmark1_V cm1,
Harald Welte82600572018-01-21 20:54:08 +010096 BSSMAP_IE_ClassmarkInformationType2 cm2,
Harald Welte16114282018-01-24 22:41:21 +010097 BSSMAP_IE_ClassmarkInformationType3 cm3 optional,
Harald Weltede371492018-01-27 23:44:41 +010098 AuthVector vec optional,
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +010099 BSC_ConnHdlrNetworkPars net,
Philipp Maieraeb29a82018-11-08 17:40:53 +0100100 boolean send_early_cm,
101 charstring ipa_ctrl_ip,
102 integer ipa_ctrl_port,
Philipp Maier9b690e42018-12-21 11:50:03 +0100103 boolean ipa_ctrl_enable,
Philipp Maier57865482019-01-07 18:33:13 +0100104 boolean mm_info,
Philipp Maierc09a1312019-04-09 16:05:26 +0200105 boolean sgsap_enable,
Harald Weltef9abf8d2019-04-21 13:07:17 +0200106 boolean gsup_enable,
Vadim Yanitskiy2dd96612020-01-07 21:48:29 +0100107 OCT4 gsup_sid,
Harald Weltec1f937a2019-04-21 21:19:23 +0200108 integer ran_idx,
Harald Welte9b751a62019-04-14 17:39:29 +0200109 boolean use_umts_aka,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200110 boolean ran_is_geran,
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200111 boolean use_osmux,
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200112 boolean use_ipv6,
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200113 boolean verify_cell_id
Harald Weltea49e36e2018-01-21 19:29:33 +0100114};
115
Harald Welte9de84792018-01-28 01:06:35 +0100116/* get a one-octet bitmaks of supported algorithms based on Classmark information */
117function f_alg_mask_from_cm(BSSMAP_IE_ClassmarkInformationType2 cm2) return OCT1 {
118 var BIT8 res := '00000001'B; /* A5/0 always supported */
119
120 if (cm2.a5_1 == '0'B) {
121 res := res or4b '00000010'B;
122 }
123 if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) {
124 res := res or4b '00000100'B;
125 }
126 if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) {
127 res := res or4b '00001000'B;
128 }
129 /* TODO: CM3 for A5/4 and beyond */
130 return bit2oct(res);
131}
132
133/* determine the best algorithm available within the bit-mask */
134function f_best_alg_from_mask(OCT1 alg_in) return OCT1 {
135 var BIT8 alg := oct2bit(alg_in);
136 var BIT8 ordered_algs[8] := {
137 '10000000'B, '01000000'B, '00100000'B, '00010000'B,
138 '00001000'B, /* A5/3 */
139 '00000010'B, /* A5/1 */
140 '00000100'B, /* A5/2 */
141 '00000001'B /* A5/0 */ }
142 for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) {
143 if (alg and4b ordered_algs[i] != '00000000'B) {
144 return bit2oct(ordered_algs[i]);
145 }
146 }
147 return '00'O;
148}
149
150/* return an integer like '1' for A5/1 based on a mask (with only one bit set */
151function f_alg_from_mask(OCT1 mask_in) return integer {
152 var BIT8 mask := oct2bit(mask_in);
153 for (var integer i := 0; i < 8; i := i+1) {
154 if (mask and4b ('00000001'B << i) != '00000000'B) {
155 return i;
156 }
157 }
158 return -1;
159}
160
Harald Weltea10db902018-01-27 12:44:49 +0100161/* altstep for the global guard timer */
162private altstep as_Tguard() runs on BSC_ConnHdlr {
163 [] g_Tguard.timeout {
Daniel Willmann90829d62018-02-15 17:45:14 +0100164 setverdict(fail, "Tguard timeout");
Daniel Willmannafce8662018-07-06 23:11:32 +0200165 mtc.stop;
Harald Weltea10db902018-01-27 12:44:49 +0100166 }
167}
168
169/* init function, called as first function in new BSC_ConnHdlr */
Harald Weltead2952e2018-01-27 14:12:46 +0100170function f_init_handler(BSC_ConnHdlrPars pars, float t_guard := 60.0) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100171 /* make parameters available via component variable */
172 g_pars := pars;
173 /* Start guard timer and activate it as default */
Harald Weltead2952e2018-01-27 14:12:46 +0100174 g_Tguard.start(t_guard);
Harald Weltea10db902018-01-27 12:44:49 +0100175 activate(as_Tguard());
Harald Weltef640a012018-04-14 17:49:21 +0200176 /* Route all SMPP messages for our MSISDN to us */
177 f_create_smpp_expect(hex2str(pars.msisdn));
Philipp Maier57865482019-01-07 18:33:13 +0100178
Harald Welte4263c522018-12-06 11:56:27 +0100179 /* Route all SGs message for our IMSI to us */
Philipp Maier57865482019-01-07 18:33:13 +0100180 if (g_pars.sgsap_enable == true) {
181 f_create_sgsap_expect(pars.imsi);
182 }
Philipp Maieraeb29a82018-11-08 17:40:53 +0100183
184 if (g_pars.ipa_ctrl_enable == true) {
185 f_ipa_ctrl_start(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port);
186 }
Philipp Maierc39a9d82018-11-09 11:21:08 +0100187
188 map(self:MSCVTY, system:MSCVTY);
189 f_vty_set_prompts(MSCVTY);
190 f_vty_transceive(MSCVTY, "enable");
Harald Weltea10db902018-01-27 12:44:49 +0100191}
192
Harald Weltea49e36e2018-01-21 19:29:33 +0100193
Harald Welte6811d102019-04-14 22:23:14 +0200194/* Callback function from general RAN_Emulation whenever a connectionless
Harald Weltea49e36e2018-01-21 19:29:33 +0100195 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
196private function BscUnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200197runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Weltea49e36e2018-01-21 19:29:33 +0100198 var template PDU_BSSAP resp := omit;
199
200 log("BSSMAP_BscUnitdataCallback");
201 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200202 if (match(bssap, tr_BSSMAP_Reset(g_ran_ops.use_osmux))){
Harald Weltea49e36e2018-01-21 19:29:33 +0100203 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200204 resp := ts_BSSMAP_ResetAck(g_ran_ops.use_osmux);
Harald Weltea49e36e2018-01-21 19:29:33 +0100205 }
206
207 /* FIXME: Handle paging, etc. */
208 return resp;
209}
210
Harald Welte9b751a62019-04-14 17:39:29 +0200211private function RncUnitdataCallback(RANAP_PDU ranap)
212runs on RAN_Emulation_CT return template RANAP_PDU {
213 var template RANAP_PDU resp := omit;
214
215 log("RANAP_RncUnitdataCallback");
216 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200217 if (match(ranap, tr_RANAP_Reset())) {
Harald Welte9b751a62019-04-14 17:39:29 +0200218 log("RANAP_RncUnitdataCallback: Responding to RESET with RESET-ACK");
219 var CN_DomainIndicator dom;
220 dom := ranap.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator;
221 resp := ts_RANAP_ResetAck(dom);
222 }
223
224 /* FIXME: Handle paging, etc. */
225 return resp;
226}
227
228
Harald Welte6811d102019-04-14 22:23:14 +0200229const RanOps BSC_RanOps := {
Harald Weltea49e36e2018-01-21 19:29:33 +0100230 /* Create call-back for inbound connections from MSC (hand-over) */
Harald Welte6811d102019-04-14 22:23:14 +0200231 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Weltea49e36e2018-01-21 19:29:33 +0100232 unitdata_cb := refers(BscUnitdataCallback),
Harald Welte9b751a62019-04-14 17:39:29 +0200233 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
234 ranap_unitdata_cb := refers(RncUnitdataCallback),
235 ps_domain := false,
Harald Weltea49e36e2018-01-21 19:29:33 +0100236 decode_dtap := true,
Harald Weltea4ca4462018-02-09 00:17:14 +0100237 role_ms := true,
Harald Welte2fce7882019-04-15 11:48:05 +0200238 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200239 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200240 use_osmux := false,
Harald Weltea4ca4462018-02-09 00:17:14 +0100241 sccp_addr_local := omit,
242 sccp_addr_peer := omit
Harald Weltea49e36e2018-01-21 19:29:33 +0100243}
244
245
246private function MnccUnitdataCallback(MNCC_PDU mncc)
247runs on MNCC_Emulation_CT return template MNCC_PDU {
248 log("Ignoring MNCC", mncc);
249 return omit;
250}
251
252const MnccOps BCC_MnccOps := {
253 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
254 unitdata_cb := refers(MnccUnitdataCallback)
255}
256
257
258
Harald Welte6811d102019-04-14 22:23:14 +0200259/* Encode 'l3' and ask RAN_Emulation to create new connection with COMPL L3 INFO */
Harald Weltea49e36e2018-01-21 19:29:33 +0100260function f_bssap_compl_l3(PDU_ML3_MS_NW l3)
261runs on BSC_ConnHdlr {
262 log("Sending COMPL L3: ", l3);
263 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
264 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
265 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc))));
Harald Welte71b69332018-01-21 20:43:53 +0100266 alt {
Harald Welte6811d102019-04-14 22:23:14 +0200267 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
268 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte71b69332018-01-21 20:43:53 +0100269 setverdict(fail, "DISC.ind from SCCP");
Daniel Willmannafce8662018-07-06 23:11:32 +0200270 mtc.stop;
Harald Welte71b69332018-01-21 20:43:53 +0100271 }
272 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100273}
274
Harald Welte9b751a62019-04-14 17:39:29 +0200275/* generate Iu LAI from BSSAP CGI */
276private function f_IuLAI_from_BssmapCI(BSSMAP_IE_CellIdentifier ci) return LAI {
277 var LAI lai;
278 if (ischosen(ci.cellIdentification.cI_CGI)) {
279 lai.pLMNidentity := ci.cellIdentification.cI_CGI.mcc_mnc;
280 lai.lAC := ci.cellIdentification.cI_CGI.lac;
281 } else if (ischosen(ci.cellIdentification.cI_SAI)) {
282 lai.pLMNidentity := ci.cellIdentification.cI_SAI.mcc_mnc;
283 lai.lAC := ci.cellIdentification.cI_SAI.lac;
284 } else if (ischosen(ci.cellIdentification.ci_LAC_RNC_CI)) {
285 lai.pLMNidentity := ci.cellIdentification.ci_LAC_RNC_CI.mcc_mnc;
286 lai.lAC := ci.cellIdentification.ci_LAC_RNC_CI.lac;
287 } else {
288 mtc.stop;
289 }
290 lai.iE_Extensions := omit;
291 return lai;
292}
293
294/* like f_bssap_compl_l3() but for 3G */
295function f_ranap_initial_ue(PDU_ML3_MS_NW l3)
296runs on BSC_ConnHdlr {
297 log("Sending InitialUE: ", l3);
298 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
299 var RANAP_PDU ranap;
300 var LAI lai := f_IuLAI_from_BssmapCI(g_pars.cell_id);
301 var SAI sai := {
302 pLMNidentity := lai.pLMNidentity,
303 lAC := lai.lAC,
304 sAC := '0000'O, /* FIXME */
305 iE_Extensions := omit
306 };
307 var IuSignallingConnectionIdentifier sigc_id := int2bit(23, 24);
308 var GlobalRNC_ID grnc_id := {
309 pLMNidentity := lai.pLMNidentity,
310 rNC_ID := 2342 /* FIXME */
311 };
312
313 ranap := valueof(ts_RANAP_initialUE_CS(lai, sai, l3_enc, sigc_id, grnc_id));
314 BSSAP.send(ts_RANAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, ranap));
315 alt {
316 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
317 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
318 setverdict(fail, "DISC.ind from SCCP");
319 mtc.stop;
320 }
321 }
322}
323
Harald Weltedceacc72019-04-21 20:58:35 +0200324/* Send BSSMAP Complete L3 or RANAP Initial UE depending on 2G/3G RAN type */
325function f_cl3_or_initial_ue(PDU_ML3_MS_NW l3)
326runs on BSC_ConnHdlr {
327 if (g_pars.ran_is_geran) {
328 f_bssap_compl_l3(l3);
329 } else {
330 f_ranap_initial_ue(l3);
331 }
332}
333
Harald Welte081b19a2018-02-10 09:11:13 +0100334type enumerated EstablishType {
335 EST_TYPE_MO_CALL,
Harald Welte0bef21e2018-02-10 09:48:23 +0100336 EST_TYPE_EMERG_CALL,
Harald Weltef45efeb2018-04-09 18:19:24 +0200337 EST_TYPE_PAG_RESP,
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700338 EST_TYPE_MO_SMS,
339 EST_TYPE_SS_ACT
Harald Welte081b19a2018-02-10 09:11:13 +0100340};
341
Harald Weltea49e36e2018-01-21 19:29:33 +0100342/* helper function to fully establish a dedicated channel */
Harald Welteb9e86fa2018-04-09 18:18:31 +0200343function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL)
Harald Weltea49e36e2018-01-21 19:29:33 +0100344runs on BSC_ConnHdlr {
Harald Welte081b19a2018-02-10 09:11:13 +0100345 var PDU_ML3_MS_NW l3_info;
Harald Welteb9e86fa2018-04-09 18:18:31 +0200346 var MobileIdentityLV mi;
347
348 /* If we have a TMSI, use TMSI instead of IMSI */
349 if (ispresent(g_pars.tmsi)) {
350 mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi));
351 } else {
352 mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
353 }
354
Harald Welte081b19a2018-02-10 09:11:13 +0100355 select (etype) {
356 case (EST_TYPE_MO_CALL) {
357 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
358 }
Harald Welte0bef21e2018-02-10 09:48:23 +0100359 case (EST_TYPE_EMERG_CALL) {
360 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi));
361 }
Harald Welte081b19a2018-02-10 09:11:13 +0100362 case (EST_TYPE_PAG_RESP) {
363 l3_info := valueof(ts_PAG_RESP(mi));
364 }
Harald Weltef45efeb2018-04-09 18:19:24 +0200365 case (EST_TYPE_MO_SMS) {
366 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi));
367 }
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700368 case (EST_TYPE_SS_ACT) {
369 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi));
370 }
Harald Welte081b19a2018-02-10 09:11:13 +0100371 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100372
373 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Weltedceacc72019-04-21 20:58:35 +0200374 f_cl3_or_initial_ue(l3_info);
Harald Weltea49e36e2018-01-21 19:29:33 +0100375
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200376 f_verify_vty_lac_ci(verify_vlr := false);
377
Harald Weltede371492018-01-27 23:44:41 +0100378 f_mm_common();
Pau Espin Pedrolf8034482019-06-03 13:15:58 +0200379 if (g_pars.net.expect_ciph or not g_pars.ran_is_geran) {
Harald Welte148a7082018-01-26 18:56:43 +0100380 /* implicit CM SERVICE ACCEPT? */
381 } else {
Harald Welte0bef21e2018-02-10 09:48:23 +0100382 if (etype != EST_TYPE_PAG_RESP) {
Harald Welte081b19a2018-02-10 09:11:13 +0100383 /* explicit CM SERVICE ACCEPT */
384 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
385 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100386 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100387}
388
389/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
Harald Welte9de84792018-01-28 01:06:35 +0100390function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100391{
392 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
393 return f_build_lu(mi);
394}
Harald Welte9de84792018-01-28 01:06:35 +0100395function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100396{
397 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
398 return f_build_lu(mi);
399}
Harald Welte9de84792018-01-28 01:06:35 +0100400function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100401{
402 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
403 return f_build_lu(mi);
404}
Harald Welte9de84792018-01-28 01:06:35 +0100405private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100406{
407 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
408 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 +0100409 old_lai, mi, g_pars.cm1));
Harald Weltea49e36e2018-01-21 19:29:33 +0100410 return l3_info;
411}
412
Harald Weltea183a5d2019-05-09 13:40:52 +0200413altstep as_GSUP_SAI() runs on BSC_ConnHdlr {
414var GSUP_IE auth_tuple;
415[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)) {
416 if (g_pars.use_umts_aka) {
417 g_pars.vec := f_gen_auth_vec_3g();
418 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand,
419 g_pars.vec.sres,
420 g_pars.vec.kc,
421 g_pars.vec.ik,
422 g_pars.vec.ck,
423 g_pars.vec.autn,
424 g_pars.vec.res));
425 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
426 } else {
427 g_pars.vec := f_gen_auth_vec_2g();
428 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand,
429 g_pars.vec.sres,
430 g_pars.vec.kc));
431 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
432 }
433 }
434}
435
Harald Welte9de84792018-01-28 01:06:35 +0100436function f_mm_auth() runs on BSC_ConnHdlr
Harald Welte148a7082018-01-26 18:56:43 +0100437{
Harald Weltede371492018-01-27 23:44:41 +0100438 if (g_pars.net.expect_auth) {
Harald Weltea183a5d2019-05-09 13:40:52 +0200439 as_GSUP_SAI();
Harald Weltec1f937a2019-04-21 21:19:23 +0200440 if (g_pars.use_umts_aka) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200441 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn)));
442 var OCT4 res := substr(g_pars.vec.res, 0, 4);
443 var OCT4 xres := substr(g_pars.vec.res, 4, 4);
444 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres)));
445 } else {
Harald Weltec1f937a2019-04-21 21:19:23 +0200446 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand)));
447 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres)));
448 }
Harald Welte148a7082018-01-26 18:56:43 +0100449 }
Harald Welte9de84792018-01-28 01:06:35 +0100450}
Harald Welte148a7082018-01-26 18:56:43 +0100451
Oliver Smith1d118ff2019-07-03 10:57:35 +0200452function f_mm_imei() runs on BSC_ConnHdlr
453{
454 var PDU_DTAP_MT dtap_mt;
455 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700456 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200457
458 if (not g_pars.net.expect_imei) {
459 return
460 }
461
462 /* MSC <-> BSC: ID req/rsp for IMEI */
463 alt {
464 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEI))) {
465 mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
466 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
467 }
468 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
469 setverdict(fail, "Expected ID REQ for IMEI DTAP MT message, but got: ", dtap_mt);
470 mtc.stop;
471 }
472 }
473
474 /* MSC <-> HLR: Check IMEI req/res/err */
475 alt {
476 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
477 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
478 }
479 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
480 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
481 }
482 [] GSUP.receive(?) -> value gsup_msg {
483 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
484 g_pars.imsi, "), but got: ", gsup_msg);
485 mtc.stop;
486 }
487 }
488}
489
490function f_mm_imei_early() runs on BSC_ConnHdlr
491{
492 var PDU_DTAP_MT dtap_mt;
493 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700494 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200495
496 if (not g_pars.net.expect_imei_early) {
497 return
498 }
499
500 /* MSC <-> BSC: ID req/rsp for IMEISV */
501 alt {
502 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEISV))) {
503 mi := valueof(ts_MI_IMEISV_LV(g_pars.imei));
504 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
505 }
506 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
507 setverdict(fail, "Expected ID REQ for IMEISV DTAP MT message, but got: ", dtap_mt);
508 mtc.stop;
509 }
510 }
511
512 /* MSC <-> HLR: Check IMEI req/res/err */
513 alt {
514 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
515 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
516 }
517 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
518 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
519 }
520 [] GSUP.receive(?) -> value gsup_msg {
521 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
522 g_pars.imsi, "), but got: ", gsup_msg);
523 mtc.stop;
524 }
525 }
526}
527
Harald Welte79f1e452020-08-18 22:55:02 +0200528function f_expect_common_id() runs on BSC_ConnHdlr
529{
530 if (g_pars.ran_is_geran) {
531 if (mp_expect_common_id) {
532 BSSAP.receive(tr_BSSMAP_CommonId(g_pars.imsi));
533 }
534 } else {
535 BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
536 }
537}
538
Harald Welte9de84792018-01-28 01:06:35 +0100539function f_mm_common() runs on BSC_ConnHdlr
540{
541 f_mm_auth();
Harald Welte9b751a62019-04-14 17:39:29 +0200542 if (g_pars.ran_is_geran) {
543 if (g_pars.net.expect_ciph) {
544 var OCT1 a5_net := f_alg_mask_from_cm(g_pars.cm2);
545 var OCT1 a5_intersect := g_pars.net.kc_support and4b a5_net;
546 alt {
547 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(a5_intersect, g_pars.vec.kc)) {
548 var OCT1 a5_chosen := f_best_alg_from_mask(a5_intersect);
549 var integer a5_nr := f_alg_from_mask(a5_chosen);
550 BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
551 }
552 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(?, g_pars.vec.kc)) {
553 setverdict(fail, "Wrong ciphering algorithm mask in CiphModCmd");
554 mtc.stop;
555 }
Harald Welte9de84792018-01-28 01:06:35 +0100556 }
Harald Welte9b751a62019-04-14 17:39:29 +0200557 /* FIXME: Send the best available algorithm */
558 }
Harald Welte79f1e452020-08-18 22:55:02 +0200559 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200560 } else { /* UTRAN */
561 alt {
562 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
563 uia_key := oct2bit(g_pars.vec.ik),
564 key_sts := ?,
565 uea_algs := ?,
566 uea_key := oct2bit(g_pars.vec.ck))) {
567 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/
568 var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/
569 BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen));
Harald Welte79f1e452020-08-18 22:55:02 +0200570 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200571 }
572 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
573 setverdict(fail, "Invalid SecurityModeCommand (ciphering case)");
574 mtc.stop;
575 }
576 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
577 uia_key := oct2bit(g_pars.vec.ik),
578 key_sts := ?)) {
579 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/
580 BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
Harald Welte79f1e452020-08-18 22:55:02 +0200581 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200582 }
583 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
584 setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)");
Daniel Willmannafce8662018-07-06 23:11:32 +0200585 mtc.stop;
Harald Welte9de84792018-01-28 01:06:35 +0100586 }
587 }
Harald Welte148a7082018-01-26 18:56:43 +0100588 }
589}
590
Philipp Maier9b690e42018-12-21 11:50:03 +0100591function f_expect_mm_info() runs on BSC_ConnHdlr {
592 if (g_pars.mm_info == true) {
593 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info));
594 }
595}
596
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200597private function f_lac_ci_vty_str(BSSMAP_IE_CellIdentifier cell_id) return charstring
598{
599 return "LAC / cell ID: "
600 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.lac)) & " / "
601 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.ci));
602}
603
604/* Get an IMSI's info and verify that the g_pars.cell_id is reflected in the info.
605 * Verify both the "LAC / cell ID" in the VLR and the "LAC / cell ID" in the "Connection:" part, if any.
606 * If verify_vlr == false, then only verify the "Connection:" part, and fail if there is no "Connection:"; this is
607 * useful when a conn has been established, but the subscriber has not been authenticated, so the VLR does not yet
608 * reflect the new conn's cell ID.
609 */
610function f_verify_vty_lac_ci(boolean verify_vlr := true) runs on BSC_ConnHdlr {
611 if (not g_pars.ran_is_geran) {
612 log("Skipping f_verify_vty_lac_ci(), disabled for Iu");
613 setverdict(pass);
614 return;
615 }
616 if (not g_pars.verify_cell_id) {
617 /* Skip this verification; either the TC expects no cell id to end up being accepted, or this was
618 * disabled globally to test an older osmo-msc which doesn't store the cell id properly yet. */
619 log("Skipping f_verify_vty_lac_ci()");
620 setverdict(pass);
621 return;
622 }
623
624 var charstring vty_cmd := "show subscriber imsi " & hex2str(g_pars.imsi) & " conn";
625 var charstring result := f_vty_transceive_ret(MSCVTY, vty_cmd);
626 var charstring expect_lac_ci := "LAC / cell ID: "
627 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.lac)) & " / "
628 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.ci));
629
630 var boolean vlr_matches := false;
631 var boolean connection_present := false;
632 var boolean connection_matches := false;
633
634 /* There are two occurences of LAC / cell ID: once for the VLR record, and once for the active connection. The
635 * active connection part starts with 'Connection:'. If there is no active connection, that part is omitted.
636 * So, first find out whether there is a 'Connection:' part. Then verify the LAC / cell ID above 'Connection:'
637 * and below 'Connection:', separately.
638 */
639 var integer connection_start := f_strstr(result, "Connection:");
640 connection_present := (connection_start >= 0);
641
642 var integer lac_ci_match := f_strstr(result, expect_lac_ci);
643 if (connection_present) {
644 if (lac_ci_match > connection_start) {
645 /* The first match is below 'Connection:', so the VLR part above it did not match. */
646 vlr_matches := false;
647 connection_matches := true;
648 } else if (lac_ci_match >= 0) {
649 /* The first match is above 'Connection:', so the VLR part matches. */
650 vlr_matches := true;
651
652 /* Now find a match below 'Connection:' */
653 lac_ci_match := f_strstr(result, expect_lac_ci, connection_start);
654 connection_matches := (lac_ci_match > 0);
655 }
656 } else {
657 /* There is no 'Connection:', so a match, if any, is from the VLR part. */
658 vlr_matches := (lac_ci_match >= 0);
659 }
660
661 if (verify_vlr) {
662 if (not vlr_matches) {
663 setverdict(fail, vty_cmd, " shows mismatching LAC / cell ID in the VLR part, expecting: ",
664 expect_lac_ci, " -- got: ", result);
665 return;
666 } else {
667 log("f_verify_vty_lac_ci(): VLR record matches ", expect_lac_ci);
668 setverdict(pass);
669 }
670 }
671
672 if (connection_present) {
673 if (not connection_matches) {
674 setverdict(fail, vty_cmd, " shows mismatching LAC cell ID in the 'Connection' part, expecting: ",
675 expect_lac_ci, " -- got: ", result);
676 } else {
677 log("f_verify_vty_lac_ci(): Active connection matches ", expect_lac_ci);
678 setverdict(pass);
679 }
680 }
681
682 if (not verify_vlr and not connection_present) {
683 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);
684 }
685}
686
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100687function f_perform_lu()
Harald Weltea49e36e2018-01-21 19:29:33 +0100688runs on BSC_ConnHdlr {
689 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
690 var PDU_DTAP_MT dtap_mt;
691
692 /* tell GSUP dispatcher to send this IMSI to us */
693 f_create_gsup_expect(hex2str(g_pars.imsi));
694
695 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Welte9b751a62019-04-14 17:39:29 +0200696 if (g_pars.ran_is_geran) {
697 f_bssap_compl_l3(l3_lu);
698 if (g_pars.send_early_cm) {
699 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
700 }
701 } else {
702 f_ranap_initial_ue(l3_lu);
Harald Welte8a121b32018-01-22 03:00:41 +0100703 }
Harald Welte5c2622c2018-01-21 20:45:20 +0100704
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200705 /* at this point the conn has been established, but the subscriber has not been authenticated, so the VLR does
706 * not yet reflect this conn's cell ID. */
707 f_verify_vty_lac_ci(verify_vlr := false);
708
Oliver Smith1d118ff2019-07-03 10:57:35 +0200709 f_mm_imei_early();
Harald Weltede371492018-01-27 23:44:41 +0100710 f_mm_common();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100711 f_msc_lu_hlr();
Oliver Smith1d118ff2019-07-03 10:57:35 +0200712 f_mm_imei();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100713 f_accept_reject_lu();
714 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
715 f_expect_clear();
Harald Welte16114282018-01-24 22:41:21 +0100716
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100717 setverdict(pass);
718}
719
720function f_msc_lu_hlr() runs on BSC_ConnHdlr
721{
Harald Weltea49e36e2018-01-21 19:29:33 +0100722 /* Expect MSC to perform LU with HLR */
723 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
724 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
725 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
726 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100727}
728
729function f_accept_reject_lu() runs on BSC_ConnHdlr {
730 var PDU_DTAP_MT dtap_mt;
Harald Weltea49e36e2018-01-21 19:29:33 +0100731
732 alt {
733 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
734 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
Harald Weltede371492018-01-27 23:44:41 +0100735 if (g_pars.net.expect_tmsi) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100736 if (not ispresent(lu_acc.mobileIdentityTLV) or
737 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
738 setverdict(fail, "Expected TMSI but no TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200739 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100740 } else {
Harald Welte256571e2018-01-24 18:47:19 +0100741 g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets;
Harald Weltea49e36e2018-01-21 19:29:33 +0100742 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
743 }
744 } else {
745 if (ispresent(lu_acc.mobileIdentityTLV) and
746 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
747 setverdict(fail, "Expected no TMSI but TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200748 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100749 }
750 }
751 }
752 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
753 setverdict(fail, "Expected LU ACK, but received LU REJ");
Daniel Willmannafce8662018-07-06 23:11:32 +0200754 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100755 }
756 }
Philipp Maier9b690e42018-12-21 11:50:03 +0100757
758 /* Wait for MM-Information (if enabled) */
759 f_expect_mm_info();
Harald Weltea49e36e2018-01-21 19:29:33 +0100760 setverdict(pass);
761}
762
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100763function f_expect_lu_reject(template OCT1 cause := ?) runs on BSC_ConnHdlr {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200764 var PDU_DTAP_MT dtap_mt;
765 timer T := 5.0;
766
767 T.start;
768 alt {
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100769 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej(cause))) {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200770 setverdict(pass);
771 }
772 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
773 setverdict(fail, "Expected LU reject BSSAP message, got: ", dtap_mt);
774 }
775 [] T.timeout {
776 setverdict(fail, "Timeout waiting for LU reject");
777 }
778 }
779}
780
Harald Weltea49e36e2018-01-21 19:29:33 +0100781function f_foo() runs on BSC_ConnHdlr{
Harald Welte6811d102019-04-14 22:23:14 +0200782 /* SCCP CC handled by RAN_Emulation_CT.main() */
Harald Weltea49e36e2018-01-21 19:29:33 +0100783 /* Expect auth, if enabled */
784
785 /* TODO: ISD */
786 /* Expect encr, if enabled */
787 /* Expect encr, if enabled */
788 /* Expect ASS CMD, if chan_type != requested */
789 /* Send ASS CMPL in successful case */
790
791 /* Expect AoIP port/ip information for RTP stream */
792 /* Expect MSC-originated MGCP to our simulated MGW */
793 /* Verify Counters via CTRL */
794 /* re-configure MSC behaviour via VTY */
795}
796
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200797type record CrcxResponse {
798 integer resp, /* 1 = reply with OK, 0 = do not reply, -1 = reply with error */
799 HostName mgw_rtp_ip,
800 PortNumber mgw_rtp_port,
801 MgcpConnectionId mgcp_connection_id /* MGCP Connection ID BSS Side */
802}
803
Harald Welteb71901a2018-01-26 19:16:05 +0100804/* parameters related to a (MO?) voice call */
805type record CallParameters {
Harald Welteb71901a2018-01-26 19:16:05 +0100806 /* CC related parameters */
807 hexstring called_party, /* whom are we calling */
808 integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100809 boolean mo_call, /* For a MO call, the transaction_id was allocated by the MS,
810 important to set the TI flag properly */
Harald Welteb71901a2018-01-26 19:16:05 +0100811 BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */
Harald Welte0bef21e2018-02-10 09:48:23 +0100812 boolean emergency, /* is this an emergency call? */
Harald Welteb71901a2018-01-26 19:16:05 +0100813
814 /* MNCC related parameters */
815 uint32_t mncc_callref optional, /* call reference on the MNCC side */
816 MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200817 HostName mncc_rtp_ip optional, /* MNCC Side RTP IP */
818 PortNumber mncc_rtp_port optional, /* MNCC Side RTP port */
Harald Welteb71901a2018-01-26 19:16:05 +0100819
820 /* RTP related parameters */
821 HostName bss_rtp_ip optional, /* BSS Side RTP IP */
822 PortNumber bss_rtp_port optional, /* BSS Side RTP Port */
823 HostName mss_rtp_ip optional, /* MSS Side RTP IP */
824 PortNumber mss_rtp_port optional, /* MSS Side RTP Port */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200825 integer got_crcx_count,
826 CrcxResponse mgw_conn_1,
827 CrcxResponse mgw_conn_2,
Harald Welteb71901a2018-01-26 19:16:05 +0100828 uint7_t rtp_payload_type, /* dynamic RTP payload type */
829 charstring rtp_sdp_format, /* AMR/8000 or the like */
Philipp Maier2a98a732018-03-19 16:06:12 +0100830 boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX
831 (f_mt_call and f_mt_call) */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200832 boolean stop_after_cc_setup, /* Special case: stop call establish after CC Setup */
833 boolean ran_clear_when_alerting, /* Special case: send Clear upon CC Alerting */
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100834 boolean expect_release, /* Special case: expect call establish to cause direct CC Rel */
Harald Welteb71901a2018-01-26 19:16:05 +0100835
Philipp Maiercd668572018-03-19 16:11:52 +0100836 MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */
Harald Welteb71901a2018-01-26 19:16:05 +0100837 MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200838
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200839 boolean use_osmux, /* MSC is expected to use Osmux for this call */
840 integer got_osmux_count
Harald Welteb71901a2018-01-26 19:16:05 +0100841}
842
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200843template (value) CallParameters t_CallParams(hexstring called := '12345'H, integer tid := 0) := {
Harald Welteb71901a2018-01-26 19:16:05 +0100844 called_party := called,
845 transaction_id := tid,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100846 mo_call := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100847 bearer_cap := valueof(ts_Bcap_voice),
Harald Welte0bef21e2018-02-10 09:48:23 +0100848 emergency := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100849 mncc_callref := omit,
850 mncc_bearer_cap := valueof(ts_MNCC_bcap_voice),
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200851 mncc_rtp_ip := "42.23.11.5",
852 mncc_rtp_port := 423,
Harald Welte4017d552018-01-26 21:40:05 +0100853 bss_rtp_ip := "9.8.7.6",
854 bss_rtp_port := 9000,
Harald Welteb71901a2018-01-26 19:16:05 +0100855 mss_rtp_ip := omit,
856 mss_rtp_port := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200857 got_crcx_count := 0,
858 mgw_conn_1 := {
859 resp := 1,
860 mgw_rtp_ip := "1.1.1.1",
861 mgw_rtp_port := 10000,
862 mgcp_connection_id := '11111'H
863 },
864 mgw_conn_2 := {
865 resp := 1,
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +0200866 mgw_rtp_ip := "2.2.2.2",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200867 mgw_rtp_port := 11000,
868 mgcp_connection_id := '22222'H
869 },
Harald Welteb71901a2018-01-26 19:16:05 +0100870 rtp_payload_type := 98,
871 rtp_sdp_format := "AMR/8000",
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100872 mgw_drop_dlcx := false,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200873 stop_after_cc_setup := false,
874 ran_clear_when_alerting := false,
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100875 expect_release := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100876 mgcp_call_id := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200877 mgcp_ep := "rtpbridge/1@mgw",
878 use_osmux := false,
879 got_osmux_count := 0
Harald Welteb71901a2018-01-26 19:16:05 +0100880};
881
Harald Welte4263c522018-12-06 11:56:27 +0100882/* Allocate a call reference and send SETUP via MNCC to MSC */
883function f_mt_call_initate(inout CallParameters cpars)
Harald Welte33ec09b2018-02-10 15:34:46 +0100884runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200885 cpars.mo_call := false;
Harald Welte4263c522018-12-06 11:56:27 +0100886 cpars.mncc_callref := f_rnd_int(2147483648);
887 MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
888 hex2str(cpars.called_party), hex2str(g_pars.imsi)));
889}
Harald Welte33ec09b2018-02-10 15:34:46 +0100890
Harald Welte408a7ef2019-04-21 17:08:40 +0200891private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) :=
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200892 ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
Harald Welte408a7ef2019-04-21 17:08:40 +0200893 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200894 cpars.mgw_conn_2.mgw_rtp_port,
Harald Welte408a7ef2019-04-21 17:08:40 +0200895 { int2str(cpars.rtp_payload_type) },
896 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
897 cpars.rtp_sdp_format)),
898 valueof(ts_SDP_ptime(20)) });
899
Harald Welte4263c522018-12-06 11:56:27 +0100900/* Complete call, begin with a paging response message via BSSAP */
901function f_mt_call_complete(inout CallParameters cpars)
902runs on BSC_ConnHdlr {
Harald Welte33ec09b2018-02-10 15:34:46 +0100903 var MNCC_PDU mncc;
904 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200905 var template MgcpResponse mgcp_resp;
906 var MgcpOsmuxCID osmux_cid;
907 var PDU_BSSAP bssap;
Harald Welte33ec09b2018-02-10 15:34:46 +0100908
Harald Welte6811d102019-04-14 22:23:14 +0200909 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Welte33ec09b2018-02-10 15:34:46 +0100910
Harald Welteb9e86fa2018-04-09 18:18:31 +0200911 f_establish_fully(EST_TYPE_PAG_RESP);
Harald Welte33ec09b2018-02-10 15:34:46 +0100912
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100913 log("f_mt_call_complete 1");
914
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200915 cpars.got_osmux_count := 0;
916
Harald Welte33ec09b2018-02-10 15:34:46 +0100917 /* MS <- MSC: Expect CC SETUP */
918 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party)));
919
920 /* MS -> MSC: ALERTING */
921 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id)));
922 MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100923 log("f_mt_call_complete 2");
Harald Welte33ec09b2018-02-10 15:34:46 +0100924
Harald Welte33ec09b2018-02-10 15:34:46 +0100925 /* Create MGCP expect */
926 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
927 /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */
928 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
929
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200930 /* First MGCP CRCX */
Harald Welte33ec09b2018-02-10 15:34:46 +0100931 MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100932 log("f_mt_call_complete 3");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200933 if (not f_handle_crcx(cpars, mgcp_cmd)) {
934 return;
Philipp Maier4b2692d2018-03-14 16:37:48 +0100935 }
Harald Welte33ec09b2018-02-10 15:34:46 +0100936 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +0100937
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +0100938
Harald Welte9b751a62019-04-14 17:39:29 +0200939 if (g_pars.ran_is_geran) {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200940 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200941 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Harald Welte9b751a62019-04-14 17:39:29 +0200942
943 interleave {
944 /* Second MGCP CRCX (this time for MSS/CN side) */
945 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100946 log("f_mt_call_complete 4");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200947 if (not f_handle_crcx(cpars, mgcp_cmd)) {
948 break;
949 }
Harald Welte9b751a62019-04-14 17:39:29 +0200950 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100951
952 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
953 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
954 log("f_mt_call_complete 5");
955 }
956
Harald Welte9b751a62019-04-14 17:39:29 +0200957 /* expect the MSC to trigger a BSSMAP ASSIGNMENT */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200958 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200959 var template BSSMAP_IE_AoIP_TransportLayerAddress tla;
Harald Welte9b751a62019-04-14 17:39:29 +0200960 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200961 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100962 log("f_mt_call_complete 6");
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200963 tla := f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port);
Harald Welte9b751a62019-04-14 17:39:29 +0200964 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
965
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200966 if (cpars.use_osmux) {
967 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
968 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
969 mtc.stop;
970 }
971 osmuxCID := valueof(ts_OsmuxCID(0));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200972 if (not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
973 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 +0200974 mtc.stop;
975 }
976 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
977 } else {
978 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
979 }
980 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100981
982 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
Harald Welte9b751a62019-04-14 17:39:29 +0200983 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100984
985 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
986 log("f_mt_call_complete 7");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200987 var octetstring ip;
988 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
989 if (is_ipv6) {
990 ip := f_inet6_addr(cpars.mncc_rtp_ip);
991 } else {
992 ip := f_inet_addr(cpars.mncc_rtp_ip);
993 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100994 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200995 is_ipv6, ip,
996 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100997 /* payload type 3 = GSM FR */ 3));
998 }
999
1000 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1001 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1002 log("f_mt_call_complete 8");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001003 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 +01001004 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001005 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001006 { int2str(cpars.rtp_payload_type) },
1007 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1008 cpars.rtp_sdp_format)),
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001009 valueof(ts_SDP_ptime(20)) }));
1010 if (cpars.use_osmux) {
1011 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1012 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1013 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1014 mtc.stop;
1015 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001016 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 +02001017 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001018 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 +02001019 }
1020 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001021 }
1022
1023 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1024 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1025 log("f_mt_call_complete 9");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001026 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001027 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001028 cpars.mgw_conn_2.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001029 { int2str(cpars.rtp_payload_type) },
1030 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1031 cpars.rtp_sdp_format)),
1032 valueof(ts_SDP_ptime(20)) }));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001033 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 +01001034 }
1035
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001036 }
Harald Welte9b751a62019-04-14 17:39:29 +02001037 } else {
Harald Welte9b751a62019-04-14 17:39:29 +02001038 interleave {
1039 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001040 log("f_mt_call_complete 4.iu");
1041 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1042 break;
Harald Welte9b751a62019-04-14 17:39:29 +02001043 }
Harald Welte9b751a62019-04-14 17:39:29 +02001044 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001045
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001046 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1047 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1048 log("f_mt_call_complete 5.iu");
1049 }
1050
1051 [] BSSAP.receive(tr_RANAP_RabAssReq(?)) {
1052 log("f_mt_call_complete 6.iu");
1053 var RAB_SetupOrModifiedList l := {
1054 {
1055 {
1056 id := id_RAB_SetupOrModifiedItem,
1057 criticality := ignore,
1058 value_ := {
1059 rAB_SetupOrModifiedItem := {
1060 rAB_ID := int2bit(23, 8),
1061 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1062 iuTransportAssociation := {
1063 bindingID := '040c0000'O
1064 },
1065 dl_dataVolumes := omit,
1066 iE_Extensions := omit
1067 }
1068 }
1069 }
1070 }
1071 };
1072 BSSAP.send(ts_RANAP_RabAssResp(l));
1073
1074 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
1075 }
1076
1077 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1078 log("f_mt_call_complete 7.iu");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001079 var octetstring ip;
1080 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1081 if (is_ipv6) {
1082 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1083 } else {
1084 ip := f_inet_addr(cpars.mncc_rtp_ip);
1085 }
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001086 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001087 is_ipv6, ip,
1088 cpars.mncc_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001089 /* payload type 3 = GSM FR */ 3));
1090 }
1091
1092 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1093 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1094 log("f_mt_call_complete 8.iu");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001095 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 +01001096 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001097 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001098 { int2str(cpars.rtp_payload_type) },
1099 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1100 cpars.rtp_sdp_format)),
1101 valueof(ts_SDP_ptime(20)) }));
1102 if (cpars.use_osmux) {
1103 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1104 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1105 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1106 mtc.stop;
1107 }
1108 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
1109 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001110 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 +01001111 }
1112 MGCP.send(mgcp_resp);
1113 }
1114
1115 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1116 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1117 log("f_mt_call_complete 9.iu");
1118 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1119 hex2str(cpars.mgcp_call_id), "42",
1120 cpars.mgw_conn_2.mgw_rtp_port,
1121 { int2str(cpars.rtp_payload_type) },
1122 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1123 cpars.rtp_sdp_format)),
1124 valueof(ts_SDP_ptime(20)) }));
1125 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
1126 }
1127
Harald Welte33ec09b2018-02-10 15:34:46 +01001128 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001129 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001130
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001131 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1132 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1133 } else {
1134 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1135 mtc.stop;
1136 }
1137
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001138 log("f_mt_call_complete DONE");
Harald Welte4263c522018-12-06 11:56:27 +01001139}
1140
Harald Weltee035e3e2019-04-21 17:32:05 +02001141function f_expect_paging(boolean by_tmsi := true)
1142runs on BSC_ConnHdlr {
Harald Welte9b751a62019-04-14 17:39:29 +02001143 if (g_pars.ran_is_geran) {
1144 BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
1145 } else {
Harald Welte62113fc2019-05-09 13:04:02 +02001146 BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi)));
Harald Welte9b751a62019-04-14 17:39:29 +02001147 }
Harald Weltee035e3e2019-04-21 17:32:05 +02001148}
1149
Harald Welte4263c522018-12-06 11:56:27 +01001150function f_mt_call_establish(inout CallParameters cpars)
1151runs on BSC_ConnHdlr {
1152
1153 /* Initiate the call via MNCC */
1154 f_mt_call_initate(cpars);
1155
1156 /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
Harald Welte6811d102019-04-14 22:23:14 +02001157 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Weltee035e3e2019-04-21 17:32:05 +02001158 f_expect_paging()
Harald Welte4263c522018-12-06 11:56:27 +01001159
1160 /* Complete the call via BSSAP */
1161 f_mt_call_complete(cpars);
Harald Welte33ec09b2018-02-10 15:34:46 +01001162
Harald Welte33ec09b2018-02-10 15:34:46 +01001163 setverdict(pass);
1164}
1165
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001166/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1167 * Return true when an OK reply was sent, false otherwise.
1168 * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */
1169function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd)
1170runs on BSC_ConnHdlr
1171return boolean {
1172 var CrcxResponse conn := cpars.mgw_conn_1;
1173 if (cpars.got_crcx_count > 0) {
1174 conn := cpars.mgw_conn_2;
1175 }
1176 cpars.got_crcx_count := cpars.got_crcx_count + 1;
1177
1178 var MgcpMessage mgcp_msg := {
1179 command := mgcp_cmd
1180 }
1181 var template MgcpResponse mgcp_resp;
1182 var MgcpOsmuxCID osmux_cid;
1183 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1184 if (ispresent(cpars.mgcp_call_id)) {
1185 if (cpars.mgcp_call_id != call_id) {
1186 setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id);
1187 mtc.stop;
1188 }
1189 } else {
1190 cpars.mgcp_call_id := call_id;
1191 }
1192
1193 /* When the endpoint contains a wildcard we keep the endpoint
1194 * identifier we have set up in cpars. Otherwise we use the
1195 * endpoint name that the call agent has supplied */
1196 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1197 cpars.mgcp_ep := mgcp_cmd.line.ep;
1198 }
1199
1200 if (conn.resp == -1) {
1201 /* Reply with error */
1202 var MgcpResponse mgcp_rsp := {
1203 line := {
1204 code := "542",
1205 trans_id := mgcp_cmd.line.trans_id,
1206 string := "FORCED_FAIL"
1207 },
1208 sdp := omit
1209
1210 }
1211 var MgcpParameter mgcp_rsp_param := {
1212 code := "Z",
1213 val := cpars.mgcp_ep
1214 };
1215 mgcp_rsp.params[0] := mgcp_rsp_param;
1216 MGCP.send(mgcp_rsp);
1217 return false;
1218 }
1219
1220 if (conn.resp == 0) {
1221 /* Do not reply at all */
1222 return false;
1223 }
1224
1225 if (conn.resp != 1) {
1226 setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1");
1227 mtc.stop;
1228 }
1229
1230 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1231 hex2str(cpars.mgcp_call_id), "42",
1232 conn.mgw_rtp_port,
1233 { int2str(cpars.rtp_payload_type) },
1234 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1235 cpars.rtp_sdp_format)),
1236 valueof(ts_SDP_ptime(20)) }));
1237
1238 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1239 if (not cpars.use_osmux) {
1240 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1241 mtc.stop;
1242 }
1243 cpars.got_osmux_count := cpars.got_osmux_count + 1;
1244 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1245 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1246 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1247 if (osmux_cid != -1) {
1248 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1249 mtc.stop;
1250 }
1251
1252 osmux_cid := 0;
1253 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1254 } else {
1255 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1256 }
1257
1258 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep));
1259 MGCP.send(mgcp_resp);
1260 return true;
1261}
1262
1263
1264altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr {
1265 var MgcpCommand mgcp_cmd;
1266 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1267 log("as_optional_mgcp_crcx: rx CRCX");
1268 f_handle_crcx(cpars, mgcp_cmd);
1269
1270 /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an
1271 * CRCX is handled. */
1272 repeat;
1273 }
1274}
1275
1276private altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr {
1277 var MgcpCommand mgcp_cmd;
1278 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1279 log("as_optional_mgcp_mdcx: rx MDCX");
1280 log(mgcp_cmd);
1281 var charstring conn_id;
1282 var charstring rtp_payload_type;
1283 f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id);
1284 rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0];
1285
1286 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip,
1287 mgcp_cmd.sdp.origin.session_id, "42",
1288 mgw_rtp_port,
1289 { rtp_payload_type },
1290 { valueof(ts_SDP_ptime(20)) }));
1291 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp));
1292
1293 /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is
1294 * handled. */
1295 repeat;
1296 }
1297}
1298
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001299private altstep as_optional_mgcp_dlcx(CallParameters cpars) runs on BSC_ConnHdlr {
1300 var MgcpCommand mgcp_cmd;
1301 var boolean respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1302 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1303 log("as_optional_mgcp_dlcx: rx MGCP DLCX");
1304 if (respond_to_dlcx) {
1305 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1306 }
1307 /* Without this 'repeat', currently active other interleave and alt series exit as soon as a
1308 * DLCX is handled. */
1309 repeat;
1310 }
1311}
1312
Philipp Maier3716a5e2018-03-21 15:53:35 +01001313function f_mo_call_establish(inout CallParameters cpars)
Harald Welteb71901a2018-01-26 19:16:05 +01001314runs on BSC_ConnHdlr {
1315
Harald Welteb71901a2018-01-26 19:16:05 +01001316 var MNCC_PDU mncc;
1317 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001318 var template MgcpResponse mgcp_resp;
Philipp Maier2a98a732018-03-19 16:06:12 +01001319 var boolean respond_to_dlcx;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001320 var PDU_BSSAP bssap;
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001321 var RANAP_PDU ranap;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001322 var MgcpOsmuxCID osmux_cid;
Harald Welteb71901a2018-01-26 19:16:05 +01001323
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001324 cpars.mo_call := true;
1325
Harald Welte0bef21e2018-02-10 09:48:23 +01001326 if (cpars.emergency) {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001327 f_establish_fully(EST_TYPE_EMERG_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001328 } else {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001329 f_establish_fully(EST_TYPE_MO_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001330 }
Harald Welteb71901a2018-01-26 19:16:05 +01001331
1332 /* Create MNCC and MGCP expect */
1333 f_create_mncc_expect(hex2str(cpars.called_party));
1334 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1335
Harald Welte0bef21e2018-02-10 09:48:23 +01001336 if (cpars.emergency) {
1337 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id)));
1338 } else {
1339 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party)));
1340 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001341
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001342 if (cpars.stop_after_cc_setup) {
1343 return;
1344 }
1345
1346 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001347 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001348
1349 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 +01001350 var boolean got_mncc_setup_compl_ind := false;
1351 var boolean got_cc_connect := false;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001352
Harald Welteb71901a2018-01-26 19:16:05 +01001353 interleave {
1354 [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001355 log("f_mo_call_establish 1: rx MNCC SETUP ind");
Harald Welteb71901a2018-01-26 19:16:05 +01001356 cpars.mncc_callref := mncc.u.signal.callref;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001357 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1358 }
1359
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001360 /* First MGCP CRCX */
Harald Welteb71901a2018-01-26 19:16:05 +01001361 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001362 log("f_mo_call_establish 2: rx 1st CRCX");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001363 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1364 break;
1365 }
Philipp Maierf1e02bb2018-03-15 16:30:00 +01001366 }
1367
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001368 /* Second MGCP CRCX */
1369 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
1370 log("f_mo_call_establish 6: rx 2nd CRCX");
1371 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1372 break;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001373 }
Harald Welteb71901a2018-01-26 19:16:05 +01001374 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001375
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001376 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1377 log("f_mo_call_establish 3: rx RTP CREATE");
1378 /* Call Proceeding */
1379 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1380 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001381
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001382 /* Alerting */
1383 MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref));
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001384 }
Harald Welte9b751a62019-04-14 17:39:29 +02001385
Neels Hofmeyreccaa992019-10-15 16:42:21 +02001386 //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001387 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001388 log("f_mo_call_establish 4: rx Assignment Request");
1389 var BSSMAP_IE_AoIP_TransportLayerAddress tla;
1390 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001391 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
1392
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001393 if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass)) {
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001394 log("Expected:", tla_ass);
1395 log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer);
1396 setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE");
1397 mtc.stop;
1398 }
1399
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001400 tla := valueof(f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001401 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001402 if (cpars.use_osmux) {
1403 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1404 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1405 mtc.stop;
1406 }
1407 osmuxCID := valueof(ts_OsmuxCID(0));
1408 if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1409 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1410 mtc.stop;
1411 }
1412 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1413 } else {
1414 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1415 }
1416 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001417 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001418 [] BSSAP.receive(tr_RANAP_RabAssReq(*)) -> value ranap {
1419 log("f_mo_call_establish 4.iu: rx RANAP RAB Assignment Request");
1420 var RAB_SetupOrModifiedList l := {
1421 {
1422 {
1423 id := id_RAB_SetupOrModifiedItem,
1424 criticality := ignore,
1425 value_ := {
1426 rAB_SetupOrModifiedItem := {
1427 rAB_ID := int2bit(23, 8),
1428 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1429 iuTransportAssociation := {
1430 bindingID := '040c0000'O
1431 },
1432 dl_dataVolumes := omit,
1433 iE_Extensions := omit
1434 }
1435 }
1436 }
1437 }
1438 };
1439 BSSAP.send(ts_RANAP_RabAssResp(l));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001440 }
Harald Welte9b751a62019-04-14 17:39:29 +02001441
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001442 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1443 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1444 log("f_mo_call_establish 5: rx MDCX for the RAN side");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001445 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 +01001446 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001447 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001448 { int2str(cpars.rtp_payload_type) },
1449 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1450 cpars.rtp_sdp_format)),
1451 valueof(ts_SDP_ptime(20)) }));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001452
1453 if (cpars.use_osmux) {
1454 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1455 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1456 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1457 mtc.stop;
1458 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001459 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 +02001460 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001461 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 +02001462 }
1463 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001464 }
Harald Welte9b751a62019-04-14 17:39:29 +02001465
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001466 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {
1467 log("f_mo_call_establish 7: rx CC Alerting");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001468
1469 if (cpars.ran_clear_when_alerting) {
1470 if (g_pars.ran_is_geran) {
1471 BSSAP.send(ts_BSSMAP_ClearRequest(0));
1472 } else {
1473 BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention));
1474 }
1475 break;
1476 }
1477
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001478 cpars.mncc_callref := mncc.u.signal.callref;
1479 /* Call Proceeding */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001480 var octetstring ip;
1481 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1482 if (is_ipv6) {
1483 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1484 } else {
1485 ip := f_inet_addr(cpars.mncc_rtp_ip);
1486 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001487 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001488 is_ipv6, ip,
1489 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001490 /* payload type 3 = GSM FR */ 3));
1491 MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref));
1492 }
1493
1494 [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc {
1495 log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001496 got_mncc_setup_compl_ind := true;
1497 if (not cpars.expect_release and got_cc_connect) {
1498 break;
1499 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001500 }
1501
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001502 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) {
1503 log("f_mo_call_establish 10: rx CC CONNECT");
1504 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id)));
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001505 got_cc_connect := true;
1506 if (not cpars.expect_release and got_mncc_setup_compl_ind) {
1507 break;
1508 }
Harald Welteb71901a2018-01-26 19:16:05 +01001509 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001510
1511 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1512 log("f_mo_call_establish 11: rx CC RELEASE");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001513 if (not cpars.expect_release) {
1514 setverdict(fail, "Got unexpected CC Release");
1515 mtc.stop;
1516 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001517 f_expect_clear();
1518 break;
1519 }
1520 }
1521
1522 f_sleep(0.5);
1523 deactivate(mdcx);
1524
1525 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1526 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1527 } else {
1528 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1529 mtc.stop;
Harald Welteb71901a2018-01-26 19:16:05 +01001530 }
1531
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001532 log("f_mo_call_establish DONE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001533 setverdict(pass);
1534}
Harald Welteb71901a2018-01-26 19:16:05 +01001535
Harald Welte4c422b72019-02-17 16:27:10 +01001536function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001537runs on BSC_ConnHdlr {
1538
1539 var MobileIdentityLV mi;
1540 var MNCC_PDU mncc;
1541 var MgcpCommand mgcp_cmd;
1542 var boolean respond_to_dlcx;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001543 var boolean dlcx_contained_ci := false;
1544 var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand;
1545
1546 if (is_csfb) {
1547 t_clear := tr_BSSMAP_ClearCommandCSFB;
1548 }
1549
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001550 log("f_call_hangup 0: tx MNCC_DISC_REQ");
Harald Welteb71901a2018-01-26 19:16:05 +01001551 MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1552 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1553
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001554 log("f_call_hangup 1: rx DTAP CC DISC");
1555
Philipp Maier3716a5e2018-03-21 15:53:35 +01001556 if (release_by_ms) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001557 var BIT1 tid_remote := '1'B;
1558 if (cpars.mo_call) {
1559 tid_remote := '0'B;
1560 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001561 /* B-side (MS) Release of call */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001562 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 +01001563 MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001564 log("f_call_hangup 2: rx MNCC REL ind");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001565 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001566 log("f_call_hangup 3: rx DTAP CC REL COMPL");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001567 } else {
1568 /* A-side (PLMN) Release of call */
1569 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42))));
1570 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001571 log("f_call_hangup 4: rx DTAP CC RELEASE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001572 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
1573 }
Harald Welteb71901a2018-01-26 19:16:05 +01001574
Philipp Maier2a98a732018-03-19 16:06:12 +01001575 respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1576
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001577 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 +01001578 var default dlcx := activate(as_optional_mgcp_dlcx(cpars));
Harald Welte9b751a62019-04-14 17:39:29 +02001579
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001580 /* clearing of radio channel */
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001581 alt {
1582 [g_pars.ran_is_geran] BSSAP.receive(t_clear) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001583 log("f_call_hangup 5: rx BSSAP Clear Command");
1584 BSSAP.send(ts_BSSMAP_ClearComplete);
1585 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1586 log("f_call_hangup 6: rx SCCP DISC");
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001587 setverdict(pass);
Philipp Maier2a98a732018-03-19 16:06:12 +01001588 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001589 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) {
1590 log("f_call_hangup 5.iu: rx Iu Release Command");
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001591 BSSAP.send(ts_RANAP_IuReleaseComplete);
1592 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001593 log("f_call_hangup 6.iu: rx SCCP DISC");
1594 setverdict(pass);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001595 }
1596 }
1597
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001598 f_sleep(1.0);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001599 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1600 log("f_call_hangup 9: done");
1601
1602 deactivate(mdcx);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001603 deactivate(dlcx);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001604}
1605
1606function f_mt_call(inout CallParameters cpars)
1607runs on BSC_ConnHdlr {
1608
1609 f_mt_call_establish(cpars);
1610
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001611 log("Hold the call for some time");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001612 f_sleep(3.0);
1613
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001614 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001615 f_call_hangup(cpars, true);
1616
1617 setverdict(pass);
1618}
1619
1620function f_mo_call(inout CallParameters cpars)
1621runs on BSC_ConnHdlr {
1622
1623 f_mo_call_establish(cpars);
1624
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001625 log("Hold the call for some time");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001626 f_sleep(3.0);
1627
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001628 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001629 f_call_hangup(cpars, false);
1630
Harald Welteb71901a2018-01-26 19:16:05 +01001631 setverdict(pass);
1632}
Harald Weltea49e36e2018-01-21 19:29:33 +01001633
Daniel Willmann8b084372018-02-04 13:35:26 +01001634function f_mo_seq_dtmf_dup(inout CallParameters cpars)
1635runs on BSC_ConnHdlr {
1636
1637 timer T := 1.0;
Daniel Willmann8b084372018-02-04 13:35:26 +01001638 var MNCC_PDU mncc;
1639 var MgcpCommand mgcp_cmd;
1640 var template PDU_ML3_MS_NW dtmf_dtap;
1641
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001642 f_mo_call_establish(cpars);
Daniel Willmann8b084372018-02-04 13:35:26 +01001643
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001644 /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by
1645 * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001646
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001647 /* Find out the next NSD that will be used, from RAN emulation. */
1648 var N_Sd_Array last_n_sd := f_bssmap_last_n_sd();
1649 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 +01001650
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001651 /* Compose DTAP with this correct NSD */
Daniel Willmann8b084372018-02-04 13:35:26 +01001652 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001653
1654 /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */
1655 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001656 T.start;
1657 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001658 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
1659 log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind");
1660 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001661 [] T.timeout {
1662 setverdict(fail, "Timeout waiting for START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001663 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001664 }
1665 }
1666
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001667 /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message
1668 * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */
1669 dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2);
Daniel Willmann92f66272018-02-06 15:50:52 +01001670 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true));
Daniel Willmann8b084372018-02-04 13:35:26 +01001671 T.start;
1672 alt {
1673 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001674 setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001675 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001676 }
1677 [] T.timeout { }
1678 }
1679
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001680 /* Here the NSD should be correct again and we see a DTMF. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001681 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001682 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001683 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001684 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) {
1685 log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind");
1686 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001687 [] T.timeout {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001688 setverdict(fail, "Timeout waiting for final START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001689 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001690 }
1691 }
1692
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001693 f_call_hangup(cpars, true);
Daniel Willmann8b084372018-02-04 13:35:26 +01001694 setverdict(pass);
1695}
Harald Welte9b751a62019-04-14 17:39:29 +02001696
Harald Welte1ddc7162018-01-27 14:25:46 +01001697/* expect a clear command */
Harald Welte5946b332018-03-18 23:32:21 +01001698altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr {
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001699 var PDU_BSSAP bssap;
Harald Welte5946b332018-03-18 23:32:21 +01001700 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1701 BSSAP.send(ts_BSSMAP_ClearComplete);
1702 alt {
Harald Welte6811d102019-04-14 22:23:14 +02001703 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte5946b332018-03-18 23:32:21 +01001704 setverdict(pass);
1705 }
1706 [] BSSAP.receive {
1707 setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001708 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001709 }
1710 }
1711 }
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001712 [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap {
1713 setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001714 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001715 }
1716}
1717
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001718function f_expect_clear(float t := 5.0, boolean verify_vlr_cell_id := true) runs on BSC_ConnHdlr {
Harald Welte1ddc7162018-01-27 14:25:46 +01001719 timer T := t;
1720
1721 T.start;
1722 alt {
Harald Welte9b751a62019-04-14 17:39:29 +02001723 [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { }
1724 [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { }
Harald Welte1ddc7162018-01-27 14:25:46 +01001725 [] T.timeout {
Harald Welte5946b332018-03-18 23:32:21 +01001726 setverdict(fail, "Timeout waiting for ClearCommand/Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001727 mtc.stop;
Harald Welte1ddc7162018-01-27 14:25:46 +01001728 }
1729 }
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001730
1731 if (verify_vlr_cell_id) {
1732 /* Now the conn is gone, but the VLR reflects the cell ID */
1733 f_verify_vty_lac_ci();
1734 }
Harald Welte1ddc7162018-01-27 14:25:46 +01001735}
1736
Neels Hofmeyr0ac63152019-05-07 01:20:17 +02001737function f_create_bssmap_exp_handoverRequest(integer targetPointCode) runs on BSC_ConnHdlr {
1738 BSSAP_PROC.call(RAN_register_handoverRequest:{targetPointCode, self}) {
1739 [] BSSAP_PROC.getreply(RAN_register_handoverRequest:{?, ?}) {};
1740 }
1741}
1742
1743function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array {
1744 var N_Sd_Array last_n_sd;
1745 BSSAP_PROC.call(RAN_last_n_sd:{self, -}) {
1746 [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) {
1747 return last_n_sd;
1748 };
1749 }
1750}
1751
1752function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr {
1753 BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) {
1754 [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self});
1755 }
1756}
1757
Harald Weltef45efeb2018-04-09 18:19:24 +02001758type record SmsParametersTp {
1759 OCT1 msg_ref,
1760 TP_DA da,
1761 OCT1 pid,
1762 OCT1 dcs,
1763 integer udl,
1764 octetstring ud
1765}
1766type record SmsParametersRp {
1767 OCT1 msg_ref,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001768 RP_NumberingPlan_and_NumberDigits smsc_addr optional
Harald Weltef45efeb2018-04-09 18:19:24 +02001769}
1770type record SmsParameters {
1771 SmsParametersTp tp,
1772 SmsParametersRp rp,
1773 uint3_t tid,
1774 OCT1 dlci,
1775 uint7_t exp_rp_err optional
1776}
1777
1778template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := {
1779 tP_DA_NoPad := {
1780 tP_LengthIndicator := 0, /* overwritten */
1781 tP_NumberingPlanID := npl,
1782 tP_TypeOfNumber := ton,
1783 tp_Spare := '0'B,
1784 tP_DAValue := addr
1785 }
1786}
1787
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001788template RP_NumberingPlan_and_NumberDigits t_RP_Addr(template hexstring addr,
1789 template BIT4 npi := '0001'B,
1790 template BIT3 ton := '001'B,
1791 template BIT1 ext := '1'B) := {
1792 rP_NumberingPlanIdentification := npi,
1793 rP_TypeOfNumber := ton,
1794 rP_Ext := ext,
1795 rP_NumberDigits := addr
1796}
1797
Harald Weltef45efeb2018-04-09 18:19:24 +02001798template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := {
1799 tp := {
1800 msg_ref := '23'O,
1801 da := ts_TP_DA('0000'B, '000'B, tp_daddr),
1802 pid := '00'O,
1803 dcs := '00'O,
1804 udl := 0,
1805 ud := ''O
1806 },
1807 rp := {
1808 msg_ref := '42'O,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001809 /* We don't really need to have both SM-RP-DA/OA here, because only one IE
Vadim Yanitskiyafb15a82020-01-05 14:04:53 +01001810 * is included in MO/MT SMS, and in the most cases it's the SMSC address.
1811 * NOTE: this address is currently hard-coded by OsmoMSC. */
1812 smsc_addr := t_RP_Addr('447785016005'H)
Harald Weltef45efeb2018-04-09 18:19:24 +02001813 },
1814 tid := 0,
1815 dlci := '03'O,
1816 exp_rp_err := omit
1817}
1818
1819private altstep as_other_sms() runs on BSC_ConnHdlr {
1820 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) {
1821 setverdict(fail, "Unexpected SMS related PDU from MSC");
Daniel Willmannafce8662018-07-06 23:11:32 +02001822 mtc.stop;
Harald Weltef45efeb2018-04-09 18:19:24 +02001823 }
1824}
1825
Vadim Yanitskiy9cc019a2018-11-15 02:06:07 +07001826/* Submit a MO RP-SMMA over an already existing DTAP connection */
1827function f_mo_smma(inout SmsParameters spars)
1828runs on BSC_ConnHdlr {
1829 var template (value) RPDU_MS_SGSN rp_mo;
1830 var template (value) PDU_ML3_MS_NW l3_mo;
1831
1832 var default d := activate(as_other_sms());
1833
1834 /* just in case this is routed to SMPP.. */
1835 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1836
1837 rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref);
1838 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1839 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1840 /* receive CP-ACK for CP-DATA above */
1841 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1842
1843 deactivate(d);
1844 setverdict(pass);
1845}
1846
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001847/* Submit a MO-SMS over an already existing DTAP connection */
1848function f_mo_sms_submit(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02001849runs on BSC_ConnHdlr {
1850 var template (value) TPDU_RP_DATA_MS_SGSN tp_mo;
1851 var template (value) RPDU_MS_SGSN rp_mo;
1852 var template (value) PDU_ML3_MS_NW l3_mo;
1853
Harald Weltef45efeb2018-04-09 18:19:24 +02001854 var default d := activate(as_other_sms());
1855
Harald Weltef640a012018-04-14 17:49:21 +02001856 /* just in case this is routed to SMPP.. */
1857 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1858
Harald Weltef45efeb2018-04-09 18:19:24 +02001859 tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs,
1860 spars.tp.udl, spars.tp.ud);
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001861 rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, omit, spars.rp.smsc_addr, tp_mo);
Harald Weltef45efeb2018-04-09 18:19:24 +02001862 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1863 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1864 /* receive CP-ACK for CP-DATA above */
1865 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1866
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001867 deactivate(d);
1868 setverdict(pass);
1869}
1870
1871/* Wait RP-ACK for MO-SMS on an already existing DTAP connection */
1872function f_mo_sms_wait_rp_ack(inout SmsParameters spars)
1873runs on BSC_ConnHdlr {
1874 var template (value) PDU_ML3_MS_NW l3_mo;
1875
1876 var template TPDU_RP_DATA_SGSN_MS tp_mt;
1877 var template RPDU_SGSN_MS rp_mt;
1878 var template PDU_ML3_NW_MS l3_mt;
1879
1880 var default d := activate(as_other_sms());
1881
1882 /* just in case this is routed to SMPP.. */
1883 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1884
Harald Weltef45efeb2018-04-09 18:19:24 +02001885 if (ispresent(spars.exp_rp_err)) {
1886 /* expect an RP-ERROR message from MSC with given cause */
1887 rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err);
1888 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1889 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1890 /* send CP-ACK for CP-DATA just received */
1891 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1892 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1893 } else {
1894 /* expect RP-ACK for RP-DATA */
1895 rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref);
1896 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1897 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1898 /* send CP-ACO for CP-DATA just received */
1899 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1900 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1901 }
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001902
Harald Weltef45efeb2018-04-09 18:19:24 +02001903 deactivate(d);
1904 setverdict(pass);
1905}
1906
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001907/* Submit a MO-SMS, and wait for RP-ACK on an existing
1908 * (and authenticated, ...) DTAP connection */
1909function f_mo_sms(inout SmsParameters spars)
1910runs on BSC_ConnHdlr {
1911 f_mo_sms_submit(spars);
1912 f_mo_sms_wait_rp_ack(spars);
1913}
1914
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01001915function f_mt_sms_deliver_pdu(in SmsParameters spars)
1916runs on BSC_ConnHdlr
1917return template PDU_DTAP_MT {
1918 var template TPDU_RP_DATA_SGSN_MS tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?);
1919 var template RPDU_SGSN_MS rp_mt := tr_RP_DATA_MT(?, spars.rp.smsc_addr, omit, tp_mt);
1920 var template PDU_ML3_NW_MS l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt));
1921 return tr_PDU_DTAP_MT(l3_mt, spars.dlci);
1922}
1923
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001924/* Wait for MT SMS on an already existing DTAP connection */
1925function f_mt_sms_expect(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02001926runs on BSC_ConnHdlr {
Harald Weltef45efeb2018-04-09 18:19:24 +02001927 var template (value) PDU_ML3_MS_NW l3_mo;
Harald Weltef45efeb2018-04-09 18:19:24 +02001928 var PDU_DTAP_MT dtap_mt;
1929
1930 var default d := activate(as_other_sms());
1931
1932 /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01001933 BSSAP.receive(f_mt_sms_deliver_pdu(spars)) -> value dtap_mt;
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001934
Harald Weltef45efeb2018-04-09 18:19:24 +02001935 /* Extract relevant identifiers */
1936 spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio);
1937 spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference;
1938
1939 /* send CP-ACK for CP-DATA just received */
1940 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO);
1941 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1942
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001943 deactivate(d);
1944 setverdict(pass);
1945}
1946
1947/* Send RP-ACK for MT-SMS over an already existing DTAP connection */
1948function f_mt_sms_send_rp_ack(inout SmsParameters spars)
1949runs on BSC_ConnHdlr {
1950 var template (value) RPDU_MS_SGSN rp_mo;
1951 var template (value) PDU_ML3_MS_NW l3_mo;
1952 var template PDU_ML3_NW_MS l3_mt;
1953
1954 var default d := activate(as_other_sms());
1955
Harald Weltef45efeb2018-04-09 18:19:24 +02001956 /* send RP-ACK for RP-DATA */
1957 rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref);
1958 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
1959 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1960
1961 /* expect CP-ACK for CP-DATA(RP-ACK) just sent */
Harald Weltee008eea2018-04-14 21:05:48 +02001962 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
Harald Weltef45efeb2018-04-09 18:19:24 +02001963 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1964
1965 deactivate(d);
1966 setverdict(pass);
1967}
1968
Vadim Yanitskiy56318522018-11-24 03:40:47 +07001969/* Send RP-ERROR for MT-SMS over an already existing DTAP connection */
1970function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause)
1971runs on BSC_ConnHdlr {
1972 var template (value) RPDU_MS_SGSN rp_mo;
1973 var template (value) PDU_ML3_MS_NW l3_mo;
1974 var template PDU_ML3_NW_MS l3_mt;
1975
1976 var default d := activate(as_other_sms());
1977
1978 /* send RP-ACK for RP-DATA */
1979 rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause);
1980 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
1981 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1982
1983 /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */
1984 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
1985 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1986
1987 deactivate(d);
1988 setverdict(pass);
1989}
1990
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001991/* Wait for a MT-SMS and send RP-ACK over an already existing
1992 * (and authenticated, ...) DTAP connection */
1993function f_mt_sms(inout SmsParameters spars)
1994runs on BSC_ConnHdlr {
1995 f_mt_sms_expect(spars);
1996 f_mt_sms_send_rp_ack(spars);
1997}
Harald Weltea49e36e2018-01-21 19:29:33 +01001998
1999
Harald Weltea49e36e2018-01-21 19:29:33 +01002000}