blob: 4330b5357e5414b62f3772f2745acd0915e44225 [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 {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200908 var template TransportLayerAddress rab_tla := ? /* FIXME: encode the mgw_rtp_ip/mgw_rtp_port */
Harald Welte9b751a62019-04-14 17:39:29 +0200909 var template RAB_SetupOrModifyList rab_sml := tr_RAB_SML(rab_id := ?, tla := rab_tla, binding_id := ?);
Harald Welte33ec09b2018-02-10 15:34:46 +0100910
Harald Welte9b751a62019-04-14 17:39:29 +0200911 interleave {
912 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
913 var SDP_Message sdp := valueof(ts_SDP_CRCX_CN(cpars));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200914 MGCP.send(ts_CRCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
Harald Welte9b751a62019-04-14 17:39:29 +0200915 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
916 MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref));
917 }
918 [] BSSAP.receive(tr_RANAP_RabAssReq(rab_sml)) {
919 //BSSAP.send(ts_RANAP_RabAssResp(rab_sml)); FIXME
920 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100921
922 /* FIXME: same MNCC and MGCP as in 2G above */
Harald Welte33ec09b2018-02-10 15:34:46 +0100923 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +0100924 }
Harald Welte33ec09b2018-02-10 15:34:46 +0100925
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200926 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
927 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
928 } else {
929 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
930 mtc.stop;
931 }
932
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100933 log("f_mt_call_complete DONE");
Harald Welte4263c522018-12-06 11:56:27 +0100934}
935
Harald Weltee035e3e2019-04-21 17:32:05 +0200936function f_expect_paging(boolean by_tmsi := true)
937runs on BSC_ConnHdlr {
Harald Welte9b751a62019-04-14 17:39:29 +0200938 if (g_pars.ran_is_geran) {
939 BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
940 } else {
Harald Welte62113fc2019-05-09 13:04:02 +0200941 BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi)));
Harald Welte9b751a62019-04-14 17:39:29 +0200942 }
Harald Weltee035e3e2019-04-21 17:32:05 +0200943}
944
Harald Welte4263c522018-12-06 11:56:27 +0100945function f_mt_call_establish(inout CallParameters cpars)
946runs on BSC_ConnHdlr {
947
948 /* Initiate the call via MNCC */
949 f_mt_call_initate(cpars);
950
951 /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
Harald Welte6811d102019-04-14 22:23:14 +0200952 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Weltee035e3e2019-04-21 17:32:05 +0200953 f_expect_paging()
Harald Welte4263c522018-12-06 11:56:27 +0100954
955 /* Complete the call via BSSAP */
956 f_mt_call_complete(cpars);
Harald Welte33ec09b2018-02-10 15:34:46 +0100957
Harald Welte33ec09b2018-02-10 15:34:46 +0100958 setverdict(pass);
959}
960
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200961/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
962 * Return true when an OK reply was sent, false otherwise.
963 * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */
964function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd)
965runs on BSC_ConnHdlr
966return boolean {
967 var CrcxResponse conn := cpars.mgw_conn_1;
968 if (cpars.got_crcx_count > 0) {
969 conn := cpars.mgw_conn_2;
970 }
971 cpars.got_crcx_count := cpars.got_crcx_count + 1;
972
973 var MgcpMessage mgcp_msg := {
974 command := mgcp_cmd
975 }
976 var template MgcpResponse mgcp_resp;
977 var MgcpOsmuxCID osmux_cid;
978 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
979 if (ispresent(cpars.mgcp_call_id)) {
980 if (cpars.mgcp_call_id != call_id) {
981 setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id);
982 mtc.stop;
983 }
984 } else {
985 cpars.mgcp_call_id := call_id;
986 }
987
988 /* When the endpoint contains a wildcard we keep the endpoint
989 * identifier we have set up in cpars. Otherwise we use the
990 * endpoint name that the call agent has supplied */
991 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
992 cpars.mgcp_ep := mgcp_cmd.line.ep;
993 }
994
995 if (conn.resp == -1) {
996 /* Reply with error */
997 var MgcpResponse mgcp_rsp := {
998 line := {
999 code := "542",
1000 trans_id := mgcp_cmd.line.trans_id,
1001 string := "FORCED_FAIL"
1002 },
1003 sdp := omit
1004
1005 }
1006 var MgcpParameter mgcp_rsp_param := {
1007 code := "Z",
1008 val := cpars.mgcp_ep
1009 };
1010 mgcp_rsp.params[0] := mgcp_rsp_param;
1011 MGCP.send(mgcp_rsp);
1012 return false;
1013 }
1014
1015 if (conn.resp == 0) {
1016 /* Do not reply at all */
1017 return false;
1018 }
1019
1020 if (conn.resp != 1) {
1021 setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1");
1022 mtc.stop;
1023 }
1024
1025 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1026 hex2str(cpars.mgcp_call_id), "42",
1027 conn.mgw_rtp_port,
1028 { int2str(cpars.rtp_payload_type) },
1029 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1030 cpars.rtp_sdp_format)),
1031 valueof(ts_SDP_ptime(20)) }));
1032
1033 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1034 if (not cpars.use_osmux) {
1035 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1036 mtc.stop;
1037 }
1038 cpars.got_osmux_count := cpars.got_osmux_count + 1;
1039 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1040 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1041 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1042 if (osmux_cid != -1) {
1043 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1044 mtc.stop;
1045 }
1046
1047 osmux_cid := 0;
1048 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1049 } else {
1050 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1051 }
1052
1053 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep));
1054 MGCP.send(mgcp_resp);
1055 return true;
1056}
1057
1058
1059altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr {
1060 var MgcpCommand mgcp_cmd;
1061 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1062 log("as_optional_mgcp_crcx: rx CRCX");
1063 f_handle_crcx(cpars, mgcp_cmd);
1064
1065 /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an
1066 * CRCX is handled. */
1067 repeat;
1068 }
1069}
1070
1071private altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr {
1072 var MgcpCommand mgcp_cmd;
1073 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1074 log("as_optional_mgcp_mdcx: rx MDCX");
1075 log(mgcp_cmd);
1076 var charstring conn_id;
1077 var charstring rtp_payload_type;
1078 f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id);
1079 rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0];
1080
1081 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip,
1082 mgcp_cmd.sdp.origin.session_id, "42",
1083 mgw_rtp_port,
1084 { rtp_payload_type },
1085 { valueof(ts_SDP_ptime(20)) }));
1086 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp));
1087
1088 /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is
1089 * handled. */
1090 repeat;
1091 }
1092}
1093
Philipp Maier3716a5e2018-03-21 15:53:35 +01001094function f_mo_call_establish(inout CallParameters cpars)
Harald Welteb71901a2018-01-26 19:16:05 +01001095runs on BSC_ConnHdlr {
1096
Harald Welteb71901a2018-01-26 19:16:05 +01001097 var MNCC_PDU mncc;
1098 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001099 var template MgcpResponse mgcp_resp;
Philipp Maier2a98a732018-03-19 16:06:12 +01001100 var boolean respond_to_dlcx;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001101 var PDU_BSSAP bssap;
1102 var MgcpOsmuxCID osmux_cid;
Harald Welteb71901a2018-01-26 19:16:05 +01001103
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001104 cpars.mo_call := true;
1105
Harald Welte0bef21e2018-02-10 09:48:23 +01001106 if (cpars.emergency) {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001107 f_establish_fully(EST_TYPE_EMERG_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001108 } else {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001109 f_establish_fully(EST_TYPE_MO_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001110 }
Harald Welteb71901a2018-01-26 19:16:05 +01001111
1112 /* Create MNCC and MGCP expect */
1113 f_create_mncc_expect(hex2str(cpars.called_party));
1114 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1115
Harald Welte0bef21e2018-02-10 09:48:23 +01001116 if (cpars.emergency) {
1117 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id)));
1118 } else {
1119 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party)));
1120 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001121
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001122 if (cpars.stop_after_cc_setup) {
1123 return;
1124 }
1125
1126 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass :=
1127 tr_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.mgw_conn_1.mgw_rtp_ip), ?);
1128
1129 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 +01001130
Harald Welteb71901a2018-01-26 19:16:05 +01001131 interleave {
1132 [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001133 log("f_mo_call_establish 1: rx MNCC SETUP ind");
Harald Welteb71901a2018-01-26 19:16:05 +01001134 cpars.mncc_callref := mncc.u.signal.callref;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001135 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1136 }
1137
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001138 /* First MGCP CRCX */
Harald Welteb71901a2018-01-26 19:16:05 +01001139 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001140 log("f_mo_call_establish 2: rx 1st CRCX");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001141 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1142 break;
1143 }
Philipp Maierf1e02bb2018-03-15 16:30:00 +01001144 }
1145
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001146 /* Second MGCP CRCX */
1147 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
1148 log("f_mo_call_establish 6: rx 2nd CRCX");
1149 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1150 break;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001151 }
Harald Welteb71901a2018-01-26 19:16:05 +01001152 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001153
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001154 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1155 log("f_mo_call_establish 3: rx RTP CREATE");
1156 /* Call Proceeding */
1157 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1158 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001159
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001160 /* Alerting */
1161 MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref));
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001162 }
Harald Welte9b751a62019-04-14 17:39:29 +02001163
Neels Hofmeyreccaa992019-10-15 16:42:21 +02001164 //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001165 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001166 log("f_mo_call_establish 4: rx Assignment Request");
1167 var BSSMAP_IE_AoIP_TransportLayerAddress tla;
1168 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001169 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
1170
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001171 if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass)) {
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001172 log("Expected:", tla_ass);
1173 log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer);
1174 setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE");
1175 mtc.stop;
1176 }
1177
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001178 tla := valueof(ts_BSSMAP_IE_AoIP_TLA4(f_inet_addr(cpars.bss_rtp_ip), cpars.bss_rtp_port));
1179 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001180 if (cpars.use_osmux) {
1181 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1182 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1183 mtc.stop;
1184 }
1185 osmuxCID := valueof(ts_OsmuxCID(0));
1186 if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1187 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1188 mtc.stop;
1189 }
1190 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1191 } else {
1192 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1193 }
1194 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001195 }
1196 /*
1197 [!g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_RabAssReq(rab_sml)) {
1198 //BSSAP.send(ts_RANAP_RabAssResp(rab_sml)); FIXME
1199 }
1200 */
Harald Welte9b751a62019-04-14 17:39:29 +02001201
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001202 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1203 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1204 log("f_mo_call_establish 5: rx MDCX for the RAN side");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001205 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 +01001206 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001207 cpars.mgw_conn_2.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001208 { int2str(cpars.rtp_payload_type) },
1209 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1210 cpars.rtp_sdp_format)),
1211 valueof(ts_SDP_ptime(20)) }));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001212
1213 if (cpars.use_osmux) {
1214 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1215 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1216 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1217 mtc.stop;
1218 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001219 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 +02001220 } else {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001221 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 +02001222 }
1223 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001224 }
Harald Welte9b751a62019-04-14 17:39:29 +02001225
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001226 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {
1227 log("f_mo_call_establish 7: rx CC Alerting");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001228
1229 if (cpars.ran_clear_when_alerting) {
1230 if (g_pars.ran_is_geran) {
1231 BSSAP.send(ts_BSSMAP_ClearRequest(0));
1232 } else {
1233 BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention));
1234 }
1235 break;
1236 }
1237
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001238 cpars.mncc_callref := mncc.u.signal.callref;
1239 /* Call Proceeding */
1240 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
1241 /* ip 42.23.11.5 */ hex2int('42231105'H),
1242 /* port 423 */ 423,
1243 /* payload type 3 = GSM FR */ 3));
1244 MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref));
1245 }
1246
1247 [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc {
1248 log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind");
1249 }
1250
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001251 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) {
1252 log("f_mo_call_establish 10: rx CC CONNECT");
1253 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001254 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001255
1256 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1257 log("f_mo_call_establish 11: rx CC RELEASE");
1258 f_expect_clear();
1259 break;
1260 }
1261 }
1262
1263 f_sleep(0.5);
1264 deactivate(mdcx);
1265
1266 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1267 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1268 } else {
1269 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1270 mtc.stop;
Harald Welteb71901a2018-01-26 19:16:05 +01001271 }
1272
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001273 log("f_mo_call_establish DONE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001274 setverdict(pass);
1275}
Harald Welteb71901a2018-01-26 19:16:05 +01001276
Harald Welte4c422b72019-02-17 16:27:10 +01001277function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001278runs on BSC_ConnHdlr {
1279
1280 var MobileIdentityLV mi;
1281 var MNCC_PDU mncc;
1282 var MgcpCommand mgcp_cmd;
1283 var boolean respond_to_dlcx;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001284 var boolean dlcx_contained_ci := false;
1285 var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand;
1286
1287 if (is_csfb) {
1288 t_clear := tr_BSSMAP_ClearCommandCSFB;
1289 }
1290
Harald Welteb71901a2018-01-26 19:16:05 +01001291 MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1292 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1293
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001294 log("f_call_hangup 1: rx DTAP CC DISC");
1295
Philipp Maier3716a5e2018-03-21 15:53:35 +01001296 if (release_by_ms) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001297 var BIT1 tid_remote := '1'B;
1298 if (cpars.mo_call) {
1299 tid_remote := '0'B;
1300 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001301 /* B-side (MS) Release of call */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001302 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 +01001303 MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001304 log("f_call_hangup 2: rx MNCC REL ind");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001305 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001306 log("f_call_hangup 3: rx DTAP CC REL COMPL");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001307 } else {
1308 /* A-side (PLMN) Release of call */
1309 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42))));
1310 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001311 log("f_call_hangup 4: rx DTAP CC RELEASE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001312 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
1313 }
Harald Welteb71901a2018-01-26 19:16:05 +01001314
Philipp Maier2a98a732018-03-19 16:06:12 +01001315 respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1316
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001317 var default mdcx := activate(as_optional_mgcp_mdcx(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_port));
Harald Welte9b751a62019-04-14 17:39:29 +02001318
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001319 /* clearing of radio channel */
1320 interleave {
1321 //[g_pars.ran_is_geran] BSSAP.receive(t_clear) {
1322 [] BSSAP.receive(t_clear) {
1323 log("f_call_hangup 5: rx BSSAP Clear Command");
1324 BSSAP.send(ts_BSSMAP_ClearComplete);
1325 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1326 log("f_call_hangup 6: rx SCCP DISC");
Philipp Maier2a98a732018-03-19 16:06:12 +01001327 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001328 /*
1329 [!g_pars.ran_is_geran] BSSAP.receive(t_iurel) {
1330 BSSAP.send(ts_RANAP_IuReleaseComplete);
1331 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
Harald Welte9b751a62019-04-14 17:39:29 +02001332 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001333 */
1334 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1335 log("f_call_hangup 7: rx MGCP DLCX");
Harald Welte9b751a62019-04-14 17:39:29 +02001336 if (respond_to_dlcx) {
Harald Welte9b751a62019-04-14 17:39:29 +02001337 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
Harald Welte9b751a62019-04-14 17:39:29 +02001338 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001339 dlcx_contained_ci := f_MgcpCmd_contains_par(mgcp_cmd, "I");
1340 }
1341 }
1342
1343 /* Two DLCXes expected, one for RAN and one for CN side.
1344 * Unless the first DLCX did not contain a CI, in which case it was a wildcard DLCX for both. */
1345 if (dlcx_contained_ci) {
1346 MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1347 log("f_call_hangup 8: rx MGCP DLCX");
1348 if (respond_to_dlcx) {
1349 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
Harald Welte9b751a62019-04-14 17:39:29 +02001350 }
Harald Welteb71901a2018-01-26 19:16:05 +01001351 }
1352 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001353
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001354 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1355 log("f_call_hangup 9: done");
1356
1357 deactivate(mdcx);
1358
Philipp Maier3716a5e2018-03-21 15:53:35 +01001359 setverdict(pass);
1360}
1361
1362function f_mt_call(inout CallParameters cpars)
1363runs on BSC_ConnHdlr {
1364
1365 f_mt_call_establish(cpars);
1366
1367 /* Hold the call for some time */
1368 f_sleep(3.0);
1369
1370 f_call_hangup(cpars, true);
1371
1372 setverdict(pass);
1373}
1374
1375function f_mo_call(inout CallParameters cpars)
1376runs on BSC_ConnHdlr {
1377
1378 f_mo_call_establish(cpars);
1379
1380 /* Hold the call for some time */
1381 f_sleep(3.0);
1382
1383 f_call_hangup(cpars, false);
1384
Harald Welteb71901a2018-01-26 19:16:05 +01001385 setverdict(pass);
1386}
Harald Weltea49e36e2018-01-21 19:29:33 +01001387
Daniel Willmann8b084372018-02-04 13:35:26 +01001388function f_mo_seq_dtmf_dup(inout CallParameters cpars)
1389runs on BSC_ConnHdlr {
1390
1391 timer T := 1.0;
Daniel Willmann8b084372018-02-04 13:35:26 +01001392 var MNCC_PDU mncc;
1393 var MgcpCommand mgcp_cmd;
1394 var template PDU_ML3_MS_NW dtmf_dtap;
1395
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001396 f_mo_call_establish(cpars);
Daniel Willmann8b084372018-02-04 13:35:26 +01001397
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001398 /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by
1399 * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001400
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001401 /* Find out the next NSD that will be used, from RAN emulation. */
1402 var N_Sd_Array last_n_sd := f_bssmap_last_n_sd();
1403 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 +01001404
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001405 /* Compose DTAP with this correct NSD */
Daniel Willmann8b084372018-02-04 13:35:26 +01001406 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001407
1408 /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */
1409 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001410 T.start;
1411 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001412 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
1413 log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind");
1414 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001415 [] T.timeout {
1416 setverdict(fail, "Timeout waiting for START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001417 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001418 }
1419 }
1420
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001421 /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message
1422 * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */
1423 dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2);
Daniel Willmann92f66272018-02-06 15:50:52 +01001424 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true));
Daniel Willmann8b084372018-02-04 13:35:26 +01001425 T.start;
1426 alt {
1427 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001428 setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001429 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001430 }
1431 [] T.timeout { }
1432 }
1433
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001434 /* Here the NSD should be correct again and we see a DTMF. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001435 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001436 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001437 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001438 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) {
1439 log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind");
1440 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001441 [] T.timeout {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001442 setverdict(fail, "Timeout waiting for final START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001443 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001444 }
1445 }
1446
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001447 f_call_hangup(cpars, true);
Daniel Willmann8b084372018-02-04 13:35:26 +01001448 setverdict(pass);
1449}
Harald Welte9b751a62019-04-14 17:39:29 +02001450
Harald Welte1ddc7162018-01-27 14:25:46 +01001451/* expect a clear command */
Harald Welte5946b332018-03-18 23:32:21 +01001452altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr {
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001453 var PDU_BSSAP bssap;
Harald Welte5946b332018-03-18 23:32:21 +01001454 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1455 BSSAP.send(ts_BSSMAP_ClearComplete);
1456 alt {
Harald Welte6811d102019-04-14 22:23:14 +02001457 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte5946b332018-03-18 23:32:21 +01001458 setverdict(pass);
1459 }
1460 [] BSSAP.receive {
1461 setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001462 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001463 }
1464 }
1465 }
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001466 [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap {
1467 setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001468 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001469 }
1470}
1471
Harald Welte1ddc7162018-01-27 14:25:46 +01001472function f_expect_clear(float t := 5.0) runs on BSC_ConnHdlr {
1473 timer T := t;
1474
1475 T.start;
1476 alt {
Harald Welte9b751a62019-04-14 17:39:29 +02001477 [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { }
1478 [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { }
Harald Welte1ddc7162018-01-27 14:25:46 +01001479 [] T.timeout {
Harald Welte5946b332018-03-18 23:32:21 +01001480 setverdict(fail, "Timeout waiting for ClearCommand/Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001481 mtc.stop;
Harald Welte1ddc7162018-01-27 14:25:46 +01001482 }
1483 }
1484}
1485
Neels Hofmeyr0ac63152019-05-07 01:20:17 +02001486function f_create_bssmap_exp_handoverRequest(integer targetPointCode) runs on BSC_ConnHdlr {
1487 BSSAP_PROC.call(RAN_register_handoverRequest:{targetPointCode, self}) {
1488 [] BSSAP_PROC.getreply(RAN_register_handoverRequest:{?, ?}) {};
1489 }
1490}
1491
1492function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array {
1493 var N_Sd_Array last_n_sd;
1494 BSSAP_PROC.call(RAN_last_n_sd:{self, -}) {
1495 [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) {
1496 return last_n_sd;
1497 };
1498 }
1499}
1500
1501function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr {
1502 BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) {
1503 [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self});
1504 }
1505}
1506
Harald Weltef45efeb2018-04-09 18:19:24 +02001507type record SmsParametersTp {
1508 OCT1 msg_ref,
1509 TP_DA da,
1510 OCT1 pid,
1511 OCT1 dcs,
1512 integer udl,
1513 octetstring ud
1514}
1515type record SmsParametersRp {
1516 OCT1 msg_ref,
1517 RP_NumberingPlan_and_NumberDigits orig optional,
1518 RP_NumberingPlan_and_NumberDigits dest optional
1519}
1520type record SmsParameters {
1521 SmsParametersTp tp,
1522 SmsParametersRp rp,
1523 uint3_t tid,
1524 OCT1 dlci,
1525 uint7_t exp_rp_err optional
1526}
1527
1528template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := {
1529 tP_DA_NoPad := {
1530 tP_LengthIndicator := 0, /* overwritten */
1531 tP_NumberingPlanID := npl,
1532 tP_TypeOfNumber := ton,
1533 tp_Spare := '0'B,
1534 tP_DAValue := addr
1535 }
1536}
1537
1538template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := {
1539 tp := {
1540 msg_ref := '23'O,
1541 da := ts_TP_DA('0000'B, '000'B, tp_daddr),
1542 pid := '00'O,
1543 dcs := '00'O,
1544 udl := 0,
1545 ud := ''O
1546 },
1547 rp := {
1548 msg_ref := '42'O,
1549 orig := omit,
1550 dest := { '0000'B, '000'B, '0'B, '98765'H }
1551 },
1552 tid := 0,
1553 dlci := '03'O,
1554 exp_rp_err := omit
1555}
1556
1557private altstep as_other_sms() runs on BSC_ConnHdlr {
1558 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) {
1559 setverdict(fail, "Unexpected SMS related PDU from MSC");
Daniel Willmannafce8662018-07-06 23:11:32 +02001560 mtc.stop;
Harald Weltef45efeb2018-04-09 18:19:24 +02001561 }
1562}
1563
Vadim Yanitskiy9cc019a2018-11-15 02:06:07 +07001564/* Submit a MO RP-SMMA over an already existing DTAP connection */
1565function f_mo_smma(inout SmsParameters spars)
1566runs on BSC_ConnHdlr {
1567 var template (value) RPDU_MS_SGSN rp_mo;
1568 var template (value) PDU_ML3_MS_NW l3_mo;
1569
1570 var default d := activate(as_other_sms());
1571
1572 /* just in case this is routed to SMPP.. */
1573 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1574
1575 rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref);
1576 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1577 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1578 /* receive CP-ACK for CP-DATA above */
1579 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1580
1581 deactivate(d);
1582 setverdict(pass);
1583}
1584
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001585/* Submit a MO-SMS over an already existing DTAP connection */
1586function f_mo_sms_submit(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02001587runs on BSC_ConnHdlr {
1588 var template (value) TPDU_RP_DATA_MS_SGSN tp_mo;
1589 var template (value) RPDU_MS_SGSN rp_mo;
1590 var template (value) PDU_ML3_MS_NW l3_mo;
1591
Harald Weltef45efeb2018-04-09 18:19:24 +02001592 var default d := activate(as_other_sms());
1593
Harald Weltef640a012018-04-14 17:49:21 +02001594 /* just in case this is routed to SMPP.. */
1595 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1596
Harald Weltef45efeb2018-04-09 18:19:24 +02001597 tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs,
1598 spars.tp.udl, spars.tp.ud);
1599 rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, spars.rp.orig, spars.rp.dest, tp_mo);
1600 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1601 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1602 /* receive CP-ACK for CP-DATA above */
1603 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1604
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001605 deactivate(d);
1606 setverdict(pass);
1607}
1608
1609/* Wait RP-ACK for MO-SMS on an already existing DTAP connection */
1610function f_mo_sms_wait_rp_ack(inout SmsParameters spars)
1611runs on BSC_ConnHdlr {
1612 var template (value) PDU_ML3_MS_NW l3_mo;
1613
1614 var template TPDU_RP_DATA_SGSN_MS tp_mt;
1615 var template RPDU_SGSN_MS rp_mt;
1616 var template PDU_ML3_NW_MS l3_mt;
1617
1618 var default d := activate(as_other_sms());
1619
1620 /* just in case this is routed to SMPP.. */
1621 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1622
Harald Weltef45efeb2018-04-09 18:19:24 +02001623 if (ispresent(spars.exp_rp_err)) {
1624 /* expect an RP-ERROR message from MSC with given cause */
1625 rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err);
1626 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1627 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1628 /* send CP-ACK for CP-DATA just received */
1629 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1630 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1631 } else {
1632 /* expect RP-ACK for RP-DATA */
1633 rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref);
1634 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1635 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1636 /* send CP-ACO for CP-DATA just received */
1637 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1638 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1639 }
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001640
Harald Weltef45efeb2018-04-09 18:19:24 +02001641 deactivate(d);
1642 setverdict(pass);
1643}
1644
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001645/* Submit a MO-SMS, and wait for RP-ACK on an existing
1646 * (and authenticated, ...) DTAP connection */
1647function f_mo_sms(inout SmsParameters spars)
1648runs on BSC_ConnHdlr {
1649 f_mo_sms_submit(spars);
1650 f_mo_sms_wait_rp_ack(spars);
1651}
1652
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001653/* Wait for MT SMS on an already existing DTAP connection */
1654function f_mt_sms_expect(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02001655runs on BSC_ConnHdlr {
Harald Weltef45efeb2018-04-09 18:19:24 +02001656 var template (value) PDU_ML3_MS_NW l3_mo;
Harald Weltef45efeb2018-04-09 18:19:24 +02001657 var template TPDU_RP_DATA_SGSN_MS tp_mt;
1658 var template RPDU_SGSN_MS rp_mt;
1659 var template PDU_ML3_NW_MS l3_mt;
Harald Weltef45efeb2018-04-09 18:19:24 +02001660 var PDU_DTAP_MT dtap_mt;
1661
1662 var default d := activate(as_other_sms());
1663
1664 /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */
1665 tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?);
1666 rp_mt := tr_RP_DATA_MT(?, ?, omit, tp_mt);
1667 l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt));
1668 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci)) -> value dtap_mt;
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001669
Harald Weltef45efeb2018-04-09 18:19:24 +02001670 /* Extract relevant identifiers */
1671 spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio);
1672 spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference;
1673
1674 /* send CP-ACK for CP-DATA just received */
1675 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO);
1676 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1677
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001678 deactivate(d);
1679 setverdict(pass);
1680}
1681
1682/* Send RP-ACK for MT-SMS over an already existing DTAP connection */
1683function f_mt_sms_send_rp_ack(inout SmsParameters spars)
1684runs on BSC_ConnHdlr {
1685 var template (value) RPDU_MS_SGSN rp_mo;
1686 var template (value) PDU_ML3_MS_NW l3_mo;
1687 var template PDU_ML3_NW_MS l3_mt;
1688
1689 var default d := activate(as_other_sms());
1690
Harald Weltef45efeb2018-04-09 18:19:24 +02001691 /* send RP-ACK for RP-DATA */
1692 rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref);
1693 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
1694 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1695
1696 /* expect CP-ACK for CP-DATA(RP-ACK) just sent */
Harald Weltee008eea2018-04-14 21:05:48 +02001697 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
Harald Weltef45efeb2018-04-09 18:19:24 +02001698 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1699
1700 deactivate(d);
1701 setverdict(pass);
1702}
1703
Vadim Yanitskiy56318522018-11-24 03:40:47 +07001704/* Send RP-ERROR for MT-SMS over an already existing DTAP connection */
1705function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause)
1706runs on BSC_ConnHdlr {
1707 var template (value) RPDU_MS_SGSN rp_mo;
1708 var template (value) PDU_ML3_MS_NW l3_mo;
1709 var template PDU_ML3_NW_MS l3_mt;
1710
1711 var default d := activate(as_other_sms());
1712
1713 /* send RP-ACK for RP-DATA */
1714 rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause);
1715 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
1716 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1717
1718 /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */
1719 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
1720 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1721
1722 deactivate(d);
1723 setverdict(pass);
1724}
1725
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001726/* Wait for a MT-SMS and send RP-ACK over an already existing
1727 * (and authenticated, ...) DTAP connection */
1728function f_mt_sms(inout SmsParameters spars)
1729runs on BSC_ConnHdlr {
1730 f_mt_sms_expect(spars);
1731 f_mt_sms_send_rp_ack(spars);
1732}
Harald Weltea49e36e2018-01-21 19:29:33 +01001733
1734
Harald Weltea49e36e2018-01-21 19:29:33 +01001735}
1736
1737