blob: 64e2aff48938316a5386756073ad5d0d40401878 [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,
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200136 boolean verify_cell_id,
137 OCT3 common_id_last_eutran_plmn optional
Harald Weltea49e36e2018-01-21 19:29:33 +0100138};
139
Harald Welte9de84792018-01-28 01:06:35 +0100140/* get a one-octet bitmaks of supported algorithms based on Classmark information */
Eric Wild26f4a622021-05-17 15:27:05 +0200141function 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 +0100142 var BIT8 res := '00000001'B; /* A5/0 always supported */
143
144 if (cm2.a5_1 == '0'B) {
145 res := res or4b '00000010'B;
146 }
147 if (cm2.classmarkInformationType2_oct5.a5_2 == '1'B ) {
148 res := res or4b '00000100'B;
149 }
150 if (cm2.classmarkInformationType2_oct5.a5_3 == '1'B) {
151 res := res or4b '00001000'B;
152 }
Eric Wild26f4a622021-05-17 15:27:05 +0200153 if (not istemplatekind(cm3, "omit")) {
154 var BSSMAP_IE_ClassmarkInformationType3 v := valueof(cm3);
155 var BIT8 tmp := oct2bit(v.classmark3ValuePart[0]) and4b '00001111'B;
156 res := res or4b (tmp << 4);
157 }
158
Harald Welte9de84792018-01-28 01:06:35 +0100159 return bit2oct(res);
160}
161
162/* determine the best algorithm available within the bit-mask */
163function f_best_alg_from_mask(OCT1 alg_in) return OCT1 {
164 var BIT8 alg := oct2bit(alg_in);
165 var BIT8 ordered_algs[8] := {
166 '10000000'B, '01000000'B, '00100000'B, '00010000'B,
167 '00001000'B, /* A5/3 */
168 '00000010'B, /* A5/1 */
169 '00000100'B, /* A5/2 */
170 '00000001'B /* A5/0 */ }
171 for (var integer i := 0; i < sizeof(ordered_algs); i := i+1) {
172 if (alg and4b ordered_algs[i] != '00000000'B) {
173 return bit2oct(ordered_algs[i]);
174 }
175 }
176 return '00'O;
177}
178
179/* return an integer like '1' for A5/1 based on a mask (with only one bit set */
180function f_alg_from_mask(OCT1 mask_in) return integer {
181 var BIT8 mask := oct2bit(mask_in);
182 for (var integer i := 0; i < 8; i := i+1) {
183 if (mask and4b ('00000001'B << i) != '00000000'B) {
184 return i;
185 }
186 }
187 return -1;
188}
189
Eric Wild26f4a622021-05-17 15:27:05 +0200190/* return true for A5/x supported by OCT1 bitmask */
191function f_alg_supported_by_mask(OCT1 mask_in, integer whicha5) return boolean {
192 var BIT8 mask := oct2bit(mask_in);
193 if (mask and4b ('00000001'B << whicha5) != '00000000'B) {
194 return true;
195 }
196 return false;
197}
198
Harald Weltea10db902018-01-27 12:44:49 +0100199/* altstep for the global guard timer */
200private altstep as_Tguard() runs on BSC_ConnHdlr {
201 [] g_Tguard.timeout {
Daniel Willmann90829d62018-02-15 17:45:14 +0100202 setverdict(fail, "Tguard timeout");
Daniel Willmannafce8662018-07-06 23:11:32 +0200203 mtc.stop;
Harald Weltea10db902018-01-27 12:44:49 +0100204 }
205}
206
207/* init function, called as first function in new BSC_ConnHdlr */
Harald Weltead2952e2018-01-27 14:12:46 +0100208function f_init_handler(BSC_ConnHdlrPars pars, float t_guard := 60.0) runs on BSC_ConnHdlr {
Harald Weltea10db902018-01-27 12:44:49 +0100209 /* make parameters available via component variable */
210 g_pars := pars;
211 /* Start guard timer and activate it as default */
Harald Weltead2952e2018-01-27 14:12:46 +0100212 g_Tguard.start(t_guard);
Harald Weltea10db902018-01-27 12:44:49 +0100213 activate(as_Tguard());
Harald Weltef640a012018-04-14 17:49:21 +0200214 /* Route all SMPP messages for our MSISDN to us */
215 f_create_smpp_expect(hex2str(pars.msisdn));
Philipp Maier57865482019-01-07 18:33:13 +0100216
Harald Welte4263c522018-12-06 11:56:27 +0100217 /* Route all SGs message for our IMSI to us */
Philipp Maier57865482019-01-07 18:33:13 +0100218 if (g_pars.sgsap_enable == true) {
219 f_create_sgsap_expect(pars.imsi);
220 }
Philipp Maieraeb29a82018-11-08 17:40:53 +0100221
222 if (g_pars.ipa_ctrl_enable == true) {
Pau Espin Pedrol9a5b8ff2021-01-04 19:01:31 +0100223 f_ipa_ctrl_start_client(g_pars.ipa_ctrl_ip, g_pars.ipa_ctrl_port);
Philipp Maieraeb29a82018-11-08 17:40:53 +0100224 }
Philipp Maierc39a9d82018-11-09 11:21:08 +0100225
226 map(self:MSCVTY, system:MSCVTY);
227 f_vty_set_prompts(MSCVTY);
228 f_vty_transceive(MSCVTY, "enable");
Harald Weltea10db902018-01-27 12:44:49 +0100229}
230
Harald Weltea49e36e2018-01-21 19:29:33 +0100231
Harald Welte6811d102019-04-14 22:23:14 +0200232/* Callback function from general RAN_Emulation whenever a connectionless
Harald Weltea49e36e2018-01-21 19:29:33 +0100233 * BSSMAP message arrives. Canreturn a PDU_BSSAPthat should be sent in return */
234private function BscUnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200235runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Weltea49e36e2018-01-21 19:29:33 +0100236 var template PDU_BSSAP resp := omit;
237
238 log("BSSMAP_BscUnitdataCallback");
239 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200240 if (match(bssap, tr_BSSMAP_Reset(g_ran_ops.use_osmux))){
Harald Weltea49e36e2018-01-21 19:29:33 +0100241 log("BSSMAP_BscUnitdataCallback: Responding to RESET with RESET-ACK");
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200242 resp := ts_BSSMAP_ResetAck(g_ran_ops.use_osmux);
Harald Weltea49e36e2018-01-21 19:29:33 +0100243 }
244
245 /* FIXME: Handle paging, etc. */
246 return resp;
247}
248
Harald Welte9b751a62019-04-14 17:39:29 +0200249private function RncUnitdataCallback(RANAP_PDU ranap)
250runs on RAN_Emulation_CT return template RANAP_PDU {
251 var template RANAP_PDU resp := omit;
252
253 log("RANAP_RncUnitdataCallback");
254 /* answer all RESET with RESET ACK */
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200255 if (match(ranap, tr_RANAP_Reset())) {
Harald Welte9b751a62019-04-14 17:39:29 +0200256 log("RANAP_RncUnitdataCallback: Responding to RESET with RESET-ACK");
257 var CN_DomainIndicator dom;
258 dom := ranap.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator;
259 resp := ts_RANAP_ResetAck(dom);
260 }
261
262 /* FIXME: Handle paging, etc. */
263 return resp;
264}
265
266
Harald Welte6811d102019-04-14 22:23:14 +0200267const RanOps BSC_RanOps := {
Harald Weltea49e36e2018-01-21 19:29:33 +0100268 /* Create call-back for inbound connections from MSC (hand-over) */
Harald Welte6811d102019-04-14 22:23:14 +0200269 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Weltea49e36e2018-01-21 19:29:33 +0100270 unitdata_cb := refers(BscUnitdataCallback),
Harald Welte9b751a62019-04-14 17:39:29 +0200271 ranap_create_cb := refers(RAN_Emulation.RanapExpectedCreateCallback),
272 ranap_unitdata_cb := refers(RncUnitdataCallback),
273 ps_domain := false,
Harald Weltea49e36e2018-01-21 19:29:33 +0100274 decode_dtap := true,
Harald Weltea4ca4462018-02-09 00:17:14 +0100275 role_ms := true,
Harald Welte2fce7882019-04-15 11:48:05 +0200276 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200277 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200278 use_osmux := false,
Eric Wild49888a62022-03-30 03:16:11 +0200279 bssap_reset_retries := 1,
Harald Weltea4ca4462018-02-09 00:17:14 +0100280 sccp_addr_local := omit,
281 sccp_addr_peer := omit
Harald Weltea49e36e2018-01-21 19:29:33 +0100282}
283
284
285private function MnccUnitdataCallback(MNCC_PDU mncc)
286runs on MNCC_Emulation_CT return template MNCC_PDU {
287 log("Ignoring MNCC", mncc);
288 return omit;
289}
290
291const MnccOps BCC_MnccOps := {
292 create_cb := refers(MNCC_Emulation.ExpectedCreateCallback),
293 unitdata_cb := refers(MnccUnitdataCallback)
294}
295
296
297
Harald Welte6811d102019-04-14 22:23:14 +0200298/* Encode 'l3' and ask RAN_Emulation to create new connection with COMPL L3 INFO */
Harald Weltea49e36e2018-01-21 19:29:33 +0100299function f_bssap_compl_l3(PDU_ML3_MS_NW l3)
300runs on BSC_ConnHdlr {
301 log("Sending COMPL L3: ", l3);
302 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
303 BSSAP.send(ts_BSSAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own,
304 valueof(ts_BSSMAP_ComplL3(g_pars.cell_id, l3_enc))));
Harald Welte71b69332018-01-21 20:43:53 +0100305 alt {
Harald Welte6811d102019-04-14 22:23:14 +0200306 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
307 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte71b69332018-01-21 20:43:53 +0100308 setverdict(fail, "DISC.ind from SCCP");
Daniel Willmannafce8662018-07-06 23:11:32 +0200309 mtc.stop;
Harald Welte71b69332018-01-21 20:43:53 +0100310 }
311 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100312}
313
Harald Welte9b751a62019-04-14 17:39:29 +0200314/* generate Iu LAI from BSSAP CGI */
315private function f_IuLAI_from_BssmapCI(BSSMAP_IE_CellIdentifier ci) return LAI {
316 var LAI lai;
317 if (ischosen(ci.cellIdentification.cI_CGI)) {
318 lai.pLMNidentity := ci.cellIdentification.cI_CGI.mcc_mnc;
319 lai.lAC := ci.cellIdentification.cI_CGI.lac;
320 } else if (ischosen(ci.cellIdentification.cI_SAI)) {
321 lai.pLMNidentity := ci.cellIdentification.cI_SAI.mcc_mnc;
322 lai.lAC := ci.cellIdentification.cI_SAI.lac;
323 } else if (ischosen(ci.cellIdentification.ci_LAC_RNC_CI)) {
324 lai.pLMNidentity := ci.cellIdentification.ci_LAC_RNC_CI.mcc_mnc;
325 lai.lAC := ci.cellIdentification.ci_LAC_RNC_CI.lac;
326 } else {
327 mtc.stop;
328 }
329 lai.iE_Extensions := omit;
330 return lai;
331}
332
333/* like f_bssap_compl_l3() but for 3G */
334function f_ranap_initial_ue(PDU_ML3_MS_NW l3)
335runs on BSC_ConnHdlr {
336 log("Sending InitialUE: ", l3);
337 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3);
338 var RANAP_PDU ranap;
339 var LAI lai := f_IuLAI_from_BssmapCI(g_pars.cell_id);
340 var SAI sai := {
341 pLMNidentity := lai.pLMNidentity,
342 lAC := lai.lAC,
343 sAC := '0000'O, /* FIXME */
344 iE_Extensions := omit
345 };
346 var IuSignallingConnectionIdentifier sigc_id := int2bit(23, 24);
347 var GlobalRNC_ID grnc_id := {
348 pLMNidentity := lai.pLMNidentity,
349 rNC_ID := 2342 /* FIXME */
350 };
351
352 ranap := valueof(ts_RANAP_initialUE_CS(lai, sai, l3_enc, sigc_id, grnc_id));
353 BSSAP.send(ts_RANAP_Conn_Req(g_pars.sccp_addr_peer, g_pars.sccp_addr_own, ranap));
354 alt {
355 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_CONF_IND) {}
356 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
357 setverdict(fail, "DISC.ind from SCCP");
358 mtc.stop;
359 }
360 }
361}
362
Harald Weltedceacc72019-04-21 20:58:35 +0200363/* Send BSSMAP Complete L3 or RANAP Initial UE depending on 2G/3G RAN type */
364function f_cl3_or_initial_ue(PDU_ML3_MS_NW l3)
365runs on BSC_ConnHdlr {
366 if (g_pars.ran_is_geran) {
367 f_bssap_compl_l3(l3);
368 } else {
369 f_ranap_initial_ue(l3);
370 }
371}
372
Harald Welte081b19a2018-02-10 09:11:13 +0100373type enumerated EstablishType {
374 EST_TYPE_MO_CALL,
Harald Welte0bef21e2018-02-10 09:48:23 +0100375 EST_TYPE_EMERG_CALL,
Harald Weltef45efeb2018-04-09 18:19:24 +0200376 EST_TYPE_PAG_RESP,
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700377 EST_TYPE_MO_SMS,
Oliver Smith92b280c2023-04-20 13:13:23 +0200378 EST_TYPE_SS_ACT,
379 EST_TYPE_MO_CSD
Harald Welte081b19a2018-02-10 09:11:13 +0100380};
381
Harald Weltea49e36e2018-01-21 19:29:33 +0100382/* helper function to fully establish a dedicated channel */
Harald Welteb9e86fa2018-04-09 18:18:31 +0200383function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL)
Harald Weltea49e36e2018-01-21 19:29:33 +0100384runs on BSC_ConnHdlr {
Harald Welte081b19a2018-02-10 09:11:13 +0100385 var PDU_ML3_MS_NW l3_info;
Harald Welteb9e86fa2018-04-09 18:18:31 +0200386 var MobileIdentityLV mi;
387
388 /* If we have a TMSI, use TMSI instead of IMSI */
389 if (ispresent(g_pars.tmsi)) {
390 mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi));
391 } else {
392 mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
393 }
394
Harald Welte081b19a2018-02-10 09:11:13 +0100395 select (etype) {
396 case (EST_TYPE_MO_CALL) {
397 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
398 }
Oliver Smith92b280c2023-04-20 13:13:23 +0200399 case (EST_TYPE_MO_CSD) {
400 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
401 }
Harald Welte0bef21e2018-02-10 09:48:23 +0100402 case (EST_TYPE_EMERG_CALL) {
403 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi));
404 }
Harald Welte081b19a2018-02-10 09:11:13 +0100405 case (EST_TYPE_PAG_RESP) {
406 l3_info := valueof(ts_PAG_RESP(mi));
407 }
Harald Weltef45efeb2018-04-09 18:19:24 +0200408 case (EST_TYPE_MO_SMS) {
409 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi));
410 }
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700411 case (EST_TYPE_SS_ACT) {
412 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi));
413 }
Harald Welte081b19a2018-02-10 09:11:13 +0100414 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100415
416 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Weltedceacc72019-04-21 20:58:35 +0200417 f_cl3_or_initial_ue(l3_info);
Harald Weltea49e36e2018-01-21 19:29:33 +0100418
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200419 f_verify_vty_lac_ci(verify_vlr := false);
420
Harald Weltede371492018-01-27 23:44:41 +0100421 f_mm_common();
Pau Espin Pedrolf8034482019-06-03 13:15:58 +0200422 if (g_pars.net.expect_ciph or not g_pars.ran_is_geran) {
Harald Welte148a7082018-01-26 18:56:43 +0100423 /* implicit CM SERVICE ACCEPT? */
424 } else {
Harald Welte0bef21e2018-02-10 09:48:23 +0100425 if (etype != EST_TYPE_PAG_RESP) {
Harald Welte081b19a2018-02-10 09:11:13 +0100426 /* explicit CM SERVICE ACCEPT */
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200427 if (g_pars.net.expect_attach_success) {
428 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
429 } else {
430 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_REJ));
431 }
Harald Welte081b19a2018-02-10 09:11:13 +0100432 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100433 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100434}
435
436/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
Harald Welte9de84792018-01-28 01:06:35 +0100437function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100438{
439 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
440 return f_build_lu(mi);
441}
Harald Welte9de84792018-01-28 01:06:35 +0100442function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100443{
444 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
445 return f_build_lu(mi);
446}
Harald Welte9de84792018-01-28 01:06:35 +0100447function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100448{
449 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
450 return f_build_lu(mi);
451}
Harald Welte9de84792018-01-28 01:06:35 +0100452private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100453{
454 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
455 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 +0100456 old_lai, mi, g_pars.cm1));
Harald Weltea49e36e2018-01-21 19:29:33 +0100457 return l3_info;
458}
459
Harald Weltea183a5d2019-05-09 13:40:52 +0200460altstep as_GSUP_SAI() runs on BSC_ConnHdlr {
461var GSUP_IE auth_tuple;
462[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)) {
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200463 if (g_pars.net.hlr_has_auth_info) {
464 if (g_pars.use_umts_aka) {
465 if (not g_pars.vec_keep) {
466 g_pars.vec := f_gen_auth_vec_3g();
467 }
468 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand,
469 g_pars.vec.sres,
470 g_pars.vec.kc,
471 g_pars.vec.ik,
472 g_pars.vec.ck,
473 g_pars.vec.autn,
474 g_pars.vec.res));
475 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
476 } else {
477 if (not g_pars.vec_keep) {
478 g_pars.vec := f_gen_auth_vec_2g();
479 }
480 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand,
481 g_pars.vec.sres,
482 g_pars.vec.kc));
483 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +0200484 }
Harald Weltea183a5d2019-05-09 13:40:52 +0200485 } else {
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200486 log("XXX ts_GSUP_SAI_ERR");
487 /* HLR knows the IMSI but has no authentication info; osmo-hlr responds with GMM_CAUSE_IMSI_UNKNOWN=2 in
488 * this case, for SAI this merely means there is no auth entry for this IMSI. */
489 GSUP.send(ts_GSUP_SAI_ERR(g_pars.imsi, 2));
Harald Weltea183a5d2019-05-09 13:40:52 +0200490 }
491 }
492}
493
Harald Welte9de84792018-01-28 01:06:35 +0100494function f_mm_auth() runs on BSC_ConnHdlr
Harald Welte148a7082018-01-26 18:56:43 +0100495{
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200496 if (g_pars.net.expect_auth or g_pars.net.expect_auth_attempt) {
Harald Weltea183a5d2019-05-09 13:40:52 +0200497 as_GSUP_SAI();
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200498 }
499 if (g_pars.net.expect_auth) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200500 if (g_pars.use_umts_aka) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200501 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn)));
502 var OCT4 res := substr(g_pars.vec.res, 0, 4);
503 var OCT4 xres := substr(g_pars.vec.res, 4, 4);
504 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres)));
505 } else {
Harald Weltec1f937a2019-04-21 21:19:23 +0200506 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand)));
507 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres)));
508 }
Harald Welte148a7082018-01-26 18:56:43 +0100509 }
Harald Welte9de84792018-01-28 01:06:35 +0100510}
Harald Welte148a7082018-01-26 18:56:43 +0100511
Oliver Smith1d118ff2019-07-03 10:57:35 +0200512function f_mm_imei() runs on BSC_ConnHdlr
513{
514 var PDU_DTAP_MT dtap_mt;
515 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700516 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200517
518 if (not g_pars.net.expect_imei) {
519 return
520 }
521
522 /* MSC <-> BSC: ID req/rsp for IMEI */
523 alt {
524 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEI))) {
525 mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
526 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
527 }
528 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
529 setverdict(fail, "Expected ID REQ for IMEI DTAP MT message, but got: ", dtap_mt);
530 mtc.stop;
531 }
532 }
533
534 /* MSC <-> HLR: Check IMEI req/res/err */
535 alt {
536 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
537 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
538 }
539 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
540 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
541 }
542 [] GSUP.receive(?) -> value gsup_msg {
543 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
544 g_pars.imsi, "), but got: ", gsup_msg);
545 mtc.stop;
546 }
547 }
548}
549
550function f_mm_imei_early() runs on BSC_ConnHdlr
551{
552 var PDU_DTAP_MT dtap_mt;
553 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700554 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200555
556 if (not g_pars.net.expect_imei_early) {
557 return
558 }
559
560 /* MSC <-> BSC: ID req/rsp for IMEISV */
561 alt {
562 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEISV))) {
563 mi := valueof(ts_MI_IMEISV_LV(g_pars.imei));
564 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
565 }
566 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
567 setverdict(fail, "Expected ID REQ for IMEISV DTAP MT message, but got: ", dtap_mt);
568 mtc.stop;
569 }
570 }
571
572 /* MSC <-> HLR: Check IMEI req/res/err */
573 alt {
574 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
575 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
576 }
577 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
578 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
579 }
580 [] GSUP.receive(?) -> value gsup_msg {
581 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
582 g_pars.imsi, "), but got: ", gsup_msg);
583 mtc.stop;
584 }
585 }
586}
587
Harald Welte79f1e452020-08-18 22:55:02 +0200588function f_expect_common_id() runs on BSC_ConnHdlr
589{
590 if (g_pars.ran_is_geran) {
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200591 BSSAP.receive(tr_BSSMAP_CommonId(g_pars.imsi,
592 f_tr_BSSMAP_LastUsedEUTRANPLMNId(g_pars.common_id_last_eutran_plmn)));
Harald Welte79f1e452020-08-18 22:55:02 +0200593 } else {
594 BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
595 }
596}
597
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200598/* For UMTS AKA on GERAN, calculate the specific kc from the UMTS AKA ck and ik vectors. */
599function f_auth3g_kc(AuthVector vec) return OCT8 {
Eric Wild26f4a622021-05-17 15:27:05 +0200600 var integer i;
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200601 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 +0200602 for (i := 1; i < 8; i := i + 1) {
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200603 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 +0200604 res := res & a;
605 }
606
607 return res;
608}
609
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200610function f_get_expected_encryption(
611 out template BSSMAP_IE_EncryptionInformation encryptionInformation,
612 out template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm,
613 out template BSSMAP_IE_KC128 kC128,
614 out OCT1 a5_perm_alg) runs on BSC_ConnHdlr
615{
616 var OCT1 a5_ms := f_alg_mask_from_cm(g_pars.cm2, g_pars.cm3);
617 a5_perm_alg := g_pars.net.kc_support and4b a5_ms;
618
619 if (not g_pars.net.expect_ciph) {
620 encryptionInformation := *;
621 chosenEncryptionAlgorithm := *;
622 kC128 := *;
623 return;
624 }
625
Neels Hofmeyrf6eff812021-06-23 23:29:39 +0200626 var OCT8 kc;
627 if (g_pars.use_umts_aka) {
628 kc := f_auth3g_kc(g_pars.vec);
629 } else {
630 kc := g_pars.vec.kc;
631 }
632 encryptionInformation := tr_BSSMAP_IE_EncrInfo(kc, a5_perm_alg);
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200633
634 var OCT1 chosen_alg := int2oct(f_alg_from_mask(f_best_alg_from_mask(a5_perm_alg)) + 1, 1);
635 chosenEncryptionAlgorithm := tr_BSSMAP_IE_ChosenEncryptionAlgorithm(chosen_alg);
636
637 if (g_pars.use_umts_aka and f_alg_supported_by_mask(a5_perm_alg, 4)) {
638 /* A5/4 is permitted, expecting kc128 to be present */
639 var OCT32 full_sha256 := f_calculate_HMAC_SHA256(g_pars.vec.ck & g_pars.vec.ik, '32'O, 32);
640 var OCT16 expect_kc128 := substr(full_sha256, 0, 16);
641 kC128 := tr_BSSMAP_IE_Kc128(expect_kc128);
642 } else {
643 kC128 := omit
644 }
645}
646
Eric Wild26f4a622021-05-17 15:27:05 +0200647
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300648private function f_mm_ciph_geran() runs on BSC_ConnHdlr
649{
650 var template BSSMAP_IE_EncryptionInformation encryptionInformation;
651 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm;
652 var template BSSMAP_IE_KC128 kC128;
653 var OCT1 a5_perm_alg;
654 var PDU_BSSAP pdu;
655
Vadim Yanitskiy172bc6e2021-12-06 17:54:57 +0300656 if (not g_pars.net.expect_ciph) {
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300657 /* There is nothing to do */
658 return;
659 }
660
661 f_get_expected_encryption(encryptionInformation, chosenEncryptionAlgorithm, kC128, a5_perm_alg);
662 alt {
663 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128)) -> value pdu {
664 var OCT1 a5_chosen := f_best_alg_from_mask(a5_perm_alg);
665 var integer a5_nr := f_alg_from_mask(a5_chosen);
666 BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
667 }
668 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2) -> value pdu {
669 log("Error: Ciphering Mode Command with unexpected content. Expected: ",
670 tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128), " got: ", pdu);
671 setverdict(fail, "Ciphering Mode Command with unexpected content.");
672 mtc.stop;
673 }
674 [] BSSAP.receive(tr_BSSMAP_ClassmarkRequest) {
675 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3))
676 repeat;
677 }
678 }
679 /* FIXME: Send the best available algorithm */
680}
681
682private function f_mm_ciph_utran() runs on BSC_ConnHdlr
683{
684 alt {
685 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
686 uia_key := oct2bit(g_pars.vec.ik),
687 key_sts := ?,
688 uea_algs := ?,
689 uea_key := oct2bit(g_pars.vec.ck))) {
690 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/
691 var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/
692 BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen));
693 }
694 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
695 setverdict(fail, "Invalid SecurityModeCommand (ciphering case)");
696 mtc.stop;
697 }
698 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
699 uia_key := oct2bit(g_pars.vec.ik),
700 key_sts := ?)) {
701 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/
702 BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
703 }
704 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
705 setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)");
706 mtc.stop;
707 }
708 }
709}
710
Harald Welte9de84792018-01-28 01:06:35 +0100711function f_mm_common() runs on BSC_ConnHdlr
712{
713 f_mm_auth();
Eric Wild26f4a622021-05-17 15:27:05 +0200714
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300715 if (g_pars.ran_is_geran) {
716 f_mm_ciph_geran();
717 } else {
718 f_mm_ciph_utran();
Harald Welte148a7082018-01-26 18:56:43 +0100719 }
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300720
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200721 if (not g_pars.net.expect_attach_success) {
722 return;
723 }
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300724 f_expect_common_id();
Harald Welte148a7082018-01-26 18:56:43 +0100725}
726
Philipp Maier9b690e42018-12-21 11:50:03 +0100727function f_expect_mm_info() runs on BSC_ConnHdlr {
728 if (g_pars.mm_info == true) {
729 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info));
730 }
731}
732
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200733private function f_lac_ci_vty_str(BSSMAP_IE_CellIdentifier cell_id) return charstring
734{
735 return "LAC / cell ID: "
736 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.lac)) & " / "
737 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.ci));
738}
739
740/* Get an IMSI's info and verify that the g_pars.cell_id is reflected in the info.
741 * Verify both the "LAC / cell ID" in the VLR and the "LAC / cell ID" in the "Connection:" part, if any.
742 * If verify_vlr == false, then only verify the "Connection:" part, and fail if there is no "Connection:"; this is
743 * useful when a conn has been established, but the subscriber has not been authenticated, so the VLR does not yet
744 * reflect the new conn's cell ID.
745 */
746function f_verify_vty_lac_ci(boolean verify_vlr := true) runs on BSC_ConnHdlr {
747 if (not g_pars.ran_is_geran) {
748 log("Skipping f_verify_vty_lac_ci(), disabled for Iu");
749 setverdict(pass);
750 return;
751 }
752 if (not g_pars.verify_cell_id) {
753 /* Skip this verification; either the TC expects no cell id to end up being accepted, or this was
754 * disabled globally to test an older osmo-msc which doesn't store the cell id properly yet. */
755 log("Skipping f_verify_vty_lac_ci()");
756 setverdict(pass);
757 return;
758 }
759
760 var charstring vty_cmd := "show subscriber imsi " & hex2str(g_pars.imsi) & " conn";
761 var charstring result := f_vty_transceive_ret(MSCVTY, vty_cmd);
762 var charstring expect_lac_ci := "LAC / cell ID: "
763 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.lac)) & " / "
764 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.ci));
765
766 var boolean vlr_matches := false;
767 var boolean connection_present := false;
768 var boolean connection_matches := false;
769
770 /* There are two occurences of LAC / cell ID: once for the VLR record, and once for the active connection. The
771 * active connection part starts with 'Connection:'. If there is no active connection, that part is omitted.
772 * So, first find out whether there is a 'Connection:' part. Then verify the LAC / cell ID above 'Connection:'
773 * and below 'Connection:', separately.
774 */
775 var integer connection_start := f_strstr(result, "Connection:");
776 connection_present := (connection_start >= 0);
777
778 var integer lac_ci_match := f_strstr(result, expect_lac_ci);
779 if (connection_present) {
780 if (lac_ci_match > connection_start) {
781 /* The first match is below 'Connection:', so the VLR part above it did not match. */
782 vlr_matches := false;
783 connection_matches := true;
784 } else if (lac_ci_match >= 0) {
785 /* The first match is above 'Connection:', so the VLR part matches. */
786 vlr_matches := true;
787
788 /* Now find a match below 'Connection:' */
789 lac_ci_match := f_strstr(result, expect_lac_ci, connection_start);
790 connection_matches := (lac_ci_match > 0);
791 }
792 } else {
793 /* There is no 'Connection:', so a match, if any, is from the VLR part. */
794 vlr_matches := (lac_ci_match >= 0);
795 }
796
797 if (verify_vlr) {
798 if (not vlr_matches) {
799 setverdict(fail, vty_cmd, " shows mismatching LAC / cell ID in the VLR part, expecting: ",
800 expect_lac_ci, " -- got: ", result);
801 return;
802 } else {
803 log("f_verify_vty_lac_ci(): VLR record matches ", expect_lac_ci);
804 setverdict(pass);
805 }
806 }
807
808 if (connection_present) {
809 if (not connection_matches) {
810 setverdict(fail, vty_cmd, " shows mismatching LAC cell ID in the 'Connection' part, expecting: ",
811 expect_lac_ci, " -- got: ", result);
812 } else {
813 log("f_verify_vty_lac_ci(): Active connection matches ", expect_lac_ci);
814 setverdict(pass);
815 }
816 }
817
818 if (not verify_vlr and not connection_present) {
819 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);
820 }
821}
822
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100823function f_perform_lu()
Harald Weltea49e36e2018-01-21 19:29:33 +0100824runs on BSC_ConnHdlr {
825 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
826 var PDU_DTAP_MT dtap_mt;
827
828 /* tell GSUP dispatcher to send this IMSI to us */
829 f_create_gsup_expect(hex2str(g_pars.imsi));
830
831 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Welte9b751a62019-04-14 17:39:29 +0200832 if (g_pars.ran_is_geran) {
833 f_bssap_compl_l3(l3_lu);
834 if (g_pars.send_early_cm) {
835 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
836 }
837 } else {
838 f_ranap_initial_ue(l3_lu);
Harald Welte8a121b32018-01-22 03:00:41 +0100839 }
Harald Welte5c2622c2018-01-21 20:45:20 +0100840
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200841 /* at this point the conn has been established, but the subscriber has not been authenticated, so the VLR does
842 * not yet reflect this conn's cell ID. */
843 f_verify_vty_lac_ci(verify_vlr := false);
844
Oliver Smith1d118ff2019-07-03 10:57:35 +0200845 f_mm_imei_early();
Harald Weltede371492018-01-27 23:44:41 +0100846 f_mm_common();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100847 f_msc_lu_hlr();
Oliver Smith1d118ff2019-07-03 10:57:35 +0200848 f_mm_imei();
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200849 as_accept_reject_lu(g_pars.net.expect_attach_success);
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100850 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200851 f_expect_clear(verify_vlr_cell_id := g_pars.net.expect_attach_success);
Harald Welte16114282018-01-24 22:41:21 +0100852
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100853 setverdict(pass);
854}
855
856function f_msc_lu_hlr() runs on BSC_ConnHdlr
857{
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200858 if (not g_pars.net.expect_attach_success) {
859 return;
860 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100861 /* Expect MSC to perform LU with HLR */
862 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
863 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
864 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
865 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100866}
867
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200868altstep as_accept_reject_lu(boolean expect_accept := true) runs on BSC_ConnHdlr {
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100869 var PDU_DTAP_MT dtap_mt;
Harald Weltea49e36e2018-01-21 19:29:33 +0100870
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200871 [expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
Harald Weltea49e36e2018-01-21 19:29:33 +0100872 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
Harald Weltede371492018-01-27 23:44:41 +0100873 if (g_pars.net.expect_tmsi) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100874 if (not ispresent(lu_acc.mobileIdentityTLV) or
875 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
876 setverdict(fail, "Expected TMSI but no TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200877 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100878 } else {
Harald Welte256571e2018-01-24 18:47:19 +0100879 g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets;
Harald Weltea49e36e2018-01-21 19:29:33 +0100880 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
881 }
882 } else {
883 if (ispresent(lu_acc.mobileIdentityTLV) and
884 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
885 setverdict(fail, "Expected no TMSI but TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200886 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100887 }
888 }
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200889
890 /* Wait for MM-Information (if enabled) */
891 f_expect_mm_info();
892 setverdict(pass);
893 }
894 [expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100895 setverdict(fail, "Expected LU ACK, but received LU REJ");
Daniel Willmannafce8662018-07-06 23:11:32 +0200896 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100897 }
Philipp Maier9b690e42018-12-21 11:50:03 +0100898
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200899 [not expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
900 setverdict(pass);
901 }
902 [not expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
903 setverdict(fail, "Expected LU REJ, but received LU ACK");
904 mtc.stop;
905 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100906}
907
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100908function f_expect_lu_reject(template OCT1 cause := ?) runs on BSC_ConnHdlr {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200909 var PDU_DTAP_MT dtap_mt;
910 timer T := 5.0;
911
912 T.start;
913 alt {
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100914 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej(cause))) {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200915 setverdict(pass);
916 }
917 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
918 setverdict(fail, "Expected LU reject BSSAP message, got: ", dtap_mt);
919 }
920 [] T.timeout {
921 setverdict(fail, "Timeout waiting for LU reject");
922 }
923 }
924}
925
Harald Weltea49e36e2018-01-21 19:29:33 +0100926function f_foo() runs on BSC_ConnHdlr{
Harald Welte6811d102019-04-14 22:23:14 +0200927 /* SCCP CC handled by RAN_Emulation_CT.main() */
Harald Weltea49e36e2018-01-21 19:29:33 +0100928 /* Expect auth, if enabled */
929
930 /* TODO: ISD */
931 /* Expect encr, if enabled */
932 /* Expect encr, if enabled */
933 /* Expect ASS CMD, if chan_type != requested */
934 /* Send ASS CMPL in successful case */
935
936 /* Expect AoIP port/ip information for RTP stream */
937 /* Expect MSC-originated MGCP to our simulated MGW */
938 /* Verify Counters via CTRL */
939 /* re-configure MSC behaviour via VTY */
940}
941
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200942type record CrcxResponse {
943 integer resp, /* 1 = reply with OK, 0 = do not reply, -1 = reply with error */
944 HostName mgw_rtp_ip,
945 PortNumber mgw_rtp_port,
946 MgcpConnectionId mgcp_connection_id /* MGCP Connection ID BSS Side */
947}
948
Harald Welteb71901a2018-01-26 19:16:05 +0100949/* parameters related to a (MO?) voice call */
950type record CallParameters {
Harald Welteb71901a2018-01-26 19:16:05 +0100951 /* CC related parameters */
952 hexstring called_party, /* whom are we calling */
953 integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100954 boolean mo_call, /* For a MO call, the transaction_id was allocated by the MS,
955 important to set the TI flag properly */
Harald Welteb71901a2018-01-26 19:16:05 +0100956 BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */
Harald Welte0bef21e2018-02-10 09:48:23 +0100957 boolean emergency, /* is this an emergency call? */
Oliver Smith92b280c2023-04-20 13:13:23 +0200958 boolean csd, /* is this a circuit switched data call? */
Harald Welteb71901a2018-01-26 19:16:05 +0100959
960 /* MNCC related parameters */
961 uint32_t mncc_callref optional, /* call reference on the MNCC side */
962 MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200963 HostName mncc_rtp_ip optional, /* MNCC Side RTP IP */
964 PortNumber mncc_rtp_port optional, /* MNCC Side RTP port */
Harald Welteb71901a2018-01-26 19:16:05 +0100965
966 /* RTP related parameters */
967 HostName bss_rtp_ip optional, /* BSS Side RTP IP */
968 PortNumber bss_rtp_port optional, /* BSS Side RTP Port */
969 HostName mss_rtp_ip optional, /* MSS Side RTP IP */
970 PortNumber mss_rtp_port optional, /* MSS Side RTP Port */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200971 integer got_crcx_count,
972 CrcxResponse mgw_conn_1,
973 CrcxResponse mgw_conn_2,
Harald Welteb71901a2018-01-26 19:16:05 +0100974 uint7_t rtp_payload_type, /* dynamic RTP payload type */
975 charstring rtp_sdp_format, /* AMR/8000 or the like */
Philipp Maier2a98a732018-03-19 16:06:12 +0100976 boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX
977 (f_mt_call and f_mt_call) */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200978 boolean stop_after_cc_setup, /* Special case: stop call establish after CC Setup */
979 boolean ran_clear_when_alerting, /* Special case: send Clear upon CC Alerting */
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100980 boolean expect_release, /* Special case: expect call establish to cause direct CC Rel */
Harald Welteb71901a2018-01-26 19:16:05 +0100981
Philipp Maiercd668572018-03-19 16:11:52 +0100982 MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */
Harald Welteb71901a2018-01-26 19:16:05 +0100983 MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200984
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200985 boolean use_osmux, /* MSC is expected to use Osmux for this call */
986 integer got_osmux_count
Harald Welteb71901a2018-01-26 19:16:05 +0100987}
988
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200989template (value) CallParameters t_CallParams(hexstring called := '12345'H, integer tid := 0) := {
Harald Welteb71901a2018-01-26 19:16:05 +0100990 called_party := called,
991 transaction_id := tid,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100992 mo_call := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100993 bearer_cap := valueof(ts_Bcap_voice),
Harald Welte0bef21e2018-02-10 09:48:23 +0100994 emergency := false,
Oliver Smithf89620d2023-06-21 18:21:25 +0200995 csd := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100996 mncc_callref := omit,
997 mncc_bearer_cap := valueof(ts_MNCC_bcap_voice),
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200998 mncc_rtp_ip := "42.23.11.5",
999 mncc_rtp_port := 423,
Harald Welte4017d552018-01-26 21:40:05 +01001000 bss_rtp_ip := "9.8.7.6",
1001 bss_rtp_port := 9000,
Harald Welteb71901a2018-01-26 19:16:05 +01001002 mss_rtp_ip := omit,
1003 mss_rtp_port := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001004 got_crcx_count := 0,
1005 mgw_conn_1 := {
1006 resp := 1,
1007 mgw_rtp_ip := "1.1.1.1",
1008 mgw_rtp_port := 10000,
1009 mgcp_connection_id := '11111'H
1010 },
1011 mgw_conn_2 := {
1012 resp := 1,
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001013 mgw_rtp_ip := "2.2.2.2",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001014 mgw_rtp_port := 11000,
1015 mgcp_connection_id := '22222'H
1016 },
Harald Welteb71901a2018-01-26 19:16:05 +01001017 rtp_payload_type := 98,
1018 rtp_sdp_format := "AMR/8000",
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001019 mgw_drop_dlcx := false,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001020 stop_after_cc_setup := false,
1021 ran_clear_when_alerting := false,
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001022 expect_release := false,
Harald Welteb71901a2018-01-26 19:16:05 +01001023 mgcp_call_id := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001024 mgcp_ep := "rtpbridge/1@mgw",
1025 use_osmux := false,
1026 got_osmux_count := 0
Harald Welteb71901a2018-01-26 19:16:05 +01001027};
1028
Neels Hofmeyrf797d292021-07-27 22:33:09 +02001029template CallParameters tr_CallParams := {
1030 called_party := ?,
1031 transaction_id := ?,
1032 mo_call := ?,
1033 bearer_cap := ?,
1034 emergency := ?,
Oliver Smithf89620d2023-06-21 18:21:25 +02001035 csd := ?,
Neels Hofmeyrf797d292021-07-27 22:33:09 +02001036 mncc_callref := *,
1037 mncc_bearer_cap := ?,
1038 mncc_rtp_ip := ?,
1039 mncc_rtp_port := ?,
1040 bss_rtp_ip := ?,
1041 bss_rtp_port := ?,
1042 mss_rtp_ip := *,
1043 mss_rtp_port := *,
1044 got_crcx_count := ?,
1045 mgw_conn_1 := ?,
1046 mgw_conn_2 := ?,
1047 rtp_payload_type := ?,
1048 rtp_sdp_format := ?,
1049 mgw_drop_dlcx := ?,
1050 stop_after_cc_setup := ?,
1051 ran_clear_when_alerting := ?,
1052 expect_release := ?,
1053 mgcp_call_id := *,
1054 mgcp_ep := ?,
1055 use_osmux := ?,
1056 got_osmux_count := ?
1057};
1058
Harald Welte4263c522018-12-06 11:56:27 +01001059/* Allocate a call reference and send SETUP via MNCC to MSC */
Oliver Smith97dc91f2023-05-31 13:53:21 +02001060function f_mt_call_initiate(inout CallParameters cpars)
Harald Welte33ec09b2018-02-10 15:34:46 +01001061runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001062 cpars.mo_call := false;
Harald Welte4263c522018-12-06 11:56:27 +01001063 cpars.mncc_callref := f_rnd_int(2147483648);
Oliver Smithc1dd36a2023-05-31 13:52:24 +02001064
Harald Welte4263c522018-12-06 11:56:27 +01001065 MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
Oliver Smith8cf75ab2023-06-21 16:19:51 +02001066 hex2str(cpars.called_party), hex2str(g_pars.imsi),
1067 cpars.mncc_bearer_cap));
Harald Welte4263c522018-12-06 11:56:27 +01001068}
Harald Welte33ec09b2018-02-10 15:34:46 +01001069
Harald Welte408a7ef2019-04-21 17:08:40 +02001070private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) :=
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001071 ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
Harald Welte408a7ef2019-04-21 17:08:40 +02001072 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001073 cpars.mgw_conn_2.mgw_rtp_port,
Harald Welte408a7ef2019-04-21 17:08:40 +02001074 { int2str(cpars.rtp_payload_type) },
1075 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1076 cpars.rtp_sdp_format)),
1077 valueof(ts_SDP_ptime(20)) });
1078
Harald Welte4263c522018-12-06 11:56:27 +01001079/* Complete call, begin with a paging response message via BSSAP */
1080function f_mt_call_complete(inout CallParameters cpars)
1081runs on BSC_ConnHdlr {
Harald Welte33ec09b2018-02-10 15:34:46 +01001082 var MNCC_PDU mncc;
1083 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001084 var template MgcpResponse mgcp_resp;
1085 var MgcpOsmuxCID osmux_cid;
1086 var PDU_BSSAP bssap;
Harald Welte33ec09b2018-02-10 15:34:46 +01001087
Harald Welte6811d102019-04-14 22:23:14 +02001088 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Welte33ec09b2018-02-10 15:34:46 +01001089
Harald Welteb9e86fa2018-04-09 18:18:31 +02001090 f_establish_fully(EST_TYPE_PAG_RESP);
Harald Welte33ec09b2018-02-10 15:34:46 +01001091
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001092 log("f_mt_call_complete 1");
1093
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001094 cpars.got_osmux_count := 0;
1095
Harald Welte33ec09b2018-02-10 15:34:46 +01001096 /* MS <- MSC: Expect CC SETUP */
1097 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party)));
1098
1099 /* MS -> MSC: ALERTING */
1100 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id)));
1101 MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001102 log("f_mt_call_complete 2");
Harald Welte33ec09b2018-02-10 15:34:46 +01001103
Harald Welte33ec09b2018-02-10 15:34:46 +01001104 /* Create MGCP expect */
1105 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1106 /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */
1107 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1108
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001109 /* First MGCP CRCX */
Harald Welte33ec09b2018-02-10 15:34:46 +01001110 MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001111 log("f_mt_call_complete 3");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001112 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1113 return;
Philipp Maier4b2692d2018-03-14 16:37:48 +01001114 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001115 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001116
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001117
Harald Welte9b751a62019-04-14 17:39:29 +02001118 if (g_pars.ran_is_geran) {
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001119 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass1 :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001120 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001121 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass2 :=
1122 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_2.mgw_rtp_ip, ?);
Harald Welte9b751a62019-04-14 17:39:29 +02001123
1124 interleave {
1125 /* Second MGCP CRCX (this time for MSS/CN side) */
1126 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001127 log("f_mt_call_complete 4");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001128 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1129 break;
1130 }
Harald Welte9b751a62019-04-14 17:39:29 +02001131 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001132
1133 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1134 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1135 log("f_mt_call_complete 5");
1136 }
1137
Harald Welte9b751a62019-04-14 17:39:29 +02001138 /* expect the MSC to trigger a BSSMAP ASSIGNMENT */
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001139 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, (tla_ass1, tla_ass2))) -> value bssap {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001140 var template BSSMAP_IE_AoIP_TransportLayerAddress tla;
Harald Welte9b751a62019-04-14 17:39:29 +02001141 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001142 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001143 log("f_mt_call_complete 6");
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001144 tla := f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port);
Harald Welte9b751a62019-04-14 17:39:29 +02001145 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
1146
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001147 if (cpars.use_osmux) {
1148 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1149 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1150 mtc.stop;
1151 }
1152 osmuxCID := valueof(ts_OsmuxCID(0));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001153 if (not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1154 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 +02001155 mtc.stop;
1156 }
1157 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1158 } else {
1159 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1160 }
1161 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001162
1163 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
Harald Welte9b751a62019-04-14 17:39:29 +02001164 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001165
1166 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1167 log("f_mt_call_complete 7");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001168 var octetstring ip;
1169 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1170 if (is_ipv6) {
1171 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1172 } else {
1173 ip := f_inet_addr(cpars.mncc_rtp_ip);
1174 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001175 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001176 is_ipv6, ip,
1177 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001178 /* payload type 3 = GSM FR */ 3));
1179 }
1180
1181 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1182 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1183 log("f_mt_call_complete 8");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001184 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 +01001185 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001186 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001187 { int2str(cpars.rtp_payload_type) },
1188 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1189 cpars.rtp_sdp_format)),
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001190 valueof(ts_SDP_ptime(20)) }));
1191 if (cpars.use_osmux) {
1192 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1193 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1194 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1195 mtc.stop;
1196 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001197 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 +02001198 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001199 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 +02001200 }
1201 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001202 }
1203
1204 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1205 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001206 var SDP_Message sdp;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001207 log("f_mt_call_complete 9");
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001208
1209 if (isvalue(mgcp_cmd.sdp)) {
1210 sdp := mgcp_cmd.sdp;
1211 if (sdp.media_list[0].media_field.ports.port_number != cpars.mncc_rtp_port) {
1212 setverdict(fail, "Wrong MDCX Connection port received, expected ", cpars.mncc_rtp_port, " and received ", sdp.media_list[0].media_field.ports.port_number)
1213 mtc.stop;
1214 }
1215 if (sdp.connection.conn_addr.addr != cpars.mncc_rtp_ip) {
1216 setverdict(fail, "Wrong MDCX Connection address received, expected ", cpars.mncc_rtp_ip, " and received ", sdp.connection.conn_addr.addr)
1217 mtc.stop;
1218 }
1219 }
1220
1221 sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1222 hex2str(cpars.mgcp_call_id), "42",
1223 cpars.mgw_conn_2.mgw_rtp_port,
1224 { int2str(cpars.rtp_payload_type) },
1225 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1226 cpars.rtp_sdp_format)),
1227 valueof(ts_SDP_ptime(20)) }));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001228 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 +01001229 }
1230
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001231 }
Harald Welte9b751a62019-04-14 17:39:29 +02001232 } else {
Harald Welte9b751a62019-04-14 17:39:29 +02001233 interleave {
1234 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001235 log("f_mt_call_complete 4.iu");
1236 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1237 break;
Harald Welte9b751a62019-04-14 17:39:29 +02001238 }
Harald Welte9b751a62019-04-14 17:39:29 +02001239 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001240
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001241 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1242 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1243 log("f_mt_call_complete 5.iu");
1244 }
1245
1246 [] BSSAP.receive(tr_RANAP_RabAssReq(?)) {
1247 log("f_mt_call_complete 6.iu");
1248 var RAB_SetupOrModifiedList l := {
1249 {
1250 {
1251 id := id_RAB_SetupOrModifiedItem,
1252 criticality := ignore,
1253 value_ := {
1254 rAB_SetupOrModifiedItem := {
1255 rAB_ID := int2bit(23, 8),
1256 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1257 iuTransportAssociation := {
1258 bindingID := '040c0000'O
1259 },
1260 dl_dataVolumes := omit,
1261 iE_Extensions := omit
1262 }
1263 }
1264 }
1265 }
1266 };
1267 BSSAP.send(ts_RANAP_RabAssResp(l));
1268
1269 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
1270 }
1271
1272 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1273 log("f_mt_call_complete 7.iu");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001274 var octetstring ip;
1275 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1276 if (is_ipv6) {
1277 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1278 } else {
1279 ip := f_inet_addr(cpars.mncc_rtp_ip);
1280 }
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001281 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001282 is_ipv6, ip,
1283 cpars.mncc_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001284 /* payload type 3 = GSM FR */ 3));
1285 }
1286
1287 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1288 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1289 log("f_mt_call_complete 8.iu");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001290 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 +01001291 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001292 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001293 { int2str(cpars.rtp_payload_type) },
1294 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1295 cpars.rtp_sdp_format)),
1296 valueof(ts_SDP_ptime(20)) }));
1297 if (cpars.use_osmux) {
1298 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1299 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1300 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1301 mtc.stop;
1302 }
1303 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
1304 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001305 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 +01001306 }
1307 MGCP.send(mgcp_resp);
1308 }
1309
1310 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1311 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1312 log("f_mt_call_complete 9.iu");
1313 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1314 hex2str(cpars.mgcp_call_id), "42",
1315 cpars.mgw_conn_2.mgw_rtp_port,
1316 { int2str(cpars.rtp_payload_type) },
1317 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1318 cpars.rtp_sdp_format)),
1319 valueof(ts_SDP_ptime(20)) }));
1320 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
1321 }
1322
Harald Welte33ec09b2018-02-10 15:34:46 +01001323 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001324 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001325
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001326 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1327 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1328 } else {
1329 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1330 mtc.stop;
1331 }
1332
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001333 log("f_mt_call_complete DONE");
Harald Welte4263c522018-12-06 11:56:27 +01001334}
1335
Harald Weltee035e3e2019-04-21 17:32:05 +02001336function f_expect_paging(boolean by_tmsi := true)
1337runs on BSC_ConnHdlr {
Harald Welte9b751a62019-04-14 17:39:29 +02001338 if (g_pars.ran_is_geran) {
1339 BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
1340 } else {
Harald Welte62113fc2019-05-09 13:04:02 +02001341 BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi)));
Harald Welte9b751a62019-04-14 17:39:29 +02001342 }
Harald Weltee035e3e2019-04-21 17:32:05 +02001343}
1344
Harald Welte4263c522018-12-06 11:56:27 +01001345function f_mt_call_establish(inout CallParameters cpars)
1346runs on BSC_ConnHdlr {
1347
1348 /* Initiate the call via MNCC */
Oliver Smith97dc91f2023-05-31 13:53:21 +02001349 f_mt_call_initiate(cpars);
Harald Welte4263c522018-12-06 11:56:27 +01001350
1351 /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
Harald Welte6811d102019-04-14 22:23:14 +02001352 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Weltee035e3e2019-04-21 17:32:05 +02001353 f_expect_paging()
Harald Welte4263c522018-12-06 11:56:27 +01001354
1355 /* Complete the call via BSSAP */
1356 f_mt_call_complete(cpars);
Harald Welte33ec09b2018-02-10 15:34:46 +01001357
Harald Welte33ec09b2018-02-10 15:34:46 +01001358 setverdict(pass);
1359}
1360
Neels Hofmeyrc47ce852023-03-06 17:16:50 +01001361function f_call_keep_open(inout CallParameters cpars, float open_time := 5.0)
1362runs on BSC_ConnHdlr {
1363 log("Hold the call for some time");
1364
1365 timer T := open_time;
1366 T.start;
1367 alt {
1368 [] MNCC.receive(tr_MNCC_DISC_ind(cpars.mncc_callref));
1369 [] MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
1370 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1371 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
1372 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1373 [] BSSAP.receive(tr_BSSMAP_ClearCommand);
1374 [] BSSAP.receive(tr_BSSMAP_ClearCommandCSFB);
1375 [] BSSAP.receive(tr_RANAP_IuReleaseCommand(?));
1376
1377 [] T.timeout {
1378 log("Call stayed open for ", open_time, " seconds, all is well.")
1379 setverdict(pass);
1380 return;
1381 }
1382 }
1383
1384 setverdict(fail, "An unexpected release event disconnected the active call prematurely");
1385 mtc.stop;
1386}
1387
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001388/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1389 * Return true when an OK reply was sent, false otherwise.
1390 * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */
1391function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd)
1392runs on BSC_ConnHdlr
1393return boolean {
1394 var CrcxResponse conn := cpars.mgw_conn_1;
1395 if (cpars.got_crcx_count > 0) {
1396 conn := cpars.mgw_conn_2;
1397 }
1398 cpars.got_crcx_count := cpars.got_crcx_count + 1;
1399
1400 var MgcpMessage mgcp_msg := {
1401 command := mgcp_cmd
1402 }
1403 var template MgcpResponse mgcp_resp;
1404 var MgcpOsmuxCID osmux_cid;
1405 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1406 if (ispresent(cpars.mgcp_call_id)) {
1407 if (cpars.mgcp_call_id != call_id) {
1408 setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id);
1409 mtc.stop;
1410 }
1411 } else {
1412 cpars.mgcp_call_id := call_id;
1413 }
1414
1415 /* When the endpoint contains a wildcard we keep the endpoint
1416 * identifier we have set up in cpars. Otherwise we use the
1417 * endpoint name that the call agent has supplied */
1418 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1419 cpars.mgcp_ep := mgcp_cmd.line.ep;
1420 }
1421
1422 if (conn.resp == -1) {
1423 /* Reply with error */
1424 var MgcpResponse mgcp_rsp := {
1425 line := {
1426 code := "542",
1427 trans_id := mgcp_cmd.line.trans_id,
1428 string := "FORCED_FAIL"
1429 },
1430 sdp := omit
1431
1432 }
1433 var MgcpParameter mgcp_rsp_param := {
1434 code := "Z",
1435 val := cpars.mgcp_ep
1436 };
1437 mgcp_rsp.params[0] := mgcp_rsp_param;
1438 MGCP.send(mgcp_rsp);
1439 return false;
1440 }
1441
1442 if (conn.resp == 0) {
1443 /* Do not reply at all */
1444 return false;
1445 }
1446
1447 if (conn.resp != 1) {
1448 setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1");
1449 mtc.stop;
1450 }
1451
1452 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1453 hex2str(cpars.mgcp_call_id), "42",
1454 conn.mgw_rtp_port,
1455 { int2str(cpars.rtp_payload_type) },
1456 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1457 cpars.rtp_sdp_format)),
1458 valueof(ts_SDP_ptime(20)) }));
1459
1460 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1461 if (not cpars.use_osmux) {
1462 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1463 mtc.stop;
1464 }
1465 cpars.got_osmux_count := cpars.got_osmux_count + 1;
1466 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1467 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1468 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1469 if (osmux_cid != -1) {
1470 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1471 mtc.stop;
1472 }
1473
1474 osmux_cid := 0;
1475 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1476 } else {
1477 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1478 }
1479
1480 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep));
1481 MGCP.send(mgcp_resp);
1482 return true;
1483}
1484
1485
1486altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr {
1487 var MgcpCommand mgcp_cmd;
1488 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1489 log("as_optional_mgcp_crcx: rx CRCX");
1490 f_handle_crcx(cpars, mgcp_cmd);
1491
1492 /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an
1493 * CRCX is handled. */
1494 repeat;
1495 }
1496}
1497
1498private altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr {
1499 var MgcpCommand mgcp_cmd;
1500 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1501 log("as_optional_mgcp_mdcx: rx MDCX");
1502 log(mgcp_cmd);
1503 var charstring conn_id;
1504 var charstring rtp_payload_type;
1505 f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id);
1506 rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0];
1507
1508 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip,
1509 mgcp_cmd.sdp.origin.session_id, "42",
1510 mgw_rtp_port,
1511 { rtp_payload_type },
1512 { valueof(ts_SDP_ptime(20)) }));
1513 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp));
1514
1515 /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is
1516 * handled. */
1517 repeat;
1518 }
1519}
1520
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001521private altstep as_optional_mgcp_dlcx(CallParameters cpars) runs on BSC_ConnHdlr {
1522 var MgcpCommand mgcp_cmd;
1523 var boolean respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1524 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1525 log("as_optional_mgcp_dlcx: rx MGCP DLCX");
1526 if (respond_to_dlcx) {
1527 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1528 }
1529 /* Without this 'repeat', currently active other interleave and alt series exit as soon as a
1530 * DLCX is handled. */
1531 repeat;
1532 }
1533}
1534
Philipp Maier3716a5e2018-03-21 15:53:35 +01001535function f_mo_call_establish(inout CallParameters cpars)
Harald Welteb71901a2018-01-26 19:16:05 +01001536runs on BSC_ConnHdlr {
1537
Harald Welteb71901a2018-01-26 19:16:05 +01001538 var MNCC_PDU mncc;
1539 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001540 var template MgcpResponse mgcp_resp;
Philipp Maier2a98a732018-03-19 16:06:12 +01001541 var boolean respond_to_dlcx;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001542 var PDU_BSSAP bssap;
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001543 var RANAP_PDU ranap;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001544 var MgcpOsmuxCID osmux_cid;
Harald Welteb71901a2018-01-26 19:16:05 +01001545
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001546 cpars.mo_call := true;
1547
Harald Welte0bef21e2018-02-10 09:48:23 +01001548 if (cpars.emergency) {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001549 f_establish_fully(EST_TYPE_EMERG_CALL);
Oliver Smith92b280c2023-04-20 13:13:23 +02001550 } else if (cpars.csd) {
1551 f_establish_fully(EST_TYPE_MO_CSD);
Harald Welte0bef21e2018-02-10 09:48:23 +01001552 } else {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001553 f_establish_fully(EST_TYPE_MO_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001554 }
Harald Welteb71901a2018-01-26 19:16:05 +01001555
1556 /* Create MNCC and MGCP expect */
1557 f_create_mncc_expect(hex2str(cpars.called_party));
1558 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1559
Harald Welte0bef21e2018-02-10 09:48:23 +01001560 if (cpars.emergency) {
1561 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id)));
1562 } else {
Oliver Smith9c417f22023-07-07 13:25:11 +02001563 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party,
1564 cpars.bearer_cap)));
Harald Welte0bef21e2018-02-10 09:48:23 +01001565 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001566
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001567 if (cpars.stop_after_cc_setup) {
1568 return;
1569 }
1570
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001571 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass1 :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001572 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001573 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass2 :=
1574 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_2.mgw_rtp_ip, ?);
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001575
1576 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 +01001577 var boolean got_mncc_setup_compl_ind := false;
1578 var boolean got_cc_connect := false;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001579
Harald Welteb71901a2018-01-26 19:16:05 +01001580 interleave {
1581 [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001582 log("f_mo_call_establish 1: rx MNCC SETUP ind");
Harald Welteb71901a2018-01-26 19:16:05 +01001583 cpars.mncc_callref := mncc.u.signal.callref;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001584 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1585 }
1586
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001587 /* First MGCP CRCX */
Harald Welteb71901a2018-01-26 19:16:05 +01001588 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001589 log("f_mo_call_establish 2: rx 1st CRCX");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001590 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1591 break;
1592 }
Philipp Maierf1e02bb2018-03-15 16:30:00 +01001593 }
1594
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001595 /* Second MGCP CRCX */
1596 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
1597 log("f_mo_call_establish 6: rx 2nd CRCX");
1598 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1599 break;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001600 }
Harald Welteb71901a2018-01-26 19:16:05 +01001601 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001602
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001603 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1604 log("f_mo_call_establish 3: rx RTP CREATE");
1605 /* Call Proceeding */
1606 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1607 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001608
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001609 /* Alerting */
1610 MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref));
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001611 }
Harald Welte9b751a62019-04-14 17:39:29 +02001612
Neels Hofmeyreccaa992019-10-15 16:42:21 +02001613 //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001614 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001615 log("f_mo_call_establish 4: rx Assignment Request");
1616 var BSSMAP_IE_AoIP_TransportLayerAddress tla;
1617 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001618 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
1619
Oliver Smithd6c90062023-05-08 15:20:20 +02001620 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer)) {
1621 setverdict(fail, "MSC sent Assignment Request without AoIP Transport Layer IE");
1622 mtc.stop;
1623 }
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001624 if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass1)
1625 and not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass2)) {
1626 log("Expected one of: 1:", tla_ass1, " 2:", tla_ass2);
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001627 log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer);
1628 setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE");
1629 mtc.stop;
1630 }
1631
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001632 tla := valueof(f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001633 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001634 if (cpars.use_osmux) {
1635 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1636 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1637 mtc.stop;
1638 }
1639 osmuxCID := valueof(ts_OsmuxCID(0));
1640 if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1641 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1642 mtc.stop;
1643 }
1644 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1645 } else {
1646 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1647 }
1648 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001649 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001650 [] BSSAP.receive(tr_RANAP_RabAssReq(*)) -> value ranap {
1651 log("f_mo_call_establish 4.iu: rx RANAP RAB Assignment Request");
1652 var RAB_SetupOrModifiedList l := {
1653 {
1654 {
1655 id := id_RAB_SetupOrModifiedItem,
1656 criticality := ignore,
1657 value_ := {
1658 rAB_SetupOrModifiedItem := {
1659 rAB_ID := int2bit(23, 8),
1660 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1661 iuTransportAssociation := {
1662 bindingID := '040c0000'O
1663 },
1664 dl_dataVolumes := omit,
1665 iE_Extensions := omit
1666 }
1667 }
1668 }
1669 }
1670 };
1671 BSSAP.send(ts_RANAP_RabAssResp(l));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001672 }
Harald Welte9b751a62019-04-14 17:39:29 +02001673
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001674 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1675 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1676 log("f_mo_call_establish 5: rx MDCX for the RAN side");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001677 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 +01001678 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001679 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001680 { int2str(cpars.rtp_payload_type) },
1681 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1682 cpars.rtp_sdp_format)),
1683 valueof(ts_SDP_ptime(20)) }));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001684
1685 if (cpars.use_osmux) {
1686 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1687 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1688 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1689 mtc.stop;
1690 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001691 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 +02001692 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001693 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 +02001694 }
1695 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001696 }
Harald Welte9b751a62019-04-14 17:39:29 +02001697
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001698 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {
1699 log("f_mo_call_establish 7: rx CC Alerting");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001700
1701 if (cpars.ran_clear_when_alerting) {
1702 if (g_pars.ran_is_geran) {
1703 BSSAP.send(ts_BSSMAP_ClearRequest(0));
1704 } else {
1705 BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention));
1706 }
1707 break;
1708 }
1709
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001710 cpars.mncc_callref := mncc.u.signal.callref;
1711 /* Call Proceeding */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001712 var octetstring ip;
1713 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1714 if (is_ipv6) {
1715 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1716 } else {
1717 ip := f_inet_addr(cpars.mncc_rtp_ip);
1718 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001719 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001720 is_ipv6, ip,
1721 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001722 /* payload type 3 = GSM FR */ 3));
1723 MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref));
1724 }
1725
1726 [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc {
1727 log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001728 got_mncc_setup_compl_ind := true;
1729 if (not cpars.expect_release and got_cc_connect) {
1730 break;
1731 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001732 }
1733
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001734 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) {
1735 log("f_mo_call_establish 10: rx CC CONNECT");
1736 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id)));
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001737 got_cc_connect := true;
1738 if (not cpars.expect_release and got_mncc_setup_compl_ind) {
1739 break;
1740 }
Harald Welteb71901a2018-01-26 19:16:05 +01001741 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001742
1743 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1744 log("f_mo_call_establish 11: rx CC RELEASE");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001745 if (not cpars.expect_release) {
1746 setverdict(fail, "Got unexpected CC Release");
1747 mtc.stop;
1748 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001749 f_expect_clear();
1750 break;
1751 }
1752 }
1753
1754 f_sleep(0.5);
1755 deactivate(mdcx);
1756
1757 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1758 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1759 } else {
1760 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1761 mtc.stop;
Harald Welteb71901a2018-01-26 19:16:05 +01001762 }
1763
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001764 log("f_mo_call_establish DONE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001765 setverdict(pass);
1766}
Harald Welteb71901a2018-01-26 19:16:05 +01001767
Harald Welte4c422b72019-02-17 16:27:10 +01001768function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001769runs on BSC_ConnHdlr {
1770
1771 var MobileIdentityLV mi;
1772 var MNCC_PDU mncc;
1773 var MgcpCommand mgcp_cmd;
1774 var boolean respond_to_dlcx;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001775 var boolean dlcx_contained_ci := false;
1776 var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand;
1777
1778 if (is_csfb) {
1779 t_clear := tr_BSSMAP_ClearCommandCSFB;
1780 }
1781
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001782 log("f_call_hangup 0: tx MNCC_DISC_REQ");
Harald Welteb71901a2018-01-26 19:16:05 +01001783 MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1784 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1785
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001786 log("f_call_hangup 1: rx DTAP CC DISC");
1787
Philipp Maier3716a5e2018-03-21 15:53:35 +01001788 if (release_by_ms) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001789 var BIT1 tid_remote := '1'B;
1790 if (cpars.mo_call) {
1791 tid_remote := '0'B;
1792 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001793 /* B-side (MS) Release of call */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001794 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 +01001795 MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001796 log("f_call_hangup 2: rx MNCC REL ind");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001797 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001798 log("f_call_hangup 3: rx DTAP CC REL COMPL");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001799 } else {
1800 /* A-side (PLMN) Release of call */
1801 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42))));
1802 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
Oliver Smith6f546a92023-07-10 15:03:31 +02001803 log("f_call_hangup 2.a: rx DTAP CC RELEASE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001804 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
Oliver Smith6f546a92023-07-10 15:03:31 +02001805 log("f_call_hangup 3.a: rx MNCC REL cnf");
1806 MNCC.receive(tr_MNCC_REL_cnf(cpars.mncc_callref, cause := *));
Philipp Maier3716a5e2018-03-21 15:53:35 +01001807 }
Harald Welteb71901a2018-01-26 19:16:05 +01001808
Philipp Maier2a98a732018-03-19 16:06:12 +01001809 respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1810
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001811 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 +01001812 var default dlcx := activate(as_optional_mgcp_dlcx(cpars));
Harald Welte9b751a62019-04-14 17:39:29 +02001813
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001814 /* clearing of radio channel */
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001815 alt {
1816 [g_pars.ran_is_geran] BSSAP.receive(t_clear) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001817 log("f_call_hangup 5: rx BSSAP Clear Command");
1818 BSSAP.send(ts_BSSMAP_ClearComplete);
1819 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1820 log("f_call_hangup 6: rx SCCP DISC");
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001821 setverdict(pass);
Philipp Maier2a98a732018-03-19 16:06:12 +01001822 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001823 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) {
1824 log("f_call_hangup 5.iu: rx Iu Release Command");
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001825 BSSAP.send(ts_RANAP_IuReleaseComplete);
1826 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001827 log("f_call_hangup 6.iu: rx SCCP DISC");
1828 setverdict(pass);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001829 }
1830 }
1831
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001832 f_sleep(1.0);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001833 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1834 log("f_call_hangup 9: done");
1835
1836 deactivate(mdcx);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001837 deactivate(dlcx);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001838}
1839
Oliver Smith98e24bc2023-07-07 12:36:59 +02001840function f_mt_call(inout CallParameters cpars, float open_time := 5.0)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001841runs on BSC_ConnHdlr {
1842
1843 f_mt_call_establish(cpars);
1844
Oliver Smith98e24bc2023-07-07 12:36:59 +02001845 f_call_keep_open(cpars, open_time);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001846
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001847 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001848 f_call_hangup(cpars, true);
1849
Oliver Smith3a33e552023-07-06 11:55:12 +02001850 /* Unregister the IMSI that was registered in f_mt_call_establish */
1851 f_ran_unregister_imsi(g_pars.imsi);
1852
Philipp Maier3716a5e2018-03-21 15:53:35 +01001853 setverdict(pass);
1854}
1855
Oliver Smith98e24bc2023-07-07 12:36:59 +02001856function f_mo_call(inout CallParameters cpars, float open_time := 5.0)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001857runs on BSC_ConnHdlr {
1858
1859 f_mo_call_establish(cpars);
1860
Oliver Smith98e24bc2023-07-07 12:36:59 +02001861 f_call_keep_open(cpars, open_time);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001862
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001863 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001864 f_call_hangup(cpars, false);
1865
Harald Welteb71901a2018-01-26 19:16:05 +01001866 setverdict(pass);
1867}
Harald Weltea49e36e2018-01-21 19:29:33 +01001868
Daniel Willmann8b084372018-02-04 13:35:26 +01001869function f_mo_seq_dtmf_dup(inout CallParameters cpars)
1870runs on BSC_ConnHdlr {
1871
1872 timer T := 1.0;
Daniel Willmann8b084372018-02-04 13:35:26 +01001873 var MNCC_PDU mncc;
1874 var MgcpCommand mgcp_cmd;
1875 var template PDU_ML3_MS_NW dtmf_dtap;
1876
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001877 f_mo_call_establish(cpars);
Daniel Willmann8b084372018-02-04 13:35:26 +01001878
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001879 /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by
1880 * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001881
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001882 /* Find out the next NSD that will be used, from RAN emulation. */
1883 var N_Sd_Array last_n_sd := f_bssmap_last_n_sd();
1884 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 +01001885
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001886 /* Compose DTAP with this correct NSD */
Daniel Willmann8b084372018-02-04 13:35:26 +01001887 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001888
1889 /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */
1890 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001891 T.start;
1892 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001893 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
1894 log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind");
1895 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001896 [] T.timeout {
1897 setverdict(fail, "Timeout waiting for START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001898 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001899 }
1900 }
1901
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001902 /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message
1903 * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */
1904 dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2);
Daniel Willmann92f66272018-02-06 15:50:52 +01001905 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true));
Daniel Willmann8b084372018-02-04 13:35:26 +01001906 T.start;
1907 alt {
1908 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001909 setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001910 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001911 }
1912 [] T.timeout { }
1913 }
1914
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001915 /* Here the NSD should be correct again and we see a DTMF. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001916 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001917 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001918 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001919 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) {
1920 log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind");
1921 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001922 [] T.timeout {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001923 setverdict(fail, "Timeout waiting for final START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001924 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001925 }
1926 }
1927
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001928 f_call_hangup(cpars, true);
Daniel Willmann8b084372018-02-04 13:35:26 +01001929 setverdict(pass);
1930}
Harald Welte9b751a62019-04-14 17:39:29 +02001931
Harald Welte1ddc7162018-01-27 14:25:46 +01001932/* expect a clear command */
Harald Welte5946b332018-03-18 23:32:21 +01001933altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr {
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001934 var PDU_BSSAP bssap;
Harald Welte5946b332018-03-18 23:32:21 +01001935 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1936 BSSAP.send(ts_BSSMAP_ClearComplete);
1937 alt {
Harald Welte6811d102019-04-14 22:23:14 +02001938 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte5946b332018-03-18 23:32:21 +01001939 setverdict(pass);
1940 }
1941 [] BSSAP.receive {
1942 setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001943 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001944 }
1945 }
1946 }
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001947 [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap {
1948 setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001949 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001950 }
1951}
1952
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001953function f_expect_clear(float t := 5.0, boolean verify_vlr_cell_id := true) runs on BSC_ConnHdlr {
Harald Welte1ddc7162018-01-27 14:25:46 +01001954 timer T := t;
1955
1956 T.start;
1957 alt {
Harald Welte9b751a62019-04-14 17:39:29 +02001958 [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { }
1959 [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { }
Harald Welte1ddc7162018-01-27 14:25:46 +01001960 [] T.timeout {
Harald Welte5946b332018-03-18 23:32:21 +01001961 setverdict(fail, "Timeout waiting for ClearCommand/Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001962 mtc.stop;
Harald Welte1ddc7162018-01-27 14:25:46 +01001963 }
1964 }
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001965
1966 if (verify_vlr_cell_id) {
1967 /* Now the conn is gone, but the VLR reflects the cell ID */
1968 f_verify_vty_lac_ci();
1969 }
Harald Welte1ddc7162018-01-27 14:25:46 +01001970}
1971
Neels Hofmeyr0ac63152019-05-07 01:20:17 +02001972function f_create_bssmap_exp_handoverRequest(integer targetPointCode) runs on BSC_ConnHdlr {
1973 BSSAP_PROC.call(RAN_register_handoverRequest:{targetPointCode, self}) {
1974 [] BSSAP_PROC.getreply(RAN_register_handoverRequest:{?, ?}) {};
1975 }
1976}
1977
1978function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array {
1979 var N_Sd_Array last_n_sd;
1980 BSSAP_PROC.call(RAN_last_n_sd:{self, -}) {
1981 [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) {
1982 return last_n_sd;
1983 };
1984 }
1985}
1986
1987function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr {
1988 BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) {
1989 [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self});
1990 }
1991}
1992
Harald Weltef45efeb2018-04-09 18:19:24 +02001993type record SmsParametersTp {
1994 OCT1 msg_ref,
1995 TP_DA da,
1996 OCT1 pid,
1997 OCT1 dcs,
1998 integer udl,
1999 octetstring ud
2000}
2001type record SmsParametersRp {
2002 OCT1 msg_ref,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002003 RP_NumberingPlan_and_NumberDigits smsc_addr optional
Harald Weltef45efeb2018-04-09 18:19:24 +02002004}
2005type record SmsParameters {
2006 SmsParametersTp tp,
2007 SmsParametersRp rp,
2008 uint3_t tid,
2009 OCT1 dlci,
2010 uint7_t exp_rp_err optional
2011}
2012
2013template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := {
2014 tP_DA_NoPad := {
2015 tP_LengthIndicator := 0, /* overwritten */
2016 tP_NumberingPlanID := npl,
2017 tP_TypeOfNumber := ton,
2018 tp_Spare := '0'B,
2019 tP_DAValue := addr
2020 }
2021}
2022
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002023template RP_NumberingPlan_and_NumberDigits t_RP_Addr(template hexstring addr,
2024 template BIT4 npi := '0001'B,
2025 template BIT3 ton := '001'B,
2026 template BIT1 ext := '1'B) := {
2027 rP_NumberingPlanIdentification := npi,
2028 rP_TypeOfNumber := ton,
2029 rP_Ext := ext,
2030 rP_NumberDigits := addr
2031}
2032
Harald Weltef45efeb2018-04-09 18:19:24 +02002033template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := {
2034 tp := {
2035 msg_ref := '23'O,
2036 da := ts_TP_DA('0000'B, '000'B, tp_daddr),
2037 pid := '00'O,
2038 dcs := '00'O,
2039 udl := 0,
2040 ud := ''O
2041 },
2042 rp := {
2043 msg_ref := '42'O,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002044 /* We don't really need to have both SM-RP-DA/OA here, because only one IE
Vadim Yanitskiyafb15a82020-01-05 14:04:53 +01002045 * is included in MO/MT SMS, and in the most cases it's the SMSC address.
2046 * NOTE: this address is currently hard-coded by OsmoMSC. */
2047 smsc_addr := t_RP_Addr('447785016005'H)
Harald Weltef45efeb2018-04-09 18:19:24 +02002048 },
2049 tid := 0,
2050 dlci := '03'O,
2051 exp_rp_err := omit
2052}
2053
2054private altstep as_other_sms() runs on BSC_ConnHdlr {
2055 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) {
2056 setverdict(fail, "Unexpected SMS related PDU from MSC");
Daniel Willmannafce8662018-07-06 23:11:32 +02002057 mtc.stop;
Harald Weltef45efeb2018-04-09 18:19:24 +02002058 }
2059}
2060
Vadim Yanitskiy9cc019a2018-11-15 02:06:07 +07002061/* Submit a MO RP-SMMA over an already existing DTAP connection */
2062function f_mo_smma(inout SmsParameters spars)
2063runs on BSC_ConnHdlr {
2064 var template (value) RPDU_MS_SGSN rp_mo;
2065 var template (value) PDU_ML3_MS_NW l3_mo;
2066
2067 var default d := activate(as_other_sms());
2068
2069 /* just in case this is routed to SMPP.. */
2070 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2071
2072 rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref);
2073 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
2074 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2075 /* receive CP-ACK for CP-DATA above */
2076 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
2077
2078 deactivate(d);
2079 setverdict(pass);
2080}
2081
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002082/* Submit a MO-SMS over an already existing DTAP connection */
2083function f_mo_sms_submit(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02002084runs on BSC_ConnHdlr {
2085 var template (value) TPDU_RP_DATA_MS_SGSN tp_mo;
2086 var template (value) RPDU_MS_SGSN rp_mo;
2087 var template (value) PDU_ML3_MS_NW l3_mo;
2088
Harald Weltef45efeb2018-04-09 18:19:24 +02002089 var default d := activate(as_other_sms());
2090
Harald Weltef640a012018-04-14 17:49:21 +02002091 /* just in case this is routed to SMPP.. */
2092 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2093
Harald Weltef45efeb2018-04-09 18:19:24 +02002094 tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs,
2095 spars.tp.udl, spars.tp.ud);
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002096 rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, omit, spars.rp.smsc_addr, tp_mo);
Harald Weltef45efeb2018-04-09 18:19:24 +02002097 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
2098 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2099 /* receive CP-ACK for CP-DATA above */
2100 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
2101
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002102 deactivate(d);
2103 setverdict(pass);
2104}
2105
2106/* Wait RP-ACK for MO-SMS on an already existing DTAP connection */
2107function f_mo_sms_wait_rp_ack(inout SmsParameters spars)
2108runs on BSC_ConnHdlr {
2109 var template (value) PDU_ML3_MS_NW l3_mo;
2110
2111 var template TPDU_RP_DATA_SGSN_MS tp_mt;
2112 var template RPDU_SGSN_MS rp_mt;
2113 var template PDU_ML3_NW_MS l3_mt;
2114
2115 var default d := activate(as_other_sms());
2116
2117 /* just in case this is routed to SMPP.. */
2118 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2119
Harald Weltef45efeb2018-04-09 18:19:24 +02002120 if (ispresent(spars.exp_rp_err)) {
2121 /* expect an RP-ERROR message from MSC with given cause */
2122 rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err);
2123 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
2124 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2125 /* send CP-ACK for CP-DATA just received */
2126 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
2127 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2128 } else {
2129 /* expect RP-ACK for RP-DATA */
2130 rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref);
2131 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
2132 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2133 /* send CP-ACO for CP-DATA just received */
2134 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
2135 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2136 }
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002137
Harald Weltef45efeb2018-04-09 18:19:24 +02002138 deactivate(d);
2139 setverdict(pass);
2140}
2141
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002142/* Submit a MO-SMS, and wait for RP-ACK on an existing
2143 * (and authenticated, ...) DTAP connection */
2144function f_mo_sms(inout SmsParameters spars)
2145runs on BSC_ConnHdlr {
2146 f_mo_sms_submit(spars);
2147 f_mo_sms_wait_rp_ack(spars);
2148}
2149
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002150function f_mt_sms_deliver_pdu(in SmsParameters spars)
2151runs on BSC_ConnHdlr
2152return template PDU_DTAP_MT {
2153 var template TPDU_RP_DATA_SGSN_MS tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?);
2154 var template RPDU_SGSN_MS rp_mt := tr_RP_DATA_MT(?, spars.rp.smsc_addr, omit, tp_mt);
2155 var template PDU_ML3_NW_MS l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt));
2156 return tr_PDU_DTAP_MT(l3_mt, spars.dlci);
2157}
2158
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002159/* Wait for MT SMS on an already existing DTAP connection */
2160function f_mt_sms_expect(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02002161runs on BSC_ConnHdlr {
Harald Weltef45efeb2018-04-09 18:19:24 +02002162 var template (value) PDU_ML3_MS_NW l3_mo;
Harald Weltef45efeb2018-04-09 18:19:24 +02002163 var PDU_DTAP_MT dtap_mt;
2164
2165 var default d := activate(as_other_sms());
2166
2167 /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002168 BSSAP.receive(f_mt_sms_deliver_pdu(spars)) -> value dtap_mt;
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002169
Harald Weltef45efeb2018-04-09 18:19:24 +02002170 /* Extract relevant identifiers */
2171 spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio);
2172 spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference;
2173
2174 /* send CP-ACK for CP-DATA just received */
2175 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO);
2176 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2177
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002178 deactivate(d);
2179 setverdict(pass);
2180}
2181
2182/* Send RP-ACK for MT-SMS over an already existing DTAP connection */
2183function f_mt_sms_send_rp_ack(inout SmsParameters spars)
2184runs on BSC_ConnHdlr {
2185 var template (value) RPDU_MS_SGSN rp_mo;
2186 var template (value) PDU_ML3_MS_NW l3_mo;
2187 var template PDU_ML3_NW_MS l3_mt;
2188
2189 var default d := activate(as_other_sms());
2190
Harald Weltef45efeb2018-04-09 18:19:24 +02002191 /* send RP-ACK for RP-DATA */
2192 rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref);
2193 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2194 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2195
2196 /* expect CP-ACK for CP-DATA(RP-ACK) just sent */
Harald Weltee008eea2018-04-14 21:05:48 +02002197 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
Harald Weltef45efeb2018-04-09 18:19:24 +02002198 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2199
2200 deactivate(d);
2201 setverdict(pass);
2202}
2203
Vadim Yanitskiy56318522018-11-24 03:40:47 +07002204/* Send RP-ERROR for MT-SMS over an already existing DTAP connection */
2205function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause)
2206runs on BSC_ConnHdlr {
2207 var template (value) RPDU_MS_SGSN rp_mo;
2208 var template (value) PDU_ML3_MS_NW l3_mo;
2209 var template PDU_ML3_NW_MS l3_mt;
2210
2211 var default d := activate(as_other_sms());
2212
2213 /* send RP-ACK for RP-DATA */
2214 rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause);
2215 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2216 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2217
2218 /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */
2219 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
2220 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2221
2222 deactivate(d);
2223 setverdict(pass);
2224}
2225
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002226/* Wait for a MT-SMS and send RP-ACK over an already existing
2227 * (and authenticated, ...) DTAP connection */
2228function f_mt_sms(inout SmsParameters spars)
2229runs on BSC_ConnHdlr {
2230 f_mt_sms_expect(spars);
2231 f_mt_sms_send_rp_ack(spars);
2232}
Harald Weltea49e36e2018-01-21 19:29:33 +01002233
2234
Harald Weltea49e36e2018-01-21 19:29:33 +01002235}