blob: c6e82d4ea96c35a48572ed528f7f3c56d0c47b41 [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
Philipp Maier11a58942018-06-25 16:40:48 +020055/* Get the matching payload type for a specified BSSAP codec type
56 * (see also: BSSAP_Types.ttcn */
57private function f_get_mgcp_pt(BSSMAP_FIELD_CodecType codecType) return SDP_FIELD_PayloadType {
58 if (codecType == GSM_FR) {
59 return PT_GSM;
60 } else if (codecType == GSM_HR) {
61 return PT_GSMHR;
62 } else if (codecType == GSM_EFR) {
63 return PT_GSMEFR;
64 } else if (codecType == FR_AMR or codecType == HR_AMR) {
65 return PT_AMR;
66 } else if (codecType == FR_AMR_WB or codecType == OHR_AMR or codecType == OFR_AMR_WB or codecType == OHR_AMR_WB) {
67 return PT_AMRWB;
68 }
69
70 return PT_PCMU;
71}
72
Harald Welte211219e2018-01-29 22:03:36 +010073/* Tuple containing host/ip and port */
74type record HostPort {
75 HostName host,
76 PortNumber port_nr
77};
78
79/* State encapsulating one MGCP Connection */
80type record MgcpConnState {
Philipp Maier3e2af5d2018-07-11 17:01:05 +020081 integer crcx_seen, /* Counts how many CRCX operations happend */
82 integer mdcx_seen, /* Counts how many MDCX operations happend C */
83 integer crcx_seen_exp, /* Sets the expected number of CRCX operations */
84 integer mdcx_seen_exp, /* Sets the expected number of MDCX operations */
Harald Welte211219e2018-01-29 22:03:36 +010085 MgcpConnectionId conn_id,
86 charstring mime_type, /* e.g. AMR */
87 integer sample_rate, /* 8000 */
88 integer ptime, /* 20 */
89 uint7_t rtp_pt, /* RTP Payload Type */
90 HostPort mgw, /* MGW side */
91 HostPort peer /* CA side */
92};
93
94/* BTS media state */
95type record BtsMediaState {
96 boolean ipa_crcx_seen,
Philipp Maierc1e95c82018-07-18 16:03:00 +020097 boolean ipa_mdcx_seen,
Harald Welte211219e2018-01-29 22:03:36 +010098 uint16_t conn_id,
99 uint7_t rtp_pt,
100 HostPort bts,
101 HostPort peer
102};
103
104type record MediaState {
105 MgcpEndpoint mgcp_ep,
106 MgcpConnState mgcp_conn[2],
Harald Welte261af4b2018-02-12 21:20:39 +0100107 BtsMediaState bts,
108 BtsMediaState bts1 /* only during hand-over */
Harald Welte211219e2018-01-29 22:03:36 +0100109};
110
Philipp Maier11a58942018-06-25 16:40:48 +0200111function f_MediaState_init(inout MediaState g_media, integer nr, HostName bts, HostName mgw, BSSMAP_FIELD_CodecType codecType) {
Harald Welte211219e2018-01-29 22:03:36 +0100112 /* BTS Side */
113 g_media.bts := {
114 ipa_crcx_seen := false,
Philipp Maierc1e95c82018-07-18 16:03:00 +0200115 ipa_mdcx_seen := false,
Harald Welte211219e2018-01-29 22:03:36 +0100116 conn_id := nr,
117 rtp_pt := 0,
118 bts := {
119 host := bts,
120 port_nr := 9000 + nr*2
121 },
122 peer := -
123 }
124
Harald Welte261af4b2018-02-12 21:20:39 +0100125 g_media.bts1 := {
126 ipa_crcx_seen := false,
Philipp Maierc1e95c82018-07-18 16:03:00 +0200127 ipa_mdcx_seen := false,
Harald Welte261af4b2018-02-12 21:20:39 +0100128 conn_id := nr,
129 rtp_pt := 0,
130 bts := {
131 host := bts, /* FIXME */
132 port_nr := 9000 + nr*2
133 },
134 peer := -
135 }
136
Harald Welte363cb0a2018-01-30 19:35:53 +0100137 g_media.mgcp_ep := "rtpbridge/" & int2str(nr) & "@mgw";
Harald Welte211219e2018-01-29 22:03:36 +0100138
139 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier11a58942018-06-25 16:40:48 +0200140 g_media.mgcp_conn[i].mime_type := f_encoding_name_from_pt(f_get_mgcp_pt(codecType));
Harald Welte211219e2018-01-29 22:03:36 +0100141 g_media.mgcp_conn[i].sample_rate := 8000;
142 g_media.mgcp_conn[i].ptime := 20;
Philipp Maier11a58942018-06-25 16:40:48 +0200143 g_media.mgcp_conn[i].rtp_pt := enum2int(f_get_mgcp_pt(codecType));
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200144 g_media.mgcp_conn[i].crcx_seen := 0;
145 g_media.mgcp_conn[i].mdcx_seen := 0;
146 g_media.mgcp_conn[i].crcx_seen_exp := 0;
147 g_media.mgcp_conn[i].mdcx_seen_exp := 0;
Harald Welte211219e2018-01-29 22:03:36 +0100148 g_media.mgcp_conn[i].conn_id := f_mgcp_alloc_conn_id();
149 }
150
151 g_media.mgcp_conn[0].mgw := {
152 host := mgw,
153 port_nr := 10000 + nr*2
154 }
155 g_media.mgcp_conn[1].mgw := {
156 host := mgw,
157 port_nr := 11000 + nr*2
158 }
159}
160
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200161/* Helper function to get the next free MGCP connection identifier. We can
162 * recognize free connection identifiers by the fact that no CRCX happend yet */
Harald Welte211219e2018-01-29 22:03:36 +0100163private function f_get_free_mgcp_conn() runs on MSC_ConnHdlr return integer {
164 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200165 if (not g_media.mgcp_conn[i].crcx_seen >= 1) {
Harald Welte211219e2018-01-29 22:03:36 +0100166 return i;
167 }
168 }
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100169 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Only 2 Connections per EP!");
170 /* Should never be reached */
171 return -1;
Harald Welte211219e2018-01-29 22:03:36 +0100172}
173
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200174/* Helper function to pick a specific connection by its cid. Since we reach out
175 * for a connection that is in-use we also check if there was already exactly
176 * one CRCX happening on that connection. */
Harald Welte211219e2018-01-29 22:03:36 +0100177private function f_get_mgcp_conn(MgcpConnectionId cid) runs on MSC_ConnHdlr return integer {
178 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200179 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 +0100180 return i;
181 }
182 }
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100183 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No Connection for ID ", cid));
184 /* Should not be reached */
185 return -1;
Harald Welte211219e2018-01-29 22:03:36 +0100186}
187
Philipp Maierb2422352018-07-11 10:36:57 +0200188/* altstep for handling of IPACC media related commands. Activated by as_Media() to test
189 * RSL level media handling */
190altstep as_Media_ipacc() runs on MSC_ConnHdlr {
Harald Welte211219e2018-01-29 22:03:36 +0100191 var RSL_Message rsl;
Harald Welte211219e2018-01-29 22:03:36 +0100192 var RSL_IE_Body ie;
Harald Welte930d0a72018-03-22 22:08:40 +0100193 var boolean b_unused;
Harald Welte211219e2018-01-29 22:03:36 +0100194 [not g_media.bts.ipa_crcx_seen] RSL.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl {
195 /* Extract parameters from request + use in response */
196 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
197 g_media.bts.rtp_pt := ie.ipa_rtp_pt;
198 }
199 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
200 g_media.bts.rtp_pt := ie.ipa_rtp_pt2;
201 }
202 RSL.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts.conn_id,
203 oct2int(f_inet_addr(g_media.bts.bts.host)),
204 g_media.bts.bts.port_nr,
205 g_media.bts.rtp_pt));
206 g_media.bts.ipa_crcx_seen := true;
207 repeat;
208 }
209 [g_media.bts.ipa_crcx_seen] RSL.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{
210 /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */
Harald Welte930d0a72018-03-22 22:08:40 +0100211 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie);
Harald Welte211219e2018-01-29 22:03:36 +0100212 if (g_media.bts.conn_id != ie.ipa_conn_id) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100213 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("IPA MDCX for unknown ConnId", rsl));
Harald Welte211219e2018-01-29 22:03:36 +0100214 }
215 /* mandatory */
Harald Welte930d0a72018-03-22 22:08:40 +0100216 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_IP, ie);
Harald Welte211219e2018-01-29 22:03:36 +0100217 g_media.bts.peer.host := f_inet_ntoa(int2oct(ie.ipa_remote_ip, 4));
Harald Welte930d0a72018-03-22 22:08:40 +0100218 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_PORT, ie);
Harald Welte211219e2018-01-29 22:03:36 +0100219 g_media.bts.peer.port_nr := ie.ipa_remote_port;
220 /* optional */
221 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
222 g_media.bts.rtp_pt := ie.ipa_rtp_pt;
223 }
224 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
225 g_media.bts.rtp_pt := ie.ipa_rtp_pt2;
226 }
227 RSL.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts.conn_id,
228 oct2int(f_inet_addr(g_media.bts.peer.host)),
229 g_media.bts.peer.port_nr,
230 g_media.bts.rtp_pt));
Philipp Maierc1e95c82018-07-18 16:03:00 +0200231 g_media.bts.ipa_mdcx_seen := true;
Harald Welte211219e2018-01-29 22:03:36 +0100232 repeat;
233 }
Harald Welte261af4b2018-02-12 21:20:39 +0100234
235 /* on second (new) BTS during hand-over */
236 [not g_media.bts1.ipa_crcx_seen] RSL1.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl {
237 /* Extract parameters from request + use in response */
238 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
239 g_media.bts1.rtp_pt := ie.ipa_rtp_pt;
240 }
241 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
242 g_media.bts1.rtp_pt := ie.ipa_rtp_pt2;
243 }
244 RSL1.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts1.conn_id,
245 oct2int(f_inet_addr(g_media.bts1.bts.host)),
246 g_media.bts1.bts.port_nr,
247 g_media.bts1.rtp_pt));
248 g_media.bts1.ipa_crcx_seen := true;
249 repeat;
250 }
251 /* on second (new) BTS during hand-over */
252 [g_media.bts1.ipa_crcx_seen] RSL1.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{
253 /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */
Harald Welte930d0a72018-03-22 22:08:40 +0100254 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie);
Harald Welte261af4b2018-02-12 21:20:39 +0100255 if (g_media.bts1.conn_id != ie.ipa_conn_id) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100256 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("IPA MDCX for unknown ConnId", rsl));
Harald Welte261af4b2018-02-12 21:20:39 +0100257 }
258 /* mandatory */
Harald Welte930d0a72018-03-22 22:08:40 +0100259 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_IP, ie);
Harald Welte261af4b2018-02-12 21:20:39 +0100260 g_media.bts1.peer.host := f_inet_ntoa(int2oct(ie.ipa_remote_ip, 4));
Harald Welte930d0a72018-03-22 22:08:40 +0100261 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_PORT, ie);
Harald Welte261af4b2018-02-12 21:20:39 +0100262 g_media.bts1.peer.port_nr := ie.ipa_remote_port;
263 /* optional */
264 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
265 g_media.bts1.rtp_pt := ie.ipa_rtp_pt;
266 }
267 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
268 g_media.bts1.rtp_pt := ie.ipa_rtp_pt2;
269 }
270 RSL1.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts1.conn_id,
271 oct2int(f_inet_addr(g_media.bts1.peer.host)),
272 g_media.bts1.peer.port_nr,
273 g_media.bts1.rtp_pt));
Philipp Maierc1e95c82018-07-18 16:03:00 +0200274 g_media.bts1.ipa_mdcx_seen := true;
Harald Welte261af4b2018-02-12 21:20:39 +0100275 repeat;
276 }
277
Philipp Maierb2422352018-07-11 10:36:57 +0200278
279}
280
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200281function f_rx_crcx(MgcpCommand mgcp_cmd)
282 runs on MSC_ConnHdlr return template MgcpResponse {
283 var MgcpOsmuxCID osmux_cid;
284 var SDP_Message sdp;
285 var integer cid := f_get_free_mgcp_conn();
Philipp Maiera2083892020-09-21 14:18:36 +0200286 var charstring local_rtp_addr;
287
288 if (g_pars.media_mgw_offer_ipv6 == true) {
289 local_rtp_addr := host_mgw_rtp_v6; /* Use IPv6 by default if no remote addr is provided by client */
290 } else {
291 local_rtp_addr := host_mgw_rtp_v4; /* Use IPv4 by default if no remote addr is provided by client */
292 }
293
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200294 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard)) {
295 if (cid != 0) {
296 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "MGCP wildcard EP only works in first CRCX");
297 }
298 /* we keep the endpoint name allocated during MediaState_init */
299 } else {
300 /* Call Agent allocated endpoint, trust/use it always */
301 g_media.mgcp_ep := mgcp_cmd.line.ep;
302 }
303 if (isvalue(mgcp_cmd.sdp)) {
304 sdp := mgcp_cmd.sdp;
305 g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr;
306 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 +0200307 if (sdp.connection.addr_type == "IP6") {
308 local_rtp_addr := host_mgw_rtp_v6;
309 } else {
310 local_rtp_addr := host_mgw_rtp_v4;
311 }
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200312 }
313 var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid];
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200314 sdp := valueof(ts_SDP(mgcp_conn.mgw.host, local_rtp_addr, "foo", "21",
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200315 mgcp_conn.mgw.port_nr, { int2str(mgcp_conn.rtp_pt) },
316 {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt,
317 mgcp_conn.mime_type & "/" &
318 int2str(mgcp_conn.sample_rate))),
319 valueof(ts_SDP_ptime(mgcp_conn.ptime)) } ));
320 var template MgcpResponse mgcp_resp;
321 if (g_pars.use_osmux and f_MgcpCmd_contains_par(mgcp_cmd, "X-OSMUX")) {
322 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
323 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, osmux_cid, sdp);
324 } else {
325 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp);
326 }
327 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(g_media.mgcp_ep));
328 g_media.mgcp_conn[cid].crcx_seen := g_media.mgcp_conn[cid].crcx_seen + 1;
329 return mgcp_resp;
330}
331
332function f_rx_mdcx(MgcpCommand mgcp_cmd)
333 runs on MSC_ConnHdlr return template MgcpResponse {
334 var SDP_Message sdp;
335 var integer cid := f_get_mgcp_conn(f_MgcpCmd_extract_conn_id(mgcp_cmd));
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200336 var charstring local_rtp_addr;
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200337 if (isvalue(mgcp_cmd.sdp)) {
338 sdp := mgcp_cmd.sdp;
339 g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr;
340 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 +0200341 if (sdp.connection.addr_type == "IP6") {
342 local_rtp_addr := host_mgw_rtp_v6;
343 } else {
344 local_rtp_addr := host_mgw_rtp_v4;
345 }
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200346 } else {
347 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "MDCX has no [recognizable] SDP");
348 }
349 var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid];
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200350 sdp := valueof(ts_SDP(mgcp_conn.peer.host, local_rtp_addr, "foo", "21",
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200351 mgcp_conn.peer.port_nr, { int2str(mgcp_conn.rtp_pt) },
352 {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt,
353 mgcp_conn.mime_type & "/" &
354 int2str(mgcp_conn.sample_rate))),
355 valueof(ts_SDP_ptime(mgcp_conn.ptime)) } ));
356 g_media.mgcp_conn[cid].mdcx_seen := g_media.mgcp_conn[cid].mdcx_seen + 1;
357 return ts_MDCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp);
358}
359
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200360function tr_MGCP_RecvFrom_any(template MgcpMessage msg)
361runs on MSC_ConnHdlr return template MGCP_RecvFrom {
362 var template MGCP_RecvFrom mrf := {
363 connId := ?,
364 remName := ?,
365 remPort := ?,
366 locName := ?,
367 locPort := ?,
368 msg := msg
369 }
370 return mrf;
371}
372
Philipp Maierb2422352018-07-11 10:36:57 +0200373/* altstep for handling of MGCP media related commands. Activated by as_Media() to test
374 * MGW level media handling */
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200375
Philipp Maierc1e95c82018-07-18 16:03:00 +0200376altstep as_Media_mgw(boolean norepeat := false) runs on MSC_ConnHdlr {
Philipp Maierb2422352018-07-11 10:36:57 +0200377 var MgcpCommand mgcp_cmd;
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200378 var template MgcpResponse mgcp_resp;
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200379 var MGCP_RecvFrom mrf;
380 var template MgcpMessage msg_crcx := {
381 command := tr_CRCX
382 }
383 var template MgcpMessage msg_mdcx := {
384 command := tr_MDCX
385 }
386 var template MgcpMessage msg_resp;
Philipp Maierb2422352018-07-11 10:36:57 +0200387
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200388 [g_pars.aoip] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200389 mgcp_resp := f_rx_crcx(mgcp_cmd);
Harald Welte363cb0a2018-01-30 19:35:53 +0100390 MGCP.send(mgcp_resp);
Philipp Maierc1e95c82018-07-18 16:03:00 +0200391 if(norepeat == false) {
392 repeat;
393 }
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200394 }
395
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200396 [not g_pars.aoip] MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_crcx)) -> value mrf {
397 mgcp_resp := f_rx_crcx(mrf.msg.command);
398 msg_resp := {
399 response := mgcp_resp
400 }
401 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
402 if(norepeat == false) {
403 repeat;
404 }
405 }
406
407 [g_pars.aoip] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
Pau Espin Pedrol513b8312019-06-18 17:37:36 +0200408 mgcp_resp := f_rx_mdcx(mgcp_cmd);
409 MGCP.send(mgcp_resp);
Philipp Maierc1e95c82018-07-18 16:03:00 +0200410 if(norepeat == false) {
411 repeat;
412 }
Harald Welte211219e2018-01-29 22:03:36 +0100413 }
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200414
415 [not g_pars.aoip] MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_mdcx)) -> value mrf {
416 mgcp_resp := f_rx_mdcx(mrf.msg.command);
417 msg_resp := {
418 response := mgcp_resp
419 }
420 MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp));
421 if(norepeat == false) {
422 repeat;
423 }
424 }
Harald Welte211219e2018-01-29 22:03:36 +0100425}
426
Philipp Maierb2422352018-07-11 10:36:57 +0200427/* Altsteps for handling of media related commands. Can be activated by a given
428 * test case if it expects to see media related handling (i.e. voice calls) */
429altstep as_Media() runs on MSC_ConnHdlr {
430 [] as_Media_ipacc();
431 [] as_Media_mgw();
432}
Harald Welte211219e2018-01-29 22:03:36 +0100433
Harald Welte28d943e2017-11-25 15:00:50 +0100434/* this component represents a single subscriber connection at the MSC.
Harald Welte6811d102019-04-14 22:23:14 +0200435 * There is a 1:1 mapping between SCCP connections and RAN_ConnHdlr components.
436 * We inherit all component variables, ports, functions, ... from RAN_ConnHdlr */
Harald Welte47cd0e32020-08-21 12:39:11 +0200437type component MSC_ConnHdlr extends RAN_ConnHdlr, RSL_DchanHdlr, MGCP_ConnHdlr, BSSAP_LE_ConnHdlr, StatsD_ConnHdlr {
Harald Welte28d943e2017-11-25 15:00:50 +0100438 /* SCCP Connecction Identifier for the underlying SCCP connection */
439 var integer g_sccp_conn_id;
440
Harald Welte6811d102019-04-14 22:23:14 +0200441 /* procedure port back to our parent (RAN_Emulation_CT) for control */
442 port RAN_PROC_PT RAN;
Harald Weltec20b1c42018-02-12 20:50:08 +0100443 port TELNETasp_PT BSCVTY;
Harald Welte28d943e2017-11-25 15:00:50 +0100444
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200445 /* Proxy MGCP-over-IPA and MGCP-over-UDP */
446 port IPA_MGCP_PT MGCP_MSC_CLIENT;
447 var integer g_trans_id := 0;
448
Harald Welte211219e2018-01-29 22:03:36 +0100449 var MediaState g_media;
Harald Weltea0630032018-03-20 21:09:55 +0100450 var TestHdlrParams g_pars;
Harald Weltee97eab42018-03-21 18:46:06 +0100451
Pau Espin Pedrol392963f2019-06-18 17:17:19 +0200452 var charstring host_bts := "127.0.0.2";
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200453 var charstring host_mgw_mgcp := "127.0.0.3";
454 var charstring host_mgw_rtp_v4 := "127.0.0.5";
455 var charstring host_mgw_rtp_v6 := "::1";
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200456 var charstring host_msc := "127.0.0.4";
457
Harald Weltee97eab42018-03-21 18:46:06 +0100458 var boolean g_vty_initialized := false;
Harald Welte211219e2018-01-29 22:03:36 +0100459}
460
Harald Welteeddf0e92020-06-21 19:42:15 +0200461function f_MscConnHdlr_init_vty() runs on MSC_ConnHdlr {
Harald Weltee97eab42018-03-21 18:46:06 +0100462 if (not g_vty_initialized) {
463 map(self:BSCVTY, system:BSCVTY);
464 f_vty_set_prompts(BSCVTY);
465 f_vty_transceive(BSCVTY, "enable");
466 g_vty_initialized := true;
467 }
Harald Welte28d943e2017-11-25 15:00:50 +0100468}
469
Harald Welteeddf0e92020-06-21 19:42:15 +0200470/* initialize all parameters */
471function f_MscConnHdlr_init(integer i, HostName bts, HostName mgw, BSSMAP_FIELD_CodecType codecType) runs on MSC_ConnHdlr {
472 f_MediaState_init(g_media, i, bts, mgw, codecType);
473 f_MscConnHdlr_init_vty();
474}
475
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +0200476private function get_next_trans_id() runs on MSC_ConnHdlr return MgcpTransId {
477 var MgcpTransId tid := int2str(g_trans_id);
478 g_trans_id := g_trans_id + 1;
479 return tid;
480}
481
Harald Welte6811d102019-04-14 22:23:14 +0200482/* Callback function from general RAN_Emulation whenever a connectionless
Harald Welte28d943e2017-11-25 15:00:50 +0100483 * BSSMAP message arrives. Can retunr a PDU_BSSAP that should be sent in return */
484private function UnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200485runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Welte28d943e2017-11-25 15:00:50 +0100486 var template PDU_BSSAP resp := omit;
Pau Espin Pedrol95549182019-06-06 16:17:30 +0200487 var boolean append_osmux_support := g_ran_ops.use_osmux and
488 (g_ran_ops.transport == BSSAP_TRANSPORT_AoIP);
Harald Welte28d943e2017-11-25 15:00:50 +0100489
Harald Weltec1a2fff2017-12-17 11:06:19 +0100490 /* answer all RESET with a RESET ACK */
Pau Espin Pedrol95549182019-06-06 16:17:30 +0200491 if (match(bssap, tr_BSSMAP_Reset(append_osmux_support))) {
492 resp := ts_BSSMAP_ResetAck(append_osmux_support);
Harald Welte28d943e2017-11-25 15:00:50 +0100493 }
494
495 return resp;
496}
497
Harald Welte47cd0e32020-08-21 12:39:11 +0200498/* Callback function from general BSSAP_LE_Emulation whenever a connectionless
499 * BSSAP_LE message arrives. Can return a PDU_BSSAP_LE that should be sent in return */
500private function BSSAP_LE_UnitdataCallback(PDU_BSSAP_LE bssap)
501runs on BSSAP_LE_Emulation_CT return template PDU_BSSAP_LE {
502 var template PDU_BSSAP_LE resp := omit;
503
504 /* answer all RESET with a RESET ACK */
505 if (match(bssap, tr_BSSMAP_LE_Reset)) {
506 resp := ts_BSSMAP_LE_ResetAck;
507 }
508
509 return resp;
510}
511
Harald Welte6811d102019-04-14 22:23:14 +0200512const RanOps MSC_RanOps := {
513 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Welte0b476062018-01-21 19:07:32 +0100514 unitdata_cb := refers(UnitdataCallback),
515 decode_dtap := false,
Harald Welte930d0a72018-03-22 22:08:40 +0100516 role_ms := false,
Harald Welte2fce7882019-04-15 11:48:05 +0200517 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200518 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200519 use_osmux := false,
Harald Welte930d0a72018-03-22 22:08:40 +0100520 sccp_addr_local := omit,
521 sccp_addr_peer := omit
Harald Welte28d943e2017-11-25 15:00:50 +0100522}
523
Harald Welte47cd0e32020-08-21 12:39:11 +0200524const BssapLeOps SMLC_BssapLeOps := {
525 create_cb := refers(BSSAP_LE_Emulation.ExpectedCreateCallback),
526 unitdata_cb := refers(BSSAP_LE_UnitdataCallback),
527 decode_dtap := false,
528 role_ms := false,
529 sccp_addr_local := omit,
530 sccp_addr_peer := omit
531}
532
Daniel Willmann191e0d92018-01-17 12:44:35 +0100533const MGCPOps MSC_MGCPOps := {
Harald Welte930d0a72018-03-22 22:08:40 +0100534 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
535 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
Daniel Willmann191e0d92018-01-17 12:44:35 +0100536}
537
Harald Weltec1a2fff2017-12-17 11:06:19 +0100538/* register an expect with the BSSMAP core */
Neels Hofmeyr4f118412020-06-04 15:25:10 +0200539function f_create_bssmap_exp(octetstring l3_enc) runs on MSC_ConnHdlr {
Harald Welte6811d102019-04-14 22:23:14 +0200540 RAN.call(RAN_register:{l3_enc, self}) {
541 [] RAN.getreply(RAN_register:{?, ?}) {};
Harald Welte28d943e2017-11-25 15:00:50 +0100542 }
543}
544
Harald Welte651fcdc2018-05-10 20:23:16 +0200545type record TestHdlrEncrParams {
546 OCT1 enc_alg,
547 octetstring enc_key
548};
549
550template (value) TestHdlrEncrParams t_EncrParams(OCT1 alg, octetstring key) := {
551 enc_alg := alg,
552 enc_key := key
553}
554
Harald Weltecc0b0142018-05-29 15:19:33 +0200555type record TestHdlrParamsLcls {
556 GlobalCallReferenceValue gcr optional,
557 /* LCLS Configuration */
558 BIT4 cfg optional,
559 /* LCLS Connection Status Control */
560 BIT4 csc optional,
Max2eeb5112018-11-06 19:21:41 +0100561 BIT4 exp_sts optional,
562 /* Whether to adjust *cx_seen_exp for LCLS tests */
563 boolean adjust_cx_exp
Harald Weltecc0b0142018-05-29 15:19:33 +0200564}
565
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200566type record TestHdlrParamsMSCPool {
Neels Hofmeyr4f118412020-06-04 15:25:10 +0200567 integer bssap_idx,
Neels Hofmeyr4f118412020-06-04 15:25:10 +0200568 integer rsl_idx,
569 PDU_ML3_MS_NW l3_info optional
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200570}
571
Harald Weltec1a2fff2017-12-17 11:06:19 +0100572type record TestHdlrParams {
573 OCT1 ra,
574 GsmFrameNumber fn,
575 hexstring imsi,
Harald Welte60aa5762018-03-21 19:33:13 +0100576 RslLinkId link_id,
Harald Weltecbe911c2018-06-01 18:23:07 +0200577 integer media_nr, /* determins MGCP EP, port numbers */
Harald Welte651fcdc2018-05-10 20:23:16 +0200578 BSSMAP_IE_SpeechCodecList ass_codec_list optional,
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +0200579 RSL_IE_Body expect_mr_conf_ie optional, /* typically present for AMR codecs */
Philipp Maierd0e64b02019-03-13 14:15:23 +0100580 bitstring expect_mr_s0_s7 optional, /* typically present for AMR codecs */
Harald Weltecc0b0142018-05-29 15:19:33 +0200581 TestHdlrEncrParams encr optional,
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100582 TestHdlrParamsLcls lcls,
Neels Hofmeyr90f80962020-06-12 16:16:55 +0200583 SCCP_PAR_Address sccp_addr_msc optional,
584 SCCP_PAR_Address sccp_addr_bsc optional,
Pau Espin Pedrolf7630a62019-10-28 15:07:08 +0100585 uint5_t exp_ms_power_level,
Pau Espin Pedrol8f773632019-11-05 11:46:53 +0100586 boolean exp_ms_power_params,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200587 boolean aoip,
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200588 boolean use_osmux,
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200589 charstring host_aoip_tla,
Philipp Maiera2083892020-09-21 14:18:36 +0200590 TestHdlrParamsMSCPool mscpool,
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +0200591 boolean media_mgw_offer_ipv6,
Neels Hofmeyr559d5d02021-04-16 16:50:49 +0200592 OCT3 last_used_eutran_plmn optional,
593 boolean expect_channel_mode_modify
Harald Weltec1a2fff2017-12-17 11:06:19 +0100594};
595
Philipp Maier48604732018-10-09 15:00:37 +0200596/* Note: Do not use valueof() to get a value of this template, use
597 * f_gen_test_hdlr_pars() instead in order to get a configuration that is
Pau Espin Pedrol8df10112020-01-09 18:21:53 +0100598 * matched to the current test situation (aoip vs. sccplite) */
Harald Weltec1a2fff2017-12-17 11:06:19 +0100599template (value) TestHdlrParams t_def_TestHdlrPars := {
600 ra := '23'O,
601 fn := 23,
602 imsi := '001019876543210'H,
Harald Welte60aa5762018-03-21 19:33:13 +0100603 link_id := valueof(ts_RslLinkID_DCCH(0)),
Harald Weltecbe911c2018-06-01 18:23:07 +0200604 media_nr := 1,
Harald Welte651fcdc2018-05-10 20:23:16 +0200605 ass_codec_list := omit,
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +0200606 expect_mr_conf_ie := omit,
Philipp Maierd0e64b02019-03-13 14:15:23 +0100607 expect_mr_s0_s7 := omit,
Harald Weltecc0b0142018-05-29 15:19:33 +0200608 encr := omit,
609 lcls := {
610 gcr := omit,
611 cfg := omit,
612 csc := omit,
Max2eeb5112018-11-06 19:21:41 +0100613 exp_sts := omit,
614 adjust_cx_exp := true
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100615 },
Neels Hofmeyr90f80962020-06-12 16:16:55 +0200616 sccp_addr_msc := omit,
617 sccp_addr_bsc := omit,
Pau Espin Pedrolf7630a62019-10-28 15:07:08 +0100618 exp_ms_power_level := 7, /* calculated from osmo-bsc.cfg "ms max power" */
Pau Espin Pedrol8f773632019-11-05 11:46:53 +0100619 exp_ms_power_params := false,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200620 aoip := true,
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200621 use_osmux := false,
Pau Espin Pedrol07866632020-09-03 19:10:55 +0200622 host_aoip_tla := "1.2.3.4",
Neels Hofmeyrf246a922020-05-13 02:27:10 +0200623 mscpool := {
Neels Hofmeyr4f118412020-06-04 15:25:10 +0200624 bssap_idx := 0,
Neels Hofmeyr4f118412020-06-04 15:25:10 +0200625 rsl_idx := 0,
626 l3_info := omit
Philipp Maiera2083892020-09-21 14:18:36 +0200627 },
Pau Espin Pedrolc08d5522021-04-16 15:40:38 +0200628 media_mgw_offer_ipv6 := true,
Neels Hofmeyr559d5d02021-04-16 16:50:49 +0200629 last_used_eutran_plmn := omit,
630 expect_channel_mode_modify := false
Harald Weltec1a2fff2017-12-17 11:06:19 +0100631}
632
Harald Weltea0630032018-03-20 21:09:55 +0100633function f_create_chan_and_exp() runs on MSC_ConnHdlr {
634 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
Harald Welte6ed6bf92018-01-24 21:09:15 +0100635 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
Harald Weltec1a2fff2017-12-17 11:06:19 +0100636 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
637
Neels Hofmeyrd601f9c2021-06-04 22:46:06 +0200638 f_create_bssmap_exp(l3_enc);
Harald Weltec1a2fff2017-12-17 11:06:19 +0100639 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
Harald Weltea0630032018-03-20 21:09:55 +0100640 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
Harald Weltec1a2fff2017-12-17 11:06:19 +0100641}
642
Harald Welte898113b2018-01-31 18:32:21 +0100643function f_rsl_send_l3(template PDU_ML3_MS_NW l3, template (omit) RslLinkId link_id := omit,
644 template (omit) RslChannelNr chan_nr := omit) runs on MSC_ConnHdlr {
645 if (not isvalue(link_id)) {
646 link_id := ts_RslLinkID_DCCH(0);
647 }
648 if (not isvalue(chan_nr)) {
649 chan_nr := g_chan_nr;
650 }
651 RSL.send(ts_RSL_DATA_IND(valueof(chan_nr), valueof(link_id), enc_PDU_ML3_MS_NW(valueof(l3))));
652}
653
Harald Weltec1a2fff2017-12-17 11:06:19 +0100654function f_rsl_reply(template PDU_ML3_MS_NW l3, RSL_Message orig) runs on MSC_ConnHdlr {
655 var RslChannelNr chan_nr := orig.ies[0].body.chan_nr;
Harald Welte1a40de62017-12-23 02:28:34 +0100656 var RslLinkId link_id;
Harald Welte8d5eead2017-12-17 18:56:45 +0100657 if (orig.msg_type == RSL_MT_ENCR_CMD) {
658 link_id := orig.ies[2].body.link_id;
659 } else {
660 link_id := orig.ies[1].body.link_id;
661 }
Harald Welte898113b2018-01-31 18:32:21 +0100662 f_rsl_send_l3(l3, link_id, chan_nr);
Harald Weltec1a2fff2017-12-17 11:06:19 +0100663}
664
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100665/* Convert the chipher representation on BSSMAP to the representation used on RSL */
Harald Weltee613f962018-04-18 22:38:16 +0200666function f_chipher_mode_bssmap_to_rsl(OCT1 alg_bssmap) return RSL_AlgId
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100667{
668 /* A5 0 */
669 if (alg_bssmap == '01'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200670 return RSL_ALG_ID_A5_0;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100671 }
672 /* A5 1 */
673 else if (alg_bssmap == '02'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200674 return RSL_ALG_ID_A5_1;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100675 }
676 /* A5 2 */
677 else if (alg_bssmap == '04'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200678 return RSL_ALG_ID_A5_2;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100679 }
680 /* A5 3 */
681 else if (alg_bssmap == '08'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200682 return RSL_ALG_ID_A5_3;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100683 }
684 /* A5 4 */
685 else if (alg_bssmap == '10'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200686 return RSL_ALG_ID_A5_4;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100687 }
688 /* A5 5 */
689 else if (alg_bssmap == '20'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200690 return RSL_ALG_ID_A5_5;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100691 }
692 /* A5 6 */
693 else if (alg_bssmap == '40'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200694 return RSL_ALG_ID_A5_6;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100695 }
696 /* A5 7 */
697 else if (alg_bssmap == '80'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200698 return RSL_ALG_ID_A5_7;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100699 } else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100700 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Encryption Algorithm");
Harald Weltee613f962018-04-18 22:38:16 +0200701 return RSL_ALG_ID_A5_0;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100702 }
703}
704
Harald Welte38b2a102017-12-23 02:42:58 +0100705function f_cipher_mode(OCT1 alg, OCT8 key, template OCT16 kc128 := omit, boolean exp_fail := false)
706runs on MSC_ConnHdlr {
Harald Welte73cd2712017-12-17 00:44:52 +0100707 var PDU_BSSAP bssap;
708 var RSL_Message rsl;
Harald Weltee613f962018-04-18 22:38:16 +0200709 var RSL_AlgId alg_rsl;
Harald Welte73cd2712017-12-17 00:44:52 +0100710
711 if (isvalue(kc128)) {
712 BSSAP.send(ts_BSSMAP_CipherModeCmdKc128(alg, key, valueof(kc128)));
713 } else {
714 BSSAP.send(ts_BSSMAP_CipherModeCmd(alg, key));
715 }
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100716
717 /* RSL uses a different representation of the encryption algorithm,
718 * so we need to convert first */
719 alg_rsl := f_chipher_mode_bssmap_to_rsl(alg);
720
Harald Welte73cd2712017-12-17 00:44:52 +0100721 alt {
722 /* RSL/UE Side */
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100723 [] RSL.receive(tr_RSL_ENCR_CMD(g_chan_nr, ?, alg_rsl, key)) -> value rsl {
Harald Welte73cd2712017-12-17 00:44:52 +0100724 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[3].body.l3_info.payload);
725 log("Rx L3 from net: ", l3);
726 if (ischosen(l3.msgs.rrm.cipheringModeCommand)) {
727 f_rsl_reply(ts_RRM_CiphModeCompl, rsl);
728 }
729 repeat;
730 }
731 [] BSSAP.receive(tr_BSSMAP_CipherModeCompl) -> value bssap {
732 // bssap.bssmap.cipherModeComplete.chosenEncryptionAlgorithm.algoritmhIdentifier
Harald Welte38b2a102017-12-23 02:42:58 +0100733 if (exp_fail == true) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100734 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Cipher Mode Complete");
Harald Welte38b2a102017-12-23 02:42:58 +0100735 } else {
736 setverdict(pass);
737 }
Harald Welte73cd2712017-12-17 00:44:52 +0100738 }
739 [] BSSAP.receive(tr_BSSMAP_CipherModeRej) -> value bssap {
Harald Welte38b2a102017-12-23 02:42:58 +0100740 if (exp_fail == false) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100741 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Ciphering Mode Reject");
Harald Welte38b2a102017-12-23 02:42:58 +0100742 } else {
743 setverdict(pass);
744 }
Harald Welte73cd2712017-12-17 00:44:52 +0100745 }
746 }
747}
748
Harald Welte211219e2018-01-29 22:03:36 +0100749/* Convert from Ericsson ChanDesc2 format to Osmocom RslChannelNr format */
750function f_ChDesc2RslChanNr(ChannelDescription2_V ch_desc, out RslChannelNr chan_nr, out GsmArfcn arfcn) {
751 var BIT5 inp := ch_desc.channelTypeandTDMAOffset;
Harald Welte6fa1f732018-03-21 22:46:16 +0100752 var uint3_t tn := bit2int(ch_desc.timeslotNumber);
Harald Welte211219e2018-01-29 22:03:36 +0100753
754 if (match(inp, '00001'B)) { /* TCH/F */
Harald Welte6fa1f732018-03-21 22:46:16 +0100755 chan_nr := valueof(t_RslChanNr_Bm(tn));
Harald Welte211219e2018-01-29 22:03:36 +0100756 }
Neels Hofmeyr9c3b82f2021-05-27 00:38:59 +0200757 else if (match(inp, '11101'B)) { /* VAMOS TCH/F */
758 chan_nr := valueof(t_RslChanNr_Osmo_VAMOS_Bm(tn));
759 }
Harald Welte211219e2018-01-29 22:03:36 +0100760 else if (match(inp, '0001?'B)) { /* TCH/H */
Harald Welte6fa1f732018-03-21 22:46:16 +0100761 chan_nr := valueof(t_RslChanNr_Lm(tn, bit2int(substr(inp, 4, 1))));
Harald Welte211219e2018-01-29 22:03:36 +0100762 }
Neels Hofmeyr9c3b82f2021-05-27 00:38:59 +0200763 else if (match(inp, '1111?'B)) { /* VAMOS TCH/H */
764 chan_nr := valueof(t_RslChanNr_Osmo_VAMOS_Lm(tn, bit2int(substr(inp, 4, 1))));
765 }
Harald Welte211219e2018-01-29 22:03:36 +0100766 else if (match(inp, '001??'B)) { /* SDCCH/4 */
Harald Welte6fa1f732018-03-21 22:46:16 +0100767 chan_nr := valueof(t_RslChanNr_SDCCH4(tn, bit2int(substr(inp, 3, 2))));
Harald Welte211219e2018-01-29 22:03:36 +0100768 }
769 else if (match(inp, '01???'B)) { /* SDCCH/8 */
Harald Welte6fa1f732018-03-21 22:46:16 +0100770 chan_nr := valueof(t_RslChanNr_SDCCH8(tn, bit2int(substr(inp, 2, 3))));
Harald Welte211219e2018-01-29 22:03:36 +0100771 }
772 else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100773 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown ChDesc!");
Harald Welte211219e2018-01-29 22:03:36 +0100774 }
775
776 if (ch_desc.octet3 and4b '10'O == '10'O) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100777 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No support for Hopping");
Harald Welte211219e2018-01-29 22:03:36 +0100778 } else {
779 var OCT2 concat := ch_desc.octet3 & ch_desc.octet4;
780 arfcn := oct2int(concat);
781 }
782}
783
784type record AssignmentState {
785 /* global */
786 boolean voice_call,
787 boolean is_assignment,
788 /* Assignment related bits */
789 boolean rr_ass_cmpl_seen,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100790 boolean old_lchan_deact_sacch_seen,
791 boolean old_lchan_rll_rel_req_seen,
Harald Welte21583082018-01-29 22:28:26 +0100792 boolean assignment_done,
Harald Welte211219e2018-01-29 22:03:36 +0100793 RslChannelNr old_chan_nr,
794 /* Modify related bits */
Neels Hofmeyr559d5d02021-04-16 16:50:49 +0200795 PDU_ML3_NW_MS rr_channel_mode_modify_msg optional,
Harald Welte211219e2018-01-29 22:03:36 +0100796 boolean rr_modify_seen,
Neels Hofmeyr559d5d02021-04-16 16:50:49 +0200797 RSL_Message rsl_mode_modify_msg optional,
Harald Welte21583082018-01-29 22:28:26 +0100798 boolean modify_done
Harald Welte211219e2018-01-29 22:03:36 +0100799}
800
801template (value) AssignmentState ts_AssignmentStateInit := {
802 voice_call := false,
803 is_assignment := false,
804 rr_ass_cmpl_seen := false,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100805 old_lchan_deact_sacch_seen := false,
806 old_lchan_rll_rel_req_seen := false,
Harald Welte21583082018-01-29 22:28:26 +0100807 assignment_done := false,
Harald Welte211219e2018-01-29 22:03:36 +0100808 old_chan_nr := -,
Neels Hofmeyr559d5d02021-04-16 16:50:49 +0200809 rr_channel_mode_modify_msg := omit,
Harald Welte211219e2018-01-29 22:03:36 +0100810 rr_modify_seen := false,
Neels Hofmeyr559d5d02021-04-16 16:50:49 +0200811 rsl_mode_modify_msg := omit,
Harald Welte21583082018-01-29 22:28:26 +0100812 modify_done := false
Harald Welte211219e2018-01-29 22:03:36 +0100813}
814
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200815private template RSL_IE_Body tr_EncrInfo(template RSL_AlgId alg, template octetstring key) := {
816 encr_info := {
817 len := ?,
818 alg_id := alg,
819 key := key
820 }
821}
822
823/* ensure the RSL CHAN ACT (during assignment) contains values we expect depending on test case */
824private function f_check_chan_act(AssignmentState st, RSL_Message chan_act) runs on MSC_ConnHdlr {
825 var RSL_IE_Body encr_info;
Pau Espin Pedrol3d008ae2019-10-28 13:35:46 +0100826 var RSL_IE_Body ms_power_param;
Pau Espin Pedrolf7630a62019-10-28 15:07:08 +0100827 var RSL_IE_Body ms_power;
Pau Espin Pedrol3d008ae2019-10-28 13:35:46 +0100828
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200829 if (ispresent(g_pars.encr) and g_pars.encr.enc_alg != '01'O) {
830 if (not f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100831 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Missing Encryption IE in CHAN ACT");
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200832 } else {
833 var RSL_AlgId alg := f_chipher_mode_bssmap_to_rsl(g_pars.encr.enc_alg);
834 if (not match(encr_info, tr_EncrInfo(alg, g_pars.encr.enc_key))) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100835 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong Encryption IE in CHAN ACT");
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200836 }
837 }
838 } else {
839 if (f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) {
840 if (encr_info.encr_info.alg_id != RSL_ALG_ID_A5_0) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100841 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Encryption in CHAN ACT");
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200842 }
843 }
844 }
845 /* 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 +0100846 * RSL_IE_TIMING_ADVANCE */
Pau Espin Pedrol3d008ae2019-10-28 13:35:46 +0100847
Pau Espin Pedrol8f773632019-11-05 11:46:53 +0100848 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 +0100849 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "IE MS Power Parameters not found in CHAN ACT");
850 }
851
Pau Espin Pedrolf7630a62019-10-28 15:07:08 +0100852 if (not f_rsl_find_ie(chan_act, RSL_IE_MS_POWER, ms_power)) {
853 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "IE MS Power not found in CHAN ACT");
854 } else {
855 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 +0100856 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 +0100857 }
858 }
859
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200860}
861
Harald Welte211219e2018-01-29 22:03:36 +0100862altstep as_assignment(inout AssignmentState st) runs on MSC_ConnHdlr {
Harald Weltec1a2fff2017-12-17 11:06:19 +0100863 var RSL_Message rsl;
Harald Welte211219e2018-01-29 22:03:36 +0100864 [not st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
865 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
866 log("Rx L3 from net: ", l3);
867 if (ischosen(l3.msgs.rrm.assignmentCommand)) {
868 var RslChannelNr new_chan_nr;
869 var GsmArfcn arfcn;
870 f_ChDesc2RslChanNr(l3.msgs.rrm.assignmentCommand.descrOf1stChAfterTime,
871 new_chan_nr, arfcn);
872 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
Harald Weltec1a2fff2017-12-17 11:06:19 +0100873
Harald Welte211219e2018-01-29 22:03:36 +0100874 /* register our component for this channel number at the RSL Emulation */
875 f_rslem_register(0, new_chan_nr);
Vadim Yanitskiy539e6302020-06-22 03:11:54 +0700876 /* dispatch queued messages for this channel (if any) */
877 f_rslem_dchan_queue_dispatch();
878
Harald Welte211219e2018-01-29 22:03:36 +0100879 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_AssignmentComplete('00'O));
880 /* send assignment complete over the new channel */
Neels Hofmeyrb0e73652018-07-14 21:56:51 +0200881 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
Harald Welte211219e2018-01-29 22:03:36 +0100882 enc_PDU_ML3_MS_NW(l3_tx)));
883 /* by default, send via the new channel from now */
884 st.old_chan_nr := g_chan_nr;
885 g_chan_nr := new_chan_nr;
886 st.rr_ass_cmpl_seen := true;
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200887 /* obtain channel activation from RSL_Emulation for new channel */
888 var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
889 /* check it (e.g. for correct ciphering parameters) */
890 f_check_chan_act(st, chan_act);
Harald Welte211219e2018-01-29 22:03:36 +0100891 repeat;
892 } else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100893 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected L3 received", l3));
Harald Weltec1a2fff2017-12-17 11:06:19 +0100894 }
Harald Welte211219e2018-01-29 22:03:36 +0100895 }
Neels Hofmeyr861a4c12018-11-07 01:23:17 +0100896 [st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_DEACT_SACCH(st.old_chan_nr)) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100897 st.old_lchan_deact_sacch_seen := true;
Neels Hofmeyr861a4c12018-11-07 01:23:17 +0100898 repeat;
899 }
Harald Welte211219e2018-01-29 22:03:36 +0100900 [st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_REL_REQ(st.old_chan_nr, tr_RslLinkID_DCCH(0))) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100901 st.old_lchan_rll_rel_req_seen := true;
Harald Welte211219e2018-01-29 22:03:36 +0100902 RSL.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
903 repeat;
904 }
905 [st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) {
906 RSL.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr));
Harald Welte1909f462018-01-29 22:29:29 +0100907 /* unregister for old channel number in RSL emulation */
908 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
909 f_rslem_unregister(0, st.old_chan_nr);
Harald Welte21583082018-01-29 22:28:26 +0100910 st.assignment_done := true;
Harald Welte211219e2018-01-29 22:03:36 +0100911 repeat;
912 }
913}
914
915altstep as_modify(inout AssignmentState st) runs on MSC_ConnHdlr {
916 /* no assignment, just mode modify */
917 var RSL_Message rsl;
918
919 [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 +0100920 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
921 log("Rx L3 from net: ", l3);
922 if (ischosen(l3.msgs.rrm.channelModeModify)) {
Neels Hofmeyr559d5d02021-04-16 16:50:49 +0200923 st.rr_channel_mode_modify_msg := l3;
Harald Weltec1a2fff2017-12-17 11:06:19 +0100924 f_rsl_reply(ts_RRM_ModeModifyAck(l3.msgs.rrm.channelModeModify.channelDescription,
925 l3.msgs.rrm.channelModeModify.channelMode), rsl);
Harald Welte211219e2018-01-29 22:03:36 +0100926 st.rr_modify_seen := true;
Harald Weltec1a2fff2017-12-17 11:06:19 +0100927 }
928 repeat;
929 }
Harald Welte211219e2018-01-29 22:03:36 +0100930 [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 +0200931 st.rsl_mode_modify_msg := rsl;
Harald Weltec1a2fff2017-12-17 11:06:19 +0100932 RSL.send(ts_RSL_MODE_MODIFY_ACK(g_chan_nr));
Harald Welte21583082018-01-29 22:28:26 +0100933 st.modify_done := true;
Harald Weltec1a2fff2017-12-17 11:06:19 +0100934 repeat;
935 }
Harald Welte211219e2018-01-29 22:03:36 +0100936}
Daniel Willmann191e0d92018-01-17 12:44:35 +0100937
Harald Welte211219e2018-01-29 22:03:36 +0100938/* Determine if given rsl_chan_nr is compatible with given BSSMAP ChannelType */
939function f_channel_compatible(BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr)
940return boolean {
941 select (bssmap.speechOrDataIndicator) {
942 case ('0011'B) { /* Signalling */
943 /* all channels support signalling */
944 return true;
945 }
946 case else { /* Speech, Speech+CTM or CSD */
947 select (bssmap.channelRateAndType) {
948 case ('08'O) { /* TCH/F */
949 select (rsl_chan_nr) {
950 case (t_RslChanNr_Bm(?)) { return true; }
951 }
952 }
953 case ('09'O) { /* TCH/H */
954 select (rsl_chan_nr) {
955 case (t_RslChanNr_Lm(?, ?)) { return true; }
956 }
957 }
958 case else { /* full or half-rate */
959 select (rsl_chan_nr) {
960 case (t_RslChanNr_Bm(?)) { return true; }
961 case (t_RslChanNr_Lm(?, ?)) { return true; }
962 }
963 }
964 }
Harald Weltec1a2fff2017-12-17 11:06:19 +0100965 }
Harald Welte211219e2018-01-29 22:03:36 +0100966 }
967 return false;
968}
Daniel Willmann191e0d92018-01-17 12:44:35 +0100969
Philipp Maier8ef527e2018-05-18 11:12:50 +0200970/* Determine if the channel mode specified within rsl_chan_nr requires a
971 * MODE MODIFY in to match the channel mode specified by given BSSMAP
972 * ChannelType */
Neels Hofmeyrc2425cc2021-04-19 13:19:55 +0000973function f_channel_needs_modify(TELNETasp_PT vty, BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr)
Philipp Maier8ef527e2018-05-18 11:12:50 +0200974return boolean {
975
Philipp Maier8ef527e2018-05-18 11:12:50 +0200976 var boolean current_signalling := false;
977 var boolean desired_signalling := false;
978
979 select (rsl_chan_nr) {
980 case (t_RslChanNr_SDCCH4(?, ?)) { current_signalling := true; }
981 case (t_RslChanNr_SDCCH8(?, ?)) { current_signalling := true; }
Neels Hofmeyrc2425cc2021-04-19 13:19:55 +0000982 case (t_RslChanNr_Bm(?)) {
983 /* TCH/F, always subslot 0 */
984 var charstring res := f_vty_transceive_ret(vty, "show lchan 0 0 " & int2str(rsl_chan_nr.tn) & " 0");
985 if (f_strstr(res, "Channel Mode / Codec: SIGNALLING", 0) >= 0) {
986 current_signalling := true;
987 }
988 }
989 case (t_RslChanNr_Lm(?, ?)) {
990 /* TCH/H */
991 var charstring res := f_vty_transceive_ret(vty, "show lchan 0 0 " & int2str(rsl_chan_nr.tn)
992 & " " & int2str(rsl_chan_nr.u.lm.sub_chan));
993 if (f_strstr(res, "Channel Mode / Codec: SIGNALLING", 0) >= 0) {
994 current_signalling := true;
995 }
996 }
Philipp Maier8ef527e2018-05-18 11:12:50 +0200997 }
998
999 if (bssmap.speechOrDataIndicator == '0011'B) {
1000 desired_signalling := true;
1001 }
1002
1003 if (current_signalling == desired_signalling) {
1004 /* The desired channel mode is equal to the one we currently
1005 * have, there is no mode modification needed or expected */
1006 return false;
1007 } else {
1008 /* The desired channel mode and the current channel mode do
1009 * not match. A mode modification is required */
1010 return true;
1011 }
1012}
1013
Harald Weltecc0b0142018-05-29 15:19:33 +02001014/* patch an BSSMAP ASS REQ with LCLS related IEs, depending on g_params */
1015function f_ass_patch_lcls(inout template (omit) PDU_BSSAP ass_tpl,
1016 inout template PDU_BSSAP ass_cpl) runs on MSC_ConnHdlr {
1017 if (istemplatekind(ass_tpl, "omit")) {
1018 return;
1019 }
1020 if (ispresent(g_pars.lcls.gcr)) {
1021 ass_tpl.pdu.bssmap.assignmentRequest.globalCallReference := ts_BSSMAP_IE_GCR(g_pars.lcls.gcr);
1022 }
1023 if (ispresent(g_pars.lcls.cfg)) {
1024 ass_tpl.pdu.bssmap.assignmentRequest.lCLS_Configuration := ts_BSSMAP_IE_LclsCfg(g_pars.lcls.cfg);
1025 }
1026 if (ispresent(g_pars.lcls.csc)) {
1027 ass_tpl.pdu.bssmap.assignmentRequest.lCLS_ConnectionStatusControl := ts_BSSMAP_IE_LclsCsc(g_pars.lcls.csc);
1028 }
Harald Welte343b7742018-06-05 23:41:37 +02001029 if (ischosen(ass_cpl.pdu.bssmap.assignmentComplete)) {
1030 if (ispresent(g_pars.lcls.exp_sts)) {
1031 ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status := tr_BSSMAP_IE_LclsSts(g_pars.lcls.exp_sts);
1032 } else {
1033 ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status := omit;
1034 }
Harald Weltecc0b0142018-05-29 15:19:33 +02001035 }
1036}
1037
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001038/* Send a MGCP request through MGCP-over-IPA from MSC side and receive a (matching!) response */
1039function mgcp_transceive_mgw(template MgcpCommand cmd, template MgcpResponse resp := ?) runs on MSC_ConnHdlr {
1040 template MgcpResponse resp_any := ?
1041 var MgcpResponse resp_val;
1042 resp.line.trans_id := cmd.line.trans_id;
1043 timer T := 5.0;
1044
1045 BSSAP.send(cmd);
1046 T.start;
1047 alt {
1048 [] as_Media_mgw();
1049 [] BSSAP.receive(resp) -> value resp_val { }
1050 [] BSSAP.receive(resp_any) {
1051 setverdict(fail, "Response didn't match template");
1052 mtc.stop;
1053 }
1054 [] BSSAP.receive { repeat; }
1055 [] T.timeout {
1056 setverdict(fail, "Timeout waiting for response to ", cmd);
1057 mtc.stop;
1058 }
1059 }
1060 T.stop;
1061}
1062
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001063/* Helper function to check if the activity on the MGCP matches what we
1064 * expected */
1065function f_check_mgcp_expectations() runs on MSC_ConnHdlr {
1066 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier0a5d7e72018-07-16 15:13:11 +02001067 log(testcasename(), ": Check MGCP test expectations for g_media.mgcp_conn[", i , "]:",
1068 " crcx_seen=", g_media.mgcp_conn[i].crcx_seen, ", crcx_seen_exp=", g_media.mgcp_conn[i].crcx_seen_exp,
1069 ", mdcx_seen=", g_media.mgcp_conn[i].mdcx_seen, ", mdcx_seen_exp=", g_media.mgcp_conn[i].mdcx_seen_exp);
1070
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001071 if(g_media.mgcp_conn[i].crcx_seen != g_media.mgcp_conn[i].crcx_seen_exp) {
Max4b0f4962018-11-06 19:20:24 +01001072 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 +02001073 }
1074 if(g_media.mgcp_conn[i].mdcx_seen != g_media.mgcp_conn[i].mdcx_seen_exp) {
Max4b0f4962018-11-06 19:20:24 +01001075 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 +02001076 }
1077 }
1078}
1079
Harald Welte211219e2018-01-29 22:03:36 +01001080/* establish a channel fully, expecting an assignment matching 'exp' */
Harald Welte7a14fd52018-05-10 22:26:55 +02001081function f_establish_fully(template (omit) PDU_BSSAP ass_tpl, template PDU_BSSAP exp_ass_cpl)
1082runs on MSC_ConnHdlr {
Philipp Maier11a58942018-06-25 16:40:48 +02001083
1084 var BSSMAP_FIELD_CodecType codecType;
Philipp Maier48aeeec2018-09-14 18:20:04 +02001085 timer T := 10.0;
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001086
Philipp Maier4ce978c2020-08-11 22:54:07 +02001087 if (not istemplatekind(ass_tpl, "omit") and isvalue(ass_tpl.pdu.bssmap.assignmentRequest.codecList)) {
Philipp Maier11a58942018-06-25 16:40:48 +02001088 codecType := valueof(ass_tpl.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
1089 } else {
1090 /* Make sure a meaningful default is assigned in case the
1091 * codecList is not populated */
1092 codecType := FR_AMR;
1093 }
1094
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001095 f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType);
Harald Welte7a14fd52018-05-10 22:26:55 +02001096
Harald Weltecc0b0142018-05-29 15:19:33 +02001097 /* patch in the LCLS related items, as needed */
1098 f_ass_patch_lcls(ass_tpl, exp_ass_cpl);
1099
Harald Welte7a14fd52018-05-10 22:26:55 +02001100 f_create_chan_and_exp();
1101 /* we should now have a COMPL_L3 at the MSC */
Philipp Maier48aeeec2018-09-14 18:20:04 +02001102
1103 var template PDU_BSSAP exp_l3_compl;
1104 exp_l3_compl := tr_BSSMAP_ComplL3()
Philipp Maier48604732018-10-09 15:00:37 +02001105 if (g_pars.aoip == false) {
Philipp Maier48aeeec2018-09-14 18:20:04 +02001106 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
1107 } else {
1108 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
1109 }
1110 T.start;
1111 alt {
1112 [] BSSAP.receive(exp_l3_compl);
1113 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001114 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
Philipp Maier48aeeec2018-09-14 18:20:04 +02001115 }
1116 [] T.timeout {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001117 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
Philipp Maier48aeeec2018-09-14 18:20:04 +02001118 }
1119 }
Harald Welte7a14fd52018-05-10 22:26:55 +02001120
1121 /* start ciphering, if requested */
1122 if (ispresent(g_pars.encr)) {
1123 f_cipher_mode(g_pars.encr.enc_alg, g_pars.encr.enc_key);
1124 }
1125
1126 /* bail out early if no assignment requested */
1127 if (istemplatekind(ass_tpl, "omit")) {
1128 return;
1129 }
1130
1131 var PDU_BSSAP ass_cmd := valueof(ass_tpl);
Harald Welte211219e2018-01-29 22:03:36 +01001132 var PDU_BSSAP bssap;
Harald Welte211219e2018-01-29 22:03:36 +01001133 var boolean exp_compl := ischosen(exp_ass_cpl.pdu.bssmap.assignmentComplete);
Philipp Maier86f39202018-02-07 14:40:09 +01001134 var boolean exp_fail := ischosen(exp_ass_cpl.pdu.bssmap.assignmentFailure);
Philipp Maier8ef527e2018-05-18 11:12:50 +02001135 var boolean exp_modify;
Philipp Maier48aeeec2018-09-14 18:20:04 +02001136
Harald Welte211219e2018-01-29 22:03:36 +01001137 var ExpectCriteria mgcpcrit := {
1138 connid := omit,
1139 endpoint := omit,
1140 transid := omit
1141 };
1142 var AssignmentState st := valueof(ts_AssignmentStateInit);
1143 /* if the channel type is SIGNAL, we're not handling a voice call */
1144 if (ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechOrDataIndicator != '0011'B) {
1145 st.voice_call := true;
Philipp Maier8ef527e2018-05-18 11:12:50 +02001146 exp_modify := true;
Harald Welte211219e2018-01-29 22:03:36 +01001147 }
Philipp Maier8ef527e2018-05-18 11:12:50 +02001148
Harald Welte211219e2018-01-29 22:03:36 +01001149 /* determine if the current channel can support the given service or not */
1150 if (not f_channel_compatible(ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr)) {
1151 st.is_assignment := true;
Philipp Maier8ef527e2018-05-18 11:12:50 +02001152
1153 /* We decided to assign a new channel, so we do not expect
1154 * any mode modify messages on RSL */
1155 exp_modify := false;
1156 } else {
1157 /* We will continue working with the currently assigned
1158 * channel, we must now check if the mode of the current
1159 * channel is compatible. If not we expect the BSC to modify
1160 * the mode */
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02001161 st.is_assignment := false;
Neels Hofmeyrc2425cc2021-04-19 13:19:55 +00001162 exp_modify := f_channel_needs_modify(BSCVTY, ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr);
Harald Welte211219e2018-01-29 22:03:36 +01001163 }
1164
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001165 /* Some test situations will involve MGCP transactions on a media
1166 * gateway. Depending on the situation, we set up how many of each MGCP
1167 * message type are expected to be exchanged. */
1168 if (isbound(exp_ass_cpl.pdu.bssmap.assignmentFailure)) {
1169 /* For tests that expect the assignment to fail, assume that
1170 * there will be no MGW communication as well. */
1171 g_media.mgcp_conn[0].crcx_seen_exp := 0;
1172 g_media.mgcp_conn[0].mdcx_seen_exp := 0;
1173 g_media.mgcp_conn[1].crcx_seen_exp := 0;
1174 g_media.mgcp_conn[1].mdcx_seen_exp := 0;
1175 } else if (st.voice_call) {
1176 /* For voice calls we expect the following MGCP activity */
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001177 g_media.mgcp_conn[0].crcx_seen_exp := 1;
1178 g_media.mgcp_conn[0].mdcx_seen_exp := 1;
1179 g_media.mgcp_conn[1].crcx_seen_exp := 1;
1180 g_media.mgcp_conn[1].mdcx_seen_exp := 0;
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001181 }
1182
Vadim Yanitskiy539e6302020-06-22 03:11:54 +07001183 /* On receipt of the BSSAP Assignment Command, the IUT (osmo-bsc) will allocate
1184 * a channel and send us RR Assignment Command together with ip.access CRCX.
1185 * There is a risk that the RSL Emulation component would dequeue and process
1186 * ip.access CRCX faster than we process the Assignment Command and register
1187 * the corresponding handler for the indicated RSL channel number. This would
1188 * result in a failure, because at that moment there will be no handler for
1189 * ip.access CRCX. Let's guard against this and enable additional queueing. */
1190 f_rslem_dchan_queue_enable();
1191
Harald Welte211219e2018-01-29 22:03:36 +01001192 f_create_mgcp_expect(mgcpcrit);
1193 BSSAP.send(ass_cmd);
1194
1195 T.start;
1196 alt {
1197 /* assignment related bits */
1198 [st.is_assignment] as_assignment(st);
1199
1200 /* modify related bits */
Philipp Maier8ef527e2018-05-18 11:12:50 +02001201 [not st.is_assignment and exp_modify] as_modify(st);
Harald Welte211219e2018-01-29 22:03:36 +01001202
1203 /* voice call related bits (IPA CRCX/MDCX + MGCP) */
1204 [st.voice_call] as_Media();
1205
1206 /* if we receive exactly what we expected, always return + pass */
Philipp Maier8ef527e2018-05-18 11:12:50 +02001207 [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 +01001208 setverdict(pass);
1209 }
Philipp Maier86f39202018-02-07 14:40:09 +01001210 [exp_fail] BSSAP.receive(exp_ass_cpl) -> value bssap {
1211 setverdict(pass);
1212 }
Harald Welte21583082018-01-29 22:28:26 +01001213 [(st.is_assignment and st.assignment_done or
Philipp Maier8ef527e2018-05-18 11:12:50 +02001214 (not st.is_assignment and (st.modify_done or not exp_modify))) and
Harald Welte21583082018-01-29 22:28:26 +01001215 exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001216 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching ASSIGNMENT COMPLETE");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001217 }
1218 [exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected ASSIGNMENT FAIL");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001220 }
1221 [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected ASSIGNMENT COMPLETE");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001223 }
1224 [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001225 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching ASSIGNMENT FAIL");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001226 }
1227 [] T.timeout {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001228 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASSIGNMENT COMPLETE");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001229 }
1230 }
Harald Welte211219e2018-01-29 22:03:36 +01001231 log("g_media ", g_media);
1232 if (not isbound(bssap)) {
Daniel Willmannafce8662018-07-06 23:11:32 +02001233 mtc.stop;
Harald Welte211219e2018-01-29 22:03:36 +01001234 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001235
Neels Hofmeyr559d5d02021-04-16 16:50:49 +02001236 if (exp_modify) {
1237 /* Verify that the RR Channel Mode Modify and RSL MODE MODIFY message asked for the expected channel
1238 * mode. */
1239 /* TODO: more precisely expect the different types of speech? */
1240 var OCT1 rr_channel_mode := st.rr_channel_mode_modify_msg.msgs.rrm.channelModeModify.channelMode.mode;
1241
1242 if (st.voice_call and rr_channel_mode == '00'O) {
1243 setverdict(fail, "f_establish_fully(): Expected RR Channel Mode Modify",
1244 " to a speech mode, but got channelMode == ", rr_channel_mode);
1245 mtc.stop;
1246 } else if (not st.voice_call and rr_channel_mode != '00'O) {
1247 setverdict(fail, "f_establish_fully(): Expected RR Channel Mode Modify",
1248 " to signalling mode, but got channelMode == ", rr_channel_mode);
1249 mtc.stop;
1250 }
1251
1252 var RSL_IE_Body chan_mode_ie;
1253 if (not f_rsl_find_ie(st.rsl_mode_modify_msg, RSL_IE_CHAN_MODE, chan_mode_ie)) {
1254 setverdict(fail, "RSL MODE MODIFY message lacks a Channel Mode IE");
1255 mtc.stop;
1256 }
1257 var RSL_SpeechDataInd rsl_spd_ind := chan_mode_ie.chan_mode.spd_ind;
1258 if (st.voice_call and rsl_spd_ind != RSL_SPDI_SPEECH) {
1259 setverdict(fail, "f_establish_fully(): Expected RSL MODE MODIFY",
1260 " to a speech mode, but got spd_ind == ", rsl_spd_ind);
1261 mtc.stop;
1262 } else if (not st.voice_call and rsl_spd_ind != RSL_SPDI_SIGN) {
1263 setverdict(fail, "f_establish_fully(): Expected RSL MODE MODIFY",
1264 " to signalling mode, but got spd_ind == ", rsl_spd_ind);
1265 mtc.stop;
1266 }
1267 }
1268
Philipp Maiera0976e92018-07-16 15:19:42 +02001269 /* When the BSC detects that LCLS is possible it will cross the
1270 * connetions that point to the PBX side of the MGW. In our case this
1271 * is mgcp_conn[1]. The BSC performs this operation already before the
1272 * assignment complete is generated. This means we expect another MDCX
1273 * at mgcp_conn[1] when LCLS is expected. */
Max2eeb5112018-11-06 19:21:41 +01001274 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 +02001275 if (valueof(exp_ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status.lCLS_BSS_StatusValue) == LCLS_STS_locally_switched) {
1276 g_media.mgcp_conn[1].mdcx_seen_exp := g_media.mgcp_conn[1].mdcx_seen_exp + 1;
1277
1278 }
1279 }
1280
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001281 if (not exp_fail and st.voice_call and not g_pars.aoip) {
1282 /* With SCCPLite, connect to BSC-located MGW using a CRCX + SDP.
1283 It is sent in MGCP over IPA in the BSC<->MSC (BSC-NAT)
1284 connection. BSC will forward it to its MGW. */
1285 var template MgcpCommand cmd;
1286 var template MgcpResponse resp;
1287 var integer cic := f_bssmap_ie_cic_2_int(ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode);
1288 var MgcpEndpoint ep := int2str(cic) & "@mgw"; /* 1: matches value configured in BSC_Tests.ttcn pass in AssignReq */
1289 var MgcpCallId call_id := '51234'H;
1290 var SDP_attribute_list attributes := { valueof(ts_SDP_ptime(20)) };
1291 if (g_pars.use_osmux) {
1292 cmd := ts_CRCX_osmux(get_next_trans_id(), ep, "sendrecv", call_id, cic);
1293 resp := tr_CRCX_ACK_osmux;
1294 } else {
1295 cmd := ts_CRCX(get_next_trans_id(), ep, "sendrecv", call_id);
1296 resp := tr_CRCX_ACK;
1297 }
Pau Espin Pedrol07866632020-09-03 19:10:55 +02001298 cmd.sdp := ts_SDP(host_msc, host_mgw_rtp_v4, "23", "42",
Pau Espin Pedrolfd02ad42019-06-18 17:45:20 +02001299 14000, { int2str(g_media.mgcp_conn[1].rtp_pt) },
1300 { valueof(ts_SDP_ptime(20)) });
1301 mgcp_transceive_mgw(cmd, resp);
1302 }
1303
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001304 f_check_mgcp_expectations();
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001305
1306 if (st.is_assignment and st.assignment_done) {
1307 if (not st.old_lchan_deact_sacch_seen) {
1308 setverdict(fail, "f_establish_fully(): Assignment completed, but the old lchan was not",
1309 " released properly: expected a Deact SACCH on the old lchan, but saw none.");
1310 }
1311 if (st.old_lchan_rll_rel_req_seen) {
1312 setverdict(fail, "f_establish_fully(): Assignment completed, but the old lchan was not",
1313 " released properly: saw an RLL Release on the old lchan, but expecting none.");
1314 }
1315 }
Neels Hofmeyr9d686302021-04-25 19:02:29 +00001316
1317 var charstring lchan_info := f_vty_transceive_ret(BSCVTY, "show lchan 0 0 " & int2str(g_chan_nr.tn) & " 0");
1318 if (f_strstr(lchan_info, "State: ESTABLISHED") < 0) {
1319 log("after f_establish_fully(), 'show lchan' replied: ", lchan_info);
1320 setverdict(fail, "lchan is not in state ESTABLISHED");
1321 mtc.stop;
1322 }
Harald Welte930d0a72018-03-22 22:08:40 +01001323}
1324
Harald Welte261af4b2018-02-12 21:20:39 +01001325type record HandoverState {
1326 /* Assignment related bits */
1327 boolean rr_ho_cmpl_seen,
Philipp Maierc1e95c82018-07-18 16:03:00 +02001328 integer mdcx_seen_before_ho,
Harald Welte261af4b2018-02-12 21:20:39 +01001329 boolean handover_done,
1330 RslChannelNr old_chan_nr
1331};
1332
1333altstep as_handover(inout HandoverState st) runs on MSC_ConnHdlr {
1334 var RSL_Message rsl;
1335 [not st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
1336 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
1337 log("Rx L3 from net: ", l3);
1338 if (ischosen(l3.msgs.rrm.handoverCommand)) {
1339 var RslChannelNr new_chan_nr;
1340 var GsmArfcn arfcn;
1341 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
1342 new_chan_nr, arfcn);
1343 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
1344
1345 /* register our component for this channel number at the RSL Emulation */
1346 f_rslem_register(0, new_chan_nr, RSL1_PROC);
1347
1348 /* resume processing of RSL DChan messages, which was temporarily suspended
1349 * before performing a hand-over */
1350 f_rslem_resume(RSL1_PROC);
1351
Neels Hofmeyr378a49c2018-06-15 22:18:43 +02001352 /* send handover detect */
1353 RSL1.send(ts_RSL_HANDO_DET(new_chan_nr));
1354 f_sleep(0.3);
1355
Harald Welte261af4b2018-02-12 21:20:39 +01001356 /* send handover complete over the new channel */
1357 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
Neels Hofmeyrd07ee132018-07-14 22:28:29 +02001358 RSL1.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
Harald Welte261af4b2018-02-12 21:20:39 +01001359 enc_PDU_ML3_MS_NW(l3_tx)));
1360 /* by default, send via the new channel from now */
1361 st.old_chan_nr := g_chan_nr;
1362 g_chan_nr := new_chan_nr;
1363 st.rr_ho_cmpl_seen := true;
Philipp Maierc1e95c82018-07-18 16:03:00 +02001364
1365 /* Memorize how many MDCX we have seen before. We need this number to detect
1366 * that we have received the handover related MDCX */
1367 st.mdcx_seen_before_ho := g_media.mgcp_conn[0].mdcx_seen;
Harald Welte261af4b2018-02-12 21:20:39 +01001368 repeat;
1369 } else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001370 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected L3 received", l3));
Harald Welte261af4b2018-02-12 21:20:39 +01001371 }
1372 }
Philipp Maierc1e95c82018-07-18 16:03:00 +02001373 [st.rr_ho_cmpl_seen] as_Media_ipacc();
Philipp Maier09f1c6d2020-09-14 21:28:52 +02001374 [st.rr_ho_cmpl_seen] as_Media_mgw();
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01001375 [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_DEACT_SACCH(st.old_chan_nr)) {
1376 repeat;
1377 }
Harald Welte261af4b2018-02-12 21:20:39 +01001378 [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_REL_REQ(st.old_chan_nr, tr_RslLinkID_DCCH(0))) {
1379 RSL.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1380 repeat;
1381 }
1382 [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) {
1383 RSL.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr));
1384 /* unregister for old channel number in RSL emulation */
1385 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
1386 f_rslem_unregister(0, st.old_chan_nr);
Philipp Maierc1e95c82018-07-18 16:03:00 +02001387
1388 /* The channel release must not necessarly be synchronized to the RSL handover
1389 * procedure since those events may happen independently nearly at the same
1390 * time. When we receive the RSL_RF_CHAN_REL command the media negotiation on
1391 * IPACC or MGCP level may be still in progress. In order to make sure that
1392 * we do only stop when we have seen an MDCX on MGCP level and another a CRCX
Neels Hofmeyrffd2ef12020-10-12 18:45:58 +00001393 * as well as an MDCX on IPACC level.
1394 * If ipa_crcx_seen is false, this is not a voice channel and we need not check MGCP at all.. */
1395 if (g_media.bts.ipa_crcx_seen
1396 and (g_media.mgcp_conn[0].mdcx_seen <= st.mdcx_seen_before_ho or
1397 g_media.bts1.ipa_mdcx_seen == false or g_media.bts1.ipa_crcx_seen == false)) {
Philipp Maierc1e95c82018-07-18 16:03:00 +02001398 repeat;
1399 } else {
1400 st.handover_done := true;
1401 }
Harald Welte261af4b2018-02-12 21:20:39 +01001402 }
1403}
1404
1405
Harald Weltec1a2fff2017-12-17 11:06:19 +01001406
Harald Welte28d943e2017-11-25 15:00:50 +01001407}