blob: 92ec3b15502b91b1711554f0716c4eb76d8886ff [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;
Pau Espin Pedrol8f1403a2024-01-18 20:08:43 +010034import from GSUP_Templates all;
Harald Weltea49e36e2018-01-21 19:29:33 +010035import from GSUP_Emulation all;
36
37import from MNCC_Types all;
38import from MNCC_Emulation all;
39
Harald Welte4aa970c2018-01-26 10:38:09 +010040import from MGCP_Types all;
41import from MGCP_Emulation all;
Harald Welteb71901a2018-01-26 19:16:05 +010042import from MGCP_Templates all;
43import from SDP_Types all;
Harald Welte4aa970c2018-01-26 10:38:09 +010044
Harald Weltea49e36e2018-01-21 19:29:33 +010045import from MobileL3_Types all;
46import from MobileL3_CommonIE_Types all;
47import from MobileL3_MM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010048import from MobileL3_CC_Types all;
Harald Weltef45efeb2018-04-09 18:19:24 +020049import from MobileL3_SMS_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010050import from L3_Templates all;
Harald Welte158a7ca2018-02-16 18:11:31 +010051import from L3_Common all;
Harald Weltea49e36e2018-01-21 19:29:33 +010052
Harald Weltef640a012018-04-14 17:49:21 +020053import from SMPP_Emulation all;
54
Philipp Maieraeb29a82018-11-08 17:40:53 +010055import from IPA_Emulation all;
56import from Osmocom_CTRL_Functions all;
57import from Osmocom_CTRL_Types all;
58import from Osmocom_CTRL_Adapter all;
59
Philipp Maierc39a9d82018-11-09 11:21:08 +010060import from TELNETasp_PortType all;
61import from Osmocom_VTY_Functions all;
62
Harald Welte4263c522018-12-06 11:56:27 +010063import from SGsAP_Emulation all;
64
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +020065import from TCCConversion_Functions { function f_strstr };
66
Neels Hofmeyrf797d292021-07-27 22:33:09 +020067type port BSC_ConnHdlr_Coord_PT message
68{
69 inout charstring, CallParameters;
70} with { extension "internal" };
71
72
Harald Weltea49e36e2018-01-21 19:29:33 +010073/* this component represents a single subscriber connection */
Harald Welte6811d102019-04-14 22:23:14 +020074type 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 +010075 var BSC_ConnHdlrPars g_pars;
Harald Weltea10db902018-01-27 12:44:49 +010076 timer g_Tguard := 60.0;
Philipp Maierc39a9d82018-11-09 11:21:08 +010077 port TELNETasp_PT MSCVTY;
Neels Hofmeyrf797d292021-07-27 22:33:09 +020078 port BSC_ConnHdlr_Coord_PT COORD;
Harald Weltea49e36e2018-01-21 19:29:33 +010079}
80
Harald Weltede371492018-01-27 23:44:41 +010081type record BSC_ConnHdlrNetworkPars {
Neels Hofmeyre860fc42022-10-05 01:15:54 +020082 /* Bitmask of expected A5 levels; in Ciphering, will expect use of the highest A5 remaining after masking this
83 * with A5 supported by the MS */
Harald Weltede371492018-01-27 23:44:41 +010084 OCT1 kc_support,
Neels Hofmeyre860fc42022-10-05 01:15:54 +020085 /* osmo-msc VTY cfg under 'network': If a test wants to temporarily modify auth and encr config, this is the
86 * original config to return to for this test (is *not* sent to vty before the test, but maybe it should).
87 * For example: { "authentication optional", "encryption a5 0 3" } */
88 rof_charstring net_config,
89 /* expect_attach_success == true: expect Location Updating / CM Service Request to succeed.
90 * expect_attach_success == false: expect the MSC to reject LU / CM Service. */
91 boolean expect_attach_success,
92 /* expect_tmsi == true: expect MSC to allocate a new TMSI.
93 * expect_tmsi == false: expect no TMSI to be assigned, operate with IMSI Mobile Identity. */
Harald Weltede371492018-01-27 23:44:41 +010094 boolean expect_tmsi,
Neels Hofmeyre860fc42022-10-05 01:15:54 +020095 /* expect_auth == true overrides expect_auth_attempt == false */
96 boolean expect_auth_attempt,
97 /* hlr_has_auth_info has an effect only when (expect_auth_attempt or expect_auth) == true.
98 * hlr_has_auth_info == false means the HLR responds to Send Auth Info Request with a NACK. */
99 boolean hlr_has_auth_info,
Harald Weltede371492018-01-27 23:44:41 +0100100 boolean expect_auth,
Oliver Smith1d118ff2019-07-03 10:57:35 +0200101 boolean expect_ciph,
102 boolean expect_imei,
103 boolean expect_imei_early,
104 GSUP_IMEIResult check_imei_result,
105 boolean check_imei_error
Harald Weltede371492018-01-27 23:44:41 +0100106}
107
Harald Weltea49e36e2018-01-21 19:29:33 +0100108type record BSC_ConnHdlrPars {
109 SCCP_PAR_Address sccp_addr_own,
110 SCCP_PAR_Address sccp_addr_peer,
111 BSSMAP_IE_CellIdentifier cell_id,
Harald Welte256571e2018-01-24 18:47:19 +0100112 hexstring imei,
Harald Weltea49e36e2018-01-21 19:29:33 +0100113 hexstring imsi,
Harald Welte82600572018-01-21 20:54:08 +0100114 hexstring msisdn,
Harald Welte256571e2018-01-24 18:47:19 +0100115 OCT4 tmsi optional,
Harald Welte9de84792018-01-28 01:06:35 +0100116 MobileStationClassmark1_V cm1,
Harald Welte82600572018-01-21 20:54:08 +0100117 BSSMAP_IE_ClassmarkInformationType2 cm2,
Harald Welte16114282018-01-24 22:41:21 +0100118 BSSMAP_IE_ClassmarkInformationType3 cm3 optional,
Harald Weltede371492018-01-27 23:44:41 +0100119 AuthVector vec optional,
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +0200120 /* BSC_ConnectionHandler generates an auth vector in as_GSUP_SAI(). For tests that want control over which
121 * vector is used, pass vec_keep := true to not regenerate a new auth vector in as_GSUP_SAI(). */
122 boolean vec_keep,
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100123 BSC_ConnHdlrNetworkPars net,
Philipp Maieraeb29a82018-11-08 17:40:53 +0100124 boolean send_early_cm,
125 charstring ipa_ctrl_ip,
126 integer ipa_ctrl_port,
Philipp Maier9b690e42018-12-21 11:50:03 +0100127 boolean ipa_ctrl_enable,
Philipp Maier57865482019-01-07 18:33:13 +0100128 boolean mm_info,
Philipp Maierc09a1312019-04-09 16:05:26 +0200129 boolean sgsap_enable,
Harald Weltef9abf8d2019-04-21 13:07:17 +0200130 boolean gsup_enable,
Vadim Yanitskiy2dd96612020-01-07 21:48:29 +0100131 OCT4 gsup_sid,
Harald Weltec1f937a2019-04-21 21:19:23 +0200132 integer ran_idx,
Harald Welte9b751a62019-04-14 17:39:29 +0200133 boolean use_umts_aka,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200134 boolean ran_is_geran,
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200135 boolean use_osmux,
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200136 boolean use_ipv6,
Oliver Smith44424db2023-08-22 13:54:09 +0200137 boolean use_csd,
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200138 boolean verify_cell_id,
139 OCT3 common_id_last_eutran_plmn optional
Harald Weltea49e36e2018-01-21 19:29:33 +0100140};
141
Harald Welte9de84792018-01-28 01:06:35 +0100142/* get a one-octet bitmaks of supported algorithms based on Classmark information */
Eric Wild26f4a622021-05-17 15:27:05 +0200143function 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 +0100144 var BIT8 res := '00000001'B; /* A5/0 always supported */
145
146 if (cm2.a5_1 == '0'B) {
147 res := res or4b '00000010'B;
148 }
149 if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) {
150 res := res or4b '00000100'B;
151 }
152 if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) {
153 res := res or4b '00001000'B;
154 }
Eric Wild26f4a622021-05-17 15:27:05 +0200155 if (not istemplatekind(cm3, "omit")) {
156 var BSSMAP_IE_ClassmarkInformationType3 v := valueof(cm3);
157 var BIT8 tmp := oct2bit(v.classmark3ValuePart[0]) and4b '00001111'B;
158 res := res or4b (tmp << 4);
159 }
160
Harald Welte9de84792018-01-28 01:06:35 +0100161 return bit2oct(res);
162}
163
164/* determine the best algorithm available within the bit-mask */
165function f_best_alg_from_mask(OCT1 alg_in) return OCT1 {
166 var BIT8 alg := oct2bit(alg_in);
167 var BIT8 ordered_algs[8] := {
168 '10000000'B, '01000000'B, '00100000'B, '00010000'B,
169 '00001000'B, /* A5/3 */
170 '00000010'B, /* A5/1 */
171 '00000100'B, /* A5/2 */
172 '00000001'B /* A5/0 */ }
173 for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) {
174 if (alg and4b ordered_algs[i] != '00000000'B) {
175 return bit2oct(ordered_algs[i]);
176 }
177 }
178 return '00'O;
179}
180
181/* return an integer like '1' for A5/1 based on a mask (with only one bit set */
182function f_alg_from_mask(OCT1 mask_in) return integer {
183 var BIT8 mask := oct2bit(mask_in);
184 for (var integer i := 0; i < 8; i := i+1) {
185 if (mask and4b ('00000001'B << i) != '00000000'B) {
186 return i;
187 }
188 }
189 return -1;
190}
191
Eric Wild26f4a622021-05-17 15:27:05 +0200192/* return true for A5/x supported by OCT1 bitmask */
193function f_alg_supported_by_mask(OCT1 mask_in, integer whicha5) return boolean {
194 var BIT8 mask := oct2bit(mask_in);
195 if (mask and4b ('00000001'B << whicha5) != '00000000'B) {
196 return true;
197 }
198 return false;
199}
200
Harald Weltea10db902018-01-27 12:44:49 +0100201/* altstep for the global guard timer */
202private altstep as_Tguard() runs on BSC_ConnHdlr {
203 [] g_Tguard.timeout {
Daniel Willmann90829d62018-02-15 17:45:14 +0100204 setverdict(fail, "Tguard timeout");
Daniel Willmannafce8662018-07-06 23:11:32 +0200205 mtc.stop;
Harald Weltea10db902018-01-27 12:44:49 +0100206 }
207}
208
209/* init function, called as first function in new BSC_ConnHdlr */
Harald Weltead2952e2018-01-27 14:12:46 +0100210function f_init_handler(BSC_ConnHdlrPars pars, float t_guard := 60.0) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100211 /* make parameters available via component variable */
212 g_pars := pars;
213 /* Start guard timer and activate it as default */
Harald Weltead2952e2018-01-27 14:12:46 +0100214 g_Tguard.start(t_guard);
Harald Weltea10db902018-01-27 12:44:49 +0100215 activate(as_Tguard());
Harald Weltef640a012018-04-14 17:49:21 +0200216 /* Route all SMPP messages for our MSISDN to us */
217 f_create_smpp_expect(hex2str(pars.msisdn));
Philipp Maier57865482019-01-07 18:33:13 +0100218
Harald Welte4263c522018-12-06 11:56:27 +0100219 /* Route all SGs message for our IMSI to us */
Philipp Maier57865482019-01-07 18:33:13 +0100220 if (g_pars.sgsap_enable == true) {
221 f_create_sgsap_expect(pars.imsi);
222 }
Philipp Maieraeb29a82018-11-08 17:40:53 +0100223
224 if (g_pars.ipa_ctrl_enable == true) {
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100225 f_ipa_ctrl_start_client(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port);
Philipp Maieraeb29a82018-11-08 17:40:53 +0100226 }
Philipp Maierc39a9d82018-11-09 11:21:08 +0100227
228 map(self:MSCVTY, system:MSCVTY);
229 f_vty_set_prompts(MSCVTY);
230 f_vty_transceive(MSCVTY, "enable");
Harald Weltea10db902018-01-27 12:44:49 +0100231}
232
Harald Weltea49e36e2018-01-21 19:29:33 +0100233
Harald Welte6811d102019-04-14 22:23:14 +0200234/* Callback function from general RAN_Emulation whenever a connectionless
Harald Weltea49e36e2018-01-21 19:29:33 +0100235 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
236private function BscUnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200237runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Weltea49e36e2018-01-21 19:29:33 +0100238 var template PDU_BSSAP resp := omit;
239
240 log("BSSMAP_BscUnitdataCallback");
241 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200242 if (match(bssap, tr_BSSMAP_Reset(g_ran_ops.use_osmux))){
Harald Weltea49e36e2018-01-21 19:29:33 +0100243 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200244 resp := ts_BSSMAP_ResetAck(g_ran_ops.use_osmux);
Harald Weltea49e36e2018-01-21 19:29:33 +0100245 }
246
247 /* FIXME: Handle paging, etc. */
248 return resp;
249}
250
Harald Welte9b751a62019-04-14 17:39:29 +0200251private function RncUnitdataCallback(RANAP_PDU ranap)
252runs on RAN_Emulation_CT return template RANAP_PDU {
253 var template RANAP_PDU resp := omit;
254
255 log("RANAP_RncUnitdataCallback");
256 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200257 if (match(ranap, tr_RANAP_Reset())) {
Harald Welte9b751a62019-04-14 17:39:29 +0200258 log("RANAP_RncUnitdataCallback: Responding to RESET with RESET-ACK");
259 var CN_DomainIndicator dom;
260 dom := ranap.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator;
261 resp := ts_RANAP_ResetAck(dom);
262 }
263
264 /* FIXME: Handle paging, etc. */
265 return resp;
266}
267
268
Harald Welte6811d102019-04-14 22:23:14 +0200269const RanOps BSC_RanOps := {
Harald Weltea49e36e2018-01-21 19:29:33 +0100270 /* Create call-back for inbound connections from MSC (hand-over) */
Harald Welte6811d102019-04-14 22:23:14 +0200271 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Weltea49e36e2018-01-21 19:29:33 +0100272 unitdata_cb := refers(BscUnitdataCallback),
Harald Welte9b751a62019-04-14 17:39:29 +0200273 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
274 ranap_unitdata_cb := refers(RncUnitdataCallback),
275 ps_domain := false,
Harald Weltea49e36e2018-01-21 19:29:33 +0100276 decode_dtap := true,
Harald Weltea4ca4462018-02-09 00:17:14 +0100277 role_ms := true,
Harald Welte2fce7882019-04-15 11:48:05 +0200278 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200279 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200280 use_osmux := false,
Eric Wild49888a62022-03-30 03:16:11 +0200281 bssap_reset_retries := 1,
Harald Weltea4ca4462018-02-09 00:17:14 +0100282 sccp_addr_local := omit,
283 sccp_addr_peer := omit
Harald Weltea49e36e2018-01-21 19:29:33 +0100284}
285
286
287private function MnccUnitdataCallback(MNCC_PDU mncc)
288runs on MNCC_Emulation_CT return template MNCC_PDU {
289 log("Ignoring MNCC", mncc);
290 return omit;
291}
292
293const MnccOps BCC_MnccOps := {
294 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
295 unitdata_cb := refers(MnccUnitdataCallback)
296}
297
298
299
Harald Welte6811d102019-04-14 22:23:14 +0200300/* Encode 'l3' and ask RAN_Emulation to create new connection with COMPL L3 INFO */
Harald Weltea49e36e2018-01-21 19:29:33 +0100301function f_bssap_compl_l3(PDU_ML3_MS_NW l3)
302runs on BSC_ConnHdlr {
303 log("Sending COMPL L3: ", l3);
304 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
305 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
306 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc))));
Harald Welte71b69332018-01-21 20:43:53 +0100307 alt {
Harald Welte6811d102019-04-14 22:23:14 +0200308 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
309 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte71b69332018-01-21 20:43:53 +0100310 setverdict(fail, "DISC.ind from SCCP");
Daniel Willmannafce8662018-07-06 23:11:32 +0200311 mtc.stop;
Harald Welte71b69332018-01-21 20:43:53 +0100312 }
313 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100314}
315
Harald Welte9b751a62019-04-14 17:39:29 +0200316/* generate Iu LAI from BSSAP CGI */
317private function f_IuLAI_from_BssmapCI(BSSMAP_IE_CellIdentifier ci) return LAI {
318 var LAI lai;
319 if (ischosen(ci.cellIdentification.cI_CGI)) {
320 lai.pLMNidentity := ci.cellIdentification.cI_CGI.mcc_mnc;
321 lai.lAC := ci.cellIdentification.cI_CGI.lac;
322 } else if (ischosen(ci.cellIdentification.cI_SAI)) {
323 lai.pLMNidentity := ci.cellIdentification.cI_SAI.mcc_mnc;
324 lai.lAC := ci.cellIdentification.cI_SAI.lac;
325 } else if (ischosen(ci.cellIdentification.ci_LAC_RNC_CI)) {
326 lai.pLMNidentity := ci.cellIdentification.ci_LAC_RNC_CI.mcc_mnc;
327 lai.lAC := ci.cellIdentification.ci_LAC_RNC_CI.lac;
328 } else {
329 mtc.stop;
330 }
331 lai.iE_Extensions := omit;
332 return lai;
333}
334
335/* like f_bssap_compl_l3() but for 3G */
336function f_ranap_initial_ue(PDU_ML3_MS_NW l3)
337runs on BSC_ConnHdlr {
338 log("Sending InitialUE: ", l3);
339 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
340 var RANAP_PDU ranap;
341 var LAI lai := f_IuLAI_from_BssmapCI(g_pars.cell_id);
342 var SAI sai := {
343 pLMNidentity := lai.pLMNidentity,
344 lAC := lai.lAC,
345 sAC := '0000'O, /* FIXME */
346 iE_Extensions := omit
347 };
348 var IuSignallingConnectionIdentifier sigc_id := int2bit(23, 24);
349 var GlobalRNC_ID grnc_id := {
350 pLMNidentity := lai.pLMNidentity,
351 rNC_ID := 2342 /* FIXME */
352 };
353
354 ranap := valueof(ts_RANAP_initialUE_CS(lai, sai, l3_enc, sigc_id, grnc_id));
355 BSSAP.send(ts_RANAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, ranap));
356 alt {
357 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
358 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
359 setverdict(fail, "DISC.ind from SCCP");
360 mtc.stop;
361 }
362 }
363}
364
Harald Weltedceacc72019-04-21 20:58:35 +0200365/* Send BSSMAP Complete L3 or RANAP Initial UE depending on 2G/3G RAN type */
366function f_cl3_or_initial_ue(PDU_ML3_MS_NW l3)
367runs on BSC_ConnHdlr {
368 if (g_pars.ran_is_geran) {
369 f_bssap_compl_l3(l3);
370 } else {
371 f_ranap_initial_ue(l3);
372 }
373}
374
Harald Welte081b19a2018-02-10 09:11:13 +0100375type enumerated EstablishType {
376 EST_TYPE_MO_CALL,
Harald Welte0bef21e2018-02-10 09:48:23 +0100377 EST_TYPE_EMERG_CALL,
Harald Weltef45efeb2018-04-09 18:19:24 +0200378 EST_TYPE_PAG_RESP,
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700379 EST_TYPE_MO_SMS,
Oliver Smith92b280c2023-04-20 13:13:23 +0200380 EST_TYPE_SS_ACT,
Andreas Eversberg5ada75d2023-07-27 16:24:38 +0200381 EST_TYPE_MO_CSD,
382 EST_TYPE_VGCS,
383 EST_TYPE_VBS
Harald Welte081b19a2018-02-10 09:11:13 +0100384};
385
Harald Weltea49e36e2018-01-21 19:29:33 +0100386/* helper function to fully establish a dedicated channel */
Harald Welteb9e86fa2018-04-09 18:18:31 +0200387function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL)
Harald Weltea49e36e2018-01-21 19:29:33 +0100388runs on BSC_ConnHdlr {
Harald Welte081b19a2018-02-10 09:11:13 +0100389 var PDU_ML3_MS_NW l3_info;
Harald Welteb9e86fa2018-04-09 18:18:31 +0200390 var MobileIdentityLV mi;
391
392 /* If we have a TMSI, use TMSI instead of IMSI */
393 if (ispresent(g_pars.tmsi)) {
394 mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi));
395 } else {
396 mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
397 }
398
Harald Welte081b19a2018-02-10 09:11:13 +0100399 select (etype) {
400 case (EST_TYPE_MO_CALL) {
401 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
402 }
Oliver Smith92b280c2023-04-20 13:13:23 +0200403 case (EST_TYPE_MO_CSD) {
404 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
405 }
Harald Welte0bef21e2018-02-10 09:48:23 +0100406 case (EST_TYPE_EMERG_CALL) {
407 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi));
408 }
Harald Welte081b19a2018-02-10 09:11:13 +0100409 case (EST_TYPE_PAG_RESP) {
410 l3_info := valueof(ts_PAG_RESP(mi));
411 }
Harald Weltef45efeb2018-04-09 18:19:24 +0200412 case (EST_TYPE_MO_SMS) {
413 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi));
414 }
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700415 case (EST_TYPE_SS_ACT) {
416 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi));
417 }
Andreas Eversberg5ada75d2023-07-27 16:24:38 +0200418 case (EST_TYPE_VGCS) {
419 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_VGCS, mi));
420 }
421 case (EST_TYPE_VBS) {
422 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_VBS, mi));
423 }
Harald Welte081b19a2018-02-10 09:11:13 +0100424 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100425
426 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Weltedceacc72019-04-21 20:58:35 +0200427 f_cl3_or_initial_ue(l3_info);
Harald Weltea49e36e2018-01-21 19:29:33 +0100428
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200429 f_verify_vty_lac_ci(verify_vlr := false);
430
Harald Weltede371492018-01-27 23:44:41 +0100431 f_mm_common();
Pau Espin Pedrolf8034482019-06-03 13:15:58 +0200432 if (g_pars.net.expect_ciph or not g_pars.ran_is_geran) {
Harald Welte148a7082018-01-26 18:56:43 +0100433 /* implicit CM SERVICE ACCEPT? */
434 } else {
Harald Welte0bef21e2018-02-10 09:48:23 +0100435 if (etype != EST_TYPE_PAG_RESP) {
Harald Welte081b19a2018-02-10 09:11:13 +0100436 /* explicit CM SERVICE ACCEPT */
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200437 if (g_pars.net.expect_attach_success) {
438 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
439 } else {
440 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_REJ));
441 }
Harald Welte081b19a2018-02-10 09:11:13 +0100442 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100443 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100444}
445
446/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
Harald Welte9de84792018-01-28 01:06:35 +0100447function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100448{
449 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
450 return f_build_lu(mi);
451}
Harald Welte9de84792018-01-28 01:06:35 +0100452function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100453{
454 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
455 return f_build_lu(mi);
456}
Harald Welte9de84792018-01-28 01:06:35 +0100457function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100458{
459 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
460 return f_build_lu(mi);
461}
Harald Welte9de84792018-01-28 01:06:35 +0100462private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100463{
464 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
465 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 +0100466 old_lai, mi, g_pars.cm1));
Harald Weltea49e36e2018-01-21 19:29:33 +0100467 return l3_info;
468}
469
Harald Weltea183a5d2019-05-09 13:40:52 +0200470altstep as_GSUP_SAI() runs on BSC_ConnHdlr {
471var GSUP_IE auth_tuple;
472[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)) {
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200473 if (g_pars.net.hlr_has_auth_info) {
474 if (g_pars.use_umts_aka) {
475 if (not g_pars.vec_keep) {
476 g_pars.vec := f_gen_auth_vec_3g();
477 }
478 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand,
479 g_pars.vec.sres,
480 g_pars.vec.kc,
481 g_pars.vec.ik,
482 g_pars.vec.ck,
483 g_pars.vec.autn,
484 g_pars.vec.res));
485 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
486 } else {
487 if (not g_pars.vec_keep) {
488 g_pars.vec := f_gen_auth_vec_2g();
489 }
490 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand,
491 g_pars.vec.sres,
492 g_pars.vec.kc));
493 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +0200494 }
Harald Weltea183a5d2019-05-09 13:40:52 +0200495 } else {
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200496 log("XXX ts_GSUP_SAI_ERR");
497 /* HLR knows the IMSI but has no authentication info; osmo-hlr responds with GMM_CAUSE_IMSI_UNKNOWN=2 in
498 * this case, for SAI this merely means there is no auth entry for this IMSI. */
499 GSUP.send(ts_GSUP_SAI_ERR(g_pars.imsi, 2));
Harald Weltea183a5d2019-05-09 13:40:52 +0200500 }
501 }
502}
503
Harald Welte9de84792018-01-28 01:06:35 +0100504function f_mm_auth() runs on BSC_ConnHdlr
Harald Welte148a7082018-01-26 18:56:43 +0100505{
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200506 if (g_pars.net.expect_auth or g_pars.net.expect_auth_attempt) {
Harald Weltea183a5d2019-05-09 13:40:52 +0200507 as_GSUP_SAI();
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200508 }
509 if (g_pars.net.expect_auth) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200510 if (g_pars.use_umts_aka) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200511 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn)));
512 var OCT4 res := substr(g_pars.vec.res, 0, 4);
513 var OCT4 xres := substr(g_pars.vec.res, 4, 4);
514 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres)));
515 } else {
Harald Weltec1f937a2019-04-21 21:19:23 +0200516 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand)));
517 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres)));
518 }
Harald Welte148a7082018-01-26 18:56:43 +0100519 }
Harald Welte9de84792018-01-28 01:06:35 +0100520}
Harald Welte148a7082018-01-26 18:56:43 +0100521
Oliver Smith1d118ff2019-07-03 10:57:35 +0200522function f_mm_imei() runs on BSC_ConnHdlr
523{
524 var PDU_DTAP_MT dtap_mt;
525 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700526 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200527
528 if (not g_pars.net.expect_imei) {
529 return
530 }
531
532 /* MSC <-> BSC: ID req/rsp for IMEI */
533 alt {
534 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEI))) {
535 mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
536 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
537 }
538 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
539 setverdict(fail, "Expected ID REQ for IMEI DTAP MT message, but got: ", dtap_mt);
540 mtc.stop;
541 }
542 }
543
544 /* MSC <-> HLR: Check IMEI req/res/err */
545 alt {
546 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
547 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
548 }
549 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
550 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
551 }
552 [] GSUP.receive(?) -> value gsup_msg {
553 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
554 g_pars.imsi, "), but got: ", gsup_msg);
555 mtc.stop;
556 }
557 }
558}
559
560function f_mm_imei_early() runs on BSC_ConnHdlr
561{
562 var PDU_DTAP_MT dtap_mt;
563 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700564 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200565
566 if (not g_pars.net.expect_imei_early) {
567 return
568 }
569
570 /* MSC <-> BSC: ID req/rsp for IMEISV */
571 alt {
572 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEISV))) {
573 mi := valueof(ts_MI_IMEISV_LV(g_pars.imei));
574 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
575 }
576 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
577 setverdict(fail, "Expected ID REQ for IMEISV DTAP MT message, but got: ", dtap_mt);
578 mtc.stop;
579 }
580 }
581
582 /* MSC <-> HLR: Check IMEI req/res/err */
583 alt {
584 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
585 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
586 }
587 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
588 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
589 }
590 [] GSUP.receive(?) -> value gsup_msg {
591 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
592 g_pars.imsi, "), but got: ", gsup_msg);
593 mtc.stop;
594 }
595 }
596}
597
Harald Welte79f1e452020-08-18 22:55:02 +0200598function f_expect_common_id() runs on BSC_ConnHdlr
599{
600 if (g_pars.ran_is_geran) {
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200601 BSSAP.receive(tr_BSSMAP_CommonId(g_pars.imsi,
602 f_tr_BSSMAP_LastUsedEUTRANPLMNId(g_pars.common_id_last_eutran_plmn)));
Harald Welte79f1e452020-08-18 22:55:02 +0200603 } else {
604 BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
605 }
606}
607
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200608/* For UMTS AKA on GERAN, calculate the specific kc from the UMTS AKA ck and ik vectors. */
609function f_auth3g_kc(AuthVector vec) return OCT8 {
Eric Wild26f4a622021-05-17 15:27:05 +0200610 var integer i;
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200611 var octetstring res := vec.ck[0] xor4b vec.ck[0 + 8] xor4b vec.ik[0] xor4b vec.ik[0 + 8];
Eric Wild26f4a622021-05-17 15:27:05 +0200612 for (i := 1; i < 8; i := i + 1) {
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200613 var octetstring a := vec.ck[i] xor4b vec.ck[i + 8] xor4b vec.ik[i] xor4b vec.ik[i + 8];
Eric Wild26f4a622021-05-17 15:27:05 +0200614 res := res & a;
615 }
616
617 return res;
618}
619
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200620function f_get_expected_encryption(
621 out template BSSMAP_IE_EncryptionInformation encryptionInformation,
622 out template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm,
623 out template BSSMAP_IE_KC128 kC128,
624 out OCT1 a5_perm_alg) runs on BSC_ConnHdlr
625{
626 var OCT1 a5_ms := f_alg_mask_from_cm(g_pars.cm2, g_pars.cm3);
627 a5_perm_alg := g_pars.net.kc_support and4b a5_ms;
628
629 if (not g_pars.net.expect_ciph) {
630 encryptionInformation := *;
631 chosenEncryptionAlgorithm := *;
632 kC128 := *;
633 return;
634 }
635
Neels Hofmeyrf6eff812021-06-23 23:29:39 +0200636 var OCT8 kc;
637 if (g_pars.use_umts_aka) {
638 kc := f_auth3g_kc(g_pars.vec);
639 } else {
640 kc := g_pars.vec.kc;
641 }
642 encryptionInformation := tr_BSSMAP_IE_EncrInfo(kc, a5_perm_alg);
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200643
644 var OCT1 chosen_alg := int2oct(f_alg_from_mask(f_best_alg_from_mask(a5_perm_alg)) + 1, 1);
645 chosenEncryptionAlgorithm := tr_BSSMAP_IE_ChosenEncryptionAlgorithm(chosen_alg);
646
647 if (g_pars.use_umts_aka and f_alg_supported_by_mask(a5_perm_alg, 4)) {
648 /* A5/4 is permitted, expecting kc128 to be present */
649 var OCT32 full_sha256 := f_calculate_HMAC_SHA256(g_pars.vec.ck & g_pars.vec.ik, '32'O, 32);
650 var OCT16 expect_kc128 := substr(full_sha256, 0, 16);
651 kC128 := tr_BSSMAP_IE_Kc128(expect_kc128);
652 } else {
653 kC128 := omit
654 }
655}
656
Eric Wild26f4a622021-05-17 15:27:05 +0200657
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300658private function f_mm_ciph_geran() runs on BSC_ConnHdlr
659{
660 var template BSSMAP_IE_EncryptionInformation encryptionInformation;
661 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm;
662 var template BSSMAP_IE_KC128 kC128;
663 var OCT1 a5_perm_alg;
664 var PDU_BSSAP pdu;
665
Vadim Yanitskiy172bc6e2021-12-06 17:54:57 +0300666 if (not g_pars.net.expect_ciph) {
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300667 /* There is nothing to do */
668 return;
669 }
670
671 f_get_expected_encryption(encryptionInformation, chosenEncryptionAlgorithm, kC128, a5_perm_alg);
672 alt {
673 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128)) -> value pdu {
674 var OCT1 a5_chosen := f_best_alg_from_mask(a5_perm_alg);
675 var integer a5_nr := f_alg_from_mask(a5_chosen);
676 BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
677 }
678 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2) -> value pdu {
679 log("Error: Ciphering Mode Command with unexpected content. Expected: ",
680 tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128), " got: ", pdu);
681 setverdict(fail, "Ciphering Mode Command with unexpected content.");
682 mtc.stop;
683 }
684 [] BSSAP.receive(tr_BSSMAP_ClassmarkRequest) {
685 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3))
686 repeat;
687 }
688 }
689 /* FIXME: Send the best available algorithm */
690}
691
692private function f_mm_ciph_utran() runs on BSC_ConnHdlr
693{
694 alt {
695 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
696 uia_key := oct2bit(g_pars.vec.ik),
697 key_sts := ?,
698 uea_algs := ?,
699 uea_key := oct2bit(g_pars.vec.ck))) {
700 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/
701 var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/
702 BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen));
703 }
704 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
705 setverdict(fail, "Invalid SecurityModeCommand (ciphering case)");
706 mtc.stop;
707 }
708 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
709 uia_key := oct2bit(g_pars.vec.ik),
710 key_sts := ?)) {
711 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/
712 BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
713 }
714 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
715 setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)");
716 mtc.stop;
717 }
718 }
719}
720
Harald Welte9de84792018-01-28 01:06:35 +0100721function f_mm_common() runs on BSC_ConnHdlr
722{
723 f_mm_auth();
Eric Wild26f4a622021-05-17 15:27:05 +0200724
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300725 if (g_pars.ran_is_geran) {
726 f_mm_ciph_geran();
727 } else {
728 f_mm_ciph_utran();
Harald Welte148a7082018-01-26 18:56:43 +0100729 }
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300730
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200731 if (not g_pars.net.expect_attach_success) {
732 return;
733 }
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300734 f_expect_common_id();
Harald Welte148a7082018-01-26 18:56:43 +0100735}
736
Philipp Maier9b690e42018-12-21 11:50:03 +0100737function f_expect_mm_info() runs on BSC_ConnHdlr {
738 if (g_pars.mm_info == true) {
739 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info));
740 }
741}
742
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200743private function f_lac_ci_vty_str(BSSMAP_IE_CellIdentifier cell_id) return charstring
744{
745 return "LAC / cell ID: "
746 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.lac)) & " / "
747 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.ci));
748}
749
750/* Get an IMSI's info and verify that the g_pars.cell_id is reflected in the info.
751 * Verify both the "LAC / cell ID" in the VLR and the "LAC / cell ID" in the "Connection:" part, if any.
752 * If verify_vlr == false, then only verify the "Connection:" part, and fail if there is no "Connection:"; this is
753 * useful when a conn has been established, but the subscriber has not been authenticated, so the VLR does not yet
754 * reflect the new conn's cell ID.
755 */
756function f_verify_vty_lac_ci(boolean verify_vlr := true) runs on BSC_ConnHdlr {
757 if (not g_pars.ran_is_geran) {
758 log("Skipping f_verify_vty_lac_ci(), disabled for Iu");
759 setverdict(pass);
760 return;
761 }
762 if (not g_pars.verify_cell_id) {
763 /* Skip this verification; either the TC expects no cell id to end up being accepted, or this was
764 * disabled globally to test an older osmo-msc which doesn't store the cell id properly yet. */
765 log("Skipping f_verify_vty_lac_ci()");
766 setverdict(pass);
767 return;
768 }
769
770 var charstring vty_cmd := "show subscriber imsi " & hex2str(g_pars.imsi) & " conn";
771 var charstring result := f_vty_transceive_ret(MSCVTY, vty_cmd);
772 var charstring expect_lac_ci := "LAC / cell ID: "
773 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.lac)) & " / "
774 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.ci));
775
776 var boolean vlr_matches := false;
777 var boolean connection_present := false;
778 var boolean connection_matches := false;
779
780 /* There are two occurences of LAC / cell ID: once for the VLR record, and once for the active connection. The
781 * active connection part starts with 'Connection:'. If there is no active connection, that part is omitted.
782 * So, first find out whether there is a 'Connection:' part. Then verify the LAC / cell ID above 'Connection:'
783 * and below 'Connection:', separately.
784 */
785 var integer connection_start := f_strstr(result, "Connection:");
786 connection_present := (connection_start >= 0);
787
788 var integer lac_ci_match := f_strstr(result, expect_lac_ci);
789 if (connection_present) {
790 if (lac_ci_match > connection_start) {
791 /* The first match is below 'Connection:', so the VLR part above it did not match. */
792 vlr_matches := false;
793 connection_matches := true;
794 } else if (lac_ci_match >= 0) {
795 /* The first match is above 'Connection:', so the VLR part matches. */
796 vlr_matches := true;
797
798 /* Now find a match below 'Connection:' */
799 lac_ci_match := f_strstr(result, expect_lac_ci, connection_start);
800 connection_matches := (lac_ci_match > 0);
801 }
802 } else {
803 /* There is no 'Connection:', so a match, if any, is from the VLR part. */
804 vlr_matches := (lac_ci_match >= 0);
805 }
806
807 if (verify_vlr) {
808 if (not vlr_matches) {
809 setverdict(fail, vty_cmd, " shows mismatching LAC / cell ID in the VLR part, expecting: ",
810 expect_lac_ci, " -- got: ", result);
811 return;
812 } else {
813 log("f_verify_vty_lac_ci(): VLR record matches ", expect_lac_ci);
814 setverdict(pass);
815 }
816 }
817
818 if (connection_present) {
819 if (not connection_matches) {
820 setverdict(fail, vty_cmd, " shows mismatching LAC cell ID in the 'Connection' part, expecting: ",
821 expect_lac_ci, " -- got: ", result);
822 } else {
823 log("f_verify_vty_lac_ci(): Active connection matches ", expect_lac_ci);
824 setverdict(pass);
825 }
826 }
827
828 if (not verify_vlr and not connection_present) {
829 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);
830 }
831}
832
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100833function f_perform_lu()
Harald Weltea49e36e2018-01-21 19:29:33 +0100834runs on BSC_ConnHdlr {
835 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
836 var PDU_DTAP_MT dtap_mt;
837
838 /* tell GSUP dispatcher to send this IMSI to us */
839 f_create_gsup_expect(hex2str(g_pars.imsi));
840
841 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Welte9b751a62019-04-14 17:39:29 +0200842 if (g_pars.ran_is_geran) {
843 f_bssap_compl_l3(l3_lu);
844 if (g_pars.send_early_cm) {
845 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
846 }
847 } else {
848 f_ranap_initial_ue(l3_lu);
Harald Welte8a121b32018-01-22 03:00:41 +0100849 }
Harald Welte5c2622c2018-01-21 20:45:20 +0100850
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200851 /* at this point the conn has been established, but the subscriber has not been authenticated, so the VLR does
852 * not yet reflect this conn's cell ID. */
853 f_verify_vty_lac_ci(verify_vlr := false);
854
Oliver Smith1d118ff2019-07-03 10:57:35 +0200855 f_mm_imei_early();
Harald Weltede371492018-01-27 23:44:41 +0100856 f_mm_common();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100857 f_msc_lu_hlr();
Oliver Smith1d118ff2019-07-03 10:57:35 +0200858 f_mm_imei();
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200859 as_accept_reject_lu(g_pars.net.expect_attach_success);
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100860 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200861 f_expect_clear(verify_vlr_cell_id := g_pars.net.expect_attach_success);
Harald Welte16114282018-01-24 22:41:21 +0100862
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100863 setverdict(pass);
864}
865
866function f_msc_lu_hlr() runs on BSC_ConnHdlr
867{
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200868 if (not g_pars.net.expect_attach_success) {
869 return;
870 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100871 /* Expect MSC to perform LU with HLR */
872 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
873 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
874 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
875 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100876}
877
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200878altstep as_accept_reject_lu(boolean expect_accept := true) runs on BSC_ConnHdlr {
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100879 var PDU_DTAP_MT dtap_mt;
Harald Weltea49e36e2018-01-21 19:29:33 +0100880
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200881 [expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
Harald Weltea49e36e2018-01-21 19:29:33 +0100882 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
Harald Weltede371492018-01-27 23:44:41 +0100883 if (g_pars.net.expect_tmsi) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100884 if (not ispresent(lu_acc.mobileIdentityTLV) or
885 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
886 setverdict(fail, "Expected TMSI but no TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200887 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100888 } else {
Harald Welte256571e2018-01-24 18:47:19 +0100889 g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets;
Harald Weltea49e36e2018-01-21 19:29:33 +0100890 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
891 }
892 } else {
893 if (ispresent(lu_acc.mobileIdentityTLV) and
894 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
895 setverdict(fail, "Expected no TMSI but TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200896 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100897 }
898 }
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200899
900 /* Wait for MM-Information (if enabled) */
901 f_expect_mm_info();
902 setverdict(pass);
903 }
904 [expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100905 setverdict(fail, "Expected LU ACK, but received LU REJ");
Daniel Willmannafce8662018-07-06 23:11:32 +0200906 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100907 }
Philipp Maier9b690e42018-12-21 11:50:03 +0100908
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200909 [not expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
910 setverdict(pass);
911 }
912 [not expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
913 setverdict(fail, "Expected LU REJ, but received LU ACK");
914 mtc.stop;
915 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100916}
917
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100918function f_expect_lu_reject(template OCT1 cause := ?) runs on BSC_ConnHdlr {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200919 var PDU_DTAP_MT dtap_mt;
920 timer T := 5.0;
921
922 T.start;
923 alt {
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100924 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej(cause))) {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200925 setverdict(pass);
926 }
927 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
928 setverdict(fail, "Expected LU reject BSSAP message, got: ", dtap_mt);
929 }
930 [] T.timeout {
931 setverdict(fail, "Timeout waiting for LU reject");
932 }
933 }
934}
935
Harald Weltea49e36e2018-01-21 19:29:33 +0100936function f_foo() runs on BSC_ConnHdlr{
Harald Welte6811d102019-04-14 22:23:14 +0200937 /* SCCP CC handled by RAN_Emulation_CT.main() */
Harald Weltea49e36e2018-01-21 19:29:33 +0100938 /* Expect auth, if enabled */
939
940 /* TODO: ISD */
941 /* Expect encr, if enabled */
942 /* Expect encr, if enabled */
943 /* Expect ASS CMD, if chan_type != requested */
944 /* Send ASS CMPL in successful case */
945
946 /* Expect AoIP port/ip information for RTP stream */
947 /* Expect MSC-originated MGCP to our simulated MGW */
948 /* Verify Counters via CTRL */
949 /* re-configure MSC behaviour via VTY */
950}
951
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200952type record CrcxResponse {
953 integer resp, /* 1 = reply with OK, 0 = do not reply, -1 = reply with error */
954 HostName mgw_rtp_ip,
955 PortNumber mgw_rtp_port,
956 MgcpConnectionId mgcp_connection_id /* MGCP Connection ID BSS Side */
957}
958
Harald Welteb71901a2018-01-26 19:16:05 +0100959/* parameters related to a (MO?) voice call */
960type record CallParameters {
Harald Welteb71901a2018-01-26 19:16:05 +0100961 /* CC related parameters */
962 hexstring called_party, /* whom are we calling */
963 integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100964 boolean mo_call, /* For a MO call, the transaction_id was allocated by the MS,
965 important to set the TI flag properly */
Harald Welteb71901a2018-01-26 19:16:05 +0100966 BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */
Harald Welte0bef21e2018-02-10 09:48:23 +0100967 boolean emergency, /* is this an emergency call? */
Oliver Smith92b280c2023-04-20 13:13:23 +0200968 boolean csd, /* is this a circuit switched data call? */
Harald Welteb71901a2018-01-26 19:16:05 +0100969
970 /* MNCC related parameters */
971 uint32_t mncc_callref optional, /* call reference on the MNCC side */
972 MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200973 HostName mncc_rtp_ip optional, /* MNCC Side RTP IP */
974 PortNumber mncc_rtp_port optional, /* MNCC Side RTP port */
Harald Welteb71901a2018-01-26 19:16:05 +0100975
976 /* RTP related parameters */
977 HostName bss_rtp_ip optional, /* BSS Side RTP IP */
978 PortNumber bss_rtp_port optional, /* BSS Side RTP Port */
979 HostName mss_rtp_ip optional, /* MSS Side RTP IP */
980 PortNumber mss_rtp_port optional, /* MSS Side RTP Port */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200981 integer got_crcx_count,
982 CrcxResponse mgw_conn_1,
983 CrcxResponse mgw_conn_2,
Harald Welteb71901a2018-01-26 19:16:05 +0100984 uint7_t rtp_payload_type, /* dynamic RTP payload type */
985 charstring rtp_sdp_format, /* AMR/8000 or the like */
Philipp Maier2a98a732018-03-19 16:06:12 +0100986 boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX
987 (f_mt_call and f_mt_call) */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200988 boolean stop_after_cc_setup, /* Special case: stop call establish after CC Setup */
989 boolean ran_clear_when_alerting, /* Special case: send Clear upon CC Alerting */
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100990 boolean expect_release, /* Special case: expect call establish to cause direct CC Rel */
Harald Welteb71901a2018-01-26 19:16:05 +0100991
Philipp Maiercd668572018-03-19 16:11:52 +0100992 MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */
Harald Welteb71901a2018-01-26 19:16:05 +0100993 MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200994
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200995 boolean use_osmux, /* MSC is expected to use Osmux for this call */
996 integer got_osmux_count
Harald Welteb71901a2018-01-26 19:16:05 +0100997}
998
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200999template (value) CallParameters t_CallParams(hexstring called := '12345'H, integer tid := 0) := {
Harald Welteb71901a2018-01-26 19:16:05 +01001000 called_party := called,
1001 transaction_id := tid,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001002 mo_call := false,
Harald Welteb71901a2018-01-26 19:16:05 +01001003 bearer_cap := valueof(ts_Bcap_voice),
Harald Welte0bef21e2018-02-10 09:48:23 +01001004 emergency := false,
Oliver Smithf89620d2023-06-21 18:21:25 +02001005 csd := false,
Harald Welteb71901a2018-01-26 19:16:05 +01001006 mncc_callref := omit,
1007 mncc_bearer_cap := valueof(ts_MNCC_bcap_voice),
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001008 mncc_rtp_ip := "42.23.11.5",
1009 mncc_rtp_port := 423,
Harald Welte4017d552018-01-26 21:40:05 +01001010 bss_rtp_ip := "9.8.7.6",
1011 bss_rtp_port := 9000,
Harald Welteb71901a2018-01-26 19:16:05 +01001012 mss_rtp_ip := omit,
1013 mss_rtp_port := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001014 got_crcx_count := 0,
1015 mgw_conn_1 := {
1016 resp := 1,
1017 mgw_rtp_ip := "1.1.1.1",
1018 mgw_rtp_port := 10000,
1019 mgcp_connection_id := '11111'H
1020 },
1021 mgw_conn_2 := {
1022 resp := 1,
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001023 mgw_rtp_ip := "2.2.2.2",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001024 mgw_rtp_port := 11000,
1025 mgcp_connection_id := '22222'H
1026 },
Harald Welteb71901a2018-01-26 19:16:05 +01001027 rtp_payload_type := 98,
1028 rtp_sdp_format := "AMR/8000",
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001029 mgw_drop_dlcx := false,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001030 stop_after_cc_setup := false,
1031 ran_clear_when_alerting := false,
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001032 expect_release := false,
Harald Welteb71901a2018-01-26 19:16:05 +01001033 mgcp_call_id := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001034 mgcp_ep := "rtpbridge/1@mgw",
1035 use_osmux := false,
1036 got_osmux_count := 0
Harald Welteb71901a2018-01-26 19:16:05 +01001037};
1038
Neels Hofmeyrf797d292021-07-27 22:33:09 +02001039template CallParameters tr_CallParams := {
1040 called_party := ?,
1041 transaction_id := ?,
1042 mo_call := ?,
1043 bearer_cap := ?,
1044 emergency := ?,
Oliver Smithf89620d2023-06-21 18:21:25 +02001045 csd := ?,
Neels Hofmeyrf797d292021-07-27 22:33:09 +02001046 mncc_callref := *,
1047 mncc_bearer_cap := ?,
1048 mncc_rtp_ip := ?,
1049 mncc_rtp_port := ?,
1050 bss_rtp_ip := ?,
1051 bss_rtp_port := ?,
1052 mss_rtp_ip := *,
1053 mss_rtp_port := *,
1054 got_crcx_count := ?,
1055 mgw_conn_1 := ?,
1056 mgw_conn_2 := ?,
1057 rtp_payload_type := ?,
1058 rtp_sdp_format := ?,
1059 mgw_drop_dlcx := ?,
1060 stop_after_cc_setup := ?,
1061 ran_clear_when_alerting := ?,
1062 expect_release := ?,
1063 mgcp_call_id := *,
1064 mgcp_ep := ?,
1065 use_osmux := ?,
1066 got_osmux_count := ?
1067};
1068
Harald Welte4263c522018-12-06 11:56:27 +01001069/* Allocate a call reference and send SETUP via MNCC to MSC */
Oliver Smith97dc91f2023-05-31 13:53:21 +02001070function f_mt_call_initiate(inout CallParameters cpars)
Harald Welte33ec09b2018-02-10 15:34:46 +01001071runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001072 cpars.mo_call := false;
Harald Welte4263c522018-12-06 11:56:27 +01001073 cpars.mncc_callref := f_rnd_int(2147483648);
Oliver Smithc1dd36a2023-05-31 13:52:24 +02001074
Harald Welte4263c522018-12-06 11:56:27 +01001075 MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
Oliver Smith8cf75ab2023-06-21 16:19:51 +02001076 hex2str(cpars.called_party), hex2str(g_pars.imsi),
1077 cpars.mncc_bearer_cap));
Harald Welte4263c522018-12-06 11:56:27 +01001078}
Harald Welte33ec09b2018-02-10 15:34:46 +01001079
Harald Welte408a7ef2019-04-21 17:08:40 +02001080private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) :=
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001081 ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
Harald Welte408a7ef2019-04-21 17:08:40 +02001082 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001083 cpars.mgw_conn_2.mgw_rtp_port,
Harald Welte408a7ef2019-04-21 17:08:40 +02001084 { int2str(cpars.rtp_payload_type) },
1085 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1086 cpars.rtp_sdp_format)),
1087 valueof(ts_SDP_ptime(20)) });
1088
Harald Welte4263c522018-12-06 11:56:27 +01001089/* Complete call, begin with a paging response message via BSSAP */
1090function f_mt_call_complete(inout CallParameters cpars)
1091runs on BSC_ConnHdlr {
Harald Welte33ec09b2018-02-10 15:34:46 +01001092 var MNCC_PDU mncc;
1093 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001094 var template MgcpResponse mgcp_resp;
1095 var MgcpOsmuxCID osmux_cid;
1096 var PDU_BSSAP bssap;
Harald Welte33ec09b2018-02-10 15:34:46 +01001097
Harald Welte6811d102019-04-14 22:23:14 +02001098 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Welte33ec09b2018-02-10 15:34:46 +01001099
Harald Welteb9e86fa2018-04-09 18:18:31 +02001100 f_establish_fully(EST_TYPE_PAG_RESP);
Harald Welte33ec09b2018-02-10 15:34:46 +01001101
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001102 log("f_mt_call_complete 1");
1103
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001104 cpars.got_osmux_count := 0;
1105
Harald Welte33ec09b2018-02-10 15:34:46 +01001106 /* MS <- MSC: Expect CC SETUP */
1107 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party)));
1108
1109 /* MS -> MSC: ALERTING */
1110 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id)));
1111 MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001112 log("f_mt_call_complete 2");
Harald Welte33ec09b2018-02-10 15:34:46 +01001113
Harald Welte33ec09b2018-02-10 15:34:46 +01001114 /* Create MGCP expect */
1115 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1116 /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */
1117 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1118
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001119 /* First MGCP CRCX */
Harald Welte33ec09b2018-02-10 15:34:46 +01001120 MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001121 log("f_mt_call_complete 3");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001122 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1123 return;
Philipp Maier4b2692d2018-03-14 16:37:48 +01001124 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001125 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001126
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001127
Harald Welte9b751a62019-04-14 17:39:29 +02001128 if (g_pars.ran_is_geran) {
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001129 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass1 :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001130 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001131 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass2 :=
1132 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_2.mgw_rtp_ip, ?);
Harald Welte9b751a62019-04-14 17:39:29 +02001133
1134 interleave {
1135 /* Second MGCP CRCX (this time for MSS/CN side) */
1136 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001137 log("f_mt_call_complete 4");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001138 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1139 break;
1140 }
Harald Welte9b751a62019-04-14 17:39:29 +02001141 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001142
1143 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1144 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1145 log("f_mt_call_complete 5");
1146 }
1147
Harald Welte9b751a62019-04-14 17:39:29 +02001148 /* expect the MSC to trigger a BSSMAP ASSIGNMENT */
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001149 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, (tla_ass1, tla_ass2))) -> value bssap {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001150 var template BSSMAP_IE_AoIP_TransportLayerAddress tla;
Harald Welte9b751a62019-04-14 17:39:29 +02001151 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001152 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001153 log("f_mt_call_complete 6");
Oliver Smith90f31bb2023-08-23 13:31:35 +02001154
1155 if (cpars.csd and not match(bssap.pdu.bssmap.assignmentRequest.codecList.codecElements,
1156 {ts_CodecCSData})) {
1157 setverdict(fail, "MSC sent Assignment Request with unexpected codec list for CSD ",
1158 bssap.pdu.bssmap.assignmentRequest.codecList);
1159 mtc.stop;
1160 }
1161
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001162 tla := f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port);
Oliver Smith90f31bb2023-08-23 13:31:35 +02001163
1164 if (cpars.csd) {
1165 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecCSData}));
1166 } else {
1167 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
1168 }
Harald Welte9b751a62019-04-14 17:39:29 +02001169
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001170 if (cpars.use_osmux) {
1171 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1172 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1173 mtc.stop;
1174 }
1175 osmuxCID := valueof(ts_OsmuxCID(0));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001176 if (not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1177 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 +02001178 mtc.stop;
1179 }
1180 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1181 } else {
1182 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1183 }
1184 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001185
1186 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
Harald Welte9b751a62019-04-14 17:39:29 +02001187 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001188
1189 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1190 log("f_mt_call_complete 7");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001191 var octetstring ip;
1192 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1193 if (is_ipv6) {
1194 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1195 } else {
1196 ip := f_inet_addr(cpars.mncc_rtp_ip);
1197 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001198 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001199 is_ipv6, ip,
1200 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001201 /* payload type 3 = GSM FR */ 3));
1202 }
1203
1204 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1205 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1206 log("f_mt_call_complete 8");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001207 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 +01001208 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001209 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001210 { int2str(cpars.rtp_payload_type) },
1211 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1212 cpars.rtp_sdp_format)),
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001213 valueof(ts_SDP_ptime(20)) }));
1214 if (cpars.use_osmux) {
1215 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1216 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1217 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1218 mtc.stop;
1219 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001220 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 +02001221 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001222 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 +02001223 }
1224 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001225 }
1226
1227 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1228 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001229 var SDP_Message sdp;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001230 log("f_mt_call_complete 9");
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001231
1232 if (isvalue(mgcp_cmd.sdp)) {
1233 sdp := mgcp_cmd.sdp;
1234 if (sdp.media_list[0].media_field.ports.port_number != cpars.mncc_rtp_port) {
1235 setverdict(fail, "Wrong MDCX Connection port received, expected ", cpars.mncc_rtp_port, " and received ", sdp.media_list[0].media_field.ports.port_number)
1236 mtc.stop;
1237 }
1238 if (sdp.connection.conn_addr.addr != cpars.mncc_rtp_ip) {
1239 setverdict(fail, "Wrong MDCX Connection address received, expected ", cpars.mncc_rtp_ip, " and received ", sdp.connection.conn_addr.addr)
1240 mtc.stop;
1241 }
1242 }
1243
1244 sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1245 hex2str(cpars.mgcp_call_id), "42",
1246 cpars.mgw_conn_2.mgw_rtp_port,
1247 { int2str(cpars.rtp_payload_type) },
1248 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1249 cpars.rtp_sdp_format)),
1250 valueof(ts_SDP_ptime(20)) }));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001251 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 +01001252 }
1253
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001254 }
Harald Welte9b751a62019-04-14 17:39:29 +02001255 } else {
Harald Welte9b751a62019-04-14 17:39:29 +02001256 interleave {
1257 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001258 log("f_mt_call_complete 4.iu");
1259 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1260 break;
Harald Welte9b751a62019-04-14 17:39:29 +02001261 }
Harald Welte9b751a62019-04-14 17:39:29 +02001262 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001263
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001264 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1265 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1266 log("f_mt_call_complete 5.iu");
1267 }
1268
1269 [] BSSAP.receive(tr_RANAP_RabAssReq(?)) {
1270 log("f_mt_call_complete 6.iu");
1271 var RAB_SetupOrModifiedList l := {
1272 {
1273 {
1274 id := id_RAB_SetupOrModifiedItem,
1275 criticality := ignore,
1276 value_ := {
1277 rAB_SetupOrModifiedItem := {
1278 rAB_ID := int2bit(23, 8),
1279 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1280 iuTransportAssociation := {
1281 bindingID := '040c0000'O
1282 },
1283 dl_dataVolumes := omit,
1284 iE_Extensions := omit
1285 }
1286 }
1287 }
1288 }
1289 };
1290 BSSAP.send(ts_RANAP_RabAssResp(l));
1291
1292 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
1293 }
1294
1295 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1296 log("f_mt_call_complete 7.iu");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001297 var octetstring ip;
1298 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1299 if (is_ipv6) {
1300 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1301 } else {
1302 ip := f_inet_addr(cpars.mncc_rtp_ip);
1303 }
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001304 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001305 is_ipv6, ip,
1306 cpars.mncc_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001307 /* payload type 3 = GSM FR */ 3));
1308 }
1309
1310 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1311 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1312 log("f_mt_call_complete 8.iu");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001313 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 +01001314 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001315 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001316 { int2str(cpars.rtp_payload_type) },
1317 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1318 cpars.rtp_sdp_format)),
1319 valueof(ts_SDP_ptime(20)) }));
1320 if (cpars.use_osmux) {
1321 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1322 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1323 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1324 mtc.stop;
1325 }
1326 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
1327 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001328 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 +01001329 }
1330 MGCP.send(mgcp_resp);
1331 }
1332
1333 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1334 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1335 log("f_mt_call_complete 9.iu");
1336 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1337 hex2str(cpars.mgcp_call_id), "42",
1338 cpars.mgw_conn_2.mgw_rtp_port,
1339 { int2str(cpars.rtp_payload_type) },
1340 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1341 cpars.rtp_sdp_format)),
1342 valueof(ts_SDP_ptime(20)) }));
1343 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
1344 }
1345
Harald Welte33ec09b2018-02-10 15:34:46 +01001346 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001347 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001348
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001349 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1350 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1351 } else {
1352 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1353 mtc.stop;
1354 }
1355
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001356 log("f_mt_call_complete DONE");
Harald Welte4263c522018-12-06 11:56:27 +01001357}
1358
Harald Weltee035e3e2019-04-21 17:32:05 +02001359function f_expect_paging(boolean by_tmsi := true)
1360runs on BSC_ConnHdlr {
Harald Welte9b751a62019-04-14 17:39:29 +02001361 if (g_pars.ran_is_geran) {
1362 BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
1363 } else {
Harald Welte62113fc2019-05-09 13:04:02 +02001364 BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi)));
Harald Welte9b751a62019-04-14 17:39:29 +02001365 }
Harald Weltee035e3e2019-04-21 17:32:05 +02001366}
1367
Harald Welte4263c522018-12-06 11:56:27 +01001368function f_mt_call_establish(inout CallParameters cpars)
1369runs on BSC_ConnHdlr {
1370
1371 /* Initiate the call via MNCC */
Oliver Smith97dc91f2023-05-31 13:53:21 +02001372 f_mt_call_initiate(cpars);
Harald Welte4263c522018-12-06 11:56:27 +01001373
1374 /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
Harald Welte6811d102019-04-14 22:23:14 +02001375 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Weltee035e3e2019-04-21 17:32:05 +02001376 f_expect_paging()
Harald Welte4263c522018-12-06 11:56:27 +01001377
1378 /* Complete the call via BSSAP */
1379 f_mt_call_complete(cpars);
Harald Welte33ec09b2018-02-10 15:34:46 +01001380
Harald Welte33ec09b2018-02-10 15:34:46 +01001381 setverdict(pass);
1382}
1383
Neels Hofmeyrc47ce852023-03-06 17:16:50 +01001384function f_call_keep_open(inout CallParameters cpars, float open_time := 5.0)
1385runs on BSC_ConnHdlr {
1386 log("Hold the call for some time");
1387
1388 timer T := open_time;
1389 T.start;
1390 alt {
1391 [] MNCC.receive(tr_MNCC_DISC_ind(cpars.mncc_callref));
1392 [] MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
1393 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1394 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
1395 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1396 [] BSSAP.receive(tr_BSSMAP_ClearCommand);
1397 [] BSSAP.receive(tr_BSSMAP_ClearCommandCSFB);
1398 [] BSSAP.receive(tr_RANAP_IuReleaseCommand(?));
1399
1400 [] T.timeout {
1401 log("Call stayed open for ", open_time, " seconds, all is well.")
1402 setverdict(pass);
1403 return;
1404 }
1405 }
1406
1407 setverdict(fail, "An unexpected release event disconnected the active call prematurely");
1408 mtc.stop;
1409}
1410
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001411/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1412 * Return true when an OK reply was sent, false otherwise.
1413 * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */
1414function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd)
1415runs on BSC_ConnHdlr
1416return boolean {
1417 var CrcxResponse conn := cpars.mgw_conn_1;
1418 if (cpars.got_crcx_count > 0) {
1419 conn := cpars.mgw_conn_2;
1420 }
1421 cpars.got_crcx_count := cpars.got_crcx_count + 1;
1422
1423 var MgcpMessage mgcp_msg := {
1424 command := mgcp_cmd
1425 }
1426 var template MgcpResponse mgcp_resp;
1427 var MgcpOsmuxCID osmux_cid;
1428 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1429 if (ispresent(cpars.mgcp_call_id)) {
1430 if (cpars.mgcp_call_id != call_id) {
1431 setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id);
1432 mtc.stop;
1433 }
1434 } else {
1435 cpars.mgcp_call_id := call_id;
1436 }
1437
1438 /* When the endpoint contains a wildcard we keep the endpoint
1439 * identifier we have set up in cpars. Otherwise we use the
1440 * endpoint name that the call agent has supplied */
1441 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1442 cpars.mgcp_ep := mgcp_cmd.line.ep;
1443 }
1444
1445 if (conn.resp == -1) {
1446 /* Reply with error */
1447 var MgcpResponse mgcp_rsp := {
1448 line := {
1449 code := "542",
1450 trans_id := mgcp_cmd.line.trans_id,
1451 string := "FORCED_FAIL"
1452 },
1453 sdp := omit
1454
1455 }
1456 var MgcpParameter mgcp_rsp_param := {
1457 code := "Z",
1458 val := cpars.mgcp_ep
1459 };
1460 mgcp_rsp.params[0] := mgcp_rsp_param;
1461 MGCP.send(mgcp_rsp);
1462 return false;
1463 }
1464
1465 if (conn.resp == 0) {
1466 /* Do not reply at all */
1467 return false;
1468 }
1469
1470 if (conn.resp != 1) {
1471 setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1");
1472 mtc.stop;
1473 }
1474
1475 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1476 hex2str(cpars.mgcp_call_id), "42",
1477 conn.mgw_rtp_port,
1478 { int2str(cpars.rtp_payload_type) },
1479 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1480 cpars.rtp_sdp_format)),
1481 valueof(ts_SDP_ptime(20)) }));
1482
1483 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1484 if (not cpars.use_osmux) {
1485 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1486 mtc.stop;
1487 }
1488 cpars.got_osmux_count := cpars.got_osmux_count + 1;
1489 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1490 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1491 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1492 if (osmux_cid != -1) {
1493 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1494 mtc.stop;
1495 }
1496
1497 osmux_cid := 0;
1498 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1499 } else {
1500 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1501 }
1502
1503 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep));
1504 MGCP.send(mgcp_resp);
1505 return true;
1506}
1507
1508
1509altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr {
1510 var MgcpCommand mgcp_cmd;
1511 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1512 log("as_optional_mgcp_crcx: rx CRCX");
1513 f_handle_crcx(cpars, mgcp_cmd);
1514
1515 /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an
1516 * CRCX is handled. */
1517 repeat;
1518 }
1519}
1520
Andreas Eversberg1733de32023-07-27 16:27:05 +02001521altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001522 var MgcpCommand mgcp_cmd;
1523 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1524 log("as_optional_mgcp_mdcx: rx MDCX");
1525 log(mgcp_cmd);
1526 var charstring conn_id;
1527 var charstring rtp_payload_type;
1528 f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id);
1529 rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0];
1530
1531 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip,
1532 mgcp_cmd.sdp.origin.session_id, "42",
1533 mgw_rtp_port,
1534 { rtp_payload_type },
1535 { valueof(ts_SDP_ptime(20)) }));
1536 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp));
1537
1538 /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is
1539 * handled. */
1540 repeat;
1541 }
1542}
1543
Andreas Eversberg1733de32023-07-27 16:27:05 +02001544altstep as_optional_mgcp_dlcx(CallParameters cpars) runs on BSC_ConnHdlr {
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001545 var MgcpCommand mgcp_cmd;
1546 var boolean respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1547 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1548 log("as_optional_mgcp_dlcx: rx MGCP DLCX");
1549 if (respond_to_dlcx) {
1550 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1551 }
1552 /* Without this 'repeat', currently active other interleave and alt series exit as soon as a
1553 * DLCX is handled. */
1554 repeat;
1555 }
1556}
1557
Philipp Maier3716a5e2018-03-21 15:53:35 +01001558function f_mo_call_establish(inout CallParameters cpars)
Harald Welteb71901a2018-01-26 19:16:05 +01001559runs on BSC_ConnHdlr {
1560
Harald Welteb71901a2018-01-26 19:16:05 +01001561 var MNCC_PDU mncc;
1562 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001563 var template MgcpResponse mgcp_resp;
Philipp Maier2a98a732018-03-19 16:06:12 +01001564 var boolean respond_to_dlcx;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001565 var PDU_BSSAP bssap;
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001566 var RANAP_PDU ranap;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001567 var MgcpOsmuxCID osmux_cid;
Harald Welteb71901a2018-01-26 19:16:05 +01001568
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001569 cpars.mo_call := true;
1570
Harald Welte0bef21e2018-02-10 09:48:23 +01001571 if (cpars.emergency) {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001572 f_establish_fully(EST_TYPE_EMERG_CALL);
Oliver Smith92b280c2023-04-20 13:13:23 +02001573 } else if (cpars.csd) {
1574 f_establish_fully(EST_TYPE_MO_CSD);
Harald Welte0bef21e2018-02-10 09:48:23 +01001575 } else {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001576 f_establish_fully(EST_TYPE_MO_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001577 }
Harald Welteb71901a2018-01-26 19:16:05 +01001578
1579 /* Create MNCC and MGCP expect */
1580 f_create_mncc_expect(hex2str(cpars.called_party));
1581 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1582
Harald Welte0bef21e2018-02-10 09:48:23 +01001583 if (cpars.emergency) {
1584 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id)));
1585 } else {
Oliver Smith9c417f22023-07-07 13:25:11 +02001586 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party,
1587 cpars.bearer_cap)));
Harald Welte0bef21e2018-02-10 09:48:23 +01001588 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001589
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001590 if (cpars.stop_after_cc_setup) {
1591 return;
1592 }
1593
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001594 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass1 :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001595 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001596 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass2 :=
1597 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_2.mgw_rtp_ip, ?);
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001598
1599 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 +01001600 var boolean got_mncc_setup_compl_ind := false;
1601 var boolean got_cc_connect := false;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001602
Harald Welteb71901a2018-01-26 19:16:05 +01001603 interleave {
1604 [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001605 log("f_mo_call_establish 1: rx MNCC SETUP ind");
Harald Welteb71901a2018-01-26 19:16:05 +01001606 cpars.mncc_callref := mncc.u.signal.callref;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001607 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1608 }
1609
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001610 /* First MGCP CRCX */
Harald Welteb71901a2018-01-26 19:16:05 +01001611 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001612 log("f_mo_call_establish 2: rx 1st CRCX");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001613 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1614 break;
1615 }
Philipp Maierf1e02bb2018-03-15 16:30:00 +01001616 }
1617
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001618 /* Second MGCP CRCX */
1619 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
1620 log("f_mo_call_establish 6: rx 2nd CRCX");
1621 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1622 break;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001623 }
Harald Welteb71901a2018-01-26 19:16:05 +01001624 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001625
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001626 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1627 log("f_mo_call_establish 3: rx RTP CREATE");
1628 /* Call Proceeding */
1629 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1630 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001631
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001632 /* Alerting */
1633 MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref));
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001634 }
Harald Welte9b751a62019-04-14 17:39:29 +02001635
Neels Hofmeyreccaa992019-10-15 16:42:21 +02001636 //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001637 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001638 log("f_mo_call_establish 4: rx Assignment Request");
1639 var BSSMAP_IE_AoIP_TransportLayerAddress tla;
1640 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001641 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
1642
Oliver Smithd6c90062023-05-08 15:20:20 +02001643 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer)) {
1644 setverdict(fail, "MSC sent Assignment Request without AoIP Transport Layer IE");
1645 mtc.stop;
1646 }
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001647 if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass1)
1648 and not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass2)) {
1649 log("Expected one of: 1:", tla_ass1, " 2:", tla_ass2);
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001650 log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer);
1651 setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE");
1652 mtc.stop;
1653 }
1654
Oliver Smith90f31bb2023-08-23 13:31:35 +02001655 if (cpars.csd and not match(bssap.pdu.bssmap.assignmentRequest.codecList.codecElements,
1656 {ts_CodecCSData})) {
1657 setverdict(fail, "MSC sent Assignment Request with unexpected codec list for CSD ",
1658 bssap.pdu.bssmap.assignmentRequest.codecList);
1659 mtc.stop;
1660 }
1661
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001662 tla := valueof(f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port));
Oliver Smith90f31bb2023-08-23 13:31:35 +02001663
1664 if (cpars.csd) {
1665 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecCSData}));
1666 } else {
1667 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
1668 }
1669
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001670 if (cpars.use_osmux) {
1671 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1672 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1673 mtc.stop;
1674 }
1675 osmuxCID := valueof(ts_OsmuxCID(0));
1676 if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1677 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1678 mtc.stop;
1679 }
1680 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1681 } else {
1682 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1683 }
1684 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001685 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001686 [] BSSAP.receive(tr_RANAP_RabAssReq(*)) -> value ranap {
1687 log("f_mo_call_establish 4.iu: rx RANAP RAB Assignment Request");
1688 var RAB_SetupOrModifiedList l := {
1689 {
1690 {
1691 id := id_RAB_SetupOrModifiedItem,
1692 criticality := ignore,
1693 value_ := {
1694 rAB_SetupOrModifiedItem := {
1695 rAB_ID := int2bit(23, 8),
1696 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1697 iuTransportAssociation := {
1698 bindingID := '040c0000'O
1699 },
1700 dl_dataVolumes := omit,
1701 iE_Extensions := omit
1702 }
1703 }
1704 }
1705 }
1706 };
1707 BSSAP.send(ts_RANAP_RabAssResp(l));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001708 }
Harald Welte9b751a62019-04-14 17:39:29 +02001709
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001710 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1711 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1712 log("f_mo_call_establish 5: rx MDCX for the RAN side");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001713 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 +01001714 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001715 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001716 { int2str(cpars.rtp_payload_type) },
1717 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1718 cpars.rtp_sdp_format)),
1719 valueof(ts_SDP_ptime(20)) }));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001720
1721 if (cpars.use_osmux) {
1722 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1723 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1724 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1725 mtc.stop;
1726 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001727 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 +02001728 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001729 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 +02001730 }
1731 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001732 }
Harald Welte9b751a62019-04-14 17:39:29 +02001733
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001734 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {
1735 log("f_mo_call_establish 7: rx CC Alerting");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001736
1737 if (cpars.ran_clear_when_alerting) {
1738 if (g_pars.ran_is_geran) {
1739 BSSAP.send(ts_BSSMAP_ClearRequest(0));
1740 } else {
1741 BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention));
1742 }
1743 break;
1744 }
1745
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001746 cpars.mncc_callref := mncc.u.signal.callref;
1747 /* Call Proceeding */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001748 var octetstring ip;
1749 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1750 if (is_ipv6) {
1751 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1752 } else {
1753 ip := f_inet_addr(cpars.mncc_rtp_ip);
1754 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001755 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001756 is_ipv6, ip,
1757 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001758 /* payload type 3 = GSM FR */ 3));
1759 MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref));
1760 }
1761
1762 [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc {
1763 log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001764 got_mncc_setup_compl_ind := true;
1765 if (not cpars.expect_release and got_cc_connect) {
1766 break;
1767 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001768 }
1769
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001770 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) {
1771 log("f_mo_call_establish 10: rx CC CONNECT");
1772 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id)));
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001773 got_cc_connect := true;
1774 if (not cpars.expect_release and got_mncc_setup_compl_ind) {
1775 break;
1776 }
Harald Welteb71901a2018-01-26 19:16:05 +01001777 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001778
1779 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1780 log("f_mo_call_establish 11: rx CC RELEASE");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001781 if (not cpars.expect_release) {
1782 setverdict(fail, "Got unexpected CC Release");
1783 mtc.stop;
1784 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001785 f_expect_clear();
1786 break;
1787 }
1788 }
1789
1790 f_sleep(0.5);
1791 deactivate(mdcx);
1792
1793 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1794 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1795 } else {
1796 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1797 mtc.stop;
Harald Welteb71901a2018-01-26 19:16:05 +01001798 }
1799
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001800 log("f_mo_call_establish DONE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001801 setverdict(pass);
1802}
Harald Welteb71901a2018-01-26 19:16:05 +01001803
Harald Welte4c422b72019-02-17 16:27:10 +01001804function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001805runs on BSC_ConnHdlr {
1806
1807 var MobileIdentityLV mi;
1808 var MNCC_PDU mncc;
1809 var MgcpCommand mgcp_cmd;
1810 var boolean respond_to_dlcx;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001811 var boolean dlcx_contained_ci := false;
1812 var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand;
1813
1814 if (is_csfb) {
1815 t_clear := tr_BSSMAP_ClearCommandCSFB;
1816 }
1817
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001818 log("f_call_hangup 0: tx MNCC_DISC_REQ");
Harald Welteb71901a2018-01-26 19:16:05 +01001819 MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1820 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1821
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001822 log("f_call_hangup 1: rx DTAP CC DISC");
1823
Philipp Maier3716a5e2018-03-21 15:53:35 +01001824 if (release_by_ms) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001825 var BIT1 tid_remote := '1'B;
1826 if (cpars.mo_call) {
1827 tid_remote := '0'B;
1828 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001829 /* B-side (MS) Release of call */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001830 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 +01001831 MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001832 log("f_call_hangup 2: rx MNCC REL ind");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001833 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001834 log("f_call_hangup 3: rx DTAP CC REL COMPL");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001835 } else {
1836 /* A-side (PLMN) Release of call */
1837 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42))));
1838 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
Oliver Smith6f546a92023-07-10 15:03:31 +02001839 log("f_call_hangup 2.a: rx DTAP CC RELEASE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001840 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
Oliver Smith6f546a92023-07-10 15:03:31 +02001841 log("f_call_hangup 3.a: rx MNCC REL cnf");
1842 MNCC.receive(tr_MNCC_REL_cnf(cpars.mncc_callref, cause := *));
Philipp Maier3716a5e2018-03-21 15:53:35 +01001843 }
Harald Welteb71901a2018-01-26 19:16:05 +01001844
Philipp Maier2a98a732018-03-19 16:06:12 +01001845 respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1846
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001847 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 +01001848 var default dlcx := activate(as_optional_mgcp_dlcx(cpars));
Harald Welte9b751a62019-04-14 17:39:29 +02001849
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001850 /* clearing of radio channel */
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001851 alt {
1852 [g_pars.ran_is_geran] BSSAP.receive(t_clear) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001853 log("f_call_hangup 5: rx BSSAP Clear Command");
1854 BSSAP.send(ts_BSSMAP_ClearComplete);
1855 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1856 log("f_call_hangup 6: rx SCCP DISC");
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001857 setverdict(pass);
Philipp Maier2a98a732018-03-19 16:06:12 +01001858 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001859 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) {
1860 log("f_call_hangup 5.iu: rx Iu Release Command");
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001861 BSSAP.send(ts_RANAP_IuReleaseComplete);
1862 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001863 log("f_call_hangup 6.iu: rx SCCP DISC");
1864 setverdict(pass);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001865 }
1866 }
1867
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001868 f_sleep(1.0);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001869 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1870 log("f_call_hangup 9: done");
1871
1872 deactivate(mdcx);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001873 deactivate(dlcx);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001874}
1875
Oliver Smith98e24bc2023-07-07 12:36:59 +02001876function f_mt_call(inout CallParameters cpars, float open_time := 5.0)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001877runs on BSC_ConnHdlr {
1878
1879 f_mt_call_establish(cpars);
1880
Oliver Smith98e24bc2023-07-07 12:36:59 +02001881 f_call_keep_open(cpars, open_time);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001882
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001883 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001884 f_call_hangup(cpars, true);
1885
Oliver Smith3a33e552023-07-06 11:55:12 +02001886 /* Unregister the IMSI that was registered in f_mt_call_establish */
1887 f_ran_unregister_imsi(g_pars.imsi);
1888
Philipp Maier3716a5e2018-03-21 15:53:35 +01001889 setverdict(pass);
1890}
1891
Oliver Smith98e24bc2023-07-07 12:36:59 +02001892function f_mo_call(inout CallParameters cpars, float open_time := 5.0)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001893runs on BSC_ConnHdlr {
1894
1895 f_mo_call_establish(cpars);
1896
Oliver Smith98e24bc2023-07-07 12:36:59 +02001897 f_call_keep_open(cpars, open_time);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001898
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001899 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001900 f_call_hangup(cpars, false);
1901
Harald Welteb71901a2018-01-26 19:16:05 +01001902 setverdict(pass);
1903}
Harald Weltea49e36e2018-01-21 19:29:33 +01001904
Daniel Willmann8b084372018-02-04 13:35:26 +01001905function f_mo_seq_dtmf_dup(inout CallParameters cpars)
1906runs on BSC_ConnHdlr {
1907
1908 timer T := 1.0;
Daniel Willmann8b084372018-02-04 13:35:26 +01001909 var MNCC_PDU mncc;
1910 var MgcpCommand mgcp_cmd;
1911 var template PDU_ML3_MS_NW dtmf_dtap;
1912
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001913 f_mo_call_establish(cpars);
Daniel Willmann8b084372018-02-04 13:35:26 +01001914
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001915 /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by
1916 * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001917
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001918 /* Find out the next NSD that will be used, from RAN emulation. */
1919 var N_Sd_Array last_n_sd := f_bssmap_last_n_sd();
1920 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 +01001921
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001922 /* Compose DTAP with this correct NSD */
Daniel Willmann8b084372018-02-04 13:35:26 +01001923 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001924
1925 /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */
1926 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001927 T.start;
1928 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001929 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
1930 log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind");
1931 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001932 [] T.timeout {
1933 setverdict(fail, "Timeout waiting for START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001934 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001935 }
1936 }
1937
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001938 /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message
1939 * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */
1940 dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2);
Daniel Willmann92f66272018-02-06 15:50:52 +01001941 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true));
Daniel Willmann8b084372018-02-04 13:35:26 +01001942 T.start;
1943 alt {
1944 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001945 setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001946 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001947 }
1948 [] T.timeout { }
1949 }
1950
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001951 /* Here the NSD should be correct again and we see a DTMF. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001952 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001953 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001954 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001955 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) {
1956 log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind");
1957 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001958 [] T.timeout {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001959 setverdict(fail, "Timeout waiting for final START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001960 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001961 }
1962 }
1963
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001964 f_call_hangup(cpars, true);
Daniel Willmann8b084372018-02-04 13:35:26 +01001965 setverdict(pass);
1966}
Harald Welte9b751a62019-04-14 17:39:29 +02001967
Harald Welte1ddc7162018-01-27 14:25:46 +01001968/* expect a clear command */
Harald Welte5946b332018-03-18 23:32:21 +01001969altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr {
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001970 var PDU_BSSAP bssap;
Harald Welte5946b332018-03-18 23:32:21 +01001971 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1972 BSSAP.send(ts_BSSMAP_ClearComplete);
1973 alt {
Harald Welte6811d102019-04-14 22:23:14 +02001974 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte5946b332018-03-18 23:32:21 +01001975 setverdict(pass);
1976 }
1977 [] BSSAP.receive {
1978 setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001979 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001980 }
1981 }
1982 }
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001983 [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap {
1984 setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001985 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001986 }
1987}
1988
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001989function f_expect_clear(float t := 5.0, boolean verify_vlr_cell_id := true) runs on BSC_ConnHdlr {
Harald Welte1ddc7162018-01-27 14:25:46 +01001990 timer T := t;
1991
1992 T.start;
1993 alt {
Harald Welte9b751a62019-04-14 17:39:29 +02001994 [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { }
1995 [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { }
Harald Welte1ddc7162018-01-27 14:25:46 +01001996 [] T.timeout {
Harald Welte5946b332018-03-18 23:32:21 +01001997 setverdict(fail, "Timeout waiting for ClearCommand/Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001998 mtc.stop;
Harald Welte1ddc7162018-01-27 14:25:46 +01001999 }
2000 }
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02002001
2002 if (verify_vlr_cell_id) {
2003 /* Now the conn is gone, but the VLR reflects the cell ID */
2004 f_verify_vty_lac_ci();
2005 }
Harald Welte1ddc7162018-01-27 14:25:46 +01002006}
2007
Andreas Eversberge5a6ef12023-07-28 10:45:20 +02002008function f_create_bssmap_exp_n_connect(integer targetPointCode) runs on BSC_ConnHdlr {
2009 BSSAP_PROC.call(RAN_register_n_connect:{targetPointCode, self}) {
2010 [] BSSAP_PROC.getreply(RAN_register_n_connect:{?, ?}) {};
Neels Hofmeyr0ac63152019-05-07 01:20:17 +02002011 }
2012}
2013
2014function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array {
2015 var N_Sd_Array last_n_sd;
2016 BSSAP_PROC.call(RAN_last_n_sd:{self, -}) {
2017 [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) {
2018 return last_n_sd;
2019 };
2020 }
2021}
2022
2023function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr {
2024 BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) {
2025 [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self});
2026 }
2027}
2028
Harald Weltef45efeb2018-04-09 18:19:24 +02002029type record SmsParametersTp {
2030 OCT1 msg_ref,
2031 TP_DA da,
2032 OCT1 pid,
2033 OCT1 dcs,
2034 integer udl,
2035 octetstring ud
2036}
2037type record SmsParametersRp {
2038 OCT1 msg_ref,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002039 RP_NumberingPlan_and_NumberDigits smsc_addr optional
Harald Weltef45efeb2018-04-09 18:19:24 +02002040}
2041type record SmsParameters {
2042 SmsParametersTp tp,
2043 SmsParametersRp rp,
2044 uint3_t tid,
2045 OCT1 dlci,
2046 uint7_t exp_rp_err optional
2047}
2048
2049template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := {
2050 tP_DA_NoPad := {
2051 tP_LengthIndicator := 0, /* overwritten */
2052 tP_NumberingPlanID := npl,
2053 tP_TypeOfNumber := ton,
2054 tp_Spare := '0'B,
2055 tP_DAValue := addr
2056 }
2057}
2058
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002059template RP_NumberingPlan_and_NumberDigits t_RP_Addr(template hexstring addr,
2060 template BIT4 npi := '0001'B,
2061 template BIT3 ton := '001'B,
2062 template BIT1 ext := '1'B) := {
2063 rP_NumberingPlanIdentification := npi,
2064 rP_TypeOfNumber := ton,
2065 rP_Ext := ext,
2066 rP_NumberDigits := addr
2067}
2068
Harald Weltef45efeb2018-04-09 18:19:24 +02002069template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := {
2070 tp := {
2071 msg_ref := '23'O,
2072 da := ts_TP_DA('0000'B, '000'B, tp_daddr),
2073 pid := '00'O,
2074 dcs := '00'O,
2075 udl := 0,
2076 ud := ''O
2077 },
2078 rp := {
2079 msg_ref := '42'O,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002080 /* We don't really need to have both SM-RP-DA/OA here, because only one IE
Vadim Yanitskiyafb15a82020-01-05 14:04:53 +01002081 * is included in MO/MT SMS, and in the most cases it's the SMSC address.
2082 * NOTE: this address is currently hard-coded by OsmoMSC. */
2083 smsc_addr := t_RP_Addr('447785016005'H)
Harald Weltef45efeb2018-04-09 18:19:24 +02002084 },
2085 tid := 0,
2086 dlci := '03'O,
2087 exp_rp_err := omit
2088}
2089
2090private altstep as_other_sms() runs on BSC_ConnHdlr {
2091 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) {
2092 setverdict(fail, "Unexpected SMS related PDU from MSC");
Daniel Willmannafce8662018-07-06 23:11:32 +02002093 mtc.stop;
Harald Weltef45efeb2018-04-09 18:19:24 +02002094 }
2095}
2096
Vadim Yanitskiy9cc019a2018-11-15 02:06:07 +07002097/* Submit a MO RP-SMMA over an already existing DTAP connection */
2098function f_mo_smma(inout SmsParameters spars)
2099runs on BSC_ConnHdlr {
2100 var template (value) RPDU_MS_SGSN rp_mo;
2101 var template (value) PDU_ML3_MS_NW l3_mo;
2102
2103 var default d := activate(as_other_sms());
2104
2105 /* just in case this is routed to SMPP.. */
2106 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2107
2108 rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref);
2109 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
2110 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2111 /* receive CP-ACK for CP-DATA above */
2112 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
2113
2114 deactivate(d);
2115 setverdict(pass);
2116}
2117
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002118/* Submit a MO-SMS over an already existing DTAP connection */
2119function f_mo_sms_submit(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02002120runs on BSC_ConnHdlr {
2121 var template (value) TPDU_RP_DATA_MS_SGSN tp_mo;
2122 var template (value) RPDU_MS_SGSN rp_mo;
2123 var template (value) PDU_ML3_MS_NW l3_mo;
2124
Harald Weltef45efeb2018-04-09 18:19:24 +02002125 var default d := activate(as_other_sms());
2126
Harald Weltef640a012018-04-14 17:49:21 +02002127 /* just in case this is routed to SMPP.. */
2128 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2129
Harald Weltef45efeb2018-04-09 18:19:24 +02002130 tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs,
2131 spars.tp.udl, spars.tp.ud);
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002132 rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, omit, spars.rp.smsc_addr, tp_mo);
Harald Weltef45efeb2018-04-09 18:19:24 +02002133 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
2134 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2135 /* receive CP-ACK for CP-DATA above */
2136 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
2137
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002138 deactivate(d);
2139 setverdict(pass);
2140}
2141
2142/* Wait RP-ACK for MO-SMS on an already existing DTAP connection */
2143function f_mo_sms_wait_rp_ack(inout SmsParameters spars)
2144runs on BSC_ConnHdlr {
2145 var template (value) PDU_ML3_MS_NW l3_mo;
2146
2147 var template TPDU_RP_DATA_SGSN_MS tp_mt;
2148 var template RPDU_SGSN_MS rp_mt;
2149 var template PDU_ML3_NW_MS l3_mt;
2150
2151 var default d := activate(as_other_sms());
2152
2153 /* just in case this is routed to SMPP.. */
2154 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2155
Harald Weltef45efeb2018-04-09 18:19:24 +02002156 if (ispresent(spars.exp_rp_err)) {
2157 /* expect an RP-ERROR message from MSC with given cause */
2158 rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err);
2159 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
2160 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2161 /* send CP-ACK for CP-DATA just received */
2162 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
2163 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2164 } else {
2165 /* expect RP-ACK for RP-DATA */
2166 rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref);
2167 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
2168 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2169 /* send CP-ACO for CP-DATA just received */
2170 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
2171 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2172 }
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002173
Harald Weltef45efeb2018-04-09 18:19:24 +02002174 deactivate(d);
2175 setverdict(pass);
2176}
2177
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002178/* Submit a MO-SMS, and wait for RP-ACK on an existing
2179 * (and authenticated, ...) DTAP connection */
2180function f_mo_sms(inout SmsParameters spars)
2181runs on BSC_ConnHdlr {
2182 f_mo_sms_submit(spars);
2183 f_mo_sms_wait_rp_ack(spars);
2184}
2185
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002186function f_mt_sms_deliver_pdu(in SmsParameters spars)
2187runs on BSC_ConnHdlr
2188return template PDU_DTAP_MT {
2189 var template TPDU_RP_DATA_SGSN_MS tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?);
2190 var template RPDU_SGSN_MS rp_mt := tr_RP_DATA_MT(?, spars.rp.smsc_addr, omit, tp_mt);
2191 var template PDU_ML3_NW_MS l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt));
2192 return tr_PDU_DTAP_MT(l3_mt, spars.dlci);
2193}
2194
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002195/* Wait for MT SMS on an already existing DTAP connection */
2196function f_mt_sms_expect(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02002197runs on BSC_ConnHdlr {
Harald Weltef45efeb2018-04-09 18:19:24 +02002198 var template (value) PDU_ML3_MS_NW l3_mo;
Harald Weltef45efeb2018-04-09 18:19:24 +02002199 var PDU_DTAP_MT dtap_mt;
2200
2201 var default d := activate(as_other_sms());
2202
2203 /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002204 BSSAP.receive(f_mt_sms_deliver_pdu(spars)) -> value dtap_mt;
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002205
Harald Weltef45efeb2018-04-09 18:19:24 +02002206 /* Extract relevant identifiers */
2207 spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio);
2208 spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference;
2209
2210 /* send CP-ACK for CP-DATA just received */
2211 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO);
2212 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2213
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002214 deactivate(d);
2215 setverdict(pass);
2216}
2217
2218/* Send RP-ACK for MT-SMS over an already existing DTAP connection */
2219function f_mt_sms_send_rp_ack(inout SmsParameters spars)
2220runs on BSC_ConnHdlr {
2221 var template (value) RPDU_MS_SGSN rp_mo;
2222 var template (value) PDU_ML3_MS_NW l3_mo;
2223 var template PDU_ML3_NW_MS l3_mt;
2224
2225 var default d := activate(as_other_sms());
2226
Harald Weltef45efeb2018-04-09 18:19:24 +02002227 /* send RP-ACK for RP-DATA */
2228 rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref);
2229 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2230 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2231
2232 /* expect CP-ACK for CP-DATA(RP-ACK) just sent */
Harald Weltee008eea2018-04-14 21:05:48 +02002233 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
Harald Weltef45efeb2018-04-09 18:19:24 +02002234 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2235
2236 deactivate(d);
2237 setverdict(pass);
2238}
2239
Vadim Yanitskiy56318522018-11-24 03:40:47 +07002240/* Send RP-ERROR for MT-SMS over an already existing DTAP connection */
2241function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause)
2242runs on BSC_ConnHdlr {
2243 var template (value) RPDU_MS_SGSN rp_mo;
2244 var template (value) PDU_ML3_MS_NW l3_mo;
2245 var template PDU_ML3_NW_MS l3_mt;
2246
2247 var default d := activate(as_other_sms());
2248
2249 /* send RP-ACK for RP-DATA */
2250 rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause);
2251 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2252 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2253
2254 /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */
2255 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
2256 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2257
2258 deactivate(d);
2259 setverdict(pass);
2260}
2261
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002262/* Wait for a MT-SMS and send RP-ACK over an already existing
2263 * (and authenticated, ...) DTAP connection */
2264function f_mt_sms(inout SmsParameters spars)
2265runs on BSC_ConnHdlr {
2266 f_mt_sms_expect(spars);
2267 f_mt_sms_send_rp_ack(spars);
2268}
Harald Weltea49e36e2018-01-21 19:29:33 +01002269
2270
Harald Weltea49e36e2018-01-21 19:29:33 +01002271}