blob: 11f0a5feebf1f901b52b9c424f3f3753c9fea647 [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;
Harald Weltea49e36e2018-01-21 19:29:33 +010018import from GSM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010019import from IPL4asp_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010020import from SCCPasp_Types all;
21import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020022import from RAN_Emulation all;
Harald Weltea49e36e2018-01-21 19:29:33 +010023import from BSSMAP_Templates all;
24
Harald Welte9b751a62019-04-14 17:39:29 +020025import from RANAP_Constants all;
26import from RANAP_IEs all;
27import from RANAP_PDU_Contents all;
28import from RANAP_PDU_Descriptions all;
29import from RANAP_Templates all;
30
Harald Weltea49e36e2018-01-21 19:29:33 +010031import from GSUP_Types all;
32import from GSUP_Emulation all;
33
34import from MNCC_Types all;
35import from MNCC_Emulation all;
36
Harald Welte4aa970c2018-01-26 10:38:09 +010037import from MGCP_Types all;
38import from MGCP_Emulation all;
Harald Welteb71901a2018-01-26 19:16:05 +010039import from MGCP_Templates all;
40import from SDP_Types all;
Harald Welte4aa970c2018-01-26 10:38:09 +010041
Harald Weltea49e36e2018-01-21 19:29:33 +010042import from MobileL3_Types all;
43import from MobileL3_CommonIE_Types all;
44import from MobileL3_MM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010045import from MobileL3_CC_Types all;
Harald Weltef45efeb2018-04-09 18:19:24 +020046import from MobileL3_SMS_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010047import from L3_Templates all;
Harald Welte158a7ca2018-02-16 18:11:31 +010048import from L3_Common all;
Harald Weltea49e36e2018-01-21 19:29:33 +010049
Harald Weltef640a012018-04-14 17:49:21 +020050import from SMPP_Emulation all;
51
Philipp Maieraeb29a82018-11-08 17:40:53 +010052import from IPA_Emulation all;
53import from Osmocom_CTRL_Functions all;
54import from Osmocom_CTRL_Types all;
55import from Osmocom_CTRL_Adapter all;
56
Philipp Maierc39a9d82018-11-09 11:21:08 +010057import from TELNETasp_PortType all;
58import from Osmocom_VTY_Functions all;
59
Harald Welte4263c522018-12-06 11:56:27 +010060import from SGsAP_Emulation all;
61
Harald Weltea49e36e2018-01-21 19:29:33 +010062/* this component represents a single subscriber connection */
Harald Welte6811d102019-04-14 22:23:14 +020063type 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 +010064 var BSC_ConnHdlrPars g_pars;
Harald Weltea10db902018-01-27 12:44:49 +010065 timer g_Tguard := 60.0;
Philipp Maierc39a9d82018-11-09 11:21:08 +010066 port TELNETasp_PT MSCVTY;
Harald Weltea49e36e2018-01-21 19:29:33 +010067}
68
Harald Weltede371492018-01-27 23:44:41 +010069type record BSC_ConnHdlrNetworkPars {
70 OCT1 kc_support,
71 boolean expect_tmsi,
72 boolean expect_auth,
Oliver Smith1d118ff2019-07-03 10:57:35 +020073 boolean expect_ciph,
74 boolean expect_imei,
75 boolean expect_imei_early,
76 GSUP_IMEIResult check_imei_result,
77 boolean check_imei_error
Harald Weltede371492018-01-27 23:44:41 +010078}
79
Harald Weltea49e36e2018-01-21 19:29:33 +010080type record BSC_ConnHdlrPars {
81 SCCP_PAR_Address sccp_addr_own,
82 SCCP_PAR_Address sccp_addr_peer,
83 BSSMAP_IE_CellIdentifier cell_id,
Harald Welte256571e2018-01-24 18:47:19 +010084 hexstring imei,
Harald Weltea49e36e2018-01-21 19:29:33 +010085 hexstring imsi,
Harald Welte82600572018-01-21 20:54:08 +010086 hexstring msisdn,
Harald Welte256571e2018-01-24 18:47:19 +010087 OCT4 tmsi optional,
Harald Welte9de84792018-01-28 01:06:35 +010088 MobileStationClassmark1_V cm1,
Harald Welte82600572018-01-21 20:54:08 +010089 BSSMAP_IE_ClassmarkInformationType2 cm2,
Harald Welte16114282018-01-24 22:41:21 +010090 BSSMAP_IE_ClassmarkInformationType3 cm3 optional,
Harald Weltede371492018-01-27 23:44:41 +010091 AuthVector vec optional,
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +010092 BSC_ConnHdlrNetworkPars net,
Philipp Maieraeb29a82018-11-08 17:40:53 +010093 boolean send_early_cm,
94 charstring ipa_ctrl_ip,
95 integer ipa_ctrl_port,
Philipp Maier9b690e42018-12-21 11:50:03 +010096 boolean ipa_ctrl_enable,
Philipp Maier57865482019-01-07 18:33:13 +010097 boolean mm_info,
Philipp Maierc09a1312019-04-09 16:05:26 +020098 boolean sgsap_enable,
Harald Weltef9abf8d2019-04-21 13:07:17 +020099 boolean gsup_enable,
Harald Weltec1f937a2019-04-21 21:19:23 +0200100 integer ran_idx,
Harald Welte9b751a62019-04-14 17:39:29 +0200101 boolean use_umts_aka,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200102 boolean ran_is_geran,
103 boolean use_osmux
Harald Weltea49e36e2018-01-21 19:29:33 +0100104};
105
Harald Welte9de84792018-01-28 01:06:35 +0100106/* get a one-octet bitmaks of supported algorithms based on Classmark information */
107function f_alg_mask_from_cm(BSSMAP_IE_ClassmarkInformationType2 cm2) return OCT1 {
108 var BIT8 res := '00000001'B; /* A5/0 always supported */
109
110 if (cm2.a5_1 == '0'B) {
111 res := res or4b '00000010'B;
112 }
113 if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) {
114 res := res or4b '00000100'B;
115 }
116 if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) {
117 res := res or4b '00001000'B;
118 }
119 /* TODO: CM3 for A5/4 and beyond */
120 return bit2oct(res);
121}
122
123/* determine the best algorithm available within the bit-mask */
124function f_best_alg_from_mask(OCT1 alg_in) return OCT1 {
125 var BIT8 alg := oct2bit(alg_in);
126 var BIT8 ordered_algs[8] := {
127 '10000000'B, '01000000'B, '00100000'B, '00010000'B,
128 '00001000'B, /* A5/3 */
129 '00000010'B, /* A5/1 */
130 '00000100'B, /* A5/2 */
131 '00000001'B /* A5/0 */ }
132 for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) {
133 if (alg and4b ordered_algs[i] != '00000000'B) {
134 return bit2oct(ordered_algs[i]);
135 }
136 }
137 return '00'O;
138}
139
140/* return an integer like '1' for A5/1 based on a mask (with only one bit set */
141function f_alg_from_mask(OCT1 mask_in) return integer {
142 var BIT8 mask := oct2bit(mask_in);
143 for (var integer i := 0; i < 8; i := i+1) {
144 if (mask and4b ('00000001'B << i) != '00000000'B) {
145 return i;
146 }
147 }
148 return -1;
149}
150
Harald Weltea10db902018-01-27 12:44:49 +0100151/* altstep for the global guard timer */
152private altstep as_Tguard() runs on BSC_ConnHdlr {
153 [] g_Tguard.timeout {
Daniel Willmann90829d62018-02-15 17:45:14 +0100154 setverdict(fail, "Tguard timeout");
Daniel Willmannafce8662018-07-06 23:11:32 +0200155 mtc.stop;
Harald Weltea10db902018-01-27 12:44:49 +0100156 }
157}
158
159/* init function, called as first function in new BSC_ConnHdlr */
Harald Weltead2952e2018-01-27 14:12:46 +0100160function f_init_handler(BSC_ConnHdlrPars pars, float t_guard := 60.0) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100161 /* make parameters available via component variable */
162 g_pars := pars;
163 /* Start guard timer and activate it as default */
Harald Weltead2952e2018-01-27 14:12:46 +0100164 g_Tguard.start(t_guard);
Harald Weltea10db902018-01-27 12:44:49 +0100165 activate(as_Tguard());
Harald Weltef640a012018-04-14 17:49:21 +0200166 /* Route all SMPP messages for our MSISDN to us */
167 f_create_smpp_expect(hex2str(pars.msisdn));
Philipp Maier57865482019-01-07 18:33:13 +0100168
Harald Welte4263c522018-12-06 11:56:27 +0100169 /* Route all SGs message for our IMSI to us */
Philipp Maier57865482019-01-07 18:33:13 +0100170 if (g_pars.sgsap_enable == true) {
171 f_create_sgsap_expect(pars.imsi);
172 }
Philipp Maieraeb29a82018-11-08 17:40:53 +0100173
174 if (g_pars.ipa_ctrl_enable == true) {
175 f_ipa_ctrl_start(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port);
176 }
Philipp Maierc39a9d82018-11-09 11:21:08 +0100177
178 map(self:MSCVTY, system:MSCVTY);
179 f_vty_set_prompts(MSCVTY);
180 f_vty_transceive(MSCVTY, "enable");
Harald Weltea10db902018-01-27 12:44:49 +0100181}
182
Harald Weltea49e36e2018-01-21 19:29:33 +0100183
Harald Welte6811d102019-04-14 22:23:14 +0200184/* Callback function from general RAN_Emulation whenever a connectionless
Harald Weltea49e36e2018-01-21 19:29:33 +0100185 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
186private function BscUnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200187runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Weltea49e36e2018-01-21 19:29:33 +0100188 var template PDU_BSSAP resp := omit;
189
190 log("BSSMAP_BscUnitdataCallback");
191 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200192 if (match(bssap, tr_BSSMAP_Reset(g_ran_ops.use_osmux))){
Harald Weltea49e36e2018-01-21 19:29:33 +0100193 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200194 resp := ts_BSSMAP_ResetAck(g_ran_ops.use_osmux);
Harald Weltea49e36e2018-01-21 19:29:33 +0100195 }
196
197 /* FIXME: Handle paging, etc. */
198 return resp;
199}
200
Harald Welte9b751a62019-04-14 17:39:29 +0200201private function RncUnitdataCallback(RANAP_PDU ranap)
202runs on RAN_Emulation_CT return template RANAP_PDU {
203 var template RANAP_PDU resp := omit;
204
205 log("RANAP_RncUnitdataCallback");
206 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200207 if (match(ranap, tr_RANAP_Reset())) {
Harald Welte9b751a62019-04-14 17:39:29 +0200208 log("RANAP_RncUnitdataCallback: Responding to RESET with RESET-ACK");
209 var CN_DomainIndicator dom;
210 dom := ranap.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator;
211 resp := ts_RANAP_ResetAck(dom);
212 }
213
214 /* FIXME: Handle paging, etc. */
215 return resp;
216}
217
218
Harald Welte6811d102019-04-14 22:23:14 +0200219const RanOps BSC_RanOps := {
Harald Weltea49e36e2018-01-21 19:29:33 +0100220 /* Create call-back for inbound connections from MSC (hand-over) */
Harald Welte6811d102019-04-14 22:23:14 +0200221 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Weltea49e36e2018-01-21 19:29:33 +0100222 unitdata_cb := refers(BscUnitdataCallback),
Harald Welte9b751a62019-04-14 17:39:29 +0200223 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
224 ranap_unitdata_cb := refers(RncUnitdataCallback),
225 ps_domain := false,
Harald Weltea49e36e2018-01-21 19:29:33 +0100226 decode_dtap := true,
Harald Weltea4ca4462018-02-09 00:17:14 +0100227 role_ms := true,
Harald Welte2fce7882019-04-15 11:48:05 +0200228 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200229 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200230 use_osmux := false,
Harald Weltea4ca4462018-02-09 00:17:14 +0100231 sccp_addr_local := omit,
232 sccp_addr_peer := omit
Harald Weltea49e36e2018-01-21 19:29:33 +0100233}
234
235
236private function MnccUnitdataCallback(MNCC_PDU mncc)
237runs on MNCC_Emulation_CT return template MNCC_PDU {
238 log("Ignoring MNCC", mncc);
239 return omit;
240}
241
242const MnccOps BCC_MnccOps := {
243 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
244 unitdata_cb := refers(MnccUnitdataCallback)
245}
246
247
248
Harald Welte6811d102019-04-14 22:23:14 +0200249/* Encode 'l3' and ask RAN_Emulation to create new connection with COMPL L3 INFO */
Harald Weltea49e36e2018-01-21 19:29:33 +0100250function f_bssap_compl_l3(PDU_ML3_MS_NW l3)
251runs on BSC_ConnHdlr {
252 log("Sending COMPL L3: ", l3);
253 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
254 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
255 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc))));
Harald Welte71b69332018-01-21 20:43:53 +0100256 alt {
Harald Welte6811d102019-04-14 22:23:14 +0200257 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
258 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte71b69332018-01-21 20:43:53 +0100259 setverdict(fail, "DISC.ind from SCCP");
Daniel Willmannafce8662018-07-06 23:11:32 +0200260 mtc.stop;
Harald Welte71b69332018-01-21 20:43:53 +0100261 }
262 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100263}
264
Harald Welte9b751a62019-04-14 17:39:29 +0200265/* generate Iu LAI from BSSAP CGI */
266private function f_IuLAI_from_BssmapCI(BSSMAP_IE_CellIdentifier ci) return LAI {
267 var LAI lai;
268 if (ischosen(ci.cellIdentification.cI_CGI)) {
269 lai.pLMNidentity := ci.cellIdentification.cI_CGI.mcc_mnc;
270 lai.lAC := ci.cellIdentification.cI_CGI.lac;
271 } else if (ischosen(ci.cellIdentification.cI_SAI)) {
272 lai.pLMNidentity := ci.cellIdentification.cI_SAI.mcc_mnc;
273 lai.lAC := ci.cellIdentification.cI_SAI.lac;
274 } else if (ischosen(ci.cellIdentification.ci_LAC_RNC_CI)) {
275 lai.pLMNidentity := ci.cellIdentification.ci_LAC_RNC_CI.mcc_mnc;
276 lai.lAC := ci.cellIdentification.ci_LAC_RNC_CI.lac;
277 } else {
278 mtc.stop;
279 }
280 lai.iE_Extensions := omit;
281 return lai;
282}
283
284/* like f_bssap_compl_l3() but for 3G */
285function f_ranap_initial_ue(PDU_ML3_MS_NW l3)
286runs on BSC_ConnHdlr {
287 log("Sending InitialUE: ", l3);
288 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
289 var RANAP_PDU ranap;
290 var LAI lai := f_IuLAI_from_BssmapCI(g_pars.cell_id);
291 var SAI sai := {
292 pLMNidentity := lai.pLMNidentity,
293 lAC := lai.lAC,
294 sAC := '0000'O, /* FIXME */
295 iE_Extensions := omit
296 };
297 var IuSignallingConnectionIdentifier sigc_id := int2bit(23, 24);
298 var GlobalRNC_ID grnc_id := {
299 pLMNidentity := lai.pLMNidentity,
300 rNC_ID := 2342 /* FIXME */
301 };
302
303 ranap := valueof(ts_RANAP_initialUE_CS(lai, sai, l3_enc, sigc_id, grnc_id));
304 BSSAP.send(ts_RANAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, ranap));
305 alt {
306 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
307 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
308 setverdict(fail, "DISC.ind from SCCP");
309 mtc.stop;
310 }
311 }
312}
313
Harald Weltedceacc72019-04-21 20:58:35 +0200314/* Send BSSMAP Complete L3 or RANAP Initial UE depending on 2G/3G RAN type */
315function f_cl3_or_initial_ue(PDU_ML3_MS_NW l3)
316runs on BSC_ConnHdlr {
317 if (g_pars.ran_is_geran) {
318 f_bssap_compl_l3(l3);
319 } else {
320 f_ranap_initial_ue(l3);
321 }
322}
323
Harald Welte081b19a2018-02-10 09:11:13 +0100324type enumerated EstablishType {
325 EST_TYPE_MO_CALL,
Harald Welte0bef21e2018-02-10 09:48:23 +0100326 EST_TYPE_EMERG_CALL,
Harald Weltef45efeb2018-04-09 18:19:24 +0200327 EST_TYPE_PAG_RESP,
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700328 EST_TYPE_MO_SMS,
329 EST_TYPE_SS_ACT
Harald Welte081b19a2018-02-10 09:11:13 +0100330};
331
Harald Weltea49e36e2018-01-21 19:29:33 +0100332/* helper function to fully establish a dedicated channel */
Harald Welteb9e86fa2018-04-09 18:18:31 +0200333function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL)
Harald Weltea49e36e2018-01-21 19:29:33 +0100334runs on BSC_ConnHdlr {
Harald Welte081b19a2018-02-10 09:11:13 +0100335 var PDU_ML3_MS_NW l3_info;
Harald Welteb9e86fa2018-04-09 18:18:31 +0200336 var MobileIdentityLV mi;
337
338 /* If we have a TMSI, use TMSI instead of IMSI */
339 if (ispresent(g_pars.tmsi)) {
340 mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi));
341 } else {
342 mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
343 }
344
Harald Welte081b19a2018-02-10 09:11:13 +0100345 select (etype) {
346 case (EST_TYPE_MO_CALL) {
347 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
348 }
Harald Welte0bef21e2018-02-10 09:48:23 +0100349 case (EST_TYPE_EMERG_CALL) {
350 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi));
351 }
Harald Welte081b19a2018-02-10 09:11:13 +0100352 case (EST_TYPE_PAG_RESP) {
353 l3_info := valueof(ts_PAG_RESP(mi));
354 }
Harald Weltef45efeb2018-04-09 18:19:24 +0200355 case (EST_TYPE_MO_SMS) {
356 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi));
357 }
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700358 case (EST_TYPE_SS_ACT) {
359 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi));
360 }
Harald Welte081b19a2018-02-10 09:11:13 +0100361 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100362
363 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Weltedceacc72019-04-21 20:58:35 +0200364 f_cl3_or_initial_ue(l3_info);
Harald Weltea49e36e2018-01-21 19:29:33 +0100365
Harald Weltede371492018-01-27 23:44:41 +0100366 f_mm_common();
Pau Espin Pedrolf8034482019-06-03 13:15:58 +0200367 if (g_pars.net.expect_ciph or not g_pars.ran_is_geran) {
Harald Welte148a7082018-01-26 18:56:43 +0100368 /* implicit CM SERVICE ACCEPT? */
369 } else {
Harald Welte0bef21e2018-02-10 09:48:23 +0100370 if (etype != EST_TYPE_PAG_RESP) {
Harald Welte081b19a2018-02-10 09:11:13 +0100371 /* explicit CM SERVICE ACCEPT */
372 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
373 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100374 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100375}
376
377/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
Harald Welte9de84792018-01-28 01:06:35 +0100378function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100379{
380 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
381 return f_build_lu(mi);
382}
Harald Welte9de84792018-01-28 01:06:35 +0100383function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100384{
385 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
386 return f_build_lu(mi);
387}
Harald Welte9de84792018-01-28 01:06:35 +0100388function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100389{
390 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
391 return f_build_lu(mi);
392}
Harald Welte9de84792018-01-28 01:06:35 +0100393private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100394{
395 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
396 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 +0100397 old_lai, mi, g_pars.cm1));
Harald Weltea49e36e2018-01-21 19:29:33 +0100398 return l3_info;
399}
400
Harald Weltea183a5d2019-05-09 13:40:52 +0200401altstep as_GSUP_SAI() runs on BSC_ConnHdlr {
402var GSUP_IE auth_tuple;
403[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)) {
404 if (g_pars.use_umts_aka) {
405 g_pars.vec := f_gen_auth_vec_3g();
406 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand,
407 g_pars.vec.sres,
408 g_pars.vec.kc,
409 g_pars.vec.ik,
410 g_pars.vec.ck,
411 g_pars.vec.autn,
412 g_pars.vec.res));
413 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
414 } else {
415 g_pars.vec := f_gen_auth_vec_2g();
416 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand,
417 g_pars.vec.sres,
418 g_pars.vec.kc));
419 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
420 }
421 }
422}
423
Harald Welte9de84792018-01-28 01:06:35 +0100424function f_mm_auth() runs on BSC_ConnHdlr
Harald Welte148a7082018-01-26 18:56:43 +0100425{
Harald Weltede371492018-01-27 23:44:41 +0100426 if (g_pars.net.expect_auth) {
Harald Weltea183a5d2019-05-09 13:40:52 +0200427 as_GSUP_SAI();
Harald Weltec1f937a2019-04-21 21:19:23 +0200428 if (g_pars.use_umts_aka) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200429 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn)));
430 var OCT4 res := substr(g_pars.vec.res, 0, 4);
431 var OCT4 xres := substr(g_pars.vec.res, 4, 4);
432 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres)));
433 } else {
Harald Weltec1f937a2019-04-21 21:19:23 +0200434 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand)));
435 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres)));
436 }
Harald Welte148a7082018-01-26 18:56:43 +0100437 }
Harald Welte9de84792018-01-28 01:06:35 +0100438}
Harald Welte148a7082018-01-26 18:56:43 +0100439
Oliver Smith1d118ff2019-07-03 10:57:35 +0200440function f_mm_imei() runs on BSC_ConnHdlr
441{
442 var PDU_DTAP_MT dtap_mt;
443 var GSUP_PDU gsup_msg;
444 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
445
446 if (not g_pars.net.expect_imei) {
447 return
448 }
449
450 /* MSC <-> BSC: ID req/rsp for IMEI */
451 alt {
452 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEI))) {
453 mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
454 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
455 }
456 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
457 setverdict(fail, "Expected ID REQ for IMEI DTAP MT message, but got: ", dtap_mt);
458 mtc.stop;
459 }
460 }
461
462 /* MSC <-> HLR: Check IMEI req/res/err */
463 alt {
464 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
465 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
466 }
467 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
468 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
469 }
470 [] GSUP.receive(?) -> value gsup_msg {
471 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
472 g_pars.imsi, "), but got: ", gsup_msg);
473 mtc.stop;
474 }
475 }
476}
477
478function f_mm_imei_early() runs on BSC_ConnHdlr
479{
480 var PDU_DTAP_MT dtap_mt;
481 var GSUP_PDU gsup_msg;
482 var MobileL3_CommonIE_Types.MobileIdentityLV mi;
483
484 if (not g_pars.net.expect_imei_early) {
485 return
486 }
487
488 /* MSC <-> BSC: ID req/rsp for IMEISV */
489 alt {
490 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEISV))) {
491 mi := valueof(ts_MI_IMEISV_LV(g_pars.imei));
492 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
493 }
494 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
495 setverdict(fail, "Expected ID REQ for IMEISV DTAP MT message, but got: ", dtap_mt);
496 mtc.stop;
497 }
498 }
499
500 /* MSC <-> HLR: Check IMEI req/res/err */
501 alt {
502 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
503 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
504 }
505 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
506 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
507 }
508 [] GSUP.receive(?) -> value gsup_msg {
509 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
510 g_pars.imsi, "), but got: ", gsup_msg);
511 mtc.stop;
512 }
513 }
514}
515
Harald Welte9de84792018-01-28 01:06:35 +0100516function f_mm_common() runs on BSC_ConnHdlr
517{
518 f_mm_auth();
Harald Welte9b751a62019-04-14 17:39:29 +0200519 if (g_pars.ran_is_geran) {
520 if (g_pars.net.expect_ciph) {
521 var OCT1 a5_net := f_alg_mask_from_cm(g_pars.cm2);
522 var OCT1 a5_intersect := g_pars.net.kc_support and4b a5_net;
523 alt {
524 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(a5_intersect, g_pars.vec.kc)) {
525 var OCT1 a5_chosen := f_best_alg_from_mask(a5_intersect);
526 var integer a5_nr := f_alg_from_mask(a5_chosen);
527 BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
528 }
529 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(?, g_pars.vec.kc)) {
530 setverdict(fail, "Wrong ciphering algorithm mask in CiphModCmd");
531 mtc.stop;
532 }
Harald Welte9de84792018-01-28 01:06:35 +0100533 }
Harald Welte9b751a62019-04-14 17:39:29 +0200534 /* FIXME: Send the best available algorithm */
535 }
536 } else { /* UTRAN */
537 alt {
538 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
539 uia_key := oct2bit(g_pars.vec.ik),
540 key_sts := ?,
541 uea_algs := ?,
542 uea_key := oct2bit(g_pars.vec.ck))) {
543 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/
544 var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/
545 BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen));
546 BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
547 }
548 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
549 setverdict(fail, "Invalid SecurityModeCommand (ciphering case)");
550 mtc.stop;
551 }
552 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
553 uia_key := oct2bit(g_pars.vec.ik),
554 key_sts := ?)) {
555 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/
556 BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
557 BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
558 }
559 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
560 setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)");
Daniel Willmannafce8662018-07-06 23:11:32 +0200561 mtc.stop;
Harald Welte9de84792018-01-28 01:06:35 +0100562 }
563 }
Harald Welte148a7082018-01-26 18:56:43 +0100564 }
565}
566
Philipp Maier9b690e42018-12-21 11:50:03 +0100567function f_expect_mm_info() runs on BSC_ConnHdlr {
568 if (g_pars.mm_info == true) {
569 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info));
570 }
571}
572
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100573function f_perform_lu()
Harald Weltea49e36e2018-01-21 19:29:33 +0100574runs on BSC_ConnHdlr {
575 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
576 var PDU_DTAP_MT dtap_mt;
577
578 /* tell GSUP dispatcher to send this IMSI to us */
579 f_create_gsup_expect(hex2str(g_pars.imsi));
580
581 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Welte9b751a62019-04-14 17:39:29 +0200582 if (g_pars.ran_is_geran) {
583 f_bssap_compl_l3(l3_lu);
584 if (g_pars.send_early_cm) {
585 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
586 }
587 } else {
588 f_ranap_initial_ue(l3_lu);
Harald Welte8a121b32018-01-22 03:00:41 +0100589 }
Harald Welte5c2622c2018-01-21 20:45:20 +0100590
Oliver Smith1d118ff2019-07-03 10:57:35 +0200591 f_mm_imei_early();
Harald Weltede371492018-01-27 23:44:41 +0100592 f_mm_common();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100593 f_msc_lu_hlr();
Oliver Smith1d118ff2019-07-03 10:57:35 +0200594 f_mm_imei();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100595 f_accept_reject_lu();
596 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
597 f_expect_clear();
Harald Welte16114282018-01-24 22:41:21 +0100598
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100599 setverdict(pass);
600}
601
602function f_msc_lu_hlr() runs on BSC_ConnHdlr
603{
Harald Weltea49e36e2018-01-21 19:29:33 +0100604 /* Expect MSC to perform LU with HLR */
605 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
606 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
607 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
608 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100609}
610
611function f_accept_reject_lu() runs on BSC_ConnHdlr {
612 var PDU_DTAP_MT dtap_mt;
Harald Weltea49e36e2018-01-21 19:29:33 +0100613
614 alt {
615 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
616 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
Harald Weltede371492018-01-27 23:44:41 +0100617 if (g_pars.net.expect_tmsi) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100618 if (not ispresent(lu_acc.mobileIdentityTLV) or
619 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
620 setverdict(fail, "Expected TMSI but no TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200621 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100622 } else {
Harald Welte256571e2018-01-24 18:47:19 +0100623 g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets;
Harald Weltea49e36e2018-01-21 19:29:33 +0100624 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
625 }
626 } else {
627 if (ispresent(lu_acc.mobileIdentityTLV) and
628 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
629 setverdict(fail, "Expected no TMSI but TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200630 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100631 }
632 }
633 }
634 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
635 setverdict(fail, "Expected LU ACK, but received LU REJ");
Daniel Willmannafce8662018-07-06 23:11:32 +0200636 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100637 }
638 }
Philipp Maier9b690e42018-12-21 11:50:03 +0100639
640 /* Wait for MM-Information (if enabled) */
641 f_expect_mm_info();
Harald Weltea49e36e2018-01-21 19:29:33 +0100642 setverdict(pass);
643}
644
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200645function f_expect_lu_reject() runs on BSC_ConnHdlr {
646 var PDU_DTAP_MT dtap_mt;
647 timer T := 5.0;
648
649 T.start;
650 alt {
651 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
652 setverdict(pass);
653 }
654 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
655 setverdict(fail, "Expected LU reject BSSAP message, got: ", dtap_mt);
656 }
657 [] T.timeout {
658 setverdict(fail, "Timeout waiting for LU reject");
659 }
660 }
661}
662
Harald Weltea49e36e2018-01-21 19:29:33 +0100663function f_foo() runs on BSC_ConnHdlr{
Harald Welte6811d102019-04-14 22:23:14 +0200664 /* SCCP CC handled by RAN_Emulation_CT.main() */
Harald Weltea49e36e2018-01-21 19:29:33 +0100665 /* Expect auth, if enabled */
666
667 /* TODO: ISD */
668 /* Expect encr, if enabled */
669 /* Expect encr, if enabled */
670 /* Expect ASS CMD, if chan_type != requested */
671 /* Send ASS CMPL in successful case */
672
673 /* Expect AoIP port/ip information for RTP stream */
674 /* Expect MSC-originated MGCP to our simulated MGW */
675 /* Verify Counters via CTRL */
676 /* re-configure MSC behaviour via VTY */
677}
678
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200679type record CrcxResponse {
680 integer resp, /* 1 = reply with OK, 0 = do not reply, -1 = reply with error */
681 HostName mgw_rtp_ip,
682 PortNumber mgw_rtp_port,
683 MgcpConnectionId mgcp_connection_id /* MGCP Connection ID BSS Side */
684}
685
Harald Welteb71901a2018-01-26 19:16:05 +0100686/* parameters related to a (MO?) voice call */
687type record CallParameters {
Harald Welteb71901a2018-01-26 19:16:05 +0100688 /* CC related parameters */
689 hexstring called_party, /* whom are we calling */
690 integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100691 boolean mo_call, /* For a MO call, the transaction_id was allocated by the MS,
692 important to set the TI flag properly */
Harald Welteb71901a2018-01-26 19:16:05 +0100693 BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */
Harald Welte0bef21e2018-02-10 09:48:23 +0100694 boolean emergency, /* is this an emergency call? */
Harald Welteb71901a2018-01-26 19:16:05 +0100695
696 /* MNCC related parameters */
697 uint32_t mncc_callref optional, /* call reference on the MNCC side */
698 MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */
699
700 /* RTP related parameters */
701 HostName bss_rtp_ip optional, /* BSS Side RTP IP */
702 PortNumber bss_rtp_port optional, /* BSS Side RTP Port */
703 HostName mss_rtp_ip optional, /* MSS Side RTP IP */
704 PortNumber mss_rtp_port optional, /* MSS Side RTP Port */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200705 integer got_crcx_count,
706 CrcxResponse mgw_conn_1,
707 CrcxResponse mgw_conn_2,
Harald Welteb71901a2018-01-26 19:16:05 +0100708 uint7_t rtp_payload_type, /* dynamic RTP payload type */
709 charstring rtp_sdp_format, /* AMR/8000 or the like */
Philipp Maier2a98a732018-03-19 16:06:12 +0100710 boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX
711 (f_mt_call and f_mt_call) */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200712 boolean stop_after_cc_setup, /* Special case: stop call establish after CC Setup */
713 boolean ran_clear_when_alerting, /* Special case: send Clear upon CC Alerting */
Harald Welteb71901a2018-01-26 19:16:05 +0100714
Philipp Maiercd668572018-03-19 16:11:52 +0100715 MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */
Harald Welteb71901a2018-01-26 19:16:05 +0100716 MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200717
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200718 boolean use_osmux, /* MSC is expected to use Osmux for this call */
719 integer got_osmux_count
Harald Welteb71901a2018-01-26 19:16:05 +0100720}
721
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200722template (value) CallParameters t_CallParams(hexstring called := '12345'H, integer tid := 0) := {
Harald Welteb71901a2018-01-26 19:16:05 +0100723 called_party := called,
724 transaction_id := tid,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100725 mo_call := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100726 bearer_cap := valueof(ts_Bcap_voice),
Harald Welte0bef21e2018-02-10 09:48:23 +0100727 emergency := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100728 mncc_callref := omit,
729 mncc_bearer_cap := valueof(ts_MNCC_bcap_voice),
Harald Welte4017d552018-01-26 21:40:05 +0100730 bss_rtp_ip := "9.8.7.6",
731 bss_rtp_port := 9000,
Harald Welteb71901a2018-01-26 19:16:05 +0100732 mss_rtp_ip := omit,
733 mss_rtp_port := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200734 got_crcx_count := 0,
735 mgw_conn_1 := {
736 resp := 1,
737 mgw_rtp_ip := "1.1.1.1",
738 mgw_rtp_port := 10000,
739 mgcp_connection_id := '11111'H
740 },
741 mgw_conn_2 := {
742 resp := 1,
743 mgw_rtp_ip := "1.1.1.1",
744 mgw_rtp_port := 11000,
745 mgcp_connection_id := '22222'H
746 },
Harald Welteb71901a2018-01-26 19:16:05 +0100747 rtp_payload_type := 98,
748 rtp_sdp_format := "AMR/8000",
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100749 mgw_drop_dlcx := false,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200750 stop_after_cc_setup := false,
751 ran_clear_when_alerting := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100752 mgcp_call_id := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200753 mgcp_ep := "rtpbridge/1@mgw",
754 use_osmux := false,
755 got_osmux_count := 0
Harald Welteb71901a2018-01-26 19:16:05 +0100756};
757
Harald Welte4263c522018-12-06 11:56:27 +0100758/* Allocate a call reference and send SETUP via MNCC to MSC */
759function f_mt_call_initate(inout CallParameters cpars)
Harald Welte33ec09b2018-02-10 15:34:46 +0100760runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200761 cpars.mo_call := false;
Harald Welte4263c522018-12-06 11:56:27 +0100762 cpars.mncc_callref := f_rnd_int(2147483648);
763 MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
764 hex2str(cpars.called_party), hex2str(g_pars.imsi)));
765}
Harald Welte33ec09b2018-02-10 15:34:46 +0100766
Harald Welte408a7ef2019-04-21 17:08:40 +0200767private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) :=
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200768 ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
Harald Welte408a7ef2019-04-21 17:08:40 +0200769 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200770 cpars.mgw_conn_2.mgw_rtp_port,
Harald Welte408a7ef2019-04-21 17:08:40 +0200771 { int2str(cpars.rtp_payload_type) },
772 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
773 cpars.rtp_sdp_format)),
774 valueof(ts_SDP_ptime(20)) });
775
Harald Welte4263c522018-12-06 11:56:27 +0100776/* Complete call, begin with a paging response message via BSSAP */
777function f_mt_call_complete(inout CallParameters cpars)
778runs on BSC_ConnHdlr {
Harald Welte33ec09b2018-02-10 15:34:46 +0100779 var MNCC_PDU mncc;
780 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200781 var template MgcpResponse mgcp_resp;
782 var MgcpOsmuxCID osmux_cid;
783 var PDU_BSSAP bssap;
Harald Welte33ec09b2018-02-10 15:34:46 +0100784
Harald Welte6811d102019-04-14 22:23:14 +0200785 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Welte33ec09b2018-02-10 15:34:46 +0100786
Harald Welteb9e86fa2018-04-09 18:18:31 +0200787 f_establish_fully(EST_TYPE_PAG_RESP);
Harald Welte33ec09b2018-02-10 15:34:46 +0100788
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100789 log("f_mt_call_complete 1");
790
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200791 cpars.got_osmux_count := 0;
792
Harald Welte33ec09b2018-02-10 15:34:46 +0100793 /* MS <- MSC: Expect CC SETUP */
794 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party)));
795
796 /* MS -> MSC: ALERTING */
797 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id)));
798 MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100799 log("f_mt_call_complete 2");
Harald Welte33ec09b2018-02-10 15:34:46 +0100800
Harald Welte33ec09b2018-02-10 15:34:46 +0100801 /* Create MGCP expect */
802 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
803 /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */
804 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
805
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200806 /* First MGCP CRCX */
Harald Welte33ec09b2018-02-10 15:34:46 +0100807 MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100808 log("f_mt_call_complete 3");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200809 if (not f_handle_crcx(cpars, mgcp_cmd)) {
810 return;
Philipp Maier4b2692d2018-03-14 16:37:48 +0100811 }
Harald Welte33ec09b2018-02-10 15:34:46 +0100812 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +0100813
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +0100814
Harald Welte9b751a62019-04-14 17:39:29 +0200815 if (g_pars.ran_is_geran) {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200816 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass :=
817 tr_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.mgw_conn_1.mgw_rtp_ip), ?);
Harald Welte9b751a62019-04-14 17:39:29 +0200818
819 interleave {
820 /* Second MGCP CRCX (this time for MSS/CN side) */
821 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100822 log("f_mt_call_complete 4");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200823 if (not f_handle_crcx(cpars, mgcp_cmd)) {
824 break;
825 }
Harald Welte9b751a62019-04-14 17:39:29 +0200826 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100827
828 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
829 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
830 log("f_mt_call_complete 5");
831 }
832
Harald Welte9b751a62019-04-14 17:39:29 +0200833 /* expect the MSC to trigger a BSSMAP ASSIGNMENT */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200834 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200835 var template BSSMAP_IE_AoIP_TransportLayerAddress tla;
Harald Welte9b751a62019-04-14 17:39:29 +0200836 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200837 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100838 log("f_mt_call_complete 6");
Harald Welte9b751a62019-04-14 17:39:29 +0200839
840 tla := valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.bss_rtp_ip), cpars.bss_rtp_port));
841 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
842
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200843 if (cpars.use_osmux) {
844 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
845 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
846 mtc.stop;
847 }
848 osmuxCID := valueof(ts_OsmuxCID(0));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200849 if (not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
850 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 +0200851 mtc.stop;
852 }
853 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
854 } else {
855 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
856 }
857 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100858
859 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
Harald Welte9b751a62019-04-14 17:39:29 +0200860 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100861
862 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
863 log("f_mt_call_complete 7");
864 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
865 /* ip 42.23.11.5 */ hex2int('42231105'H),
866 /* port 423 */ 423,
867 /* payload type 3 = GSM FR */ 3));
868 }
869
870 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
871 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
872 log("f_mt_call_complete 8");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200873 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 +0100874 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200875 cpars.mgw_conn_2.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100876 { int2str(cpars.rtp_payload_type) },
877 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
878 cpars.rtp_sdp_format)),
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200879 valueof(ts_SDP_ptime(20)) }));
880 if (cpars.use_osmux) {
881 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
882 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
883 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
884 mtc.stop;
885 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200886 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 +0200887 } else {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200888 mgcp_resp := ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp);
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200889 }
890 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100891 }
892
893 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
894 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
895 log("f_mt_call_complete 9");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200896 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 +0100897 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200898 cpars.mgw_conn_2.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100899 { int2str(cpars.rtp_payload_type) },
900 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
901 cpars.rtp_sdp_format)),
902 valueof(ts_SDP_ptime(20)) }));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200903 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 +0100904 }
905
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +0100906 }
Harald Welte9b751a62019-04-14 17:39:29 +0200907 } else {
Harald Welte9b751a62019-04-14 17:39:29 +0200908 interleave {
909 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +0100910 log("f_mt_call_complete 4.iu");
911 if (not f_handle_crcx(cpars, mgcp_cmd)) {
912 break;
Harald Welte9b751a62019-04-14 17:39:29 +0200913 }
Harald Welte9b751a62019-04-14 17:39:29 +0200914 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100915
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +0100916 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
917 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
918 log("f_mt_call_complete 5.iu");
919 }
920
921 [] BSSAP.receive(tr_RANAP_RabAssReq(?)) {
922 log("f_mt_call_complete 6.iu");
923 var RAB_SetupOrModifiedList l := {
924 {
925 {
926 id := id_RAB_SetupOrModifiedItem,
927 criticality := ignore,
928 value_ := {
929 rAB_SetupOrModifiedItem := {
930 rAB_ID := int2bit(23, 8),
931 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
932 iuTransportAssociation := {
933 bindingID := '040c0000'O
934 },
935 dl_dataVolumes := omit,
936 iE_Extensions := omit
937 }
938 }
939 }
940 }
941 };
942 BSSAP.send(ts_RANAP_RabAssResp(l));
943
944 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
945 }
946
947 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
948 log("f_mt_call_complete 7.iu");
949 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
950 /* ip 42.23.11.5 */ hex2int('42231105'H),
951 /* port 423 */ 423,
952 /* payload type 3 = GSM FR */ 3));
953 }
954
955 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
956 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
957 log("f_mt_call_complete 8.iu");
958 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
959 hex2str(cpars.mgcp_call_id), "42",
960 cpars.mgw_conn_2.mgw_rtp_port,
961 { int2str(cpars.rtp_payload_type) },
962 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
963 cpars.rtp_sdp_format)),
964 valueof(ts_SDP_ptime(20)) }));
965 if (cpars.use_osmux) {
966 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
967 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
968 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
969 mtc.stop;
970 }
971 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
972 } else {
973 mgcp_resp := ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp);
974 }
975 MGCP.send(mgcp_resp);
976 }
977
978 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
979 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
980 log("f_mt_call_complete 9.iu");
981 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
982 hex2str(cpars.mgcp_call_id), "42",
983 cpars.mgw_conn_2.mgw_rtp_port,
984 { int2str(cpars.rtp_payload_type) },
985 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
986 cpars.rtp_sdp_format)),
987 valueof(ts_SDP_ptime(20)) }));
988 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
989 }
990
Harald Welte33ec09b2018-02-10 15:34:46 +0100991 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +0100992 }
Harald Welte33ec09b2018-02-10 15:34:46 +0100993
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200994 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
995 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
996 } else {
997 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
998 mtc.stop;
999 }
1000
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001001 log("f_mt_call_complete DONE");
Harald Welte4263c522018-12-06 11:56:27 +01001002}
1003
Harald Weltee035e3e2019-04-21 17:32:05 +02001004function f_expect_paging(boolean by_tmsi := true)
1005runs on BSC_ConnHdlr {
Harald Welte9b751a62019-04-14 17:39:29 +02001006 if (g_pars.ran_is_geran) {
1007 BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
1008 } else {
Harald Welte62113fc2019-05-09 13:04:02 +02001009 BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi)));
Harald Welte9b751a62019-04-14 17:39:29 +02001010 }
Harald Weltee035e3e2019-04-21 17:32:05 +02001011}
1012
Harald Welte4263c522018-12-06 11:56:27 +01001013function f_mt_call_establish(inout CallParameters cpars)
1014runs on BSC_ConnHdlr {
1015
1016 /* Initiate the call via MNCC */
1017 f_mt_call_initate(cpars);
1018
1019 /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
Harald Welte6811d102019-04-14 22:23:14 +02001020 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Weltee035e3e2019-04-21 17:32:05 +02001021 f_expect_paging()
Harald Welte4263c522018-12-06 11:56:27 +01001022
1023 /* Complete the call via BSSAP */
1024 f_mt_call_complete(cpars);
Harald Welte33ec09b2018-02-10 15:34:46 +01001025
Harald Welte33ec09b2018-02-10 15:34:46 +01001026 setverdict(pass);
1027}
1028
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001029/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1030 * Return true when an OK reply was sent, false otherwise.
1031 * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */
1032function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd)
1033runs on BSC_ConnHdlr
1034return boolean {
1035 var CrcxResponse conn := cpars.mgw_conn_1;
1036 if (cpars.got_crcx_count > 0) {
1037 conn := cpars.mgw_conn_2;
1038 }
1039 cpars.got_crcx_count := cpars.got_crcx_count + 1;
1040
1041 var MgcpMessage mgcp_msg := {
1042 command := mgcp_cmd
1043 }
1044 var template MgcpResponse mgcp_resp;
1045 var MgcpOsmuxCID osmux_cid;
1046 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1047 if (ispresent(cpars.mgcp_call_id)) {
1048 if (cpars.mgcp_call_id != call_id) {
1049 setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id);
1050 mtc.stop;
1051 }
1052 } else {
1053 cpars.mgcp_call_id := call_id;
1054 }
1055
1056 /* When the endpoint contains a wildcard we keep the endpoint
1057 * identifier we have set up in cpars. Otherwise we use the
1058 * endpoint name that the call agent has supplied */
1059 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1060 cpars.mgcp_ep := mgcp_cmd.line.ep;
1061 }
1062
1063 if (conn.resp == -1) {
1064 /* Reply with error */
1065 var MgcpResponse mgcp_rsp := {
1066 line := {
1067 code := "542",
1068 trans_id := mgcp_cmd.line.trans_id,
1069 string := "FORCED_FAIL"
1070 },
1071 sdp := omit
1072
1073 }
1074 var MgcpParameter mgcp_rsp_param := {
1075 code := "Z",
1076 val := cpars.mgcp_ep
1077 };
1078 mgcp_rsp.params[0] := mgcp_rsp_param;
1079 MGCP.send(mgcp_rsp);
1080 return false;
1081 }
1082
1083 if (conn.resp == 0) {
1084 /* Do not reply at all */
1085 return false;
1086 }
1087
1088 if (conn.resp != 1) {
1089 setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1");
1090 mtc.stop;
1091 }
1092
1093 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1094 hex2str(cpars.mgcp_call_id), "42",
1095 conn.mgw_rtp_port,
1096 { int2str(cpars.rtp_payload_type) },
1097 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1098 cpars.rtp_sdp_format)),
1099 valueof(ts_SDP_ptime(20)) }));
1100
1101 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1102 if (not cpars.use_osmux) {
1103 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1104 mtc.stop;
1105 }
1106 cpars.got_osmux_count := cpars.got_osmux_count + 1;
1107 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1108 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1109 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1110 if (osmux_cid != -1) {
1111 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1112 mtc.stop;
1113 }
1114
1115 osmux_cid := 0;
1116 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1117 } else {
1118 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1119 }
1120
1121 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep));
1122 MGCP.send(mgcp_resp);
1123 return true;
1124}
1125
1126
1127altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr {
1128 var MgcpCommand mgcp_cmd;
1129 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1130 log("as_optional_mgcp_crcx: rx CRCX");
1131 f_handle_crcx(cpars, mgcp_cmd);
1132
1133 /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an
1134 * CRCX is handled. */
1135 repeat;
1136 }
1137}
1138
1139private altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr {
1140 var MgcpCommand mgcp_cmd;
1141 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1142 log("as_optional_mgcp_mdcx: rx MDCX");
1143 log(mgcp_cmd);
1144 var charstring conn_id;
1145 var charstring rtp_payload_type;
1146 f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id);
1147 rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0];
1148
1149 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip,
1150 mgcp_cmd.sdp.origin.session_id, "42",
1151 mgw_rtp_port,
1152 { rtp_payload_type },
1153 { valueof(ts_SDP_ptime(20)) }));
1154 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp));
1155
1156 /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is
1157 * handled. */
1158 repeat;
1159 }
1160}
1161
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001162private altstep as_optional_mgcp_dlcx(CallParameters cpars) runs on BSC_ConnHdlr {
1163 var MgcpCommand mgcp_cmd;
1164 var boolean respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1165 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1166 log("as_optional_mgcp_dlcx: rx MGCP DLCX");
1167 if (respond_to_dlcx) {
1168 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1169 }
1170 /* Without this 'repeat', currently active other interleave and alt series exit as soon as a
1171 * DLCX is handled. */
1172 repeat;
1173 }
1174}
1175
Philipp Maier3716a5e2018-03-21 15:53:35 +01001176function f_mo_call_establish(inout CallParameters cpars)
Harald Welteb71901a2018-01-26 19:16:05 +01001177runs on BSC_ConnHdlr {
1178
Harald Welteb71901a2018-01-26 19:16:05 +01001179 var MNCC_PDU mncc;
1180 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001181 var template MgcpResponse mgcp_resp;
Philipp Maier2a98a732018-03-19 16:06:12 +01001182 var boolean respond_to_dlcx;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001183 var PDU_BSSAP bssap;
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001184 var RANAP_PDU ranap;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001185 var MgcpOsmuxCID osmux_cid;
Harald Welteb71901a2018-01-26 19:16:05 +01001186
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001187 cpars.mo_call := true;
1188
Harald Welte0bef21e2018-02-10 09:48:23 +01001189 if (cpars.emergency) {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001190 f_establish_fully(EST_TYPE_EMERG_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001191 } else {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001192 f_establish_fully(EST_TYPE_MO_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001193 }
Harald Welteb71901a2018-01-26 19:16:05 +01001194
1195 /* Create MNCC and MGCP expect */
1196 f_create_mncc_expect(hex2str(cpars.called_party));
1197 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1198
Harald Welte0bef21e2018-02-10 09:48:23 +01001199 if (cpars.emergency) {
1200 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id)));
1201 } else {
1202 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party)));
1203 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001204
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001205 if (cpars.stop_after_cc_setup) {
1206 return;
1207 }
1208
1209 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass :=
1210 tr_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.mgw_conn_1.mgw_rtp_ip), ?);
1211
1212 var default mdcx := activate(as_optional_mgcp_mdcx(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_port));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001213
Harald Welteb71901a2018-01-26 19:16:05 +01001214 interleave {
1215 [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001216 log("f_mo_call_establish 1: rx MNCC SETUP ind");
Harald Welteb71901a2018-01-26 19:16:05 +01001217 cpars.mncc_callref := mncc.u.signal.callref;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001218 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1219 }
1220
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001221 /* First MGCP CRCX */
Harald Welteb71901a2018-01-26 19:16:05 +01001222 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001223 log("f_mo_call_establish 2: rx 1st CRCX");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001224 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1225 break;
1226 }
Philipp Maierf1e02bb2018-03-15 16:30:00 +01001227 }
1228
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001229 /* Second MGCP CRCX */
1230 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
1231 log("f_mo_call_establish 6: rx 2nd CRCX");
1232 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1233 break;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001234 }
Harald Welteb71901a2018-01-26 19:16:05 +01001235 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001236
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001237 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1238 log("f_mo_call_establish 3: rx RTP CREATE");
1239 /* Call Proceeding */
1240 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1241 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001242
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001243 /* Alerting */
1244 MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref));
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001245 }
Harald Welte9b751a62019-04-14 17:39:29 +02001246
Neels Hofmeyreccaa992019-10-15 16:42:21 +02001247 //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001248 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001249 log("f_mo_call_establish 4: rx Assignment Request");
1250 var BSSMAP_IE_AoIP_TransportLayerAddress tla;
1251 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001252 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
1253
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001254 if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass)) {
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001255 log("Expected:", tla_ass);
1256 log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer);
1257 setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE");
1258 mtc.stop;
1259 }
1260
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001261 tla := valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.bss_rtp_ip), cpars.bss_rtp_port));
1262 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001263 if (cpars.use_osmux) {
1264 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1265 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1266 mtc.stop;
1267 }
1268 osmuxCID := valueof(ts_OsmuxCID(0));
1269 if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1270 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1271 mtc.stop;
1272 }
1273 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1274 } else {
1275 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1276 }
1277 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001278 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001279 [] BSSAP.receive(tr_RANAP_RabAssReq(*)) -> value ranap {
1280 log("f_mo_call_establish 4.iu: rx RANAP RAB Assignment Request");
1281 var RAB_SetupOrModifiedList l := {
1282 {
1283 {
1284 id := id_RAB_SetupOrModifiedItem,
1285 criticality := ignore,
1286 value_ := {
1287 rAB_SetupOrModifiedItem := {
1288 rAB_ID := int2bit(23, 8),
1289 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1290 iuTransportAssociation := {
1291 bindingID := '040c0000'O
1292 },
1293 dl_dataVolumes := omit,
1294 iE_Extensions := omit
1295 }
1296 }
1297 }
1298 }
1299 };
1300 BSSAP.send(ts_RANAP_RabAssResp(l));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001301 }
Harald Welte9b751a62019-04-14 17:39:29 +02001302
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001303 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1304 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1305 log("f_mo_call_establish 5: rx MDCX for the RAN side");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001306 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 +01001307 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001308 cpars.mgw_conn_2.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001309 { int2str(cpars.rtp_payload_type) },
1310 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1311 cpars.rtp_sdp_format)),
1312 valueof(ts_SDP_ptime(20)) }));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001313
1314 if (cpars.use_osmux) {
1315 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1316 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1317 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1318 mtc.stop;
1319 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001320 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 +02001321 } else {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001322 mgcp_resp := ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp);
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001323 }
1324 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001325 }
Harald Welte9b751a62019-04-14 17:39:29 +02001326
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001327 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {
1328 log("f_mo_call_establish 7: rx CC Alerting");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001329
1330 if (cpars.ran_clear_when_alerting) {
1331 if (g_pars.ran_is_geran) {
1332 BSSAP.send(ts_BSSMAP_ClearRequest(0));
1333 } else {
1334 BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention));
1335 }
1336 break;
1337 }
1338
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001339 cpars.mncc_callref := mncc.u.signal.callref;
1340 /* Call Proceeding */
1341 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
1342 /* ip 42.23.11.5 */ hex2int('42231105'H),
1343 /* port 423 */ 423,
1344 /* payload type 3 = GSM FR */ 3));
1345 MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref));
1346 }
1347
1348 [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc {
1349 log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind");
1350 }
1351
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001352 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) {
1353 log("f_mo_call_establish 10: rx CC CONNECT");
1354 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001355 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001356
1357 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1358 log("f_mo_call_establish 11: rx CC RELEASE");
1359 f_expect_clear();
1360 break;
1361 }
1362 }
1363
1364 f_sleep(0.5);
1365 deactivate(mdcx);
1366
1367 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1368 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1369 } else {
1370 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1371 mtc.stop;
Harald Welteb71901a2018-01-26 19:16:05 +01001372 }
1373
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001374 log("f_mo_call_establish DONE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001375 setverdict(pass);
1376}
Harald Welteb71901a2018-01-26 19:16:05 +01001377
Harald Welte4c422b72019-02-17 16:27:10 +01001378function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001379runs on BSC_ConnHdlr {
1380
1381 var MobileIdentityLV mi;
1382 var MNCC_PDU mncc;
1383 var MgcpCommand mgcp_cmd;
1384 var boolean respond_to_dlcx;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001385 var boolean dlcx_contained_ci := false;
1386 var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand;
1387
1388 if (is_csfb) {
1389 t_clear := tr_BSSMAP_ClearCommandCSFB;
1390 }
1391
Harald Welteb71901a2018-01-26 19:16:05 +01001392 MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1393 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1394
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001395 log("f_call_hangup 1: rx DTAP CC DISC");
1396
Philipp Maier3716a5e2018-03-21 15:53:35 +01001397 if (release_by_ms) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001398 var BIT1 tid_remote := '1'B;
1399 if (cpars.mo_call) {
1400 tid_remote := '0'B;
1401 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001402 /* B-side (MS) Release of call */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001403 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 +01001404 MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001405 log("f_call_hangup 2: rx MNCC REL ind");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001406 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001407 log("f_call_hangup 3: rx DTAP CC REL COMPL");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001408 } else {
1409 /* A-side (PLMN) Release of call */
1410 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42))));
1411 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001412 log("f_call_hangup 4: rx DTAP CC RELEASE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001413 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
1414 }
Harald Welteb71901a2018-01-26 19:16:05 +01001415
Philipp Maier2a98a732018-03-19 16:06:12 +01001416 respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1417
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001418 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 +01001419 var default dlcx := activate(as_optional_mgcp_dlcx(cpars));
Harald Welte9b751a62019-04-14 17:39:29 +02001420
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001421 /* clearing of radio channel */
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001422 alt {
1423 [g_pars.ran_is_geran] BSSAP.receive(t_clear) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001424 log("f_call_hangup 5: rx BSSAP Clear Command");
1425 BSSAP.send(ts_BSSMAP_ClearComplete);
1426 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1427 log("f_call_hangup 6: rx SCCP DISC");
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001428 setverdict(pass);
Philipp Maier2a98a732018-03-19 16:06:12 +01001429 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001430 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) {
1431 log("f_call_hangup 5.iu: rx Iu Release Command");
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001432 BSSAP.send(ts_RANAP_IuReleaseComplete);
1433 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001434 log("f_call_hangup 6.iu: rx SCCP DISC");
1435 setverdict(pass);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001436 }
1437 }
1438
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001439 f_sleep(1.0);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001440 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1441 log("f_call_hangup 9: done");
1442
1443 deactivate(mdcx);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001444 deactivate(dlcx);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001445}
1446
1447function f_mt_call(inout CallParameters cpars)
1448runs on BSC_ConnHdlr {
1449
1450 f_mt_call_establish(cpars);
1451
1452 /* Hold the call for some time */
1453 f_sleep(3.0);
1454
1455 f_call_hangup(cpars, true);
1456
1457 setverdict(pass);
1458}
1459
1460function f_mo_call(inout CallParameters cpars)
1461runs on BSC_ConnHdlr {
1462
1463 f_mo_call_establish(cpars);
1464
1465 /* Hold the call for some time */
1466 f_sleep(3.0);
1467
1468 f_call_hangup(cpars, false);
1469
Harald Welteb71901a2018-01-26 19:16:05 +01001470 setverdict(pass);
1471}
Harald Weltea49e36e2018-01-21 19:29:33 +01001472
Daniel Willmann8b084372018-02-04 13:35:26 +01001473function f_mo_seq_dtmf_dup(inout CallParameters cpars)
1474runs on BSC_ConnHdlr {
1475
1476 timer T := 1.0;
Daniel Willmann8b084372018-02-04 13:35:26 +01001477 var MNCC_PDU mncc;
1478 var MgcpCommand mgcp_cmd;
1479 var template PDU_ML3_MS_NW dtmf_dtap;
1480
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001481 f_mo_call_establish(cpars);
Daniel Willmann8b084372018-02-04 13:35:26 +01001482
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001483 /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by
1484 * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001485
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001486 /* Find out the next NSD that will be used, from RAN emulation. */
1487 var N_Sd_Array last_n_sd := f_bssmap_last_n_sd();
1488 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 +01001489
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001490 /* Compose DTAP with this correct NSD */
Daniel Willmann8b084372018-02-04 13:35:26 +01001491 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001492
1493 /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */
1494 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001495 T.start;
1496 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001497 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
1498 log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind");
1499 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001500 [] T.timeout {
1501 setverdict(fail, "Timeout waiting for START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001502 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001503 }
1504 }
1505
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001506 /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message
1507 * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */
1508 dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2);
Daniel Willmann92f66272018-02-06 15:50:52 +01001509 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true));
Daniel Willmann8b084372018-02-04 13:35:26 +01001510 T.start;
1511 alt {
1512 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001513 setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001514 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001515 }
1516 [] T.timeout { }
1517 }
1518
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001519 /* Here the NSD should be correct again and we see a DTMF. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001520 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001521 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001522 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001523 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) {
1524 log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind");
1525 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001526 [] T.timeout {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001527 setverdict(fail, "Timeout waiting for final START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001528 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001529 }
1530 }
1531
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001532 f_call_hangup(cpars, true);
Daniel Willmann8b084372018-02-04 13:35:26 +01001533 setverdict(pass);
1534}
Harald Welte9b751a62019-04-14 17:39:29 +02001535
Harald Welte1ddc7162018-01-27 14:25:46 +01001536/* expect a clear command */
Harald Welte5946b332018-03-18 23:32:21 +01001537altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr {
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001538 var PDU_BSSAP bssap;
Harald Welte5946b332018-03-18 23:32:21 +01001539 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1540 BSSAP.send(ts_BSSMAP_ClearComplete);
1541 alt {
Harald Welte6811d102019-04-14 22:23:14 +02001542 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte5946b332018-03-18 23:32:21 +01001543 setverdict(pass);
1544 }
1545 [] BSSAP.receive {
1546 setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001547 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001548 }
1549 }
1550 }
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001551 [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap {
1552 setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001553 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001554 }
1555}
1556
Harald Welte1ddc7162018-01-27 14:25:46 +01001557function f_expect_clear(float t := 5.0) runs on BSC_ConnHdlr {
1558 timer T := t;
1559
1560 T.start;
1561 alt {
Harald Welte9b751a62019-04-14 17:39:29 +02001562 [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { }
1563 [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { }
Harald Welte1ddc7162018-01-27 14:25:46 +01001564 [] T.timeout {
Harald Welte5946b332018-03-18 23:32:21 +01001565 setverdict(fail, "Timeout waiting for ClearCommand/Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001566 mtc.stop;
Harald Welte1ddc7162018-01-27 14:25:46 +01001567 }
1568 }
1569}
1570
Neels Hofmeyr0ac63152019-05-07 01:20:17 +02001571function f_create_bssmap_exp_handoverRequest(integer targetPointCode) runs on BSC_ConnHdlr {
1572 BSSAP_PROC.call(RAN_register_handoverRequest:{targetPointCode, self}) {
1573 [] BSSAP_PROC.getreply(RAN_register_handoverRequest:{?, ?}) {};
1574 }
1575}
1576
1577function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array {
1578 var N_Sd_Array last_n_sd;
1579 BSSAP_PROC.call(RAN_last_n_sd:{self, -}) {
1580 [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) {
1581 return last_n_sd;
1582 };
1583 }
1584}
1585
1586function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr {
1587 BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) {
1588 [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self});
1589 }
1590}
1591
Harald Weltef45efeb2018-04-09 18:19:24 +02001592type record SmsParametersTp {
1593 OCT1 msg_ref,
1594 TP_DA da,
1595 OCT1 pid,
1596 OCT1 dcs,
1597 integer udl,
1598 octetstring ud
1599}
1600type record SmsParametersRp {
1601 OCT1 msg_ref,
1602 RP_NumberingPlan_and_NumberDigits orig optional,
1603 RP_NumberingPlan_and_NumberDigits dest optional
1604}
1605type record SmsParameters {
1606 SmsParametersTp tp,
1607 SmsParametersRp rp,
1608 uint3_t tid,
1609 OCT1 dlci,
1610 uint7_t exp_rp_err optional
1611}
1612
1613template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := {
1614 tP_DA_NoPad := {
1615 tP_LengthIndicator := 0, /* overwritten */
1616 tP_NumberingPlanID := npl,
1617 tP_TypeOfNumber := ton,
1618 tp_Spare := '0'B,
1619 tP_DAValue := addr
1620 }
1621}
1622
1623template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := {
1624 tp := {
1625 msg_ref := '23'O,
1626 da := ts_TP_DA('0000'B, '000'B, tp_daddr),
1627 pid := '00'O,
1628 dcs := '00'O,
1629 udl := 0,
1630 ud := ''O
1631 },
1632 rp := {
1633 msg_ref := '42'O,
1634 orig := omit,
1635 dest := { '0000'B, '000'B, '0'B, '98765'H }
1636 },
1637 tid := 0,
1638 dlci := '03'O,
1639 exp_rp_err := omit
1640}
1641
1642private altstep as_other_sms() runs on BSC_ConnHdlr {
1643 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) {
1644 setverdict(fail, "Unexpected SMS related PDU from MSC");
Daniel Willmannafce8662018-07-06 23:11:32 +02001645 mtc.stop;
Harald Weltef45efeb2018-04-09 18:19:24 +02001646 }
1647}
1648
Vadim Yanitskiy9cc019a2018-11-15 02:06:07 +07001649/* Submit a MO RP-SMMA over an already existing DTAP connection */
1650function f_mo_smma(inout SmsParameters spars)
1651runs on BSC_ConnHdlr {
1652 var template (value) RPDU_MS_SGSN rp_mo;
1653 var template (value) PDU_ML3_MS_NW l3_mo;
1654
1655 var default d := activate(as_other_sms());
1656
1657 /* just in case this is routed to SMPP.. */
1658 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1659
1660 rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref);
1661 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1662 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1663 /* receive CP-ACK for CP-DATA above */
1664 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1665
1666 deactivate(d);
1667 setverdict(pass);
1668}
1669
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001670/* Submit a MO-SMS over an already existing DTAP connection */
1671function f_mo_sms_submit(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02001672runs on BSC_ConnHdlr {
1673 var template (value) TPDU_RP_DATA_MS_SGSN tp_mo;
1674 var template (value) RPDU_MS_SGSN rp_mo;
1675 var template (value) PDU_ML3_MS_NW l3_mo;
1676
Harald Weltef45efeb2018-04-09 18:19:24 +02001677 var default d := activate(as_other_sms());
1678
Harald Weltef640a012018-04-14 17:49:21 +02001679 /* just in case this is routed to SMPP.. */
1680 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1681
Harald Weltef45efeb2018-04-09 18:19:24 +02001682 tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs,
1683 spars.tp.udl, spars.tp.ud);
1684 rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, spars.rp.orig, spars.rp.dest, tp_mo);
1685 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1686 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1687 /* receive CP-ACK for CP-DATA above */
1688 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1689
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001690 deactivate(d);
1691 setverdict(pass);
1692}
1693
1694/* Wait RP-ACK for MO-SMS on an already existing DTAP connection */
1695function f_mo_sms_wait_rp_ack(inout SmsParameters spars)
1696runs on BSC_ConnHdlr {
1697 var template (value) PDU_ML3_MS_NW l3_mo;
1698
1699 var template TPDU_RP_DATA_SGSN_MS tp_mt;
1700 var template RPDU_SGSN_MS rp_mt;
1701 var template PDU_ML3_NW_MS l3_mt;
1702
1703 var default d := activate(as_other_sms());
1704
1705 /* just in case this is routed to SMPP.. */
1706 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1707
Harald Weltef45efeb2018-04-09 18:19:24 +02001708 if (ispresent(spars.exp_rp_err)) {
1709 /* expect an RP-ERROR message from MSC with given cause */
1710 rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err);
1711 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1712 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1713 /* send CP-ACK for CP-DATA just received */
1714 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1715 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1716 } else {
1717 /* expect RP-ACK for RP-DATA */
1718 rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref);
1719 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1720 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1721 /* send CP-ACO for CP-DATA just received */
1722 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1723 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1724 }
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001725
Harald Weltef45efeb2018-04-09 18:19:24 +02001726 deactivate(d);
1727 setverdict(pass);
1728}
1729
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001730/* Submit a MO-SMS, and wait for RP-ACK on an existing
1731 * (and authenticated, ...) DTAP connection */
1732function f_mo_sms(inout SmsParameters spars)
1733runs on BSC_ConnHdlr {
1734 f_mo_sms_submit(spars);
1735 f_mo_sms_wait_rp_ack(spars);
1736}
1737
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001738/* Wait for MT SMS on an already existing DTAP connection */
1739function f_mt_sms_expect(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02001740runs on BSC_ConnHdlr {
Harald Weltef45efeb2018-04-09 18:19:24 +02001741 var template (value) PDU_ML3_MS_NW l3_mo;
Harald Weltef45efeb2018-04-09 18:19:24 +02001742 var template TPDU_RP_DATA_SGSN_MS tp_mt;
1743 var template RPDU_SGSN_MS rp_mt;
1744 var template PDU_ML3_NW_MS l3_mt;
Harald Weltef45efeb2018-04-09 18:19:24 +02001745 var PDU_DTAP_MT dtap_mt;
1746
1747 var default d := activate(as_other_sms());
1748
1749 /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */
1750 tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?);
1751 rp_mt := tr_RP_DATA_MT(?, ?, omit, tp_mt);
1752 l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt));
1753 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)) -> value dtap_mt;
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001754
Harald Weltef45efeb2018-04-09 18:19:24 +02001755 /* Extract relevant identifiers */
1756 spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio);
1757 spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference;
1758
1759 /* send CP-ACK for CP-DATA just received */
1760 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO);
1761 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1762
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001763 deactivate(d);
1764 setverdict(pass);
1765}
1766
1767/* Send RP-ACK for MT-SMS over an already existing DTAP connection */
1768function f_mt_sms_send_rp_ack(inout SmsParameters spars)
1769runs on BSC_ConnHdlr {
1770 var template (value) RPDU_MS_SGSN rp_mo;
1771 var template (value) PDU_ML3_MS_NW l3_mo;
1772 var template PDU_ML3_NW_MS l3_mt;
1773
1774 var default d := activate(as_other_sms());
1775
Harald Weltef45efeb2018-04-09 18:19:24 +02001776 /* send RP-ACK for RP-DATA */
1777 rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref);
1778 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
1779 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1780
1781 /* expect CP-ACK for CP-DATA(RP-ACK) just sent */
Harald Weltee008eea2018-04-14 21:05:48 +02001782 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
Harald Weltef45efeb2018-04-09 18:19:24 +02001783 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1784
1785 deactivate(d);
1786 setverdict(pass);
1787}
1788
Vadim Yanitskiy56318522018-11-24 03:40:47 +07001789/* Send RP-ERROR for MT-SMS over an already existing DTAP connection */
1790function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause)
1791runs on BSC_ConnHdlr {
1792 var template (value) RPDU_MS_SGSN rp_mo;
1793 var template (value) PDU_ML3_MS_NW l3_mo;
1794 var template PDU_ML3_NW_MS l3_mt;
1795
1796 var default d := activate(as_other_sms());
1797
1798 /* send RP-ACK for RP-DATA */
1799 rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause);
1800 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
1801 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1802
1803 /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */
1804 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
1805 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1806
1807 deactivate(d);
1808 setverdict(pass);
1809}
1810
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001811/* Wait for a MT-SMS and send RP-ACK over an already existing
1812 * (and authenticated, ...) DTAP connection */
1813function f_mt_sms(inout SmsParameters spars)
1814runs on BSC_ConnHdlr {
1815 f_mt_sms_expect(spars);
1816 f_mt_sms_send_rp_ack(spars);
1817}
Harald Weltea49e36e2018-01-21 19:29:33 +01001818
1819
Harald Weltea49e36e2018-01-21 19:29:33 +01001820}
1821
1822