blob: 8ca8264cc36936a2dcf7d1a7ce3a68621d6b245b [file] [log] [blame]
Harald Welte34b5a952019-05-27 11:54:11 +02001/* BSC Connection Handler of MSC test suite in TTCN-3
2 * (C) 2018-2019 Harald Welte <laforge@gnumonks.org>
3 * (C) 2018-2019 sysmocom - s.f.m.c. GmbH
4 * (C) 2018 Vadim Yanitskiy <axilirator@gmail.com>
5 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
Harald Weltea49e36e2018-01-21 19:29:33 +010013module BSC_ConnectionHandler {
14
15import from General_Types all;
16import from Osmocom_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010017import from Native_Functions all;
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +020018import from Misc_Helpers all;
Harald Weltea49e36e2018-01-21 19:29:33 +010019import from GSM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010020import from IPL4asp_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010021import from SCCPasp_Types all;
22import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020023import from RAN_Emulation all;
Harald Weltea49e36e2018-01-21 19:29:33 +010024import from BSSMAP_Templates all;
25
Harald Welte9b751a62019-04-14 17:39:29 +020026import from RANAP_Constants all;
27import from RANAP_IEs all;
28import from RANAP_PDU_Contents all;
29import from RANAP_PDU_Descriptions all;
30import from RANAP_Templates all;
31
Harald Weltea49e36e2018-01-21 19:29:33 +010032import from GSUP_Types all;
33import from GSUP_Emulation all;
34
35import from MNCC_Types all;
36import from MNCC_Emulation all;
37
Harald Welte4aa970c2018-01-26 10:38:09 +010038import from MGCP_Types all;
39import from MGCP_Emulation all;
Harald Welteb71901a2018-01-26 19:16:05 +010040import from MGCP_Templates all;
41import from SDP_Types all;
Harald Welte4aa970c2018-01-26 10:38:09 +010042
Harald Weltea49e36e2018-01-21 19:29:33 +010043import from MobileL3_Types all;
44import from MobileL3_CommonIE_Types all;
45import from MobileL3_MM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010046import from MobileL3_CC_Types all;
Harald Weltef45efeb2018-04-09 18:19:24 +020047import from MobileL3_SMS_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010048import from L3_Templates all;
Harald Welte158a7ca2018-02-16 18:11:31 +010049import from L3_Common all;
Harald Weltea49e36e2018-01-21 19:29:33 +010050
Harald Weltef640a012018-04-14 17:49:21 +020051import from SMPP_Emulation all;
52
Philipp Maieraeb29a82018-11-08 17:40:53 +010053import from IPA_Emulation all;
54import from Osmocom_CTRL_Functions all;
55import from Osmocom_CTRL_Types all;
56import from Osmocom_CTRL_Adapter all;
57
Philipp Maierc39a9d82018-11-09 11:21:08 +010058import from TELNETasp_PortType all;
59import from Osmocom_VTY_Functions all;
60
Harald Welte4263c522018-12-06 11:56:27 +010061import from SGsAP_Emulation all;
62
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +020063import from TCCConversion_Functions { function f_strstr };
64
Harald Weltea49e36e2018-01-21 19:29:33 +010065/* this component represents a single subscriber connection */
Harald Welte6811d102019-04-14 22:23:14 +020066type 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 +010067 var BSC_ConnHdlrPars g_pars;
Harald Weltea10db902018-01-27 12:44:49 +010068 timer g_Tguard := 60.0;
Philipp Maierc39a9d82018-11-09 11:21:08 +010069 port TELNETasp_PT MSCVTY;
Harald Weltea49e36e2018-01-21 19:29:33 +010070}
71
Harald Weltede371492018-01-27 23:44:41 +010072type record BSC_ConnHdlrNetworkPars {
73 OCT1 kc_support,
74 boolean expect_tmsi,
75 boolean expect_auth,
Oliver Smith1d118ff2019-07-03 10:57:35 +020076 boolean expect_ciph,
77 boolean expect_imei,
78 boolean expect_imei_early,
79 GSUP_IMEIResult check_imei_result,
80 boolean check_imei_error
Harald Weltede371492018-01-27 23:44:41 +010081}
82
Harald Weltea49e36e2018-01-21 19:29:33 +010083type record BSC_ConnHdlrPars {
84 SCCP_PAR_Address sccp_addr_own,
85 SCCP_PAR_Address sccp_addr_peer,
86 BSSMAP_IE_CellIdentifier cell_id,
Harald Welte256571e2018-01-24 18:47:19 +010087 hexstring imei,
Harald Weltea49e36e2018-01-21 19:29:33 +010088 hexstring imsi,
Harald Welte82600572018-01-21 20:54:08 +010089 hexstring msisdn,
Harald Welte256571e2018-01-24 18:47:19 +010090 OCT4 tmsi optional,
Harald Welte9de84792018-01-28 01:06:35 +010091 MobileStationClassmark1_V cm1,
Harald Welte82600572018-01-21 20:54:08 +010092 BSSMAP_IE_ClassmarkInformationType2 cm2,
Harald Welte16114282018-01-24 22:41:21 +010093 BSSMAP_IE_ClassmarkInformationType3 cm3 optional,
Harald Weltede371492018-01-27 23:44:41 +010094 AuthVector vec optional,
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +010095 BSC_ConnHdlrNetworkPars net,
Philipp Maieraeb29a82018-11-08 17:40:53 +010096 boolean send_early_cm,
97 charstring ipa_ctrl_ip,
98 integer ipa_ctrl_port,
Philipp Maier9b690e42018-12-21 11:50:03 +010099 boolean ipa_ctrl_enable,
Philipp Maier57865482019-01-07 18:33:13 +0100100 boolean mm_info,
Philipp Maierc09a1312019-04-09 16:05:26 +0200101 boolean sgsap_enable,
Harald Weltef9abf8d2019-04-21 13:07:17 +0200102 boolean gsup_enable,
Vadim Yanitskiy2dd96612020-01-07 21:48:29 +0100103 OCT4 gsup_sid,
Harald Weltec1f937a2019-04-21 21:19:23 +0200104 integer ran_idx,
Harald Welte9b751a62019-04-14 17:39:29 +0200105 boolean use_umts_aka,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200106 boolean ran_is_geran,
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200107 boolean use_osmux,
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200108 boolean use_ipv6,
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200109 boolean verify_cell_id,
110 OCT3 common_id_last_eutran_plmn optional
Harald Weltea49e36e2018-01-21 19:29:33 +0100111};
112
Harald Welte9de84792018-01-28 01:06:35 +0100113/* get a one-octet bitmaks of supported algorithms based on Classmark information */
114function f_alg_mask_from_cm(BSSMAP_IE_ClassmarkInformationType2 cm2) return OCT1 {
115 var BIT8 res := '00000001'B; /* A5/0 always supported */
116
117 if (cm2.a5_1 == '0'B) {
118 res := res or4b '00000010'B;
119 }
120 if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) {
121 res := res or4b '00000100'B;
122 }
123 if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) {
124 res := res or4b '00001000'B;
125 }
126 /* TODO: CM3 for A5/4 and beyond */
127 return bit2oct(res);
128}
129
130/* determine the best algorithm available within the bit-mask */
131function f_best_alg_from_mask(OCT1 alg_in) return OCT1 {
132 var BIT8 alg := oct2bit(alg_in);
133 var BIT8 ordered_algs[8] := {
134 '10000000'B, '01000000'B, '00100000'B, '00010000'B,
135 '00001000'B, /* A5/3 */
136 '00000010'B, /* A5/1 */
137 '00000100'B, /* A5/2 */
138 '00000001'B /* A5/0 */ }
139 for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) {
140 if (alg and4b ordered_algs[i] != '00000000'B) {
141 return bit2oct(ordered_algs[i]);
142 }
143 }
144 return '00'O;
145}
146
147/* return an integer like '1' for A5/1 based on a mask (with only one bit set */
148function f_alg_from_mask(OCT1 mask_in) return integer {
149 var BIT8 mask := oct2bit(mask_in);
150 for (var integer i := 0; i < 8; i := i+1) {
151 if (mask and4b ('00000001'B << i) != '00000000'B) {
152 return i;
153 }
154 }
155 return -1;
156}
157
Harald Weltea10db902018-01-27 12:44:49 +0100158/* altstep for the global guard timer */
159private altstep as_Tguard() runs on BSC_ConnHdlr {
160 [] g_Tguard.timeout {
Daniel Willmann90829d62018-02-15 17:45:14 +0100161 setverdict(fail, "Tguard timeout");
Daniel Willmannafce8662018-07-06 23:11:32 +0200162 mtc.stop;
Harald Weltea10db902018-01-27 12:44:49 +0100163 }
164}
165
166/* init function, called as first function in new BSC_ConnHdlr */
Harald Weltead2952e2018-01-27 14:12:46 +0100167function f_init_handler(BSC_ConnHdlrPars pars, float t_guard := 60.0) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100168 /* make parameters available via component variable */
169 g_pars := pars;
170 /* Start guard timer and activate it as default */
Harald Weltead2952e2018-01-27 14:12:46 +0100171 g_Tguard.start(t_guard);
Harald Weltea10db902018-01-27 12:44:49 +0100172 activate(as_Tguard());
Harald Weltef640a012018-04-14 17:49:21 +0200173 /* Route all SMPP messages for our MSISDN to us */
174 f_create_smpp_expect(hex2str(pars.msisdn));
Philipp Maier57865482019-01-07 18:33:13 +0100175
Harald Welte4263c522018-12-06 11:56:27 +0100176 /* Route all SGs message for our IMSI to us */
Philipp Maier57865482019-01-07 18:33:13 +0100177 if (g_pars.sgsap_enable == true) {
178 f_create_sgsap_expect(pars.imsi);
179 }
Philipp Maieraeb29a82018-11-08 17:40:53 +0100180
181 if (g_pars.ipa_ctrl_enable == true) {
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100182 f_ipa_ctrl_start_client(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port);
Philipp Maieraeb29a82018-11-08 17:40:53 +0100183 }
Philipp Maierc39a9d82018-11-09 11:21:08 +0100184
185 map(self:MSCVTY, system:MSCVTY);
186 f_vty_set_prompts(MSCVTY);
187 f_vty_transceive(MSCVTY, "enable");
Harald Weltea10db902018-01-27 12:44:49 +0100188}
189
Harald Weltea49e36e2018-01-21 19:29:33 +0100190
Harald Welte6811d102019-04-14 22:23:14 +0200191/* Callback function from general RAN_Emulation whenever a connectionless
Harald Weltea49e36e2018-01-21 19:29:33 +0100192 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
193private function BscUnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200194runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Weltea49e36e2018-01-21 19:29:33 +0100195 var template PDU_BSSAP resp := omit;
196
197 log("BSSMAP_BscUnitdataCallback");
198 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200199 if (match(bssap, tr_BSSMAP_Reset(g_ran_ops.use_osmux))){
Harald Weltea49e36e2018-01-21 19:29:33 +0100200 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200201 resp := ts_BSSMAP_ResetAck(g_ran_ops.use_osmux);
Harald Weltea49e36e2018-01-21 19:29:33 +0100202 }
203
204 /* FIXME: Handle paging, etc. */
205 return resp;
206}
207
Harald Welte9b751a62019-04-14 17:39:29 +0200208private function RncUnitdataCallback(RANAP_PDU ranap)
209runs on RAN_Emulation_CT return template RANAP_PDU {
210 var template RANAP_PDU resp := omit;
211
212 log("RANAP_RncUnitdataCallback");
213 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200214 if (match(ranap, tr_RANAP_Reset())) {
Harald Welte9b751a62019-04-14 17:39:29 +0200215 log("RANAP_RncUnitdataCallback: Responding to RESET with RESET-ACK");
216 var CN_DomainIndicator dom;
217 dom := ranap.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator;
218 resp := ts_RANAP_ResetAck(dom);
219 }
220
221 /* FIXME: Handle paging, etc. */
222 return resp;
223}
224
225
Harald Welte6811d102019-04-14 22:23:14 +0200226const RanOps BSC_RanOps := {
Harald Weltea49e36e2018-01-21 19:29:33 +0100227 /* Create call-back for inbound connections from MSC (hand-over) */
Harald Welte6811d102019-04-14 22:23:14 +0200228 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Weltea49e36e2018-01-21 19:29:33 +0100229 unitdata_cb := refers(BscUnitdataCallback),
Harald Welte9b751a62019-04-14 17:39:29 +0200230 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
231 ranap_unitdata_cb := refers(RncUnitdataCallback),
232 ps_domain := false,
Harald Weltea49e36e2018-01-21 19:29:33 +0100233 decode_dtap := true,
Harald Weltea4ca4462018-02-09 00:17:14 +0100234 role_ms := true,
Harald Welte2fce7882019-04-15 11:48:05 +0200235 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200236 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200237 use_osmux := false,
Harald Weltea4ca4462018-02-09 00:17:14 +0100238 sccp_addr_local := omit,
239 sccp_addr_peer := omit
Harald Weltea49e36e2018-01-21 19:29:33 +0100240}
241
242
243private function MnccUnitdataCallback(MNCC_PDU mncc)
244runs on MNCC_Emulation_CT return template MNCC_PDU {
245 log("Ignoring MNCC", mncc);
246 return omit;
247}
248
249const MnccOps BCC_MnccOps := {
250 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
251 unitdata_cb := refers(MnccUnitdataCallback)
252}
253
254
255
Harald Welte6811d102019-04-14 22:23:14 +0200256/* Encode 'l3' and ask RAN_Emulation to create new connection with COMPL L3 INFO */
Harald Weltea49e36e2018-01-21 19:29:33 +0100257function f_bssap_compl_l3(PDU_ML3_MS_NW l3)
258runs on BSC_ConnHdlr {
259 log("Sending COMPL L3: ", l3);
260 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
261 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
262 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc))));
Harald Welte71b69332018-01-21 20:43:53 +0100263 alt {
Harald Welte6811d102019-04-14 22:23:14 +0200264 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
265 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte71b69332018-01-21 20:43:53 +0100266 setverdict(fail, "DISC.ind from SCCP");
Daniel Willmannafce8662018-07-06 23:11:32 +0200267 mtc.stop;
Harald Welte71b69332018-01-21 20:43:53 +0100268 }
269 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100270}
271
Harald Welte9b751a62019-04-14 17:39:29 +0200272/* generate Iu LAI from BSSAP CGI */
273private function f_IuLAI_from_BssmapCI(BSSMAP_IE_CellIdentifier ci) return LAI {
274 var LAI lai;
275 if (ischosen(ci.cellIdentification.cI_CGI)) {
276 lai.pLMNidentity := ci.cellIdentification.cI_CGI.mcc_mnc;
277 lai.lAC := ci.cellIdentification.cI_CGI.lac;
278 } else if (ischosen(ci.cellIdentification.cI_SAI)) {
279 lai.pLMNidentity := ci.cellIdentification.cI_SAI.mcc_mnc;
280 lai.lAC := ci.cellIdentification.cI_SAI.lac;
281 } else if (ischosen(ci.cellIdentification.ci_LAC_RNC_CI)) {
282 lai.pLMNidentity := ci.cellIdentification.ci_LAC_RNC_CI.mcc_mnc;
283 lai.lAC := ci.cellIdentification.ci_LAC_RNC_CI.lac;
284 } else {
285 mtc.stop;
286 }
287 lai.iE_Extensions := omit;
288 return lai;
289}
290
291/* like f_bssap_compl_l3() but for 3G */
292function f_ranap_initial_ue(PDU_ML3_MS_NW l3)
293runs on BSC_ConnHdlr {
294 log("Sending InitialUE: ", l3);
295 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
296 var RANAP_PDU ranap;
297 var LAI lai := f_IuLAI_from_BssmapCI(g_pars.cell_id);
298 var SAI sai := {
299 pLMNidentity := lai.pLMNidentity,
300 lAC := lai.lAC,
301 sAC := '0000'O, /* FIXME */
302 iE_Extensions := omit
303 };
304 var IuSignallingConnectionIdentifier sigc_id := int2bit(23, 24);
305 var GlobalRNC_ID grnc_id := {
306 pLMNidentity := lai.pLMNidentity,
307 rNC_ID := 2342 /* FIXME */
308 };
309
310 ranap := valueof(ts_RANAP_initialUE_CS(lai, sai, l3_enc, sigc_id, grnc_id));
311 BSSAP.send(ts_RANAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, ranap));
312 alt {
313 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
314 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
315 setverdict(fail, "DISC.ind from SCCP");
316 mtc.stop;
317 }
318 }
319}
320
Harald Weltedceacc72019-04-21 20:58:35 +0200321/* Send BSSMAP Complete L3 or RANAP Initial UE depending on 2G/3G RAN type */
322function f_cl3_or_initial_ue(PDU_ML3_MS_NW l3)
323runs on BSC_ConnHdlr {
324 if (g_pars.ran_is_geran) {
325 f_bssap_compl_l3(l3);
326 } else {
327 f_ranap_initial_ue(l3);
328 }
329}
330
Harald Welte081b19a2018-02-10 09:11:13 +0100331type enumerated EstablishType {
332 EST_TYPE_MO_CALL,
Harald Welte0bef21e2018-02-10 09:48:23 +0100333 EST_TYPE_EMERG_CALL,
Harald Weltef45efeb2018-04-09 18:19:24 +0200334 EST_TYPE_PAG_RESP,
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700335 EST_TYPE_MO_SMS,
336 EST_TYPE_SS_ACT
Harald Welte081b19a2018-02-10 09:11:13 +0100337};
338
Harald Weltea49e36e2018-01-21 19:29:33 +0100339/* helper function to fully establish a dedicated channel */
Harald Welteb9e86fa2018-04-09 18:18:31 +0200340function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL)
Harald Weltea49e36e2018-01-21 19:29:33 +0100341runs on BSC_ConnHdlr {
Harald Welte081b19a2018-02-10 09:11:13 +0100342 var PDU_ML3_MS_NW l3_info;
Harald Welteb9e86fa2018-04-09 18:18:31 +0200343 var MobileIdentityLV mi;
344
345 /* If we have a TMSI, use TMSI instead of IMSI */
346 if (ispresent(g_pars.tmsi)) {
347 mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi));
348 } else {
349 mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
350 }
351
Harald Welte081b19a2018-02-10 09:11:13 +0100352 select (etype) {
353 case (EST_TYPE_MO_CALL) {
354 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
355 }
Harald Welte0bef21e2018-02-10 09:48:23 +0100356 case (EST_TYPE_EMERG_CALL) {
357 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi));
358 }
Harald Welte081b19a2018-02-10 09:11:13 +0100359 case (EST_TYPE_PAG_RESP) {
360 l3_info := valueof(ts_PAG_RESP(mi));
361 }
Harald Weltef45efeb2018-04-09 18:19:24 +0200362 case (EST_TYPE_MO_SMS) {
363 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi));
364 }
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700365 case (EST_TYPE_SS_ACT) {
366 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi));
367 }
Harald Welte081b19a2018-02-10 09:11:13 +0100368 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100369
370 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Weltedceacc72019-04-21 20:58:35 +0200371 f_cl3_or_initial_ue(l3_info);
Harald Weltea49e36e2018-01-21 19:29:33 +0100372
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200373 f_verify_vty_lac_ci(verify_vlr := false);
374
Harald Weltede371492018-01-27 23:44:41 +0100375 f_mm_common();
Pau Espin Pedrolf8034482019-06-03 13:15:58 +0200376 if (g_pars.net.expect_ciph or not g_pars.ran_is_geran) {
Harald Welte148a7082018-01-26 18:56:43 +0100377 /* implicit CM SERVICE ACCEPT? */
378 } else {
Harald Welte0bef21e2018-02-10 09:48:23 +0100379 if (etype != EST_TYPE_PAG_RESP) {
Harald Welte081b19a2018-02-10 09:11:13 +0100380 /* explicit CM SERVICE ACCEPT */
381 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
382 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100383 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100384}
385
386/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
Harald Welte9de84792018-01-28 01:06:35 +0100387function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100388{
389 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
390 return f_build_lu(mi);
391}
Harald Welte9de84792018-01-28 01:06:35 +0100392function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100393{
394 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
395 return f_build_lu(mi);
396}
Harald Welte9de84792018-01-28 01:06:35 +0100397function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100398{
399 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
400 return f_build_lu(mi);
401}
Harald Welte9de84792018-01-28 01:06:35 +0100402private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100403{
404 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
405 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 +0100406 old_lai, mi, g_pars.cm1));
Harald Weltea49e36e2018-01-21 19:29:33 +0100407 return l3_info;
408}
409
Harald Weltea183a5d2019-05-09 13:40:52 +0200410altstep as_GSUP_SAI() runs on BSC_ConnHdlr {
411var GSUP_IE auth_tuple;
412[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)) {
413 if (g_pars.use_umts_aka) {
414 g_pars.vec := f_gen_auth_vec_3g();
415 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand,
416 g_pars.vec.sres,
417 g_pars.vec.kc,
418 g_pars.vec.ik,
419 g_pars.vec.ck,
420 g_pars.vec.autn,
421 g_pars.vec.res));
422 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
423 } else {
424 g_pars.vec := f_gen_auth_vec_2g();
425 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand,
426 g_pars.vec.sres,
427 g_pars.vec.kc));
428 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
429 }
430 }
431}
432
Harald Welte9de84792018-01-28 01:06:35 +0100433function f_mm_auth() runs on BSC_ConnHdlr
Harald Welte148a7082018-01-26 18:56:43 +0100434{
Harald Weltede371492018-01-27 23:44:41 +0100435 if (g_pars.net.expect_auth) {
Harald Weltea183a5d2019-05-09 13:40:52 +0200436 as_GSUP_SAI();
Harald Weltec1f937a2019-04-21 21:19:23 +0200437 if (g_pars.use_umts_aka) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200438 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn)));
439 var OCT4 res := substr(g_pars.vec.res, 0, 4);
440 var OCT4 xres := substr(g_pars.vec.res, 4, 4);
441 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres)));
442 } else {
Harald Weltec1f937a2019-04-21 21:19:23 +0200443 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand)));
444 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres)));
445 }
Harald Welte148a7082018-01-26 18:56:43 +0100446 }
Harald Welte9de84792018-01-28 01:06:35 +0100447}
Harald Welte148a7082018-01-26 18:56:43 +0100448
Oliver Smith1d118ff2019-07-03 10:57:35 +0200449function f_mm_imei() runs on BSC_ConnHdlr
450{
451 var PDU_DTAP_MT dtap_mt;
452 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700453 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200454
455 if (not g_pars.net.expect_imei) {
456 return
457 }
458
459 /* MSC <-> BSC: ID req/rsp for IMEI */
460 alt {
461 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEI))) {
462 mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
463 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
464 }
465 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
466 setverdict(fail, "Expected ID REQ for IMEI DTAP MT message, but got: ", dtap_mt);
467 mtc.stop;
468 }
469 }
470
471 /* MSC <-> HLR: Check IMEI req/res/err */
472 alt {
473 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
474 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
475 }
476 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
477 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
478 }
479 [] GSUP.receive(?) -> value gsup_msg {
480 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
481 g_pars.imsi, "), but got: ", gsup_msg);
482 mtc.stop;
483 }
484 }
485}
486
487function f_mm_imei_early() runs on BSC_ConnHdlr
488{
489 var PDU_DTAP_MT dtap_mt;
490 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700491 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200492
493 if (not g_pars.net.expect_imei_early) {
494 return
495 }
496
497 /* MSC <-> BSC: ID req/rsp for IMEISV */
498 alt {
499 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEISV))) {
500 mi := valueof(ts_MI_IMEISV_LV(g_pars.imei));
501 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
502 }
503 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
504 setverdict(fail, "Expected ID REQ for IMEISV DTAP MT message, but got: ", dtap_mt);
505 mtc.stop;
506 }
507 }
508
509 /* MSC <-> HLR: Check IMEI req/res/err */
510 alt {
511 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
512 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
513 }
514 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
515 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
516 }
517 [] GSUP.receive(?) -> value gsup_msg {
518 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
519 g_pars.imsi, "), but got: ", gsup_msg);
520 mtc.stop;
521 }
522 }
523}
524
Harald Welte79f1e452020-08-18 22:55:02 +0200525function f_expect_common_id() runs on BSC_ConnHdlr
526{
527 if (g_pars.ran_is_geran) {
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200528 BSSAP.receive(tr_BSSMAP_CommonId(g_pars.imsi,
529 f_tr_BSSMAP_LastUsedEUTRANPLMNId(g_pars.common_id_last_eutran_plmn)));
Harald Welte79f1e452020-08-18 22:55:02 +0200530 } else {
531 BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
532 }
533}
534
Harald Welte9de84792018-01-28 01:06:35 +0100535function f_mm_common() runs on BSC_ConnHdlr
536{
537 f_mm_auth();
Harald Welte9b751a62019-04-14 17:39:29 +0200538 if (g_pars.ran_is_geran) {
539 if (g_pars.net.expect_ciph) {
540 var OCT1 a5_net := f_alg_mask_from_cm(g_pars.cm2);
541 var OCT1 a5_intersect := g_pars.net.kc_support and4b a5_net;
542 alt {
543 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(a5_intersect, g_pars.vec.kc)) {
544 var OCT1 a5_chosen := f_best_alg_from_mask(a5_intersect);
545 var integer a5_nr := f_alg_from_mask(a5_chosen);
546 BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
547 }
548 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(?, g_pars.vec.kc)) {
549 setverdict(fail, "Wrong ciphering algorithm mask in CiphModCmd");
550 mtc.stop;
551 }
Harald Welte9de84792018-01-28 01:06:35 +0100552 }
Harald Welte9b751a62019-04-14 17:39:29 +0200553 /* FIXME: Send the best available algorithm */
554 }
Harald Welte79f1e452020-08-18 22:55:02 +0200555 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200556 } else { /* UTRAN */
557 alt {
558 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
559 uia_key := oct2bit(g_pars.vec.ik),
560 key_sts := ?,
561 uea_algs := ?,
562 uea_key := oct2bit(g_pars.vec.ck))) {
563 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/
564 var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/
565 BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen));
Harald Welte79f1e452020-08-18 22:55:02 +0200566 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200567 }
568 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
569 setverdict(fail, "Invalid SecurityModeCommand (ciphering case)");
570 mtc.stop;
571 }
572 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
573 uia_key := oct2bit(g_pars.vec.ik),
574 key_sts := ?)) {
575 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/
576 BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
Harald Welte79f1e452020-08-18 22:55:02 +0200577 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200578 }
579 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
580 setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)");
Daniel Willmannafce8662018-07-06 23:11:32 +0200581 mtc.stop;
Harald Welte9de84792018-01-28 01:06:35 +0100582 }
583 }
Harald Welte148a7082018-01-26 18:56:43 +0100584 }
585}
586
Philipp Maier9b690e42018-12-21 11:50:03 +0100587function f_expect_mm_info() runs on BSC_ConnHdlr {
588 if (g_pars.mm_info == true) {
589 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info));
590 }
591}
592
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200593private function f_lac_ci_vty_str(BSSMAP_IE_CellIdentifier cell_id) return charstring
594{
595 return "LAC / cell ID: "
596 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.lac)) & " / "
597 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.ci));
598}
599
600/* Get an IMSI's info and verify that the g_pars.cell_id is reflected in the info.
601 * Verify both the "LAC / cell ID" in the VLR and the "LAC / cell ID" in the "Connection:" part, if any.
602 * If verify_vlr == false, then only verify the "Connection:" part, and fail if there is no "Connection:"; this is
603 * useful when a conn has been established, but the subscriber has not been authenticated, so the VLR does not yet
604 * reflect the new conn's cell ID.
605 */
606function f_verify_vty_lac_ci(boolean verify_vlr := true) runs on BSC_ConnHdlr {
607 if (not g_pars.ran_is_geran) {
608 log("Skipping f_verify_vty_lac_ci(), disabled for Iu");
609 setverdict(pass);
610 return;
611 }
612 if (not g_pars.verify_cell_id) {
613 /* Skip this verification; either the TC expects no cell id to end up being accepted, or this was
614 * disabled globally to test an older osmo-msc which doesn't store the cell id properly yet. */
615 log("Skipping f_verify_vty_lac_ci()");
616 setverdict(pass);
617 return;
618 }
619
620 var charstring vty_cmd := "show subscriber imsi " & hex2str(g_pars.imsi) & " conn";
621 var charstring result := f_vty_transceive_ret(MSCVTY, vty_cmd);
622 var charstring expect_lac_ci := "LAC / cell ID: "
623 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.lac)) & " / "
624 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.ci));
625
626 var boolean vlr_matches := false;
627 var boolean connection_present := false;
628 var boolean connection_matches := false;
629
630 /* There are two occurences of LAC / cell ID: once for the VLR record, and once for the active connection. The
631 * active connection part starts with 'Connection:'. If there is no active connection, that part is omitted.
632 * So, first find out whether there is a 'Connection:' part. Then verify the LAC / cell ID above 'Connection:'
633 * and below 'Connection:', separately.
634 */
635 var integer connection_start := f_strstr(result, "Connection:");
636 connection_present := (connection_start >= 0);
637
638 var integer lac_ci_match := f_strstr(result, expect_lac_ci);
639 if (connection_present) {
640 if (lac_ci_match > connection_start) {
641 /* The first match is below 'Connection:', so the VLR part above it did not match. */
642 vlr_matches := false;
643 connection_matches := true;
644 } else if (lac_ci_match >= 0) {
645 /* The first match is above 'Connection:', so the VLR part matches. */
646 vlr_matches := true;
647
648 /* Now find a match below 'Connection:' */
649 lac_ci_match := f_strstr(result, expect_lac_ci, connection_start);
650 connection_matches := (lac_ci_match > 0);
651 }
652 } else {
653 /* There is no 'Connection:', so a match, if any, is from the VLR part. */
654 vlr_matches := (lac_ci_match >= 0);
655 }
656
657 if (verify_vlr) {
658 if (not vlr_matches) {
659 setverdict(fail, vty_cmd, " shows mismatching LAC / cell ID in the VLR part, expecting: ",
660 expect_lac_ci, " -- got: ", result);
661 return;
662 } else {
663 log("f_verify_vty_lac_ci(): VLR record matches ", expect_lac_ci);
664 setverdict(pass);
665 }
666 }
667
668 if (connection_present) {
669 if (not connection_matches) {
670 setverdict(fail, vty_cmd, " shows mismatching LAC cell ID in the 'Connection' part, expecting: ",
671 expect_lac_ci, " -- got: ", result);
672 } else {
673 log("f_verify_vty_lac_ci(): Active connection matches ", expect_lac_ci);
674 setverdict(pass);
675 }
676 }
677
678 if (not verify_vlr and not connection_present) {
679 setverdict(fail, "f_verify_vty_lac_ci(verify_vlr := false) called, which requires an active connection, but there is no 'Connection:' part to verify in ", result);
680 }
681}
682
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100683function f_perform_lu()
Harald Weltea49e36e2018-01-21 19:29:33 +0100684runs on BSC_ConnHdlr {
685 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
686 var PDU_DTAP_MT dtap_mt;
687
688 /* tell GSUP dispatcher to send this IMSI to us */
689 f_create_gsup_expect(hex2str(g_pars.imsi));
690
691 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Welte9b751a62019-04-14 17:39:29 +0200692 if (g_pars.ran_is_geran) {
693 f_bssap_compl_l3(l3_lu);
694 if (g_pars.send_early_cm) {
695 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
696 }
697 } else {
698 f_ranap_initial_ue(l3_lu);
Harald Welte8a121b32018-01-22 03:00:41 +0100699 }
Harald Welte5c2622c2018-01-21 20:45:20 +0100700
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200701 /* at this point the conn has been established, but the subscriber has not been authenticated, so the VLR does
702 * not yet reflect this conn's cell ID. */
703 f_verify_vty_lac_ci(verify_vlr := false);
704
Oliver Smith1d118ff2019-07-03 10:57:35 +0200705 f_mm_imei_early();
Harald Weltede371492018-01-27 23:44:41 +0100706 f_mm_common();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100707 f_msc_lu_hlr();
Oliver Smith1d118ff2019-07-03 10:57:35 +0200708 f_mm_imei();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100709 f_accept_reject_lu();
710 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
711 f_expect_clear();
Harald Welte16114282018-01-24 22:41:21 +0100712
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100713 setverdict(pass);
714}
715
716function f_msc_lu_hlr() runs on BSC_ConnHdlr
717{
Harald Weltea49e36e2018-01-21 19:29:33 +0100718 /* Expect MSC to perform LU with HLR */
719 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
720 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
721 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
722 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100723}
724
725function f_accept_reject_lu() runs on BSC_ConnHdlr {
726 var PDU_DTAP_MT dtap_mt;
Harald Weltea49e36e2018-01-21 19:29:33 +0100727
728 alt {
729 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
730 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
Harald Weltede371492018-01-27 23:44:41 +0100731 if (g_pars.net.expect_tmsi) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100732 if (not ispresent(lu_acc.mobileIdentityTLV) or
733 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
734 setverdict(fail, "Expected TMSI but no TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200735 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100736 } else {
Harald Welte256571e2018-01-24 18:47:19 +0100737 g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets;
Harald Weltea49e36e2018-01-21 19:29:33 +0100738 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
739 }
740 } else {
741 if (ispresent(lu_acc.mobileIdentityTLV) and
742 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
743 setverdict(fail, "Expected no TMSI but TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200744 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100745 }
746 }
747 }
748 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
749 setverdict(fail, "Expected LU ACK, but received LU REJ");
Daniel Willmannafce8662018-07-06 23:11:32 +0200750 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100751 }
752 }
Philipp Maier9b690e42018-12-21 11:50:03 +0100753
754 /* Wait for MM-Information (if enabled) */
755 f_expect_mm_info();
Harald Weltea49e36e2018-01-21 19:29:33 +0100756 setverdict(pass);
757}
758
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100759function f_expect_lu_reject(template OCT1 cause := ?) runs on BSC_ConnHdlr {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200760 var PDU_DTAP_MT dtap_mt;
761 timer T := 5.0;
762
763 T.start;
764 alt {
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100765 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej(cause))) {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200766 setverdict(pass);
767 }
768 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
769 setverdict(fail, "Expected LU reject BSSAP message, got: ", dtap_mt);
770 }
771 [] T.timeout {
772 setverdict(fail, "Timeout waiting for LU reject");
773 }
774 }
775}
776
Harald Weltea49e36e2018-01-21 19:29:33 +0100777function f_foo() runs on BSC_ConnHdlr{
Harald Welte6811d102019-04-14 22:23:14 +0200778 /* SCCP CC handled by RAN_Emulation_CT.main() */
Harald Weltea49e36e2018-01-21 19:29:33 +0100779 /* Expect auth, if enabled */
780
781 /* TODO: ISD */
782 /* Expect encr, if enabled */
783 /* Expect encr, if enabled */
784 /* Expect ASS CMD, if chan_type != requested */
785 /* Send ASS CMPL in successful case */
786
787 /* Expect AoIP port/ip information for RTP stream */
788 /* Expect MSC-originated MGCP to our simulated MGW */
789 /* Verify Counters via CTRL */
790 /* re-configure MSC behaviour via VTY */
791}
792
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200793type record CrcxResponse {
794 integer resp, /* 1 = reply with OK, 0 = do not reply, -1 = reply with error */
795 HostName mgw_rtp_ip,
796 PortNumber mgw_rtp_port,
797 MgcpConnectionId mgcp_connection_id /* MGCP Connection ID BSS Side */
798}
799
Harald Welteb71901a2018-01-26 19:16:05 +0100800/* parameters related to a (MO?) voice call */
801type record CallParameters {
Harald Welteb71901a2018-01-26 19:16:05 +0100802 /* CC related parameters */
803 hexstring called_party, /* whom are we calling */
804 integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100805 boolean mo_call, /* For a MO call, the transaction_id was allocated by the MS,
806 important to set the TI flag properly */
Harald Welteb71901a2018-01-26 19:16:05 +0100807 BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */
Harald Welte0bef21e2018-02-10 09:48:23 +0100808 boolean emergency, /* is this an emergency call? */
Harald Welteb71901a2018-01-26 19:16:05 +0100809
810 /* MNCC related parameters */
811 uint32_t mncc_callref optional, /* call reference on the MNCC side */
812 MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200813 HostName mncc_rtp_ip optional, /* MNCC Side RTP IP */
814 PortNumber mncc_rtp_port optional, /* MNCC Side RTP port */
Harald Welteb71901a2018-01-26 19:16:05 +0100815
816 /* RTP related parameters */
817 HostName bss_rtp_ip optional, /* BSS Side RTP IP */
818 PortNumber bss_rtp_port optional, /* BSS Side RTP Port */
819 HostName mss_rtp_ip optional, /* MSS Side RTP IP */
820 PortNumber mss_rtp_port optional, /* MSS Side RTP Port */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200821 integer got_crcx_count,
822 CrcxResponse mgw_conn_1,
823 CrcxResponse mgw_conn_2,
Harald Welteb71901a2018-01-26 19:16:05 +0100824 uint7_t rtp_payload_type, /* dynamic RTP payload type */
825 charstring rtp_sdp_format, /* AMR/8000 or the like */
Philipp Maier2a98a732018-03-19 16:06:12 +0100826 boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX
827 (f_mt_call and f_mt_call) */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200828 boolean stop_after_cc_setup, /* Special case: stop call establish after CC Setup */
829 boolean ran_clear_when_alerting, /* Special case: send Clear upon CC Alerting */
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100830 boolean expect_release, /* Special case: expect call establish to cause direct CC Rel */
Harald Welteb71901a2018-01-26 19:16:05 +0100831
Philipp Maiercd668572018-03-19 16:11:52 +0100832 MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */
Harald Welteb71901a2018-01-26 19:16:05 +0100833 MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200834
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200835 boolean use_osmux, /* MSC is expected to use Osmux for this call */
836 integer got_osmux_count
Harald Welteb71901a2018-01-26 19:16:05 +0100837}
838
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200839template (value) CallParameters t_CallParams(hexstring called := '12345'H, integer tid := 0) := {
Harald Welteb71901a2018-01-26 19:16:05 +0100840 called_party := called,
841 transaction_id := tid,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100842 mo_call := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100843 bearer_cap := valueof(ts_Bcap_voice),
Harald Welte0bef21e2018-02-10 09:48:23 +0100844 emergency := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100845 mncc_callref := omit,
846 mncc_bearer_cap := valueof(ts_MNCC_bcap_voice),
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200847 mncc_rtp_ip := "42.23.11.5",
848 mncc_rtp_port := 423,
Harald Welte4017d552018-01-26 21:40:05 +0100849 bss_rtp_ip := "9.8.7.6",
850 bss_rtp_port := 9000,
Harald Welteb71901a2018-01-26 19:16:05 +0100851 mss_rtp_ip := omit,
852 mss_rtp_port := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200853 got_crcx_count := 0,
854 mgw_conn_1 := {
855 resp := 1,
856 mgw_rtp_ip := "1.1.1.1",
857 mgw_rtp_port := 10000,
858 mgcp_connection_id := '11111'H
859 },
860 mgw_conn_2 := {
861 resp := 1,
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +0200862 mgw_rtp_ip := "2.2.2.2",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200863 mgw_rtp_port := 11000,
864 mgcp_connection_id := '22222'H
865 },
Harald Welteb71901a2018-01-26 19:16:05 +0100866 rtp_payload_type := 98,
867 rtp_sdp_format := "AMR/8000",
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100868 mgw_drop_dlcx := false,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200869 stop_after_cc_setup := false,
870 ran_clear_when_alerting := false,
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100871 expect_release := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100872 mgcp_call_id := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200873 mgcp_ep := "rtpbridge/1@mgw",
874 use_osmux := false,
875 got_osmux_count := 0
Harald Welteb71901a2018-01-26 19:16:05 +0100876};
877
Harald Welte4263c522018-12-06 11:56:27 +0100878/* Allocate a call reference and send SETUP via MNCC to MSC */
879function f_mt_call_initate(inout CallParameters cpars)
Harald Welte33ec09b2018-02-10 15:34:46 +0100880runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200881 cpars.mo_call := false;
Harald Welte4263c522018-12-06 11:56:27 +0100882 cpars.mncc_callref := f_rnd_int(2147483648);
883 MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
884 hex2str(cpars.called_party), hex2str(g_pars.imsi)));
885}
Harald Welte33ec09b2018-02-10 15:34:46 +0100886
Harald Welte408a7ef2019-04-21 17:08:40 +0200887private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) :=
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200888 ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
Harald Welte408a7ef2019-04-21 17:08:40 +0200889 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200890 cpars.mgw_conn_2.mgw_rtp_port,
Harald Welte408a7ef2019-04-21 17:08:40 +0200891 { int2str(cpars.rtp_payload_type) },
892 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
893 cpars.rtp_sdp_format)),
894 valueof(ts_SDP_ptime(20)) });
895
Harald Welte4263c522018-12-06 11:56:27 +0100896/* Complete call, begin with a paging response message via BSSAP */
897function f_mt_call_complete(inout CallParameters cpars)
898runs on BSC_ConnHdlr {
Harald Welte33ec09b2018-02-10 15:34:46 +0100899 var MNCC_PDU mncc;
900 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200901 var template MgcpResponse mgcp_resp;
902 var MgcpOsmuxCID osmux_cid;
903 var PDU_BSSAP bssap;
Harald Welte33ec09b2018-02-10 15:34:46 +0100904
Harald Welte6811d102019-04-14 22:23:14 +0200905 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Welte33ec09b2018-02-10 15:34:46 +0100906
Harald Welteb9e86fa2018-04-09 18:18:31 +0200907 f_establish_fully(EST_TYPE_PAG_RESP);
Harald Welte33ec09b2018-02-10 15:34:46 +0100908
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100909 log("f_mt_call_complete 1");
910
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200911 cpars.got_osmux_count := 0;
912
Harald Welte33ec09b2018-02-10 15:34:46 +0100913 /* MS <- MSC: Expect CC SETUP */
914 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party)));
915
916 /* MS -> MSC: ALERTING */
917 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id)));
918 MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100919 log("f_mt_call_complete 2");
Harald Welte33ec09b2018-02-10 15:34:46 +0100920
Harald Welte33ec09b2018-02-10 15:34:46 +0100921 /* Create MGCP expect */
922 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
923 /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */
924 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
925
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200926 /* First MGCP CRCX */
Harald Welte33ec09b2018-02-10 15:34:46 +0100927 MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100928 log("f_mt_call_complete 3");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200929 if (not f_handle_crcx(cpars, mgcp_cmd)) {
930 return;
Philipp Maier4b2692d2018-03-14 16:37:48 +0100931 }
Harald Welte33ec09b2018-02-10 15:34:46 +0100932 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +0100933
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +0100934
Harald Welte9b751a62019-04-14 17:39:29 +0200935 if (g_pars.ran_is_geran) {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200936 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200937 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Harald Welte9b751a62019-04-14 17:39:29 +0200938
939 interleave {
940 /* Second MGCP CRCX (this time for MSS/CN side) */
941 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100942 log("f_mt_call_complete 4");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200943 if (not f_handle_crcx(cpars, mgcp_cmd)) {
944 break;
945 }
Harald Welte9b751a62019-04-14 17:39:29 +0200946 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100947
948 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
949 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
950 log("f_mt_call_complete 5");
951 }
952
Harald Welte9b751a62019-04-14 17:39:29 +0200953 /* expect the MSC to trigger a BSSMAP ASSIGNMENT */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200954 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200955 var template BSSMAP_IE_AoIP_TransportLayerAddress tla;
Harald Welte9b751a62019-04-14 17:39:29 +0200956 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200957 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100958 log("f_mt_call_complete 6");
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200959 tla := f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port);
Harald Welte9b751a62019-04-14 17:39:29 +0200960 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
961
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200962 if (cpars.use_osmux) {
963 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
964 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
965 mtc.stop;
966 }
967 osmuxCID := valueof(ts_OsmuxCID(0));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200968 if (not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
969 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 +0200970 mtc.stop;
971 }
972 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
973 } else {
974 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
975 }
976 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100977
978 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
Harald Welte9b751a62019-04-14 17:39:29 +0200979 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100980
981 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
982 log("f_mt_call_complete 7");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200983 var octetstring ip;
984 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
985 if (is_ipv6) {
986 ip := f_inet6_addr(cpars.mncc_rtp_ip);
987 } else {
988 ip := f_inet_addr(cpars.mncc_rtp_ip);
989 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100990 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200991 is_ipv6, ip,
992 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100993 /* payload type 3 = GSM FR */ 3));
994 }
995
996 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
997 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
998 log("f_mt_call_complete 8");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +0200999 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_1.mgw_rtp_ip, cpars.mgw_conn_1.mgw_rtp_ip,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001000 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001001 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001002 { int2str(cpars.rtp_payload_type) },
1003 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1004 cpars.rtp_sdp_format)),
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001005 valueof(ts_SDP_ptime(20)) }));
1006 if (cpars.use_osmux) {
1007 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1008 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1009 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1010 mtc.stop;
1011 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001012 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 +02001013 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001014 mgcp_resp := ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, sdp);
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001015 }
1016 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001017 }
1018
1019 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1020 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001021 var SDP_Message sdp;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001022 log("f_mt_call_complete 9");
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001023
1024 if (isvalue(mgcp_cmd.sdp)) {
1025 sdp := mgcp_cmd.sdp;
1026 if (sdp.media_list[0].media_field.ports.port_number != cpars.mncc_rtp_port) {
1027 setverdict(fail, "Wrong MDCX Connection port received, expected ", cpars.mncc_rtp_port, " and received ", sdp.media_list[0].media_field.ports.port_number)
1028 mtc.stop;
1029 }
1030 if (sdp.connection.conn_addr.addr != cpars.mncc_rtp_ip) {
1031 setverdict(fail, "Wrong MDCX Connection address received, expected ", cpars.mncc_rtp_ip, " and received ", sdp.connection.conn_addr.addr)
1032 mtc.stop;
1033 }
1034 }
1035
1036 sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1037 hex2str(cpars.mgcp_call_id), "42",
1038 cpars.mgw_conn_2.mgw_rtp_port,
1039 { int2str(cpars.rtp_payload_type) },
1040 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1041 cpars.rtp_sdp_format)),
1042 valueof(ts_SDP_ptime(20)) }));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001043 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 +01001044 }
1045
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001046 }
Harald Welte9b751a62019-04-14 17:39:29 +02001047 } else {
Harald Welte9b751a62019-04-14 17:39:29 +02001048 interleave {
1049 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001050 log("f_mt_call_complete 4.iu");
1051 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1052 break;
Harald Welte9b751a62019-04-14 17:39:29 +02001053 }
Harald Welte9b751a62019-04-14 17:39:29 +02001054 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001055
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001056 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1057 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1058 log("f_mt_call_complete 5.iu");
1059 }
1060
1061 [] BSSAP.receive(tr_RANAP_RabAssReq(?)) {
1062 log("f_mt_call_complete 6.iu");
1063 var RAB_SetupOrModifiedList l := {
1064 {
1065 {
1066 id := id_RAB_SetupOrModifiedItem,
1067 criticality := ignore,
1068 value_ := {
1069 rAB_SetupOrModifiedItem := {
1070 rAB_ID := int2bit(23, 8),
1071 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1072 iuTransportAssociation := {
1073 bindingID := '040c0000'O
1074 },
1075 dl_dataVolumes := omit,
1076 iE_Extensions := omit
1077 }
1078 }
1079 }
1080 }
1081 };
1082 BSSAP.send(ts_RANAP_RabAssResp(l));
1083
1084 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
1085 }
1086
1087 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1088 log("f_mt_call_complete 7.iu");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001089 var octetstring ip;
1090 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1091 if (is_ipv6) {
1092 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1093 } else {
1094 ip := f_inet_addr(cpars.mncc_rtp_ip);
1095 }
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001096 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001097 is_ipv6, ip,
1098 cpars.mncc_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001099 /* payload type 3 = GSM FR */ 3));
1100 }
1101
1102 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1103 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1104 log("f_mt_call_complete 8.iu");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001105 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_1.mgw_rtp_ip, cpars.mgw_conn_1.mgw_rtp_ip,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001106 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001107 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001108 { int2str(cpars.rtp_payload_type) },
1109 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1110 cpars.rtp_sdp_format)),
1111 valueof(ts_SDP_ptime(20)) }));
1112 if (cpars.use_osmux) {
1113 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1114 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1115 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1116 mtc.stop;
1117 }
1118 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
1119 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001120 mgcp_resp := ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, sdp);
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001121 }
1122 MGCP.send(mgcp_resp);
1123 }
1124
1125 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1126 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1127 log("f_mt_call_complete 9.iu");
1128 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1129 hex2str(cpars.mgcp_call_id), "42",
1130 cpars.mgw_conn_2.mgw_rtp_port,
1131 { int2str(cpars.rtp_payload_type) },
1132 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1133 cpars.rtp_sdp_format)),
1134 valueof(ts_SDP_ptime(20)) }));
1135 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
1136 }
1137
Harald Welte33ec09b2018-02-10 15:34:46 +01001138 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001139 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001140
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001141 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1142 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1143 } else {
1144 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1145 mtc.stop;
1146 }
1147
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001148 log("f_mt_call_complete DONE");
Harald Welte4263c522018-12-06 11:56:27 +01001149}
1150
Harald Weltee035e3e2019-04-21 17:32:05 +02001151function f_expect_paging(boolean by_tmsi := true)
1152runs on BSC_ConnHdlr {
Harald Welte9b751a62019-04-14 17:39:29 +02001153 if (g_pars.ran_is_geran) {
1154 BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
1155 } else {
Harald Welte62113fc2019-05-09 13:04:02 +02001156 BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi)));
Harald Welte9b751a62019-04-14 17:39:29 +02001157 }
Harald Weltee035e3e2019-04-21 17:32:05 +02001158}
1159
Harald Welte4263c522018-12-06 11:56:27 +01001160function f_mt_call_establish(inout CallParameters cpars)
1161runs on BSC_ConnHdlr {
1162
1163 /* Initiate the call via MNCC */
1164 f_mt_call_initate(cpars);
1165
1166 /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
Harald Welte6811d102019-04-14 22:23:14 +02001167 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Weltee035e3e2019-04-21 17:32:05 +02001168 f_expect_paging()
Harald Welte4263c522018-12-06 11:56:27 +01001169
1170 /* Complete the call via BSSAP */
1171 f_mt_call_complete(cpars);
Harald Welte33ec09b2018-02-10 15:34:46 +01001172
Harald Welte33ec09b2018-02-10 15:34:46 +01001173 setverdict(pass);
1174}
1175
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001176/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1177 * Return true when an OK reply was sent, false otherwise.
1178 * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */
1179function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd)
1180runs on BSC_ConnHdlr
1181return boolean {
1182 var CrcxResponse conn := cpars.mgw_conn_1;
1183 if (cpars.got_crcx_count > 0) {
1184 conn := cpars.mgw_conn_2;
1185 }
1186 cpars.got_crcx_count := cpars.got_crcx_count + 1;
1187
1188 var MgcpMessage mgcp_msg := {
1189 command := mgcp_cmd
1190 }
1191 var template MgcpResponse mgcp_resp;
1192 var MgcpOsmuxCID osmux_cid;
1193 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1194 if (ispresent(cpars.mgcp_call_id)) {
1195 if (cpars.mgcp_call_id != call_id) {
1196 setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id);
1197 mtc.stop;
1198 }
1199 } else {
1200 cpars.mgcp_call_id := call_id;
1201 }
1202
1203 /* When the endpoint contains a wildcard we keep the endpoint
1204 * identifier we have set up in cpars. Otherwise we use the
1205 * endpoint name that the call agent has supplied */
1206 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1207 cpars.mgcp_ep := mgcp_cmd.line.ep;
1208 }
1209
1210 if (conn.resp == -1) {
1211 /* Reply with error */
1212 var MgcpResponse mgcp_rsp := {
1213 line := {
1214 code := "542",
1215 trans_id := mgcp_cmd.line.trans_id,
1216 string := "FORCED_FAIL"
1217 },
1218 sdp := omit
1219
1220 }
1221 var MgcpParameter mgcp_rsp_param := {
1222 code := "Z",
1223 val := cpars.mgcp_ep
1224 };
1225 mgcp_rsp.params[0] := mgcp_rsp_param;
1226 MGCP.send(mgcp_rsp);
1227 return false;
1228 }
1229
1230 if (conn.resp == 0) {
1231 /* Do not reply at all */
1232 return false;
1233 }
1234
1235 if (conn.resp != 1) {
1236 setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1");
1237 mtc.stop;
1238 }
1239
1240 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1241 hex2str(cpars.mgcp_call_id), "42",
1242 conn.mgw_rtp_port,
1243 { int2str(cpars.rtp_payload_type) },
1244 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1245 cpars.rtp_sdp_format)),
1246 valueof(ts_SDP_ptime(20)) }));
1247
1248 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1249 if (not cpars.use_osmux) {
1250 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1251 mtc.stop;
1252 }
1253 cpars.got_osmux_count := cpars.got_osmux_count + 1;
1254 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1255 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1256 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1257 if (osmux_cid != -1) {
1258 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1259 mtc.stop;
1260 }
1261
1262 osmux_cid := 0;
1263 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1264 } else {
1265 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1266 }
1267
1268 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep));
1269 MGCP.send(mgcp_resp);
1270 return true;
1271}
1272
1273
1274altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr {
1275 var MgcpCommand mgcp_cmd;
1276 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1277 log("as_optional_mgcp_crcx: rx CRCX");
1278 f_handle_crcx(cpars, mgcp_cmd);
1279
1280 /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an
1281 * CRCX is handled. */
1282 repeat;
1283 }
1284}
1285
1286private altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr {
1287 var MgcpCommand mgcp_cmd;
1288 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1289 log("as_optional_mgcp_mdcx: rx MDCX");
1290 log(mgcp_cmd);
1291 var charstring conn_id;
1292 var charstring rtp_payload_type;
1293 f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id);
1294 rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0];
1295
1296 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip,
1297 mgcp_cmd.sdp.origin.session_id, "42",
1298 mgw_rtp_port,
1299 { rtp_payload_type },
1300 { valueof(ts_SDP_ptime(20)) }));
1301 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp));
1302
1303 /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is
1304 * handled. */
1305 repeat;
1306 }
1307}
1308
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001309private altstep as_optional_mgcp_dlcx(CallParameters cpars) runs on BSC_ConnHdlr {
1310 var MgcpCommand mgcp_cmd;
1311 var boolean respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1312 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1313 log("as_optional_mgcp_dlcx: rx MGCP DLCX");
1314 if (respond_to_dlcx) {
1315 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1316 }
1317 /* Without this 'repeat', currently active other interleave and alt series exit as soon as a
1318 * DLCX is handled. */
1319 repeat;
1320 }
1321}
1322
Philipp Maier3716a5e2018-03-21 15:53:35 +01001323function f_mo_call_establish(inout CallParameters cpars)
Harald Welteb71901a2018-01-26 19:16:05 +01001324runs on BSC_ConnHdlr {
1325
Harald Welteb71901a2018-01-26 19:16:05 +01001326 var MNCC_PDU mncc;
1327 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001328 var template MgcpResponse mgcp_resp;
Philipp Maier2a98a732018-03-19 16:06:12 +01001329 var boolean respond_to_dlcx;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001330 var PDU_BSSAP bssap;
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001331 var RANAP_PDU ranap;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001332 var MgcpOsmuxCID osmux_cid;
Harald Welteb71901a2018-01-26 19:16:05 +01001333
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001334 cpars.mo_call := true;
1335
Harald Welte0bef21e2018-02-10 09:48:23 +01001336 if (cpars.emergency) {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001337 f_establish_fully(EST_TYPE_EMERG_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001338 } else {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001339 f_establish_fully(EST_TYPE_MO_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001340 }
Harald Welteb71901a2018-01-26 19:16:05 +01001341
1342 /* Create MNCC and MGCP expect */
1343 f_create_mncc_expect(hex2str(cpars.called_party));
1344 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1345
Harald Welte0bef21e2018-02-10 09:48:23 +01001346 if (cpars.emergency) {
1347 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id)));
1348 } else {
1349 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party)));
1350 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001351
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001352 if (cpars.stop_after_cc_setup) {
1353 return;
1354 }
1355
1356 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001357 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001358
1359 var default mdcx := activate(as_optional_mgcp_mdcx(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_port));
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001360 var boolean got_mncc_setup_compl_ind := false;
1361 var boolean got_cc_connect := false;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001362
Harald Welteb71901a2018-01-26 19:16:05 +01001363 interleave {
1364 [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001365 log("f_mo_call_establish 1: rx MNCC SETUP ind");
Harald Welteb71901a2018-01-26 19:16:05 +01001366 cpars.mncc_callref := mncc.u.signal.callref;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001367 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1368 }
1369
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001370 /* First MGCP CRCX */
Harald Welteb71901a2018-01-26 19:16:05 +01001371 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001372 log("f_mo_call_establish 2: rx 1st CRCX");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001373 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1374 break;
1375 }
Philipp Maierf1e02bb2018-03-15 16:30:00 +01001376 }
1377
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001378 /* Second MGCP CRCX */
1379 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
1380 log("f_mo_call_establish 6: rx 2nd CRCX");
1381 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1382 break;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001383 }
Harald Welteb71901a2018-01-26 19:16:05 +01001384 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001385
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001386 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1387 log("f_mo_call_establish 3: rx RTP CREATE");
1388 /* Call Proceeding */
1389 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1390 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001391
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001392 /* Alerting */
1393 MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref));
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001394 }
Harald Welte9b751a62019-04-14 17:39:29 +02001395
Neels Hofmeyreccaa992019-10-15 16:42:21 +02001396 //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001397 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001398 log("f_mo_call_establish 4: rx Assignment Request");
1399 var BSSMAP_IE_AoIP_TransportLayerAddress tla;
1400 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001401 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
1402
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001403 if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass)) {
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001404 log("Expected:", tla_ass);
1405 log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer);
1406 setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE");
1407 mtc.stop;
1408 }
1409
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001410 tla := valueof(f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001411 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001412 if (cpars.use_osmux) {
1413 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1414 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1415 mtc.stop;
1416 }
1417 osmuxCID := valueof(ts_OsmuxCID(0));
1418 if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1419 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1420 mtc.stop;
1421 }
1422 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1423 } else {
1424 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1425 }
1426 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001427 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001428 [] BSSAP.receive(tr_RANAP_RabAssReq(*)) -> value ranap {
1429 log("f_mo_call_establish 4.iu: rx RANAP RAB Assignment Request");
1430 var RAB_SetupOrModifiedList l := {
1431 {
1432 {
1433 id := id_RAB_SetupOrModifiedItem,
1434 criticality := ignore,
1435 value_ := {
1436 rAB_SetupOrModifiedItem := {
1437 rAB_ID := int2bit(23, 8),
1438 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1439 iuTransportAssociation := {
1440 bindingID := '040c0000'O
1441 },
1442 dl_dataVolumes := omit,
1443 iE_Extensions := omit
1444 }
1445 }
1446 }
1447 }
1448 };
1449 BSSAP.send(ts_RANAP_RabAssResp(l));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001450 }
Harald Welte9b751a62019-04-14 17:39:29 +02001451
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001452 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1453 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1454 log("f_mo_call_establish 5: rx MDCX for the RAN side");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001455 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_1.mgw_rtp_ip, cpars.mgw_conn_1.mgw_rtp_ip,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001456 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001457 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001458 { int2str(cpars.rtp_payload_type) },
1459 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1460 cpars.rtp_sdp_format)),
1461 valueof(ts_SDP_ptime(20)) }));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001462
1463 if (cpars.use_osmux) {
1464 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1465 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1466 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1467 mtc.stop;
1468 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001469 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 +02001470 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001471 mgcp_resp := ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, sdp);
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001472 }
1473 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001474 }
Harald Welte9b751a62019-04-14 17:39:29 +02001475
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001476 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {
1477 log("f_mo_call_establish 7: rx CC Alerting");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001478
1479 if (cpars.ran_clear_when_alerting) {
1480 if (g_pars.ran_is_geran) {
1481 BSSAP.send(ts_BSSMAP_ClearRequest(0));
1482 } else {
1483 BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention));
1484 }
1485 break;
1486 }
1487
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001488 cpars.mncc_callref := mncc.u.signal.callref;
1489 /* Call Proceeding */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001490 var octetstring ip;
1491 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1492 if (is_ipv6) {
1493 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1494 } else {
1495 ip := f_inet_addr(cpars.mncc_rtp_ip);
1496 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001497 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001498 is_ipv6, ip,
1499 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001500 /* payload type 3 = GSM FR */ 3));
1501 MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref));
1502 }
1503
1504 [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc {
1505 log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001506 got_mncc_setup_compl_ind := true;
1507 if (not cpars.expect_release and got_cc_connect) {
1508 break;
1509 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001510 }
1511
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001512 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) {
1513 log("f_mo_call_establish 10: rx CC CONNECT");
1514 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id)));
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001515 got_cc_connect := true;
1516 if (not cpars.expect_release and got_mncc_setup_compl_ind) {
1517 break;
1518 }
Harald Welteb71901a2018-01-26 19:16:05 +01001519 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001520
1521 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1522 log("f_mo_call_establish 11: rx CC RELEASE");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001523 if (not cpars.expect_release) {
1524 setverdict(fail, "Got unexpected CC Release");
1525 mtc.stop;
1526 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001527 f_expect_clear();
1528 break;
1529 }
1530 }
1531
1532 f_sleep(0.5);
1533 deactivate(mdcx);
1534
1535 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1536 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1537 } else {
1538 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1539 mtc.stop;
Harald Welteb71901a2018-01-26 19:16:05 +01001540 }
1541
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001542 log("f_mo_call_establish DONE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001543 setverdict(pass);
1544}
Harald Welteb71901a2018-01-26 19:16:05 +01001545
Harald Welte4c422b72019-02-17 16:27:10 +01001546function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001547runs on BSC_ConnHdlr {
1548
1549 var MobileIdentityLV mi;
1550 var MNCC_PDU mncc;
1551 var MgcpCommand mgcp_cmd;
1552 var boolean respond_to_dlcx;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001553 var boolean dlcx_contained_ci := false;
1554 var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand;
1555
1556 if (is_csfb) {
1557 t_clear := tr_BSSMAP_ClearCommandCSFB;
1558 }
1559
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001560 log("f_call_hangup 0: tx MNCC_DISC_REQ");
Harald Welteb71901a2018-01-26 19:16:05 +01001561 MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1562 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1563
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001564 log("f_call_hangup 1: rx DTAP CC DISC");
1565
Philipp Maier3716a5e2018-03-21 15:53:35 +01001566 if (release_by_ms) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001567 var BIT1 tid_remote := '1'B;
1568 if (cpars.mo_call) {
1569 tid_remote := '0'B;
1570 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001571 /* B-side (MS) Release of call */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001572 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 +01001573 MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001574 log("f_call_hangup 2: rx MNCC REL ind");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001575 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001576 log("f_call_hangup 3: rx DTAP CC REL COMPL");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001577 } else {
1578 /* A-side (PLMN) Release of call */
1579 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42))));
1580 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001581 log("f_call_hangup 4: rx DTAP CC RELEASE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001582 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
1583 }
Harald Welteb71901a2018-01-26 19:16:05 +01001584
Philipp Maier2a98a732018-03-19 16:06:12 +01001585 respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1586
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001587 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 +01001588 var default dlcx := activate(as_optional_mgcp_dlcx(cpars));
Harald Welte9b751a62019-04-14 17:39:29 +02001589
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001590 /* clearing of radio channel */
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001591 alt {
1592 [g_pars.ran_is_geran] BSSAP.receive(t_clear) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001593 log("f_call_hangup 5: rx BSSAP Clear Command");
1594 BSSAP.send(ts_BSSMAP_ClearComplete);
1595 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1596 log("f_call_hangup 6: rx SCCP DISC");
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001597 setverdict(pass);
Philipp Maier2a98a732018-03-19 16:06:12 +01001598 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001599 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) {
1600 log("f_call_hangup 5.iu: rx Iu Release Command");
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001601 BSSAP.send(ts_RANAP_IuReleaseComplete);
1602 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001603 log("f_call_hangup 6.iu: rx SCCP DISC");
1604 setverdict(pass);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001605 }
1606 }
1607
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001608 f_sleep(1.0);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001609 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1610 log("f_call_hangup 9: done");
1611
1612 deactivate(mdcx);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001613 deactivate(dlcx);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001614}
1615
1616function f_mt_call(inout CallParameters cpars)
1617runs on BSC_ConnHdlr {
1618
1619 f_mt_call_establish(cpars);
1620
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001621 log("Hold the call for some time");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001622 f_sleep(3.0);
1623
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001624 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001625 f_call_hangup(cpars, true);
1626
1627 setverdict(pass);
1628}
1629
1630function f_mo_call(inout CallParameters cpars)
1631runs on BSC_ConnHdlr {
1632
1633 f_mo_call_establish(cpars);
1634
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001635 log("Hold the call for some time");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001636 f_sleep(3.0);
1637
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001638 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001639 f_call_hangup(cpars, false);
1640
Harald Welteb71901a2018-01-26 19:16:05 +01001641 setverdict(pass);
1642}
Harald Weltea49e36e2018-01-21 19:29:33 +01001643
Daniel Willmann8b084372018-02-04 13:35:26 +01001644function f_mo_seq_dtmf_dup(inout CallParameters cpars)
1645runs on BSC_ConnHdlr {
1646
1647 timer T := 1.0;
Daniel Willmann8b084372018-02-04 13:35:26 +01001648 var MNCC_PDU mncc;
1649 var MgcpCommand mgcp_cmd;
1650 var template PDU_ML3_MS_NW dtmf_dtap;
1651
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001652 f_mo_call_establish(cpars);
Daniel Willmann8b084372018-02-04 13:35:26 +01001653
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001654 /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by
1655 * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001656
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001657 /* Find out the next NSD that will be used, from RAN emulation. */
1658 var N_Sd_Array last_n_sd := f_bssmap_last_n_sd();
1659 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 +01001660
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001661 /* Compose DTAP with this correct NSD */
Daniel Willmann8b084372018-02-04 13:35:26 +01001662 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001663
1664 /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */
1665 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001666 T.start;
1667 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001668 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
1669 log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind");
1670 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001671 [] T.timeout {
1672 setverdict(fail, "Timeout waiting for START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001673 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001674 }
1675 }
1676
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001677 /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message
1678 * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */
1679 dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2);
Daniel Willmann92f66272018-02-06 15:50:52 +01001680 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true));
Daniel Willmann8b084372018-02-04 13:35:26 +01001681 T.start;
1682 alt {
1683 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001684 setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001685 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001686 }
1687 [] T.timeout { }
1688 }
1689
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001690 /* Here the NSD should be correct again and we see a DTMF. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001691 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001692 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001693 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001694 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) {
1695 log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind");
1696 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001697 [] T.timeout {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001698 setverdict(fail, "Timeout waiting for final START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001699 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001700 }
1701 }
1702
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001703 f_call_hangup(cpars, true);
Daniel Willmann8b084372018-02-04 13:35:26 +01001704 setverdict(pass);
1705}
Harald Welte9b751a62019-04-14 17:39:29 +02001706
Harald Welte1ddc7162018-01-27 14:25:46 +01001707/* expect a clear command */
Harald Welte5946b332018-03-18 23:32:21 +01001708altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr {
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001709 var PDU_BSSAP bssap;
Harald Welte5946b332018-03-18 23:32:21 +01001710 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1711 BSSAP.send(ts_BSSMAP_ClearComplete);
1712 alt {
Harald Welte6811d102019-04-14 22:23:14 +02001713 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte5946b332018-03-18 23:32:21 +01001714 setverdict(pass);
1715 }
1716 [] BSSAP.receive {
1717 setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001718 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001719 }
1720 }
1721 }
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001722 [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap {
1723 setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001724 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001725 }
1726}
1727
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001728function f_expect_clear(float t := 5.0, boolean verify_vlr_cell_id := true) runs on BSC_ConnHdlr {
Harald Welte1ddc7162018-01-27 14:25:46 +01001729 timer T := t;
1730
1731 T.start;
1732 alt {
Harald Welte9b751a62019-04-14 17:39:29 +02001733 [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { }
1734 [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { }
Harald Welte1ddc7162018-01-27 14:25:46 +01001735 [] T.timeout {
Harald Welte5946b332018-03-18 23:32:21 +01001736 setverdict(fail, "Timeout waiting for ClearCommand/Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001737 mtc.stop;
Harald Welte1ddc7162018-01-27 14:25:46 +01001738 }
1739 }
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001740
1741 if (verify_vlr_cell_id) {
1742 /* Now the conn is gone, but the VLR reflects the cell ID */
1743 f_verify_vty_lac_ci();
1744 }
Harald Welte1ddc7162018-01-27 14:25:46 +01001745}
1746
Neels Hofmeyr0ac63152019-05-07 01:20:17 +02001747function f_create_bssmap_exp_handoverRequest(integer targetPointCode) runs on BSC_ConnHdlr {
1748 BSSAP_PROC.call(RAN_register_handoverRequest:{targetPointCode, self}) {
1749 [] BSSAP_PROC.getreply(RAN_register_handoverRequest:{?, ?}) {};
1750 }
1751}
1752
1753function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array {
1754 var N_Sd_Array last_n_sd;
1755 BSSAP_PROC.call(RAN_last_n_sd:{self, -}) {
1756 [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) {
1757 return last_n_sd;
1758 };
1759 }
1760}
1761
1762function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr {
1763 BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) {
1764 [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self});
1765 }
1766}
1767
Harald Weltef45efeb2018-04-09 18:19:24 +02001768type record SmsParametersTp {
1769 OCT1 msg_ref,
1770 TP_DA da,
1771 OCT1 pid,
1772 OCT1 dcs,
1773 integer udl,
1774 octetstring ud
1775}
1776type record SmsParametersRp {
1777 OCT1 msg_ref,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001778 RP_NumberingPlan_and_NumberDigits smsc_addr optional
Harald Weltef45efeb2018-04-09 18:19:24 +02001779}
1780type record SmsParameters {
1781 SmsParametersTp tp,
1782 SmsParametersRp rp,
1783 uint3_t tid,
1784 OCT1 dlci,
1785 uint7_t exp_rp_err optional
1786}
1787
1788template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := {
1789 tP_DA_NoPad := {
1790 tP_LengthIndicator := 0, /* overwritten */
1791 tP_NumberingPlanID := npl,
1792 tP_TypeOfNumber := ton,
1793 tp_Spare := '0'B,
1794 tP_DAValue := addr
1795 }
1796}
1797
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001798template RP_NumberingPlan_and_NumberDigits t_RP_Addr(template hexstring addr,
1799 template BIT4 npi := '0001'B,
1800 template BIT3 ton := '001'B,
1801 template BIT1 ext := '1'B) := {
1802 rP_NumberingPlanIdentification := npi,
1803 rP_TypeOfNumber := ton,
1804 rP_Ext := ext,
1805 rP_NumberDigits := addr
1806}
1807
Harald Weltef45efeb2018-04-09 18:19:24 +02001808template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := {
1809 tp := {
1810 msg_ref := '23'O,
1811 da := ts_TP_DA('0000'B, '000'B, tp_daddr),
1812 pid := '00'O,
1813 dcs := '00'O,
1814 udl := 0,
1815 ud := ''O
1816 },
1817 rp := {
1818 msg_ref := '42'O,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001819 /* We don't really need to have both SM-RP-DA/OA here, because only one IE
Vadim Yanitskiyafb15a82020-01-05 14:04:53 +01001820 * is included in MO/MT SMS, and in the most cases it's the SMSC address.
1821 * NOTE: this address is currently hard-coded by OsmoMSC. */
1822 smsc_addr := t_RP_Addr('447785016005'H)
Harald Weltef45efeb2018-04-09 18:19:24 +02001823 },
1824 tid := 0,
1825 dlci := '03'O,
1826 exp_rp_err := omit
1827}
1828
1829private altstep as_other_sms() runs on BSC_ConnHdlr {
1830 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) {
1831 setverdict(fail, "Unexpected SMS related PDU from MSC");
Daniel Willmannafce8662018-07-06 23:11:32 +02001832 mtc.stop;
Harald Weltef45efeb2018-04-09 18:19:24 +02001833 }
1834}
1835
Vadim Yanitskiy9cc019a2018-11-15 02:06:07 +07001836/* Submit a MO RP-SMMA over an already existing DTAP connection */
1837function f_mo_smma(inout SmsParameters spars)
1838runs on BSC_ConnHdlr {
1839 var template (value) RPDU_MS_SGSN rp_mo;
1840 var template (value) PDU_ML3_MS_NW l3_mo;
1841
1842 var default d := activate(as_other_sms());
1843
1844 /* just in case this is routed to SMPP.. */
1845 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1846
1847 rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref);
1848 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1849 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1850 /* receive CP-ACK for CP-DATA above */
1851 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1852
1853 deactivate(d);
1854 setverdict(pass);
1855}
1856
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001857/* Submit a MO-SMS over an already existing DTAP connection */
1858function f_mo_sms_submit(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02001859runs on BSC_ConnHdlr {
1860 var template (value) TPDU_RP_DATA_MS_SGSN tp_mo;
1861 var template (value) RPDU_MS_SGSN rp_mo;
1862 var template (value) PDU_ML3_MS_NW l3_mo;
1863
Harald Weltef45efeb2018-04-09 18:19:24 +02001864 var default d := activate(as_other_sms());
1865
Harald Weltef640a012018-04-14 17:49:21 +02001866 /* just in case this is routed to SMPP.. */
1867 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1868
Harald Weltef45efeb2018-04-09 18:19:24 +02001869 tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs,
1870 spars.tp.udl, spars.tp.ud);
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001871 rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, omit, spars.rp.smsc_addr, tp_mo);
Harald Weltef45efeb2018-04-09 18:19:24 +02001872 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1873 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1874 /* receive CP-ACK for CP-DATA above */
1875 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1876
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001877 deactivate(d);
1878 setverdict(pass);
1879}
1880
1881/* Wait RP-ACK for MO-SMS on an already existing DTAP connection */
1882function f_mo_sms_wait_rp_ack(inout SmsParameters spars)
1883runs on BSC_ConnHdlr {
1884 var template (value) PDU_ML3_MS_NW l3_mo;
1885
1886 var template TPDU_RP_DATA_SGSN_MS tp_mt;
1887 var template RPDU_SGSN_MS rp_mt;
1888 var template PDU_ML3_NW_MS l3_mt;
1889
1890 var default d := activate(as_other_sms());
1891
1892 /* just in case this is routed to SMPP.. */
1893 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1894
Harald Weltef45efeb2018-04-09 18:19:24 +02001895 if (ispresent(spars.exp_rp_err)) {
1896 /* expect an RP-ERROR message from MSC with given cause */
1897 rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err);
1898 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1899 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1900 /* send CP-ACK for CP-DATA just received */
1901 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1902 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1903 } else {
1904 /* expect RP-ACK for RP-DATA */
1905 rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref);
1906 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1907 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1908 /* send CP-ACO for CP-DATA just received */
1909 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1910 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1911 }
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001912
Harald Weltef45efeb2018-04-09 18:19:24 +02001913 deactivate(d);
1914 setverdict(pass);
1915}
1916
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001917/* Submit a MO-SMS, and wait for RP-ACK on an existing
1918 * (and authenticated, ...) DTAP connection */
1919function f_mo_sms(inout SmsParameters spars)
1920runs on BSC_ConnHdlr {
1921 f_mo_sms_submit(spars);
1922 f_mo_sms_wait_rp_ack(spars);
1923}
1924
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01001925function f_mt_sms_deliver_pdu(in SmsParameters spars)
1926runs on BSC_ConnHdlr
1927return template PDU_DTAP_MT {
1928 var template TPDU_RP_DATA_SGSN_MS tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?);
1929 var template RPDU_SGSN_MS rp_mt := tr_RP_DATA_MT(?, spars.rp.smsc_addr, omit, tp_mt);
1930 var template PDU_ML3_NW_MS l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt));
1931 return tr_PDU_DTAP_MT(l3_mt, spars.dlci);
1932}
1933
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001934/* Wait for MT SMS on an already existing DTAP connection */
1935function f_mt_sms_expect(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02001936runs on BSC_ConnHdlr {
Harald Weltef45efeb2018-04-09 18:19:24 +02001937 var template (value) PDU_ML3_MS_NW l3_mo;
Harald Weltef45efeb2018-04-09 18:19:24 +02001938 var PDU_DTAP_MT dtap_mt;
1939
1940 var default d := activate(as_other_sms());
1941
1942 /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01001943 BSSAP.receive(f_mt_sms_deliver_pdu(spars)) -> value dtap_mt;
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001944
Harald Weltef45efeb2018-04-09 18:19:24 +02001945 /* Extract relevant identifiers */
1946 spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio);
1947 spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference;
1948
1949 /* send CP-ACK for CP-DATA just received */
1950 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO);
1951 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1952
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001953 deactivate(d);
1954 setverdict(pass);
1955}
1956
1957/* Send RP-ACK for MT-SMS over an already existing DTAP connection */
1958function f_mt_sms_send_rp_ack(inout SmsParameters spars)
1959runs on BSC_ConnHdlr {
1960 var template (value) RPDU_MS_SGSN rp_mo;
1961 var template (value) PDU_ML3_MS_NW l3_mo;
1962 var template PDU_ML3_NW_MS l3_mt;
1963
1964 var default d := activate(as_other_sms());
1965
Harald Weltef45efeb2018-04-09 18:19:24 +02001966 /* send RP-ACK for RP-DATA */
1967 rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref);
1968 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
1969 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1970
1971 /* expect CP-ACK for CP-DATA(RP-ACK) just sent */
Harald Weltee008eea2018-04-14 21:05:48 +02001972 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
Harald Weltef45efeb2018-04-09 18:19:24 +02001973 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1974
1975 deactivate(d);
1976 setverdict(pass);
1977}
1978
Vadim Yanitskiy56318522018-11-24 03:40:47 +07001979/* Send RP-ERROR for MT-SMS over an already existing DTAP connection */
1980function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause)
1981runs on BSC_ConnHdlr {
1982 var template (value) RPDU_MS_SGSN rp_mo;
1983 var template (value) PDU_ML3_MS_NW l3_mo;
1984 var template PDU_ML3_NW_MS l3_mt;
1985
1986 var default d := activate(as_other_sms());
1987
1988 /* send RP-ACK for RP-DATA */
1989 rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause);
1990 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
1991 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1992
1993 /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */
1994 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
1995 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1996
1997 deactivate(d);
1998 setverdict(pass);
1999}
2000
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002001/* Wait for a MT-SMS and send RP-ACK over an already existing
2002 * (and authenticated, ...) DTAP connection */
2003function f_mt_sms(inout SmsParameters spars)
2004runs on BSC_ConnHdlr {
2005 f_mt_sms_expect(spars);
2006 f_mt_sms_send_rp_ack(spars);
2007}
Harald Weltea49e36e2018-01-21 19:29:33 +01002008
2009
Harald Weltea49e36e2018-01-21 19:29:33 +01002010}