blob: f141955f21c6f8413801b2cfc1c4fca5dc2c55d2 [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,
378 EST_TYPE_SS_ACT
Harald Welte081b19a2018-02-10 09:11:13 +0100379};
380
Harald Weltea49e36e2018-01-21 19:29:33 +0100381/* helper function to fully establish a dedicated channel */
Harald Welteb9e86fa2018-04-09 18:18:31 +0200382function f_establish_fully(EstablishType etype := EST_TYPE_MO_CALL)
Harald Weltea49e36e2018-01-21 19:29:33 +0100383runs on BSC_ConnHdlr {
Harald Welte081b19a2018-02-10 09:11:13 +0100384 var PDU_ML3_MS_NW l3_info;
Harald Welteb9e86fa2018-04-09 18:18:31 +0200385 var MobileIdentityLV mi;
386
387 /* If we have a TMSI, use TMSI instead of IMSI */
388 if (ispresent(g_pars.tmsi)) {
389 mi := valueof(ts_MI_TMSI_LV(g_pars.tmsi));
390 } else {
391 mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
392 }
393
Harald Welte081b19a2018-02-10 09:11:13 +0100394 select (etype) {
395 case (EST_TYPE_MO_CALL) {
396 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
397 }
Harald Welte0bef21e2018-02-10 09:48:23 +0100398 case (EST_TYPE_EMERG_CALL) {
399 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_EMERG_CALL, mi));
400 }
Harald Welte081b19a2018-02-10 09:11:13 +0100401 case (EST_TYPE_PAG_RESP) {
402 l3_info := valueof(ts_PAG_RESP(mi));
403 }
Harald Weltef45efeb2018-04-09 18:19:24 +0200404 case (EST_TYPE_MO_SMS) {
405 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_SMS, mi));
406 }
Vadim Yanitskiy20ee5e42018-05-27 17:54:21 +0700407 case (EST_TYPE_SS_ACT) {
408 l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_SS_ACT, mi));
409 }
Harald Welte081b19a2018-02-10 09:11:13 +0100410 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100411
412 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Weltedceacc72019-04-21 20:58:35 +0200413 f_cl3_or_initial_ue(l3_info);
Harald Weltea49e36e2018-01-21 19:29:33 +0100414
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200415 f_verify_vty_lac_ci(verify_vlr := false);
416
Harald Weltede371492018-01-27 23:44:41 +0100417 f_mm_common();
Pau Espin Pedrolf8034482019-06-03 13:15:58 +0200418 if (g_pars.net.expect_ciph or not g_pars.ran_is_geran) {
Harald Welte148a7082018-01-26 18:56:43 +0100419 /* implicit CM SERVICE ACCEPT? */
420 } else {
Harald Welte0bef21e2018-02-10 09:48:23 +0100421 if (etype != EST_TYPE_PAG_RESP) {
Harald Welte081b19a2018-02-10 09:11:13 +0100422 /* explicit CM SERVICE ACCEPT */
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200423 if (g_pars.net.expect_attach_success) {
424 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_ACC));
425 } else {
426 BSSAP.receive(tr_PDU_DTAP_MT(tr_CM_SERV_REJ));
427 }
Harald Welte081b19a2018-02-10 09:11:13 +0100428 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100429 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100430}
431
432/* build a PDU_ML3_MS_NW containing a Location Update by IMSI */
Harald Welte9de84792018-01-28 01:06:35 +0100433function f_build_lu_imsi(hexstring imsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100434{
435 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(imsi));
436 return f_build_lu(mi);
437}
Harald Welte9de84792018-01-28 01:06:35 +0100438function f_build_lu_imei(hexstring imei) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100439{
440 var MobileIdentityLV mi := valueof(ts_MI_IMEI_LV(imei));
441 return f_build_lu(mi);
442}
Harald Welte9de84792018-01-28 01:06:35 +0100443function f_build_lu_tmsi(OCT4 tmsi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Welteba7b6d92018-01-23 21:32:34 +0100444{
445 var MobileIdentityLV mi := valueof(ts_MI_TMSI_LV(tmsi));
446 return f_build_lu(mi);
447}
Harald Welte9de84792018-01-28 01:06:35 +0100448private function f_build_lu(MobileIdentityLV mi) runs on BSC_ConnHdlr return PDU_ML3_MS_NW
Harald Weltea49e36e2018-01-21 19:29:33 +0100449{
450 var LocationAreaIdentification_V old_lai := { '62F220'O, '9999'O };
451 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 +0100452 old_lai, mi, g_pars.cm1));
Harald Weltea49e36e2018-01-21 19:29:33 +0100453 return l3_info;
454}
455
Harald Weltea183a5d2019-05-09 13:40:52 +0200456altstep as_GSUP_SAI() runs on BSC_ConnHdlr {
457var GSUP_IE auth_tuple;
458[] GSUP.receive(tr_GSUP_SAI_REQ(g_pars.imsi)) {
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200459 if (g_pars.net.hlr_has_auth_info) {
460 if (g_pars.use_umts_aka) {
461 if (not g_pars.vec_keep) {
462 g_pars.vec := f_gen_auth_vec_3g();
463 }
464 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G3G(g_pars.vec.rand,
465 g_pars.vec.sres,
466 g_pars.vec.kc,
467 g_pars.vec.ik,
468 g_pars.vec.ck,
469 g_pars.vec.autn,
470 g_pars.vec.res));
471 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
472 } else {
473 if (not g_pars.vec_keep) {
474 g_pars.vec := f_gen_auth_vec_2g();
475 }
476 auth_tuple := valueof(ts_GSUP_IE_AuthTuple2G(g_pars.vec.rand,
477 g_pars.vec.sres,
478 g_pars.vec.kc));
479 GSUP.send(ts_GSUP_SAI_RES(g_pars.imsi, auth_tuple));
Neels Hofmeyrb00c5b02021-06-23 20:05:25 +0200480 }
Harald Weltea183a5d2019-05-09 13:40:52 +0200481 } else {
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200482 log("XXX ts_GSUP_SAI_ERR");
483 /* HLR knows the IMSI but has no authentication info; osmo-hlr responds with GMM_CAUSE_IMSI_UNKNOWN=2 in
484 * this case, for SAI this merely means there is no auth entry for this IMSI. */
485 GSUP.send(ts_GSUP_SAI_ERR(g_pars.imsi, 2));
Harald Weltea183a5d2019-05-09 13:40:52 +0200486 }
487 }
488}
489
Harald Welte9de84792018-01-28 01:06:35 +0100490function f_mm_auth() runs on BSC_ConnHdlr
Harald Welte148a7082018-01-26 18:56:43 +0100491{
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200492 if (g_pars.net.expect_auth or g_pars.net.expect_auth_attempt) {
Harald Weltea183a5d2019-05-09 13:40:52 +0200493 as_GSUP_SAI();
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200494 }
495 if (g_pars.net.expect_auth) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200496 if (g_pars.use_umts_aka) {
Harald Weltec1f937a2019-04-21 21:19:23 +0200497 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ_3G(g_pars.vec.rand, g_pars.vec.autn)));
498 var OCT4 res := substr(g_pars.vec.res, 0, 4);
499 var OCT4 xres := substr(g_pars.vec.res, 4, 4);
500 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_3G(res, xres)));
501 } else {
Harald Weltec1f937a2019-04-21 21:19:23 +0200502 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_AUTH_REQ(g_pars.vec.rand)));
503 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MT_MM_AUTH_RESP_2G(g_pars.vec.sres)));
504 }
Harald Welte148a7082018-01-26 18:56:43 +0100505 }
Harald Welte9de84792018-01-28 01:06:35 +0100506}
Harald Welte148a7082018-01-26 18:56:43 +0100507
Oliver Smith1d118ff2019-07-03 10:57:35 +0200508function f_mm_imei() runs on BSC_ConnHdlr
509{
510 var PDU_DTAP_MT dtap_mt;
511 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700512 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200513
514 if (not g_pars.net.expect_imei) {
515 return
516 }
517
518 /* MSC <-> BSC: ID req/rsp for IMEI */
519 alt {
520 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEI))) {
521 mi := valueof(ts_MI_IMEI_LV(g_pars.imei));
522 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
523 }
524 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
525 setverdict(fail, "Expected ID REQ for IMEI DTAP MT message, but got: ", dtap_mt);
526 mtc.stop;
527 }
528 }
529
530 /* MSC <-> HLR: Check IMEI req/res/err */
531 alt {
532 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
533 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
534 }
535 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
536 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
537 }
538 [] GSUP.receive(?) -> value gsup_msg {
539 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
540 g_pars.imsi, "), but got: ", gsup_msg);
541 mtc.stop;
542 }
543 }
544}
545
546function f_mm_imei_early() runs on BSC_ConnHdlr
547{
548 var PDU_DTAP_MT dtap_mt;
549 var GSUP_PDU gsup_msg;
Vadim Yanitskiy98bb2d52020-03-28 00:57:21 +0700550 var MobileIdentityLV mi;
Oliver Smith1d118ff2019-07-03 10:57:35 +0200551
552 if (not g_pars.net.expect_imei_early) {
553 return
554 }
555
556 /* MSC <-> BSC: ID req/rsp for IMEISV */
557 alt {
558 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_ID_Req(CM_ID_TYPE_IMEISV))) {
559 mi := valueof(ts_MI_IMEISV_LV(g_pars.imei));
560 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_MM_ID_Rsp(mi)));
561 }
562 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
563 setverdict(fail, "Expected ID REQ for IMEISV DTAP MT message, but got: ", dtap_mt);
564 mtc.stop;
565 }
566 }
567
568 /* MSC <-> HLR: Check IMEI req/res/err */
569 alt {
570 [g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
571 GSUP.send(ts_GSUP_CHECK_IMEI_ERR(g_pars.imsi, 96 /* Invalid Mandatory Information */));
572 }
573 [not g_pars.net.check_imei_error] GSUP.receive(tr_GSUP_CHECK_IMEI_REQ(g_pars.imsi, g_pars.imei)) {
574 GSUP.send(ts_GSUP_CHECK_IMEI_RES(g_pars.imsi, g_pars.net.check_imei_result));
575 }
576 [] GSUP.receive(?) -> value gsup_msg {
577 setverdict(fail, "Expected CHECK IMEI REQ GSUP message (with IMEI:", g_pars.imei, " and IMSI: ",
578 g_pars.imsi, "), but got: ", gsup_msg);
579 mtc.stop;
580 }
581 }
582}
583
Harald Welte79f1e452020-08-18 22:55:02 +0200584function f_expect_common_id() runs on BSC_ConnHdlr
585{
586 if (g_pars.ran_is_geran) {
Pau Espin Pedrole979c402021-04-28 17:29:54 +0200587 BSSAP.receive(tr_BSSMAP_CommonId(g_pars.imsi,
588 f_tr_BSSMAP_LastUsedEUTRANPLMNId(g_pars.common_id_last_eutran_plmn)));
Harald Welte79f1e452020-08-18 22:55:02 +0200589 } else {
590 BSSAP.receive(tr_RANAP_CommonId(imsi_hex2oct(g_pars.imsi)));
591 }
592}
593
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200594/* For UMTS AKA on GERAN, calculate the specific kc from the UMTS AKA ck and ik vectors. */
595function f_auth3g_kc(AuthVector vec) return OCT8 {
Eric Wild26f4a622021-05-17 15:27:05 +0200596 var integer i;
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200597 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 +0200598 for (i := 1; i < 8; i := i + 1) {
Neels Hofmeyr0d6fd3e2021-06-23 23:24:09 +0200599 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 +0200600 res := res & a;
601 }
602
603 return res;
604}
605
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200606function f_get_expected_encryption(
607 out template BSSMAP_IE_EncryptionInformation encryptionInformation,
608 out template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm,
609 out template BSSMAP_IE_KC128 kC128,
610 out OCT1 a5_perm_alg) runs on BSC_ConnHdlr
611{
612 var OCT1 a5_ms := f_alg_mask_from_cm(g_pars.cm2, g_pars.cm3);
613 a5_perm_alg := g_pars.net.kc_support and4b a5_ms;
614
615 if (not g_pars.net.expect_ciph) {
616 encryptionInformation := *;
617 chosenEncryptionAlgorithm := *;
618 kC128 := *;
619 return;
620 }
621
Neels Hofmeyrf6eff812021-06-23 23:29:39 +0200622 var OCT8 kc;
623 if (g_pars.use_umts_aka) {
624 kc := f_auth3g_kc(g_pars.vec);
625 } else {
626 kc := g_pars.vec.kc;
627 }
628 encryptionInformation := tr_BSSMAP_IE_EncrInfo(kc, a5_perm_alg);
Neels Hofmeyrf7831cb2021-06-23 20:04:58 +0200629
630 var OCT1 chosen_alg := int2oct(f_alg_from_mask(f_best_alg_from_mask(a5_perm_alg)) + 1, 1);
631 chosenEncryptionAlgorithm := tr_BSSMAP_IE_ChosenEncryptionAlgorithm(chosen_alg);
632
633 if (g_pars.use_umts_aka and f_alg_supported_by_mask(a5_perm_alg, 4)) {
634 /* A5/4 is permitted, expecting kc128 to be present */
635 var OCT32 full_sha256 := f_calculate_HMAC_SHA256(g_pars.vec.ck & g_pars.vec.ik, '32'O, 32);
636 var OCT16 expect_kc128 := substr(full_sha256, 0, 16);
637 kC128 := tr_BSSMAP_IE_Kc128(expect_kc128);
638 } else {
639 kC128 := omit
640 }
641}
642
Eric Wild26f4a622021-05-17 15:27:05 +0200643
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300644private function f_mm_ciph_geran() runs on BSC_ConnHdlr
645{
646 var template BSSMAP_IE_EncryptionInformation encryptionInformation;
647 var template BSSMAP_IE_ChosenEncryptionAlgorithm chosenEncryptionAlgorithm;
648 var template BSSMAP_IE_KC128 kC128;
649 var OCT1 a5_perm_alg;
650 var PDU_BSSAP pdu;
651
Vadim Yanitskiy172bc6e2021-12-06 17:54:57 +0300652 if (not g_pars.net.expect_ciph) {
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300653 /* There is nothing to do */
654 return;
655 }
656
657 f_get_expected_encryption(encryptionInformation, chosenEncryptionAlgorithm, kC128, a5_perm_alg);
658 alt {
659 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128)) -> value pdu {
660 var OCT1 a5_chosen := f_best_alg_from_mask(a5_perm_alg);
661 var integer a5_nr := f_alg_from_mask(a5_chosen);
662 BSSAP.send(ts_BSSMAP_CipherModeCompl(int2oct(a5_nr+1, 1)));
663 }
664 [] BSSAP.receive(tr_BSSMAP_CipherModeCmd2) -> value pdu {
665 log("Error: Ciphering Mode Command with unexpected content. Expected: ",
666 tr_BSSMAP_CipherModeCmd2(encryptionInformation, kC128), " got: ", pdu);
667 setverdict(fail, "Ciphering Mode Command with unexpected content.");
668 mtc.stop;
669 }
670 [] BSSAP.receive(tr_BSSMAP_ClassmarkRequest) {
671 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3))
672 repeat;
673 }
674 }
675 /* FIXME: Send the best available algorithm */
676}
677
678private function f_mm_ciph_utran() runs on BSC_ConnHdlr
679{
680 alt {
681 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(uia_algs := ?,
682 uia_key := oct2bit(g_pars.vec.ik),
683 key_sts := ?,
684 uea_algs := ?,
685 uea_key := oct2bit(g_pars.vec.ck))) {
686 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1*/
687 var EncryptionAlgorithm uea_chosen := 1; /*standard_UMTS_encryption_algorith_UEA1*/
688 BSSAP.send(ts_RANAP_SecurityModeCompleteEnc(uia_chosen, uea_chosen));
689 }
690 [g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmdEnc(?,?,?,?,?)) {
691 setverdict(fail, "Invalid SecurityModeCommand (ciphering case)");
692 mtc.stop;
693 }
694 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(uia_algs := ?,
695 uia_key := oct2bit(g_pars.vec.ik),
696 key_sts := ?)) {
697 var IntegrityProtectionAlgorithm uia_chosen := 0; /*standard_UMTS_integrity_algorithm_UIA1;*/
698 BSSAP.send(ts_RANAP_SecurityModeComplete(uia_chosen));
699 }
700 [not g_pars.net.expect_ciph] BSSAP.receive(tr_RANAP_SecurityModeCmd(?,?,?)) {
701 setverdict(fail, "Invalid SecurityModeCommand (non-ciphering case)");
702 mtc.stop;
703 }
704 }
705}
706
Harald Welte9de84792018-01-28 01:06:35 +0100707function f_mm_common() runs on BSC_ConnHdlr
708{
709 f_mm_auth();
Eric Wild26f4a622021-05-17 15:27:05 +0200710
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300711 if (g_pars.ran_is_geran) {
712 f_mm_ciph_geran();
713 } else {
714 f_mm_ciph_utran();
Harald Welte148a7082018-01-26 18:56:43 +0100715 }
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300716
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200717 if (not g_pars.net.expect_attach_success) {
718 return;
719 }
Vadim Yanitskiy0649d1c2021-11-28 04:33:32 +0300720 f_expect_common_id();
Harald Welte148a7082018-01-26 18:56:43 +0100721}
722
Philipp Maier9b690e42018-12-21 11:50:03 +0100723function f_expect_mm_info() runs on BSC_ConnHdlr {
724 if (g_pars.mm_info == true) {
725 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_MM_Info));
726 }
727}
728
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200729private function f_lac_ci_vty_str(BSSMAP_IE_CellIdentifier cell_id) return charstring
730{
731 return "LAC / cell ID: "
732 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.lac)) & " / "
733 & int2str(oct2int(cell_id.cellIdentification.cI_CGI.ci));
734}
735
736/* Get an IMSI's info and verify that the g_pars.cell_id is reflected in the info.
737 * Verify both the "LAC / cell ID" in the VLR and the "LAC / cell ID" in the "Connection:" part, if any.
738 * If verify_vlr == false, then only verify the "Connection:" part, and fail if there is no "Connection:"; this is
739 * useful when a conn has been established, but the subscriber has not been authenticated, so the VLR does not yet
740 * reflect the new conn's cell ID.
741 */
742function f_verify_vty_lac_ci(boolean verify_vlr := true) runs on BSC_ConnHdlr {
743 if (not g_pars.ran_is_geran) {
744 log("Skipping f_verify_vty_lac_ci(), disabled for Iu");
745 setverdict(pass);
746 return;
747 }
748 if (not g_pars.verify_cell_id) {
749 /* Skip this verification; either the TC expects no cell id to end up being accepted, or this was
750 * disabled globally to test an older osmo-msc which doesn't store the cell id properly yet. */
751 log("Skipping f_verify_vty_lac_ci()");
752 setverdict(pass);
753 return;
754 }
755
756 var charstring vty_cmd := "show subscriber imsi " & hex2str(g_pars.imsi) & " conn";
757 var charstring result := f_vty_transceive_ret(MSCVTY, vty_cmd);
758 var charstring expect_lac_ci := "LAC / cell ID: "
759 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.lac)) & " / "
760 & int2str(oct2int(g_pars.cell_id.cellIdentification.cI_CGI.ci));
761
762 var boolean vlr_matches := false;
763 var boolean connection_present := false;
764 var boolean connection_matches := false;
765
766 /* There are two occurences of LAC / cell ID: once for the VLR record, and once for the active connection. The
767 * active connection part starts with 'Connection:'. If there is no active connection, that part is omitted.
768 * So, first find out whether there is a 'Connection:' part. Then verify the LAC / cell ID above 'Connection:'
769 * and below 'Connection:', separately.
770 */
771 var integer connection_start := f_strstr(result, "Connection:");
772 connection_present := (connection_start >= 0);
773
774 var integer lac_ci_match := f_strstr(result, expect_lac_ci);
775 if (connection_present) {
776 if (lac_ci_match > connection_start) {
777 /* The first match is below 'Connection:', so the VLR part above it did not match. */
778 vlr_matches := false;
779 connection_matches := true;
780 } else if (lac_ci_match >= 0) {
781 /* The first match is above 'Connection:', so the VLR part matches. */
782 vlr_matches := true;
783
784 /* Now find a match below 'Connection:' */
785 lac_ci_match := f_strstr(result, expect_lac_ci, connection_start);
786 connection_matches := (lac_ci_match > 0);
787 }
788 } else {
789 /* There is no 'Connection:', so a match, if any, is from the VLR part. */
790 vlr_matches := (lac_ci_match >= 0);
791 }
792
793 if (verify_vlr) {
794 if (not vlr_matches) {
795 setverdict(fail, vty_cmd, " shows mismatching LAC / cell ID in the VLR part, expecting: ",
796 expect_lac_ci, " -- got: ", result);
797 return;
798 } else {
799 log("f_verify_vty_lac_ci(): VLR record matches ", expect_lac_ci);
800 setverdict(pass);
801 }
802 }
803
804 if (connection_present) {
805 if (not connection_matches) {
806 setverdict(fail, vty_cmd, " shows mismatching LAC cell ID in the 'Connection' part, expecting: ",
807 expect_lac_ci, " -- got: ", result);
808 } else {
809 log("f_verify_vty_lac_ci(): Active connection matches ", expect_lac_ci);
810 setverdict(pass);
811 }
812 }
813
814 if (not verify_vlr and not connection_present) {
815 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);
816 }
817}
818
Neels Hofmeyrc1f105a2018-03-01 20:00:19 +0100819function f_perform_lu()
Harald Weltea49e36e2018-01-21 19:29:33 +0100820runs on BSC_ConnHdlr {
821 var PDU_ML3_MS_NW l3_lu := f_build_lu_imsi(g_pars.imsi)
822 var PDU_DTAP_MT dtap_mt;
823
824 /* tell GSUP dispatcher to send this IMSI to us */
825 f_create_gsup_expect(hex2str(g_pars.imsi));
826
827 /* Send BSSAP_Conn_Req with COMPL L3 INFO to MSC */
Harald Welte9b751a62019-04-14 17:39:29 +0200828 if (g_pars.ran_is_geran) {
829 f_bssap_compl_l3(l3_lu);
830 if (g_pars.send_early_cm) {
831 BSSAP.send(ts_BSSMAP_ClassmarkUpd(g_pars.cm2, g_pars.cm3));
832 }
833 } else {
834 f_ranap_initial_ue(l3_lu);
Harald Welte8a121b32018-01-22 03:00:41 +0100835 }
Harald Welte5c2622c2018-01-21 20:45:20 +0100836
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +0200837 /* at this point the conn has been established, but the subscriber has not been authenticated, so the VLR does
838 * not yet reflect this conn's cell ID. */
839 f_verify_vty_lac_ci(verify_vlr := false);
840
Oliver Smith1d118ff2019-07-03 10:57:35 +0200841 f_mm_imei_early();
Harald Weltede371492018-01-27 23:44:41 +0100842 f_mm_common();
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100843 f_msc_lu_hlr();
Oliver Smith1d118ff2019-07-03 10:57:35 +0200844 f_mm_imei();
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200845 as_accept_reject_lu(g_pars.net.expect_attach_success);
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100846 /* FIXME: there could be pending SMS or other common procedures by the MSC, let's ignore them */
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200847 f_expect_clear(verify_vlr_cell_id := g_pars.net.expect_attach_success);
Harald Welte16114282018-01-24 22:41:21 +0100848
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100849 setverdict(pass);
850}
851
852function f_msc_lu_hlr() runs on BSC_ConnHdlr
853{
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200854 if (not g_pars.net.expect_attach_success) {
855 return;
856 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100857 /* Expect MSC to perform LU with HLR */
858 GSUP.receive(tr_GSUP_UL_REQ(g_pars.imsi));
859 GSUP.send(ts_GSUP_ISD_REQ(g_pars.imsi, g_pars.msisdn));
860 GSUP.receive(tr_GSUP_ISD_RES(g_pars.imsi));
861 GSUP.send(ts_GSUP_UL_RES(g_pars.imsi));
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100862}
863
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200864altstep as_accept_reject_lu(boolean expect_accept := true) runs on BSC_ConnHdlr {
Stefan Sperlinga2d59c62018-12-18 16:32:44 +0100865 var PDU_DTAP_MT dtap_mt;
Harald Weltea49e36e2018-01-21 19:29:33 +0100866
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200867 [expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
Harald Weltea49e36e2018-01-21 19:29:33 +0100868 var PDU_ML3_LocationUpdateAccept lu_acc := dtap_mt.dtap.msgs.mm.locationUpdateAccept;
Harald Weltede371492018-01-27 23:44:41 +0100869 if (g_pars.net.expect_tmsi) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100870 if (not ispresent(lu_acc.mobileIdentityTLV) or
871 not ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
872 setverdict(fail, "Expected TMSI but no TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200873 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100874 } else {
Harald Welte256571e2018-01-24 18:47:19 +0100875 g_pars.tmsi := lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi.octets;
Harald Weltea49e36e2018-01-21 19:29:33 +0100876 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_TmsiRealloc_Cmpl));
877 }
878 } else {
879 if (ispresent(lu_acc.mobileIdentityTLV) and
880 ischosen(lu_acc.mobileIdentityTLV.mobileIdentityLV.mobileIdentityV.oddEvenInd_identity.tmsi_ptmsi)) {
881 setverdict(fail, "Expected no TMSI but TMSI was allocated");
Daniel Willmannafce8662018-07-06 23:11:32 +0200882 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100883 }
884 }
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200885
886 /* Wait for MM-Information (if enabled) */
887 f_expect_mm_info();
888 setverdict(pass);
889 }
890 [expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
Harald Weltea49e36e2018-01-21 19:29:33 +0100891 setverdict(fail, "Expected LU ACK, but received LU REJ");
Daniel Willmannafce8662018-07-06 23:11:32 +0200892 mtc.stop;
Harald Weltea49e36e2018-01-21 19:29:33 +0100893 }
Philipp Maier9b690e42018-12-21 11:50:03 +0100894
Neels Hofmeyre860fc42022-10-05 01:15:54 +0200895 [not expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej)) {
896 setverdict(pass);
897 }
898 [not expect_accept] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Acc)) -> value dtap_mt {
899 setverdict(fail, "Expected LU REJ, but received LU ACK");
900 mtc.stop;
901 }
Harald Weltea49e36e2018-01-21 19:29:33 +0100902}
903
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100904function f_expect_lu_reject(template OCT1 cause := ?) runs on BSC_ConnHdlr {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200905 var PDU_DTAP_MT dtap_mt;
906 timer T := 5.0;
907
908 T.start;
909 alt {
Pau Espin Pedrold3d54a92019-12-17 17:02:54 +0100910 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_LU_Rej(cause))) {
Oliver Smith91bfa1c2019-07-19 15:01:15 +0200911 setverdict(pass);
912 }
913 [] BSSAP.receive(tr_PDU_DTAP_MT(?)) -> value dtap_mt {
914 setverdict(fail, "Expected LU reject BSSAP message, got: ", dtap_mt);
915 }
916 [] T.timeout {
917 setverdict(fail, "Timeout waiting for LU reject");
918 }
919 }
920}
921
Harald Weltea49e36e2018-01-21 19:29:33 +0100922function f_foo() runs on BSC_ConnHdlr{
Harald Welte6811d102019-04-14 22:23:14 +0200923 /* SCCP CC handled by RAN_Emulation_CT.main() */
Harald Weltea49e36e2018-01-21 19:29:33 +0100924 /* Expect auth, if enabled */
925
926 /* TODO: ISD */
927 /* Expect encr, if enabled */
928 /* Expect encr, if enabled */
929 /* Expect ASS CMD, if chan_type != requested */
930 /* Send ASS CMPL in successful case */
931
932 /* Expect AoIP port/ip information for RTP stream */
933 /* Expect MSC-originated MGCP to our simulated MGW */
934 /* Verify Counters via CTRL */
935 /* re-configure MSC behaviour via VTY */
936}
937
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200938type record CrcxResponse {
939 integer resp, /* 1 = reply with OK, 0 = do not reply, -1 = reply with error */
940 HostName mgw_rtp_ip,
941 PortNumber mgw_rtp_port,
942 MgcpConnectionId mgcp_connection_id /* MGCP Connection ID BSS Side */
943}
944
Harald Welteb71901a2018-01-26 19:16:05 +0100945/* parameters related to a (MO?) voice call */
946type record CallParameters {
Harald Welteb71901a2018-01-26 19:16:05 +0100947 /* CC related parameters */
948 hexstring called_party, /* whom are we calling */
949 integer transaction_id optional, /* which TS 04.08 CC transaction ID to use */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100950 boolean mo_call, /* For a MO call, the transaction_id was allocated by the MS,
951 important to set the TI flag properly */
Harald Welteb71901a2018-01-26 19:16:05 +0100952 BearerCapability_TLV bearer_cap, /* which bearer capabilities to claim */
Harald Welte0bef21e2018-02-10 09:48:23 +0100953 boolean emergency, /* is this an emergency call? */
Harald Welteb71901a2018-01-26 19:16:05 +0100954
955 /* MNCC related parameters */
956 uint32_t mncc_callref optional, /* call reference on the MNCC side */
957 MNCC_bearer_cap mncc_bearer_cap optional, /* MNCC-side bearer capabilities */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200958 HostName mncc_rtp_ip optional, /* MNCC Side RTP IP */
959 PortNumber mncc_rtp_port optional, /* MNCC Side RTP port */
Harald Welteb71901a2018-01-26 19:16:05 +0100960
961 /* RTP related parameters */
962 HostName bss_rtp_ip optional, /* BSS Side RTP IP */
963 PortNumber bss_rtp_port optional, /* BSS Side RTP Port */
964 HostName mss_rtp_ip optional, /* MSS Side RTP IP */
965 PortNumber mss_rtp_port optional, /* MSS Side RTP Port */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200966 integer got_crcx_count,
967 CrcxResponse mgw_conn_1,
968 CrcxResponse mgw_conn_2,
Harald Welteb71901a2018-01-26 19:16:05 +0100969 uint7_t rtp_payload_type, /* dynamic RTP payload type */
970 charstring rtp_sdp_format, /* AMR/8000 or the like */
Philipp Maier2a98a732018-03-19 16:06:12 +0100971 boolean mgw_drop_dlcx optional, /* Provoke errors by not responding to DLCX
972 (f_mt_call and f_mt_call) */
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200973 boolean stop_after_cc_setup, /* Special case: stop call establish after CC Setup */
974 boolean ran_clear_when_alerting, /* Special case: send Clear upon CC Alerting */
Neels Hofmeyr8df69622019-11-02 19:16:03 +0100975 boolean expect_release, /* Special case: expect call establish to cause direct CC Rel */
Harald Welteb71901a2018-01-26 19:16:05 +0100976
Philipp Maiercd668572018-03-19 16:11:52 +0100977 MgcpCallId mgcp_call_id optional, /* MGCP Call ID; CallAgent allocated */
Harald Welteb71901a2018-01-26 19:16:05 +0100978 MgcpEndpoint mgcp_ep optional /* MGCP Endpoint, CallAgent or MGW allocated */,
Pau Espin Pedrola65697d2019-05-21 12:54:39 +0200979
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200980 boolean use_osmux, /* MSC is expected to use Osmux for this call */
981 integer got_osmux_count
Harald Welteb71901a2018-01-26 19:16:05 +0100982}
983
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200984template (value) CallParameters t_CallParams(hexstring called := '12345'H, integer tid := 0) := {
Harald Welteb71901a2018-01-26 19:16:05 +0100985 called_party := called,
986 transaction_id := tid,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +0100987 mo_call := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100988 bearer_cap := valueof(ts_Bcap_voice),
Harald Welte0bef21e2018-02-10 09:48:23 +0100989 emergency := false,
Harald Welteb71901a2018-01-26 19:16:05 +0100990 mncc_callref := omit,
991 mncc_bearer_cap := valueof(ts_MNCC_bcap_voice),
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +0200992 mncc_rtp_ip := "42.23.11.5",
993 mncc_rtp_port := 423,
Harald Welte4017d552018-01-26 21:40:05 +0100994 bss_rtp_ip := "9.8.7.6",
995 bss_rtp_port := 9000,
Harald Welteb71901a2018-01-26 19:16:05 +0100996 mss_rtp_ip := omit,
997 mss_rtp_port := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +0200998 got_crcx_count := 0,
999 mgw_conn_1 := {
1000 resp := 1,
1001 mgw_rtp_ip := "1.1.1.1",
1002 mgw_rtp_port := 10000,
1003 mgcp_connection_id := '11111'H
1004 },
1005 mgw_conn_2 := {
1006 resp := 1,
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001007 mgw_rtp_ip := "2.2.2.2",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001008 mgw_rtp_port := 11000,
1009 mgcp_connection_id := '22222'H
1010 },
Harald Welteb71901a2018-01-26 19:16:05 +01001011 rtp_payload_type := 98,
1012 rtp_sdp_format := "AMR/8000",
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001013 mgw_drop_dlcx := false,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001014 stop_after_cc_setup := false,
1015 ran_clear_when_alerting := false,
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001016 expect_release := false,
Harald Welteb71901a2018-01-26 19:16:05 +01001017 mgcp_call_id := omit,
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001018 mgcp_ep := "rtpbridge/1@mgw",
1019 use_osmux := false,
1020 got_osmux_count := 0
Harald Welteb71901a2018-01-26 19:16:05 +01001021};
1022
Neels Hofmeyrf797d292021-07-27 22:33:09 +02001023template CallParameters tr_CallParams := {
1024 called_party := ?,
1025 transaction_id := ?,
1026 mo_call := ?,
1027 bearer_cap := ?,
1028 emergency := ?,
1029 mncc_callref := *,
1030 mncc_bearer_cap := ?,
1031 mncc_rtp_ip := ?,
1032 mncc_rtp_port := ?,
1033 bss_rtp_ip := ?,
1034 bss_rtp_port := ?,
1035 mss_rtp_ip := *,
1036 mss_rtp_port := *,
1037 got_crcx_count := ?,
1038 mgw_conn_1 := ?,
1039 mgw_conn_2 := ?,
1040 rtp_payload_type := ?,
1041 rtp_sdp_format := ?,
1042 mgw_drop_dlcx := ?,
1043 stop_after_cc_setup := ?,
1044 ran_clear_when_alerting := ?,
1045 expect_release := ?,
1046 mgcp_call_id := *,
1047 mgcp_ep := ?,
1048 use_osmux := ?,
1049 got_osmux_count := ?
1050};
1051
Harald Welte4263c522018-12-06 11:56:27 +01001052/* Allocate a call reference and send SETUP via MNCC to MSC */
Oliver Smith97dc91f2023-05-31 13:53:21 +02001053function f_mt_call_initiate(inout CallParameters cpars)
Harald Welte33ec09b2018-02-10 15:34:46 +01001054runs on BSC_ConnHdlr {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001055 cpars.mo_call := false;
Harald Welte4263c522018-12-06 11:56:27 +01001056 cpars.mncc_callref := f_rnd_int(2147483648);
1057 MNCC.send(ts_MNCC_SETUP_req(cpars.mncc_callref, hex2str(g_pars.msisdn),
1058 hex2str(cpars.called_party), hex2str(g_pars.imsi)));
1059}
Harald Welte33ec09b2018-02-10 15:34:46 +01001060
Harald Welte408a7ef2019-04-21 17:08:40 +02001061private template (value) SDP_Message ts_SDP_CRCX_CN(CallParameters cpars) :=
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001062 ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
Harald Welte408a7ef2019-04-21 17:08:40 +02001063 hex2str(cpars.mgcp_call_id), "42",
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001064 cpars.mgw_conn_2.mgw_rtp_port,
Harald Welte408a7ef2019-04-21 17:08:40 +02001065 { int2str(cpars.rtp_payload_type) },
1066 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1067 cpars.rtp_sdp_format)),
1068 valueof(ts_SDP_ptime(20)) });
1069
Harald Welte4263c522018-12-06 11:56:27 +01001070/* Complete call, begin with a paging response message via BSSAP */
1071function f_mt_call_complete(inout CallParameters cpars)
1072runs on BSC_ConnHdlr {
Harald Welte33ec09b2018-02-10 15:34:46 +01001073 var MNCC_PDU mncc;
1074 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001075 var template MgcpResponse mgcp_resp;
1076 var MgcpOsmuxCID osmux_cid;
1077 var PDU_BSSAP bssap;
Harald Welte33ec09b2018-02-10 15:34:46 +01001078
Harald Welte6811d102019-04-14 22:23:14 +02001079 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Welte33ec09b2018-02-10 15:34:46 +01001080
Harald Welteb9e86fa2018-04-09 18:18:31 +02001081 f_establish_fully(EST_TYPE_PAG_RESP);
Harald Welte33ec09b2018-02-10 15:34:46 +01001082
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001083 log("f_mt_call_complete 1");
1084
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001085 cpars.got_osmux_count := 0;
1086
Harald Welte33ec09b2018-02-10 15:34:46 +01001087 /* MS <- MSC: Expect CC SETUP */
1088 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_SETUP(cpars.transaction_id, *, cpars.called_party)));
1089
1090 /* MS -> MSC: ALERTING */
1091 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_ALERTING(cpars.transaction_id)));
1092 MNCC.receive(tr_MNCC_ALERT_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001093 log("f_mt_call_complete 2");
Harald Welte33ec09b2018-02-10 15:34:46 +01001094
Harald Welte33ec09b2018-02-10 15:34:46 +01001095 /* Create MGCP expect */
1096 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1097 /* Ask MSC via MNCC to create the RTP socket on the MSC/MGW side */
1098 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1099
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001100 /* First MGCP CRCX */
Harald Welte33ec09b2018-02-10 15:34:46 +01001101 MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001102 log("f_mt_call_complete 3");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001103 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1104 return;
Philipp Maier4b2692d2018-03-14 16:37:48 +01001105 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001106 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001107
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001108
Harald Welte9b751a62019-04-14 17:39:29 +02001109 if (g_pars.ran_is_geran) {
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001110 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass1 :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001111 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001112 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass2 :=
1113 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_2.mgw_rtp_ip, ?);
Harald Welte9b751a62019-04-14 17:39:29 +02001114
1115 interleave {
1116 /* Second MGCP CRCX (this time for MSS/CN side) */
1117 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001118 log("f_mt_call_complete 4");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001119 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1120 break;
1121 }
Harald Welte9b751a62019-04-14 17:39:29 +02001122 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001123
1124 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1125 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1126 log("f_mt_call_complete 5");
1127 }
1128
Harald Welte9b751a62019-04-14 17:39:29 +02001129 /* expect the MSC to trigger a BSSMAP ASSIGNMENT */
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001130 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, (tla_ass1, tla_ass2))) -> value bssap {
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001131 var template BSSMAP_IE_AoIP_TransportLayerAddress tla;
Harald Welte9b751a62019-04-14 17:39:29 +02001132 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001133 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001134 log("f_mt_call_complete 6");
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001135 tla := f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port);
Harald Welte9b751a62019-04-14 17:39:29 +02001136 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
1137
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001138 if (cpars.use_osmux) {
1139 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1140 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1141 mtc.stop;
1142 }
1143 osmuxCID := valueof(ts_OsmuxCID(0));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001144 if (not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1145 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 +02001146 mtc.stop;
1147 }
1148 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1149 } else {
1150 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1151 }
1152 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001153
1154 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
Harald Welte9b751a62019-04-14 17:39:29 +02001155 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001156
1157 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1158 log("f_mt_call_complete 7");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001159 var octetstring ip;
1160 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1161 if (is_ipv6) {
1162 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1163 } else {
1164 ip := f_inet_addr(cpars.mncc_rtp_ip);
1165 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001166 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001167 is_ipv6, ip,
1168 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001169 /* payload type 3 = GSM FR */ 3));
1170 }
1171
1172 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1173 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1174 log("f_mt_call_complete 8");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001175 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 +01001176 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001177 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001178 { int2str(cpars.rtp_payload_type) },
1179 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1180 cpars.rtp_sdp_format)),
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001181 valueof(ts_SDP_ptime(20)) }));
1182 if (cpars.use_osmux) {
1183 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1184 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1185 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1186 mtc.stop;
1187 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001188 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 +02001189 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001190 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 +02001191 }
1192 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001193 }
1194
1195 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1196 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001197 var SDP_Message sdp;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001198 log("f_mt_call_complete 9");
Pau Espin Pedrol956bfd22020-09-10 18:03:08 +02001199
1200 if (isvalue(mgcp_cmd.sdp)) {
1201 sdp := mgcp_cmd.sdp;
1202 if (sdp.media_list[0].media_field.ports.port_number != cpars.mncc_rtp_port) {
1203 setverdict(fail, "Wrong MDCX Connection port received, expected ", cpars.mncc_rtp_port, " and received ", sdp.media_list[0].media_field.ports.port_number)
1204 mtc.stop;
1205 }
1206 if (sdp.connection.conn_addr.addr != cpars.mncc_rtp_ip) {
1207 setverdict(fail, "Wrong MDCX Connection address received, expected ", cpars.mncc_rtp_ip, " and received ", sdp.connection.conn_addr.addr)
1208 mtc.stop;
1209 }
1210 }
1211
1212 sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1213 hex2str(cpars.mgcp_call_id), "42",
1214 cpars.mgw_conn_2.mgw_rtp_port,
1215 { int2str(cpars.rtp_payload_type) },
1216 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1217 cpars.rtp_sdp_format)),
1218 valueof(ts_SDP_ptime(20)) }));
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001219 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 +01001220 }
1221
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001222 }
Harald Welte9b751a62019-04-14 17:39:29 +02001223 } else {
Harald Welte9b751a62019-04-14 17:39:29 +02001224 interleave {
1225 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001226 log("f_mt_call_complete 4.iu");
1227 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1228 break;
Harald Welte9b751a62019-04-14 17:39:29 +02001229 }
Harald Welte9b751a62019-04-14 17:39:29 +02001230 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001231
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001232 /* MSC acknowledges the MNCC_CREATE to the MNCC handler */
1233 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1234 log("f_mt_call_complete 5.iu");
1235 }
1236
1237 [] BSSAP.receive(tr_RANAP_RabAssReq(?)) {
1238 log("f_mt_call_complete 6.iu");
1239 var RAB_SetupOrModifiedList l := {
1240 {
1241 {
1242 id := id_RAB_SetupOrModifiedItem,
1243 criticality := ignore,
1244 value_ := {
1245 rAB_SetupOrModifiedItem := {
1246 rAB_ID := int2bit(23, 8),
1247 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1248 iuTransportAssociation := {
1249 bindingID := '040c0000'O
1250 },
1251 dl_dataVolumes := omit,
1252 iE_Extensions := omit
1253 }
1254 }
1255 }
1256 }
1257 };
1258 BSSAP.send(ts_RANAP_RabAssResp(l));
1259
1260 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT(cpars.transaction_id)));
1261 }
1262
1263 [] MNCC.receive(tr_MNCC_SETUP_cnf(cpars.mncc_callref)) {
1264 log("f_mt_call_complete 7.iu");
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001265 var octetstring ip;
1266 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1267 if (is_ipv6) {
1268 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1269 } else {
1270 ip := f_inet_addr(cpars.mncc_rtp_ip);
1271 }
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001272 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001273 is_ipv6, ip,
1274 cpars.mncc_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001275 /* payload type 3 = GSM FR */ 3));
1276 }
1277
1278 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1279 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1280 log("f_mt_call_complete 8.iu");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001281 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 +01001282 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001283 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr8fe8a902019-11-03 05:51:03 +01001284 { int2str(cpars.rtp_payload_type) },
1285 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1286 cpars.rtp_sdp_format)),
1287 valueof(ts_SDP_ptime(20)) }));
1288 if (cpars.use_osmux) {
1289 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1290 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1291 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1292 mtc.stop;
1293 }
1294 mgcp_resp := ts_MDCX_ACK_osmux(mgcp_cmd.line.trans_id, cpars.mgw_conn_1.mgcp_connection_id, osmux_cid, sdp);
1295 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001296 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 +01001297 }
1298 MGCP.send(mgcp_resp);
1299 }
1300
1301 /* MDCX setting up the CN side remote RTP address received from MNCC CONNECT */
1302 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1303 log("f_mt_call_complete 9.iu");
1304 var SDP_Message sdp := valueof(ts_SDP(cpars.mgw_conn_2.mgw_rtp_ip, cpars.mgw_conn_2.mgw_rtp_ip,
1305 hex2str(cpars.mgcp_call_id), "42",
1306 cpars.mgw_conn_2.mgw_rtp_port,
1307 { int2str(cpars.rtp_payload_type) },
1308 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1309 cpars.rtp_sdp_format)),
1310 valueof(ts_SDP_ptime(20)) }));
1311 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, cpars.mgw_conn_2.mgcp_connection_id, sdp));
1312 }
1313
Harald Welte33ec09b2018-02-10 15:34:46 +01001314 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001315 }
Harald Welte33ec09b2018-02-10 15:34:46 +01001316
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001317 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1318 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1319 } else {
1320 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1321 mtc.stop;
1322 }
1323
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001324 log("f_mt_call_complete DONE");
Harald Welte4263c522018-12-06 11:56:27 +01001325}
1326
Harald Weltee035e3e2019-04-21 17:32:05 +02001327function f_expect_paging(boolean by_tmsi := true)
1328runs on BSC_ConnHdlr {
Harald Welte9b751a62019-04-14 17:39:29 +02001329 if (g_pars.ran_is_geran) {
1330 BSSAP.receive(tr_BSSMAP_Paging(g_pars.imsi));
1331 } else {
Harald Welte62113fc2019-05-09 13:04:02 +02001332 BSSAP.receive(tr_RANAP_Paging(cs_domain, imsi_hex2oct(g_pars.imsi)));
Harald Welte9b751a62019-04-14 17:39:29 +02001333 }
Harald Weltee035e3e2019-04-21 17:32:05 +02001334}
1335
Harald Welte4263c522018-12-06 11:56:27 +01001336function f_mt_call_establish(inout CallParameters cpars)
1337runs on BSC_ConnHdlr {
1338
1339 /* Initiate the call via MNCC */
Oliver Smith97dc91f2023-05-31 13:53:21 +02001340 f_mt_call_initiate(cpars);
Harald Welte4263c522018-12-06 11:56:27 +01001341
1342 /* BSC <- MSC: Expect paging. FIXME: By TMSI or not? */
Harald Welte6811d102019-04-14 22:23:14 +02001343 f_ran_register_imsi(g_pars.imsi, g_pars.tmsi);
Harald Weltee035e3e2019-04-21 17:32:05 +02001344 f_expect_paging()
Harald Welte4263c522018-12-06 11:56:27 +01001345
1346 /* Complete the call via BSSAP */
1347 f_mt_call_complete(cpars);
Harald Welte33ec09b2018-02-10 15:34:46 +01001348
Harald Welte33ec09b2018-02-10 15:34:46 +01001349 setverdict(pass);
1350}
1351
Neels Hofmeyrc47ce852023-03-06 17:16:50 +01001352function f_call_keep_open(inout CallParameters cpars, float open_time := 5.0)
1353runs on BSC_ConnHdlr {
1354 log("Hold the call for some time");
1355
1356 timer T := open_time;
1357 T.start;
1358 alt {
1359 [] MNCC.receive(tr_MNCC_DISC_ind(cpars.mncc_callref));
1360 [] MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
1361 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1362 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
1363 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1364 [] BSSAP.receive(tr_BSSMAP_ClearCommand);
1365 [] BSSAP.receive(tr_BSSMAP_ClearCommandCSFB);
1366 [] BSSAP.receive(tr_RANAP_IuReleaseCommand(?));
1367
1368 [] T.timeout {
1369 log("Call stayed open for ", open_time, " seconds, all is well.")
1370 setverdict(pass);
1371 return;
1372 }
1373 }
1374
1375 setverdict(fail, "An unexpected release event disconnected the active call prematurely");
1376 mtc.stop;
1377}
1378
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001379/* Reply to a received CRCX with an OK (or the reply configured in cpars), using the given parameters.
1380 * Return true when an OK reply was sent, false otherwise.
1381 * Count occurence of Osmux, include Osmux parameters in the reply if necessary. */
1382function f_handle_crcx(inout CallParameters cpars, MgcpCommand mgcp_cmd)
1383runs on BSC_ConnHdlr
1384return boolean {
1385 var CrcxResponse conn := cpars.mgw_conn_1;
1386 if (cpars.got_crcx_count > 0) {
1387 conn := cpars.mgw_conn_2;
1388 }
1389 cpars.got_crcx_count := cpars.got_crcx_count + 1;
1390
1391 var MgcpMessage mgcp_msg := {
1392 command := mgcp_cmd
1393 }
1394 var template MgcpResponse mgcp_resp;
1395 var MgcpOsmuxCID osmux_cid;
1396 var MgcpCallId call_id := f_MgcpCmd_extract_call_id(mgcp_cmd);
1397 if (ispresent(cpars.mgcp_call_id)) {
1398 if (cpars.mgcp_call_id != call_id) {
1399 setverdict(fail, "CRCX contained unexpected call id. Expected:", cpars.mgcp_call_id, " got:", call_id);
1400 mtc.stop;
1401 }
1402 } else {
1403 cpars.mgcp_call_id := call_id;
1404 }
1405
1406 /* When the endpoint contains a wildcard we keep the endpoint
1407 * identifier we have set up in cpars. Otherwise we use the
1408 * endpoint name that the call agent has supplied */
1409 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard) == false) {
1410 cpars.mgcp_ep := mgcp_cmd.line.ep;
1411 }
1412
1413 if (conn.resp == -1) {
1414 /* Reply with error */
1415 var MgcpResponse mgcp_rsp := {
1416 line := {
1417 code := "542",
1418 trans_id := mgcp_cmd.line.trans_id,
1419 string := "FORCED_FAIL"
1420 },
1421 sdp := omit
1422
1423 }
1424 var MgcpParameter mgcp_rsp_param := {
1425 code := "Z",
1426 val := cpars.mgcp_ep
1427 };
1428 mgcp_rsp.params[0] := mgcp_rsp_param;
1429 MGCP.send(mgcp_rsp);
1430 return false;
1431 }
1432
1433 if (conn.resp == 0) {
1434 /* Do not reply at all */
1435 return false;
1436 }
1437
1438 if (conn.resp != 1) {
1439 setverdict(fail, "Unexpected value for cpars.mgw_conn_*.resp, expect -1, 0 or 1");
1440 mtc.stop;
1441 }
1442
1443 var SDP_Message sdp := valueof(ts_SDP(conn.mgw_rtp_ip, conn.mgw_rtp_ip,
1444 hex2str(cpars.mgcp_call_id), "42",
1445 conn.mgw_rtp_port,
1446 { int2str(cpars.rtp_payload_type) },
1447 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1448 cpars.rtp_sdp_format)),
1449 valueof(ts_SDP_ptime(20)) }));
1450
1451 if (f_mgcp_contains_par(mgcp_msg, "X-OSMUX")) {
1452 if (not cpars.use_osmux) {
1453 setverdict(fail, "MSC sent X-Osmux parameter in MGCP, but not expecting any Osmux");
1454 mtc.stop;
1455 }
1456 cpars.got_osmux_count := cpars.got_osmux_count + 1;
1457 /* we expect MSC to use wildcard here, i.e. osmux_cid == -1 */
1458 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1459 log("f_handle_crcx(): got Osmux CID: ", osmux_cid);
1460 if (osmux_cid != -1) {
1461 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != -1");
1462 mtc.stop;
1463 }
1464
1465 osmux_cid := 0;
1466 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, osmux_cid, sdp);
1467 } else {
1468 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, conn.mgcp_connection_id, sdp);
1469 }
1470
1471 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(cpars.mgcp_ep));
1472 MGCP.send(mgcp_resp);
1473 return true;
1474}
1475
1476
1477altstep as_optional_mgcp_crcx(CallParameters cpars) runs on BSC_ConnHdlr {
1478 var MgcpCommand mgcp_cmd;
1479 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
1480 log("as_optional_mgcp_crcx: rx CRCX");
1481 f_handle_crcx(cpars, mgcp_cmd);
1482
1483 /* Without this 'repeat', the as_optional_mgcp_crcx() exits currently waiting interleaves as soon as an
1484 * CRCX is handled. */
1485 repeat;
1486 }
1487}
1488
1489private altstep as_optional_mgcp_mdcx(HostName mgw_rtp_ip, PortNumber mgw_rtp_port) runs on BSC_ConnHdlr {
1490 var MgcpCommand mgcp_cmd;
1491 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1492 log("as_optional_mgcp_mdcx: rx MDCX");
1493 log(mgcp_cmd);
1494 var charstring conn_id;
1495 var charstring rtp_payload_type;
1496 f_mgcp_find_param_entry(mgcp_cmd.params, "I", conn_id);
1497 rtp_payload_type := mgcp_cmd.sdp.media_list[0].media_field.fmts[0];
1498
1499 var SDP_Message sdp := valueof(ts_SDP(mgw_rtp_ip, mgw_rtp_ip,
1500 mgcp_cmd.sdp.origin.session_id, "42",
1501 mgw_rtp_port,
1502 { rtp_payload_type },
1503 { valueof(ts_SDP_ptime(20)) }));
1504 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, str2hex(conn_id), sdp));
1505
1506 /* Without this 'repeat', currently active other interleave and alt series exit as soon as an MDCX is
1507 * handled. */
1508 repeat;
1509 }
1510}
1511
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001512private altstep as_optional_mgcp_dlcx(CallParameters cpars) runs on BSC_ConnHdlr {
1513 var MgcpCommand mgcp_cmd;
1514 var boolean respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1515 [] MGCP.receive(tr_DLCX(?)) -> value mgcp_cmd {
1516 log("as_optional_mgcp_dlcx: rx MGCP DLCX");
1517 if (respond_to_dlcx) {
1518 MGCP.send(ts_DLCX_ACK2(mgcp_cmd.line.trans_id));
1519 }
1520 /* Without this 'repeat', currently active other interleave and alt series exit as soon as a
1521 * DLCX is handled. */
1522 repeat;
1523 }
1524}
1525
Philipp Maier3716a5e2018-03-21 15:53:35 +01001526function f_mo_call_establish(inout CallParameters cpars)
Harald Welteb71901a2018-01-26 19:16:05 +01001527runs on BSC_ConnHdlr {
1528
Harald Welteb71901a2018-01-26 19:16:05 +01001529 var MNCC_PDU mncc;
1530 var MgcpCommand mgcp_cmd;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001531 var template MgcpResponse mgcp_resp;
Philipp Maier2a98a732018-03-19 16:06:12 +01001532 var boolean respond_to_dlcx;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001533 var PDU_BSSAP bssap;
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001534 var RANAP_PDU ranap;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001535 var MgcpOsmuxCID osmux_cid;
Harald Welteb71901a2018-01-26 19:16:05 +01001536
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001537 cpars.mo_call := true;
1538
Harald Welte0bef21e2018-02-10 09:48:23 +01001539 if (cpars.emergency) {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001540 f_establish_fully(EST_TYPE_EMERG_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001541 } else {
Harald Welteb9e86fa2018-04-09 18:18:31 +02001542 f_establish_fully(EST_TYPE_MO_CALL);
Harald Welte0bef21e2018-02-10 09:48:23 +01001543 }
Harald Welteb71901a2018-01-26 19:16:05 +01001544
1545 /* Create MNCC and MGCP expect */
1546 f_create_mncc_expect(hex2str(cpars.called_party));
1547 f_create_mgcp_expect(ExpectCriteria:{omit,omit,omit});
1548
Harald Welte0bef21e2018-02-10 09:48:23 +01001549 if (cpars.emergency) {
1550 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_EMERG_SETUP(cpars.transaction_id)));
1551 } else {
1552 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_SETUP(cpars.transaction_id, cpars.called_party)));
1553 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001554
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001555 if (cpars.stop_after_cc_setup) {
1556 return;
1557 }
1558
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001559 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass1 :=
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001560 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_1.mgw_rtp_ip, ?);
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001561 var template BSSMAP_IE_AoIP_TransportLayerAddress tla_ass2 :=
1562 f_tr_BSSMAP_IE_AoIP_TLA(cpars.mgw_conn_2.mgw_rtp_ip, ?);
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001563
1564 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 +01001565 var boolean got_mncc_setup_compl_ind := false;
1566 var boolean got_cc_connect := false;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001567
Harald Welteb71901a2018-01-26 19:16:05 +01001568 interleave {
1569 [] MNCC.receive(tr_MNCC_SETUP_ind(?, tr_MNCC_number(hex2str(cpars.called_party)))) -> value mncc {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001570 log("f_mo_call_establish 1: rx MNCC SETUP ind");
Harald Welteb71901a2018-01-26 19:16:05 +01001571 cpars.mncc_callref := mncc.u.signal.callref;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001572 MNCC.send(ts_MNCC_RTP_CREATE(cpars.mncc_callref));
1573 }
1574
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001575 /* First MGCP CRCX */
Harald Welteb71901a2018-01-26 19:16:05 +01001576 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001577 log("f_mo_call_establish 2: rx 1st CRCX");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001578 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1579 break;
1580 }
Philipp Maierf1e02bb2018-03-15 16:30:00 +01001581 }
1582
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001583 /* Second MGCP CRCX */
1584 [] MGCP.receive(tr_CRCX(cpars.mgcp_ep)) -> value mgcp_cmd {
1585 log("f_mo_call_establish 6: rx 2nd CRCX");
1586 if (not f_handle_crcx(cpars, mgcp_cmd)) {
1587 break;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001588 }
Harald Welteb71901a2018-01-26 19:16:05 +01001589 }
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001590
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001591 [] MNCC.receive(tr_MNCC_RTP_CREATE(cpars.mncc_callref)) {
1592 log("f_mo_call_establish 3: rx RTP CREATE");
1593 /* Call Proceeding */
1594 MNCC.send(ts_MNCC_CALL_PROC_req(cpars.mncc_callref, cpars.mncc_bearer_cap));
1595 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CALL_PROC(cpars.transaction_id)));
Harald Welteb71901a2018-01-26 19:16:05 +01001596
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001597 /* Alerting */
1598 MNCC.send(ts_MNCC_ALERT_req(cpars.mncc_callref));
Neels Hofmeyr59e0c6f2019-03-06 15:21:20 +01001599 }
Harald Welte9b751a62019-04-14 17:39:29 +02001600
Neels Hofmeyreccaa992019-10-15 16:42:21 +02001601 //[g_pars.ran_is_geran] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit, tla_ass)) -> value bssap
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001602 [] BSSAP.receive(tr_BSSMAP_AssignmentReq(omit)) -> value bssap {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001603 log("f_mo_call_establish 4: rx Assignment Request");
1604 var BSSMAP_IE_AoIP_TransportLayerAddress tla;
1605 var BSSMAP_IE_SpeechCodec codec;
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001606 var BSSMAP_IE_Osmo_OsmuxCID osmuxCID;
1607
Neels Hofmeyr02d513e2022-07-25 22:07:24 +02001608 if (not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass1)
1609 and not match(bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer, tla_ass2)) {
1610 log("Expected one of: 1:", tla_ass1, " 2:", tla_ass2);
Neels Hofmeyrd9d835d2019-09-17 18:19:08 +02001611 log("Got:", bssap.pdu.bssmap.assignmentRequest.aoIPTransportLayer);
1612 setverdict(fail, "MSC sent Assignment Request with unexpected AoIP Transport Layer IE");
1613 mtc.stop;
1614 }
1615
Pau Espin Pedrol833174e2020-09-03 16:46:02 +02001616 tla := valueof(f_ts_BSSMAP_IE_AoIP_TLA(cpars.bss_rtp_ip, cpars.bss_rtp_port));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001617 codec := valueof(ts_BSSMAP_IE_SpeechCodec({ts_CodecFR}));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001618 if (cpars.use_osmux) {
1619 if (not ispresent(bssap.pdu.bssmap.assignmentRequest.osmuxCID)) {
1620 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1621 mtc.stop;
1622 }
1623 osmuxCID := valueof(ts_OsmuxCID(0));
1624 if (cpars.use_osmux and not match(bssap.pdu.bssmap.assignmentRequest.osmuxCID, osmuxCID)) {
1625 setverdict(fail, "MSC sent AssignReq without expected OsmuxCID IE");
1626 mtc.stop;
1627 }
1628 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec, osmuxCID));
1629 } else {
1630 bssap := valueof(ts_BSSMAP_AssignmentComplete(omit, tla, codec));
1631 }
1632 BSSAP.send(bssap);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001633 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001634 [] BSSAP.receive(tr_RANAP_RabAssReq(*)) -> value ranap {
1635 log("f_mo_call_establish 4.iu: rx RANAP RAB Assignment Request");
1636 var RAB_SetupOrModifiedList l := {
1637 {
1638 {
1639 id := id_RAB_SetupOrModifiedItem,
1640 criticality := ignore,
1641 value_ := {
1642 rAB_SetupOrModifiedItem := {
1643 rAB_ID := int2bit(23, 8),
1644 transportLayerAddress := hex2bit( '350001c0a8021500000000000000000000000000'H),
1645 iuTransportAssociation := {
1646 bindingID := '040c0000'O
1647 },
1648 dl_dataVolumes := omit,
1649 iE_Extensions := omit
1650 }
1651 }
1652 }
1653 }
1654 };
1655 BSSAP.send(ts_RANAP_RabAssResp(l));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001656 }
Harald Welte9b751a62019-04-14 17:39:29 +02001657
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001658 /* MDCX setting up the RAN side remote RTP address received from Assignment Complete */
1659 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
1660 log("f_mo_call_establish 5: rx MDCX for the RAN side");
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001661 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 +01001662 hex2str(cpars.mgcp_call_id), "42",
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001663 cpars.mgw_conn_1.mgw_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001664 { int2str(cpars.rtp_payload_type) },
1665 { valueof(ts_SDP_rtpmap(cpars.rtp_payload_type,
1666 cpars.rtp_sdp_format)),
1667 valueof(ts_SDP_ptime(20)) }));
Pau Espin Pedrola65697d2019-05-21 12:54:39 +02001668
1669 if (cpars.use_osmux) {
1670 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
1671 if (osmux_cid != 0) { /* we expect MSC to use specific CID here */
1672 setverdict(fail, "MSC using unexpected CID " & int2str(osmux_cid) & " != 0");
1673 mtc.stop;
1674 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001675 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 +02001676 } else {
Pau Espin Pedrolcb4c59d2020-09-03 20:55:57 +02001677 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 +02001678 }
1679 MGCP.send(mgcp_resp);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001680 }
Harald Welte9b751a62019-04-14 17:39:29 +02001681
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001682 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_ALERTING(cpars.transaction_id))) {
1683 log("f_mo_call_establish 7: rx CC Alerting");
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001684
1685 if (cpars.ran_clear_when_alerting) {
1686 if (g_pars.ran_is_geran) {
1687 BSSAP.send(ts_BSSMAP_ClearRequest(0));
1688 } else {
1689 BSSAP.send(ts_RANAP_IuReleaseRequest(ts_RanapCause_om_intervention));
1690 }
1691 break;
1692 }
1693
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001694 cpars.mncc_callref := mncc.u.signal.callref;
1695 /* Call Proceeding */
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001696 var octetstring ip;
1697 var boolean is_ipv6 := f_addr_is_ipv6(cpars.mncc_rtp_ip);
1698 if (is_ipv6) {
1699 ip := f_inet6_addr(cpars.mncc_rtp_ip);
1700 } else {
1701 ip := f_inet_addr(cpars.mncc_rtp_ip);
1702 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001703 MNCC.send(ts_MNCC_RTP_CONNECT(cpars.mncc_callref,
Pau Espin Pedrol563b3d02020-09-09 20:19:52 +02001704 is_ipv6, ip,
1705 cpars.mncc_rtp_port,
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001706 /* payload type 3 = GSM FR */ 3));
1707 MNCC.send(ts_MNCC_SETUP_rsp(cpars.mncc_callref));
1708 }
1709
1710 [] MNCC.receive(tr_MNCC_SETUP_COMPL_ind(?)) -> value mncc {
1711 log("f_mo_call_establish 8: rx MNCC SETUP COMPLETE ind");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001712 got_mncc_setup_compl_ind := true;
1713 if (not cpars.expect_release and got_cc_connect) {
1714 break;
1715 }
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001716 }
1717
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001718 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_CONNECT(cpars.transaction_id))) {
1719 log("f_mo_call_establish 10: rx CC CONNECT");
1720 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_CONNECT_ACK(cpars.transaction_id)));
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001721 got_cc_connect := true;
1722 if (not cpars.expect_release and got_mncc_setup_compl_ind) {
1723 break;
1724 }
Harald Welteb71901a2018-01-26 19:16:05 +01001725 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001726
1727 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id))) {
1728 log("f_mo_call_establish 11: rx CC RELEASE");
Neels Hofmeyr8df69622019-11-02 19:16:03 +01001729 if (not cpars.expect_release) {
1730 setverdict(fail, "Got unexpected CC Release");
1731 mtc.stop;
1732 }
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001733 f_expect_clear();
1734 break;
1735 }
1736 }
1737
1738 f_sleep(0.5);
1739 deactivate(mdcx);
1740
1741 if (cpars.use_osmux == (cpars.got_osmux_count != 0)) {
1742 log("Osmux ok: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1743 } else {
1744 setverdict(fail, "Osmux failure: use_osmux = ", cpars.use_osmux, " got_osmux_count = ", cpars.got_osmux_count);
1745 mtc.stop;
Harald Welteb71901a2018-01-26 19:16:05 +01001746 }
1747
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001748 log("f_mo_call_establish DONE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001749 setverdict(pass);
1750}
Harald Welteb71901a2018-01-26 19:16:05 +01001751
Harald Welte4c422b72019-02-17 16:27:10 +01001752function f_call_hangup(inout CallParameters cpars, boolean release_by_ms, boolean is_csfb := false)
Philipp Maier3716a5e2018-03-21 15:53:35 +01001753runs on BSC_ConnHdlr {
1754
1755 var MobileIdentityLV mi;
1756 var MNCC_PDU mncc;
1757 var MgcpCommand mgcp_cmd;
1758 var boolean respond_to_dlcx;
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001759 var boolean dlcx_contained_ci := false;
1760 var template PDU_BSSAP t_clear := tr_BSSMAP_ClearCommand;
1761
1762 if (is_csfb) {
1763 t_clear := tr_BSSMAP_ClearCommandCSFB;
1764 }
1765
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001766 log("f_call_hangup 0: tx MNCC_DISC_REQ");
Harald Welteb71901a2018-01-26 19:16:05 +01001767 MNCC.send(ts_MNCC_DISC_req(cpars.mncc_callref, valueof(ts_MNCC_cause(23))));
1768 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_DISC(cpars.transaction_id)));
1769
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001770 log("f_call_hangup 1: rx DTAP CC DISC");
1771
Philipp Maier3716a5e2018-03-21 15:53:35 +01001772 if (release_by_ms) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001773 var BIT1 tid_remote := '1'B;
1774 if (cpars.mo_call) {
1775 tid_remote := '0'B;
1776 }
Philipp Maier3716a5e2018-03-21 15:53:35 +01001777 /* B-side (MS) Release of call */
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001778 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 +01001779 MNCC.receive(tr_MNCC_REL_ind(cpars.mncc_callref));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001780 log("f_call_hangup 2: rx MNCC REL ind");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001781 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_REL_COMPL(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001782 log("f_call_hangup 3: rx DTAP CC REL COMPL");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001783 } else {
1784 /* A-side (PLMN) Release of call */
1785 MNCC.send(ts_MNCC_REL_req(cpars.mncc_callref, valueof(ts_MNCC_cause(42))));
1786 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_CC_RELEASE(cpars.transaction_id)));
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001787 log("f_call_hangup 4: rx DTAP CC RELEASE");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001788 BSSAP.send(ts_PDU_DTAP_MO(ts_ML3_MO_CC_REL_COMPL(cpars.transaction_id)));
1789 }
Harald Welteb71901a2018-01-26 19:16:05 +01001790
Philipp Maier2a98a732018-03-19 16:06:12 +01001791 respond_to_dlcx := not (isbound(cpars.mgw_drop_dlcx) and valueof(cpars.mgw_drop_dlcx));
1792
Neels Hofmeyr3c89a6b2019-10-15 16:54:37 +02001793 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 +01001794 var default dlcx := activate(as_optional_mgcp_dlcx(cpars));
Harald Welte9b751a62019-04-14 17:39:29 +02001795
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001796 /* clearing of radio channel */
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001797 alt {
1798 [g_pars.ran_is_geran] BSSAP.receive(t_clear) {
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001799 log("f_call_hangup 5: rx BSSAP Clear Command");
1800 BSSAP.send(ts_BSSMAP_ClearComplete);
1801 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
1802 log("f_call_hangup 6: rx SCCP DISC");
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001803 setverdict(pass);
Philipp Maier2a98a732018-03-19 16:06:12 +01001804 }
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001805 [not g_pars.ran_is_geran] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) {
1806 log("f_call_hangup 5.iu: rx Iu Release Command");
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001807 BSSAP.send(ts_RANAP_IuReleaseComplete);
1808 BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001809 log("f_call_hangup 6.iu: rx SCCP DISC");
1810 setverdict(pass);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001811 }
1812 }
1813
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001814 f_sleep(1.0);
Neels Hofmeyr2ca1ab42019-03-08 03:45:43 +01001815 f_create_mgcp_delete_ep(cpars.mgcp_ep);
1816 log("f_call_hangup 9: done");
1817
1818 deactivate(mdcx);
Neels Hofmeyr0b16bf12019-11-03 05:10:12 +01001819 deactivate(dlcx);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001820}
1821
1822function f_mt_call(inout CallParameters cpars)
1823runs on BSC_ConnHdlr {
1824
1825 f_mt_call_establish(cpars);
1826
Neels Hofmeyrc47ce852023-03-06 17:16:50 +01001827 f_call_keep_open(cpars);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001828
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001829 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001830 f_call_hangup(cpars, true);
1831
1832 setverdict(pass);
1833}
1834
1835function f_mo_call(inout CallParameters cpars)
1836runs on BSC_ConnHdlr {
1837
1838 f_mo_call_establish(cpars);
1839
Neels Hofmeyrc47ce852023-03-06 17:16:50 +01001840 f_call_keep_open(cpars);
Philipp Maier3716a5e2018-03-21 15:53:35 +01001841
Neels Hofmeyrba960a12019-11-02 19:17:38 +01001842 log("Hangup");
Philipp Maier3716a5e2018-03-21 15:53:35 +01001843 f_call_hangup(cpars, false);
1844
Harald Welteb71901a2018-01-26 19:16:05 +01001845 setverdict(pass);
1846}
Harald Weltea49e36e2018-01-21 19:29:33 +01001847
Daniel Willmann8b084372018-02-04 13:35:26 +01001848function f_mo_seq_dtmf_dup(inout CallParameters cpars)
1849runs on BSC_ConnHdlr {
1850
1851 timer T := 1.0;
Daniel Willmann8b084372018-02-04 13:35:26 +01001852 var MNCC_PDU mncc;
1853 var MgcpCommand mgcp_cmd;
1854 var template PDU_ML3_MS_NW dtmf_dtap;
1855
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001856 f_mo_call_establish(cpars);
Daniel Willmann8b084372018-02-04 13:35:26 +01001857
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001858 /* Send DTMF: send the exact same DTAP message twice, the dup should be filtered out by
1859 * 3GPP TS 24.007 11.2.3.2 Message Type Octet / Duplicate Detection. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001860
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001861 /* Find out the next NSD that will be used, from RAN emulation. */
1862 var N_Sd_Array last_n_sd := f_bssmap_last_n_sd();
1863 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 +01001864
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001865 /* Compose DTAP with this correct NSD */
Daniel Willmann8b084372018-02-04 13:35:26 +01001866 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "2");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001867
1868 /* Here, pass skip_seq_patching == false so that the RAN Emulation NSD increments after this message. */
1869 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001870 T.start;
1871 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001872 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
1873 log("f_mo_seq_dtmf_dup() 1: got first START_DTMF_ind");
1874 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001875 [] T.timeout {
1876 setverdict(fail, "Timeout waiting for START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001877 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001878 }
1879 }
1880
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001881 /* Send the exact same DTAP with above NSD, which is now incorrect (has not incremented), so that this message
1882 * will get filtered by the duplicate detection. Write NSD into DTAP and pass skip_seq_patching == true. */
1883 dtmf_dtap.msgs.cc.startDTMF.nsd := int2bit(next_n_sd, 2);
Daniel Willmann92f66272018-02-06 15:50:52 +01001884 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, true));
Daniel Willmann8b084372018-02-04 13:35:26 +01001885 T.start;
1886 alt {
1887 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "2")) {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001888 setverdict(fail, "f_mo_seq_dtmf_dup() 2: Received duplicate START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001889 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001890 }
1891 [] T.timeout { }
1892 }
1893
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001894 /* Here the NSD should be correct again and we see a DTMF. */
Daniel Willmann8b084372018-02-04 13:35:26 +01001895 dtmf_dtap := ts_ML3_MO_CC_START_DTMF(cpars.transaction_id, "3");
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001896 BSSAP.send(ts_PDU_DTAP_MO(dtmf_dtap, '00'O, false));
Daniel Willmann8b084372018-02-04 13:35:26 +01001897 alt {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001898 [] MNCC.receive(tr_MNCC_START_DTMF_ind(cpars.mncc_callref, "3")) {
1899 log("f_mo_seq_dtmf_dup() 3: got second START_DTMF_ind");
1900 }
Daniel Willmann8b084372018-02-04 13:35:26 +01001901 [] T.timeout {
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001902 setverdict(fail, "Timeout waiting for final START_DTMF_ind");
Daniel Willmannafce8662018-07-06 23:11:32 +02001903 mtc.stop;
Daniel Willmann8b084372018-02-04 13:35:26 +01001904 }
1905 }
1906
Neels Hofmeyr3d22e4a2019-10-03 04:07:47 +02001907 f_call_hangup(cpars, true);
Daniel Willmann8b084372018-02-04 13:35:26 +01001908 setverdict(pass);
1909}
Harald Welte9b751a62019-04-14 17:39:29 +02001910
Harald Welte1ddc7162018-01-27 14:25:46 +01001911/* expect a clear command */
Harald Welte5946b332018-03-18 23:32:21 +01001912altstep as_clear_cmd_compl_disc(float t := 5.0) runs on BSC_ConnHdlr {
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001913 var PDU_BSSAP bssap;
Harald Welte5946b332018-03-18 23:32:21 +01001914 [] BSSAP.receive(tr_BSSMAP_ClearCommand) {
1915 BSSAP.send(ts_BSSMAP_ClearComplete);
1916 alt {
Harald Welte6811d102019-04-14 22:23:14 +02001917 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
Harald Welte5946b332018-03-18 23:32:21 +01001918 setverdict(pass);
1919 }
1920 [] BSSAP.receive {
1921 setverdict(fail, "Unexpected BSSMAP while waiting for SCCP Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001922 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001923 }
1924 }
1925 }
Neels Hofmeyr6b468a42019-03-06 15:25:14 +01001926 [] BSSAP.receive(tr_BSSAP_BSSMAP) -> value bssap {
1927 setverdict(fail, "Unexpected BSSMAP while waiting for ClearCommand", bssap);
Daniel Willmannafce8662018-07-06 23:11:32 +02001928 mtc.stop;
Harald Welte5946b332018-03-18 23:32:21 +01001929 }
1930}
1931
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001932function f_expect_clear(float t := 5.0, boolean verify_vlr_cell_id := true) runs on BSC_ConnHdlr {
Harald Welte1ddc7162018-01-27 14:25:46 +01001933 timer T := t;
1934
1935 T.start;
1936 alt {
Harald Welte9b751a62019-04-14 17:39:29 +02001937 [g_pars.ran_is_geran] as_clear_cmd_compl_disc(t) { }
1938 [not g_pars.ran_is_geran] as_iu_release_compl_disc(t) { }
Harald Welte1ddc7162018-01-27 14:25:46 +01001939 [] T.timeout {
Harald Welte5946b332018-03-18 23:32:21 +01001940 setverdict(fail, "Timeout waiting for ClearCommand/Release");
Daniel Willmannafce8662018-07-06 23:11:32 +02001941 mtc.stop;
Harald Welte1ddc7162018-01-27 14:25:46 +01001942 }
1943 }
Neels Hofmeyr4e18ccc2020-06-24 19:08:17 +02001944
1945 if (verify_vlr_cell_id) {
1946 /* Now the conn is gone, but the VLR reflects the cell ID */
1947 f_verify_vty_lac_ci();
1948 }
Harald Welte1ddc7162018-01-27 14:25:46 +01001949}
1950
Neels Hofmeyr0ac63152019-05-07 01:20:17 +02001951function f_create_bssmap_exp_handoverRequest(integer targetPointCode) runs on BSC_ConnHdlr {
1952 BSSAP_PROC.call(RAN_register_handoverRequest:{targetPointCode, self}) {
1953 [] BSSAP_PROC.getreply(RAN_register_handoverRequest:{?, ?}) {};
1954 }
1955}
1956
1957function f_bssmap_last_n_sd() runs on BSC_ConnHdlr return N_Sd_Array {
1958 var N_Sd_Array last_n_sd;
1959 BSSAP_PROC.call(RAN_last_n_sd:{self, -}) {
1960 [] BSSAP_PROC.getreply(RAN_last_n_sd:{self, ?}) -> param(last_n_sd) {
1961 return last_n_sd;
1962 };
1963 }
1964}
1965
1966function f_bssmap_continue_after_n_sd(N_Sd_Array last_n_sd) runs on BSC_ConnHdlr {
1967 BSSAP_PROC.call(RAN_continue_after_n_sd:{last_n_sd, self}) {
1968 [] BSSAP_PROC.getreply(RAN_continue_after_n_sd:{last_n_sd, self});
1969 }
1970}
1971
Harald Weltef45efeb2018-04-09 18:19:24 +02001972type record SmsParametersTp {
1973 OCT1 msg_ref,
1974 TP_DA da,
1975 OCT1 pid,
1976 OCT1 dcs,
1977 integer udl,
1978 octetstring ud
1979}
1980type record SmsParametersRp {
1981 OCT1 msg_ref,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09001982 RP_NumberingPlan_and_NumberDigits smsc_addr optional
Harald Weltef45efeb2018-04-09 18:19:24 +02001983}
1984type record SmsParameters {
1985 SmsParametersTp tp,
1986 SmsParametersRp rp,
1987 uint3_t tid,
1988 OCT1 dlci,
1989 uint7_t exp_rp_err optional
1990}
1991
1992template (value) TP_DA ts_TP_DA(BIT4 npl, BIT3 ton, hexstring addr) := {
1993 tP_DA_NoPad := {
1994 tP_LengthIndicator := 0, /* overwritten */
1995 tP_NumberingPlanID := npl,
1996 tP_TypeOfNumber := ton,
1997 tp_Spare := '0'B,
1998 tP_DAValue := addr
1999 }
2000}
2001
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002002template RP_NumberingPlan_and_NumberDigits t_RP_Addr(template hexstring addr,
2003 template BIT4 npi := '0001'B,
2004 template BIT3 ton := '001'B,
2005 template BIT1 ext := '1'B) := {
2006 rP_NumberingPlanIdentification := npi,
2007 rP_TypeOfNumber := ton,
2008 rP_Ext := ext,
2009 rP_NumberDigits := addr
2010}
2011
Harald Weltef45efeb2018-04-09 18:19:24 +02002012template (value) SmsParameters t_SmsPars(hexstring tp_daddr := '12345'H) := {
2013 tp := {
2014 msg_ref := '23'O,
2015 da := ts_TP_DA('0000'B, '000'B, tp_daddr),
2016 pid := '00'O,
2017 dcs := '00'O,
2018 udl := 0,
2019 ud := ''O
2020 },
2021 rp := {
2022 msg_ref := '42'O,
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002023 /* We don't really need to have both SM-RP-DA/OA here, because only one IE
Vadim Yanitskiyafb15a82020-01-05 14:04:53 +01002024 * is included in MO/MT SMS, and in the most cases it's the SMSC address.
2025 * NOTE: this address is currently hard-coded by OsmoMSC. */
2026 smsc_addr := t_RP_Addr('447785016005'H)
Harald Weltef45efeb2018-04-09 18:19:24 +02002027 },
2028 tid := 0,
2029 dlci := '03'O,
2030 exp_rp_err := omit
2031}
2032
2033private altstep as_other_sms() runs on BSC_ConnHdlr {
2034 [] BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(?, ?, ?), ?)) {
2035 setverdict(fail, "Unexpected SMS related PDU from MSC");
Daniel Willmannafce8662018-07-06 23:11:32 +02002036 mtc.stop;
Harald Weltef45efeb2018-04-09 18:19:24 +02002037 }
2038}
2039
Vadim Yanitskiy9cc019a2018-11-15 02:06:07 +07002040/* Submit a MO RP-SMMA over an already existing DTAP connection */
2041function f_mo_smma(inout SmsParameters spars)
2042runs on BSC_ConnHdlr {
2043 var template (value) RPDU_MS_SGSN rp_mo;
2044 var template (value) PDU_ML3_MS_NW l3_mo;
2045
2046 var default d := activate(as_other_sms());
2047
2048 /* just in case this is routed to SMPP.. */
2049 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2050
2051 rp_mo := ts_RP_SMMA_MO(spars.rp.msg_ref);
2052 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
2053 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2054 /* receive CP-ACK for CP-DATA above */
2055 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
2056
2057 deactivate(d);
2058 setverdict(pass);
2059}
2060
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002061/* Submit a MO-SMS over an already existing DTAP connection */
2062function f_mo_sms_submit(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02002063runs on BSC_ConnHdlr {
2064 var template (value) TPDU_RP_DATA_MS_SGSN tp_mo;
2065 var template (value) RPDU_MS_SGSN rp_mo;
2066 var template (value) PDU_ML3_MS_NW l3_mo;
2067
Harald Weltef45efeb2018-04-09 18:19:24 +02002068 var default d := activate(as_other_sms());
2069
Harald Weltef640a012018-04-14 17:49:21 +02002070 /* just in case this is routed to SMPP.. */
2071 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2072
Harald Weltef45efeb2018-04-09 18:19:24 +02002073 tp_mo := ts_SMS_SUBMIT(spars.tp.msg_ref, spars.tp.da, spars.tp.pid, spars.tp.dcs,
2074 spars.tp.udl, spars.tp.ud);
Vadim Yanitskiy437b5a62019-12-15 14:13:39 +09002075 rp_mo := ts_RP_DATA_MO(spars.rp.msg_ref, omit, spars.rp.smsc_addr, tp_mo);
Harald Weltef45efeb2018-04-09 18:19:24 +02002076 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_DATA_MO(rp_mo));
2077 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2078 /* receive CP-ACK for CP-DATA above */
2079 BSSAP.receive(tr_PDU_DTAP_MT(tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_ACK_MT), spars.dlci));
2080
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002081 deactivate(d);
2082 setverdict(pass);
2083}
2084
2085/* Wait RP-ACK for MO-SMS on an already existing DTAP connection */
2086function f_mo_sms_wait_rp_ack(inout SmsParameters spars)
2087runs on BSC_ConnHdlr {
2088 var template (value) PDU_ML3_MS_NW l3_mo;
2089
2090 var template TPDU_RP_DATA_SGSN_MS tp_mt;
2091 var template RPDU_SGSN_MS rp_mt;
2092 var template PDU_ML3_NW_MS l3_mt;
2093
2094 var default d := activate(as_other_sms());
2095
2096 /* just in case this is routed to SMPP.. */
2097 f_create_smpp_expect(hex2str(spars.tp.da.tP_DA_NoPad.tP_DAValue));
2098
Harald Weltef45efeb2018-04-09 18:19:24 +02002099 if (ispresent(spars.exp_rp_err)) {
2100 /* expect an RP-ERROR message from MSC with given cause */
2101 rp_mt := tr_RP_ERROR_MT(spars.rp.msg_ref, spars.exp_rp_err);
2102 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
2103 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2104 /* send CP-ACK for CP-DATA just received */
2105 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
2106 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2107 } else {
2108 /* expect RP-ACK for RP-DATA */
2109 rp_mt := tr_RP_ACK_MT(spars.rp.msg_ref);
2110 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_REPL, tr_CP_DATA_MT(rp_mt));
2111 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2112 /* send CP-ACO for CP-DATA just received */
2113 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_ORIG, ts_CP_ACK_MO);
2114 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2115 }
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002116
Harald Weltef45efeb2018-04-09 18:19:24 +02002117 deactivate(d);
2118 setverdict(pass);
2119}
2120
Vadim Yanitskiyd4cc1502018-11-12 01:46:21 +07002121/* Submit a MO-SMS, and wait for RP-ACK on an existing
2122 * (and authenticated, ...) DTAP connection */
2123function f_mo_sms(inout SmsParameters spars)
2124runs on BSC_ConnHdlr {
2125 f_mo_sms_submit(spars);
2126 f_mo_sms_wait_rp_ack(spars);
2127}
2128
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002129function f_mt_sms_deliver_pdu(in SmsParameters spars)
2130runs on BSC_ConnHdlr
2131return template PDU_DTAP_MT {
2132 var template TPDU_RP_DATA_SGSN_MS tp_mt := tr_SMS_DELIVER(?, spars.tp.ud, spars.tp.pid, spars.tp.dcs, ?);
2133 var template RPDU_SGSN_MS rp_mt := tr_RP_DATA_MT(?, spars.rp.smsc_addr, omit, tp_mt);
2134 var template PDU_ML3_NW_MS l3_mt := tr_ML3_MT_SMS(?, c_TIF_ORIG, tr_CP_DATA_MT(rp_mt));
2135 return tr_PDU_DTAP_MT(l3_mt, spars.dlci);
2136}
2137
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002138/* Wait for MT SMS on an already existing DTAP connection */
2139function f_mt_sms_expect(inout SmsParameters spars)
Harald Weltef45efeb2018-04-09 18:19:24 +02002140runs on BSC_ConnHdlr {
Harald Weltef45efeb2018-04-09 18:19:24 +02002141 var template (value) PDU_ML3_MS_NW l3_mo;
Harald Weltef45efeb2018-04-09 18:19:24 +02002142 var PDU_DTAP_MT dtap_mt;
2143
2144 var default d := activate(as_other_sms());
2145
2146 /* Expect CP-DATA(RP-DATA(SMS-DELIVER)) */
Neels Hofmeyrb58d9742019-11-27 18:44:54 +01002147 BSSAP.receive(f_mt_sms_deliver_pdu(spars)) -> value dtap_mt;
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002148
Harald Weltef45efeb2018-04-09 18:19:24 +02002149 /* Extract relevant identifiers */
2150 spars.tid := bit2int(dtap_mt.dtap.tiOrSkip.transactionId.tio);
2151 spars.rp.msg_ref := dtap_mt.dtap.msgs.sms.cP_DATA.cP_User_Data.cP_RPDU.rP_DATA_SGSN_MS.rP_MessageReference;
2152
2153 /* send CP-ACK for CP-DATA just received */
2154 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_ACK_MO);
2155 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2156
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002157 deactivate(d);
2158 setverdict(pass);
2159}
2160
2161/* Send RP-ACK for MT-SMS over an already existing DTAP connection */
2162function f_mt_sms_send_rp_ack(inout SmsParameters spars)
2163runs on BSC_ConnHdlr {
2164 var template (value) RPDU_MS_SGSN rp_mo;
2165 var template (value) PDU_ML3_MS_NW l3_mo;
2166 var template PDU_ML3_NW_MS l3_mt;
2167
2168 var default d := activate(as_other_sms());
2169
Harald Weltef45efeb2018-04-09 18:19:24 +02002170 /* send RP-ACK for RP-DATA */
2171 rp_mo := ts_RP_ACK_MO(spars.rp.msg_ref);
2172 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2173 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2174
2175 /* expect CP-ACK for CP-DATA(RP-ACK) just sent */
Harald Weltee008eea2018-04-14 21:05:48 +02002176 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
Harald Weltef45efeb2018-04-09 18:19:24 +02002177 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2178
2179 deactivate(d);
2180 setverdict(pass);
2181}
2182
Vadim Yanitskiy56318522018-11-24 03:40:47 +07002183/* Send RP-ERROR for MT-SMS over an already existing DTAP connection */
2184function f_mt_sms_send_rp_error(inout SmsParameters spars, uint7_t cause)
2185runs on BSC_ConnHdlr {
2186 var template (value) RPDU_MS_SGSN rp_mo;
2187 var template (value) PDU_ML3_MS_NW l3_mo;
2188 var template PDU_ML3_NW_MS l3_mt;
2189
2190 var default d := activate(as_other_sms());
2191
2192 /* send RP-ACK for RP-DATA */
2193 rp_mo := ts_RP_ERROR_MO(spars.rp.msg_ref, cause);
2194 l3_mo := ts_ML3_MO_SMS(spars.tid, c_TIF_REPL, ts_CP_DATA_MO(rp_mo));
2195 BSSAP.send(ts_PDU_DTAP_MO(l3_mo, spars.dlci, true));
2196
2197 /* expect CP-ACK for CP-DATA(RP-ERROR) just sent */
2198 l3_mt := tr_ML3_MT_SMS(spars.tid, c_TIF_ORIG, tr_CP_ACK_MT);
2199 BSSAP.receive(tr_PDU_DTAP_MT(l3_mt, spars.dlci));
2200
2201 deactivate(d);
2202 setverdict(pass);
2203}
2204
Vadim Yanitskiy2159acb2018-11-24 02:50:29 +07002205/* Wait for a MT-SMS and send RP-ACK over an already existing
2206 * (and authenticated, ...) DTAP connection */
2207function f_mt_sms(inout SmsParameters spars)
2208runs on BSC_ConnHdlr {
2209 f_mt_sms_expect(spars);
2210 f_mt_sms_send_rp_ack(spars);
2211}
Harald Weltea49e36e2018-01-21 19:29:33 +01002212
2213
Harald Weltea49e36e2018-01-21 19:29:33 +01002214}