blob: 8eb3f7334ce55cb2c0daf818a5677c5e9193c7f2 [file] [log] [blame]
Harald Welte34b5a952019-05-27 11:54:11 +02001/* BSC Connection Handler of MSC test suite in TTCN-3
2 * (C) 2018-2019 Harald Welte <laforge@gnumonks.org>
3 * (C) 2018-2019 sysmocom - s.f.m.c. GmbH
4 * (C) 2018 Vadim Yanitskiy <axilirator@gmail.com>
5 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
Harald Weltea49e36e2018-01-21 19:29:33 +010013module BSC_ConnectionHandler {
14
Eric Wild26f4a622021-05-17 15:27:05 +020015import from TCCOpenSecurity_Functions all;
Harald Weltea49e36e2018-01-21 19:29:33 +010016import from General_Types all;
17import from Osmocom_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010018import from Native_Functions all;
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +020019import from Misc_Helpers all;
Harald Weltea49e36e2018-01-21 19:29:33 +010020import from GSM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010021import from IPL4asp_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010022import from SCCPasp_Types all;
23import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020024import from RAN_Emulation all;
Harald Weltea49e36e2018-01-21 19:29:33 +010025import from BSSMAP_Templates all;
26
Harald Welte9b751a62019-04-14 17:39:29 +020027import from RANAP_Constants all;
28import from RANAP_IEs all;
29import from RANAP_PDU_Contents all;
30import from RANAP_PDU_Descriptions all;
31import from RANAP_Templates all;
32
Harald Weltea49e36e2018-01-21 19:29:33 +010033import from GSUP_Types all;
34import from GSUP_Emulation all;
35
36import from MNCC_Types all;
37import from MNCC_Emulation all;
38
Harald Welte4aa970c2018-01-26 10:38:09 +010039import from MGCP_Types all;
40import from MGCP_Emulation all;
Harald Welteb71901a2018-01-26 19:16:05 +010041import from MGCP_Templates all;
42import from SDP_Types all;
Harald Welte4aa970c2018-01-26 10:38:09 +010043
Harald Weltea49e36e2018-01-21 19:29:33 +010044import from MobileL3_Types all;
45import from MobileL3_CommonIE_Types all;
46import from MobileL3_MM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010047import from MobileL3_CC_Types all;
Harald Weltef45efeb2018-04-09 18:19:24 +020048import from MobileL3_SMS_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010049import from L3_Templates all;
Harald Welte158a7ca2018-02-16 18:11:31 +010050import from L3_Common all;
Harald Weltea49e36e2018-01-21 19:29:33 +010051
Harald Weltef640a012018-04-14 17:49:21 +020052import from SMPP_Emulation all;
53
Philipp Maieraeb29a82018-11-08 17:40:53 +010054import from IPA_Emulation all;
55import from Osmocom_CTRL_Functions all;
56import from Osmocom_CTRL_Types all;
57import from Osmocom_CTRL_Adapter all;
58
Philipp Maierc39a9d82018-11-09 11:21:08 +010059import from TELNETasp_PortType all;
60import from Osmocom_VTY_Functions all;
61
Harald Welte4263c522018-12-06 11:56:27 +010062import from SGsAP_Emulation all;
63
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +020064import from TCCConversion_Functions { function f_strstr };
65
Harald Weltea49e36e2018-01-21 19:29:33 +010066/* this component represents a single subscriber connection */
Harald Welte6811d102019-04-14 22:23:14 +020067type component BSC_ConnHdlr extends RAN_ConnHdlr, MNCC_ConnHdlr, GSUP_ConnHdlr, MGCP_ConnHdlr, SMPP_ConnHdlr, CTRL_Adapter_CT, SGsAP_ConnHdlr {
Harald Weltea49e36e2018-01-21 19:29:33 +010068 var BSC_ConnHdlrPars g_pars;
Harald Weltea10db902018-01-27 12:44:49 +010069 timer g_Tguard := 60.0;
Philipp Maierc39a9d82018-11-09 11:21:08 +010070 port TELNETasp_PT MSCVTY;
Harald Weltea49e36e2018-01-21 19:29:33 +010071}
72
Harald Weltede371492018-01-27 23:44:41 +010073type record BSC_ConnHdlrNetworkPars {
74 OCT1 kc_support,
75 boolean expect_tmsi,
76 boolean expect_auth,
Oliver Smith1d118ff2019-07-03 10:57:35 +020077 boolean expect_ciph,
78 boolean expect_imei,
79 boolean expect_imei_early,
80 GSUP_IMEIResult check_imei_result,
81 boolean check_imei_error
Harald Weltede371492018-01-27 23:44:41 +010082}
83
Harald Weltea49e36e2018-01-21 19:29:33 +010084type record BSC_ConnHdlrPars {
85 SCCP_PAR_Address sccp_addr_own,
86 SCCP_PAR_Address sccp_addr_peer,
87 BSSMAP_IE_CellIdentifier cell_id,
Harald Welte256571e2018-01-24 18:47:19 +010088 hexstring imei,
Harald Weltea49e36e2018-01-21 19:29:33 +010089 hexstring imsi,
Harald Welte82600572018-01-21 20:54:08 +010090 hexstring msisdn,
Harald Welte256571e2018-01-24 18:47:19 +010091 OCT4 tmsi optional,
Harald Welte9de84792018-01-28 01:06:35 +010092 MobileStationClassmark1_V cm1,
Harald Welte82600572018-01-21 20:54:08 +010093 BSSMAP_IE_ClassmarkInformationType2 cm2,
Harald Welte16114282018-01-24 22:41:21 +010094 BSSMAP_IE_ClassmarkInformationType3 cm3 optional,
Harald Weltede371492018-01-27 23:44:41 +010095 AuthVector vec optional,
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +010096 BSC_ConnHdlrNetworkPars net,
Philipp Maieraeb29a82018-11-08 17:40:53 +010097 boolean send_early_cm,
98 charstring ipa_ctrl_ip,
99 integer ipa_ctrl_port,
Philipp Maier9b690e42018-12-21 11:50:03 +0100100 boolean ipa_ctrl_enable,
Philipp Maier57865482019-01-07 18:33:13 +0100101 boolean mm_info,
Philipp Maierc09a1312019-04-09 16:05:26 +0200102 boolean sgsap_enable,
Harald Weltef9abf8d2019-04-21 13:07:17 +0200103 boolean gsup_enable,
Vadim Yanitskiy2dd96612020-01-07 21:48:29 +0100104 OCT4 gsup_sid,
Harald Weltec1f937a2019-04-21 21:19:23 +0200105 integer ran_idx,
Harald Welte9b751a62019-04-14 17:39:29 +0200106 boolean use_umts_aka,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200107 boolean ran_is_geran,
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200108 boolean use_osmux,
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200109 boolean use_ipv6,
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200110 boolean verify_cell_id,
111 OCT3 common_id_last_eutran_plmn optional
Harald Weltea49e36e2018-01-21 19:29:33 +0100112};
113
Harald Welte9de84792018-01-28 01:06:35 +0100114/* get a one-octet bitmaks of supported algorithms based on Classmark information */
Eric Wild26f4a622021-05-17 15:27:05 +0200115function f_alg_mask_from_cm(BSSMAP_IE_ClassmarkInformationType2 cm2, template (omit) BSSMAP_IE_ClassmarkInformationType3 cm3 := omit) return OCT1 {
Harald Welte9de84792018-01-28 01:06:35 +0100116 var BIT8 res := '00000001'B; /* A5/0 always supported */
117
118 if (cm2.a5_1 == '0'B) {
119 res := res or4b '00000010'B;
120 }
121 if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) {
122 res := res or4b '00000100'B;
123 }
124 if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) {
125 res := res or4b '00001000'B;
126 }
Eric Wild26f4a622021-05-17 15:27:05 +0200127 if (not istemplatekind(cm3, "omit")) {
128 var BSSMAP_IE_ClassmarkInformationType3 v := valueof(cm3);
129 var BIT8 tmp := oct2bit(v.classmark3ValuePart[0]) and4b '00001111'B;
130 res := res or4b (tmp << 4);
131 }
132
Harald Welte9de84792018-01-28 01:06:35 +0100133 return bit2oct(res);
134}
135
136/* determine the best algorithm available within the bit-mask */
137function f_best_alg_from_mask(OCT1 alg_in) return OCT1 {
138 var BIT8 alg := oct2bit(alg_in);
139 var BIT8 ordered_algs[8] := {
140 '10000000'B, '01000000'B, '00100000'B, '00010000'B,
141 '00001000'B, /* A5/3 */
142 '00000010'B, /* A5/1 */
143 '00000100'B, /* A5/2 */
144 '00000001'B /* A5/0 */ }
145 for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) {
146 if (alg and4b ordered_algs[i] != '00000000'B) {
147 return bit2oct(ordered_algs[i]);
148 }
149 }
150 return '00'O;
151}
152
153/* return an integer like '1' for A5/1 based on a mask (with only one bit set */
154function f_alg_from_mask(OCT1 mask_in) return integer {
155 var BIT8 mask := oct2bit(mask_in);
156 for (var integer i := 0; i < 8; i := i+1) {
157 if (mask and4b ('00000001'B << i) != '00000000'B) {
158 return i;
159 }
160 }
161 return -1;
162}
163
Eric Wild26f4a622021-05-17 15:27:05 +0200164/* return true for A5/x supported by OCT1 bitmask */
165function f_alg_supported_by_mask(OCT1 mask_in, integer whicha5) return boolean {
166 var BIT8 mask := oct2bit(mask_in);
167 if (mask and4b ('00000001'B << whicha5) != '00000000'B) {
168 return true;
169 }
170 return false;
171}
172
Harald Weltea10db902018-01-27 12:44:49 +0100173/* altstep for the global guard timer */
174private altstep as_Tguard() runs on BSC_ConnHdlr {
175 [] g_Tguard.timeout {
Daniel Willmann90829d62018-02-15 17:45:14 +0100176 setverdict(fail, "Tguard timeout");
Daniel Willmannafce8662018-07-06 23:11:32 +0200177 mtc.stop;
Harald Weltea10db902018-01-27 12:44:49 +0100178 }
179}
180
181/* init function, called as first function in new BSC_ConnHdlr */
Harald Weltead2952e2018-01-27 14:12:46 +0100182function f_init_handler(BSC_ConnHdlrPars pars, float t_guard := 60.0) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100183 /* make parameters available via component variable */
184 g_pars := pars;
185 /* Start guard timer and activate it as default */
Harald Weltead2952e2018-01-27 14:12:46 +0100186 g_Tguard.start(t_guard);
Harald Weltea10db902018-01-27 12:44:49 +0100187 activate(as_Tguard());
Harald Weltef640a012018-04-14 17:49:21 +0200188 /* Route all SMPP messages for our MSISDN to us */
189 f_create_smpp_expect(hex2str(pars.msisdn));
Philipp Maier57865482019-01-07 18:33:13 +0100190
Harald Welte4263c522018-12-06 11:56:27 +0100191 /* Route all SGs message for our IMSI to us */
Philipp Maier57865482019-01-07 18:33:13 +0100192 if (g_pars.sgsap_enable == true) {
193 f_create_sgsap_expect(pars.imsi);
194 }
Philipp Maieraeb29a82018-11-08 17:40:53 +0100195
196 if (g_pars.ipa_ctrl_enable == true) {
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100197 f_ipa_ctrl_start_client(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port);
Philipp Maieraeb29a82018-11-08 17:40:53 +0100198 }
Philipp Maierc39a9d82018-11-09 11:21:08 +0100199
200 map(self:MSCVTY, system:MSCVTY);
201 f_vty_set_prompts(MSCVTY);
202 f_vty_transceive(MSCVTY, "enable");
Harald Weltea10db902018-01-27 12:44:49 +0100203}
204
Harald Weltea49e36e2018-01-21 19:29:33 +0100205
Harald Welte6811d102019-04-14 22:23:14 +0200206/* Callback function from general RAN_Emulation whenever a connectionless
Harald Weltea49e36e2018-01-21 19:29:33 +0100207 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
208private function BscUnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200209runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Weltea49e36e2018-01-21 19:29:33 +0100210 var template PDU_BSSAP resp := omit;
211
212 log("BSSMAP_BscUnitdataCallback");
213 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200214 if (match(bssap, tr_BSSMAP_Reset(g_ran_ops.use_osmux))){
Harald Weltea49e36e2018-01-21 19:29:33 +0100215 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200216 resp := ts_BSSMAP_ResetAck(g_ran_ops.use_osmux);
Harald Weltea49e36e2018-01-21 19:29:33 +0100217 }
218
219 /* FIXME: Handle paging, etc. */
220 return resp;
221}
222
Harald Welte9b751a62019-04-14 17:39:29 +0200223private function RncUnitdataCallback(RANAP_PDU ranap)
224runs on RAN_Emulation_CT return template RANAP_PDU {
225 var template RANAP_PDU resp := omit;
226
227 log("RANAP_RncUnitdataCallback");
228 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200229 if (match(ranap, tr_RANAP_Reset())) {
Harald Welte9b751a62019-04-14 17:39:29 +0200230 log("RANAP_RncUnitdataCallback: Responding to RESET with RESET-ACK");
231 var CN_DomainIndicator dom;
232 dom := ranap.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator;
233 resp := ts_RANAP_ResetAck(dom);
234 }
235
236 /* FIXME: Handle paging, etc. */
237 return resp;
238}
239
240
Harald Welte6811d102019-04-14 22:23:14 +0200241const RanOps BSC_RanOps := {
Harald Weltea49e36e2018-01-21 19:29:33 +0100242 /* Create call-back for inbound connections from MSC (hand-over) */
Harald Welte6811d102019-04-14 22:23:14 +0200243 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Weltea49e36e2018-01-21 19:29:33 +0100244 unitdata_cb := refers(BscUnitdataCallback),
Harald Welte9b751a62019-04-14 17:39:29 +0200245 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
246 ranap_unitdata_cb := refers(RncUnitdataCallback),
247 ps_domain := false,
Harald Weltea49e36e2018-01-21 19:29:33 +0100248 decode_dtap := true,
Harald Weltea4ca4462018-02-09 00:17:14 +0100249 role_ms := true,
Harald Welte2fce7882019-04-15 11:48:05 +0200250 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200251 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200252 use_osmux := false,
Harald Weltea4ca4462018-02-09 00:17:14 +0100253 sccp_addr_local := omit,
254 sccp_addr_peer := omit
Harald Weltea49e36e2018-01-21 19:29:33 +0100255}
256
257
258private function MnccUnitdataCallback(MNCC_PDU mncc)
259runs on MNCC_Emulation_CT return template MNCC_PDU {
260 log("Ignoring MNCC", mncc);
261 return omit;
262}
263
264const MnccOps BCC_MnccOps := {
265 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
266 unitdata_cb := refers(MnccUnitdataCallback)
267}
268
269
270
Harald Welte6811d102019-04-14 22:23:14 +0200271/* Encode 'l3' and ask RAN_Emulation to create new connection with COMPL L3 INFO */
Harald Weltea49e36e2018-01-21 19:29:33 +0100272function f_bssap_compl_l3(PDU_ML3_MS_NW l3)
273runs on BSC_ConnHdlr {
274 log("Sending COMPL L3: ", l3);
275 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
276 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
277 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc))));
Harald Welte71b69332018-01-21 20:43:53 +0100278 alt {
Harald Welte6811d102019-04-14 22:23:14 +0200279 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
280 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte71b69332018-01-21 20:43:53 +0100281 setverdict(fail, "DISC.ind from SCCP");
Daniel Willmannafce8662018-07-06 23:11:32 +0200282 mtc.stop;
Harald Welte71b69332018-01-21 20:43:53 +0100283 }
284 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100285}
286
Harald Welte9b751a62019-04-14 17:39:29 +0200287/* generate Iu LAI from BSSAP CGI */
288private function f_IuLAI_from_BssmapCI(BSSMAP_IE_CellIdentifier ci) return LAI {
289 var LAI lai;
290 if (ischosen(ci.cellIdentification.cI_CGI)) {
291 lai.pLMNidentity := ci.cellIdentification.cI_CGI.mcc_mnc;
292 lai.lAC := ci.cellIdentification.cI_CGI.lac;
293 } else if (ischosen(ci.cellIdentification.cI_SAI)) {
294 lai.pLMNidentity := ci.cellIdentification.cI_SAI.mcc_mnc;
295 lai.lAC := ci.cellIdentification.cI_SAI.lac;
296 } else if (ischosen(ci.cellIdentification.ci_LAC_RNC_CI)) {
297 lai.pLMNidentity := ci.cellIdentification.ci_LAC_RNC_CI.mcc_mnc;
298 lai.lAC := ci.cellIdentification.ci_LAC_RNC_CI.lac;
299 } else {
300 mtc.stop;
301 }
302 lai.iE_Extensions := omit;
303 return lai;
304}
305
306/* like f_bssap_compl_l3() but for 3G */
307function f_ranap_initial_ue(PDU_ML3_MS_NW l3)
308runs on BSC_ConnHdlr {
309 log("Sending InitialUE: ", l3);
310 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
311 var RANAP_PDU ranap;
312 var LAI lai := f_IuLAI_from_BssmapCI(g_pars.cell_id);
313 var SAI sai := {
314 pLMNidentity := lai.pLMNidentity,
315 lAC := lai.lAC,
316 sAC := '0000'O, /* FIXME */
317 iE_Extensions := omit
318 };
319 var IuSignallingConnectionIdentifier sigc_id := int2bit(23, 24);
320 var GlobalRNC_ID grnc_id := {
321 pLMNidentity := lai.pLMNidentity,
322 rNC_ID := 2342 /* FIXME */
323 };
324
325 ranap := valueof(ts_RANAP_initialUE_CS(lai, sai, l3_enc, sigc_id, grnc_id));
326 BSSAP.send(ts_RANAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, ranap));
327 alt {
328 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
329 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
330 setverdict(fail, "DISC.ind from SCCP");
331 mtc.stop;
332 }
333 }
334}
335
Harald Weltedceacc72019-04-21 20:58:35 +0200336/* Send BSSMAP Complete L3 or RANAP Initial UE depending on 2G/3G RAN type */
337function f_cl3_or_initial_ue(PDU_ML3_MS_NW l3)
338runs on BSC_ConnHdlr {
339 if (g_pars.ran_is_geran) {
340 f_bssap_compl_l3(l3);
341 } else {
342 f_ranap_initial_ue(l3);
343 }
344}
345
Harald Welte081b19a2018-02-10 09:11:13 +0100346type enumerated EstablishType {
347 EST_TYPE_MO_CALL,
Harald Welte0bef21e2018-02-10 09:48:23 +0100348 EST_TYPE_EMERG_CALL,
Harald Weltef45efeb2018-04-09 18:19:24 +0200349 EST_TYPE_PAG_RESP,
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700350 EST_TYPE_MO_SMS,
351 EST_TYPE_SS_ACT
Harald Welte081b19a2018-02-10 09:11:13 +0100352};
353
Harald Weltea49e36e2018-01-21 19:29:33 +0100354/* helper function to fully establish a dedicated channel */
Harald Welteb9e86fa2018-04-09 18:18:31 +0200355function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL)
Harald Weltea49e36e2018-01-21 19:29:33 +0100356runs on BSC_ConnHdlr {
Harald Welte081b19a2018-02-10 09:11:13 +0100357 var PDU_ML3_MS_NW l3_info;
Harald Welteb9e86fa2018-04-09 18:18:31 +0200358 var MobileIdentityLV mi;
359
360 /* If we have a TMSI, use TMSI instead of IMSI */
361 if (ispresent(g_pars.tmsi)) {
362 mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi));
363 } else {
364 mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
365 }
366
Harald Welte081b19a2018-02-10 09:11:13 +0100367 select (etype) {
368 case (EST_TYPE_MO_CALL) {
369 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
370 }
Harald Welte0bef21e2018-02-10 09:48:23 +0100371 case (EST_TYPE_EMERG_CALL) {
372 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi));
373 }
Harald Welte081b19a2018-02-10 09:11:13 +0100374 case (EST_TYPE_PAG_RESP) {
375 l3_info := valueof(ts_PAG_RESP(mi));
376 }
Harald Weltef45efeb2018-04-09 18:19:24 +0200377 case (EST_TYPE_MO_SMS) {
378 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi));
379 }
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700380 case (EST_TYPE_SS_ACT) {
381 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi));
382 }
Harald Welte081b19a2018-02-10 09:11:13 +0100383 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100384
385 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Weltedceacc72019-04-21 20:58:35 +0200386 f_cl3_or_initial_ue(l3_info);
Harald Weltea49e36e2018-01-21 19:29:33 +0100387
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200388 f_verify_vty_lac_ci(verify_vlr := false);
389
Harald Weltede371492018-01-27 23:44:41 +0100390 f_mm_common();
Pau Espin Pedrolf8034482019-06-03 13:15:58 +0200391 if (g_pars.net.expect_ciph or not g_pars.ran_is_geran) {
Harald Welte148a7082018-01-26 18:56:43 +0100392 /* implicit CM SERVICE ACCEPT? */
393 } else {
Harald Welte0bef21e2018-02-10 09:48:23 +0100394 if (etype != EST_TYPE_PAG_RESP) {
Harald Welte081b19a2018-02-10 09:11:13 +0100395 /* explicit CM SERVICE ACCEPT */
396 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
397 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100398 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100399}
400
401/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
Harald Welte9de84792018-01-28 01:06:35 +0100402function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100403{
404 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
405 return f_build_lu(mi);
406}
Harald Welte9de84792018-01-28 01:06:35 +0100407function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100408{
409 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
410 return f_build_lu(mi);
411}
Harald Welte9de84792018-01-28 01:06:35 +0100412function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100413{
414 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
415 return f_build_lu(mi);
416}
Harald Welte9de84792018-01-28 01:06:35 +0100417private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100418{
419 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
420 var PDU_ML3_MS_NW l3_info := valueof(ts_ML3_MO_LU_Req(valueof(ts_ML3_IE_LuType_Attach),
Harald Welte9de84792018-01-28 01:06:35 +0100421 old_lai, mi, g_pars.cm1));
Harald Weltea49e36e2018-01-21 19:29:33 +0100422 return l3_info;
423}
424
Harald Weltea183a5d2019-05-09 13:40:52 +0200425altstep as_GSUP_SAI() runs on BSC_ConnHdlr {
426var GSUP_IE auth_tuple;
427[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)) {
428 if (g_pars.use_umts_aka) {
429 g_pars.vec := f_gen_auth_vec_3g();
430 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand,
431 g_pars.vec.sres,
432 g_pars.vec.kc,
433 g_pars.vec.ik,
434 g_pars.vec.ck,
435 g_pars.vec.autn,
436 g_pars.vec.res));
437 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
Eric Wild26f4a622021-05-17 15:27:05 +0200438 g_pars.vec.kc := f_auth3g_kc();
Harald Weltea183a5d2019-05-09 13:40:52 +0200439 } else {
440 g_pars.vec := f_gen_auth_vec_2g();
441 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand,
442 g_pars.vec.sres,
443 g_pars.vec.kc));
444 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
445 }
446 }
447}
448
Harald Welte9de84792018-01-28 01:06:35 +0100449function f_mm_auth() runs on BSC_ConnHdlr
Harald Welte148a7082018-01-26 18:56:43 +0100450{
Harald Weltede371492018-01-27 23:44:41 +0100451 if (g_pars.net.expect_auth) {
Harald Weltea183a5d2019-05-09 13:40:52 +0200452 as_GSUP_SAI();
Harald Weltec1f937a2019-04-21 21:19:23 +0200453 if (g_pars.use_umts_aka) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200454 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn)));
455 var OCT4 res := substr(g_pars.vec.res, 0, 4);
456 var OCT4 xres := substr(g_pars.vec.res, 4, 4);
457 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres)));
458 } else {
Harald Weltec1f937a2019-04-21 21:19:23 +0200459 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand)));
460 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres)));
461 }
Harald Welte148a7082018-01-26 18:56:43 +0100462 }
Harald Welte9de84792018-01-28 01:06:35 +0100463}
Harald Welte148a7082018-01-26 18:56:43 +0100464
Oliver Smith1d118ff2019-07-03 10:57:35 +0200465function f_mm_imei() runs on BSC_ConnHdlr
466{
467 var PDU_DTAP_MT dtap_mt;
468 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700469 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200470
471 if (not g_pars.net.expect_imei) {
472 return
473 }
474
475 /* MSC <-> BSC: ID req/rsp for IMEI */
476 alt {
477 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEI))) {
478 mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
479 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
480 }
481 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
482 setverdict(fail, "Expected ID REQ for IMEI DTAP MT message, but got: ", dtap_mt);
483 mtc.stop;
484 }
485 }
486
487 /* MSC <-> HLR: Check IMEI req/res/err */
488 alt {
489 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
490 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
491 }
492 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
493 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
494 }
495 [] GSUP.receive(?) -> value gsup_msg {
496 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
497 g_pars.imsi, "), but got: ", gsup_msg);
498 mtc.stop;
499 }
500 }
501}
502
503function f_mm_imei_early() runs on BSC_ConnHdlr
504{
505 var PDU_DTAP_MT dtap_mt;
506 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700507 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200508
509 if (not g_pars.net.expect_imei_early) {
510 return
511 }
512
513 /* MSC <-> BSC: ID req/rsp for IMEISV */
514 alt {
515 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEISV))) {
516 mi := valueof(ts_MI_IMEISV_LV(g_pars.imei));
517 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
518 }
519 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
520 setverdict(fail, "Expected ID REQ for IMEISV DTAP MT message, but got: ", dtap_mt);
521 mtc.stop;
522 }
523 }
524
525 /* MSC <-> HLR: Check IMEI req/res/err */
526 alt {
527 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
528 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
529 }
530 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
531 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
532 }
533 [] GSUP.receive(?) -> value gsup_msg {
534 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
535 g_pars.imsi, "), but got: ", gsup_msg);
536 mtc.stop;
537 }
538 }
539}
540
Harald Welte79f1e452020-08-18 22:55:02 +0200541function f_expect_common_id() runs on BSC_ConnHdlr
542{
543 if (g_pars.ran_is_geran) {
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200544 BSSAP.receive(tr_BSSMAP_CommonId(g_pars.imsi,
545 f_tr_BSSMAP_LastUsedEUTRANPLMNId(g_pars.common_id_last_eutran_plmn)));
Harald Welte79f1e452020-08-18 22:55:02 +0200546 } else {
547 BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
548 }
549}
550
Eric Wild26f4a622021-05-17 15:27:05 +0200551function f_auth3g_kc() runs on BSC_ConnHdlr return OCT8 {
552 var integer i;
553 var octetstring res := g_pars.vec.ck[0] xor4b g_pars.vec.ck[0 + 8] xor4b g_pars.vec.ik[0] xor4b g_pars.vec.ik[0 + 8];
554 for (i := 1; i < 8; i := i + 1) {
555 var octetstring a := g_pars.vec.ck[i] xor4b g_pars.vec.ck[i + 8] xor4b g_pars.vec.ik[i] xor4b g_pars.vec.ik[i + 8];
556 res := res & a;
557 }
558
559 return res;
560}
561
562
Harald Welte9de84792018-01-28 01:06:35 +0100563function f_mm_common() runs on BSC_ConnHdlr
564{
565 f_mm_auth();
Harald Welte9b751a62019-04-14 17:39:29 +0200566 if (g_pars.ran_is_geran) {
567 if (g_pars.net.expect_ciph) {
Eric Wild26f4a622021-05-17 15:27:05 +0200568 var OCT1 a5_net := f_alg_mask_from_cm(g_pars.cm2, g_pars.cm3);
Harald Welte9b751a62019-04-14 17:39:29 +0200569 var OCT1 a5_intersect := g_pars.net.kc_support and4b a5_net;
Eric Wild26f4a622021-05-17 15:27:05 +0200570 var boolean has_a54 := f_alg_supported_by_mask(a5_intersect, 4);
571
572 var PDU_BSSAP pdu;
Harald Welte9b751a62019-04-14 17:39:29 +0200573 alt {
Eric Wild26f4a622021-05-17 15:27:05 +0200574 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(a5_intersect, g_pars.vec.kc)) -> value pdu {
575 var PDU_BSSMAP_CipherModeCommand ciphmodcmd := pdu.pdu.bssmap.cipherModeCommand;
576 if (g_pars.use_umts_aka and has_a54) {
577 var OCT32 fulloutput := f_calculate_HMAC_SHA256(g_pars.vec.ck & g_pars.vec.ik, '32'O, 32);
578 var OCT16 kc128 := substr(fulloutput, 0, 16);
579 if (not ispresent(ciphmodcmd.kC128)) {
580 setverdict(fail, "kc128 missing in CiphModCmd");
581 mtc.stop;
582 }
583 if (ciphmodcmd.kC128.kC128_Value != kc128) {
584 setverdict(fail, "kc128 wrong in CiphModCmd?!", kc128);
585 mtc.stop;
586 }
587 } else {
588 if (ispresent(ciphmodcmd.kC128)) {
589 setverdict(fail, "kc128 present in CiphModCmd, but should not exist!");
590 mtc.stop;
591 }
592 }
593
Harald Welte9b751a62019-04-14 17:39:29 +0200594 var OCT1 a5_chosen := f_best_alg_from_mask(a5_intersect);
595 var integer a5_nr := f_alg_from_mask(a5_chosen);
596 BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
597 }
598 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd(?, g_pars.vec.kc)) {
599 setverdict(fail, "Wrong ciphering algorithm mask in CiphModCmd");
600 mtc.stop;
601 }
Eric Wild26f4a622021-05-17 15:27:05 +0200602 [] BSSAP.receive(tr_BSSMAP_ClassmarkRequest) {
603 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3))
604 repeat;
605 }
Harald Welte9de84792018-01-28 01:06:35 +0100606 }
Harald Welte9b751a62019-04-14 17:39:29 +0200607 /* FIXME: Send the best available algorithm */
608 }
Harald Welte79f1e452020-08-18 22:55:02 +0200609 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200610 } else { /* UTRAN */
611 alt {
612 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
613 uia_key := oct2bit(g_pars.vec.ik),
614 key_sts := ?,
615 uea_algs := ?,
616 uea_key := oct2bit(g_pars.vec.ck))) {
617 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/
618 var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/
619 BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen));
Harald Welte79f1e452020-08-18 22:55:02 +0200620 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200621 }
622 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
623 setverdict(fail, "Invalid SecurityModeCommand (ciphering case)");
624 mtc.stop;
625 }
626 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
627 uia_key := oct2bit(g_pars.vec.ik),
628 key_sts := ?)) {
629 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/
630 BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
Harald Welte79f1e452020-08-18 22:55:02 +0200631 f_expect_common_id();
Harald Welte9b751a62019-04-14 17:39:29 +0200632 }
633 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
634 setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)");
Daniel Willmannafce8662018-07-06 23:11:32 +0200635 mtc.stop;
Harald Welte9de84792018-01-28 01:06:35 +0100636 }
637 }
Harald Welte148a7082018-01-26 18:56:43 +0100638 }
639}
640
Philipp Maier9b690e42018-12-21 11:50:03 +0100641function f_expect_mm_info() runs on BSC_ConnHdlr {
642 if (g_pars.mm_info == true) {
643 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info));
644 }
645}
646
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200647private function f_lac_ci_vty_str(BSSMAP_IE_CellIdentifier cell_id) return charstring
648{
649 return "LAC / cell ID: "
650 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.lac)) & " / "
651 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.ci));
652}
653
654/* Get an IMSI's info and verify that the g_pars.cell_id is reflected in the info.
655 * Verify both the "LAC / cell ID" in the VLR and the "LAC / cell ID" in the "Connection:" part, if any.
656 * If verify_vlr == false, then only verify the "Connection:" part, and fail if there is no "Connection:"; this is
657 * useful when a conn has been established, but the subscriber has not been authenticated, so the VLR does not yet
658 * reflect the new conn's cell ID.
659 */
660function f_verify_vty_lac_ci(boolean verify_vlr := true) runs on BSC_ConnHdlr {
661 if (not g_pars.ran_is_geran) {
662 log("Skipping f_verify_vty_lac_ci(), disabled for Iu");
663 setverdict(pass);
664 return;
665 }
666 if (not g_pars.verify_cell_id) {
667 /* Skip this verification; either the TC expects no cell id to end up being accepted, or this was
668 * disabled globally to test an older osmo-msc which doesn't store the cell id properly yet. */
669 log("Skipping f_verify_vty_lac_ci()");
670 setverdict(pass);
671 return;
672 }
673
674 var charstring vty_cmd := "show subscriber imsi " & hex2str(g_pars.imsi) & " conn";
675 var charstring result := f_vty_transceive_ret(MSCVTY, vty_cmd);
676 var charstring expect_lac_ci := "LAC / cell ID: "
677 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.lac)) & " / "
678 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.ci));
679
680 var boolean vlr_matches := false;
681 var boolean connection_present := false;
682 var boolean connection_matches := false;
683
684 /* There are two occurences of LAC / cell ID: once for the VLR record, and once for the active connection. The
685 * active connection part starts with 'Connection:'. If there is no active connection, that part is omitted.
686 * So, first find out whether there is a 'Connection:' part. Then verify the LAC / cell ID above 'Connection:'
687 * and below 'Connection:', separately.
688 */
689 var integer connection_start := f_strstr(result, "Connection:");
690 connection_present := (connection_start >= 0);
691
692 var integer lac_ci_match := f_strstr(result, expect_lac_ci);
693 if (connection_present) {
694 if (lac_ci_match > connection_start) {
695 /* The first match is below 'Connection:', so the VLR part above it did not match. */
696 vlr_matches := false;
697 connection_matches := true;
698 } else if (lac_ci_match >= 0) {
699 /* The first match is above 'Connection:', so the VLR part matches. */
700 vlr_matches := true;
701
702 /* Now find a match below 'Connection:' */
703 lac_ci_match := f_strstr(result, expect_lac_ci, connection_start);
704 connection_matches := (lac_ci_match > 0);
705 }
706 } else {
707 /* There is no 'Connection:', so a match, if any, is from the VLR part. */
708 vlr_matches := (lac_ci_match >= 0);
709 }
710
711 if (verify_vlr) {
712 if (not vlr_matches) {
713 setverdict(fail, vty_cmd, " shows mismatching LAC / cell ID in the VLR part, expecting: ",
714 expect_lac_ci, " -- got: ", result);
715 return;
716 } else {
717 log("f_verify_vty_lac_ci(): VLR record matches ", expect_lac_ci);
718 setverdict(pass);
719 }
720 }
721
722 if (connection_present) {
723 if (not connection_matches) {
724 setverdict(fail, vty_cmd, " shows mismatching LAC cell ID in the 'Connection' part, expecting: ",
725 expect_lac_ci, " -- got: ", result);
726 } else {
727 log("f_verify_vty_lac_ci(): Active connection matches ", expect_lac_ci);
728 setverdict(pass);
729 }
730 }
731
732 if (not verify_vlr and not connection_present) {
733 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);
734 }
735}
736
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100737function f_perform_lu()
Harald Weltea49e36e2018-01-21 19:29:33 +0100738runs on BSC_ConnHdlr {
739 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
740 var PDU_DTAP_MT dtap_mt;
741
742 /* tell GSUP dispatcher to send this IMSI to us */
743 f_create_gsup_expect(hex2str(g_pars.imsi));
744
745 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Welte9b751a62019-04-14 17:39:29 +0200746 if (g_pars.ran_is_geran) {
747 f_bssap_compl_l3(l3_lu);
748 if (g_pars.send_early_cm) {
749 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
750 }
751 } else {
752 f_ranap_initial_ue(l3_lu);
Harald Welte8a121b32018-01-22 03:00:41 +0100753 }
Harald Welte5c2622c2018-01-21 20:45:20 +0100754
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200755 /* at this point the conn has been established, but the subscriber has not been authenticated, so the VLR does
756 * not yet reflect this conn's cell ID. */
757 f_verify_vty_lac_ci(verify_vlr := false);
758
Oliver Smith1d118ff2019-07-03 10:57:35 +0200759 f_mm_imei_early();
Harald Weltede371492018-01-27 23:44:41 +0100760 f_mm_common();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100761 f_msc_lu_hlr();
Oliver Smith1d118ff2019-07-03 10:57:35 +0200762 f_mm_imei();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100763 f_accept_reject_lu();
764 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
765 f_expect_clear();
Harald Welte16114282018-01-24 22:41:21 +0100766
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100767 setverdict(pass);
768}
769
770function f_msc_lu_hlr() runs on BSC_ConnHdlr
771{
Harald Weltea49e36e2018-01-21 19:29:33 +0100772 /* Expect MSC to perform LU with HLR */
773 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
774 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
775 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
776 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100777}
778
779function f_accept_reject_lu() runs on BSC_ConnHdlr {
780 var PDU_DTAP_MT dtap_mt;
Harald Weltea49e36e2018-01-21 19:29:33 +0100781
782 alt {
783 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
784 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
Harald Weltede371492018-01-27 23:44:41 +0100785 if (g_pars.net.expect_tmsi) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100786 if (not ispresent(lu_acc.mobileIdentityTLV) or
787 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
788 setverdict(fail, "Expected TMSI but no TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200789 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100790 } else {
Harald Welte256571e2018-01-24 18:47:19 +0100791 g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets;
Harald Weltea49e36e2018-01-21 19:29:33 +0100792 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
793 }
794 } else {
795 if (ispresent(lu_acc.mobileIdentityTLV) and
796 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
797 setverdict(fail, "Expected no TMSI but TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200798 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100799 }
800 }
801 }
802 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
803 setverdict(fail, "Expected LU ACK, but received LU REJ");
Daniel Willmannafce8662018-07-06 23:11:32 +0200804 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100805 }
806 }
Philipp Maier9b690e42018-12-21 11:50:03 +0100807
808 /* Wait for MM-Information (if enabled) */
809 f_expect_mm_info();
Harald Weltea49e36e2018-01-21 19:29:33 +0100810 setverdict(pass);
811}
812
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100813function f_expect_lu_reject(template OCT1 cause := ?) runs on BSC_ConnHdlr {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200814 var PDU_DTAP_MT dtap_mt;
815 timer T := 5.0;
816
817 T.start;
818 alt {
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100819 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej(cause))) {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200820 setverdict(pass);
821 }
822 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
823 setverdict(fail, "Expected LU reject BSSAP message, got: ", dtap_mt);
824 }
825 [] T.timeout {
826 setverdict(fail, "Timeout waiting for LU reject");
827 }
828 }
829}
830
Harald Weltea49e36e2018-01-21 19:29:33 +0100831function f_foo() runs on BSC_ConnHdlr{
Harald Welte6811d102019-04-14 22:23:14 +0200832 /* SCCP CC handled by RAN_Emulation_CT.main() */
Harald Weltea49e36e2018-01-21 19:29:33 +0100833 /* Expect auth, if enabled */
834
835 /* TODO: ISD */
836 /* Expect encr, if enabled */
837 /* Expect encr, if enabled */
838 /* Expect ASS CMD, if chan_type != requested */
839 /* Send ASS CMPL in successful case */
840
841 /* Expect AoIP port/ip information for RTP stream */
842 /* Expect MSC-originated MGCP to our simulated MGW */
843 /* Verify Counters via CTRL */
844 /* re-configure MSC behaviour via VTY */
845}
846
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200847type record CrcxResponse {
848 integer resp, /* 1 = reply with OK, 0 = do not reply, -1 = reply with error */
849 HostName mgw_rtp_ip,
850 PortNumber mgw_rtp_port,
851 MgcpConnectionId mgcp_connection_id /* MGCP Connection ID BSS Side */
852}
853
Harald Welteb71901a2018-01-26 19:16:05 +0100854/* parameters related to a (MO?) voice call */
855type record CallParameters {
Harald Welteb71901a2018-01-26 19:16:05 +0100856 /* CC related parameters */
857 hexstring called_party, /* whom are we calling */
858 integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100859 boolean mo_call, /* For a MO call, the transaction_id was allocated by the MS,
860 important to set the TI flag properly */
Harald Welteb71901a2018-01-26 19:16:05 +0100861 BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */
Harald Welte0bef21e2018-02-10 09:48:23 +0100862 boolean emergency, /* is this an emergency call? */
Harald Welteb71901a2018-01-26 19:16:05 +0100863
864 /* MNCC related parameters */
865 uint32_t mncc_callref optional, /* call reference on the MNCC side */
866 MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200867 HostName mncc_rtp_ip optional, /* MNCC Side RTP IP */
868 PortNumber mncc_rtp_port optional, /* MNCC Side RTP port */
Harald Welteb71901a2018-01-26 19:16:05 +0100869
870 /* RTP related parameters */
871 HostName bss_rtp_ip optional, /* BSS Side RTP IP */
872 PortNumber bss_rtp_port optional, /* BSS Side RTP Port */
873 HostName mss_rtp_ip optional, /* MSS Side RTP IP */
874 PortNumber mss_rtp_port optional, /* MSS Side RTP Port */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200875 integer got_crcx_count,
876 CrcxResponse mgw_conn_1,
877 CrcxResponse mgw_conn_2,
Harald Welteb71901a2018-01-26 19:16:05 +0100878 uint7_t rtp_payload_type, /* dynamic RTP payload type */
879 charstring rtp_sdp_format, /* AMR/8000 or the like */
Philipp Maier2a98a732018-03-19 16:06:12 +0100880 boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX
881 (f_mt_call and f_mt_call) */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200882 boolean stop_after_cc_setup, /* Special case: stop call establish after CC Setup */
883 boolean ran_clear_when_alerting, /* Special case: send Clear upon CC Alerting */
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100884 boolean expect_release, /* Special case: expect call establish to cause direct CC Rel */
Harald Welteb71901a2018-01-26 19:16:05 +0100885
Philipp Maiercd668572018-03-19 16:11:52 +0100886 MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */
Harald Welteb71901a2018-01-26 19:16:05 +0100887 MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200888
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200889 boolean use_osmux, /* MSC is expected to use Osmux for this call */
890 integer got_osmux_count
Harald Welteb71901a2018-01-26 19:16:05 +0100891}
892
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200893template (value) CallParameters t_CallParams(hexstring called := '12345'H, integer tid := 0) := {
Harald Welteb71901a2018-01-26 19:16:05 +0100894 called_party := called,
895 transaction_id := tid,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100896 mo_call := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100897 bearer_cap := valueof(ts_Bcap_voice),
Harald Welte0bef21e2018-02-10 09:48:23 +0100898 emergency := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100899 mncc_callref := omit,
900 mncc_bearer_cap := valueof(ts_MNCC_bcap_voice),
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200901 mncc_rtp_ip := "42.23.11.5",
902 mncc_rtp_port := 423,
Harald Welte4017d552018-01-26 21:40:05 +0100903 bss_rtp_ip := "9.8.7.6",
904 bss_rtp_port := 9000,
Harald Welteb71901a2018-01-26 19:16:05 +0100905 mss_rtp_ip := omit,
906 mss_rtp_port := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200907 got_crcx_count := 0,
908 mgw_conn_1 := {
909 resp := 1,
910 mgw_rtp_ip := "1.1.1.1",
911 mgw_rtp_port := 10000,
912 mgcp_connection_id := '11111'H
913 },
914 mgw_conn_2 := {
915 resp := 1,
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +0200916 mgw_rtp_ip := "2.2.2.2",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200917 mgw_rtp_port := 11000,
918 mgcp_connection_id := '22222'H
919 },
Harald Welteb71901a2018-01-26 19:16:05 +0100920 rtp_payload_type := 98,
921 rtp_sdp_format := "AMR/8000",
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100922 mgw_drop_dlcx := false,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200923 stop_after_cc_setup := false,
924 ran_clear_when_alerting := false,
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100925 expect_release := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100926 mgcp_call_id := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200927 mgcp_ep := "rtpbridge/1@mgw",
928 use_osmux := false,
929 got_osmux_count := 0
Harald Welteb71901a2018-01-26 19:16:05 +0100930};
931
Harald Welte4263c522018-12-06 11:56:27 +0100932/* Allocate a call reference and send SETUP via MNCC to MSC */
933function f_mt_call_initate(inout CallParameters cpars)
Harald Welte33ec09b2018-02-10 15:34:46 +0100934runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200935 cpars.mo_call := false;
Harald Welte4263c522018-12-06 11:56:27 +0100936 cpars.mncc_callref := f_rnd_int(2147483648);
937 MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
938 hex2str(cpars.called_party), hex2str(g_pars.imsi)));
939}
Harald Welte33ec09b2018-02-10 15:34:46 +0100940
Harald Welte408a7ef2019-04-21 17:08:40 +0200941private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) :=
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200942 ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
Harald Welte408a7ef2019-04-21 17:08:40 +0200943 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200944 cpars.mgw_conn_2.mgw_rtp_port,
Harald Welte408a7ef2019-04-21 17:08:40 +0200945 { int2str(cpars.rtp_payload_type) },
946 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
947 cpars.rtp_sdp_format)),
948 valueof(ts_SDP_ptime(20)) });
949
Harald Welte4263c522018-12-06 11:56:27 +0100950/* Complete call, begin with a paging response message via BSSAP */
951function f_mt_call_complete(inout CallParameters cpars)
952runs on BSC_ConnHdlr {
Harald Welte33ec09b2018-02-10 15:34:46 +0100953 var MNCC_PDU mncc;
954 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200955 var template MgcpResponse mgcp_resp;
956 var MgcpOsmuxCID osmux_cid;
957 var PDU_BSSAP bssap;
Harald Welte33ec09b2018-02-10 15:34:46 +0100958
Harald Welte6811d102019-04-14 22:23:14 +0200959 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Welte33ec09b2018-02-10 15:34:46 +0100960
Harald Welteb9e86fa2018-04-09 18:18:31 +0200961 f_establish_fully(EST_TYPE_PAG_RESP);
Harald Welte33ec09b2018-02-10 15:34:46 +0100962
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100963 log("f_mt_call_complete 1");
964
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200965 cpars.got_osmux_count := 0;
966
Harald Welte33ec09b2018-02-10 15:34:46 +0100967 /* MS <- MSC: Expect CC SETUP */
968 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party)));
969
970 /* MS -> MSC: ALERTING */
971 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id)));
972 MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100973 log("f_mt_call_complete 2");
Harald Welte33ec09b2018-02-10 15:34:46 +0100974
Harald Welte33ec09b2018-02-10 15:34:46 +0100975 /* Create MGCP expect */
976 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
977 /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */
978 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
979
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200980 /* First MGCP CRCX */
Harald Welte33ec09b2018-02-10 15:34:46 +0100981 MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100982 log("f_mt_call_complete 3");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200983 if (not f_handle_crcx(cpars, mgcp_cmd)) {
984 return;
Philipp Maier4b2692d2018-03-14 16:37:48 +0100985 }
Harald Welte33ec09b2018-02-10 15:34:46 +0100986 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +0100987
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +0100988
Harald Welte9b751a62019-04-14 17:39:29 +0200989 if (g_pars.ran_is_geran) {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200990 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200991 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Harald Welte9b751a62019-04-14 17:39:29 +0200992
993 interleave {
994 /* Second MGCP CRCX (this time for MSS/CN side) */
995 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100996 log("f_mt_call_complete 4");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200997 if (not f_handle_crcx(cpars, mgcp_cmd)) {
998 break;
999 }
Harald Welte9b751a62019-04-14 17:39:29 +02001000 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001001
1002 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1003 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1004 log("f_mt_call_complete 5");
1005 }
1006
Harald Welte9b751a62019-04-14 17:39:29 +02001007 /* expect the MSC to trigger a BSSMAP ASSIGNMENT */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001008 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001009 var template BSSMAP_IE_AoIP_TransportLayerAddress tla;
Harald Welte9b751a62019-04-14 17:39:29 +02001010 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001011 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001012 log("f_mt_call_complete 6");
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001013 tla := f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port);
Harald Welte9b751a62019-04-14 17:39:29 +02001014 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
1015
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001016 if (cpars.use_osmux) {
1017 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1018 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1019 mtc.stop;
1020 }
1021 osmuxCID := valueof(ts_OsmuxCID(0));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001022 if (not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1023 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 +02001024 mtc.stop;
1025 }
1026 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1027 } else {
1028 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1029 }
1030 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001031
1032 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
Harald Welte9b751a62019-04-14 17:39:29 +02001033 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001034
1035 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1036 log("f_mt_call_complete 7");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001037 var octetstring ip;
1038 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1039 if (is_ipv6) {
1040 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1041 } else {
1042 ip := f_inet_addr(cpars.mncc_rtp_ip);
1043 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001044 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001045 is_ipv6, ip,
1046 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001047 /* payload type 3 = GSM FR */ 3));
1048 }
1049
1050 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1051 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1052 log("f_mt_call_complete 8");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001053 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 +01001054 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001055 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001056 { int2str(cpars.rtp_payload_type) },
1057 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1058 cpars.rtp_sdp_format)),
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001059 valueof(ts_SDP_ptime(20)) }));
1060 if (cpars.use_osmux) {
1061 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1062 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1063 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1064 mtc.stop;
1065 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001066 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 +02001067 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001068 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 +02001069 }
1070 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001071 }
1072
1073 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1074 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001075 var SDP_Message sdp;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001076 log("f_mt_call_complete 9");
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001077
1078 if (isvalue(mgcp_cmd.sdp)) {
1079 sdp := mgcp_cmd.sdp;
1080 if (sdp.media_list[0].media_field.ports.port_number != cpars.mncc_rtp_port) {
1081 setverdict(fail, "Wrong MDCX Connection port received, expected ", cpars.mncc_rtp_port, " and received ", sdp.media_list[0].media_field.ports.port_number)
1082 mtc.stop;
1083 }
1084 if (sdp.connection.conn_addr.addr != cpars.mncc_rtp_ip) {
1085 setverdict(fail, "Wrong MDCX Connection address received, expected ", cpars.mncc_rtp_ip, " and received ", sdp.connection.conn_addr.addr)
1086 mtc.stop;
1087 }
1088 }
1089
1090 sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1091 hex2str(cpars.mgcp_call_id), "42",
1092 cpars.mgw_conn_2.mgw_rtp_port,
1093 { int2str(cpars.rtp_payload_type) },
1094 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1095 cpars.rtp_sdp_format)),
1096 valueof(ts_SDP_ptime(20)) }));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001097 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 +01001098 }
1099
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001100 }
Harald Welte9b751a62019-04-14 17:39:29 +02001101 } else {
Harald Welte9b751a62019-04-14 17:39:29 +02001102 interleave {
1103 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001104 log("f_mt_call_complete 4.iu");
1105 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1106 break;
Harald Welte9b751a62019-04-14 17:39:29 +02001107 }
Harald Welte9b751a62019-04-14 17:39:29 +02001108 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001109
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001110 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1111 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1112 log("f_mt_call_complete 5.iu");
1113 }
1114
1115 [] BSSAP.receive(tr_RANAP_RabAssReq(?)) {
1116 log("f_mt_call_complete 6.iu");
1117 var RAB_SetupOrModifiedList l := {
1118 {
1119 {
1120 id := id_RAB_SetupOrModifiedItem,
1121 criticality := ignore,
1122 value_ := {
1123 rAB_SetupOrModifiedItem := {
1124 rAB_ID := int2bit(23, 8),
1125 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1126 iuTransportAssociation := {
1127 bindingID := '040c0000'O
1128 },
1129 dl_dataVolumes := omit,
1130 iE_Extensions := omit
1131 }
1132 }
1133 }
1134 }
1135 };
1136 BSSAP.send(ts_RANAP_RabAssResp(l));
1137
1138 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
1139 }
1140
1141 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1142 log("f_mt_call_complete 7.iu");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001143 var octetstring ip;
1144 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1145 if (is_ipv6) {
1146 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1147 } else {
1148 ip := f_inet_addr(cpars.mncc_rtp_ip);
1149 }
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001150 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001151 is_ipv6, ip,
1152 cpars.mncc_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001153 /* payload type 3 = GSM FR */ 3));
1154 }
1155
1156 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1157 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1158 log("f_mt_call_complete 8.iu");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001159 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 +01001160 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001161 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001162 { int2str(cpars.rtp_payload_type) },
1163 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1164 cpars.rtp_sdp_format)),
1165 valueof(ts_SDP_ptime(20)) }));
1166 if (cpars.use_osmux) {
1167 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1168 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1169 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1170 mtc.stop;
1171 }
1172 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
1173 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001174 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 +01001175 }
1176 MGCP.send(mgcp_resp);
1177 }
1178
1179 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1180 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1181 log("f_mt_call_complete 9.iu");
1182 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1183 hex2str(cpars.mgcp_call_id), "42",
1184 cpars.mgw_conn_2.mgw_rtp_port,
1185 { int2str(cpars.rtp_payload_type) },
1186 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1187 cpars.rtp_sdp_format)),
1188 valueof(ts_SDP_ptime(20)) }));
1189 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
1190 }
1191
Harald Welte33ec09b2018-02-10 15:34:46 +01001192 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001193 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001194
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001195 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1196 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1197 } else {
1198 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1199 mtc.stop;
1200 }
1201
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001202 log("f_mt_call_complete DONE");
Harald Welte4263c522018-12-06 11:56:27 +01001203}
1204
Harald Weltee035e3e2019-04-21 17:32:05 +02001205function f_expect_paging(boolean by_tmsi := true)
1206runs on BSC_ConnHdlr {
Harald Welte9b751a62019-04-14 17:39:29 +02001207 if (g_pars.ran_is_geran) {
1208 BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
1209 } else {
Harald Welte62113fc2019-05-09 13:04:02 +02001210 BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi)));
Harald Welte9b751a62019-04-14 17:39:29 +02001211 }
Harald Weltee035e3e2019-04-21 17:32:05 +02001212}
1213
Harald Welte4263c522018-12-06 11:56:27 +01001214function f_mt_call_establish(inout CallParameters cpars)
1215runs on BSC_ConnHdlr {
1216
1217 /* Initiate the call via MNCC */
1218 f_mt_call_initate(cpars);
1219
1220 /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
Harald Welte6811d102019-04-14 22:23:14 +02001221 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Weltee035e3e2019-04-21 17:32:05 +02001222 f_expect_paging()
Harald Welte4263c522018-12-06 11:56:27 +01001223
1224 /* Complete the call via BSSAP */
1225 f_mt_call_complete(cpars);
Harald Welte33ec09b2018-02-10 15:34:46 +01001226
Harald Welte33ec09b2018-02-10 15:34:46 +01001227 setverdict(pass);
1228}
1229
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001230/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1231 * Return true when an OK reply was sent, false otherwise.
1232 * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */
1233function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd)
1234runs on BSC_ConnHdlr
1235return boolean {
1236 var CrcxResponse conn := cpars.mgw_conn_1;
1237 if (cpars.got_crcx_count > 0) {
1238 conn := cpars.mgw_conn_2;
1239 }
1240 cpars.got_crcx_count := cpars.got_crcx_count + 1;
1241
1242 var MgcpMessage mgcp_msg := {
1243 command := mgcp_cmd
1244 }
1245 var template MgcpResponse mgcp_resp;
1246 var MgcpOsmuxCID osmux_cid;
1247 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1248 if (ispresent(cpars.mgcp_call_id)) {
1249 if (cpars.mgcp_call_id != call_id) {
1250 setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id);
1251 mtc.stop;
1252 }
1253 } else {
1254 cpars.mgcp_call_id := call_id;
1255 }
1256
1257 /* When the endpoint contains a wildcard we keep the endpoint
1258 * identifier we have set up in cpars. Otherwise we use the
1259 * endpoint name that the call agent has supplied */
1260 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1261 cpars.mgcp_ep := mgcp_cmd.line.ep;
1262 }
1263
1264 if (conn.resp == -1) {
1265 /* Reply with error */
1266 var MgcpResponse mgcp_rsp := {
1267 line := {
1268 code := "542",
1269 trans_id := mgcp_cmd.line.trans_id,
1270 string := "FORCED_FAIL"
1271 },
1272 sdp := omit
1273
1274 }
1275 var MgcpParameter mgcp_rsp_param := {
1276 code := "Z",
1277 val := cpars.mgcp_ep
1278 };
1279 mgcp_rsp.params[0] := mgcp_rsp_param;
1280 MGCP.send(mgcp_rsp);
1281 return false;
1282 }
1283
1284 if (conn.resp == 0) {
1285 /* Do not reply at all */
1286 return false;
1287 }
1288
1289 if (conn.resp != 1) {
1290 setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1");
1291 mtc.stop;
1292 }
1293
1294 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1295 hex2str(cpars.mgcp_call_id), "42",
1296 conn.mgw_rtp_port,
1297 { int2str(cpars.rtp_payload_type) },
1298 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1299 cpars.rtp_sdp_format)),
1300 valueof(ts_SDP_ptime(20)) }));
1301
1302 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1303 if (not cpars.use_osmux) {
1304 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1305 mtc.stop;
1306 }
1307 cpars.got_osmux_count := cpars.got_osmux_count + 1;
1308 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1309 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1310 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1311 if (osmux_cid != -1) {
1312 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1313 mtc.stop;
1314 }
1315
1316 osmux_cid := 0;
1317 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1318 } else {
1319 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1320 }
1321
1322 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep));
1323 MGCP.send(mgcp_resp);
1324 return true;
1325}
1326
1327
1328altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr {
1329 var MgcpCommand mgcp_cmd;
1330 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1331 log("as_optional_mgcp_crcx: rx CRCX");
1332 f_handle_crcx(cpars, mgcp_cmd);
1333
1334 /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an
1335 * CRCX is handled. */
1336 repeat;
1337 }
1338}
1339
1340private altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr {
1341 var MgcpCommand mgcp_cmd;
1342 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1343 log("as_optional_mgcp_mdcx: rx MDCX");
1344 log(mgcp_cmd);
1345 var charstring conn_id;
1346 var charstring rtp_payload_type;
1347 f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id);
1348 rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0];
1349
1350 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip,
1351 mgcp_cmd.sdp.origin.session_id, "42",
1352 mgw_rtp_port,
1353 { rtp_payload_type },
1354 { valueof(ts_SDP_ptime(20)) }));
1355 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp));
1356
1357 /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is
1358 * handled. */
1359 repeat;
1360 }
1361}
1362
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001363private altstep as_optional_mgcp_dlcx(CallParameters cpars) runs on BSC_ConnHdlr {
1364 var MgcpCommand mgcp_cmd;
1365 var boolean respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1366 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1367 log("as_optional_mgcp_dlcx: rx MGCP DLCX");
1368 if (respond_to_dlcx) {
1369 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1370 }
1371 /* Without this 'repeat', currently active other interleave and alt series exit as soon as a
1372 * DLCX is handled. */
1373 repeat;
1374 }
1375}
1376
Philipp Maier3716a5e2018-03-21 15:53:35 +01001377function f_mo_call_establish(inout CallParameters cpars)
Harald Welteb71901a2018-01-26 19:16:05 +01001378runs on BSC_ConnHdlr {
1379
Harald Welteb71901a2018-01-26 19:16:05 +01001380 var MNCC_PDU mncc;
1381 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001382 var template MgcpResponse mgcp_resp;
Philipp Maier2a98a732018-03-19 16:06:12 +01001383 var boolean respond_to_dlcx;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001384 var PDU_BSSAP bssap;
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001385 var RANAP_PDU ranap;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001386 var MgcpOsmuxCID osmux_cid;
Harald Welteb71901a2018-01-26 19:16:05 +01001387
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001388 cpars.mo_call := true;
1389
Harald Welte0bef21e2018-02-10 09:48:23 +01001390 if (cpars.emergency) {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001391 f_establish_fully(EST_TYPE_EMERG_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001392 } else {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001393 f_establish_fully(EST_TYPE_MO_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001394 }
Harald Welteb71901a2018-01-26 19:16:05 +01001395
1396 /* Create MNCC and MGCP expect */
1397 f_create_mncc_expect(hex2str(cpars.called_party));
1398 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1399
Harald Welte0bef21e2018-02-10 09:48:23 +01001400 if (cpars.emergency) {
1401 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id)));
1402 } else {
1403 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party)));
1404 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001405
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001406 if (cpars.stop_after_cc_setup) {
1407 return;
1408 }
1409
1410 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001411 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001412
1413 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 +01001414 var boolean got_mncc_setup_compl_ind := false;
1415 var boolean got_cc_connect := false;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001416
Harald Welteb71901a2018-01-26 19:16:05 +01001417 interleave {
1418 [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001419 log("f_mo_call_establish 1: rx MNCC SETUP ind");
Harald Welteb71901a2018-01-26 19:16:05 +01001420 cpars.mncc_callref := mncc.u.signal.callref;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001421 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1422 }
1423
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001424 /* First MGCP CRCX */
Harald Welteb71901a2018-01-26 19:16:05 +01001425 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001426 log("f_mo_call_establish 2: rx 1st CRCX");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001427 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1428 break;
1429 }
Philipp Maierf1e02bb2018-03-15 16:30:00 +01001430 }
1431
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001432 /* Second MGCP CRCX */
1433 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
1434 log("f_mo_call_establish 6: rx 2nd CRCX");
1435 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1436 break;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001437 }
Harald Welteb71901a2018-01-26 19:16:05 +01001438 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001439
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001440 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1441 log("f_mo_call_establish 3: rx RTP CREATE");
1442 /* Call Proceeding */
1443 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1444 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001445
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001446 /* Alerting */
1447 MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref));
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001448 }
Harald Welte9b751a62019-04-14 17:39:29 +02001449
Neels Hofmeyreccaa992019-10-15 16:42:21 +02001450 //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001451 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001452 log("f_mo_call_establish 4: rx Assignment Request");
1453 var BSSMAP_IE_AoIP_TransportLayerAddress tla;
1454 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001455 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
1456
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001457 if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass)) {
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001458 log("Expected:", tla_ass);
1459 log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer);
1460 setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE");
1461 mtc.stop;
1462 }
1463
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001464 tla := valueof(f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001465 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001466 if (cpars.use_osmux) {
1467 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1468 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1469 mtc.stop;
1470 }
1471 osmuxCID := valueof(ts_OsmuxCID(0));
1472 if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1473 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1474 mtc.stop;
1475 }
1476 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1477 } else {
1478 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1479 }
1480 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001481 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001482 [] BSSAP.receive(tr_RANAP_RabAssReq(*)) -> value ranap {
1483 log("f_mo_call_establish 4.iu: rx RANAP RAB Assignment Request");
1484 var RAB_SetupOrModifiedList l := {
1485 {
1486 {
1487 id := id_RAB_SetupOrModifiedItem,
1488 criticality := ignore,
1489 value_ := {
1490 rAB_SetupOrModifiedItem := {
1491 rAB_ID := int2bit(23, 8),
1492 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1493 iuTransportAssociation := {
1494 bindingID := '040c0000'O
1495 },
1496 dl_dataVolumes := omit,
1497 iE_Extensions := omit
1498 }
1499 }
1500 }
1501 }
1502 };
1503 BSSAP.send(ts_RANAP_RabAssResp(l));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001504 }
Harald Welte9b751a62019-04-14 17:39:29 +02001505
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001506 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1507 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1508 log("f_mo_call_establish 5: rx MDCX for the RAN side");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001509 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 +01001510 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001511 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001512 { int2str(cpars.rtp_payload_type) },
1513 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1514 cpars.rtp_sdp_format)),
1515 valueof(ts_SDP_ptime(20)) }));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001516
1517 if (cpars.use_osmux) {
1518 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1519 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1520 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1521 mtc.stop;
1522 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001523 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 +02001524 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001525 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 +02001526 }
1527 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001528 }
Harald Welte9b751a62019-04-14 17:39:29 +02001529
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001530 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {
1531 log("f_mo_call_establish 7: rx CC Alerting");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001532
1533 if (cpars.ran_clear_when_alerting) {
1534 if (g_pars.ran_is_geran) {
1535 BSSAP.send(ts_BSSMAP_ClearRequest(0));
1536 } else {
1537 BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention));
1538 }
1539 break;
1540 }
1541
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001542 cpars.mncc_callref := mncc.u.signal.callref;
1543 /* Call Proceeding */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001544 var octetstring ip;
1545 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1546 if (is_ipv6) {
1547 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1548 } else {
1549 ip := f_inet_addr(cpars.mncc_rtp_ip);
1550 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001551 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001552 is_ipv6, ip,
1553 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001554 /* payload type 3 = GSM FR */ 3));
1555 MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref));
1556 }
1557
1558 [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc {
1559 log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001560 got_mncc_setup_compl_ind := true;
1561 if (not cpars.expect_release and got_cc_connect) {
1562 break;
1563 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001564 }
1565
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001566 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) {
1567 log("f_mo_call_establish 10: rx CC CONNECT");
1568 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id)));
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001569 got_cc_connect := true;
1570 if (not cpars.expect_release and got_mncc_setup_compl_ind) {
1571 break;
1572 }
Harald Welteb71901a2018-01-26 19:16:05 +01001573 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001574
1575 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1576 log("f_mo_call_establish 11: rx CC RELEASE");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001577 if (not cpars.expect_release) {
1578 setverdict(fail, "Got unexpected CC Release");
1579 mtc.stop;
1580 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001581 f_expect_clear();
1582 break;
1583 }
1584 }
1585
1586 f_sleep(0.5);
1587 deactivate(mdcx);
1588
1589 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1590 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1591 } else {
1592 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1593 mtc.stop;
Harald Welteb71901a2018-01-26 19:16:05 +01001594 }
1595
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001596 log("f_mo_call_establish DONE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001597 setverdict(pass);
1598}
Harald Welteb71901a2018-01-26 19:16:05 +01001599
Harald Welte4c422b72019-02-17 16:27:10 +01001600function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001601runs on BSC_ConnHdlr {
1602
1603 var MobileIdentityLV mi;
1604 var MNCC_PDU mncc;
1605 var MgcpCommand mgcp_cmd;
1606 var boolean respond_to_dlcx;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001607 var boolean dlcx_contained_ci := false;
1608 var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand;
1609
1610 if (is_csfb) {
1611 t_clear := tr_BSSMAP_ClearCommandCSFB;
1612 }
1613
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001614 log("f_call_hangup 0: tx MNCC_DISC_REQ");
Harald Welteb71901a2018-01-26 19:16:05 +01001615 MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1616 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1617
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001618 log("f_call_hangup 1: rx DTAP CC DISC");
1619
Philipp Maier3716a5e2018-03-21 15:53:35 +01001620 if (release_by_ms) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001621 var BIT1 tid_remote := '1'B;
1622 if (cpars.mo_call) {
1623 tid_remote := '0'B;
1624 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001625 /* B-side (MS) Release of call */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001626 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 +01001627 MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001628 log("f_call_hangup 2: rx MNCC REL ind");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001629 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001630 log("f_call_hangup 3: rx DTAP CC REL COMPL");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001631 } else {
1632 /* A-side (PLMN) Release of call */
1633 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42))));
1634 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001635 log("f_call_hangup 4: rx DTAP CC RELEASE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001636 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
1637 }
Harald Welteb71901a2018-01-26 19:16:05 +01001638
Philipp Maier2a98a732018-03-19 16:06:12 +01001639 respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1640
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001641 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 +01001642 var default dlcx := activate(as_optional_mgcp_dlcx(cpars));
Harald Welte9b751a62019-04-14 17:39:29 +02001643
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001644 /* clearing of radio channel */
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001645 alt {
1646 [g_pars.ran_is_geran] BSSAP.receive(t_clear) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001647 log("f_call_hangup 5: rx BSSAP Clear Command");
1648 BSSAP.send(ts_BSSMAP_ClearComplete);
1649 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1650 log("f_call_hangup 6: rx SCCP DISC");
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001651 setverdict(pass);
Philipp Maier2a98a732018-03-19 16:06:12 +01001652 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001653 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) {
1654 log("f_call_hangup 5.iu: rx Iu Release Command");
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001655 BSSAP.send(ts_RANAP_IuReleaseComplete);
1656 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001657 log("f_call_hangup 6.iu: rx SCCP DISC");
1658 setverdict(pass);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001659 }
1660 }
1661
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001662 f_sleep(1.0);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001663 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1664 log("f_call_hangup 9: done");
1665
1666 deactivate(mdcx);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001667 deactivate(dlcx);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001668}
1669
1670function f_mt_call(inout CallParameters cpars)
1671runs on BSC_ConnHdlr {
1672
1673 f_mt_call_establish(cpars);
1674
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001675 log("Hold the call for some time");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001676 f_sleep(3.0);
1677
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001678 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001679 f_call_hangup(cpars, true);
1680
1681 setverdict(pass);
1682}
1683
1684function f_mo_call(inout CallParameters cpars)
1685runs on BSC_ConnHdlr {
1686
1687 f_mo_call_establish(cpars);
1688
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001689 log("Hold the call for some time");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001690 f_sleep(3.0);
1691
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001692 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001693 f_call_hangup(cpars, false);
1694
Harald Welteb71901a2018-01-26 19:16:05 +01001695 setverdict(pass);
1696}
Harald Weltea49e36e2018-01-21 19:29:33 +01001697
Daniel Willmann8b084372018-02-04 13:35:26 +01001698function f_mo_seq_dtmf_dup(inout CallParameters cpars)
1699runs on BSC_ConnHdlr {
1700
1701 timer T := 1.0;
Daniel Willmann8b084372018-02-04 13:35:26 +01001702 var MNCC_PDU mncc;
1703 var MgcpCommand mgcp_cmd;
1704 var template PDU_ML3_MS_NW dtmf_dtap;
1705
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001706 f_mo_call_establish(cpars);
Daniel Willmann8b084372018-02-04 13:35:26 +01001707
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001708 /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by
1709 * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001710
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001711 /* Find out the next NSD that will be used, from RAN emulation. */
1712 var N_Sd_Array last_n_sd := f_bssmap_last_n_sd();
1713 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 +01001714
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001715 /* Compose DTAP with this correct NSD */
Daniel Willmann8b084372018-02-04 13:35:26 +01001716 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001717
1718 /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */
1719 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001720 T.start;
1721 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001722 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
1723 log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind");
1724 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001725 [] T.timeout {
1726 setverdict(fail, "Timeout waiting for START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001727 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001728 }
1729 }
1730
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001731 /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message
1732 * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */
1733 dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2);
Daniel Willmann92f66272018-02-06 15:50:52 +01001734 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true));
Daniel Willmann8b084372018-02-04 13:35:26 +01001735 T.start;
1736 alt {
1737 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001738 setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001739 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001740 }
1741 [] T.timeout { }
1742 }
1743
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001744 /* Here the NSD should be correct again and we see a DTMF. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001745 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001746 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001747 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001748 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) {
1749 log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind");
1750 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001751 [] T.timeout {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001752 setverdict(fail, "Timeout waiting for final START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001753 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001754 }
1755 }
1756
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001757 f_call_hangup(cpars, true);
Daniel Willmann8b084372018-02-04 13:35:26 +01001758 setverdict(pass);
1759}
Harald Welte9b751a62019-04-14 17:39:29 +02001760
Harald Welte1ddc7162018-01-27 14:25:46 +01001761/* expect a clear command */
Harald Welte5946b332018-03-18 23:32:21 +01001762altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr {
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001763 var PDU_BSSAP bssap;
Harald Welte5946b332018-03-18 23:32:21 +01001764 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1765 BSSAP.send(ts_BSSMAP_ClearComplete);
1766 alt {
Harald Welte6811d102019-04-14 22:23:14 +02001767 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte5946b332018-03-18 23:32:21 +01001768 setverdict(pass);
1769 }
1770 [] BSSAP.receive {
1771 setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001772 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001773 }
1774 }
1775 }
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001776 [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap {
1777 setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001778 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001779 }
1780}
1781
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001782function f_expect_clear(float t := 5.0, boolean verify_vlr_cell_id := true) runs on BSC_ConnHdlr {
Harald Welte1ddc7162018-01-27 14:25:46 +01001783 timer T := t;
1784
1785 T.start;
1786 alt {
Harald Welte9b751a62019-04-14 17:39:29 +02001787 [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { }
1788 [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { }
Harald Welte1ddc7162018-01-27 14:25:46 +01001789 [] T.timeout {
Harald Welte5946b332018-03-18 23:32:21 +01001790 setverdict(fail, "Timeout waiting for ClearCommand/Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001791 mtc.stop;
Harald Welte1ddc7162018-01-27 14:25:46 +01001792 }
1793 }
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001794
1795 if (verify_vlr_cell_id) {
1796 /* Now the conn is gone, but the VLR reflects the cell ID */
1797 f_verify_vty_lac_ci();
1798 }
Harald Welte1ddc7162018-01-27 14:25:46 +01001799}
1800
Neels Hofmeyr0ac63152019-05-07 01:20:17 +02001801function f_create_bssmap_exp_handoverRequest(integer targetPointCode) runs on BSC_ConnHdlr {
1802 BSSAP_PROC.call(RAN_register_handoverRequest:{targetPointCode, self}) {
1803 [] BSSAP_PROC.getreply(RAN_register_handoverRequest:{?, ?}) {};
1804 }
1805}
1806
1807function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array {
1808 var N_Sd_Array last_n_sd;
1809 BSSAP_PROC.call(RAN_last_n_sd:{self, -}) {
1810 [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) {
1811 return last_n_sd;
1812 };
1813 }
1814}
1815
1816function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr {
1817 BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) {
1818 [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self});
1819 }
1820}
1821
Harald Weltef45efeb2018-04-09 18:19:24 +02001822type record SmsParametersTp {
1823 OCT1 msg_ref,
1824 TP_DA da,
1825 OCT1 pid,
1826 OCT1 dcs,
1827 integer udl,
1828 octetstring ud
1829}
1830type record SmsParametersRp {
1831 OCT1 msg_ref,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001832 RP_NumberingPlan_and_NumberDigits smsc_addr optional
Harald Weltef45efeb2018-04-09 18:19:24 +02001833}
1834type record SmsParameters {
1835 SmsParametersTp tp,
1836 SmsParametersRp rp,
1837 uint3_t tid,
1838 OCT1 dlci,
1839 uint7_t exp_rp_err optional
1840}
1841
1842template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := {
1843 tP_DA_NoPad := {
1844 tP_LengthIndicator := 0, /* overwritten */
1845 tP_NumberingPlanID := npl,
1846 tP_TypeOfNumber := ton,
1847 tp_Spare := '0'B,
1848 tP_DAValue := addr
1849 }
1850}
1851
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001852template RP_NumberingPlan_and_NumberDigits t_RP_Addr(template hexstring addr,
1853 template BIT4 npi := '0001'B,
1854 template BIT3 ton := '001'B,
1855 template BIT1 ext := '1'B) := {
1856 rP_NumberingPlanIdentification := npi,
1857 rP_TypeOfNumber := ton,
1858 rP_Ext := ext,
1859 rP_NumberDigits := addr
1860}
1861
Harald Weltef45efeb2018-04-09 18:19:24 +02001862template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := {
1863 tp := {
1864 msg_ref := '23'O,
1865 da := ts_TP_DA('0000'B, '000'B, tp_daddr),
1866 pid := '00'O,
1867 dcs := '00'O,
1868 udl := 0,
1869 ud := ''O
1870 },
1871 rp := {
1872 msg_ref := '42'O,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001873 /* We don't really need to have both SM-RP-DA/OA here, because only one IE
Vadim Yanitskiyafb15a82020-01-05 14:04:53 +01001874 * is included in MO/MT SMS, and in the most cases it's the SMSC address.
1875 * NOTE: this address is currently hard-coded by OsmoMSC. */
1876 smsc_addr := t_RP_Addr('447785016005'H)
Harald Weltef45efeb2018-04-09 18:19:24 +02001877 },
1878 tid := 0,
1879 dlci := '03'O,
1880 exp_rp_err := omit
1881}
1882
1883private altstep as_other_sms() runs on BSC_ConnHdlr {
1884 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) {
1885 setverdict(fail, "Unexpected SMS related PDU from MSC");
Daniel Willmannafce8662018-07-06 23:11:32 +02001886 mtc.stop;
Harald Weltef45efeb2018-04-09 18:19:24 +02001887 }
1888}
1889
Vadim Yanitskiy9cc019a2018-11-15 02:06:07 +07001890/* Submit a MO RP-SMMA over an already existing DTAP connection */
1891function f_mo_smma(inout SmsParameters spars)
1892runs on BSC_ConnHdlr {
1893 var template (value) RPDU_MS_SGSN rp_mo;
1894 var template (value) PDU_ML3_MS_NW l3_mo;
1895
1896 var default d := activate(as_other_sms());
1897
1898 /* just in case this is routed to SMPP.. */
1899 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1900
1901 rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref);
1902 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1903 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1904 /* receive CP-ACK for CP-DATA above */
1905 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1906
1907 deactivate(d);
1908 setverdict(pass);
1909}
1910
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001911/* Submit a MO-SMS over an already existing DTAP connection */
1912function f_mo_sms_submit(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02001913runs on BSC_ConnHdlr {
1914 var template (value) TPDU_RP_DATA_MS_SGSN tp_mo;
1915 var template (value) RPDU_MS_SGSN rp_mo;
1916 var template (value) PDU_ML3_MS_NW l3_mo;
1917
Harald Weltef45efeb2018-04-09 18:19:24 +02001918 var default d := activate(as_other_sms());
1919
Harald Weltef640a012018-04-14 17:49:21 +02001920 /* just in case this is routed to SMPP.. */
1921 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1922
Harald Weltef45efeb2018-04-09 18:19:24 +02001923 tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs,
1924 spars.tp.udl, spars.tp.ud);
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001925 rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, omit, spars.rp.smsc_addr, tp_mo);
Harald Weltef45efeb2018-04-09 18:19:24 +02001926 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
1927 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1928 /* receive CP-ACK for CP-DATA above */
1929 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
1930
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001931 deactivate(d);
1932 setverdict(pass);
1933}
1934
1935/* Wait RP-ACK for MO-SMS on an already existing DTAP connection */
1936function f_mo_sms_wait_rp_ack(inout SmsParameters spars)
1937runs on BSC_ConnHdlr {
1938 var template (value) PDU_ML3_MS_NW l3_mo;
1939
1940 var template TPDU_RP_DATA_SGSN_MS tp_mt;
1941 var template RPDU_SGSN_MS rp_mt;
1942 var template PDU_ML3_NW_MS l3_mt;
1943
1944 var default d := activate(as_other_sms());
1945
1946 /* just in case this is routed to SMPP.. */
1947 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
1948
Harald Weltef45efeb2018-04-09 18:19:24 +02001949 if (ispresent(spars.exp_rp_err)) {
1950 /* expect an RP-ERROR message from MSC with given cause */
1951 rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err);
1952 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1953 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1954 /* send CP-ACK for CP-DATA just received */
1955 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1956 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1957 } else {
1958 /* expect RP-ACK for RP-DATA */
1959 rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref);
1960 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
1961 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
1962 /* send CP-ACO for CP-DATA just received */
1963 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
1964 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
1965 }
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001966
Harald Weltef45efeb2018-04-09 18:19:24 +02001967 deactivate(d);
1968 setverdict(pass);
1969}
1970
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07001971/* Submit a MO-SMS, and wait for RP-ACK on an existing
1972 * (and authenticated, ...) DTAP connection */
1973function f_mo_sms(inout SmsParameters spars)
1974runs on BSC_ConnHdlr {
1975 f_mo_sms_submit(spars);
1976 f_mo_sms_wait_rp_ack(spars);
1977}
1978
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01001979function f_mt_sms_deliver_pdu(in SmsParameters spars)
1980runs on BSC_ConnHdlr
1981return template PDU_DTAP_MT {
1982 var template TPDU_RP_DATA_SGSN_MS tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?);
1983 var template RPDU_SGSN_MS rp_mt := tr_RP_DATA_MT(?, spars.rp.smsc_addr, omit, tp_mt);
1984 var template PDU_ML3_NW_MS l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt));
1985 return tr_PDU_DTAP_MT(l3_mt, spars.dlci);
1986}
1987
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001988/* Wait for MT SMS on an already existing DTAP connection */
1989function f_mt_sms_expect(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02001990runs on BSC_ConnHdlr {
Harald Weltef45efeb2018-04-09 18:19:24 +02001991 var template (value) PDU_ML3_MS_NW l3_mo;
Harald Weltef45efeb2018-04-09 18:19:24 +02001992 var PDU_DTAP_MT dtap_mt;
1993
1994 var default d := activate(as_other_sms());
1995
1996 /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01001997 BSSAP.receive(f_mt_sms_deliver_pdu(spars)) -> value dtap_mt;
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07001998
Harald Weltef45efeb2018-04-09 18:19:24 +02001999 /* Extract relevant identifiers */
2000 spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio);
2001 spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference;
2002
2003 /* send CP-ACK for CP-DATA just received */
2004 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO);
2005 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2006
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002007 deactivate(d);
2008 setverdict(pass);
2009}
2010
2011/* Send RP-ACK for MT-SMS over an already existing DTAP connection */
2012function f_mt_sms_send_rp_ack(inout SmsParameters spars)
2013runs on BSC_ConnHdlr {
2014 var template (value) RPDU_MS_SGSN rp_mo;
2015 var template (value) PDU_ML3_MS_NW l3_mo;
2016 var template PDU_ML3_NW_MS l3_mt;
2017
2018 var default d := activate(as_other_sms());
2019
Harald Weltef45efeb2018-04-09 18:19:24 +02002020 /* send RP-ACK for RP-DATA */
2021 rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref);
2022 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2023 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2024
2025 /* expect CP-ACK for CP-DATA(RP-ACK) just sent */
Harald Weltee008eea2018-04-14 21:05:48 +02002026 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
Harald Weltef45efeb2018-04-09 18:19:24 +02002027 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2028
2029 deactivate(d);
2030 setverdict(pass);
2031}
2032
Vadim Yanitskiy56318522018-11-24 03:40:47 +07002033/* Send RP-ERROR for MT-SMS over an already existing DTAP connection */
2034function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause)
2035runs on BSC_ConnHdlr {
2036 var template (value) RPDU_MS_SGSN rp_mo;
2037 var template (value) PDU_ML3_MS_NW l3_mo;
2038 var template PDU_ML3_NW_MS l3_mt;
2039
2040 var default d := activate(as_other_sms());
2041
2042 /* send RP-ACK for RP-DATA */
2043 rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause);
2044 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2045 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2046
2047 /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */
2048 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
2049 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2050
2051 deactivate(d);
2052 setverdict(pass);
2053}
2054
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002055/* Wait for a MT-SMS and send RP-ACK over an already existing
2056 * (and authenticated, ...) DTAP connection */
2057function f_mt_sms(inout SmsParameters spars)
2058runs on BSC_ConnHdlr {
2059 f_mt_sms_expect(spars);
2060 f_mt_sms_send_rp_ack(spars);
2061}
Harald Weltea49e36e2018-01-21 19:29:33 +01002062
2063
Harald Weltea49e36e2018-01-21 19:29:33 +01002064}