blob: e25d496fffa25daa358c583ece3b39ee1c020b91 [file] [log] [blame]
Harald Welte34b5a952019-05-27 11:54:11 +02001/* BSC Connection Handler of MSC test suite in TTCN-3
2 * (C) 2018-2019 Harald Welte <laforge@gnumonks.org>
3 * (C) 2018-2019 sysmocom - s.f.m.c. GmbH
4 * (C) 2018 Vadim Yanitskiy <axilirator@gmail.com>
5 * All rights reserved.
6 *
7 * Released under the terms of GNU General Public License, Version 2 or
8 * (at your option) any later version.
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
Harald Weltea49e36e2018-01-21 19:29:33 +010013module BSC_ConnectionHandler {
14
Eric Wild26f4a622021-05-17 15:27:05 +020015import from TCCOpenSecurity_Functions all;
Harald Weltea49e36e2018-01-21 19:29:33 +010016import from General_Types all;
17import from Osmocom_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010018import from Native_Functions all;
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +020019import from Misc_Helpers all;
Harald Weltea49e36e2018-01-21 19:29:33 +010020import from GSM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010021import from IPL4asp_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010022import from SCCPasp_Types all;
23import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020024import from RAN_Emulation all;
Harald Weltea49e36e2018-01-21 19:29:33 +010025import from BSSMAP_Templates all;
26
Harald Welte9b751a62019-04-14 17:39:29 +020027import from RANAP_Constants all;
28import from RANAP_IEs all;
29import from RANAP_PDU_Contents all;
30import from RANAP_PDU_Descriptions all;
31import from RANAP_Templates all;
32
Harald Weltea49e36e2018-01-21 19:29:33 +010033import from GSUP_Types all;
34import from GSUP_Emulation all;
35
36import from MNCC_Types all;
37import from MNCC_Emulation all;
38
Harald Welte4aa970c2018-01-26 10:38:09 +010039import from MGCP_Types all;
40import from MGCP_Emulation all;
Harald Welteb71901a2018-01-26 19:16:05 +010041import from MGCP_Templates all;
42import from SDP_Types all;
Harald Welte4aa970c2018-01-26 10:38:09 +010043
Harald Weltea49e36e2018-01-21 19:29:33 +010044import from MobileL3_Types all;
45import from MobileL3_CommonIE_Types all;
46import from MobileL3_MM_Types all;
Harald Welteb71901a2018-01-26 19:16:05 +010047import from MobileL3_CC_Types all;
Harald Weltef45efeb2018-04-09 18:19:24 +020048import from MobileL3_SMS_Types all;
Harald Weltea49e36e2018-01-21 19:29:33 +010049import from L3_Templates all;
Harald Welte158a7ca2018-02-16 18:11:31 +010050import from L3_Common all;
Harald Weltea49e36e2018-01-21 19:29:33 +010051
Harald Weltef640a012018-04-14 17:49:21 +020052import from SMPP_Emulation all;
53
Philipp Maieraeb29a82018-11-08 17:40:53 +010054import from IPA_Emulation all;
55import from Osmocom_CTRL_Functions all;
56import from Osmocom_CTRL_Types all;
57import from Osmocom_CTRL_Adapter all;
58
Philipp Maierc39a9d82018-11-09 11:21:08 +010059import from TELNETasp_PortType all;
60import from Osmocom_VTY_Functions all;
61
Harald Welte4263c522018-12-06 11:56:27 +010062import from SGsAP_Emulation all;
63
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +020064import from TCCConversion_Functions { function f_strstr };
65
Neels Hofmeyrf797d292021-07-27 22:33:09 +020066type port BSC_ConnHdlr_Coord_PT message
67{
68 inout charstring, CallParameters;
69} with { extension "internal" };
70
71
Harald Weltea49e36e2018-01-21 19:29:33 +010072/* this component represents a single subscriber connection */
Harald Welte6811d102019-04-14 22:23:14 +020073type 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 +010074 var BSC_ConnHdlrPars g_pars;
Harald Weltea10db902018-01-27 12:44:49 +010075 timer g_Tguard := 60.0;
Philipp Maierc39a9d82018-11-09 11:21:08 +010076 port TELNETasp_PT MSCVTY;
Neels Hofmeyrf797d292021-07-27 22:33:09 +020077 port BSC_ConnHdlr_Coord_PT COORD;
Harald Weltea49e36e2018-01-21 19:29:33 +010078}
79
Harald Weltede371492018-01-27 23:44:41 +010080type record BSC_ConnHdlrNetworkPars {
Neels Hofmeyre860fc42022-10-05 01:15:54 +020081 /* Bitmask of expected A5 levels; in Ciphering, will expect use of the highest A5 remaining after masking this
82 * with A5 supported by the MS */
Harald Weltede371492018-01-27 23:44:41 +010083 OCT1 kc_support,
Neels Hofmeyre860fc42022-10-05 01:15:54 +020084 /* osmo-msc VTY cfg under 'network': If a test wants to temporarily modify auth and encr config, this is the
85 * original config to return to for this test (is *not* sent to vty before the test, but maybe it should).
86 * For example: { "authentication optional", "encryption a5 0 3" } */
87 rof_charstring net_config,
88 /* expect_attach_success == true: expect Location Updating / CM Service Request to succeed.
89 * expect_attach_success == false: expect the MSC to reject LU / CM Service. */
90 boolean expect_attach_success,
91 /* expect_tmsi == true: expect MSC to allocate a new TMSI.
92 * expect_tmsi == false: expect no TMSI to be assigned, operate with IMSI Mobile Identity. */
Harald Weltede371492018-01-27 23:44:41 +010093 boolean expect_tmsi,
Neels Hofmeyre860fc42022-10-05 01:15:54 +020094 /* expect_auth == true overrides expect_auth_attempt == false */
95 boolean expect_auth_attempt,
96 /* hlr_has_auth_info has an effect only when (expect_auth_attempt or expect_auth) == true.
97 * hlr_has_auth_info == false means the HLR responds to Send Auth Info Request with a NACK. */
98 boolean hlr_has_auth_info,
Harald Weltede371492018-01-27 23:44:41 +010099 boolean expect_auth,
Oliver Smith1d118ff2019-07-03 10:57:35 +0200100 boolean expect_ciph,
101 boolean expect_imei,
102 boolean expect_imei_early,
103 GSUP_IMEIResult check_imei_result,
104 boolean check_imei_error
Harald Weltede371492018-01-27 23:44:41 +0100105}
106
Harald Weltea49e36e2018-01-21 19:29:33 +0100107type record BSC_ConnHdlrPars {
108 SCCP_PAR_Address sccp_addr_own,
109 SCCP_PAR_Address sccp_addr_peer,
110 BSSMAP_IE_CellIdentifier cell_id,
Harald Welte256571e2018-01-24 18:47:19 +0100111 hexstring imei,
Harald Weltea49e36e2018-01-21 19:29:33 +0100112 hexstring imsi,
Harald Welte82600572018-01-21 20:54:08 +0100113 hexstring msisdn,
Harald Welte256571e2018-01-24 18:47:19 +0100114 OCT4 tmsi optional,
Harald Welte9de84792018-01-28 01:06:35 +0100115 MobileStationClassmark1_V cm1,
Harald Welte82600572018-01-21 20:54:08 +0100116 BSSMAP_IE_ClassmarkInformationType2 cm2,
Harald Welte16114282018-01-24 22:41:21 +0100117 BSSMAP_IE_ClassmarkInformationType3 cm3 optional,
Harald Weltede371492018-01-27 23:44:41 +0100118 AuthVector vec optional,
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +0200119 /* BSC_ConnectionHandler generates an auth vector in as_GSUP_SAI(). For tests that want control over which
120 * vector is used, pass vec_keep := true to not regenerate a new auth vector in as_GSUP_SAI(). */
121 boolean vec_keep,
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100122 BSC_ConnHdlrNetworkPars net,
Philipp Maieraeb29a82018-11-08 17:40:53 +0100123 boolean send_early_cm,
124 charstring ipa_ctrl_ip,
125 integer ipa_ctrl_port,
Philipp Maier9b690e42018-12-21 11:50:03 +0100126 boolean ipa_ctrl_enable,
Philipp Maier57865482019-01-07 18:33:13 +0100127 boolean mm_info,
Philipp Maierc09a1312019-04-09 16:05:26 +0200128 boolean sgsap_enable,
Harald Weltef9abf8d2019-04-21 13:07:17 +0200129 boolean gsup_enable,
Vadim Yanitskiy2dd96612020-01-07 21:48:29 +0100130 OCT4 gsup_sid,
Harald Weltec1f937a2019-04-21 21:19:23 +0200131 integer ran_idx,
Harald Welte9b751a62019-04-14 17:39:29 +0200132 boolean use_umts_aka,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200133 boolean ran_is_geran,
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200134 boolean use_osmux,
Pau Espin Pedrol833174e2020-09-03 16:46:02 +0200135 boolean use_ipv6,
Oliver Smith44424db2023-08-22 13:54:09 +0200136 boolean use_csd,
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200137 boolean verify_cell_id,
138 OCT3 common_id_last_eutran_plmn optional
Harald Weltea49e36e2018-01-21 19:29:33 +0100139};
140
Harald Welte9de84792018-01-28 01:06:35 +0100141/* get a one-octet bitmaks of supported algorithms based on Classmark information */
Eric Wild26f4a622021-05-17 15:27:05 +0200142function 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 +0100143 var BIT8 res := '00000001'B; /* A5/0 always supported */
144
145 if (cm2.a5_1 == '0'B) {
146 res := res or4b '00000010'B;
147 }
148 if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) {
149 res := res or4b '00000100'B;
150 }
151 if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) {
152 res := res or4b '00001000'B;
153 }
Eric Wild26f4a622021-05-17 15:27:05 +0200154 if (not istemplatekind(cm3, "omit")) {
155 var BSSMAP_IE_ClassmarkInformationType3 v := valueof(cm3);
156 var BIT8 tmp := oct2bit(v.classmark3ValuePart[0]) and4b '00001111'B;
157 res := res or4b (tmp << 4);
158 }
159
Harald Welte9de84792018-01-28 01:06:35 +0100160 return bit2oct(res);
161}
162
163/* determine the best algorithm available within the bit-mask */
164function f_best_alg_from_mask(OCT1 alg_in) return OCT1 {
165 var BIT8 alg := oct2bit(alg_in);
166 var BIT8 ordered_algs[8] := {
167 '10000000'B, '01000000'B, '00100000'B, '00010000'B,
168 '00001000'B, /* A5/3 */
169 '00000010'B, /* A5/1 */
170 '00000100'B, /* A5/2 */
171 '00000001'B /* A5/0 */ }
172 for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) {
173 if (alg and4b ordered_algs[i] != '00000000'B) {
174 return bit2oct(ordered_algs[i]);
175 }
176 }
177 return '00'O;
178}
179
180/* return an integer like '1' for A5/1 based on a mask (with only one bit set */
181function f_alg_from_mask(OCT1 mask_in) return integer {
182 var BIT8 mask := oct2bit(mask_in);
183 for (var integer i := 0; i < 8; i := i+1) {
184 if (mask and4b ('00000001'B << i) != '00000000'B) {
185 return i;
186 }
187 }
188 return -1;
189}
190
Eric Wild26f4a622021-05-17 15:27:05 +0200191/* return true for A5/x supported by OCT1 bitmask */
192function f_alg_supported_by_mask(OCT1 mask_in, integer whicha5) return boolean {
193 var BIT8 mask := oct2bit(mask_in);
194 if (mask and4b ('00000001'B << whicha5) != '00000000'B) {
195 return true;
196 }
197 return false;
198}
199
Harald Weltea10db902018-01-27 12:44:49 +0100200/* altstep for the global guard timer */
201private altstep as_Tguard() runs on BSC_ConnHdlr {
202 [] g_Tguard.timeout {
Daniel Willmann90829d62018-02-15 17:45:14 +0100203 setverdict(fail, "Tguard timeout");
Daniel Willmannafce8662018-07-06 23:11:32 +0200204 mtc.stop;
Harald Weltea10db902018-01-27 12:44:49 +0100205 }
206}
207
208/* init function, called as first function in new BSC_ConnHdlr */
Harald Weltead2952e2018-01-27 14:12:46 +0100209function f_init_handler(BSC_ConnHdlrPars pars, float t_guard := 60.0) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100210 /* make parameters available via component variable */
211 g_pars := pars;
212 /* Start guard timer and activate it as default */
Harald Weltead2952e2018-01-27 14:12:46 +0100213 g_Tguard.start(t_guard);
Harald Weltea10db902018-01-27 12:44:49 +0100214 activate(as_Tguard());
Harald Weltef640a012018-04-14 17:49:21 +0200215 /* Route all SMPP messages for our MSISDN to us */
216 f_create_smpp_expect(hex2str(pars.msisdn));
Philipp Maier57865482019-01-07 18:33:13 +0100217
Harald Welte4263c522018-12-06 11:56:27 +0100218 /* Route all SGs message for our IMSI to us */
Philipp Maier57865482019-01-07 18:33:13 +0100219 if (g_pars.sgsap_enable == true) {
220 f_create_sgsap_expect(pars.imsi);
221 }
Philipp Maieraeb29a82018-11-08 17:40:53 +0100222
223 if (g_pars.ipa_ctrl_enable == true) {
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100224 f_ipa_ctrl_start_client(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port);
Philipp Maieraeb29a82018-11-08 17:40:53 +0100225 }
Philipp Maierc39a9d82018-11-09 11:21:08 +0100226
227 map(self:MSCVTY, system:MSCVTY);
228 f_vty_set_prompts(MSCVTY);
229 f_vty_transceive(MSCVTY, "enable");
Harald Weltea10db902018-01-27 12:44:49 +0100230}
231
Harald Weltea49e36e2018-01-21 19:29:33 +0100232
Harald Welte6811d102019-04-14 22:23:14 +0200233/* Callback function from general RAN_Emulation whenever a connectionless
Harald Weltea49e36e2018-01-21 19:29:33 +0100234 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
235private function BscUnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200236runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Weltea49e36e2018-01-21 19:29:33 +0100237 var template PDU_BSSAP resp := omit;
238
239 log("BSSMAP_BscUnitdataCallback");
240 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200241 if (match(bssap, tr_BSSMAP_Reset(g_ran_ops.use_osmux))){
Harald Weltea49e36e2018-01-21 19:29:33 +0100242 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200243 resp := ts_BSSMAP_ResetAck(g_ran_ops.use_osmux);
Harald Weltea49e36e2018-01-21 19:29:33 +0100244 }
245
246 /* FIXME: Handle paging, etc. */
247 return resp;
248}
249
Harald Welte9b751a62019-04-14 17:39:29 +0200250private function RncUnitdataCallback(RANAP_PDU ranap)
251runs on RAN_Emulation_CT return template RANAP_PDU {
252 var template RANAP_PDU resp := omit;
253
254 log("RANAP_RncUnitdataCallback");
255 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200256 if (match(ranap, tr_RANAP_Reset())) {
Harald Welte9b751a62019-04-14 17:39:29 +0200257 log("RANAP_RncUnitdataCallback: Responding to RESET with RESET-ACK");
258 var CN_DomainIndicator dom;
259 dom := ranap.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator;
260 resp := ts_RANAP_ResetAck(dom);
261 }
262
263 /* FIXME: Handle paging, etc. */
264 return resp;
265}
266
267
Harald Welte6811d102019-04-14 22:23:14 +0200268const RanOps BSC_RanOps := {
Harald Weltea49e36e2018-01-21 19:29:33 +0100269 /* Create call-back for inbound connections from MSC (hand-over) */
Harald Welte6811d102019-04-14 22:23:14 +0200270 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Weltea49e36e2018-01-21 19:29:33 +0100271 unitdata_cb := refers(BscUnitdataCallback),
Harald Welte9b751a62019-04-14 17:39:29 +0200272 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
273 ranap_unitdata_cb := refers(RncUnitdataCallback),
274 ps_domain := false,
Harald Weltea49e36e2018-01-21 19:29:33 +0100275 decode_dtap := true,
Harald Weltea4ca4462018-02-09 00:17:14 +0100276 role_ms := true,
Harald Welte2fce7882019-04-15 11:48:05 +0200277 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200278 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200279 use_osmux := false,
Eric Wild49888a62022-03-30 03:16:11 +0200280 bssap_reset_retries := 1,
Harald Weltea4ca4462018-02-09 00:17:14 +0100281 sccp_addr_local := omit,
282 sccp_addr_peer := omit
Harald Weltea49e36e2018-01-21 19:29:33 +0100283}
284
285
286private function MnccUnitdataCallback(MNCC_PDU mncc)
287runs on MNCC_Emulation_CT return template MNCC_PDU {
288 log("Ignoring MNCC", mncc);
289 return omit;
290}
291
292const MnccOps BCC_MnccOps := {
293 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
294 unitdata_cb := refers(MnccUnitdataCallback)
295}
296
297
298
Harald Welte6811d102019-04-14 22:23:14 +0200299/* Encode 'l3' and ask RAN_Emulation to create new connection with COMPL L3 INFO */
Harald Weltea49e36e2018-01-21 19:29:33 +0100300function f_bssap_compl_l3(PDU_ML3_MS_NW l3)
301runs on BSC_ConnHdlr {
302 log("Sending COMPL L3: ", l3);
303 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
304 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
305 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc))));
Harald Welte71b69332018-01-21 20:43:53 +0100306 alt {
Harald Welte6811d102019-04-14 22:23:14 +0200307 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
308 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte71b69332018-01-21 20:43:53 +0100309 setverdict(fail, "DISC.ind from SCCP");
Daniel Willmannafce8662018-07-06 23:11:32 +0200310 mtc.stop;
Harald Welte71b69332018-01-21 20:43:53 +0100311 }
312 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100313}
314
Harald Welte9b751a62019-04-14 17:39:29 +0200315/* generate Iu LAI from BSSAP CGI */
316private function f_IuLAI_from_BssmapCI(BSSMAP_IE_CellIdentifier ci) return LAI {
317 var LAI lai;
318 if (ischosen(ci.cellIdentification.cI_CGI)) {
319 lai.pLMNidentity := ci.cellIdentification.cI_CGI.mcc_mnc;
320 lai.lAC := ci.cellIdentification.cI_CGI.lac;
321 } else if (ischosen(ci.cellIdentification.cI_SAI)) {
322 lai.pLMNidentity := ci.cellIdentification.cI_SAI.mcc_mnc;
323 lai.lAC := ci.cellIdentification.cI_SAI.lac;
324 } else if (ischosen(ci.cellIdentification.ci_LAC_RNC_CI)) {
325 lai.pLMNidentity := ci.cellIdentification.ci_LAC_RNC_CI.mcc_mnc;
326 lai.lAC := ci.cellIdentification.ci_LAC_RNC_CI.lac;
327 } else {
328 mtc.stop;
329 }
330 lai.iE_Extensions := omit;
331 return lai;
332}
333
334/* like f_bssap_compl_l3() but for 3G */
335function f_ranap_initial_ue(PDU_ML3_MS_NW l3)
336runs on BSC_ConnHdlr {
337 log("Sending InitialUE: ", l3);
338 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
339 var RANAP_PDU ranap;
340 var LAI lai := f_IuLAI_from_BssmapCI(g_pars.cell_id);
341 var SAI sai := {
342 pLMNidentity := lai.pLMNidentity,
343 lAC := lai.lAC,
344 sAC := '0000'O, /* FIXME */
345 iE_Extensions := omit
346 };
347 var IuSignallingConnectionIdentifier sigc_id := int2bit(23, 24);
348 var GlobalRNC_ID grnc_id := {
349 pLMNidentity := lai.pLMNidentity,
350 rNC_ID := 2342 /* FIXME */
351 };
352
353 ranap := valueof(ts_RANAP_initialUE_CS(lai, sai, l3_enc, sigc_id, grnc_id));
354 BSSAP.send(ts_RANAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, ranap));
355 alt {
356 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
357 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
358 setverdict(fail, "DISC.ind from SCCP");
359 mtc.stop;
360 }
361 }
362}
363
Harald Weltedceacc72019-04-21 20:58:35 +0200364/* Send BSSMAP Complete L3 or RANAP Initial UE depending on 2G/3G RAN type */
365function f_cl3_or_initial_ue(PDU_ML3_MS_NW l3)
366runs on BSC_ConnHdlr {
367 if (g_pars.ran_is_geran) {
368 f_bssap_compl_l3(l3);
369 } else {
370 f_ranap_initial_ue(l3);
371 }
372}
373
Harald Welte081b19a2018-02-10 09:11:13 +0100374type enumerated EstablishType {
375 EST_TYPE_MO_CALL,
Harald Welte0bef21e2018-02-10 09:48:23 +0100376 EST_TYPE_EMERG_CALL,
Harald Weltef45efeb2018-04-09 18:19:24 +0200377 EST_TYPE_PAG_RESP,
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700378 EST_TYPE_MO_SMS,
Oliver Smith92b280c2023-04-20 13:13:23 +0200379 EST_TYPE_SS_ACT,
Andreas Eversberg5ada75d2023-07-27 16:24:38 +0200380 EST_TYPE_MO_CSD,
381 EST_TYPE_VGCS,
382 EST_TYPE_VBS
Harald Welte081b19a2018-02-10 09:11:13 +0100383};
384
Harald Weltea49e36e2018-01-21 19:29:33 +0100385/* helper function to fully establish a dedicated channel */
Harald Welteb9e86fa2018-04-09 18:18:31 +0200386function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL)
Harald Weltea49e36e2018-01-21 19:29:33 +0100387runs on BSC_ConnHdlr {
Harald Welte081b19a2018-02-10 09:11:13 +0100388 var PDU_ML3_MS_NW l3_info;
Harald Welteb9e86fa2018-04-09 18:18:31 +0200389 var MobileIdentityLV mi;
390
391 /* If we have a TMSI, use TMSI instead of IMSI */
392 if (ispresent(g_pars.tmsi)) {
393 mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi));
394 } else {
395 mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
396 }
397
Harald Welte081b19a2018-02-10 09:11:13 +0100398 select (etype) {
399 case (EST_TYPE_MO_CALL) {
400 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
401 }
Oliver Smith92b280c2023-04-20 13:13:23 +0200402 case (EST_TYPE_MO_CSD) {
403 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
404 }
Harald Welte0bef21e2018-02-10 09:48:23 +0100405 case (EST_TYPE_EMERG_CALL) {
406 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi));
407 }
Harald Welte081b19a2018-02-10 09:11:13 +0100408 case (EST_TYPE_PAG_RESP) {
409 l3_info := valueof(ts_PAG_RESP(mi));
410 }
Harald Weltef45efeb2018-04-09 18:19:24 +0200411 case (EST_TYPE_MO_SMS) {
412 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi));
413 }
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700414 case (EST_TYPE_SS_ACT) {
415 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi));
416 }
Andreas Eversberg5ada75d2023-07-27 16:24:38 +0200417 case (EST_TYPE_VGCS) {
418 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_VGCS, mi));
419 }
420 case (EST_TYPE_VBS) {
421 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_VBS, mi));
422 }
Harald Welte081b19a2018-02-10 09:11:13 +0100423 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100424
425 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Weltedceacc72019-04-21 20:58:35 +0200426 f_cl3_or_initial_ue(l3_info);
Harald Weltea49e36e2018-01-21 19:29:33 +0100427
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200428 f_verify_vty_lac_ci(verify_vlr := false);
429
Harald Weltede371492018-01-27 23:44:41 +0100430 f_mm_common();
Pau Espin Pedrolf8034482019-06-03 13:15:58 +0200431 if (g_pars.net.expect_ciph or not g_pars.ran_is_geran) {
Harald Welte148a7082018-01-26 18:56:43 +0100432 /* implicit CM SERVICE ACCEPT? */
433 } else {
Harald Welte0bef21e2018-02-10 09:48:23 +0100434 if (etype != EST_TYPE_PAG_RESP) {
Harald Welte081b19a2018-02-10 09:11:13 +0100435 /* explicit CM SERVICE ACCEPT */
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200436 if (g_pars.net.expect_attach_success) {
437 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
438 } else {
439 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_REJ));
440 }
Harald Welte081b19a2018-02-10 09:11:13 +0100441 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100442 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100443}
444
445/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
Harald Welte9de84792018-01-28 01:06:35 +0100446function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100447{
448 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
449 return f_build_lu(mi);
450}
Harald Welte9de84792018-01-28 01:06:35 +0100451function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100452{
453 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
454 return f_build_lu(mi);
455}
Harald Welte9de84792018-01-28 01:06:35 +0100456function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100457{
458 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
459 return f_build_lu(mi);
460}
Harald Welte9de84792018-01-28 01:06:35 +0100461private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100462{
463 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
464 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 +0100465 old_lai, mi, g_pars.cm1));
Harald Weltea49e36e2018-01-21 19:29:33 +0100466 return l3_info;
467}
468
Harald Weltea183a5d2019-05-09 13:40:52 +0200469altstep as_GSUP_SAI() runs on BSC_ConnHdlr {
470var GSUP_IE auth_tuple;
471[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)) {
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200472 if (g_pars.net.hlr_has_auth_info) {
473 if (g_pars.use_umts_aka) {
474 if (not g_pars.vec_keep) {
475 g_pars.vec := f_gen_auth_vec_3g();
476 }
477 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand,
478 g_pars.vec.sres,
479 g_pars.vec.kc,
480 g_pars.vec.ik,
481 g_pars.vec.ck,
482 g_pars.vec.autn,
483 g_pars.vec.res));
484 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
485 } else {
486 if (not g_pars.vec_keep) {
487 g_pars.vec := f_gen_auth_vec_2g();
488 }
489 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand,
490 g_pars.vec.sres,
491 g_pars.vec.kc));
492 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +0200493 }
Harald Weltea183a5d2019-05-09 13:40:52 +0200494 } else {
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200495 log("XXX ts_GSUP_SAI_ERR");
496 /* HLR knows the IMSI but has no authentication info; osmo-hlr responds with GMM_CAUSE_IMSI_UNKNOWN=2 in
497 * this case, for SAI this merely means there is no auth entry for this IMSI. */
498 GSUP.send(ts_GSUP_SAI_ERR(g_pars.imsi, 2));
Harald Weltea183a5d2019-05-09 13:40:52 +0200499 }
500 }
501}
502
Harald Welte9de84792018-01-28 01:06:35 +0100503function f_mm_auth() runs on BSC_ConnHdlr
Harald Welte148a7082018-01-26 18:56:43 +0100504{
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200505 if (g_pars.net.expect_auth or g_pars.net.expect_auth_attempt) {
Harald Weltea183a5d2019-05-09 13:40:52 +0200506 as_GSUP_SAI();
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200507 }
508 if (g_pars.net.expect_auth) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200509 if (g_pars.use_umts_aka) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200510 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn)));
511 var OCT4 res := substr(g_pars.vec.res, 0, 4);
512 var OCT4 xres := substr(g_pars.vec.res, 4, 4);
513 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres)));
514 } else {
Harald Weltec1f937a2019-04-21 21:19:23 +0200515 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand)));
516 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres)));
517 }
Harald Welte148a7082018-01-26 18:56:43 +0100518 }
Harald Welte9de84792018-01-28 01:06:35 +0100519}
Harald Welte148a7082018-01-26 18:56:43 +0100520
Oliver Smith1d118ff2019-07-03 10:57:35 +0200521function f_mm_imei() runs on BSC_ConnHdlr
522{
523 var PDU_DTAP_MT dtap_mt;
524 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700525 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200526
527 if (not g_pars.net.expect_imei) {
528 return
529 }
530
531 /* MSC <-> BSC: ID req/rsp for IMEI */
532 alt {
533 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEI))) {
534 mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
535 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
536 }
537 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
538 setverdict(fail, "Expected ID REQ for IMEI DTAP MT message, but got: ", dtap_mt);
539 mtc.stop;
540 }
541 }
542
543 /* MSC <-> HLR: Check IMEI req/res/err */
544 alt {
545 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
546 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
547 }
548 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
549 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
550 }
551 [] GSUP.receive(?) -> value gsup_msg {
552 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
553 g_pars.imsi, "), but got: ", gsup_msg);
554 mtc.stop;
555 }
556 }
557}
558
559function f_mm_imei_early() runs on BSC_ConnHdlr
560{
561 var PDU_DTAP_MT dtap_mt;
562 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700563 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200564
565 if (not g_pars.net.expect_imei_early) {
566 return
567 }
568
569 /* MSC <-> BSC: ID req/rsp for IMEISV */
570 alt {
571 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEISV))) {
572 mi := valueof(ts_MI_IMEISV_LV(g_pars.imei));
573 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
574 }
575 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
576 setverdict(fail, "Expected ID REQ for IMEISV DTAP MT message, but got: ", dtap_mt);
577 mtc.stop;
578 }
579 }
580
581 /* MSC <-> HLR: Check IMEI req/res/err */
582 alt {
583 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
584 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
585 }
586 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
587 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
588 }
589 [] GSUP.receive(?) -> value gsup_msg {
590 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
591 g_pars.imsi, "), but got: ", gsup_msg);
592 mtc.stop;
593 }
594 }
595}
596
Harald Welte79f1e452020-08-18 22:55:02 +0200597function f_expect_common_id() runs on BSC_ConnHdlr
598{
599 if (g_pars.ran_is_geran) {
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200600 BSSAP.receive(tr_BSSMAP_CommonId(g_pars.imsi,
601 f_tr_BSSMAP_LastUsedEUTRANPLMNId(g_pars.common_id_last_eutran_plmn)));
Harald Welte79f1e452020-08-18 22:55:02 +0200602 } else {
603 BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
604 }
605}
606
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200607/* For UMTS AKA on GERAN, calculate the specific kc from the UMTS AKA ck and ik vectors. */
608function f_auth3g_kc(AuthVector vec) return OCT8 {
Eric Wild26f4a622021-05-17 15:27:05 +0200609 var integer i;
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200610 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 +0200611 for (i := 1; i < 8; i := i + 1) {
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200612 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 +0200613 res := res & a;
614 }
615
616 return res;
617}
618
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200619function f_get_expected_encryption(
620 out template BSSMAP_IE_EncryptionInformation encryptionInformation,
621 out template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm,
622 out template BSSMAP_IE_KC128 kC128,
623 out OCT1 a5_perm_alg) runs on BSC_ConnHdlr
624{
625 var OCT1 a5_ms := f_alg_mask_from_cm(g_pars.cm2, g_pars.cm3);
626 a5_perm_alg := g_pars.net.kc_support and4b a5_ms;
627
628 if (not g_pars.net.expect_ciph) {
629 encryptionInformation := *;
630 chosenEncryptionAlgorithm := *;
631 kC128 := *;
632 return;
633 }
634
Neels Hofmeyrf6eff812021-06-23 23:29:39 +0200635 var OCT8 kc;
636 if (g_pars.use_umts_aka) {
637 kc := f_auth3g_kc(g_pars.vec);
638 } else {
639 kc := g_pars.vec.kc;
640 }
641 encryptionInformation := tr_BSSMAP_IE_EncrInfo(kc, a5_perm_alg);
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200642
643 var OCT1 chosen_alg := int2oct(f_alg_from_mask(f_best_alg_from_mask(a5_perm_alg)) + 1, 1);
644 chosenEncryptionAlgorithm := tr_BSSMAP_IE_ChosenEncryptionAlgorithm(chosen_alg);
645
646 if (g_pars.use_umts_aka and f_alg_supported_by_mask(a5_perm_alg, 4)) {
647 /* A5/4 is permitted, expecting kc128 to be present */
648 var OCT32 full_sha256 := f_calculate_HMAC_SHA256(g_pars.vec.ck & g_pars.vec.ik, '32'O, 32);
649 var OCT16 expect_kc128 := substr(full_sha256, 0, 16);
650 kC128 := tr_BSSMAP_IE_Kc128(expect_kc128);
651 } else {
652 kC128 := omit
653 }
654}
655
Eric Wild26f4a622021-05-17 15:27:05 +0200656
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300657private function f_mm_ciph_geran() runs on BSC_ConnHdlr
658{
659 var template BSSMAP_IE_EncryptionInformation encryptionInformation;
660 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm;
661 var template BSSMAP_IE_KC128 kC128;
662 var OCT1 a5_perm_alg;
663 var PDU_BSSAP pdu;
664
Vadim Yanitskiy172bc6e2021-12-06 17:54:57 +0300665 if (not g_pars.net.expect_ciph) {
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300666 /* There is nothing to do */
667 return;
668 }
669
670 f_get_expected_encryption(encryptionInformation, chosenEncryptionAlgorithm, kC128, a5_perm_alg);
671 alt {
672 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128)) -> value pdu {
673 var OCT1 a5_chosen := f_best_alg_from_mask(a5_perm_alg);
674 var integer a5_nr := f_alg_from_mask(a5_chosen);
675 BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
676 }
677 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2) -> value pdu {
678 log("Error: Ciphering Mode Command with unexpected content. Expected: ",
679 tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128), " got: ", pdu);
680 setverdict(fail, "Ciphering Mode Command with unexpected content.");
681 mtc.stop;
682 }
683 [] BSSAP.receive(tr_BSSMAP_ClassmarkRequest) {
684 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3))
685 repeat;
686 }
687 }
688 /* FIXME: Send the best available algorithm */
689}
690
691private function f_mm_ciph_utran() runs on BSC_ConnHdlr
692{
693 alt {
694 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
695 uia_key := oct2bit(g_pars.vec.ik),
696 key_sts := ?,
697 uea_algs := ?,
698 uea_key := oct2bit(g_pars.vec.ck))) {
699 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/
700 var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/
701 BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen));
702 }
703 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
704 setverdict(fail, "Invalid SecurityModeCommand (ciphering case)");
705 mtc.stop;
706 }
707 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
708 uia_key := oct2bit(g_pars.vec.ik),
709 key_sts := ?)) {
710 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/
711 BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
712 }
713 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
714 setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)");
715 mtc.stop;
716 }
717 }
718}
719
Harald Welte9de84792018-01-28 01:06:35 +0100720function f_mm_common() runs on BSC_ConnHdlr
721{
722 f_mm_auth();
Eric Wild26f4a622021-05-17 15:27:05 +0200723
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300724 if (g_pars.ran_is_geran) {
725 f_mm_ciph_geran();
726 } else {
727 f_mm_ciph_utran();
Harald Welte148a7082018-01-26 18:56:43 +0100728 }
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300729
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200730 if (not g_pars.net.expect_attach_success) {
731 return;
732 }
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300733 f_expect_common_id();
Harald Welte148a7082018-01-26 18:56:43 +0100734}
735
Philipp Maier9b690e42018-12-21 11:50:03 +0100736function f_expect_mm_info() runs on BSC_ConnHdlr {
737 if (g_pars.mm_info == true) {
738 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info));
739 }
740}
741
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200742private function f_lac_ci_vty_str(BSSMAP_IE_CellIdentifier cell_id) return charstring
743{
744 return "LAC / cell ID: "
745 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.lac)) & " / "
746 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.ci));
747}
748
749/* Get an IMSI's info and verify that the g_pars.cell_id is reflected in the info.
750 * Verify both the "LAC / cell ID" in the VLR and the "LAC / cell ID" in the "Connection:" part, if any.
751 * If verify_vlr == false, then only verify the "Connection:" part, and fail if there is no "Connection:"; this is
752 * useful when a conn has been established, but the subscriber has not been authenticated, so the VLR does not yet
753 * reflect the new conn's cell ID.
754 */
755function f_verify_vty_lac_ci(boolean verify_vlr := true) runs on BSC_ConnHdlr {
756 if (not g_pars.ran_is_geran) {
757 log("Skipping f_verify_vty_lac_ci(), disabled for Iu");
758 setverdict(pass);
759 return;
760 }
761 if (not g_pars.verify_cell_id) {
762 /* Skip this verification; either the TC expects no cell id to end up being accepted, or this was
763 * disabled globally to test an older osmo-msc which doesn't store the cell id properly yet. */
764 log("Skipping f_verify_vty_lac_ci()");
765 setverdict(pass);
766 return;
767 }
768
769 var charstring vty_cmd := "show subscriber imsi " & hex2str(g_pars.imsi) & " conn";
770 var charstring result := f_vty_transceive_ret(MSCVTY, vty_cmd);
771 var charstring expect_lac_ci := "LAC / cell ID: "
772 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.lac)) & " / "
773 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.ci));
774
775 var boolean vlr_matches := false;
776 var boolean connection_present := false;
777 var boolean connection_matches := false;
778
779 /* There are two occurences of LAC / cell ID: once for the VLR record, and once for the active connection. The
780 * active connection part starts with 'Connection:'. If there is no active connection, that part is omitted.
781 * So, first find out whether there is a 'Connection:' part. Then verify the LAC / cell ID above 'Connection:'
782 * and below 'Connection:', separately.
783 */
784 var integer connection_start := f_strstr(result, "Connection:");
785 connection_present := (connection_start >= 0);
786
787 var integer lac_ci_match := f_strstr(result, expect_lac_ci);
788 if (connection_present) {
789 if (lac_ci_match > connection_start) {
790 /* The first match is below 'Connection:', so the VLR part above it did not match. */
791 vlr_matches := false;
792 connection_matches := true;
793 } else if (lac_ci_match >= 0) {
794 /* The first match is above 'Connection:', so the VLR part matches. */
795 vlr_matches := true;
796
797 /* Now find a match below 'Connection:' */
798 lac_ci_match := f_strstr(result, expect_lac_ci, connection_start);
799 connection_matches := (lac_ci_match > 0);
800 }
801 } else {
802 /* There is no 'Connection:', so a match, if any, is from the VLR part. */
803 vlr_matches := (lac_ci_match >= 0);
804 }
805
806 if (verify_vlr) {
807 if (not vlr_matches) {
808 setverdict(fail, vty_cmd, " shows mismatching LAC / cell ID in the VLR part, expecting: ",
809 expect_lac_ci, " -- got: ", result);
810 return;
811 } else {
812 log("f_verify_vty_lac_ci(): VLR record matches ", expect_lac_ci);
813 setverdict(pass);
814 }
815 }
816
817 if (connection_present) {
818 if (not connection_matches) {
819 setverdict(fail, vty_cmd, " shows mismatching LAC cell ID in the 'Connection' part, expecting: ",
820 expect_lac_ci, " -- got: ", result);
821 } else {
822 log("f_verify_vty_lac_ci(): Active connection matches ", expect_lac_ci);
823 setverdict(pass);
824 }
825 }
826
827 if (not verify_vlr and not connection_present) {
828 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);
829 }
830}
831
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100832function f_perform_lu()
Harald Weltea49e36e2018-01-21 19:29:33 +0100833runs on BSC_ConnHdlr {
834 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
835 var PDU_DTAP_MT dtap_mt;
836
837 /* tell GSUP dispatcher to send this IMSI to us */
838 f_create_gsup_expect(hex2str(g_pars.imsi));
839
840 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Welte9b751a62019-04-14 17:39:29 +0200841 if (g_pars.ran_is_geran) {
842 f_bssap_compl_l3(l3_lu);
843 if (g_pars.send_early_cm) {
844 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
845 }
846 } else {
847 f_ranap_initial_ue(l3_lu);
Harald Welte8a121b32018-01-22 03:00:41 +0100848 }
Harald Welte5c2622c2018-01-21 20:45:20 +0100849
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200850 /* at this point the conn has been established, but the subscriber has not been authenticated, so the VLR does
851 * not yet reflect this conn's cell ID. */
852 f_verify_vty_lac_ci(verify_vlr := false);
853
Oliver Smith1d118ff2019-07-03 10:57:35 +0200854 f_mm_imei_early();
Harald Weltede371492018-01-27 23:44:41 +0100855 f_mm_common();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100856 f_msc_lu_hlr();
Oliver Smith1d118ff2019-07-03 10:57:35 +0200857 f_mm_imei();
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200858 as_accept_reject_lu(g_pars.net.expect_attach_success);
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100859 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200860 f_expect_clear(verify_vlr_cell_id := g_pars.net.expect_attach_success);
Harald Welte16114282018-01-24 22:41:21 +0100861
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100862 setverdict(pass);
863}
864
865function f_msc_lu_hlr() runs on BSC_ConnHdlr
866{
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200867 if (not g_pars.net.expect_attach_success) {
868 return;
869 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100870 /* Expect MSC to perform LU with HLR */
871 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
872 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
873 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
874 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100875}
876
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200877altstep as_accept_reject_lu(boolean expect_accept := true) runs on BSC_ConnHdlr {
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100878 var PDU_DTAP_MT dtap_mt;
Harald Weltea49e36e2018-01-21 19:29:33 +0100879
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200880 [expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
Harald Weltea49e36e2018-01-21 19:29:33 +0100881 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
Harald Weltede371492018-01-27 23:44:41 +0100882 if (g_pars.net.expect_tmsi) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100883 if (not ispresent(lu_acc.mobileIdentityTLV) or
884 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
885 setverdict(fail, "Expected TMSI but no TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200886 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100887 } else {
Harald Welte256571e2018-01-24 18:47:19 +0100888 g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets;
Harald Weltea49e36e2018-01-21 19:29:33 +0100889 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
890 }
891 } else {
892 if (ispresent(lu_acc.mobileIdentityTLV) and
893 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
894 setverdict(fail, "Expected no TMSI but TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200895 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100896 }
897 }
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200898
899 /* Wait for MM-Information (if enabled) */
900 f_expect_mm_info();
901 setverdict(pass);
902 }
903 [expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100904 setverdict(fail, "Expected LU ACK, but received LU REJ");
Daniel Willmannafce8662018-07-06 23:11:32 +0200905 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100906 }
Philipp Maier9b690e42018-12-21 11:50:03 +0100907
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200908 [not expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
909 setverdict(pass);
910 }
911 [not expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
912 setverdict(fail, "Expected LU REJ, but received LU ACK");
913 mtc.stop;
914 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100915}
916
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100917function f_expect_lu_reject(template OCT1 cause := ?) runs on BSC_ConnHdlr {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200918 var PDU_DTAP_MT dtap_mt;
919 timer T := 5.0;
920
921 T.start;
922 alt {
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100923 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej(cause))) {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200924 setverdict(pass);
925 }
926 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
927 setverdict(fail, "Expected LU reject BSSAP message, got: ", dtap_mt);
928 }
929 [] T.timeout {
930 setverdict(fail, "Timeout waiting for LU reject");
931 }
932 }
933}
934
Harald Weltea49e36e2018-01-21 19:29:33 +0100935function f_foo() runs on BSC_ConnHdlr{
Harald Welte6811d102019-04-14 22:23:14 +0200936 /* SCCP CC handled by RAN_Emulation_CT.main() */
Harald Weltea49e36e2018-01-21 19:29:33 +0100937 /* Expect auth, if enabled */
938
939 /* TODO: ISD */
940 /* Expect encr, if enabled */
941 /* Expect encr, if enabled */
942 /* Expect ASS CMD, if chan_type != requested */
943 /* Send ASS CMPL in successful case */
944
945 /* Expect AoIP port/ip information for RTP stream */
946 /* Expect MSC-originated MGCP to our simulated MGW */
947 /* Verify Counters via CTRL */
948 /* re-configure MSC behaviour via VTY */
949}
950
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200951type record CrcxResponse {
952 integer resp, /* 1 = reply with OK, 0 = do not reply, -1 = reply with error */
953 HostName mgw_rtp_ip,
954 PortNumber mgw_rtp_port,
955 MgcpConnectionId mgcp_connection_id /* MGCP Connection ID BSS Side */
956}
957
Harald Welteb71901a2018-01-26 19:16:05 +0100958/* parameters related to a (MO?) voice call */
959type record CallParameters {
Harald Welteb71901a2018-01-26 19:16:05 +0100960 /* CC related parameters */
961 hexstring called_party, /* whom are we calling */
962 integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100963 boolean mo_call, /* For a MO call, the transaction_id was allocated by the MS,
964 important to set the TI flag properly */
Harald Welteb71901a2018-01-26 19:16:05 +0100965 BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */
Harald Welte0bef21e2018-02-10 09:48:23 +0100966 boolean emergency, /* is this an emergency call? */
Oliver Smith92b280c2023-04-20 13:13:23 +0200967 boolean csd, /* is this a circuit switched data call? */
Harald Welteb71901a2018-01-26 19:16:05 +0100968
969 /* MNCC related parameters */
970 uint32_t mncc_callref optional, /* call reference on the MNCC side */
971 MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200972 HostName mncc_rtp_ip optional, /* MNCC Side RTP IP */
973 PortNumber mncc_rtp_port optional, /* MNCC Side RTP port */
Harald Welteb71901a2018-01-26 19:16:05 +0100974
975 /* RTP related parameters */
976 HostName bss_rtp_ip optional, /* BSS Side RTP IP */
977 PortNumber bss_rtp_port optional, /* BSS Side RTP Port */
978 HostName mss_rtp_ip optional, /* MSS Side RTP IP */
979 PortNumber mss_rtp_port optional, /* MSS Side RTP Port */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200980 integer got_crcx_count,
981 CrcxResponse mgw_conn_1,
982 CrcxResponse mgw_conn_2,
Harald Welteb71901a2018-01-26 19:16:05 +0100983 uint7_t rtp_payload_type, /* dynamic RTP payload type */
984 charstring rtp_sdp_format, /* AMR/8000 or the like */
Philipp Maier2a98a732018-03-19 16:06:12 +0100985 boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX
986 (f_mt_call and f_mt_call) */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200987 boolean stop_after_cc_setup, /* Special case: stop call establish after CC Setup */
988 boolean ran_clear_when_alerting, /* Special case: send Clear upon CC Alerting */
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100989 boolean expect_release, /* Special case: expect call establish to cause direct CC Rel */
Harald Welteb71901a2018-01-26 19:16:05 +0100990
Philipp Maiercd668572018-03-19 16:11:52 +0100991 MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */
Harald Welteb71901a2018-01-26 19:16:05 +0100992 MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200993
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200994 boolean use_osmux, /* MSC is expected to use Osmux for this call */
995 integer got_osmux_count
Harald Welteb71901a2018-01-26 19:16:05 +0100996}
997
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200998template (value) CallParameters t_CallParams(hexstring called := '12345'H, integer tid := 0) := {
Harald Welteb71901a2018-01-26 19:16:05 +0100999 called_party := called,
1000 transaction_id := tid,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001001 mo_call := false,
Harald Welteb71901a2018-01-26 19:16:05 +01001002 bearer_cap := valueof(ts_Bcap_voice),
Harald Welte0bef21e2018-02-10 09:48:23 +01001003 emergency := false,
Oliver Smithf89620d2023-06-21 18:21:25 +02001004 csd := false,
Harald Welteb71901a2018-01-26 19:16:05 +01001005 mncc_callref := omit,
1006 mncc_bearer_cap := valueof(ts_MNCC_bcap_voice),
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001007 mncc_rtp_ip := "42.23.11.5",
1008 mncc_rtp_port := 423,
Harald Welte4017d552018-01-26 21:40:05 +01001009 bss_rtp_ip := "9.8.7.6",
1010 bss_rtp_port := 9000,
Harald Welteb71901a2018-01-26 19:16:05 +01001011 mss_rtp_ip := omit,
1012 mss_rtp_port := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001013 got_crcx_count := 0,
1014 mgw_conn_1 := {
1015 resp := 1,
1016 mgw_rtp_ip := "1.1.1.1",
1017 mgw_rtp_port := 10000,
1018 mgcp_connection_id := '11111'H
1019 },
1020 mgw_conn_2 := {
1021 resp := 1,
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001022 mgw_rtp_ip := "2.2.2.2",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001023 mgw_rtp_port := 11000,
1024 mgcp_connection_id := '22222'H
1025 },
Harald Welteb71901a2018-01-26 19:16:05 +01001026 rtp_payload_type := 98,
1027 rtp_sdp_format := "AMR/8000",
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001028 mgw_drop_dlcx := false,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001029 stop_after_cc_setup := false,
1030 ran_clear_when_alerting := false,
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001031 expect_release := false,
Harald Welteb71901a2018-01-26 19:16:05 +01001032 mgcp_call_id := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001033 mgcp_ep := "rtpbridge/1@mgw",
1034 use_osmux := false,
1035 got_osmux_count := 0
Harald Welteb71901a2018-01-26 19:16:05 +01001036};
1037
Neels Hofmeyrf797d292021-07-27 22:33:09 +02001038template CallParameters tr_CallParams := {
1039 called_party := ?,
1040 transaction_id := ?,
1041 mo_call := ?,
1042 bearer_cap := ?,
1043 emergency := ?,
Oliver Smithf89620d2023-06-21 18:21:25 +02001044 csd := ?,
Neels Hofmeyrf797d292021-07-27 22:33:09 +02001045 mncc_callref := *,
1046 mncc_bearer_cap := ?,
1047 mncc_rtp_ip := ?,
1048 mncc_rtp_port := ?,
1049 bss_rtp_ip := ?,
1050 bss_rtp_port := ?,
1051 mss_rtp_ip := *,
1052 mss_rtp_port := *,
1053 got_crcx_count := ?,
1054 mgw_conn_1 := ?,
1055 mgw_conn_2 := ?,
1056 rtp_payload_type := ?,
1057 rtp_sdp_format := ?,
1058 mgw_drop_dlcx := ?,
1059 stop_after_cc_setup := ?,
1060 ran_clear_when_alerting := ?,
1061 expect_release := ?,
1062 mgcp_call_id := *,
1063 mgcp_ep := ?,
1064 use_osmux := ?,
1065 got_osmux_count := ?
1066};
1067
Harald Welte4263c522018-12-06 11:56:27 +01001068/* Allocate a call reference and send SETUP via MNCC to MSC */
Oliver Smith97dc91f2023-05-31 13:53:21 +02001069function f_mt_call_initiate(inout CallParameters cpars)
Harald Welte33ec09b2018-02-10 15:34:46 +01001070runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001071 cpars.mo_call := false;
Harald Welte4263c522018-12-06 11:56:27 +01001072 cpars.mncc_callref := f_rnd_int(2147483648);
Oliver Smithc1dd36a2023-05-31 13:52:24 +02001073
Harald Welte4263c522018-12-06 11:56:27 +01001074 MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
Oliver Smith8cf75ab2023-06-21 16:19:51 +02001075 hex2str(cpars.called_party), hex2str(g_pars.imsi),
1076 cpars.mncc_bearer_cap));
Harald Welte4263c522018-12-06 11:56:27 +01001077}
Harald Welte33ec09b2018-02-10 15:34:46 +01001078
Harald Welte408a7ef2019-04-21 17:08:40 +02001079private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) :=
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001080 ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
Harald Welte408a7ef2019-04-21 17:08:40 +02001081 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001082 cpars.mgw_conn_2.mgw_rtp_port,
Harald Welte408a7ef2019-04-21 17:08:40 +02001083 { int2str(cpars.rtp_payload_type) },
1084 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1085 cpars.rtp_sdp_format)),
1086 valueof(ts_SDP_ptime(20)) });
1087
Harald Welte4263c522018-12-06 11:56:27 +01001088/* Complete call, begin with a paging response message via BSSAP */
1089function f_mt_call_complete(inout CallParameters cpars)
1090runs on BSC_ConnHdlr {
Harald Welte33ec09b2018-02-10 15:34:46 +01001091 var MNCC_PDU mncc;
1092 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001093 var template MgcpResponse mgcp_resp;
1094 var MgcpOsmuxCID osmux_cid;
1095 var PDU_BSSAP bssap;
Harald Welte33ec09b2018-02-10 15:34:46 +01001096
Harald Welte6811d102019-04-14 22:23:14 +02001097 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Welte33ec09b2018-02-10 15:34:46 +01001098
Harald Welteb9e86fa2018-04-09 18:18:31 +02001099 f_establish_fully(EST_TYPE_PAG_RESP);
Harald Welte33ec09b2018-02-10 15:34:46 +01001100
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001101 log("f_mt_call_complete 1");
1102
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001103 cpars.got_osmux_count := 0;
1104
Harald Welte33ec09b2018-02-10 15:34:46 +01001105 /* MS <- MSC: Expect CC SETUP */
1106 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party)));
1107
1108 /* MS -> MSC: ALERTING */
1109 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id)));
1110 MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001111 log("f_mt_call_complete 2");
Harald Welte33ec09b2018-02-10 15:34:46 +01001112
Harald Welte33ec09b2018-02-10 15:34:46 +01001113 /* Create MGCP expect */
1114 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1115 /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */
1116 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1117
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001118 /* First MGCP CRCX */
Harald Welte33ec09b2018-02-10 15:34:46 +01001119 MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001120 log("f_mt_call_complete 3");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001121 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1122 return;
Philipp Maier4b2692d2018-03-14 16:37:48 +01001123 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001124 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001125
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001126
Harald Welte9b751a62019-04-14 17:39:29 +02001127 if (g_pars.ran_is_geran) {
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001128 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass1 :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001129 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001130 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass2 :=
1131 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_2.mgw_rtp_ip, ?);
Harald Welte9b751a62019-04-14 17:39:29 +02001132
1133 interleave {
1134 /* Second MGCP CRCX (this time for MSS/CN side) */
1135 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001136 log("f_mt_call_complete 4");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001137 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1138 break;
1139 }
Harald Welte9b751a62019-04-14 17:39:29 +02001140 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001141
1142 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1143 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1144 log("f_mt_call_complete 5");
1145 }
1146
Harald Welte9b751a62019-04-14 17:39:29 +02001147 /* expect the MSC to trigger a BSSMAP ASSIGNMENT */
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001148 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, (tla_ass1, tla_ass2))) -> value bssap {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001149 var template BSSMAP_IE_AoIP_TransportLayerAddress tla;
Harald Welte9b751a62019-04-14 17:39:29 +02001150 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001151 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001152 log("f_mt_call_complete 6");
Oliver Smith90f31bb2023-08-23 13:31:35 +02001153
1154 if (cpars.csd and not match(bssap.pdu.bssmap.assignmentRequest.codecList.codecElements,
1155 {ts_CodecCSData})) {
1156 setverdict(fail, "MSC sent Assignment Request with unexpected codec list for CSD ",
1157 bssap.pdu.bssmap.assignmentRequest.codecList);
1158 mtc.stop;
1159 }
1160
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001161 tla := f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port);
Oliver Smith90f31bb2023-08-23 13:31:35 +02001162
1163 if (cpars.csd) {
1164 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecCSData}));
1165 } else {
1166 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
1167 }
Harald Welte9b751a62019-04-14 17:39:29 +02001168
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001169 if (cpars.use_osmux) {
1170 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1171 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1172 mtc.stop;
1173 }
1174 osmuxCID := valueof(ts_OsmuxCID(0));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001175 if (not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1176 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 +02001177 mtc.stop;
1178 }
1179 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1180 } else {
1181 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1182 }
1183 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001184
1185 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
Harald Welte9b751a62019-04-14 17:39:29 +02001186 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001187
1188 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1189 log("f_mt_call_complete 7");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001190 var octetstring ip;
1191 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1192 if (is_ipv6) {
1193 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1194 } else {
1195 ip := f_inet_addr(cpars.mncc_rtp_ip);
1196 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001197 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001198 is_ipv6, ip,
1199 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001200 /* payload type 3 = GSM FR */ 3));
1201 }
1202
1203 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1204 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1205 log("f_mt_call_complete 8");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001206 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 +01001207 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001208 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001209 { int2str(cpars.rtp_payload_type) },
1210 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1211 cpars.rtp_sdp_format)),
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001212 valueof(ts_SDP_ptime(20)) }));
1213 if (cpars.use_osmux) {
1214 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1215 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1216 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1217 mtc.stop;
1218 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001219 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001220 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001221 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 +02001222 }
1223 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001224 }
1225
1226 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1227 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001228 var SDP_Message sdp;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001229 log("f_mt_call_complete 9");
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001230
1231 if (isvalue(mgcp_cmd.sdp)) {
1232 sdp := mgcp_cmd.sdp;
1233 if (sdp.media_list[0].media_field.ports.port_number != cpars.mncc_rtp_port) {
1234 setverdict(fail, "Wrong MDCX Connection port received, expected ", cpars.mncc_rtp_port, " and received ", sdp.media_list[0].media_field.ports.port_number)
1235 mtc.stop;
1236 }
1237 if (sdp.connection.conn_addr.addr != cpars.mncc_rtp_ip) {
1238 setverdict(fail, "Wrong MDCX Connection address received, expected ", cpars.mncc_rtp_ip, " and received ", sdp.connection.conn_addr.addr)
1239 mtc.stop;
1240 }
1241 }
1242
1243 sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1244 hex2str(cpars.mgcp_call_id), "42",
1245 cpars.mgw_conn_2.mgw_rtp_port,
1246 { int2str(cpars.rtp_payload_type) },
1247 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1248 cpars.rtp_sdp_format)),
1249 valueof(ts_SDP_ptime(20)) }));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001250 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 +01001251 }
1252
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001253 }
Harald Welte9b751a62019-04-14 17:39:29 +02001254 } else {
Harald Welte9b751a62019-04-14 17:39:29 +02001255 interleave {
1256 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001257 log("f_mt_call_complete 4.iu");
1258 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1259 break;
Harald Welte9b751a62019-04-14 17:39:29 +02001260 }
Harald Welte9b751a62019-04-14 17:39:29 +02001261 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001262
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001263 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1264 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1265 log("f_mt_call_complete 5.iu");
1266 }
1267
1268 [] BSSAP.receive(tr_RANAP_RabAssReq(?)) {
1269 log("f_mt_call_complete 6.iu");
1270 var RAB_SetupOrModifiedList l := {
1271 {
1272 {
1273 id := id_RAB_SetupOrModifiedItem,
1274 criticality := ignore,
1275 value_ := {
1276 rAB_SetupOrModifiedItem := {
1277 rAB_ID := int2bit(23, 8),
1278 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1279 iuTransportAssociation := {
1280 bindingID := '040c0000'O
1281 },
1282 dl_dataVolumes := omit,
1283 iE_Extensions := omit
1284 }
1285 }
1286 }
1287 }
1288 };
1289 BSSAP.send(ts_RANAP_RabAssResp(l));
1290
1291 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
1292 }
1293
1294 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1295 log("f_mt_call_complete 7.iu");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001296 var octetstring ip;
1297 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1298 if (is_ipv6) {
1299 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1300 } else {
1301 ip := f_inet_addr(cpars.mncc_rtp_ip);
1302 }
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001303 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001304 is_ipv6, ip,
1305 cpars.mncc_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001306 /* payload type 3 = GSM FR */ 3));
1307 }
1308
1309 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1310 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1311 log("f_mt_call_complete 8.iu");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001312 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 +01001313 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001314 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001315 { int2str(cpars.rtp_payload_type) },
1316 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1317 cpars.rtp_sdp_format)),
1318 valueof(ts_SDP_ptime(20)) }));
1319 if (cpars.use_osmux) {
1320 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1321 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1322 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1323 mtc.stop;
1324 }
1325 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
1326 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001327 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 +01001328 }
1329 MGCP.send(mgcp_resp);
1330 }
1331
1332 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1333 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1334 log("f_mt_call_complete 9.iu");
1335 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1336 hex2str(cpars.mgcp_call_id), "42",
1337 cpars.mgw_conn_2.mgw_rtp_port,
1338 { int2str(cpars.rtp_payload_type) },
1339 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1340 cpars.rtp_sdp_format)),
1341 valueof(ts_SDP_ptime(20)) }));
1342 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
1343 }
1344
Harald Welte33ec09b2018-02-10 15:34:46 +01001345 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001346 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001347
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001348 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1349 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1350 } else {
1351 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1352 mtc.stop;
1353 }
1354
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001355 log("f_mt_call_complete DONE");
Harald Welte4263c522018-12-06 11:56:27 +01001356}
1357
Harald Weltee035e3e2019-04-21 17:32:05 +02001358function f_expect_paging(boolean by_tmsi := true)
1359runs on BSC_ConnHdlr {
Harald Welte9b751a62019-04-14 17:39:29 +02001360 if (g_pars.ran_is_geran) {
1361 BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
1362 } else {
Harald Welte62113fc2019-05-09 13:04:02 +02001363 BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi)));
Harald Welte9b751a62019-04-14 17:39:29 +02001364 }
Harald Weltee035e3e2019-04-21 17:32:05 +02001365}
1366
Harald Welte4263c522018-12-06 11:56:27 +01001367function f_mt_call_establish(inout CallParameters cpars)
1368runs on BSC_ConnHdlr {
1369
1370 /* Initiate the call via MNCC */
Oliver Smith97dc91f2023-05-31 13:53:21 +02001371 f_mt_call_initiate(cpars);
Harald Welte4263c522018-12-06 11:56:27 +01001372
1373 /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
Harald Welte6811d102019-04-14 22:23:14 +02001374 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Weltee035e3e2019-04-21 17:32:05 +02001375 f_expect_paging()
Harald Welte4263c522018-12-06 11:56:27 +01001376
1377 /* Complete the call via BSSAP */
1378 f_mt_call_complete(cpars);
Harald Welte33ec09b2018-02-10 15:34:46 +01001379
Harald Welte33ec09b2018-02-10 15:34:46 +01001380 setverdict(pass);
1381}
1382
Neels Hofmeyrc47ce852023-03-06 17:16:50 +01001383function f_call_keep_open(inout CallParameters cpars, float open_time := 5.0)
1384runs on BSC_ConnHdlr {
1385 log("Hold the call for some time");
1386
1387 timer T := open_time;
1388 T.start;
1389 alt {
1390 [] MNCC.receive(tr_MNCC_DISC_ind(cpars.mncc_callref));
1391 [] MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
1392 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1393 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
1394 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1395 [] BSSAP.receive(tr_BSSMAP_ClearCommand);
1396 [] BSSAP.receive(tr_BSSMAP_ClearCommandCSFB);
1397 [] BSSAP.receive(tr_RANAP_IuReleaseCommand(?));
1398
1399 [] T.timeout {
1400 log("Call stayed open for ", open_time, " seconds, all is well.")
1401 setverdict(pass);
1402 return;
1403 }
1404 }
1405
1406 setverdict(fail, "An unexpected release event disconnected the active call prematurely");
1407 mtc.stop;
1408}
1409
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001410/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1411 * Return true when an OK reply was sent, false otherwise.
1412 * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */
1413function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd)
1414runs on BSC_ConnHdlr
1415return boolean {
1416 var CrcxResponse conn := cpars.mgw_conn_1;
1417 if (cpars.got_crcx_count > 0) {
1418 conn := cpars.mgw_conn_2;
1419 }
1420 cpars.got_crcx_count := cpars.got_crcx_count + 1;
1421
1422 var MgcpMessage mgcp_msg := {
1423 command := mgcp_cmd
1424 }
1425 var template MgcpResponse mgcp_resp;
1426 var MgcpOsmuxCID osmux_cid;
1427 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1428 if (ispresent(cpars.mgcp_call_id)) {
1429 if (cpars.mgcp_call_id != call_id) {
1430 setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id);
1431 mtc.stop;
1432 }
1433 } else {
1434 cpars.mgcp_call_id := call_id;
1435 }
1436
1437 /* When the endpoint contains a wildcard we keep the endpoint
1438 * identifier we have set up in cpars. Otherwise we use the
1439 * endpoint name that the call agent has supplied */
1440 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1441 cpars.mgcp_ep := mgcp_cmd.line.ep;
1442 }
1443
1444 if (conn.resp == -1) {
1445 /* Reply with error */
1446 var MgcpResponse mgcp_rsp := {
1447 line := {
1448 code := "542",
1449 trans_id := mgcp_cmd.line.trans_id,
1450 string := "FORCED_FAIL"
1451 },
1452 sdp := omit
1453
1454 }
1455 var MgcpParameter mgcp_rsp_param := {
1456 code := "Z",
1457 val := cpars.mgcp_ep
1458 };
1459 mgcp_rsp.params[0] := mgcp_rsp_param;
1460 MGCP.send(mgcp_rsp);
1461 return false;
1462 }
1463
1464 if (conn.resp == 0) {
1465 /* Do not reply at all */
1466 return false;
1467 }
1468
1469 if (conn.resp != 1) {
1470 setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1");
1471 mtc.stop;
1472 }
1473
1474 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1475 hex2str(cpars.mgcp_call_id), "42",
1476 conn.mgw_rtp_port,
1477 { int2str(cpars.rtp_payload_type) },
1478 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1479 cpars.rtp_sdp_format)),
1480 valueof(ts_SDP_ptime(20)) }));
1481
1482 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1483 if (not cpars.use_osmux) {
1484 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1485 mtc.stop;
1486 }
1487 cpars.got_osmux_count := cpars.got_osmux_count + 1;
1488 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1489 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1490 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1491 if (osmux_cid != -1) {
1492 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1493 mtc.stop;
1494 }
1495
1496 osmux_cid := 0;
1497 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1498 } else {
1499 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1500 }
1501
1502 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep));
1503 MGCP.send(mgcp_resp);
1504 return true;
1505}
1506
1507
1508altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr {
1509 var MgcpCommand mgcp_cmd;
1510 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1511 log("as_optional_mgcp_crcx: rx CRCX");
1512 f_handle_crcx(cpars, mgcp_cmd);
1513
1514 /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an
1515 * CRCX is handled. */
1516 repeat;
1517 }
1518}
1519
Andreas Eversberg1733de32023-07-27 16:27:05 +02001520altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001521 var MgcpCommand mgcp_cmd;
1522 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1523 log("as_optional_mgcp_mdcx: rx MDCX");
1524 log(mgcp_cmd);
1525 var charstring conn_id;
1526 var charstring rtp_payload_type;
1527 f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id);
1528 rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0];
1529
1530 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip,
1531 mgcp_cmd.sdp.origin.session_id, "42",
1532 mgw_rtp_port,
1533 { rtp_payload_type },
1534 { valueof(ts_SDP_ptime(20)) }));
1535 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp));
1536
1537 /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is
1538 * handled. */
1539 repeat;
1540 }
1541}
1542
Andreas Eversberg1733de32023-07-27 16:27:05 +02001543altstep as_optional_mgcp_dlcx(CallParameters cpars) runs on BSC_ConnHdlr {
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001544 var MgcpCommand mgcp_cmd;
1545 var boolean respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1546 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1547 log("as_optional_mgcp_dlcx: rx MGCP DLCX");
1548 if (respond_to_dlcx) {
1549 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1550 }
1551 /* Without this 'repeat', currently active other interleave and alt series exit as soon as a
1552 * DLCX is handled. */
1553 repeat;
1554 }
1555}
1556
Philipp Maier3716a5e2018-03-21 15:53:35 +01001557function f_mo_call_establish(inout CallParameters cpars)
Harald Welteb71901a2018-01-26 19:16:05 +01001558runs on BSC_ConnHdlr {
1559
Harald Welteb71901a2018-01-26 19:16:05 +01001560 var MNCC_PDU mncc;
1561 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001562 var template MgcpResponse mgcp_resp;
Philipp Maier2a98a732018-03-19 16:06:12 +01001563 var boolean respond_to_dlcx;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001564 var PDU_BSSAP bssap;
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001565 var RANAP_PDU ranap;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001566 var MgcpOsmuxCID osmux_cid;
Harald Welteb71901a2018-01-26 19:16:05 +01001567
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001568 cpars.mo_call := true;
1569
Harald Welte0bef21e2018-02-10 09:48:23 +01001570 if (cpars.emergency) {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001571 f_establish_fully(EST_TYPE_EMERG_CALL);
Oliver Smith92b280c2023-04-20 13:13:23 +02001572 } else if (cpars.csd) {
1573 f_establish_fully(EST_TYPE_MO_CSD);
Harald Welte0bef21e2018-02-10 09:48:23 +01001574 } else {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001575 f_establish_fully(EST_TYPE_MO_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001576 }
Harald Welteb71901a2018-01-26 19:16:05 +01001577
1578 /* Create MNCC and MGCP expect */
1579 f_create_mncc_expect(hex2str(cpars.called_party));
1580 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1581
Harald Welte0bef21e2018-02-10 09:48:23 +01001582 if (cpars.emergency) {
1583 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id)));
1584 } else {
Oliver Smith9c417f22023-07-07 13:25:11 +02001585 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party,
1586 cpars.bearer_cap)));
Harald Welte0bef21e2018-02-10 09:48:23 +01001587 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001588
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001589 if (cpars.stop_after_cc_setup) {
1590 return;
1591 }
1592
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001593 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass1 :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001594 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001595 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass2 :=
1596 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_2.mgw_rtp_ip, ?);
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001597
1598 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 +01001599 var boolean got_mncc_setup_compl_ind := false;
1600 var boolean got_cc_connect := false;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001601
Harald Welteb71901a2018-01-26 19:16:05 +01001602 interleave {
1603 [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001604 log("f_mo_call_establish 1: rx MNCC SETUP ind");
Harald Welteb71901a2018-01-26 19:16:05 +01001605 cpars.mncc_callref := mncc.u.signal.callref;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001606 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1607 }
1608
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001609 /* First MGCP CRCX */
Harald Welteb71901a2018-01-26 19:16:05 +01001610 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001611 log("f_mo_call_establish 2: rx 1st CRCX");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001612 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1613 break;
1614 }
Philipp Maierf1e02bb2018-03-15 16:30:00 +01001615 }
1616
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001617 /* Second MGCP CRCX */
1618 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
1619 log("f_mo_call_establish 6: rx 2nd CRCX");
1620 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1621 break;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001622 }
Harald Welteb71901a2018-01-26 19:16:05 +01001623 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001624
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001625 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1626 log("f_mo_call_establish 3: rx RTP CREATE");
1627 /* Call Proceeding */
1628 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1629 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001630
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001631 /* Alerting */
1632 MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref));
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001633 }
Harald Welte9b751a62019-04-14 17:39:29 +02001634
Neels Hofmeyreccaa992019-10-15 16:42:21 +02001635 //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001636 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001637 log("f_mo_call_establish 4: rx Assignment Request");
1638 var BSSMAP_IE_AoIP_TransportLayerAddress tla;
1639 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001640 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
1641
Oliver Smithd6c90062023-05-08 15:20:20 +02001642 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer)) {
1643 setverdict(fail, "MSC sent Assignment Request without AoIP Transport Layer IE");
1644 mtc.stop;
1645 }
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001646 if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass1)
1647 and not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass2)) {
1648 log("Expected one of: 1:", tla_ass1, " 2:", tla_ass2);
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001649 log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer);
1650 setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE");
1651 mtc.stop;
1652 }
1653
Oliver Smith90f31bb2023-08-23 13:31:35 +02001654 if (cpars.csd and not match(bssap.pdu.bssmap.assignmentRequest.codecList.codecElements,
1655 {ts_CodecCSData})) {
1656 setverdict(fail, "MSC sent Assignment Request with unexpected codec list for CSD ",
1657 bssap.pdu.bssmap.assignmentRequest.codecList);
1658 mtc.stop;
1659 }
1660
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001661 tla := valueof(f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port));
Oliver Smith90f31bb2023-08-23 13:31:35 +02001662
1663 if (cpars.csd) {
1664 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecCSData}));
1665 } else {
1666 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
1667 }
1668
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001669 if (cpars.use_osmux) {
1670 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1671 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1672 mtc.stop;
1673 }
1674 osmuxCID := valueof(ts_OsmuxCID(0));
1675 if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1676 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1677 mtc.stop;
1678 }
1679 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1680 } else {
1681 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1682 }
1683 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001684 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001685 [] BSSAP.receive(tr_RANAP_RabAssReq(*)) -> value ranap {
1686 log("f_mo_call_establish 4.iu: rx RANAP RAB Assignment Request");
1687 var RAB_SetupOrModifiedList l := {
1688 {
1689 {
1690 id := id_RAB_SetupOrModifiedItem,
1691 criticality := ignore,
1692 value_ := {
1693 rAB_SetupOrModifiedItem := {
1694 rAB_ID := int2bit(23, 8),
1695 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1696 iuTransportAssociation := {
1697 bindingID := '040c0000'O
1698 },
1699 dl_dataVolumes := omit,
1700 iE_Extensions := omit
1701 }
1702 }
1703 }
1704 }
1705 };
1706 BSSAP.send(ts_RANAP_RabAssResp(l));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001707 }
Harald Welte9b751a62019-04-14 17:39:29 +02001708
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001709 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1710 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1711 log("f_mo_call_establish 5: rx MDCX for the RAN side");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001712 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 +01001713 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001714 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001715 { int2str(cpars.rtp_payload_type) },
1716 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1717 cpars.rtp_sdp_format)),
1718 valueof(ts_SDP_ptime(20)) }));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001719
1720 if (cpars.use_osmux) {
1721 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1722 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1723 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1724 mtc.stop;
1725 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001726 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 +02001727 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001728 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 +02001729 }
1730 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001731 }
Harald Welte9b751a62019-04-14 17:39:29 +02001732
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001733 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {
1734 log("f_mo_call_establish 7: rx CC Alerting");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001735
1736 if (cpars.ran_clear_when_alerting) {
1737 if (g_pars.ran_is_geran) {
1738 BSSAP.send(ts_BSSMAP_ClearRequest(0));
1739 } else {
1740 BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention));
1741 }
1742 break;
1743 }
1744
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001745 cpars.mncc_callref := mncc.u.signal.callref;
1746 /* Call Proceeding */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001747 var octetstring ip;
1748 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1749 if (is_ipv6) {
1750 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1751 } else {
1752 ip := f_inet_addr(cpars.mncc_rtp_ip);
1753 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001754 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001755 is_ipv6, ip,
1756 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001757 /* payload type 3 = GSM FR */ 3));
1758 MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref));
1759 }
1760
1761 [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc {
1762 log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001763 got_mncc_setup_compl_ind := true;
1764 if (not cpars.expect_release and got_cc_connect) {
1765 break;
1766 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001767 }
1768
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001769 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) {
1770 log("f_mo_call_establish 10: rx CC CONNECT");
1771 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id)));
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001772 got_cc_connect := true;
1773 if (not cpars.expect_release and got_mncc_setup_compl_ind) {
1774 break;
1775 }
Harald Welteb71901a2018-01-26 19:16:05 +01001776 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001777
1778 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1779 log("f_mo_call_establish 11: rx CC RELEASE");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001780 if (not cpars.expect_release) {
1781 setverdict(fail, "Got unexpected CC Release");
1782 mtc.stop;
1783 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001784 f_expect_clear();
1785 break;
1786 }
1787 }
1788
1789 f_sleep(0.5);
1790 deactivate(mdcx);
1791
1792 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1793 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1794 } else {
1795 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1796 mtc.stop;
Harald Welteb71901a2018-01-26 19:16:05 +01001797 }
1798
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001799 log("f_mo_call_establish DONE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001800 setverdict(pass);
1801}
Harald Welteb71901a2018-01-26 19:16:05 +01001802
Harald Welte4c422b72019-02-17 16:27:10 +01001803function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001804runs on BSC_ConnHdlr {
1805
1806 var MobileIdentityLV mi;
1807 var MNCC_PDU mncc;
1808 var MgcpCommand mgcp_cmd;
1809 var boolean respond_to_dlcx;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001810 var boolean dlcx_contained_ci := false;
1811 var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand;
1812
1813 if (is_csfb) {
1814 t_clear := tr_BSSMAP_ClearCommandCSFB;
1815 }
1816
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001817 log("f_call_hangup 0: tx MNCC_DISC_REQ");
Harald Welteb71901a2018-01-26 19:16:05 +01001818 MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1819 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1820
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001821 log("f_call_hangup 1: rx DTAP CC DISC");
1822
Philipp Maier3716a5e2018-03-21 15:53:35 +01001823 if (release_by_ms) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001824 var BIT1 tid_remote := '1'B;
1825 if (cpars.mo_call) {
1826 tid_remote := '0'B;
1827 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001828 /* B-side (MS) Release of call */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001829 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 +01001830 MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001831 log("f_call_hangup 2: rx MNCC REL ind");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001832 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001833 log("f_call_hangup 3: rx DTAP CC REL COMPL");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001834 } else {
1835 /* A-side (PLMN) Release of call */
1836 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42))));
1837 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
Oliver Smith6f546a92023-07-10 15:03:31 +02001838 log("f_call_hangup 2.a: rx DTAP CC RELEASE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001839 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
Oliver Smith6f546a92023-07-10 15:03:31 +02001840 log("f_call_hangup 3.a: rx MNCC REL cnf");
1841 MNCC.receive(tr_MNCC_REL_cnf(cpars.mncc_callref, cause := *));
Philipp Maier3716a5e2018-03-21 15:53:35 +01001842 }
Harald Welteb71901a2018-01-26 19:16:05 +01001843
Philipp Maier2a98a732018-03-19 16:06:12 +01001844 respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1845
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001846 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 +01001847 var default dlcx := activate(as_optional_mgcp_dlcx(cpars));
Harald Welte9b751a62019-04-14 17:39:29 +02001848
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001849 /* clearing of radio channel */
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001850 alt {
1851 [g_pars.ran_is_geran] BSSAP.receive(t_clear) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001852 log("f_call_hangup 5: rx BSSAP Clear Command");
1853 BSSAP.send(ts_BSSMAP_ClearComplete);
1854 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1855 log("f_call_hangup 6: rx SCCP DISC");
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001856 setverdict(pass);
Philipp Maier2a98a732018-03-19 16:06:12 +01001857 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001858 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) {
1859 log("f_call_hangup 5.iu: rx Iu Release Command");
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001860 BSSAP.send(ts_RANAP_IuReleaseComplete);
1861 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001862 log("f_call_hangup 6.iu: rx SCCP DISC");
1863 setverdict(pass);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001864 }
1865 }
1866
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001867 f_sleep(1.0);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001868 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1869 log("f_call_hangup 9: done");
1870
1871 deactivate(mdcx);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001872 deactivate(dlcx);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001873}
1874
Oliver Smith98e24bc2023-07-07 12:36:59 +02001875function f_mt_call(inout CallParameters cpars, float open_time := 5.0)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001876runs on BSC_ConnHdlr {
1877
1878 f_mt_call_establish(cpars);
1879
Oliver Smith98e24bc2023-07-07 12:36:59 +02001880 f_call_keep_open(cpars, open_time);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001881
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001882 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001883 f_call_hangup(cpars, true);
1884
Oliver Smith3a33e552023-07-06 11:55:12 +02001885 /* Unregister the IMSI that was registered in f_mt_call_establish */
1886 f_ran_unregister_imsi(g_pars.imsi);
1887
Philipp Maier3716a5e2018-03-21 15:53:35 +01001888 setverdict(pass);
1889}
1890
Oliver Smith98e24bc2023-07-07 12:36:59 +02001891function f_mo_call(inout CallParameters cpars, float open_time := 5.0)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001892runs on BSC_ConnHdlr {
1893
1894 f_mo_call_establish(cpars);
1895
Oliver Smith98e24bc2023-07-07 12:36:59 +02001896 f_call_keep_open(cpars, open_time);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001897
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001898 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001899 f_call_hangup(cpars, false);
1900
Harald Welteb71901a2018-01-26 19:16:05 +01001901 setverdict(pass);
1902}
Harald Weltea49e36e2018-01-21 19:29:33 +01001903
Daniel Willmann8b084372018-02-04 13:35:26 +01001904function f_mo_seq_dtmf_dup(inout CallParameters cpars)
1905runs on BSC_ConnHdlr {
1906
1907 timer T := 1.0;
Daniel Willmann8b084372018-02-04 13:35:26 +01001908 var MNCC_PDU mncc;
1909 var MgcpCommand mgcp_cmd;
1910 var template PDU_ML3_MS_NW dtmf_dtap;
1911
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001912 f_mo_call_establish(cpars);
Daniel Willmann8b084372018-02-04 13:35:26 +01001913
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001914 /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by
1915 * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001916
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001917 /* Find out the next NSD that will be used, from RAN emulation. */
1918 var N_Sd_Array last_n_sd := f_bssmap_last_n_sd();
1919 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 +01001920
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001921 /* Compose DTAP with this correct NSD */
Daniel Willmann8b084372018-02-04 13:35:26 +01001922 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001923
1924 /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */
1925 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001926 T.start;
1927 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001928 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
1929 log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind");
1930 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001931 [] T.timeout {
1932 setverdict(fail, "Timeout waiting for START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001933 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001934 }
1935 }
1936
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001937 /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message
1938 * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */
1939 dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2);
Daniel Willmann92f66272018-02-06 15:50:52 +01001940 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true));
Daniel Willmann8b084372018-02-04 13:35:26 +01001941 T.start;
1942 alt {
1943 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001944 setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001945 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001946 }
1947 [] T.timeout { }
1948 }
1949
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001950 /* Here the NSD should be correct again and we see a DTMF. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001951 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001952 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001953 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001954 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) {
1955 log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind");
1956 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001957 [] T.timeout {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001958 setverdict(fail, "Timeout waiting for final START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001959 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001960 }
1961 }
1962
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001963 f_call_hangup(cpars, true);
Daniel Willmann8b084372018-02-04 13:35:26 +01001964 setverdict(pass);
1965}
Harald Welte9b751a62019-04-14 17:39:29 +02001966
Harald Welte1ddc7162018-01-27 14:25:46 +01001967/* expect a clear command */
Harald Welte5946b332018-03-18 23:32:21 +01001968altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr {
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001969 var PDU_BSSAP bssap;
Harald Welte5946b332018-03-18 23:32:21 +01001970 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1971 BSSAP.send(ts_BSSMAP_ClearComplete);
1972 alt {
Harald Welte6811d102019-04-14 22:23:14 +02001973 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte5946b332018-03-18 23:32:21 +01001974 setverdict(pass);
1975 }
1976 [] BSSAP.receive {
1977 setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001978 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001979 }
1980 }
1981 }
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001982 [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap {
1983 setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001984 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001985 }
1986}
1987
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001988function f_expect_clear(float t := 5.0, boolean verify_vlr_cell_id := true) runs on BSC_ConnHdlr {
Harald Welte1ddc7162018-01-27 14:25:46 +01001989 timer T := t;
1990
1991 T.start;
1992 alt {
Harald Welte9b751a62019-04-14 17:39:29 +02001993 [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { }
1994 [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { }
Harald Welte1ddc7162018-01-27 14:25:46 +01001995 [] T.timeout {
Harald Welte5946b332018-03-18 23:32:21 +01001996 setverdict(fail, "Timeout waiting for ClearCommand/Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001997 mtc.stop;
Harald Welte1ddc7162018-01-27 14:25:46 +01001998 }
1999 }
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02002000
2001 if (verify_vlr_cell_id) {
2002 /* Now the conn is gone, but the VLR reflects the cell ID */
2003 f_verify_vty_lac_ci();
2004 }
Harald Welte1ddc7162018-01-27 14:25:46 +01002005}
2006
Andreas Eversberge5a6ef12023-07-28 10:45:20 +02002007function f_create_bssmap_exp_n_connect(integer targetPointCode) runs on BSC_ConnHdlr {
2008 BSSAP_PROC.call(RAN_register_n_connect:{targetPointCode, self}) {
2009 [] BSSAP_PROC.getreply(RAN_register_n_connect:{?, ?}) {};
Neels Hofmeyr0ac63152019-05-07 01:20:17 +02002010 }
2011}
2012
2013function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array {
2014 var N_Sd_Array last_n_sd;
2015 BSSAP_PROC.call(RAN_last_n_sd:{self, -}) {
2016 [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) {
2017 return last_n_sd;
2018 };
2019 }
2020}
2021
2022function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr {
2023 BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) {
2024 [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self});
2025 }
2026}
2027
Harald Weltef45efeb2018-04-09 18:19:24 +02002028type record SmsParametersTp {
2029 OCT1 msg_ref,
2030 TP_DA da,
2031 OCT1 pid,
2032 OCT1 dcs,
2033 integer udl,
2034 octetstring ud
2035}
2036type record SmsParametersRp {
2037 OCT1 msg_ref,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002038 RP_NumberingPlan_and_NumberDigits smsc_addr optional
Harald Weltef45efeb2018-04-09 18:19:24 +02002039}
2040type record SmsParameters {
2041 SmsParametersTp tp,
2042 SmsParametersRp rp,
2043 uint3_t tid,
2044 OCT1 dlci,
2045 uint7_t exp_rp_err optional
2046}
2047
2048template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := {
2049 tP_DA_NoPad := {
2050 tP_LengthIndicator := 0, /* overwritten */
2051 tP_NumberingPlanID := npl,
2052 tP_TypeOfNumber := ton,
2053 tp_Spare := '0'B,
2054 tP_DAValue := addr
2055 }
2056}
2057
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002058template RP_NumberingPlan_and_NumberDigits t_RP_Addr(template hexstring addr,
2059 template BIT4 npi := '0001'B,
2060 template BIT3 ton := '001'B,
2061 template BIT1 ext := '1'B) := {
2062 rP_NumberingPlanIdentification := npi,
2063 rP_TypeOfNumber := ton,
2064 rP_Ext := ext,
2065 rP_NumberDigits := addr
2066}
2067
Harald Weltef45efeb2018-04-09 18:19:24 +02002068template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := {
2069 tp := {
2070 msg_ref := '23'O,
2071 da := ts_TP_DA('0000'B, '000'B, tp_daddr),
2072 pid := '00'O,
2073 dcs := '00'O,
2074 udl := 0,
2075 ud := ''O
2076 },
2077 rp := {
2078 msg_ref := '42'O,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002079 /* We don't really need to have both SM-RP-DA/OA here, because only one IE
Vadim Yanitskiyafb15a82020-01-05 14:04:53 +01002080 * is included in MO/MT SMS, and in the most cases it's the SMSC address.
2081 * NOTE: this address is currently hard-coded by OsmoMSC. */
2082 smsc_addr := t_RP_Addr('447785016005'H)
Harald Weltef45efeb2018-04-09 18:19:24 +02002083 },
2084 tid := 0,
2085 dlci := '03'O,
2086 exp_rp_err := omit
2087}
2088
2089private altstep as_other_sms() runs on BSC_ConnHdlr {
2090 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) {
2091 setverdict(fail, "Unexpected SMS related PDU from MSC");
Daniel Willmannafce8662018-07-06 23:11:32 +02002092 mtc.stop;
Harald Weltef45efeb2018-04-09 18:19:24 +02002093 }
2094}
2095
Vadim Yanitskiy9cc019a2018-11-15 02:06:07 +07002096/* Submit a MO RP-SMMA over an already existing DTAP connection */
2097function f_mo_smma(inout SmsParameters spars)
2098runs on BSC_ConnHdlr {
2099 var template (value) RPDU_MS_SGSN rp_mo;
2100 var template (value) PDU_ML3_MS_NW l3_mo;
2101
2102 var default d := activate(as_other_sms());
2103
2104 /* just in case this is routed to SMPP.. */
2105 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2106
2107 rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref);
2108 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
2109 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2110 /* receive CP-ACK for CP-DATA above */
2111 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
2112
2113 deactivate(d);
2114 setverdict(pass);
2115}
2116
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002117/* Submit a MO-SMS over an already existing DTAP connection */
2118function f_mo_sms_submit(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02002119runs on BSC_ConnHdlr {
2120 var template (value) TPDU_RP_DATA_MS_SGSN tp_mo;
2121 var template (value) RPDU_MS_SGSN rp_mo;
2122 var template (value) PDU_ML3_MS_NW l3_mo;
2123
Harald Weltef45efeb2018-04-09 18:19:24 +02002124 var default d := activate(as_other_sms());
2125
Harald Weltef640a012018-04-14 17:49:21 +02002126 /* just in case this is routed to SMPP.. */
2127 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2128
Harald Weltef45efeb2018-04-09 18:19:24 +02002129 tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs,
2130 spars.tp.udl, spars.tp.ud);
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002131 rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, omit, spars.rp.smsc_addr, tp_mo);
Harald Weltef45efeb2018-04-09 18:19:24 +02002132 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
2133 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2134 /* receive CP-ACK for CP-DATA above */
2135 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
2136
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002137 deactivate(d);
2138 setverdict(pass);
2139}
2140
2141/* Wait RP-ACK for MO-SMS on an already existing DTAP connection */
2142function f_mo_sms_wait_rp_ack(inout SmsParameters spars)
2143runs on BSC_ConnHdlr {
2144 var template (value) PDU_ML3_MS_NW l3_mo;
2145
2146 var template TPDU_RP_DATA_SGSN_MS tp_mt;
2147 var template RPDU_SGSN_MS rp_mt;
2148 var template PDU_ML3_NW_MS l3_mt;
2149
2150 var default d := activate(as_other_sms());
2151
2152 /* just in case this is routed to SMPP.. */
2153 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2154
Harald Weltef45efeb2018-04-09 18:19:24 +02002155 if (ispresent(spars.exp_rp_err)) {
2156 /* expect an RP-ERROR message from MSC with given cause */
2157 rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err);
2158 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
2159 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2160 /* send CP-ACK for CP-DATA just received */
2161 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
2162 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2163 } else {
2164 /* expect RP-ACK for RP-DATA */
2165 rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref);
2166 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
2167 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2168 /* send CP-ACO for CP-DATA just received */
2169 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
2170 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2171 }
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002172
Harald Weltef45efeb2018-04-09 18:19:24 +02002173 deactivate(d);
2174 setverdict(pass);
2175}
2176
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002177/* Submit a MO-SMS, and wait for RP-ACK on an existing
2178 * (and authenticated, ...) DTAP connection */
2179function f_mo_sms(inout SmsParameters spars)
2180runs on BSC_ConnHdlr {
2181 f_mo_sms_submit(spars);
2182 f_mo_sms_wait_rp_ack(spars);
2183}
2184
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002185function f_mt_sms_deliver_pdu(in SmsParameters spars)
2186runs on BSC_ConnHdlr
2187return template PDU_DTAP_MT {
2188 var template TPDU_RP_DATA_SGSN_MS tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?);
2189 var template RPDU_SGSN_MS rp_mt := tr_RP_DATA_MT(?, spars.rp.smsc_addr, omit, tp_mt);
2190 var template PDU_ML3_NW_MS l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt));
2191 return tr_PDU_DTAP_MT(l3_mt, spars.dlci);
2192}
2193
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002194/* Wait for MT SMS on an already existing DTAP connection */
2195function f_mt_sms_expect(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02002196runs on BSC_ConnHdlr {
Harald Weltef45efeb2018-04-09 18:19:24 +02002197 var template (value) PDU_ML3_MS_NW l3_mo;
Harald Weltef45efeb2018-04-09 18:19:24 +02002198 var PDU_DTAP_MT dtap_mt;
2199
2200 var default d := activate(as_other_sms());
2201
2202 /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002203 BSSAP.receive(f_mt_sms_deliver_pdu(spars)) -> value dtap_mt;
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002204
Harald Weltef45efeb2018-04-09 18:19:24 +02002205 /* Extract relevant identifiers */
2206 spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio);
2207 spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference;
2208
2209 /* send CP-ACK for CP-DATA just received */
2210 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO);
2211 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2212
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002213 deactivate(d);
2214 setverdict(pass);
2215}
2216
2217/* Send RP-ACK for MT-SMS over an already existing DTAP connection */
2218function f_mt_sms_send_rp_ack(inout SmsParameters spars)
2219runs on BSC_ConnHdlr {
2220 var template (value) RPDU_MS_SGSN rp_mo;
2221 var template (value) PDU_ML3_MS_NW l3_mo;
2222 var template PDU_ML3_NW_MS l3_mt;
2223
2224 var default d := activate(as_other_sms());
2225
Harald Weltef45efeb2018-04-09 18:19:24 +02002226 /* send RP-ACK for RP-DATA */
2227 rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref);
2228 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2229 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2230
2231 /* expect CP-ACK for CP-DATA(RP-ACK) just sent */
Harald Weltee008eea2018-04-14 21:05:48 +02002232 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
Harald Weltef45efeb2018-04-09 18:19:24 +02002233 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2234
2235 deactivate(d);
2236 setverdict(pass);
2237}
2238
Vadim Yanitskiy56318522018-11-24 03:40:47 +07002239/* Send RP-ERROR for MT-SMS over an already existing DTAP connection */
2240function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause)
2241runs on BSC_ConnHdlr {
2242 var template (value) RPDU_MS_SGSN rp_mo;
2243 var template (value) PDU_ML3_MS_NW l3_mo;
2244 var template PDU_ML3_NW_MS l3_mt;
2245
2246 var default d := activate(as_other_sms());
2247
2248 /* send RP-ACK for RP-DATA */
2249 rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause);
2250 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2251 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2252
2253 /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */
2254 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
2255 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2256
2257 deactivate(d);
2258 setverdict(pass);
2259}
2260
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002261/* Wait for a MT-SMS and send RP-ACK over an already existing
2262 * (and authenticated, ...) DTAP connection */
2263function f_mt_sms(inout SmsParameters spars)
2264runs on BSC_ConnHdlr {
2265 f_mt_sms_expect(spars);
2266 f_mt_sms_send_rp_ack(spars);
2267}
Harald Weltea49e36e2018-01-21 19:29:33 +01002268
2269
Harald Weltea49e36e2018-01-21 19:29:33 +01002270}