blob: dd044e0b047084ee0274849a89c137f2c56f2641 [file] [log] [blame]
Harald Welte28d943e2017-11-25 15:00:50 +01001module MSC_ConnectionHandler {
2
Harald Welte34b5a952019-05-27 11:54:11 +02003/* MSC Connection HAndler of BSC Tests in TTCN-3
4 * (C) 2017-2019 Harald Welte <laforge@gnumonks.org>
5 * contributions by sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +010014import from Misc_Helpers all;
Harald Welte28d943e2017-11-25 15:00:50 +010015import from General_Types all;
16import from Osmocom_Types all;
Harald Weltec1a2fff2017-12-17 11:06:19 +010017import from GSM_Types all;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +020018import from IPA_Emulation all;
Harald Welte28d943e2017-11-25 15:00:50 +010019import from SCCPasp_Types all;
20import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020021import from RAN_Emulation all;
Harald Welte47cd0e32020-08-21 12:39:11 +020022import from BSSAP_LE_Emulation all;
23import from BSSAP_LE_Types all;
24import from BSSMAP_LE_Templates all;
Harald Welte28d943e2017-11-25 15:00:50 +010025import from BSSMAP_Templates all;
26
Harald Welte211219e2018-01-29 22:03:36 +010027import from IPL4asp_Types all;
28import from Native_Functions all;
29
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +020030import from MGCP_CodecPort all;
Harald Welte28d943e2017-11-25 15:00:50 +010031import from MGCP_Types all;
32import from MGCP_Templates all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010033import from MGCP_Emulation all;
Harald Welte28d943e2017-11-25 15:00:50 +010034import from SDP_Types all;
35
Daniel Willmannebdecc02020-08-12 15:30:17 +020036import from StatsD_Checker all;
37
Harald Weltec1a2fff2017-12-17 11:06:19 +010038import from RSL_Emulation all;
39import from RSL_Types all;
40
41import from MobileL3_Types all;
42import from MobileL3_CommonIE_Types all;
Harald Welte211219e2018-01-29 22:03:36 +010043import from MobileL3_RRM_Types all;
Harald Weltec1a2fff2017-12-17 11:06:19 +010044import from L3_Templates all;
45
Harald Weltec20b1c42018-02-12 20:50:08 +010046import from TELNETasp_PortType all;
47import from Osmocom_VTY_Functions all;
Neels Hofmeyrc2425cc2021-04-19 13:19:55 +000048import from TCCConversion_Functions all;
Harald Weltec20b1c42018-02-12 20:50:08 +010049
Harald Weltec1a2fff2017-12-17 11:06:19 +010050
Harald Welte211219e2018-01-29 22:03:36 +010051/***********************************************************************
52 * Media related handling
53 ***********************************************************************/
54
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +020055/* TODO: import OSMUX_Types.ttcn */
56type INT1 OsmuxCID (0 .. 255);
57
Philipp Maier11a58942018-06-25 16:40:48 +020058/* Get the matching payload type for a specified BSSAP codec type
59 * (see also: BSSAP_Types.ttcn */
60private function f_get_mgcp_pt(BSSMAP_FIELD_CodecType codecType) return SDP_FIELD_PayloadType {
61 if (codecType == GSM_FR) {
62 return PT_GSM;
63 } else if (codecType == GSM_HR) {
64 return PT_GSMHR;
65 } else if (codecType == GSM_EFR) {
66 return PT_GSMEFR;
67 } else if (codecType == FR_AMR or codecType == HR_AMR) {
68 return PT_AMR;
69 } else if (codecType == FR_AMR_WB or codecType == OHR_AMR or codecType == OFR_AMR_WB or codecType == OHR_AMR_WB) {
70 return PT_AMRWB;
71 }
72
73 return PT_PCMU;
74}
75
Harald Welte211219e2018-01-29 22:03:36 +010076/* Tuple containing host/ip and port */
77type record HostPort {
78 HostName host,
79 PortNumber port_nr
80};
81
82/* State encapsulating one MGCP Connection */
83type record MgcpConnState {
Philipp Maier3e2af5d2018-07-11 17:01:05 +020084 integer crcx_seen, /* Counts how many CRCX operations happend */
85 integer mdcx_seen, /* Counts how many MDCX operations happend C */
86 integer crcx_seen_exp, /* Sets the expected number of CRCX operations */
87 integer mdcx_seen_exp, /* Sets the expected number of MDCX operations */
Harald Welte211219e2018-01-29 22:03:36 +010088 MgcpConnectionId conn_id,
89 charstring mime_type, /* e.g. AMR */
90 integer sample_rate, /* 8000 */
91 integer ptime, /* 20 */
92 uint7_t rtp_pt, /* RTP Payload Type */
93 HostPort mgw, /* MGW side */
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +020094 HostPort peer, /* CA side */
95 OsmuxCID local_osmux_cid optional,
96 OsmuxCID remote_osmux_cid optional
Harald Welte211219e2018-01-29 22:03:36 +010097};
98
99/* BTS media state */
100type record BtsMediaState {
101 boolean ipa_crcx_seen,
Philipp Maierc1e95c82018-07-18 16:03:00 +0200102 boolean ipa_mdcx_seen,
Harald Welte211219e2018-01-29 22:03:36 +0100103 uint16_t conn_id,
104 uint7_t rtp_pt,
105 HostPort bts,
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200106 HostPort peer,
107 OsmuxCID local_osmux_cid optional,
108 OsmuxCID remote_osmux_cid optional
Harald Welte211219e2018-01-29 22:03:36 +0100109};
110
111type record MediaState {
112 MgcpEndpoint mgcp_ep,
113 MgcpConnState mgcp_conn[2],
Harald Welte261af4b2018-02-12 21:20:39 +0100114 BtsMediaState bts,
115 BtsMediaState bts1 /* only during hand-over */
Harald Welte211219e2018-01-29 22:03:36 +0100116};
117
Philipp Maier11a58942018-06-25 16:40:48 +0200118function f_MediaState_init(inout MediaState g_media, integer nr, HostName bts, HostName mgw, BSSMAP_FIELD_CodecType codecType) {
Harald Welte211219e2018-01-29 22:03:36 +0100119 /* BTS Side */
120 g_media.bts := {
121 ipa_crcx_seen := false,
Philipp Maierc1e95c82018-07-18 16:03:00 +0200122 ipa_mdcx_seen := false,
Harald Welte211219e2018-01-29 22:03:36 +0100123 conn_id := nr,
124 rtp_pt := 0,
125 bts := {
126 host := bts,
127 port_nr := 9000 + nr*2
128 },
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200129 peer := -,
130 local_osmux_cid := nr,
131 remote_osmux_cid := omit
Harald Welte211219e2018-01-29 22:03:36 +0100132 }
133
Harald Welte261af4b2018-02-12 21:20:39 +0100134 g_media.bts1 := {
135 ipa_crcx_seen := false,
Philipp Maierc1e95c82018-07-18 16:03:00 +0200136 ipa_mdcx_seen := false,
Harald Welte261af4b2018-02-12 21:20:39 +0100137 conn_id := nr,
138 rtp_pt := 0,
139 bts := {
140 host := bts, /* FIXME */
141 port_nr := 9000 + nr*2
142 },
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200143 peer := -,
144 local_osmux_cid := nr,
145 remote_osmux_cid := omit
Harald Welte261af4b2018-02-12 21:20:39 +0100146 }
147
Harald Welte363cb0a2018-01-30 19:35:53 +0100148 g_media.mgcp_ep := "rtpbridge/" & int2str(nr) & "@mgw";
Harald Welte211219e2018-01-29 22:03:36 +0100149
150 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier11a58942018-06-25 16:40:48 +0200151 g_media.mgcp_conn[i].mime_type := f_encoding_name_from_pt(f_get_mgcp_pt(codecType));
Harald Welte211219e2018-01-29 22:03:36 +0100152 g_media.mgcp_conn[i].sample_rate := 8000;
153 g_media.mgcp_conn[i].ptime := 20;
Philipp Maier11a58942018-06-25 16:40:48 +0200154 g_media.mgcp_conn[i].rtp_pt := enum2int(f_get_mgcp_pt(codecType));
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200155 g_media.mgcp_conn[i].crcx_seen := 0;
156 g_media.mgcp_conn[i].mdcx_seen := 0;
157 g_media.mgcp_conn[i].crcx_seen_exp := 0;
158 g_media.mgcp_conn[i].mdcx_seen_exp := 0;
Harald Welte211219e2018-01-29 22:03:36 +0100159 g_media.mgcp_conn[i].conn_id := f_mgcp_alloc_conn_id();
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200160 g_media.mgcp_conn[i].local_osmux_cid := i;
161 g_media.mgcp_conn[i].remote_osmux_cid := omit;
Harald Welte211219e2018-01-29 22:03:36 +0100162 }
163
164 g_media.mgcp_conn[0].mgw := {
165 host := mgw,
166 port_nr := 10000 + nr*2
167 }
168 g_media.mgcp_conn[1].mgw := {
169 host := mgw,
170 port_nr := 11000 + nr*2
171 }
172}
173
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200174/* Helper function to get the next free MGCP connection identifier. We can
175 * recognize free connection identifiers by the fact that no CRCX happend yet */
Harald Welte211219e2018-01-29 22:03:36 +0100176private function f_get_free_mgcp_conn() runs on MSC_ConnHdlr return integer {
177 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200178 if (not g_media.mgcp_conn[i].crcx_seen >= 1) {
Harald Welte211219e2018-01-29 22:03:36 +0100179 return i;
180 }
181 }
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100182 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Only 2 Connections per EP!");
183 /* Should never be reached */
184 return -1;
Harald Welte211219e2018-01-29 22:03:36 +0100185}
186
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200187/* Helper function to pick a specific connection by its cid. Since we reach out
188 * for a connection that is in-use we also check if there was already exactly
189 * one CRCX happening on that connection. */
Harald Welte211219e2018-01-29 22:03:36 +0100190private function f_get_mgcp_conn(MgcpConnectionId cid) runs on MSC_ConnHdlr return integer {
191 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200192 if (g_media.mgcp_conn[i].conn_id == cid and g_media.mgcp_conn[i].crcx_seen == 1) {
Harald Welte211219e2018-01-29 22:03:36 +0100193 return i;
194 }
195 }
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100196 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No Connection for ID ", cid));
197 /* Should not be reached */
198 return -1;
Harald Welte211219e2018-01-29 22:03:36 +0100199}
200
Philipp Maierb2422352018-07-11 10:36:57 +0200201/* altstep for handling of IPACC media related commands. Activated by as_Media() to test
202 * RSL level media handling */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200203altstep as_Media_ipacc(RSL_DCHAN_PT rsl_pt := RSL, RSL_DCHAN_PT rsl_pt_ho_target := RSL1) runs on MSC_ConnHdlr {
Harald Welte211219e2018-01-29 22:03:36 +0100204 var RSL_Message rsl;
Harald Welte211219e2018-01-29 22:03:36 +0100205 var RSL_IE_Body ie;
Harald Welte930d0a72018-03-22 22:08:40 +0100206 var boolean b_unused;
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200207 [not g_media.bts.ipa_crcx_seen] rsl_pt.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl {
Harald Welte211219e2018-01-29 22:03:36 +0100208 /* Extract parameters from request + use in response */
209 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
210 g_media.bts.rtp_pt := ie.ipa_rtp_pt;
211 }
212 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
213 g_media.bts.rtp_pt := ie.ipa_rtp_pt2;
214 }
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200215 if (f_rsl_find_ie(rsl, RSL_IE_OSMO_OSMUX_CID, ie)) {
216 if (not g_pars.use_osmux_bts) {
217 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx unexpected IPAC CRCX with Osmux CID IE");
218 }
219 g_media.bts.remote_osmux_cid := ie.osmux_cid.cid;
220 } else {
221 if (g_pars.use_osmux_bts) {
222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx unexpected IPAC CRCX without Osmux CID IE");
223 }
224 g_media.bts.local_osmux_cid := omit;
225 g_media.bts.remote_osmux_cid := omit;
226 }
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200227 rsl_pt.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts.conn_id,
Vadim Yanitskiyfc631642021-07-03 02:42:45 +0200228 f_inet_addr(g_media.bts.bts.host),
Harald Welte211219e2018-01-29 22:03:36 +0100229 g_media.bts.bts.port_nr,
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200230 g_media.bts.rtp_pt,
231 g_media.bts.local_osmux_cid));
Harald Welte211219e2018-01-29 22:03:36 +0100232 g_media.bts.ipa_crcx_seen := true;
233 repeat;
234 }
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200235 [g_media.bts.ipa_crcx_seen] rsl_pt.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{
Harald Welte211219e2018-01-29 22:03:36 +0100236 /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */
Harald Welte930d0a72018-03-22 22:08:40 +0100237 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie);
Harald Welte211219e2018-01-29 22:03:36 +0100238 if (g_media.bts.conn_id != ie.ipa_conn_id) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100239 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("IPA MDCX for unknown ConnId", rsl));
Harald Welte211219e2018-01-29 22:03:36 +0100240 }
241 /* mandatory */
Harald Welte930d0a72018-03-22 22:08:40 +0100242 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_IP, ie);
Vadim Yanitskiyfc631642021-07-03 02:42:45 +0200243 g_media.bts.peer.host := f_inet_ntoa(ie.ipa_remote_ip);
Harald Welte930d0a72018-03-22 22:08:40 +0100244 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_PORT, ie);
Harald Welte211219e2018-01-29 22:03:36 +0100245 g_media.bts.peer.port_nr := ie.ipa_remote_port;
246 /* optional */
247 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
248 g_media.bts.rtp_pt := ie.ipa_rtp_pt;
249 }
250 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
251 g_media.bts.rtp_pt := ie.ipa_rtp_pt2;
252 }
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200253 if (f_rsl_find_ie(rsl, RSL_IE_OSMO_OSMUX_CID, ie)) {
254 if (not g_pars.use_osmux_bts) {
255 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx unexpected IPAC MDCX with Osmux CID IE");
256 }
257 g_media.bts.remote_osmux_cid := ie.osmux_cid.cid;
258 } else {
259 if (g_pars.use_osmux_bts) {
260 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx unexpected IPAC MDCX without Osmux CID IE");
261 }
262 g_media.bts.local_osmux_cid := omit;
263 g_media.bts.remote_osmux_cid := omit;
264 }
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200265 rsl_pt.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts.conn_id,
Vadim Yanitskiyfc631642021-07-03 02:42:45 +0200266 f_inet_addr(g_media.bts.peer.host),
Harald Welte211219e2018-01-29 22:03:36 +0100267 g_media.bts.peer.port_nr,
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200268 g_media.bts.rtp_pt,
269 g_media.bts.local_osmux_cid));
Philipp Maierc1e95c82018-07-18 16:03:00 +0200270 g_media.bts.ipa_mdcx_seen := true;
Harald Welte211219e2018-01-29 22:03:36 +0100271 repeat;
272 }
Harald Welte261af4b2018-02-12 21:20:39 +0100273
274 /* on second (new) BTS during hand-over */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200275 [not g_media.bts1.ipa_crcx_seen] rsl_pt_ho_target.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl {
Harald Welte261af4b2018-02-12 21:20:39 +0100276 /* Extract parameters from request + use in response */
277 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
278 g_media.bts1.rtp_pt := ie.ipa_rtp_pt;
279 }
280 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
281 g_media.bts1.rtp_pt := ie.ipa_rtp_pt2;
282 }
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200283 if (f_rsl_find_ie(rsl, RSL_IE_OSMO_OSMUX_CID, ie)) {
284 if (not g_pars.use_osmux_bts) {
285 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx unexpected IPAC CRCX with Osmux CID IE");
286 }
287 g_media.bts.remote_osmux_cid := ie.osmux_cid.cid;
288 } else {
289 if (g_pars.use_osmux_bts) {
290 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx unexpected IPAC CRCX without Osmux CID IE");
291 }
292 g_media.bts.local_osmux_cid := omit;
293 g_media.bts.remote_osmux_cid := omit;
294 }
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200295 rsl_pt_ho_target.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts1.conn_id,
Vadim Yanitskiyfc631642021-07-03 02:42:45 +0200296 f_inet_addr(g_media.bts1.bts.host),
Harald Welte261af4b2018-02-12 21:20:39 +0100297 g_media.bts1.bts.port_nr,
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200298 g_media.bts1.rtp_pt,
299 g_media.bts.local_osmux_cid));
Harald Welte261af4b2018-02-12 21:20:39 +0100300 g_media.bts1.ipa_crcx_seen := true;
301 repeat;
302 }
303 /* on second (new) BTS during hand-over */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200304 [g_media.bts1.ipa_crcx_seen] rsl_pt_ho_target.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{
Harald Welte261af4b2018-02-12 21:20:39 +0100305 /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */
Harald Welte930d0a72018-03-22 22:08:40 +0100306 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie);
Harald Welte261af4b2018-02-12 21:20:39 +0100307 if (g_media.bts1.conn_id != ie.ipa_conn_id) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("IPA MDCX for unknown ConnId", rsl));
Harald Welte261af4b2018-02-12 21:20:39 +0100309 }
310 /* mandatory */
Harald Welte930d0a72018-03-22 22:08:40 +0100311 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_IP, ie);
Vadim Yanitskiyfc631642021-07-03 02:42:45 +0200312 g_media.bts1.peer.host := f_inet_ntoa(ie.ipa_remote_ip);
Harald Welte930d0a72018-03-22 22:08:40 +0100313 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_PORT, ie);
Harald Welte261af4b2018-02-12 21:20:39 +0100314 g_media.bts1.peer.port_nr := ie.ipa_remote_port;
315 /* optional */
316 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
317 g_media.bts1.rtp_pt := ie.ipa_rtp_pt;
318 }
319 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
320 g_media.bts1.rtp_pt := ie.ipa_rtp_pt2;
321 }
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200322 if (f_rsl_find_ie(rsl, RSL_IE_OSMO_OSMUX_CID, ie)) {
323 if (not g_pars.use_osmux_bts) {
324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx unexpected IPAC MDCX with Osmux CID IE");
325 }
326 g_media.bts.remote_osmux_cid := ie.osmux_cid.cid;
327 } else {
328 if (g_pars.use_osmux_bts) {
329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx unexpected IPAC MDCX without Osmux CID IE");
330 }
331 g_media.bts.local_osmux_cid := omit;
332 g_media.bts.remote_osmux_cid := omit;
333 }
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200334 rsl_pt_ho_target.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts1.conn_id,
Vadim Yanitskiyfc631642021-07-03 02:42:45 +0200335 f_inet_addr(g_media.bts1.peer.host),
Harald Welte261af4b2018-02-12 21:20:39 +0100336 g_media.bts1.peer.port_nr,
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200337 g_media.bts1.rtp_pt,
338 g_media.bts.local_osmux_cid));
Philipp Maierc1e95c82018-07-18 16:03:00 +0200339 g_media.bts1.ipa_mdcx_seen := true;
Harald Welte261af4b2018-02-12 21:20:39 +0100340 repeat;
341 }
342
Philipp Maierb2422352018-07-11 10:36:57 +0200343
344}
345
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200346function f_rx_crcx(MgcpCommand mgcp_cmd)
347 runs on MSC_ConnHdlr return template MgcpResponse {
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200348 var SDP_Message sdp;
349 var integer cid := f_get_free_mgcp_conn();
Philipp Maiera2083892020-09-21 14:18:36 +0200350 var charstring local_rtp_addr;
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200351 var MgcpOsmuxCID osmux_cid;
Philipp Maiera2083892020-09-21 14:18:36 +0200352
353 if (g_pars.media_mgw_offer_ipv6 == true) {
354 local_rtp_addr := host_mgw_rtp_v6; /* Use IPv6 by default if no remote addr is provided by client */
355 } else {
356 local_rtp_addr := host_mgw_rtp_v4; /* Use IPv4 by default if no remote addr is provided by client */
357 }
358
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200359 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard)) {
360 if (cid != 0) {
361 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "MGCP wildcard EP only works in first CRCX");
362 }
363 /* we keep the endpoint name allocated during MediaState_init */
364 } else {
365 /* Call Agent allocated endpoint, trust/use it always */
366 g_media.mgcp_ep := mgcp_cmd.line.ep;
367 }
368 if (isvalue(mgcp_cmd.sdp)) {
369 sdp := mgcp_cmd.sdp;
370 g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr;
371 g_media.mgcp_conn[cid].peer.port_nr := sdp.media_list[0].media_field.ports.port_number;
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200372 if (sdp.connection.addr_type == "IP6") {
373 local_rtp_addr := host_mgw_rtp_v6;
374 } else {
375 local_rtp_addr := host_mgw_rtp_v4;
376 }
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200377 }
378 var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid];
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200379 sdp := valueof(ts_SDP(mgcp_conn.mgw.host, local_rtp_addr, "foo", "21",
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200380 mgcp_conn.mgw.port_nr, { int2str(mgcp_conn.rtp_pt) },
381 {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt,
382 mgcp_conn.mime_type & "/" &
383 int2str(mgcp_conn.sample_rate))),
384 valueof(ts_SDP_ptime(mgcp_conn.ptime)) } ));
385 var template MgcpResponse mgcp_resp;
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200386 if ((g_pars.use_osmux_cn or g_pars.use_osmux_bts) and
387 f_MgcpCmd_contains_par(mgcp_cmd, "X-OSMUX")) {
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200388 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200389 if (osmux_cid != -1) {
390 mgcp_conn.remote_osmux_cid := osmux_cid;
391 }
392 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, mgcp_conn.local_osmux_cid, sdp);
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200393 } else {
394 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp);
395 }
396 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(g_media.mgcp_ep));
397 g_media.mgcp_conn[cid].crcx_seen := g_media.mgcp_conn[cid].crcx_seen + 1;
398 return mgcp_resp;
399}
400
401function f_rx_mdcx(MgcpCommand mgcp_cmd)
402 runs on MSC_ConnHdlr return template MgcpResponse {
403 var SDP_Message sdp;
404 var integer cid := f_get_mgcp_conn(f_MgcpCmd_extract_conn_id(mgcp_cmd));
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200405 var charstring local_rtp_addr;
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200406 if (isvalue(mgcp_cmd.sdp)) {
407 sdp := mgcp_cmd.sdp;
408 g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr;
409 g_media.mgcp_conn[cid].peer.port_nr := sdp.media_list[0].media_field.ports.port_number;
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200410 if (sdp.connection.addr_type == "IP6") {
411 local_rtp_addr := host_mgw_rtp_v6;
412 } else {
413 local_rtp_addr := host_mgw_rtp_v4;
414 }
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200415 } else {
416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "MDCX has no [recognizable] SDP");
417 }
418 var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid];
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200419 sdp := valueof(ts_SDP(mgcp_conn.peer.host, local_rtp_addr, "foo", "21",
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200420 mgcp_conn.peer.port_nr, { int2str(mgcp_conn.rtp_pt) },
421 {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt,
422 mgcp_conn.mime_type & "/" &
423 int2str(mgcp_conn.sample_rate))),
424 valueof(ts_SDP_ptime(mgcp_conn.ptime)) } ));
425 g_media.mgcp_conn[cid].mdcx_seen := g_media.mgcp_conn[cid].mdcx_seen + 1;
426 return ts_MDCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp);
427}
428
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200429function tr_MGCP_RecvFrom_any(template MgcpMessage msg)
430runs on MSC_ConnHdlr return template MGCP_RecvFrom {
431 var template MGCP_RecvFrom mrf := {
432 connId := ?,
433 remName := ?,
434 remPort := ?,
435 locName := ?,
436 locPort := ?,
437 msg := msg
438 }
439 return mrf;
440}
441
Philipp Maierb2422352018-07-11 10:36:57 +0200442/* altstep for handling of MGCP media related commands. Activated by as_Media() to test
443 * MGW level media handling */
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200444
Neels Hofmeyr9b320c12022-04-07 00:19:01 +0200445altstep as_Media_mgw(boolean norepeat := false, boolean fail_on_dlcx := true) runs on MSC_ConnHdlr {
Philipp Maierb2422352018-07-11 10:36:57 +0200446 var MgcpCommand mgcp_cmd;
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200447 var template MgcpResponse mgcp_resp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200448 var MGCP_RecvFrom mrf;
449 var template MgcpMessage msg_crcx := {
450 command := tr_CRCX
451 }
452 var template MgcpMessage msg_mdcx := {
453 command := tr_MDCX
454 }
Neels Hofmeyr9b320c12022-04-07 00:19:01 +0200455 var template MgcpMessage msg_dlcx := {
456 command := tr_DLCX
457 }
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200458 var template MgcpMessage msg_resp;
Philipp Maierb2422352018-07-11 10:36:57 +0200459
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200460 [g_pars.aoip] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200461 mgcp_resp := f_rx_crcx(mgcp_cmd);
Harald Welte363cb0a2018-01-30 19:35:53 +0100462 MGCP.send(mgcp_resp);
Philipp Maierc1e95c82018-07-18 16:03:00 +0200463 if(norepeat == false) {
464 repeat;
465 }
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200466 }
467
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200468 [not g_pars.aoip] MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_crcx)) -> value mrf {
469 mgcp_resp := f_rx_crcx(mrf.msg.command);
470 msg_resp := {
471 response := mgcp_resp
472 }
473 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
474 if(norepeat == false) {
475 repeat;
476 }
477 }
478
479 [g_pars.aoip] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200480 mgcp_resp := f_rx_mdcx(mgcp_cmd);
481 MGCP.send(mgcp_resp);
Philipp Maierc1e95c82018-07-18 16:03:00 +0200482 if(norepeat == false) {
483 repeat;
484 }
Harald Welte211219e2018-01-29 22:03:36 +0100485 }
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200486
487 [not g_pars.aoip] MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_mdcx)) -> value mrf {
488 mgcp_resp := f_rx_mdcx(mrf.msg.command);
489 msg_resp := {
490 response := mgcp_resp
491 }
492 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
493 if(norepeat == false) {
494 repeat;
495 }
496 }
Neels Hofmeyr9b320c12022-04-07 00:19:01 +0200497
498 [fail_on_dlcx and g_pars.aoip] MGCP.receive(tr_DLCX) {
499 setverdict(fail, "Unexpected DLCX received");
500 }
501
502 [fail_on_dlcx and not g_pars.aoip] MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_dlcx)) {
503 setverdict(fail, "Unexpected DLCX received");
504 }
Harald Welte211219e2018-01-29 22:03:36 +0100505}
506
Philipp Maierb2422352018-07-11 10:36:57 +0200507/* Altsteps for handling of media related commands. Can be activated by a given
508 * test case if it expects to see media related handling (i.e. voice calls) */
Neels Hofmeyr9b320c12022-04-07 00:19:01 +0200509altstep as_Media(boolean fail_on_dlcx := true) runs on MSC_ConnHdlr {
Philipp Maierb2422352018-07-11 10:36:57 +0200510 [] as_Media_ipacc();
Neels Hofmeyr9b320c12022-04-07 00:19:01 +0200511 [] as_Media_mgw(fail_on_dlcx := fail_on_dlcx);
Philipp Maierb2422352018-07-11 10:36:57 +0200512}
Harald Welte211219e2018-01-29 22:03:36 +0100513
Neels Hofmeyrd36a82f2021-07-20 22:10:49 +0200514type port Coord_PT message
515{
516 inout charstring;
517} with { extension "internal" };
518
Harald Welte28d943e2017-11-25 15:00:50 +0100519/* this component represents a single subscriber connection at the MSC.
Harald Welte6811d102019-04-14 22:23:14 +0200520 * There is a 1:1 mapping between SCCP connections and RAN_ConnHdlr components.
521 * We inherit all component variables, ports, functions, ... from RAN_ConnHdlr */
Harald Welte47cd0e32020-08-21 12:39:11 +0200522type component MSC_ConnHdlr extends RAN_ConnHdlr, RSL_DchanHdlr, MGCP_ConnHdlr, BSSAP_LE_ConnHdlr, StatsD_ConnHdlr {
Harald Welte28d943e2017-11-25 15:00:50 +0100523 /* SCCP Connecction Identifier for the underlying SCCP connection */
524 var integer g_sccp_conn_id;
525
Harald Welte6811d102019-04-14 22:23:14 +0200526 /* procedure port back to our parent (RAN_Emulation_CT) for control */
527 port RAN_PROC_PT RAN;
Harald Weltec20b1c42018-02-12 20:50:08 +0100528 port TELNETasp_PT BSCVTY;
Neels Hofmeyrd36a82f2021-07-20 22:10:49 +0200529 port Coord_PT COORD;
Vadim Yanitskiy5f14d342022-02-07 14:18:38 +0600530 port Coord_PT COORD2;
Harald Welte28d943e2017-11-25 15:00:50 +0100531
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200532 /* Proxy MGCP-over-IPA and MGCP-over-UDP */
533 port IPA_MGCP_PT MGCP_MSC_CLIENT;
534 var integer g_trans_id := 0;
535
Harald Welte211219e2018-01-29 22:03:36 +0100536 var MediaState g_media;
Harald Weltea0630032018-03-20 21:09:55 +0100537 var TestHdlrParams g_pars;
Harald Weltee97eab42018-03-21 18:46:06 +0100538
Pau Espin Pedrol392963f2019-06-18 17:17:19 +0200539 var charstring host_bts := "127.0.0.2";
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200540 var charstring host_mgw_mgcp := "127.0.0.3";
541 var charstring host_mgw_rtp_v4 := "127.0.0.5";
542 var charstring host_mgw_rtp_v6 := "::1";
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200543 var charstring host_msc := "127.0.0.4";
544
Harald Weltee97eab42018-03-21 18:46:06 +0100545 var boolean g_vty_initialized := false;
Harald Welte211219e2018-01-29 22:03:36 +0100546}
547
Harald Welteeddf0e92020-06-21 19:42:15 +0200548function f_MscConnHdlr_init_vty() runs on MSC_ConnHdlr {
Harald Weltee97eab42018-03-21 18:46:06 +0100549 if (not g_vty_initialized) {
550 map(self:BSCVTY, system:BSCVTY);
551 f_vty_set_prompts(BSCVTY);
552 f_vty_transceive(BSCVTY, "enable");
553 g_vty_initialized := true;
554 }
Harald Welte28d943e2017-11-25 15:00:50 +0100555}
556
Harald Welteeddf0e92020-06-21 19:42:15 +0200557/* initialize all parameters */
558function f_MscConnHdlr_init(integer i, HostName bts, HostName mgw, BSSMAP_FIELD_CodecType codecType) runs on MSC_ConnHdlr {
559 f_MediaState_init(g_media, i, bts, mgw, codecType);
560 f_MscConnHdlr_init_vty();
561}
562
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200563private function get_next_trans_id() runs on MSC_ConnHdlr return MgcpTransId {
564 var MgcpTransId tid := int2str(g_trans_id);
565 g_trans_id := g_trans_id + 1;
566 return tid;
567}
568
Harald Welte6811d102019-04-14 22:23:14 +0200569/* Callback function from general RAN_Emulation whenever a connectionless
Harald Welte28d943e2017-11-25 15:00:50 +0100570 * BSSMAP message arrives. Can retunr a PDU_BSSAP that should be sent in return */
571private function UnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200572runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Welte28d943e2017-11-25 15:00:50 +0100573 var template PDU_BSSAP resp := omit;
Pau Espin Pedrol95549182019-06-06 16:17:30 +0200574 var boolean append_osmux_support := g_ran_ops.use_osmux and
575 (g_ran_ops.transport == BSSAP_TRANSPORT_AoIP);
Harald Welte28d943e2017-11-25 15:00:50 +0100576
Harald Weltec1a2fff2017-12-17 11:06:19 +0100577 /* answer all RESET with a RESET ACK */
Pau Espin Pedrol95549182019-06-06 16:17:30 +0200578 if (match(bssap, tr_BSSMAP_Reset(append_osmux_support))) {
579 resp := ts_BSSMAP_ResetAck(append_osmux_support);
Harald Welte28d943e2017-11-25 15:00:50 +0100580 }
581
582 return resp;
583}
584
Harald Welte47cd0e32020-08-21 12:39:11 +0200585/* Callback function from general BSSAP_LE_Emulation whenever a connectionless
586 * BSSAP_LE message arrives. Can return a PDU_BSSAP_LE that should be sent in return */
587private function BSSAP_LE_UnitdataCallback(PDU_BSSAP_LE bssap)
588runs on BSSAP_LE_Emulation_CT return template PDU_BSSAP_LE {
589 var template PDU_BSSAP_LE resp := omit;
590
591 /* answer all RESET with a RESET ACK */
592 if (match(bssap, tr_BSSMAP_LE_Reset)) {
593 resp := ts_BSSMAP_LE_ResetAck;
594 }
595
596 return resp;
597}
598
Harald Welte6811d102019-04-14 22:23:14 +0200599const RanOps MSC_RanOps := {
600 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Welte0b476062018-01-21 19:07:32 +0100601 unitdata_cb := refers(UnitdataCallback),
602 decode_dtap := false,
Harald Welte930d0a72018-03-22 22:08:40 +0100603 role_ms := false,
Harald Welte2fce7882019-04-15 11:48:05 +0200604 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200605 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200606 use_osmux := false,
Eric Wild66448c12022-04-02 14:57:53 +0200607 bssap_reset_retries := 1,
Harald Welte930d0a72018-03-22 22:08:40 +0100608 sccp_addr_local := omit,
609 sccp_addr_peer := omit
Harald Welte28d943e2017-11-25 15:00:50 +0100610}
611
Harald Welte47cd0e32020-08-21 12:39:11 +0200612const BssapLeOps SMLC_BssapLeOps := {
613 create_cb := refers(BSSAP_LE_Emulation.ExpectedCreateCallback),
614 unitdata_cb := refers(BSSAP_LE_UnitdataCallback),
615 decode_dtap := false,
616 role_ms := false,
617 sccp_addr_local := omit,
618 sccp_addr_peer := omit
619}
620
Daniel Willmann191e0d92018-01-17 12:44:35 +0100621const MGCPOps MSC_MGCPOps := {
Harald Welte930d0a72018-03-22 22:08:40 +0100622 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
623 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
Daniel Willmann191e0d92018-01-17 12:44:35 +0100624}
625
Harald Weltec1a2fff2017-12-17 11:06:19 +0100626/* register an expect with the BSSMAP core */
Neels Hofmeyr4f118412020-06-04 15:25:10 +0200627function f_create_bssmap_exp(octetstring l3_enc) runs on MSC_ConnHdlr {
Harald Welte6811d102019-04-14 22:23:14 +0200628 RAN.call(RAN_register:{l3_enc, self}) {
629 [] RAN.getreply(RAN_register:{?, ?}) {};
Harald Welte28d943e2017-11-25 15:00:50 +0100630 }
631}
632
Harald Welte651fcdc2018-05-10 20:23:16 +0200633type record TestHdlrEncrParams {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +0100634 /* A mask of multiple encryption algorithms, for Encryption Information IE. */
635 OCT1 enc_alg_permitted,
636 /* Expect this encryption algorithm in Channel Activation from the BSC.
637 * To expect no encryption, set to '01'O == A5/0. */
638 OCT1 enc_alg_expect,
639 /* In BSSMAP, the Chosen Encryption Algorithm IE that the test sends to the BSC.
640 * When set to omit, the MSC will not send a Chosen Encryption Algorithm IE. */
641 OCT1 enc_alg_chosen optional,
Neels Hofmeyr6c388f22021-06-11 02:36:56 +0200642 octetstring enc_key,
643 octetstring enc_kc128 optional
Harald Welte651fcdc2018-05-10 20:23:16 +0200644};
645
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +0100646template (value) TestHdlrEncrParams t_EncrParams(OCT1 alg_permitted,
647 octetstring key, template (omit) octetstring kc128 := omit) := {
648 enc_alg_permitted := alg_permitted,
649 enc_alg_expect := alg_permitted, /* <- for compat with tests before enc_alg_expect was added */
650 enc_alg_chosen := alg_permitted, /* <- for compat with tests before enc_alg_chosen was added */
Neels Hofmeyr6c388f22021-06-11 02:36:56 +0200651 enc_key := key,
652 enc_kc128 := kc128
Harald Welte651fcdc2018-05-10 20:23:16 +0200653}
654
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +0100655template (value) TestHdlrEncrParams t_EncrParams2(OCT1 alg_permitted,
656 OCT1 alg_expect,
657 template(omit) OCT1 alg_chosen,
658 octetstring key,
659 template (omit) octetstring kc128 := omit) := {
660 enc_alg_permitted := alg_permitted,
661 enc_alg_expect := alg_expect,
662 enc_alg_chosen := alg_chosen,
663 enc_key := key,
664 enc_kc128 := kc128
665}
666
667/* Convenience for common t_EncrParams2 usage.
668 *
669 * To test a scenario where only A5/3 is permitted:
670 * f_encr_params('08'O);
671 * To test a scenario where A5/3 is chosen from A5/0,A5/1,A5/3 (1 | 2 | 8 = 11 = 0xb):
672 * f_encr_params('0b'O, '08'O);
673 * To test the same, but the Chosen Encryption Algorithm IE should reflect A5/1:
674 * f_encr_params('0b'O, '08'O, '02'O);
675 * To test the same, but the MSC sends no Chosen Encryption Algorithm IE:
676 * f_encr_params('0b'O, '08'O, omit);
677 *
678 * Set alg_chosen and alg_expect magically when == '00'O:
679 * - enc_alg_expect is set to alg_chosen if present, else to alg_permitted.
680 * - enc_alg_chosen is set to alg_permitted.
681 * When only alg_permitted is given, alg_permitted must reflect only one algorithm, or f_cipher_mode_bssmap_to_rsl()
682 * will fail.
683 * When alg_chosen is passed as omit, the messages from the MSC will not contain a Chosen Encryption Algorithm IE.
684 */
685function f_encr_params(OCT1 alg_permitted, OCT1 alg_expect := '00'O, template (omit) OCT1 alg_chosen := '00'O,
686 boolean kc128 := false)
687 return TestHdlrEncrParams
688{
689 if (not istemplatekind(alg_chosen, "omit")) {
690 if (valueof(alg_chosen) == '00'O) {
691 if (alg_expect != '00'O) {
692 alg_chosen := alg_expect;
693 } else {
694 /* In this case, alg_permitted should have only one permitted algo */
695 alg_chosen := alg_permitted;
696 }
697 }
698 if (alg_expect == '00'O) {
699 alg_expect := valueof(alg_chosen);
700 }
701 }
702 if (alg_expect == '00'O) {
703 /* In this case, alg_permitted should have only one permitted algo */
704 alg_expect := valueof(alg_permitted);
705 }
Vadim Yanitskiy35c9a332022-03-16 20:26:35 +0300706 var template (omit) octetstring kc := omit;
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +0100707 if (kc128) {
708 kc := f_rnd_octstring(16);
709 }
710 return valueof(t_EncrParams2(alg_permitted, alg_expect, alg_chosen, f_rnd_octstring(8), kc));
711}
712
Harald Weltecc0b0142018-05-29 15:19:33 +0200713type record TestHdlrParamsLcls {
714 GlobalCallReferenceValue gcr optional,
715 /* LCLS Configuration */
716 BIT4 cfg optional,
717 /* LCLS Connection Status Control */
718 BIT4 csc optional,
Max2eeb5112018-11-06 19:21:41 +0100719 BIT4 exp_sts optional,
720 /* Whether to adjust *cx_seen_exp for LCLS tests */
721 boolean adjust_cx_exp
Harald Weltecc0b0142018-05-29 15:19:33 +0200722}
723
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200724type record TestHdlrParamsMSCPool {
Neels Hofmeyr4f118412020-06-04 15:25:10 +0200725 integer bssap_idx,
Neels Hofmeyr4f118412020-06-04 15:25:10 +0200726 integer rsl_idx,
727 PDU_ML3_MS_NW l3_info optional
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200728}
729
Harald Weltec1a2fff2017-12-17 11:06:19 +0100730type record TestHdlrParams {
731 OCT1 ra,
732 GsmFrameNumber fn,
733 hexstring imsi,
Harald Welte60aa5762018-03-21 19:33:13 +0100734 RslLinkId link_id,
Harald Weltecbe911c2018-06-01 18:23:07 +0200735 integer media_nr, /* determins MGCP EP, port numbers */
Harald Welte651fcdc2018-05-10 20:23:16 +0200736 BSSMAP_IE_SpeechCodecList ass_codec_list optional,
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +0200737 RSL_IE_Body expect_mr_conf_ie optional, /* typically present for AMR codecs */
Philipp Maierd0e64b02019-03-13 14:15:23 +0100738 bitstring expect_mr_s0_s7 optional, /* typically present for AMR codecs */
Harald Weltecc0b0142018-05-29 15:19:33 +0200739 TestHdlrEncrParams encr optional,
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100740 TestHdlrParamsLcls lcls,
Neels Hofmeyr90f80962020-06-12 16:16:55 +0200741 SCCP_PAR_Address sccp_addr_msc optional,
742 SCCP_PAR_Address sccp_addr_bsc optional,
Pau Espin Pedrolf7630a62019-10-28 15:07:08 +0100743 uint5_t exp_ms_power_level,
Pau Espin Pedrol8f773632019-11-05 11:46:53 +0100744 boolean exp_ms_power_params,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200745 boolean aoip,
Pau Espin Pedrolf967afc2022-08-08 18:17:20 +0200746 boolean use_osmux_cn,
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200747 boolean use_osmux_bts,
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200748 charstring host_aoip_tla,
Philipp Maiera2083892020-09-21 14:18:36 +0200749 TestHdlrParamsMSCPool mscpool,
Pau Espin Pedrol3c630532022-10-20 19:00:11 +0200750 integer mgwpool_idx, /* MGCP_Emulation_CT (vc_MGCP) to use for this MSC ConnHdlr */
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +0200751 boolean media_mgw_offer_ipv6,
Neels Hofmeyr559d5d02021-04-16 16:50:49 +0200752 OCT3 last_used_eutran_plmn optional,
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +0200753 boolean exp_fast_return, /* RR Release expected to contain CellSelectInd ? */
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200754 boolean expect_channel_mode_modify,
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +0100755 uint3_t expect_tsc optional,
Neels Hofmeyr907b23b2022-02-17 21:58:47 +0100756 BSSMAP_IE_CellIdentifier cell_id_source,
Neels Hofmeyra23f3b12022-03-02 19:57:12 +0100757 boolean expect_ho_fail,
758 boolean inter_bsc_ho_in__ho_req_in_initial_sccp_cr
Harald Weltec1a2fff2017-12-17 11:06:19 +0100759};
760
Philipp Maier48604732018-10-09 15:00:37 +0200761/* Note: Do not use valueof() to get a value of this template, use
762 * f_gen_test_hdlr_pars() instead in order to get a configuration that is
Pau Espin Pedrol8df10112020-01-09 18:21:53 +0100763 * matched to the current test situation (aoip vs. sccplite) */
Harald Weltec1a2fff2017-12-17 11:06:19 +0100764template (value) TestHdlrParams t_def_TestHdlrPars := {
765 ra := '23'O,
766 fn := 23,
767 imsi := '001019876543210'H,
Harald Welte60aa5762018-03-21 19:33:13 +0100768 link_id := valueof(ts_RslLinkID_DCCH(0)),
Harald Weltecbe911c2018-06-01 18:23:07 +0200769 media_nr := 1,
Harald Welte651fcdc2018-05-10 20:23:16 +0200770 ass_codec_list := omit,
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +0200771 expect_mr_conf_ie := omit,
Philipp Maierd0e64b02019-03-13 14:15:23 +0100772 expect_mr_s0_s7 := omit,
Harald Weltecc0b0142018-05-29 15:19:33 +0200773 encr := omit,
774 lcls := {
775 gcr := omit,
776 cfg := omit,
777 csc := omit,
Max2eeb5112018-11-06 19:21:41 +0100778 exp_sts := omit,
779 adjust_cx_exp := true
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100780 },
Neels Hofmeyr90f80962020-06-12 16:16:55 +0200781 sccp_addr_msc := omit,
782 sccp_addr_bsc := omit,
Pau Espin Pedrolf7630a62019-10-28 15:07:08 +0100783 exp_ms_power_level := 7, /* calculated from osmo-bsc.cfg "ms max power" */
Pau Espin Pedrol8f773632019-11-05 11:46:53 +0100784 exp_ms_power_params := false,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200785 aoip := true,
Pau Espin Pedrolf967afc2022-08-08 18:17:20 +0200786 use_osmux_cn := false,
Pau Espin Pedrol29c6dfb2022-08-08 18:37:56 +0200787 use_osmux_bts := false,
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200788 host_aoip_tla := "1.2.3.4",
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200789 mscpool := {
Neels Hofmeyr4f118412020-06-04 15:25:10 +0200790 bssap_idx := 0,
Neels Hofmeyr4f118412020-06-04 15:25:10 +0200791 rsl_idx := 0,
792 l3_info := omit
Philipp Maiera2083892020-09-21 14:18:36 +0200793 },
Pau Espin Pedrol3c630532022-10-20 19:00:11 +0200794 mgwpool_idx := 0,
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +0200795 media_mgw_offer_ipv6 := true,
Neels Hofmeyr559d5d02021-04-16 16:50:49 +0200796 last_used_eutran_plmn := omit,
Pau Espin Pedrol9ae36d52021-06-15 17:29:43 +0200797 exp_fast_return := false,
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200798 expect_channel_mode_modify := false,
Pau Espin Pedrola8ef3be2022-02-16 16:21:17 +0100799 expect_tsc := omit,
Neels Hofmeyr907b23b2022-02-17 21:58:47 +0100800 cell_id_source := valueof(ts_CellID_LAC_CI(1, 1)),
Neels Hofmeyra23f3b12022-03-02 19:57:12 +0100801 expect_ho_fail := false,
802 inter_bsc_ho_in__ho_req_in_initial_sccp_cr := true
Harald Weltec1a2fff2017-12-17 11:06:19 +0100803}
804
Vadim Yanitskiya7fc5a62021-12-04 20:10:08 +0300805function f_create_chan_and_exp(template (present) PDU_BSSAP exp_l3_compl := ?)
806runs on MSC_ConnHdlr {
Harald Weltea0630032018-03-20 21:09:55 +0100807 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
Harald Welte6ed6bf92018-01-24 21:09:15 +0100808 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
Harald Weltec1a2fff2017-12-17 11:06:19 +0100809 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200810 var template uint3_t tsc := ?;
Vadim Yanitskiya7fc5a62021-12-04 20:10:08 +0300811 timer T;
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200812
813 if (not istemplatekind(g_pars.expect_tsc, "omit")) {
814 tsc := g_pars.expect_tsc;
815 }
Harald Weltec1a2fff2017-12-17 11:06:19 +0100816
Vadim Yanitskiya7fc5a62021-12-04 20:10:08 +0300817 if (istemplatekind(exp_l3_compl, "?")) {
818 if (g_pars.aoip == false) {
819 exp_l3_compl := tr_BSSMAP_ComplL3(l3_enc, codec_list := omit);
820 } else {
821 exp_l3_compl := tr_BSSMAP_ComplL3(l3_enc, codec_list := ?);
822 }
823 }
824
Neels Hofmeyrd601f9c2021-06-04 22:46:06 +0200825 f_create_bssmap_exp(l3_enc);
Harald Weltec1a2fff2017-12-17 11:06:19 +0100826 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200827 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc);
Vadim Yanitskiya7fc5a62021-12-04 20:10:08 +0300828 /* wait for a COMPL_L3 from the BSC to ensure that the SCCP connection is up */
829 T.start(2.0);
830 alt {
831 [] BSSAP.receive(exp_l3_compl);
832 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
833 setverdict(fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
834 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
835 }
836 [] T.timeout {
837 setverdict(fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
838 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
839 }
840 }
Harald Weltec1a2fff2017-12-17 11:06:19 +0100841}
842
Harald Welte898113b2018-01-31 18:32:21 +0100843function f_rsl_send_l3(template PDU_ML3_MS_NW l3, template (omit) RslLinkId link_id := omit,
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200844 template (omit) RslChannelNr chan_nr := omit, RSL_DCHAN_PT rsl_pt := RSL) runs on MSC_ConnHdlr {
Harald Welte898113b2018-01-31 18:32:21 +0100845 if (not isvalue(link_id)) {
846 link_id := ts_RslLinkID_DCCH(0);
847 }
848 if (not isvalue(chan_nr)) {
849 chan_nr := g_chan_nr;
850 }
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200851 rsl_pt.send(ts_RSL_DATA_IND(valueof(chan_nr), valueof(link_id), enc_PDU_ML3_MS_NW(valueof(l3))));
Harald Welte898113b2018-01-31 18:32:21 +0100852}
853
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200854function f_rsl_reply(template PDU_ML3_MS_NW l3, RSL_Message orig, RSL_DCHAN_PT rsl_pt := RSL) runs on MSC_ConnHdlr {
Harald Weltec1a2fff2017-12-17 11:06:19 +0100855 var RslChannelNr chan_nr := orig.ies[0].body.chan_nr;
Harald Welte1a40de62017-12-23 02:28:34 +0100856 var RslLinkId link_id;
Harald Welte8d5eead2017-12-17 18:56:45 +0100857 if (orig.msg_type == RSL_MT_ENCR_CMD) {
858 link_id := orig.ies[2].body.link_id;
859 } else {
860 link_id := orig.ies[1].body.link_id;
861 }
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200862 f_rsl_send_l3(l3, link_id, chan_nr, rsl_pt := rsl_pt);
Harald Weltec1a2fff2017-12-17 11:06:19 +0100863}
864
Oliver Smith598e1ed2021-07-09 10:28:40 +0200865/* Convert the cipher representation on BSSMAP to the representation used on RSL */
866function f_cipher_mode_bssmap_to_rsl(OCT1 alg_bssmap) return RSL_AlgId
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100867{
Vadim Yanitskiy4483a222022-03-14 22:07:43 +0300868 select (alg_bssmap) {
869 case ('01'O) { return RSL_ALG_ID_A5_0; }
870 case ('02'O) { return RSL_ALG_ID_A5_1; }
871 case ('04'O) { return RSL_ALG_ID_A5_2; }
872 case ('08'O) { return RSL_ALG_ID_A5_3; }
873 case ('10'O) { return RSL_ALG_ID_A5_4; }
874 case ('20'O) { return RSL_ALG_ID_A5_5; }
875 case ('40'O) { return RSL_ALG_ID_A5_6; }
876 case ('80'O) { return RSL_ALG_ID_A5_7; }
877 case else {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +0100878 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Encryption Algorithm: " &
879 oct2str(alg_bssmap));
Harald Weltee613f962018-04-18 22:38:16 +0200880 return RSL_ALG_ID_A5_0;
Vadim Yanitskiy4483a222022-03-14 22:07:43 +0300881 }
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100882 }
883}
884
Vadim Yanitskiyaf2972e2022-03-14 22:27:57 +0300885/* Convert the cipher representation on BSSMAP to the one used on RR (3GPP TS 44.018) */
886function f_cipher_mode_bssmap_to_rr(OCT1 alg_bssmap) return BIT3
887{
888 select (alg_bssmap) {
889 case ('01'O) /* A5/0 */ { return '000'B; } /* SC=0 */
890 case ('02'O) /* A5/1 */ { return '000'B; } /* SC=1 */
891 case ('04'O) /* A5/2 */ { return '001'B; } /* SC=1 */
892 case ('08'O) /* A5/3 */ { return '010'B; } /* SC=1 */
893 case ('10'O) /* A5/4 */ { return '011'B; } /* SC=1 */
894 case ('20'O) /* A5/5 */ { return '100'B; } /* SC=1 */
895 case ('40'O) /* A5/6 */ { return '101'B; } /* SC=1 */
896 case ('80'O) /* A5/7 */ { return '110'B; } /* SC=1 */
897 case else {
898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Encryption Algorithm: " &
899 oct2str(alg_bssmap));
900 return '000'B;
901 }
902 }
903}
904
Neels Hofmeyr58ffceb2021-06-21 02:17:30 +0200905function f_verify_encr_info(RSL_Message rsl) runs on MSC_ConnHdlr {
906 var RSL_IE_Body encr_info;
907 var RSL_AlgId alg_rsl;
908 var template octetstring expect_kc;
909
910 /* If no encryption is enabled, then make sure there is no RSL_IE_ENCR_INFO */
911 if (not ispresent(g_pars.encr)) {
912 if (f_rsl_find_ie(rsl, RSL_IE_ENCR_INFO, encr_info)) {
913 setverdict(fail, "Found Encryption IE, but expected no encryption in ", rsl.msg_type);
914 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
915 return;
916 }
917 setverdict(pass);
918 return;
919 }
920
921 /* RSL uses a different representation of the encryption algorithm,
922 * so we need to convert first */
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +0100923 alg_rsl := f_cipher_mode_bssmap_to_rsl(g_pars.encr.enc_alg_expect);
Neels Hofmeyr58ffceb2021-06-21 02:17:30 +0200924
925 if (alg_rsl == RSL_ALG_ID_A5_4 and ispresent(g_pars.encr.enc_kc128)) {
926 expect_kc := g_pars.encr.enc_kc128;
927 } else if (alg_rsl == RSL_ALG_ID_A5_0) {
928 /* When A5/0 is chosen, no encryption is active, so technically, no key is needed. However, 3GPP TS
929 * 48.058 9.3.7 Encryption Information stays quite silent about presence or absence of a key for A5/0.
930 * The only thing specified is how to indicate the length of the key; the possibility that the key may
931 * be zero length is not explicitly mentioned. So it seems that we should always send the key along,
932 * even for A5/0. Still, let's also allow a zero length key for A5/0. */
933 expect_kc := (g_pars.encr.enc_key, ''O);
934 } else {
935 expect_kc := g_pars.encr.enc_key;
936 }
937 log("for encryption algo ", alg_rsl, " expect kc = ", expect_kc);
938
939 if (not f_rsl_find_ie(rsl, RSL_IE_ENCR_INFO, encr_info)) {
940 if (alg_rsl == RSL_ALG_ID_A5_0) {
941 /* For A5/0, encryption is not active. It is fine to omit the Encryption Information in this
942 * case. Note that the first channel may see an RSL Encryption Command with A5/0 indicated, and
943 * a subsequent handover may activate a new channel without any Encryption Information. */
944 setverdict(pass);
945 return;
946 }
947 setverdict(fail, "Missing Encryption Information IE in ", rsl.msg_type);
948 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
949 return;
950 }
951
952 if (not match(encr_info, tr_EncrInfo(alg_rsl, expect_kc))) {
953 setverdict(fail, "Unexpected Kc in Encryption Information IE in ", rsl.msg_type);
954 Misc_Helpers.f_shutdown(__BFILE__, __LINE__);
955 return;
956 }
957 setverdict(pass);
958}
959
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200960function f_cipher_mode(TestHdlrEncrParams enc, boolean exp_fail := false,
961 RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC)
Harald Welte38b2a102017-12-23 02:42:58 +0100962runs on MSC_ConnHdlr {
Harald Welte73cd2712017-12-17 00:44:52 +0100963 var PDU_BSSAP bssap;
964 var RSL_Message rsl;
965
Neels Hofmeyr6c388f22021-06-11 02:36:56 +0200966 if (isvalue(enc.enc_kc128)) {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +0100967 BSSAP.send(ts_BSSMAP_CipherModeCmdKc128(enc.enc_alg_permitted, enc.enc_key, valueof(enc.enc_kc128)));
Harald Welte73cd2712017-12-17 00:44:52 +0100968 } else {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +0100969 BSSAP.send(ts_BSSMAP_CipherModeCmd(enc.enc_alg_permitted, enc.enc_key));
Harald Welte73cd2712017-12-17 00:44:52 +0100970 }
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100971
Harald Welte73cd2712017-12-17 00:44:52 +0100972 alt {
973 /* RSL/UE Side */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200974 [] rsl_pt.receive(tr_RSL_ENCR_CMD(g_chan_nr)) -> value rsl {
Harald Welte73cd2712017-12-17 00:44:52 +0100975 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[3].body.l3_info.payload);
976 log("Rx L3 from net: ", l3);
Neels Hofmeyr72749342021-06-11 02:41:37 +0200977
Neels Hofmeyr58ffceb2021-06-21 02:17:30 +0200978 f_verify_encr_info(rsl);
979
Harald Welte73cd2712017-12-17 00:44:52 +0100980 if (ischosen(l3.msgs.rrm.cipheringModeCommand)) {
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200981 f_rsl_reply(ts_RRM_CiphModeCompl, rsl, rsl_pt := rsl_pt);
Harald Welte73cd2712017-12-17 00:44:52 +0100982 }
983 repeat;
984 }
985 [] BSSAP.receive(tr_BSSMAP_CipherModeCompl) -> value bssap {
Harald Welte38b2a102017-12-23 02:42:58 +0100986 if (exp_fail == true) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100987 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Cipher Mode Complete");
Harald Welte38b2a102017-12-23 02:42:58 +0100988 } else {
989 setverdict(pass);
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +0100990 var RSL_AlgId alg_rsl := f_cipher_mode_bssmap_to_rsl(g_pars.encr.enc_alg_expect);
Neels Hofmeyr5e31cfc2021-06-11 02:42:11 +0200991 if (oct2int(bssap.pdu.bssmap.cipherModeComplete.chosenEncryptionAlgorithm.algorithmIdentifier) != enum2int(alg_rsl)) {
992 setverdict(fail, "Unexpected Encryption Algorithm ID in BSSMAP Cipher Mode Complete");
993 }
Harald Welte38b2a102017-12-23 02:42:58 +0100994 }
Harald Welte73cd2712017-12-17 00:44:52 +0100995 }
996 [] BSSAP.receive(tr_BSSMAP_CipherModeRej) -> value bssap {
Harald Welte38b2a102017-12-23 02:42:58 +0100997 if (exp_fail == false) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100998 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Ciphering Mode Reject");
Harald Welte38b2a102017-12-23 02:42:58 +0100999 } else {
1000 setverdict(pass);
1001 }
Harald Welte73cd2712017-12-17 00:44:52 +01001002 }
1003 }
1004}
1005
Harald Welte211219e2018-01-29 22:03:36 +01001006/* Convert from Ericsson ChanDesc2 format to Osmocom RslChannelNr format */
1007function f_ChDesc2RslChanNr(ChannelDescription2_V ch_desc, out RslChannelNr chan_nr, out GsmArfcn arfcn) {
1008 var BIT5 inp := ch_desc.channelTypeandTDMAOffset;
Harald Welte6fa1f732018-03-21 22:46:16 +01001009 var uint3_t tn := bit2int(ch_desc.timeslotNumber);
Harald Welte211219e2018-01-29 22:03:36 +01001010
Vadim Yanitskiy2bcea3d2021-11-18 19:13:48 +03001011 select (inp) {
1012 case ('00001'B) { /* TCH/F */
Harald Welte6fa1f732018-03-21 22:46:16 +01001013 chan_nr := valueof(t_RslChanNr_Bm(tn));
Vadim Yanitskiy2bcea3d2021-11-18 19:13:48 +03001014 }
1015 case ('11101'B) { /* VAMOS TCH/F */
Neels Hofmeyr9c3b82f2021-05-27 00:38:59 +02001016 chan_nr := valueof(t_RslChanNr_Osmo_VAMOS_Bm(tn));
Vadim Yanitskiy2bcea3d2021-11-18 19:13:48 +03001017 }
1018 case ('0001?'B) { /* TCH/H */
Harald Welte6fa1f732018-03-21 22:46:16 +01001019 chan_nr := valueof(t_RslChanNr_Lm(tn, bit2int(substr(inp, 4, 1))));
Vadim Yanitskiy2bcea3d2021-11-18 19:13:48 +03001020 }
1021 case ('1111?'B) { /* VAMOS TCH/H */
Neels Hofmeyr9c3b82f2021-05-27 00:38:59 +02001022 chan_nr := valueof(t_RslChanNr_Osmo_VAMOS_Lm(tn, bit2int(substr(inp, 4, 1))));
Vadim Yanitskiy2bcea3d2021-11-18 19:13:48 +03001023 }
1024 case ('001??'B) { /* SDCCH/4 */
Harald Welte6fa1f732018-03-21 22:46:16 +01001025 chan_nr := valueof(t_RslChanNr_SDCCH4(tn, bit2int(substr(inp, 3, 2))));
Vadim Yanitskiy2bcea3d2021-11-18 19:13:48 +03001026 }
1027 case ('01???'B) { /* SDCCH/8 */
Harald Welte6fa1f732018-03-21 22:46:16 +01001028 chan_nr := valueof(t_RslChanNr_SDCCH8(tn, bit2int(substr(inp, 2, 3))));
Vadim Yanitskiy2bcea3d2021-11-18 19:13:48 +03001029 }
1030 case else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001031 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown ChDesc!");
Vadim Yanitskiy2bcea3d2021-11-18 19:13:48 +03001032 }
Harald Welte211219e2018-01-29 22:03:36 +01001033 }
1034
1035 if (ch_desc.octet3 and4b '10'O == '10'O) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001036 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No support for Hopping");
Harald Welte211219e2018-01-29 22:03:36 +01001037 } else {
1038 var OCT2 concat := ch_desc.octet3 & ch_desc.octet4;
1039 arfcn := oct2int(concat);
1040 }
1041}
1042
1043type record AssignmentState {
1044 /* global */
1045 boolean voice_call,
1046 boolean is_assignment,
1047 /* Assignment related bits */
1048 boolean rr_ass_cmpl_seen,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001049 boolean old_lchan_deact_sacch_seen,
1050 boolean old_lchan_rll_rel_req_seen,
Harald Welte21583082018-01-29 22:28:26 +01001051 boolean assignment_done,
Harald Welte211219e2018-01-29 22:03:36 +01001052 RslChannelNr old_chan_nr,
1053 /* Modify related bits */
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02001054 PDU_ML3_NW_MS rr_channel_mode_modify_msg optional,
Harald Welte211219e2018-01-29 22:03:36 +01001055 boolean rr_modify_seen,
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02001056 RSL_Message rsl_mode_modify_msg optional,
Harald Welte21583082018-01-29 22:28:26 +01001057 boolean modify_done
Harald Welte211219e2018-01-29 22:03:36 +01001058}
1059
1060template (value) AssignmentState ts_AssignmentStateInit := {
1061 voice_call := false,
1062 is_assignment := false,
1063 rr_ass_cmpl_seen := false,
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001064 old_lchan_deact_sacch_seen := false,
1065 old_lchan_rll_rel_req_seen := false,
Harald Welte21583082018-01-29 22:28:26 +01001066 assignment_done := false,
Harald Welte211219e2018-01-29 22:03:36 +01001067 old_chan_nr := -,
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02001068 rr_channel_mode_modify_msg := omit,
Harald Welte211219e2018-01-29 22:03:36 +01001069 rr_modify_seen := false,
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02001070 rsl_mode_modify_msg := omit,
Harald Welte21583082018-01-29 22:28:26 +01001071 modify_done := false
Harald Welte211219e2018-01-29 22:03:36 +01001072}
1073
Harald Welte8a9bf6f2018-05-10 22:00:49 +02001074private template RSL_IE_Body tr_EncrInfo(template RSL_AlgId alg, template octetstring key) := {
1075 encr_info := {
1076 len := ?,
1077 alg_id := alg,
1078 key := key
1079 }
1080}
1081
1082/* ensure the RSL CHAN ACT (during assignment) contains values we expect depending on test case */
1083private function f_check_chan_act(AssignmentState st, RSL_Message chan_act) runs on MSC_ConnHdlr {
1084 var RSL_IE_Body encr_info;
Pau Espin Pedrol3d008ae2019-10-28 13:35:46 +01001085 var RSL_IE_Body ms_power_param;
Pau Espin Pedrolf7630a62019-10-28 15:07:08 +01001086 var RSL_IE_Body ms_power;
Pau Espin Pedrol3d008ae2019-10-28 13:35:46 +01001087
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01001088 if (ispresent(g_pars.encr) and g_pars.encr.enc_alg_permitted != '01'O) {
Harald Welte8a9bf6f2018-05-10 22:00:49 +02001089 if (not f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001090 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Missing Encryption IE in CHAN ACT");
Harald Welte8a9bf6f2018-05-10 22:00:49 +02001091 } else {
Neels Hofmeyrd23e8a02022-02-17 01:55:59 +01001092 var RSL_AlgId alg := f_cipher_mode_bssmap_to_rsl(g_pars.encr.enc_alg_expect);
Neels Hofmeyr0588cad2021-06-11 01:38:18 +02001093 var octetstring expect_key;
1094 if (alg == RSL_ALG_ID_A5_4) {
1095 expect_key := g_pars.encr.enc_kc128;
1096 } else {
1097 expect_key := g_pars.encr.enc_key;
1098 }
1099 if (not match(encr_info, tr_EncrInfo(alg, expect_key))) {
1100 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1101 "Unexpected Kc in Encryption IE in RSL ENCR CMD");
Harald Welte8a9bf6f2018-05-10 22:00:49 +02001102 }
1103 }
1104 } else {
1105 if (f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) {
1106 if (encr_info.encr_info.alg_id != RSL_ALG_ID_A5_0) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001107 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Encryption in CHAN ACT");
Harald Welte8a9bf6f2018-05-10 22:00:49 +02001108 }
1109 }
1110 }
1111 /* FIXME: validate RSL_IE_ACT_TYPE, RSL_IE_CHAN_MODE, RSL_IE_CHAN_IDENT, RSL_IE_BS_POWER,
Pau Espin Pedrol7a9ccf82019-11-05 11:33:33 +01001112 * RSL_IE_TIMING_ADVANCE */
Pau Espin Pedrol3d008ae2019-10-28 13:35:46 +01001113
Pau Espin Pedrol8f773632019-11-05 11:46:53 +01001114 if (g_pars.exp_ms_power_params and not f_rsl_find_ie(chan_act, RSL_IE_MS_POWER_PARAM, ms_power_param)) {
Pau Espin Pedrol3d008ae2019-10-28 13:35:46 +01001115 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "IE MS Power Parameters not found in CHAN ACT");
1116 }
1117
Pau Espin Pedrolf7630a62019-10-28 15:07:08 +01001118 if (not f_rsl_find_ie(chan_act, RSL_IE_MS_POWER, ms_power)) {
1119 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "IE MS Power not found in CHAN ACT");
1120 } else {
1121 if (not match(ms_power.ms_power, tr_RSL_IE_MS_Power(g_pars.exp_ms_power_level, false))) {
Pau Espin Pedrol7a9ccf82019-11-05 11:33:33 +01001122 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Wrong MS Power IE in CHAN ACT, ", ms_power.ms_power.power_level, " vs exp ", g_pars.exp_ms_power_level));
Pau Espin Pedrolf7630a62019-10-28 15:07:08 +01001123 }
1124 }
1125
Harald Welte8a9bf6f2018-05-10 22:00:49 +02001126}
1127
Neels Hofmeyr6a955cc2021-10-02 14:53:48 +02001128function rr_chan_desc_tsc(ChannelDescription2_V cd2)
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +02001129 return uint3_t
1130{
1131 var uint3_t tsc := oct2int(cd2.octet3);
1132 tsc := tsc / 32; /* shl 5 */
1133 return tsc;
1134}
1135
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +02001136altstep as_assignment(inout AssignmentState st, RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC) runs on MSC_ConnHdlr {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001137 var RSL_Message rsl;
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +02001138 [not st.rr_ass_cmpl_seen] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
Harald Welte211219e2018-01-29 22:03:36 +01001139 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
1140 log("Rx L3 from net: ", l3);
1141 if (ischosen(l3.msgs.rrm.assignmentCommand)) {
1142 var RslChannelNr new_chan_nr;
1143 var GsmArfcn arfcn;
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +02001144
1145 if (not istemplatekind(g_pars.expect_tsc, "omit")) {
1146 var uint3_t got_tsc := rr_chan_desc_tsc(l3.msgs.rrm.assignmentCommand.descrOf1stChAfterTime);
1147 if (not match(got_tsc, g_pars.expect_tsc)) {
1148 setverdict(fail, "RR Assignment: unexpected TSC in Channel Description: expected ",
1149 g_pars.expect_tsc, " got ", got_tsc);
1150 mtc.stop;
1151 }
1152 }
1153
Harald Welte211219e2018-01-29 22:03:36 +01001154 f_ChDesc2RslChanNr(l3.msgs.rrm.assignmentCommand.descrOf1stChAfterTime,
1155 new_chan_nr, arfcn);
1156 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
Harald Weltec1a2fff2017-12-17 11:06:19 +01001157
Harald Welte211219e2018-01-29 22:03:36 +01001158 /* register our component for this channel number at the RSL Emulation */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +02001159 f_rslem_register(0, new_chan_nr, PT := rsl_proc_pt);
Vadim Yanitskiy539e6302020-06-22 03:11:54 +07001160 /* dispatch queued messages for this channel (if any) */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +02001161 f_rslem_dchan_queue_dispatch(PT := rsl_proc_pt);
Vadim Yanitskiy539e6302020-06-22 03:11:54 +07001162
Harald Welte211219e2018-01-29 22:03:36 +01001163 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_AssignmentComplete('00'O));
1164 /* send assignment complete over the new channel */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +02001165 rsl_pt.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
Harald Welte211219e2018-01-29 22:03:36 +01001166 enc_PDU_ML3_MS_NW(l3_tx)));
1167 /* by default, send via the new channel from now */
1168 st.old_chan_nr := g_chan_nr;
1169 g_chan_nr := new_chan_nr;
1170 st.rr_ass_cmpl_seen := true;
Harald Welte8a9bf6f2018-05-10 22:00:49 +02001171 /* obtain channel activation from RSL_Emulation for new channel */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +02001172 var RSL_Message chan_act := f_rslem_get_last_act(rsl_proc_pt, 0, g_chan_nr);
Harald Welte8a9bf6f2018-05-10 22:00:49 +02001173 /* check it (e.g. for correct ciphering parameters) */
1174 f_check_chan_act(st, chan_act);
Harald Welte211219e2018-01-29 22:03:36 +01001175 repeat;
1176 } else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001177 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected L3 received", l3));
Harald Weltec1a2fff2017-12-17 11:06:19 +01001178 }
Harald Welte211219e2018-01-29 22:03:36 +01001179 }
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +02001180 [st.rr_ass_cmpl_seen] rsl_pt.receive(tr_RSL_DEACT_SACCH(st.old_chan_nr)) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001181 st.old_lchan_deact_sacch_seen := true;
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01001182 repeat;
1183 }
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +02001184 [st.rr_ass_cmpl_seen] rsl_pt.receive(tr_RSL_REL_REQ(st.old_chan_nr, tr_RslLinkID_DCCH(0))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001185 st.old_lchan_rll_rel_req_seen := true;
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +02001186 rsl_pt.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
Harald Welte211219e2018-01-29 22:03:36 +01001187 repeat;
1188 }
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +02001189 [st.rr_ass_cmpl_seen] rsl_pt.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) {
1190 rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr));
Harald Welte1909f462018-01-29 22:29:29 +01001191 /* unregister for old channel number in RSL emulation */
1192 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +02001193 f_rslem_unregister(0, st.old_chan_nr, PT := rsl_proc_pt);
Harald Welte21583082018-01-29 22:28:26 +01001194 st.assignment_done := true;
Harald Welte211219e2018-01-29 22:03:36 +01001195 repeat;
1196 }
1197}
1198
1199altstep as_modify(inout AssignmentState st) runs on MSC_ConnHdlr {
1200 /* no assignment, just mode modify */
1201 var RSL_Message rsl;
1202
1203 [st.voice_call and not st.rr_modify_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
Harald Weltec1a2fff2017-12-17 11:06:19 +01001204 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
1205 log("Rx L3 from net: ", l3);
1206 if (ischosen(l3.msgs.rrm.channelModeModify)) {
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02001207 st.rr_channel_mode_modify_msg := l3;
Harald Weltec1a2fff2017-12-17 11:06:19 +01001208 f_rsl_reply(ts_RRM_ModeModifyAck(l3.msgs.rrm.channelModeModify.channelDescription,
1209 l3.msgs.rrm.channelModeModify.channelMode), rsl);
Harald Welte211219e2018-01-29 22:03:36 +01001210 st.rr_modify_seen := true;
Harald Weltec1a2fff2017-12-17 11:06:19 +01001211 }
1212 repeat;
1213 }
Harald Welte211219e2018-01-29 22:03:36 +01001214 [st.voice_call and st.rr_modify_seen] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_MODE_MODIFY_REQ)) -> value rsl {
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02001215 st.rsl_mode_modify_msg := rsl;
Harald Weltec1a2fff2017-12-17 11:06:19 +01001216 RSL.send(ts_RSL_MODE_MODIFY_ACK(g_chan_nr));
Harald Welte21583082018-01-29 22:28:26 +01001217 st.modify_done := true;
Harald Weltec1a2fff2017-12-17 11:06:19 +01001218 repeat;
1219 }
Harald Welte211219e2018-01-29 22:03:36 +01001220}
Daniel Willmann191e0d92018-01-17 12:44:35 +01001221
Harald Welte211219e2018-01-29 22:03:36 +01001222/* Determine if given rsl_chan_nr is compatible with given BSSMAP ChannelType */
1223function f_channel_compatible(BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr)
1224return boolean {
1225 select (bssmap.speechOrDataIndicator) {
1226 case ('0011'B) { /* Signalling */
1227 /* all channels support signalling */
1228 return true;
1229 }
1230 case else { /* Speech, Speech+CTM or CSD */
1231 select (bssmap.channelRateAndType) {
1232 case ('08'O) { /* TCH/F */
1233 select (rsl_chan_nr) {
1234 case (t_RslChanNr_Bm(?)) { return true; }
1235 }
1236 }
1237 case ('09'O) { /* TCH/H */
1238 select (rsl_chan_nr) {
1239 case (t_RslChanNr_Lm(?, ?)) { return true; }
1240 }
1241 }
1242 case else { /* full or half-rate */
1243 select (rsl_chan_nr) {
1244 case (t_RslChanNr_Bm(?)) { return true; }
1245 case (t_RslChanNr_Lm(?, ?)) { return true; }
1246 }
1247 }
1248 }
Harald Weltec1a2fff2017-12-17 11:06:19 +01001249 }
Harald Welte211219e2018-01-29 22:03:36 +01001250 }
1251 return false;
1252}
Daniel Willmann191e0d92018-01-17 12:44:35 +01001253
Philipp Maier8ef527e2018-05-18 11:12:50 +02001254/* Determine if the channel mode specified within rsl_chan_nr requires a
1255 * MODE MODIFY in to match the channel mode specified by given BSSMAP
1256 * ChannelType */
Neels Hofmeyrc2425cc2021-04-19 13:19:55 +00001257function f_channel_needs_modify(TELNETasp_PT vty, BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr)
Philipp Maier8ef527e2018-05-18 11:12:50 +02001258return boolean {
1259
Philipp Maier8ef527e2018-05-18 11:12:50 +02001260 var boolean current_signalling := false;
1261 var boolean desired_signalling := false;
1262
1263 select (rsl_chan_nr) {
1264 case (t_RslChanNr_SDCCH4(?, ?)) { current_signalling := true; }
1265 case (t_RslChanNr_SDCCH8(?, ?)) { current_signalling := true; }
Neels Hofmeyrc2425cc2021-04-19 13:19:55 +00001266 case (t_RslChanNr_Bm(?)) {
1267 /* TCH/F, always subslot 0 */
1268 var charstring res := f_vty_transceive_ret(vty, "show lchan 0 0 " & int2str(rsl_chan_nr.tn) & " 0");
1269 if (f_strstr(res, "Channel Mode / Codec: SIGNALLING", 0) >= 0) {
1270 current_signalling := true;
1271 }
1272 }
1273 case (t_RslChanNr_Lm(?, ?)) {
1274 /* TCH/H */
1275 var charstring res := f_vty_transceive_ret(vty, "show lchan 0 0 " & int2str(rsl_chan_nr.tn)
1276 & " " & int2str(rsl_chan_nr.u.lm.sub_chan));
1277 if (f_strstr(res, "Channel Mode / Codec: SIGNALLING", 0) >= 0) {
1278 current_signalling := true;
1279 }
1280 }
Philipp Maier8ef527e2018-05-18 11:12:50 +02001281 }
1282
1283 if (bssmap.speechOrDataIndicator == '0011'B) {
1284 desired_signalling := true;
1285 }
1286
1287 if (current_signalling == desired_signalling) {
1288 /* The desired channel mode is equal to the one we currently
1289 * have, there is no mode modification needed or expected */
1290 return false;
1291 } else {
1292 /* The desired channel mode and the current channel mode do
1293 * not match. A mode modification is required */
1294 return true;
1295 }
1296}
1297
Harald Weltecc0b0142018-05-29 15:19:33 +02001298/* patch an BSSMAP ASS REQ with LCLS related IEs, depending on g_params */
1299function f_ass_patch_lcls(inout template (omit) PDU_BSSAP ass_tpl,
1300 inout template PDU_BSSAP ass_cpl) runs on MSC_ConnHdlr {
1301 if (istemplatekind(ass_tpl, "omit")) {
1302 return;
1303 }
1304 if (ispresent(g_pars.lcls.gcr)) {
1305 ass_tpl.pdu.bssmap.assignmentRequest.globalCallReference := ts_BSSMAP_IE_GCR(g_pars.lcls.gcr);
1306 }
1307 if (ispresent(g_pars.lcls.cfg)) {
1308 ass_tpl.pdu.bssmap.assignmentRequest.lCLS_Configuration := ts_BSSMAP_IE_LclsCfg(g_pars.lcls.cfg);
1309 }
1310 if (ispresent(g_pars.lcls.csc)) {
1311 ass_tpl.pdu.bssmap.assignmentRequest.lCLS_ConnectionStatusControl := ts_BSSMAP_IE_LclsCsc(g_pars.lcls.csc);
1312 }
Harald Welte343b7742018-06-05 23:41:37 +02001313 if (ischosen(ass_cpl.pdu.bssmap.assignmentComplete)) {
1314 if (ispresent(g_pars.lcls.exp_sts)) {
1315 ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status := tr_BSSMAP_IE_LclsSts(g_pars.lcls.exp_sts);
1316 } else {
1317 ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status := omit;
1318 }
Harald Weltecc0b0142018-05-29 15:19:33 +02001319 }
1320}
1321
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001322/* Send a MGCP request through MGCP-over-IPA from MSC side and receive a (matching!) response */
1323function mgcp_transceive_mgw(template MgcpCommand cmd, template MgcpResponse resp := ?) runs on MSC_ConnHdlr {
1324 template MgcpResponse resp_any := ?
1325 var MgcpResponse resp_val;
1326 resp.line.trans_id := cmd.line.trans_id;
1327 timer T := 5.0;
1328
1329 BSSAP.send(cmd);
1330 T.start;
1331 alt {
1332 [] as_Media_mgw();
1333 [] BSSAP.receive(resp) -> value resp_val { }
1334 [] BSSAP.receive(resp_any) {
1335 setverdict(fail, "Response didn't match template");
1336 mtc.stop;
1337 }
1338 [] BSSAP.receive { repeat; }
1339 [] T.timeout {
1340 setverdict(fail, "Timeout waiting for response to ", cmd);
1341 mtc.stop;
1342 }
1343 }
1344 T.stop;
1345}
1346
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001347/* Helper function to check if the activity on the MGCP matches what we
1348 * expected */
1349function f_check_mgcp_expectations() runs on MSC_ConnHdlr {
1350 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier0a5d7e72018-07-16 15:13:11 +02001351 log(testcasename(), ": Check MGCP test expectations for g_media.mgcp_conn[", i , "]:",
1352 " crcx_seen=", g_media.mgcp_conn[i].crcx_seen, ", crcx_seen_exp=", g_media.mgcp_conn[i].crcx_seen_exp,
1353 ", mdcx_seen=", g_media.mgcp_conn[i].mdcx_seen, ", mdcx_seen_exp=", g_media.mgcp_conn[i].mdcx_seen_exp);
1354
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001355 if(g_media.mgcp_conn[i].crcx_seen != g_media.mgcp_conn[i].crcx_seen_exp) {
Max4b0f4962018-11-06 19:20:24 +01001356 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unexpected number of MGW-CRCX transactions on g_media.mgcp_conn[" & int2str(i) & "]");
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001357 }
1358 if(g_media.mgcp_conn[i].mdcx_seen != g_media.mgcp_conn[i].mdcx_seen_exp) {
Max4b0f4962018-11-06 19:20:24 +01001359 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unexpected number of MGW-MDCX transactions on g_media.mgcp_conn[" & int2str(i) & "]");
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001360 }
1361 }
1362}
1363
Harald Welte211219e2018-01-29 22:03:36 +01001364/* establish a channel fully, expecting an assignment matching 'exp' */
Harald Welte7a14fd52018-05-10 22:26:55 +02001365function f_establish_fully(template (omit) PDU_BSSAP ass_tpl, template PDU_BSSAP exp_ass_cpl)
1366runs on MSC_ConnHdlr {
Philipp Maier11a58942018-06-25 16:40:48 +02001367
1368 var BSSMAP_FIELD_CodecType codecType;
Philipp Maier48aeeec2018-09-14 18:20:04 +02001369 timer T := 10.0;
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001370
Philipp Maier4ce978c2020-08-11 22:54:07 +02001371 if (not istemplatekind(ass_tpl, "omit") and isvalue(ass_tpl.pdu.bssmap.assignmentRequest.codecList)) {
Philipp Maier11a58942018-06-25 16:40:48 +02001372 codecType := valueof(ass_tpl.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
1373 } else {
1374 /* Make sure a meaningful default is assigned in case the
1375 * codecList is not populated */
1376 codecType := FR_AMR;
1377 }
1378
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001379 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
Harald Welte7a14fd52018-05-10 22:26:55 +02001380
Harald Weltecc0b0142018-05-29 15:19:33 +02001381 /* patch in the LCLS related items, as needed */
1382 f_ass_patch_lcls(ass_tpl, exp_ass_cpl);
1383
Harald Welte7a14fd52018-05-10 22:26:55 +02001384 f_create_chan_and_exp();
Harald Welte7a14fd52018-05-10 22:26:55 +02001385
1386 /* start ciphering, if requested */
1387 if (ispresent(g_pars.encr)) {
Neels Hofmeyr6c388f22021-06-11 02:36:56 +02001388 f_cipher_mode(g_pars.encr);
Harald Welte7a14fd52018-05-10 22:26:55 +02001389 }
1390
1391 /* bail out early if no assignment requested */
1392 if (istemplatekind(ass_tpl, "omit")) {
1393 return;
1394 }
1395
1396 var PDU_BSSAP ass_cmd := valueof(ass_tpl);
Harald Welte211219e2018-01-29 22:03:36 +01001397 var PDU_BSSAP bssap;
Harald Welte211219e2018-01-29 22:03:36 +01001398 var boolean exp_compl := ischosen(exp_ass_cpl.pdu.bssmap.assignmentComplete);
Philipp Maier86f39202018-02-07 14:40:09 +01001399 var boolean exp_fail := ischosen(exp_ass_cpl.pdu.bssmap.assignmentFailure);
Philipp Maier8ef527e2018-05-18 11:12:50 +02001400 var boolean exp_modify;
Philipp Maier48aeeec2018-09-14 18:20:04 +02001401
Harald Welte211219e2018-01-29 22:03:36 +01001402 var ExpectCriteria mgcpcrit := {
1403 connid := omit,
1404 endpoint := omit,
1405 transid := omit
1406 };
1407 var AssignmentState st := valueof(ts_AssignmentStateInit);
1408 /* if the channel type is SIGNAL, we're not handling a voice call */
1409 if (ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechOrDataIndicator != '0011'B) {
1410 st.voice_call := true;
Philipp Maier8ef527e2018-05-18 11:12:50 +02001411 exp_modify := true;
Harald Welte211219e2018-01-29 22:03:36 +01001412 }
Philipp Maier8ef527e2018-05-18 11:12:50 +02001413
Harald Welte211219e2018-01-29 22:03:36 +01001414 /* determine if the current channel can support the given service or not */
1415 if (not f_channel_compatible(ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr)) {
1416 st.is_assignment := true;
Philipp Maier8ef527e2018-05-18 11:12:50 +02001417
1418 /* We decided to assign a new channel, so we do not expect
1419 * any mode modify messages on RSL */
1420 exp_modify := false;
1421 } else {
1422 /* We will continue working with the currently assigned
1423 * channel, we must now check if the mode of the current
1424 * channel is compatible. If not we expect the BSC to modify
1425 * the mode */
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02001426 st.is_assignment := false;
Neels Hofmeyrc2425cc2021-04-19 13:19:55 +00001427 exp_modify := f_channel_needs_modify(BSCVTY, ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr);
Harald Welte211219e2018-01-29 22:03:36 +01001428 }
1429
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001430 /* Some test situations will involve MGCP transactions on a media
1431 * gateway. Depending on the situation, we set up how many of each MGCP
1432 * message type are expected to be exchanged. */
1433 if (isbound(exp_ass_cpl.pdu.bssmap.assignmentFailure)) {
1434 /* For tests that expect the assignment to fail, assume that
1435 * there will be no MGW communication as well. */
1436 g_media.mgcp_conn[0].crcx_seen_exp := 0;
1437 g_media.mgcp_conn[0].mdcx_seen_exp := 0;
1438 g_media.mgcp_conn[1].crcx_seen_exp := 0;
1439 g_media.mgcp_conn[1].mdcx_seen_exp := 0;
1440 } else if (st.voice_call) {
1441 /* For voice calls we expect the following MGCP activity */
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001442 g_media.mgcp_conn[0].crcx_seen_exp := 1;
1443 g_media.mgcp_conn[0].mdcx_seen_exp := 1;
1444 g_media.mgcp_conn[1].crcx_seen_exp := 1;
1445 g_media.mgcp_conn[1].mdcx_seen_exp := 0;
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001446 }
1447
Vadim Yanitskiy539e6302020-06-22 03:11:54 +07001448 /* On receipt of the BSSAP Assignment Command, the IUT (osmo-bsc) will allocate
1449 * a channel and send us RR Assignment Command together with ip.access CRCX.
1450 * There is a risk that the RSL Emulation component would dequeue and process
1451 * ip.access CRCX faster than we process the Assignment Command and register
1452 * the corresponding handler for the indicated RSL channel number. This would
1453 * result in a failure, because at that moment there will be no handler for
1454 * ip.access CRCX. Let's guard against this and enable additional queueing. */
1455 f_rslem_dchan_queue_enable();
1456
Harald Welte211219e2018-01-29 22:03:36 +01001457 f_create_mgcp_expect(mgcpcrit);
1458 BSSAP.send(ass_cmd);
1459
1460 T.start;
1461 alt {
1462 /* assignment related bits */
1463 [st.is_assignment] as_assignment(st);
1464
1465 /* modify related bits */
Philipp Maier8ef527e2018-05-18 11:12:50 +02001466 [not st.is_assignment and exp_modify] as_modify(st);
Harald Welte211219e2018-01-29 22:03:36 +01001467
1468 /* voice call related bits (IPA CRCX/MDCX + MGCP) */
1469 [st.voice_call] as_Media();
1470
1471 /* if we receive exactly what we expected, always return + pass */
Philipp Maier8ef527e2018-05-18 11:12:50 +02001472 [st.is_assignment and st.assignment_done or (not st.is_assignment and (st.modify_done or not exp_modify))] BSSAP.receive(exp_ass_cpl) -> value bssap {
Harald Welte211219e2018-01-29 22:03:36 +01001473 setverdict(pass);
1474 }
Philipp Maier86f39202018-02-07 14:40:09 +01001475 [exp_fail] BSSAP.receive(exp_ass_cpl) -> value bssap {
1476 setverdict(pass);
1477 }
Harald Welte21583082018-01-29 22:28:26 +01001478 [(st.is_assignment and st.assignment_done or
Philipp Maier8ef527e2018-05-18 11:12:50 +02001479 (not st.is_assignment and (st.modify_done or not exp_modify))) and
Harald Welte21583082018-01-29 22:28:26 +01001480 exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001481 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching ASSIGNMENT COMPLETE");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001482 }
1483 [exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001484 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected ASSIGNMENT FAIL");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001485 }
1486 [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001487 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected ASSIGNMENT COMPLETE");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001488 }
1489 [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001490 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching ASSIGNMENT FAIL");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001491 }
1492 [] T.timeout {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASSIGNMENT COMPLETE");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001494 }
1495 }
Harald Welte211219e2018-01-29 22:03:36 +01001496 log("g_media ", g_media);
1497 if (not isbound(bssap)) {
Daniel Willmannafce8662018-07-06 23:11:32 +02001498 mtc.stop;
Harald Welte211219e2018-01-29 22:03:36 +01001499 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001500
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02001501 if (exp_modify) {
1502 /* Verify that the RR Channel Mode Modify and RSL MODE MODIFY message asked for the expected channel
1503 * mode. */
1504 /* TODO: more precisely expect the different types of speech? */
1505 var OCT1 rr_channel_mode := st.rr_channel_mode_modify_msg.msgs.rrm.channelModeModify.channelMode.mode;
1506
1507 if (st.voice_call and rr_channel_mode == '00'O) {
1508 setverdict(fail, "f_establish_fully(): Expected RR Channel Mode Modify",
1509 " to a speech mode, but got channelMode == ", rr_channel_mode);
1510 mtc.stop;
1511 } else if (not st.voice_call and rr_channel_mode != '00'O) {
1512 setverdict(fail, "f_establish_fully(): Expected RR Channel Mode Modify",
1513 " to signalling mode, but got channelMode == ", rr_channel_mode);
1514 mtc.stop;
1515 }
1516
1517 var RSL_IE_Body chan_mode_ie;
1518 if (not f_rsl_find_ie(st.rsl_mode_modify_msg, RSL_IE_CHAN_MODE, chan_mode_ie)) {
1519 setverdict(fail, "RSL MODE MODIFY message lacks a Channel Mode IE");
1520 mtc.stop;
1521 }
1522 var RSL_SpeechDataInd rsl_spd_ind := chan_mode_ie.chan_mode.spd_ind;
1523 if (st.voice_call and rsl_spd_ind != RSL_SPDI_SPEECH) {
1524 setverdict(fail, "f_establish_fully(): Expected RSL MODE MODIFY",
1525 " to a speech mode, but got spd_ind == ", rsl_spd_ind);
1526 mtc.stop;
1527 } else if (not st.voice_call and rsl_spd_ind != RSL_SPDI_SIGN) {
1528 setverdict(fail, "f_establish_fully(): Expected RSL MODE MODIFY",
1529 " to signalling mode, but got spd_ind == ", rsl_spd_ind);
1530 mtc.stop;
1531 }
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +02001532
1533 if (not istemplatekind(g_pars.expect_tsc, "omit")) {
1534 var uint3_t got_tsc := rr_chan_desc_tsc(st.rr_channel_mode_modify_msg.msgs.rrm.channelModeModify.channelDescription);
1535 if (not match(got_tsc, g_pars.expect_tsc)) {
1536 setverdict(fail, "RR Channel Mode Modify: unexpected TSC in Channel Description: expected ",
1537 g_pars.expect_tsc, " got ", got_tsc);
1538 mtc.stop;
1539 }
1540 }
1541
1542 } else {
1543 /* not exp_modify, so this did a Channel Activate */
1544
1545 /* Check the TSC */
1546 if (not istemplatekind(g_pars.expect_tsc, "omit")) {
1547 var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
1548 var RSL_IE_Body ie;
1549 if (f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, ie)) {
1550 var uint3_t got_tsc := ie.chan_ident.ch_desc.v.tsc;
1551 if (not match(got_tsc, g_pars.expect_tsc)) {
1552 setverdict(fail, "RSL CHANnel ACTIVation: unexpected TSC in Channel Description: expected ",
1553 g_pars.expect_tsc, " got ", got_tsc);
1554 mtc.stop;
1555 }
1556 }
1557 }
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02001558 }
1559
Philipp Maiera0976e92018-07-16 15:19:42 +02001560 /* When the BSC detects that LCLS is possible it will cross the
1561 * connetions that point to the PBX side of the MGW. In our case this
1562 * is mgcp_conn[1]. The BSC performs this operation already before the
1563 * assignment complete is generated. This means we expect another MDCX
1564 * at mgcp_conn[1] when LCLS is expected. */
Max2eeb5112018-11-06 19:21:41 +01001565 if (g_pars.lcls.adjust_cx_exp and ispresent(exp_ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status.lCLS_BSS_StatusValue)) {
Philipp Maiera0976e92018-07-16 15:19:42 +02001566 if (valueof(exp_ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status.lCLS_BSS_StatusValue) == LCLS_STS_locally_switched) {
1567 g_media.mgcp_conn[1].mdcx_seen_exp := g_media.mgcp_conn[1].mdcx_seen_exp + 1;
1568
1569 }
1570 }
1571
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001572 if (not exp_fail and st.voice_call and not g_pars.aoip) {
1573 /* With SCCPLite, connect to BSC-located MGW using a CRCX + SDP.
1574 It is sent in MGCP over IPA in the BSC<->MSC (BSC-NAT)
1575 connection. BSC will forward it to its MGW. */
1576 var template MgcpCommand cmd;
1577 var template MgcpResponse resp;
1578 var integer cic := f_bssmap_ie_cic_2_int(ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode);
1579 var MgcpEndpoint ep := int2str(cic) & "@mgw"; /* 1: matches value configured in BSC_Tests.ttcn pass in AssignReq */
1580 var MgcpCallId call_id := '51234'H;
1581 var SDP_attribute_list attributes := { valueof(ts_SDP_ptime(20)) };
Pau Espin Pedrolf967afc2022-08-08 18:17:20 +02001582 if (g_pars.use_osmux_cn) {
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001583 cmd := ts_CRCX_osmux(get_next_trans_id(), ep, "sendrecv", call_id, cic);
1584 resp := tr_CRCX_ACK_osmux;
1585 } else {
1586 cmd := ts_CRCX(get_next_trans_id(), ep, "sendrecv", call_id);
1587 resp := tr_CRCX_ACK;
1588 }
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001589 cmd.sdp := ts_SDP(host_msc, host_mgw_rtp_v4, "23", "42",
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001590 14000, { int2str(g_media.mgcp_conn[1].rtp_pt) },
1591 { valueof(ts_SDP_ptime(20)) });
1592 mgcp_transceive_mgw(cmd, resp);
1593 }
1594
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001595 f_check_mgcp_expectations();
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001596
1597 if (st.is_assignment and st.assignment_done) {
1598 if (not st.old_lchan_deact_sacch_seen) {
1599 setverdict(fail, "f_establish_fully(): Assignment completed, but the old lchan was not",
1600 " released properly: expected a Deact SACCH on the old lchan, but saw none.");
1601 }
1602 if (st.old_lchan_rll_rel_req_seen) {
1603 setverdict(fail, "f_establish_fully(): Assignment completed, but the old lchan was not",
1604 " released properly: saw an RLL Release on the old lchan, but expecting none.");
1605 }
1606 }
Neels Hofmeyr9d686302021-04-25 19:02:29 +00001607
1608 var charstring lchan_info := f_vty_transceive_ret(BSCVTY, "show lchan 0 0 " & int2str(g_chan_nr.tn) & " 0");
1609 if (f_strstr(lchan_info, "State: ESTABLISHED") < 0) {
1610 log("after f_establish_fully(), 'show lchan' replied: ", lchan_info);
1611 setverdict(fail, "lchan is not in state ESTABLISHED");
1612 mtc.stop;
1613 }
Harald Welte930d0a72018-03-22 22:08:40 +01001614}
1615
Harald Welte261af4b2018-02-12 21:20:39 +01001616type record HandoverState {
1617 /* Assignment related bits */
1618 boolean rr_ho_cmpl_seen,
Philipp Maierc1e95c82018-07-18 16:03:00 +02001619 integer mdcx_seen_before_ho,
Harald Welte261af4b2018-02-12 21:20:39 +01001620 boolean handover_done,
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02001621 RslChannelNr old_chan_nr,
1622 uint3_t expect_target_tsc optional
Harald Welte261af4b2018-02-12 21:20:39 +01001623};
1624
1625altstep as_handover(inout HandoverState st) runs on MSC_ConnHdlr {
1626 var RSL_Message rsl;
1627 [not st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
1628 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
1629 log("Rx L3 from net: ", l3);
1630 if (ischosen(l3.msgs.rrm.handoverCommand)) {
1631 var RslChannelNr new_chan_nr;
1632 var GsmArfcn arfcn;
1633 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
1634 new_chan_nr, arfcn);
1635 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
1636
Neels Hofmeyrc741fcb2021-10-02 14:52:28 +02001637 /* Verify correct TSC in handoverCommand */
1638 if (ispresent(st.expect_target_tsc)) {
1639 var uint3_t got_tsc := rr_chan_desc_tsc(l3.msgs.rrm.handoverCommand.channelDescription2);
1640 if (not match(got_tsc, st.expect_target_tsc)) {
1641 setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ",
1642 st.expect_target_tsc, " got ", got_tsc);
1643 mtc.stop;
1644 } else {
1645 log("handoverCommand: verified TSC = ", got_tsc, " (matches ",
1646 st.expect_target_tsc, ")");
1647 }
1648 }
1649
Harald Welte261af4b2018-02-12 21:20:39 +01001650 /* register our component for this channel number at the RSL Emulation */
1651 f_rslem_register(0, new_chan_nr, RSL1_PROC);
1652
1653 /* resume processing of RSL DChan messages, which was temporarily suspended
1654 * before performing a hand-over */
1655 f_rslem_resume(RSL1_PROC);
1656
Neels Hofmeyr378a49c2018-06-15 22:18:43 +02001657 /* send handover detect */
1658 RSL1.send(ts_RSL_HANDO_DET(new_chan_nr));
1659 f_sleep(0.3);
1660
Harald Welte261af4b2018-02-12 21:20:39 +01001661 /* send handover complete over the new channel */
1662 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
Neels Hofmeyrd07ee132018-07-14 22:28:29 +02001663 RSL1.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
Harald Welte261af4b2018-02-12 21:20:39 +01001664 enc_PDU_ML3_MS_NW(l3_tx)));
1665 /* by default, send via the new channel from now */
1666 st.old_chan_nr := g_chan_nr;
1667 g_chan_nr := new_chan_nr;
1668 st.rr_ho_cmpl_seen := true;
Philipp Maierc1e95c82018-07-18 16:03:00 +02001669
1670 /* Memorize how many MDCX we have seen before. We need this number to detect
1671 * that we have received the handover related MDCX */
1672 st.mdcx_seen_before_ho := g_media.mgcp_conn[0].mdcx_seen;
Harald Welte261af4b2018-02-12 21:20:39 +01001673 repeat;
1674 } else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001675 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected L3 received", l3));
Harald Welte261af4b2018-02-12 21:20:39 +01001676 }
1677 }
Philipp Maierc1e95c82018-07-18 16:03:00 +02001678 [st.rr_ho_cmpl_seen] as_Media_ipacc();
Philipp Maier09f1c6d2020-09-14 21:28:52 +02001679 [st.rr_ho_cmpl_seen] as_Media_mgw();
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01001680 [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_DEACT_SACCH(st.old_chan_nr)) {
1681 repeat;
1682 }
Harald Welte261af4b2018-02-12 21:20:39 +01001683 [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_REL_REQ(st.old_chan_nr, tr_RslLinkID_DCCH(0))) {
1684 RSL.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1685 repeat;
1686 }
1687 [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) {
1688 RSL.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr));
1689 /* unregister for old channel number in RSL emulation */
1690 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
1691 f_rslem_unregister(0, st.old_chan_nr);
Philipp Maierc1e95c82018-07-18 16:03:00 +02001692
1693 /* The channel release must not necessarly be synchronized to the RSL handover
1694 * procedure since those events may happen independently nearly at the same
1695 * time. When we receive the RSL_RF_CHAN_REL command the media negotiation on
1696 * IPACC or MGCP level may be still in progress. In order to make sure that
1697 * we do only stop when we have seen an MDCX on MGCP level and another a CRCX
Neels Hofmeyrffd2ef12020-10-12 18:45:58 +00001698 * as well as an MDCX on IPACC level.
1699 * If ipa_crcx_seen is false, this is not a voice channel and we need not check MGCP at all.. */
1700 if (g_media.bts.ipa_crcx_seen
1701 and (g_media.mgcp_conn[0].mdcx_seen <= st.mdcx_seen_before_ho or
1702 g_media.bts1.ipa_mdcx_seen == false or g_media.bts1.ipa_crcx_seen == false)) {
Philipp Maierc1e95c82018-07-18 16:03:00 +02001703 repeat;
1704 } else {
1705 st.handover_done := true;
1706 }
Harald Welte261af4b2018-02-12 21:20:39 +01001707 }
1708}
1709
1710
Harald Weltec1a2fff2017-12-17 11:06:19 +01001711
Harald Welte28d943e2017-11-25 15:00:50 +01001712}