blob: 3cc8f8a67ab47f388b7ac46bbe8990899d2933ad [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;
Harald Welte28d943e2017-11-25 15:00:50 +010018import from SCCPasp_Types all;
19import from BSSAP_Types all;
Harald Welte6811d102019-04-14 22:23:14 +020020import from RAN_Emulation all;
Harald Welte28d943e2017-11-25 15:00:50 +010021import from BSSMAP_Templates all;
22
Harald Welte211219e2018-01-29 22:03:36 +010023import from IPL4asp_Types all;
24import from Native_Functions all;
25
Harald Welte28d943e2017-11-25 15:00:50 +010026import from MGCP_Types all;
27import from MGCP_Templates all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010028import from MGCP_Emulation all;
Harald Welte28d943e2017-11-25 15:00:50 +010029import from SDP_Types all;
30
Harald Weltec1a2fff2017-12-17 11:06:19 +010031import from RSL_Emulation all;
32import from RSL_Types all;
33
34import from MobileL3_Types all;
35import from MobileL3_CommonIE_Types all;
Harald Welte211219e2018-01-29 22:03:36 +010036import from MobileL3_RRM_Types all;
Harald Weltec1a2fff2017-12-17 11:06:19 +010037import from L3_Templates all;
38
Harald Weltec20b1c42018-02-12 20:50:08 +010039import from TELNETasp_PortType all;
40import from Osmocom_VTY_Functions all;
41
Harald Weltec1a2fff2017-12-17 11:06:19 +010042
Harald Welte211219e2018-01-29 22:03:36 +010043/***********************************************************************
44 * Media related handling
45 ***********************************************************************/
46
Philipp Maier11a58942018-06-25 16:40:48 +020047/* Get the matching payload type for a specified BSSAP codec type
48 * (see also: BSSAP_Types.ttcn */
49private function f_get_mgcp_pt(BSSMAP_FIELD_CodecType codecType) return SDP_FIELD_PayloadType {
50 if (codecType == GSM_FR) {
51 return PT_GSM;
52 } else if (codecType == GSM_HR) {
53 return PT_GSMHR;
54 } else if (codecType == GSM_EFR) {
55 return PT_GSMEFR;
56 } else if (codecType == FR_AMR or codecType == HR_AMR) {
57 return PT_AMR;
58 } else if (codecType == FR_AMR_WB or codecType == OHR_AMR or codecType == OFR_AMR_WB or codecType == OHR_AMR_WB) {
59 return PT_AMRWB;
60 }
61
62 return PT_PCMU;
63}
64
Harald Welte211219e2018-01-29 22:03:36 +010065/* Tuple containing host/ip and port */
66type record HostPort {
67 HostName host,
68 PortNumber port_nr
69};
70
71/* State encapsulating one MGCP Connection */
72type record MgcpConnState {
Philipp Maier3e2af5d2018-07-11 17:01:05 +020073 integer crcx_seen, /* Counts how many CRCX operations happend */
74 integer mdcx_seen, /* Counts how many MDCX operations happend C */
75 integer crcx_seen_exp, /* Sets the expected number of CRCX operations */
76 integer mdcx_seen_exp, /* Sets the expected number of MDCX operations */
Harald Welte211219e2018-01-29 22:03:36 +010077 MgcpConnectionId conn_id,
78 charstring mime_type, /* e.g. AMR */
79 integer sample_rate, /* 8000 */
80 integer ptime, /* 20 */
81 uint7_t rtp_pt, /* RTP Payload Type */
82 HostPort mgw, /* MGW side */
83 HostPort peer /* CA side */
84};
85
86/* BTS media state */
87type record BtsMediaState {
88 boolean ipa_crcx_seen,
Philipp Maierc1e95c82018-07-18 16:03:00 +020089 boolean ipa_mdcx_seen,
Harald Welte211219e2018-01-29 22:03:36 +010090 uint16_t conn_id,
91 uint7_t rtp_pt,
92 HostPort bts,
93 HostPort peer
94};
95
96type record MediaState {
97 MgcpEndpoint mgcp_ep,
98 MgcpConnState mgcp_conn[2],
Harald Welte261af4b2018-02-12 21:20:39 +010099 BtsMediaState bts,
100 BtsMediaState bts1 /* only during hand-over */
Harald Welte211219e2018-01-29 22:03:36 +0100101};
102
Philipp Maier11a58942018-06-25 16:40:48 +0200103function f_MediaState_init(inout MediaState g_media, integer nr, HostName bts, HostName mgw, BSSMAP_FIELD_CodecType codecType) {
Harald Welte211219e2018-01-29 22:03:36 +0100104 /* BTS Side */
105 g_media.bts := {
106 ipa_crcx_seen := false,
Philipp Maierc1e95c82018-07-18 16:03:00 +0200107 ipa_mdcx_seen := false,
Harald Welte211219e2018-01-29 22:03:36 +0100108 conn_id := nr,
109 rtp_pt := 0,
110 bts := {
111 host := bts,
112 port_nr := 9000 + nr*2
113 },
114 peer := -
115 }
116
Harald Welte261af4b2018-02-12 21:20:39 +0100117 g_media.bts1 := {
118 ipa_crcx_seen := false,
Philipp Maierc1e95c82018-07-18 16:03:00 +0200119 ipa_mdcx_seen := false,
Harald Welte261af4b2018-02-12 21:20:39 +0100120 conn_id := nr,
121 rtp_pt := 0,
122 bts := {
123 host := bts, /* FIXME */
124 port_nr := 9000 + nr*2
125 },
126 peer := -
127 }
128
Harald Welte363cb0a2018-01-30 19:35:53 +0100129 g_media.mgcp_ep := "rtpbridge/" & int2str(nr) & "@mgw";
Harald Welte211219e2018-01-29 22:03:36 +0100130
131 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier11a58942018-06-25 16:40:48 +0200132 g_media.mgcp_conn[i].mime_type := f_encoding_name_from_pt(f_get_mgcp_pt(codecType));
Harald Welte211219e2018-01-29 22:03:36 +0100133 g_media.mgcp_conn[i].sample_rate := 8000;
134 g_media.mgcp_conn[i].ptime := 20;
Philipp Maier11a58942018-06-25 16:40:48 +0200135 g_media.mgcp_conn[i].rtp_pt := enum2int(f_get_mgcp_pt(codecType));
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200136 g_media.mgcp_conn[i].crcx_seen := 0;
137 g_media.mgcp_conn[i].mdcx_seen := 0;
138 g_media.mgcp_conn[i].crcx_seen_exp := 0;
139 g_media.mgcp_conn[i].mdcx_seen_exp := 0;
Harald Welte211219e2018-01-29 22:03:36 +0100140 g_media.mgcp_conn[i].conn_id := f_mgcp_alloc_conn_id();
141 }
142
143 g_media.mgcp_conn[0].mgw := {
144 host := mgw,
145 port_nr := 10000 + nr*2
146 }
147 g_media.mgcp_conn[1].mgw := {
148 host := mgw,
149 port_nr := 11000 + nr*2
150 }
151}
152
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200153/* Helper function to get the next free MGCP connection identifier. We can
154 * recognize free connection identifiers by the fact that no CRCX happend yet */
Harald Welte211219e2018-01-29 22:03:36 +0100155private function f_get_free_mgcp_conn() runs on MSC_ConnHdlr return integer {
156 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200157 if (not g_media.mgcp_conn[i].crcx_seen >= 1) {
Harald Welte211219e2018-01-29 22:03:36 +0100158 return i;
159 }
160 }
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100161 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Only 2 Connections per EP!");
162 /* Should never be reached */
163 return -1;
Harald Welte211219e2018-01-29 22:03:36 +0100164}
165
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200166/* Helper function to pick a specific connection by its cid. Since we reach out
167 * for a connection that is in-use we also check if there was already exactly
168 * one CRCX happening on that connection. */
Harald Welte211219e2018-01-29 22:03:36 +0100169private function f_get_mgcp_conn(MgcpConnectionId cid) runs on MSC_ConnHdlr return integer {
170 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200171 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 +0100172 return i;
173 }
174 }
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100175 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No Connection for ID ", cid));
176 /* Should not be reached */
177 return -1;
Harald Welte211219e2018-01-29 22:03:36 +0100178}
179
Philipp Maierb2422352018-07-11 10:36:57 +0200180/* altstep for handling of IPACC media related commands. Activated by as_Media() to test
181 * RSL level media handling */
182altstep as_Media_ipacc() runs on MSC_ConnHdlr {
Harald Welte211219e2018-01-29 22:03:36 +0100183 var RSL_Message rsl;
Harald Welte211219e2018-01-29 22:03:36 +0100184 var RSL_IE_Body ie;
Harald Welte930d0a72018-03-22 22:08:40 +0100185 var boolean b_unused;
Harald Welte211219e2018-01-29 22:03:36 +0100186 [not g_media.bts.ipa_crcx_seen] RSL.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl {
187 /* Extract parameters from request + use in response */
188 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
189 g_media.bts.rtp_pt := ie.ipa_rtp_pt;
190 }
191 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
192 g_media.bts.rtp_pt := ie.ipa_rtp_pt2;
193 }
194 RSL.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts.conn_id,
195 oct2int(f_inet_addr(g_media.bts.bts.host)),
196 g_media.bts.bts.port_nr,
197 g_media.bts.rtp_pt));
198 g_media.bts.ipa_crcx_seen := true;
199 repeat;
200 }
201 [g_media.bts.ipa_crcx_seen] RSL.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{
202 /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */
Harald Welte930d0a72018-03-22 22:08:40 +0100203 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie);
Harald Welte211219e2018-01-29 22:03:36 +0100204 if (g_media.bts.conn_id != ie.ipa_conn_id) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100205 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("IPA MDCX for unknown ConnId", rsl));
Harald Welte211219e2018-01-29 22:03:36 +0100206 }
207 /* mandatory */
Harald Welte930d0a72018-03-22 22:08:40 +0100208 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_IP, ie);
Harald Welte211219e2018-01-29 22:03:36 +0100209 g_media.bts.peer.host := f_inet_ntoa(int2oct(ie.ipa_remote_ip, 4));
Harald Welte930d0a72018-03-22 22:08:40 +0100210 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_PORT, ie);
Harald Welte211219e2018-01-29 22:03:36 +0100211 g_media.bts.peer.port_nr := ie.ipa_remote_port;
212 /* optional */
213 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
214 g_media.bts.rtp_pt := ie.ipa_rtp_pt;
215 }
216 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
217 g_media.bts.rtp_pt := ie.ipa_rtp_pt2;
218 }
219 RSL.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts.conn_id,
220 oct2int(f_inet_addr(g_media.bts.peer.host)),
221 g_media.bts.peer.port_nr,
222 g_media.bts.rtp_pt));
Philipp Maierc1e95c82018-07-18 16:03:00 +0200223 g_media.bts.ipa_mdcx_seen := true;
Harald Welte211219e2018-01-29 22:03:36 +0100224 repeat;
225 }
Harald Welte261af4b2018-02-12 21:20:39 +0100226
227 /* on second (new) BTS during hand-over */
228 [not g_media.bts1.ipa_crcx_seen] RSL1.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl {
229 /* Extract parameters from request + use in response */
230 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
231 g_media.bts1.rtp_pt := ie.ipa_rtp_pt;
232 }
233 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
234 g_media.bts1.rtp_pt := ie.ipa_rtp_pt2;
235 }
236 RSL1.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts1.conn_id,
237 oct2int(f_inet_addr(g_media.bts1.bts.host)),
238 g_media.bts1.bts.port_nr,
239 g_media.bts1.rtp_pt));
240 g_media.bts1.ipa_crcx_seen := true;
241 repeat;
242 }
243 /* on second (new) BTS during hand-over */
244 [g_media.bts1.ipa_crcx_seen] RSL1.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{
245 /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */
Harald Welte930d0a72018-03-22 22:08:40 +0100246 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie);
Harald Welte261af4b2018-02-12 21:20:39 +0100247 if (g_media.bts1.conn_id != ie.ipa_conn_id) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100248 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("IPA MDCX for unknown ConnId", rsl));
Harald Welte261af4b2018-02-12 21:20:39 +0100249 }
250 /* mandatory */
Harald Welte930d0a72018-03-22 22:08:40 +0100251 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_IP, ie);
Harald Welte261af4b2018-02-12 21:20:39 +0100252 g_media.bts1.peer.host := f_inet_ntoa(int2oct(ie.ipa_remote_ip, 4));
Harald Welte930d0a72018-03-22 22:08:40 +0100253 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_PORT, ie);
Harald Welte261af4b2018-02-12 21:20:39 +0100254 g_media.bts1.peer.port_nr := ie.ipa_remote_port;
255 /* optional */
256 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
257 g_media.bts1.rtp_pt := ie.ipa_rtp_pt;
258 }
259 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
260 g_media.bts1.rtp_pt := ie.ipa_rtp_pt2;
261 }
262 RSL1.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts1.conn_id,
263 oct2int(f_inet_addr(g_media.bts1.peer.host)),
264 g_media.bts1.peer.port_nr,
265 g_media.bts1.rtp_pt));
Philipp Maierc1e95c82018-07-18 16:03:00 +0200266 g_media.bts1.ipa_mdcx_seen := true;
Harald Welte261af4b2018-02-12 21:20:39 +0100267 repeat;
268 }
269
Philipp Maierb2422352018-07-11 10:36:57 +0200270
271}
272
273/* altstep for handling of MGCP media related commands. Activated by as_Media() to test
274 * MGW level media handling */
Philipp Maierc1e95c82018-07-18 16:03:00 +0200275altstep as_Media_mgw(boolean norepeat := false) runs on MSC_ConnHdlr {
Philipp Maierb2422352018-07-11 10:36:57 +0200276 var MgcpCommand mgcp_cmd;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200277 var MgcpOsmuxCID osmux_cid;
Philipp Maierb2422352018-07-11 10:36:57 +0200278
Harald Welte211219e2018-01-29 22:03:36 +0100279 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
280 var SDP_Message sdp;
281 var integer cid := f_get_free_mgcp_conn();
Harald Welte363cb0a2018-01-30 19:35:53 +0100282 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard)) {
283 if (cid != 0) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100284 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "MGCP wildcard EP only works in first CRCX");
Harald Welte363cb0a2018-01-30 19:35:53 +0100285 }
286 /* we keep the endpoint name allocated during MediaState_init */
287 } else {
288 /* Call Agent allocated endpoint, trust/use it always */
289 g_media.mgcp_ep := mgcp_cmd.line.ep;
290 }
Harald Welte211219e2018-01-29 22:03:36 +0100291 if (isvalue(mgcp_cmd.sdp)) {
292 sdp := mgcp_cmd.sdp;
293 g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr;
294 g_media.mgcp_conn[cid].peer.port_nr := sdp.media_list[0].media_field.ports.port_number;
295 }
296 var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid];
297 sdp := valueof(ts_SDP(mgcp_conn.mgw.host, mgcp_conn.mgw.host, "foo", "21",
298 mgcp_conn.mgw.port_nr, { int2str(mgcp_conn.rtp_pt) },
299 {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt,
300 mgcp_conn.mime_type & "/" &
301 int2str(mgcp_conn.sample_rate))),
302 valueof(ts_SDP_ptime(mgcp_conn.ptime)) } ));
Harald Welte363cb0a2018-01-30 19:35:53 +0100303 var template MgcpResponse mgcp_resp;
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200304 if (g_pars.use_osmux and f_MgcpCmd_contains_par(mgcp_cmd, "X-OSMUX")) {
305 osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd);
306 mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, osmux_cid, sdp);
307 } else {
308 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp);
309 }
Harald Welte363cb0a2018-01-30 19:35:53 +0100310 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(g_media.mgcp_ep));
311 MGCP.send(mgcp_resp);
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200312 g_media.mgcp_conn[cid].crcx_seen := g_media.mgcp_conn[cid].crcx_seen + 1;
Philipp Maierc1e95c82018-07-18 16:03:00 +0200313 if(norepeat == false) {
314 repeat;
315 }
Harald Welte211219e2018-01-29 22:03:36 +0100316 }
317 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
318 var SDP_Message sdp;
319 var integer cid := f_get_mgcp_conn(f_MgcpCmd_extract_conn_id(mgcp_cmd));
320 if (isvalue(mgcp_cmd.sdp)) {
321 sdp := mgcp_cmd.sdp;
322 g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr;
323 g_media.mgcp_conn[cid].peer.port_nr := sdp.media_list[0].media_field.ports.port_number;
324 } else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100325 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "MDCX has no [recognizable] SDP");
Harald Welte211219e2018-01-29 22:03:36 +0100326 }
327 var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid];
328 sdp := valueof(ts_SDP(mgcp_conn.peer.host, mgcp_conn.peer.host, "foo", "21",
329 mgcp_conn.peer.port_nr, { int2str(mgcp_conn.rtp_pt) },
330 {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt,
331 mgcp_conn.mime_type & "/" &
332 int2str(mgcp_conn.sample_rate))),
333 valueof(ts_SDP_ptime(mgcp_conn.ptime)) } ));
334 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp));
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200335 g_media.mgcp_conn[cid].mdcx_seen := g_media.mgcp_conn[cid].mdcx_seen + 1;
Philipp Maierc1e95c82018-07-18 16:03:00 +0200336 if(norepeat == false) {
337 repeat;
338 }
Harald Welte211219e2018-01-29 22:03:36 +0100339 }
340}
341
Philipp Maierb2422352018-07-11 10:36:57 +0200342/* Altsteps for handling of media related commands. Can be activated by a given
343 * test case if it expects to see media related handling (i.e. voice calls) */
344altstep as_Media() runs on MSC_ConnHdlr {
345 [] as_Media_ipacc();
346 [] as_Media_mgw();
347}
Harald Welte211219e2018-01-29 22:03:36 +0100348
Harald Welte28d943e2017-11-25 15:00:50 +0100349/* this component represents a single subscriber connection at the MSC.
Harald Welte6811d102019-04-14 22:23:14 +0200350 * There is a 1:1 mapping between SCCP connections and RAN_ConnHdlr components.
351 * We inherit all component variables, ports, functions, ... from RAN_ConnHdlr */
352type component MSC_ConnHdlr extends RAN_ConnHdlr, RSL_DchanHdlr, MGCP_ConnHdlr {
Harald Welte28d943e2017-11-25 15:00:50 +0100353 /* SCCP Connecction Identifier for the underlying SCCP connection */
354 var integer g_sccp_conn_id;
355
Harald Welte6811d102019-04-14 22:23:14 +0200356 /* procedure port back to our parent (RAN_Emulation_CT) for control */
357 port RAN_PROC_PT RAN;
Harald Weltec20b1c42018-02-12 20:50:08 +0100358 port TELNETasp_PT BSCVTY;
Harald Welte28d943e2017-11-25 15:00:50 +0100359
Harald Welte211219e2018-01-29 22:03:36 +0100360 var MediaState g_media;
Harald Weltea0630032018-03-20 21:09:55 +0100361 var TestHdlrParams g_pars;
Harald Weltee97eab42018-03-21 18:46:06 +0100362
363 var boolean g_vty_initialized := false;
Harald Welte211219e2018-01-29 22:03:36 +0100364}
365
366/* initialize all parameters */
Philipp Maier11a58942018-06-25 16:40:48 +0200367function f_MscConnHdlr_init(integer i, HostName bts, HostName mgw, BSSMAP_FIELD_CodecType codecType) runs on MSC_ConnHdlr {
368 f_MediaState_init(g_media, i, bts, mgw, codecType);
Harald Weltee97eab42018-03-21 18:46:06 +0100369 if (not g_vty_initialized) {
370 map(self:BSCVTY, system:BSCVTY);
371 f_vty_set_prompts(BSCVTY);
372 f_vty_transceive(BSCVTY, "enable");
373 g_vty_initialized := true;
374 }
Harald Welte28d943e2017-11-25 15:00:50 +0100375}
376
Harald Welte6811d102019-04-14 22:23:14 +0200377/* Callback function from general RAN_Emulation whenever a connectionless
Harald Welte28d943e2017-11-25 15:00:50 +0100378 * BSSMAP message arrives. Can retunr a PDU_BSSAP that should be sent in return */
379private function UnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200380runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Welte28d943e2017-11-25 15:00:50 +0100381 var template PDU_BSSAP resp := omit;
382
Harald Weltec1a2fff2017-12-17 11:06:19 +0100383 /* answer all RESET with a RESET ACK */
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200384 if (match(bssap, tr_BSSMAP_Reset(g_ran_ops.use_osmux))) {
385 resp := ts_BSSMAP_ResetAck(g_ran_ops.use_osmux);
Harald Welte28d943e2017-11-25 15:00:50 +0100386 }
387
388 return resp;
389}
390
Harald Welte6811d102019-04-14 22:23:14 +0200391const RanOps MSC_RanOps := {
392 create_cb := refers(RAN_Emulation.ExpectedCreateCallback),
Harald Welte0b476062018-01-21 19:07:32 +0100393 unitdata_cb := refers(UnitdataCallback),
394 decode_dtap := false,
Harald Welte930d0a72018-03-22 22:08:40 +0100395 role_ms := false,
Harald Welte2fce7882019-04-15 11:48:05 +0200396 protocol := RAN_PROTOCOL_BSSAP,
Pau Espin Pedrolc6b78ff2019-06-06 15:58:17 +0200397 transport := BSSAP_TRANSPORT_AoIP,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200398 use_osmux := false,
Harald Welte930d0a72018-03-22 22:08:40 +0100399 sccp_addr_local := omit,
400 sccp_addr_peer := omit
Harald Welte28d943e2017-11-25 15:00:50 +0100401}
402
Daniel Willmann191e0d92018-01-17 12:44:35 +0100403const MGCPOps MSC_MGCPOps := {
Harald Welte930d0a72018-03-22 22:08:40 +0100404 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
405 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
Daniel Willmann191e0d92018-01-17 12:44:35 +0100406}
407
Harald Weltec1a2fff2017-12-17 11:06:19 +0100408/* register an expect with the BSSMAP core */
Daniel Willmann191e0d92018-01-17 12:44:35 +0100409private function f_create_bssmap_exp(octetstring l3_enc) runs on MSC_ConnHdlr {
Harald Welte6811d102019-04-14 22:23:14 +0200410 RAN.call(RAN_register:{l3_enc, self}) {
411 [] RAN.getreply(RAN_register:{?, ?}) {};
Harald Welte28d943e2017-11-25 15:00:50 +0100412 }
413}
414
Harald Welte651fcdc2018-05-10 20:23:16 +0200415type record TestHdlrEncrParams {
416 OCT1 enc_alg,
417 octetstring enc_key
418};
419
420template (value) TestHdlrEncrParams t_EncrParams(OCT1 alg, octetstring key) := {
421 enc_alg := alg,
422 enc_key := key
423}
424
Harald Weltecc0b0142018-05-29 15:19:33 +0200425type record TestHdlrParamsLcls {
426 GlobalCallReferenceValue gcr optional,
427 /* LCLS Configuration */
428 BIT4 cfg optional,
429 /* LCLS Connection Status Control */
430 BIT4 csc optional,
Max2eeb5112018-11-06 19:21:41 +0100431 BIT4 exp_sts optional,
432 /* Whether to adjust *cx_seen_exp for LCLS tests */
433 boolean adjust_cx_exp
Harald Weltecc0b0142018-05-29 15:19:33 +0200434}
435
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100436type record TestHdlrParamsHandover {
437 SCCP_PAR_Address sccp_addr_msc,
438 SCCP_PAR_Address sccp_addr_bsc
439}
440
Harald Weltec1a2fff2017-12-17 11:06:19 +0100441type record TestHdlrParams {
442 OCT1 ra,
443 GsmFrameNumber fn,
444 hexstring imsi,
Harald Welte60aa5762018-03-21 19:33:13 +0100445 RslLinkId link_id,
Harald Weltecbe911c2018-06-01 18:23:07 +0200446 integer media_nr, /* determins MGCP EP, port numbers */
Harald Welte651fcdc2018-05-10 20:23:16 +0200447 BSSMAP_IE_SpeechCodecList ass_codec_list optional,
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +0200448 RSL_IE_Body expect_mr_conf_ie optional, /* typically present for AMR codecs */
Philipp Maierd0e64b02019-03-13 14:15:23 +0100449 bitstring expect_mr_s0_s7 optional, /* typically present for AMR codecs */
Harald Weltecc0b0142018-05-29 15:19:33 +0200450 TestHdlrEncrParams encr optional,
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100451 TestHdlrParamsLcls lcls,
Philipp Maier48604732018-10-09 15:00:37 +0200452 TestHdlrParamsHandover handover optional,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200453 boolean aoip,
454 boolean use_osmux
Harald Weltec1a2fff2017-12-17 11:06:19 +0100455};
456
Philipp Maier48604732018-10-09 15:00:37 +0200457/* Note: Do not use valueof() to get a value of this template, use
458 * f_gen_test_hdlr_pars() instead in order to get a configuration that is
Maxd4e56962018-10-31 19:08:25 +0100459 * matched to the current test situation (aoio vs. sccplite) */
Harald Weltec1a2fff2017-12-17 11:06:19 +0100460template (value) TestHdlrParams t_def_TestHdlrPars := {
461 ra := '23'O,
462 fn := 23,
463 imsi := '001019876543210'H,
Harald Welte60aa5762018-03-21 19:33:13 +0100464 link_id := valueof(ts_RslLinkID_DCCH(0)),
Harald Weltecbe911c2018-06-01 18:23:07 +0200465 media_nr := 1,
Harald Welte651fcdc2018-05-10 20:23:16 +0200466 ass_codec_list := omit,
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +0200467 expect_mr_conf_ie := omit,
Philipp Maierd0e64b02019-03-13 14:15:23 +0100468 expect_mr_s0_s7 := omit,
Harald Weltecc0b0142018-05-29 15:19:33 +0200469 encr := omit,
470 lcls := {
471 gcr := omit,
472 cfg := omit,
473 csc := omit,
Max2eeb5112018-11-06 19:21:41 +0100474 exp_sts := omit,
475 adjust_cx_exp := true
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100476 },
Philipp Maier48604732018-10-09 15:00:37 +0200477 handover := omit,
Pau Espin Pedrolc6a53db2019-05-20 19:31:47 +0200478 aoip := true,
479 use_osmux := false
Harald Weltec1a2fff2017-12-17 11:06:19 +0100480}
481
Harald Weltea0630032018-03-20 21:09:55 +0100482function f_create_chan_and_exp() runs on MSC_ConnHdlr {
483 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
Harald Welte6ed6bf92018-01-24 21:09:15 +0100484 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
Harald Weltec1a2fff2017-12-17 11:06:19 +0100485 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
486
487 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
Harald Weltea0630032018-03-20 21:09:55 +0100488 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
Daniel Willmann191e0d92018-01-17 12:44:35 +0100489 f_create_bssmap_exp(l3_enc);
Harald Weltec1a2fff2017-12-17 11:06:19 +0100490}
491
Harald Welte898113b2018-01-31 18:32:21 +0100492function f_rsl_send_l3(template PDU_ML3_MS_NW l3, template (omit) RslLinkId link_id := omit,
493 template (omit) RslChannelNr chan_nr := omit) runs on MSC_ConnHdlr {
494 if (not isvalue(link_id)) {
495 link_id := ts_RslLinkID_DCCH(0);
496 }
497 if (not isvalue(chan_nr)) {
498 chan_nr := g_chan_nr;
499 }
500 RSL.send(ts_RSL_DATA_IND(valueof(chan_nr), valueof(link_id), enc_PDU_ML3_MS_NW(valueof(l3))));
501}
502
Harald Weltec1a2fff2017-12-17 11:06:19 +0100503function f_rsl_reply(template PDU_ML3_MS_NW l3, RSL_Message orig) runs on MSC_ConnHdlr {
504 var RslChannelNr chan_nr := orig.ies[0].body.chan_nr;
Harald Welte1a40de62017-12-23 02:28:34 +0100505 var RslLinkId link_id;
Harald Welte8d5eead2017-12-17 18:56:45 +0100506 if (orig.msg_type == RSL_MT_ENCR_CMD) {
507 link_id := orig.ies[2].body.link_id;
508 } else {
509 link_id := orig.ies[1].body.link_id;
510 }
Harald Welte898113b2018-01-31 18:32:21 +0100511 f_rsl_send_l3(l3, link_id, chan_nr);
Harald Weltec1a2fff2017-12-17 11:06:19 +0100512}
513
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100514/* Convert the chipher representation on BSSMAP to the representation used on RSL */
Harald Weltee613f962018-04-18 22:38:16 +0200515function f_chipher_mode_bssmap_to_rsl(OCT1 alg_bssmap) return RSL_AlgId
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100516{
517 /* A5 0 */
518 if (alg_bssmap == '01'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200519 return RSL_ALG_ID_A5_0;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100520 }
521 /* A5 1 */
522 else if (alg_bssmap == '02'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200523 return RSL_ALG_ID_A5_1;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100524 }
525 /* A5 2 */
526 else if (alg_bssmap == '04'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200527 return RSL_ALG_ID_A5_2;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100528 }
529 /* A5 3 */
530 else if (alg_bssmap == '08'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200531 return RSL_ALG_ID_A5_3;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100532 }
533 /* A5 4 */
534 else if (alg_bssmap == '10'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200535 return RSL_ALG_ID_A5_4;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100536 }
537 /* A5 5 */
538 else if (alg_bssmap == '20'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200539 return RSL_ALG_ID_A5_5;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100540 }
541 /* A5 6 */
542 else if (alg_bssmap == '40'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200543 return RSL_ALG_ID_A5_6;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100544 }
545 /* A5 7 */
546 else if (alg_bssmap == '80'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200547 return RSL_ALG_ID_A5_7;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100548 } else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100549 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Encryption Algorithm");
Harald Weltee613f962018-04-18 22:38:16 +0200550 return RSL_ALG_ID_A5_0;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100551 }
552}
553
Harald Welte38b2a102017-12-23 02:42:58 +0100554function f_cipher_mode(OCT1 alg, OCT8 key, template OCT16 kc128 := omit, boolean exp_fail := false)
555runs on MSC_ConnHdlr {
Harald Welte73cd2712017-12-17 00:44:52 +0100556 var PDU_BSSAP bssap;
557 var RSL_Message rsl;
Harald Weltee613f962018-04-18 22:38:16 +0200558 var RSL_AlgId alg_rsl;
Harald Welte73cd2712017-12-17 00:44:52 +0100559
560 if (isvalue(kc128)) {
561 BSSAP.send(ts_BSSMAP_CipherModeCmdKc128(alg, key, valueof(kc128)));
562 } else {
563 BSSAP.send(ts_BSSMAP_CipherModeCmd(alg, key));
564 }
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100565
566 /* RSL uses a different representation of the encryption algorithm,
567 * so we need to convert first */
568 alg_rsl := f_chipher_mode_bssmap_to_rsl(alg);
569
Harald Welte73cd2712017-12-17 00:44:52 +0100570 alt {
571 /* RSL/UE Side */
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100572 [] RSL.receive(tr_RSL_ENCR_CMD(g_chan_nr, ?, alg_rsl, key)) -> value rsl {
Harald Welte73cd2712017-12-17 00:44:52 +0100573 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[3].body.l3_info.payload);
574 log("Rx L3 from net: ", l3);
575 if (ischosen(l3.msgs.rrm.cipheringModeCommand)) {
576 f_rsl_reply(ts_RRM_CiphModeCompl, rsl);
577 }
578 repeat;
579 }
580 [] BSSAP.receive(tr_BSSMAP_CipherModeCompl) -> value bssap {
581 // bssap.bssmap.cipherModeComplete.chosenEncryptionAlgorithm.algoritmhIdentifier
Harald Welte38b2a102017-12-23 02:42:58 +0100582 if (exp_fail == true) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100583 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Cipher Mode Complete");
Harald Welte38b2a102017-12-23 02:42:58 +0100584 } else {
585 setverdict(pass);
586 }
Harald Welte73cd2712017-12-17 00:44:52 +0100587 }
588 [] BSSAP.receive(tr_BSSMAP_CipherModeRej) -> value bssap {
Harald Welte38b2a102017-12-23 02:42:58 +0100589 if (exp_fail == false) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100590 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Ciphering Mode Reject");
Harald Welte38b2a102017-12-23 02:42:58 +0100591 } else {
592 setverdict(pass);
593 }
Harald Welte73cd2712017-12-17 00:44:52 +0100594 }
595 }
596}
597
Harald Welte211219e2018-01-29 22:03:36 +0100598/* Convert from Ericsson ChanDesc2 format to Osmocom RslChannelNr format */
599function f_ChDesc2RslChanNr(ChannelDescription2_V ch_desc, out RslChannelNr chan_nr, out GsmArfcn arfcn) {
600 var BIT5 inp := ch_desc.channelTypeandTDMAOffset;
Harald Welte6fa1f732018-03-21 22:46:16 +0100601 var uint3_t tn := bit2int(ch_desc.timeslotNumber);
Harald Welte211219e2018-01-29 22:03:36 +0100602
603 if (match(inp, '00001'B)) { /* TCH/F */
Harald Welte6fa1f732018-03-21 22:46:16 +0100604 chan_nr := valueof(t_RslChanNr_Bm(tn));
Harald Welte211219e2018-01-29 22:03:36 +0100605 }
606 else if (match(inp, '0001?'B)) { /* TCH/H */
Harald Welte6fa1f732018-03-21 22:46:16 +0100607 chan_nr := valueof(t_RslChanNr_Lm(tn, bit2int(substr(inp, 4, 1))));
Harald Welte211219e2018-01-29 22:03:36 +0100608 }
609 else if (match(inp, '001??'B)) { /* SDCCH/4 */
Harald Welte6fa1f732018-03-21 22:46:16 +0100610 chan_nr := valueof(t_RslChanNr_SDCCH4(tn, bit2int(substr(inp, 3, 2))));
Harald Welte211219e2018-01-29 22:03:36 +0100611 }
612 else if (match(inp, '01???'B)) { /* SDCCH/8 */
Harald Welte6fa1f732018-03-21 22:46:16 +0100613 chan_nr := valueof(t_RslChanNr_SDCCH8(tn, bit2int(substr(inp, 2, 3))));
Harald Welte211219e2018-01-29 22:03:36 +0100614 }
615 else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100616 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown ChDesc!");
Harald Welte211219e2018-01-29 22:03:36 +0100617 }
618
619 if (ch_desc.octet3 and4b '10'O == '10'O) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100620 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No support for Hopping");
Harald Welte211219e2018-01-29 22:03:36 +0100621 } else {
622 var OCT2 concat := ch_desc.octet3 & ch_desc.octet4;
623 arfcn := oct2int(concat);
624 }
625}
626
627type record AssignmentState {
628 /* global */
629 boolean voice_call,
630 boolean is_assignment,
631 /* Assignment related bits */
632 boolean rr_ass_cmpl_seen,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100633 boolean old_lchan_deact_sacch_seen,
634 boolean old_lchan_rll_rel_req_seen,
Harald Welte21583082018-01-29 22:28:26 +0100635 boolean assignment_done,
Harald Welte211219e2018-01-29 22:03:36 +0100636 RslChannelNr old_chan_nr,
637 /* Modify related bits */
638 boolean rr_modify_seen,
Harald Welte21583082018-01-29 22:28:26 +0100639 boolean modify_done
Harald Welte211219e2018-01-29 22:03:36 +0100640}
641
642template (value) AssignmentState ts_AssignmentStateInit := {
643 voice_call := false,
644 is_assignment := false,
645 rr_ass_cmpl_seen := false,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100646 old_lchan_deact_sacch_seen := false,
647 old_lchan_rll_rel_req_seen := false,
Harald Welte21583082018-01-29 22:28:26 +0100648 assignment_done := false,
Harald Welte211219e2018-01-29 22:03:36 +0100649 old_chan_nr := -,
650 rr_modify_seen := false,
Harald Welte21583082018-01-29 22:28:26 +0100651 modify_done := false
Harald Welte211219e2018-01-29 22:03:36 +0100652}
653
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200654private template RSL_IE_Body tr_EncrInfo(template RSL_AlgId alg, template octetstring key) := {
655 encr_info := {
656 len := ?,
657 alg_id := alg,
658 key := key
659 }
660}
661
662/* ensure the RSL CHAN ACT (during assignment) contains values we expect depending on test case */
663private function f_check_chan_act(AssignmentState st, RSL_Message chan_act) runs on MSC_ConnHdlr {
664 var RSL_IE_Body encr_info;
665 if (ispresent(g_pars.encr) and g_pars.encr.enc_alg != '01'O) {
666 if (not f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100667 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Missing Encryption IE in CHAN ACT");
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200668 } else {
669 var RSL_AlgId alg := f_chipher_mode_bssmap_to_rsl(g_pars.encr.enc_alg);
670 if (not match(encr_info, tr_EncrInfo(alg, g_pars.encr.enc_key))) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100671 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong Encryption IE in CHAN ACT");
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200672 }
673 }
674 } else {
675 if (f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) {
676 if (encr_info.encr_info.alg_id != RSL_ALG_ID_A5_0) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100677 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Encryption in CHAN ACT");
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200678 }
679 }
680 }
681 /* FIXME: validate RSL_IE_ACT_TYPE, RSL_IE_CHAN_MODE, RSL_IE_CHAN_IDENT, RSL_IE_BS_POWER,
682 * RSL_IE_MS_POWER, RSL_IE_TIMING_ADVANCE */
683}
684
Harald Welte211219e2018-01-29 22:03:36 +0100685altstep as_assignment(inout AssignmentState st) runs on MSC_ConnHdlr {
Harald Weltec1a2fff2017-12-17 11:06:19 +0100686 var RSL_Message rsl;
Harald Welte211219e2018-01-29 22:03:36 +0100687 [not st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
688 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
689 log("Rx L3 from net: ", l3);
690 if (ischosen(l3.msgs.rrm.assignmentCommand)) {
691 var RslChannelNr new_chan_nr;
692 var GsmArfcn arfcn;
693 f_ChDesc2RslChanNr(l3.msgs.rrm.assignmentCommand.descrOf1stChAfterTime,
694 new_chan_nr, arfcn);
695 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
Harald Weltec1a2fff2017-12-17 11:06:19 +0100696
Harald Welte211219e2018-01-29 22:03:36 +0100697 /* register our component for this channel number at the RSL Emulation */
698 f_rslem_register(0, new_chan_nr);
699 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_AssignmentComplete('00'O));
700 /* send assignment complete over the new channel */
Neels Hofmeyrb0e73652018-07-14 21:56:51 +0200701 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
Harald Welte211219e2018-01-29 22:03:36 +0100702 enc_PDU_ML3_MS_NW(l3_tx)));
703 /* by default, send via the new channel from now */
704 st.old_chan_nr := g_chan_nr;
705 g_chan_nr := new_chan_nr;
706 st.rr_ass_cmpl_seen := true;
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200707 /* obtain channel activation from RSL_Emulation for new channel */
708 var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
709 /* check it (e.g. for correct ciphering parameters) */
710 f_check_chan_act(st, chan_act);
Harald Welte211219e2018-01-29 22:03:36 +0100711 repeat;
712 } else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100713 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected L3 received", l3));
Harald Weltec1a2fff2017-12-17 11:06:19 +0100714 }
Harald Welte211219e2018-01-29 22:03:36 +0100715 }
Neels Hofmeyr861a4c12018-11-07 01:23:17 +0100716 [st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_DEACT_SACCH(st.old_chan_nr)) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100717 st.old_lchan_deact_sacch_seen := true;
Neels Hofmeyr861a4c12018-11-07 01:23:17 +0100718 repeat;
719 }
Harald Welte211219e2018-01-29 22:03:36 +0100720 [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 +0100721 st.old_lchan_rll_rel_req_seen := true;
Harald Welte211219e2018-01-29 22:03:36 +0100722 RSL.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
723 repeat;
724 }
725 [st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) {
726 RSL.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr));
Harald Welte1909f462018-01-29 22:29:29 +0100727 /* unregister for old channel number in RSL emulation */
728 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
729 f_rslem_unregister(0, st.old_chan_nr);
Harald Welte21583082018-01-29 22:28:26 +0100730 st.assignment_done := true;
Harald Welte211219e2018-01-29 22:03:36 +0100731 repeat;
732 }
733}
734
735altstep as_modify(inout AssignmentState st) runs on MSC_ConnHdlr {
736 /* no assignment, just mode modify */
737 var RSL_Message rsl;
738
739 [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 +0100740 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
741 log("Rx L3 from net: ", l3);
742 if (ischosen(l3.msgs.rrm.channelModeModify)) {
743 f_rsl_reply(ts_RRM_ModeModifyAck(l3.msgs.rrm.channelModeModify.channelDescription,
744 l3.msgs.rrm.channelModeModify.channelMode), rsl);
Harald Welte211219e2018-01-29 22:03:36 +0100745 st.rr_modify_seen := true;
Harald Weltec1a2fff2017-12-17 11:06:19 +0100746 }
747 repeat;
748 }
Harald Welte211219e2018-01-29 22:03:36 +0100749 [st.voice_call and st.rr_modify_seen] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_MODE_MODIFY_REQ)) -> value rsl {
Harald Weltec1a2fff2017-12-17 11:06:19 +0100750 RSL.send(ts_RSL_MODE_MODIFY_ACK(g_chan_nr));
Harald Welte21583082018-01-29 22:28:26 +0100751 st.modify_done := true;
Harald Weltec1a2fff2017-12-17 11:06:19 +0100752 repeat;
753 }
Harald Welte211219e2018-01-29 22:03:36 +0100754}
Daniel Willmann191e0d92018-01-17 12:44:35 +0100755
Harald Welte211219e2018-01-29 22:03:36 +0100756/* Determine if given rsl_chan_nr is compatible with given BSSMAP ChannelType */
757function f_channel_compatible(BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr)
758return boolean {
759 select (bssmap.speechOrDataIndicator) {
760 case ('0011'B) { /* Signalling */
761 /* all channels support signalling */
762 return true;
763 }
764 case else { /* Speech, Speech+CTM or CSD */
765 select (bssmap.channelRateAndType) {
766 case ('08'O) { /* TCH/F */
767 select (rsl_chan_nr) {
768 case (t_RslChanNr_Bm(?)) { return true; }
769 }
770 }
771 case ('09'O) { /* TCH/H */
772 select (rsl_chan_nr) {
773 case (t_RslChanNr_Lm(?, ?)) { return true; }
774 }
775 }
776 case else { /* full or half-rate */
777 select (rsl_chan_nr) {
778 case (t_RslChanNr_Bm(?)) { return true; }
779 case (t_RslChanNr_Lm(?, ?)) { return true; }
780 }
781 }
782 }
Harald Weltec1a2fff2017-12-17 11:06:19 +0100783 }
Harald Welte211219e2018-01-29 22:03:36 +0100784 }
785 return false;
786}
Daniel Willmann191e0d92018-01-17 12:44:35 +0100787
Philipp Maier8ef527e2018-05-18 11:12:50 +0200788/* Determine if the channel mode specified within rsl_chan_nr requires a
789 * MODE MODIFY in to match the channel mode specified by given BSSMAP
790 * ChannelType */
791function f_channel_needs_modify(BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr)
792return boolean {
793
794 /* FIXME: This tests the rsl_chan_nr to determine if we are on a
795 * signalling channel or not. Unfortunately this may lead to false
796 * results if we are on a TCH. The problem is that a TCH may be also
797 * used in signalling mode, but this function assumes that only SDCCH4
798 * and SDCCH8 are used as signalling channels at all. */
799
800 var boolean current_signalling := false;
801 var boolean desired_signalling := false;
802
803 select (rsl_chan_nr) {
804 case (t_RslChanNr_SDCCH4(?, ?)) { current_signalling := true; }
805 case (t_RslChanNr_SDCCH8(?, ?)) { current_signalling := true; }
806 }
807
808 if (bssmap.speechOrDataIndicator == '0011'B) {
809 desired_signalling := true;
810 }
811
812 if (current_signalling == desired_signalling) {
813 /* The desired channel mode is equal to the one we currently
814 * have, there is no mode modification needed or expected */
815 return false;
816 } else {
817 /* The desired channel mode and the current channel mode do
818 * not match. A mode modification is required */
819 return true;
820 }
821}
822
Harald Weltecc0b0142018-05-29 15:19:33 +0200823/* patch an BSSMAP ASS REQ with LCLS related IEs, depending on g_params */
824function f_ass_patch_lcls(inout template (omit) PDU_BSSAP ass_tpl,
825 inout template PDU_BSSAP ass_cpl) runs on MSC_ConnHdlr {
826 if (istemplatekind(ass_tpl, "omit")) {
827 return;
828 }
829 if (ispresent(g_pars.lcls.gcr)) {
830 ass_tpl.pdu.bssmap.assignmentRequest.globalCallReference := ts_BSSMAP_IE_GCR(g_pars.lcls.gcr);
831 }
832 if (ispresent(g_pars.lcls.cfg)) {
833 ass_tpl.pdu.bssmap.assignmentRequest.lCLS_Configuration := ts_BSSMAP_IE_LclsCfg(g_pars.lcls.cfg);
834 }
835 if (ispresent(g_pars.lcls.csc)) {
836 ass_tpl.pdu.bssmap.assignmentRequest.lCLS_ConnectionStatusControl := ts_BSSMAP_IE_LclsCsc(g_pars.lcls.csc);
837 }
Harald Welte343b7742018-06-05 23:41:37 +0200838 if (ischosen(ass_cpl.pdu.bssmap.assignmentComplete)) {
839 if (ispresent(g_pars.lcls.exp_sts)) {
840 ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status := tr_BSSMAP_IE_LclsSts(g_pars.lcls.exp_sts);
841 } else {
842 ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status := omit;
843 }
Harald Weltecc0b0142018-05-29 15:19:33 +0200844 }
845}
846
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200847/* Helper function to check if the activity on the MGCP matches what we
848 * expected */
849function f_check_mgcp_expectations() runs on MSC_ConnHdlr {
850 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier0a5d7e72018-07-16 15:13:11 +0200851 log(testcasename(), ": Check MGCP test expectations for g_media.mgcp_conn[", i , "]:",
852 " crcx_seen=", g_media.mgcp_conn[i].crcx_seen, ", crcx_seen_exp=", g_media.mgcp_conn[i].crcx_seen_exp,
853 ", mdcx_seen=", g_media.mgcp_conn[i].mdcx_seen, ", mdcx_seen_exp=", g_media.mgcp_conn[i].mdcx_seen_exp);
854
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200855 if(g_media.mgcp_conn[i].crcx_seen != g_media.mgcp_conn[i].crcx_seen_exp) {
Max4b0f4962018-11-06 19:20:24 +0100856 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 +0200857 }
858 if(g_media.mgcp_conn[i].mdcx_seen != g_media.mgcp_conn[i].mdcx_seen_exp) {
Max4b0f4962018-11-06 19:20:24 +0100859 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 +0200860 }
861 }
862}
863
Harald Welte211219e2018-01-29 22:03:36 +0100864/* establish a channel fully, expecting an assignment matching 'exp' */
Harald Welte7a14fd52018-05-10 22:26:55 +0200865function f_establish_fully(template (omit) PDU_BSSAP ass_tpl, template PDU_BSSAP exp_ass_cpl)
866runs on MSC_ConnHdlr {
Philipp Maier11a58942018-06-25 16:40:48 +0200867
868 var BSSMAP_FIELD_CodecType codecType;
Philipp Maier48aeeec2018-09-14 18:20:04 +0200869 timer T := 10.0;
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200870
Philipp Maier11a58942018-06-25 16:40:48 +0200871 if (isvalue(ass_tpl.pdu.bssmap.assignmentRequest.codecList)) {
872 codecType := valueof(ass_tpl.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
873 } else {
874 /* Make sure a meaningful default is assigned in case the
875 * codecList is not populated */
876 codecType := FR_AMR;
877 }
878
879 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", codecType);
Harald Welte7a14fd52018-05-10 22:26:55 +0200880
Harald Weltecc0b0142018-05-29 15:19:33 +0200881 /* patch in the LCLS related items, as needed */
882 f_ass_patch_lcls(ass_tpl, exp_ass_cpl);
883
Harald Welte7a14fd52018-05-10 22:26:55 +0200884 f_create_chan_and_exp();
885 /* we should now have a COMPL_L3 at the MSC */
Philipp Maier48aeeec2018-09-14 18:20:04 +0200886
887 var template PDU_BSSAP exp_l3_compl;
888 exp_l3_compl := tr_BSSMAP_ComplL3()
Philipp Maier48604732018-10-09 15:00:37 +0200889 if (g_pars.aoip == false) {
Philipp Maier48aeeec2018-09-14 18:20:04 +0200890 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
891 } else {
892 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
893 }
894 T.start;
895 alt {
896 [] BSSAP.receive(exp_l3_compl);
897 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100898 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
Philipp Maier48aeeec2018-09-14 18:20:04 +0200899 }
900 [] T.timeout {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100901 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
Philipp Maier48aeeec2018-09-14 18:20:04 +0200902 }
903 }
Harald Welte7a14fd52018-05-10 22:26:55 +0200904
905 /* start ciphering, if requested */
906 if (ispresent(g_pars.encr)) {
907 f_cipher_mode(g_pars.encr.enc_alg, g_pars.encr.enc_key);
908 }
909
910 /* bail out early if no assignment requested */
911 if (istemplatekind(ass_tpl, "omit")) {
912 return;
913 }
914
915 var PDU_BSSAP ass_cmd := valueof(ass_tpl);
Harald Welte211219e2018-01-29 22:03:36 +0100916 var PDU_BSSAP bssap;
Harald Welte211219e2018-01-29 22:03:36 +0100917 var boolean exp_compl := ischosen(exp_ass_cpl.pdu.bssmap.assignmentComplete);
Philipp Maier86f39202018-02-07 14:40:09 +0100918 var boolean exp_fail := ischosen(exp_ass_cpl.pdu.bssmap.assignmentFailure);
Philipp Maier8ef527e2018-05-18 11:12:50 +0200919 var boolean exp_modify;
Philipp Maier48aeeec2018-09-14 18:20:04 +0200920
Harald Welte211219e2018-01-29 22:03:36 +0100921 var ExpectCriteria mgcpcrit := {
922 connid := omit,
923 endpoint := omit,
924 transid := omit
925 };
926 var AssignmentState st := valueof(ts_AssignmentStateInit);
927 /* if the channel type is SIGNAL, we're not handling a voice call */
928 if (ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechOrDataIndicator != '0011'B) {
929 st.voice_call := true;
Philipp Maier8ef527e2018-05-18 11:12:50 +0200930 exp_modify := true;
Harald Welte211219e2018-01-29 22:03:36 +0100931 }
Philipp Maier8ef527e2018-05-18 11:12:50 +0200932
Harald Welte211219e2018-01-29 22:03:36 +0100933 /* determine if the current channel can support the given service or not */
934 if (not f_channel_compatible(ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr)) {
935 st.is_assignment := true;
Philipp Maier8ef527e2018-05-18 11:12:50 +0200936
937 /* We decided to assign a new channel, so we do not expect
938 * any mode modify messages on RSL */
939 exp_modify := false;
940 } else {
941 /* We will continue working with the currently assigned
942 * channel, we must now check if the mode of the current
943 * channel is compatible. If not we expect the BSC to modify
944 * the mode */
945 exp_modify := f_channel_needs_modify(ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr);
Harald Welte211219e2018-01-29 22:03:36 +0100946 }
947
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200948 /* Some test situations will involve MGCP transactions on a media
949 * gateway. Depending on the situation, we set up how many of each MGCP
950 * message type are expected to be exchanged. */
951 if (isbound(exp_ass_cpl.pdu.bssmap.assignmentFailure)) {
952 /* For tests that expect the assignment to fail, assume that
953 * there will be no MGW communication as well. */
954 g_media.mgcp_conn[0].crcx_seen_exp := 0;
955 g_media.mgcp_conn[0].mdcx_seen_exp := 0;
956 g_media.mgcp_conn[1].crcx_seen_exp := 0;
957 g_media.mgcp_conn[1].mdcx_seen_exp := 0;
958 } else if (st.voice_call) {
959 /* For voice calls we expect the following MGCP activity */
Philipp Maier48604732018-10-09 15:00:37 +0200960 if (g_pars.aoip == false) {
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200961 g_media.mgcp_conn[0].crcx_seen_exp := 1;
962 g_media.mgcp_conn[0].mdcx_seen_exp := 1;
963 g_media.mgcp_conn[1].crcx_seen_exp := 0;
964 g_media.mgcp_conn[1].mdcx_seen_exp := 0;
965 } else {
966 g_media.mgcp_conn[0].crcx_seen_exp := 1;
967 g_media.mgcp_conn[0].mdcx_seen_exp := 1;
968 g_media.mgcp_conn[1].crcx_seen_exp := 1;
969 g_media.mgcp_conn[1].mdcx_seen_exp := 0;
970 }
971 }
972
Harald Welte211219e2018-01-29 22:03:36 +0100973 f_create_mgcp_expect(mgcpcrit);
974 BSSAP.send(ass_cmd);
975
976 T.start;
977 alt {
978 /* assignment related bits */
979 [st.is_assignment] as_assignment(st);
980
981 /* modify related bits */
Philipp Maier8ef527e2018-05-18 11:12:50 +0200982 [not st.is_assignment and exp_modify] as_modify(st);
Harald Welte211219e2018-01-29 22:03:36 +0100983
984 /* voice call related bits (IPA CRCX/MDCX + MGCP) */
985 [st.voice_call] as_Media();
986
987 /* if we receive exactly what we expected, always return + pass */
Philipp Maier8ef527e2018-05-18 11:12:50 +0200988 [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 +0100989 setverdict(pass);
990 }
Philipp Maier86f39202018-02-07 14:40:09 +0100991 [exp_fail] BSSAP.receive(exp_ass_cpl) -> value bssap {
992 setverdict(pass);
993 }
Harald Welte21583082018-01-29 22:28:26 +0100994 [(st.is_assignment and st.assignment_done or
Philipp Maier8ef527e2018-05-18 11:12:50 +0200995 (not st.is_assignment and (st.modify_done or not exp_modify))) and
Harald Welte21583082018-01-29 22:28:26 +0100996 exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100997 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching ASSIGNMENT COMPLETE");
Harald Weltec1a2fff2017-12-17 11:06:19 +0100998 }
999 [exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001000 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected ASSIGNMENT FAIL");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001001 }
1002 [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001003 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected ASSIGNMENT COMPLETE");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001004 }
1005 [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001006 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching ASSIGNMENT FAIL");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001007 }
1008 [] T.timeout {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001009 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASSIGNMENT COMPLETE");
Harald Weltec1a2fff2017-12-17 11:06:19 +01001010 }
1011 }
Harald Welte211219e2018-01-29 22:03:36 +01001012 log("g_media ", g_media);
1013 if (not isbound(bssap)) {
Daniel Willmannafce8662018-07-06 23:11:32 +02001014 mtc.stop;
Harald Welte211219e2018-01-29 22:03:36 +01001015 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001016
Philipp Maiera0976e92018-07-16 15:19:42 +02001017 /* When the BSC detects that LCLS is possible it will cross the
1018 * connetions that point to the PBX side of the MGW. In our case this
1019 * is mgcp_conn[1]. The BSC performs this operation already before the
1020 * assignment complete is generated. This means we expect another MDCX
1021 * at mgcp_conn[1] when LCLS is expected. */
Max2eeb5112018-11-06 19:21:41 +01001022 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 +02001023 if (valueof(exp_ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status.lCLS_BSS_StatusValue) == LCLS_STS_locally_switched) {
1024 g_media.mgcp_conn[1].mdcx_seen_exp := g_media.mgcp_conn[1].mdcx_seen_exp + 1;
1025
1026 }
1027 }
1028
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001029 f_check_mgcp_expectations();
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001030
1031 if (st.is_assignment and st.assignment_done) {
1032 if (not st.old_lchan_deact_sacch_seen) {
1033 setverdict(fail, "f_establish_fully(): Assignment completed, but the old lchan was not",
1034 " released properly: expected a Deact SACCH on the old lchan, but saw none.");
1035 }
1036 if (st.old_lchan_rll_rel_req_seen) {
1037 setverdict(fail, "f_establish_fully(): Assignment completed, but the old lchan was not",
1038 " released properly: saw an RLL Release on the old lchan, but expecting none.");
1039 }
1040 }
Harald Welte930d0a72018-03-22 22:08:40 +01001041}
1042
Harald Welte261af4b2018-02-12 21:20:39 +01001043type record HandoverState {
1044 /* Assignment related bits */
1045 boolean rr_ho_cmpl_seen,
Philipp Maierc1e95c82018-07-18 16:03:00 +02001046 integer mdcx_seen_before_ho,
Harald Welte261af4b2018-02-12 21:20:39 +01001047 boolean handover_done,
1048 RslChannelNr old_chan_nr
1049};
1050
1051altstep as_handover(inout HandoverState st) runs on MSC_ConnHdlr {
1052 var RSL_Message rsl;
1053 [not st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
1054 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
1055 log("Rx L3 from net: ", l3);
1056 if (ischosen(l3.msgs.rrm.handoverCommand)) {
1057 var RslChannelNr new_chan_nr;
1058 var GsmArfcn arfcn;
1059 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
1060 new_chan_nr, arfcn);
1061 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
1062
1063 /* register our component for this channel number at the RSL Emulation */
1064 f_rslem_register(0, new_chan_nr, RSL1_PROC);
1065
1066 /* resume processing of RSL DChan messages, which was temporarily suspended
1067 * before performing a hand-over */
1068 f_rslem_resume(RSL1_PROC);
1069
Neels Hofmeyr378a49c2018-06-15 22:18:43 +02001070 /* send handover detect */
1071 RSL1.send(ts_RSL_HANDO_DET(new_chan_nr));
1072 f_sleep(0.3);
1073
Harald Welte261af4b2018-02-12 21:20:39 +01001074 /* send handover complete over the new channel */
1075 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
Neels Hofmeyrd07ee132018-07-14 22:28:29 +02001076 RSL1.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
Harald Welte261af4b2018-02-12 21:20:39 +01001077 enc_PDU_ML3_MS_NW(l3_tx)));
1078 /* by default, send via the new channel from now */
1079 st.old_chan_nr := g_chan_nr;
1080 g_chan_nr := new_chan_nr;
1081 st.rr_ho_cmpl_seen := true;
Philipp Maierc1e95c82018-07-18 16:03:00 +02001082
1083 /* Memorize how many MDCX we have seen before. We need this number to detect
1084 * that we have received the handover related MDCX */
1085 st.mdcx_seen_before_ho := g_media.mgcp_conn[0].mdcx_seen;
Harald Welte261af4b2018-02-12 21:20:39 +01001086 repeat;
1087 } else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001088 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected L3 received", l3));
Harald Welte261af4b2018-02-12 21:20:39 +01001089 }
1090 }
Philipp Maierc1e95c82018-07-18 16:03:00 +02001091 [st.rr_ho_cmpl_seen] as_Media_ipacc();
1092 [st.rr_ho_cmpl_seen] as_Media_mgw(true);
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01001093 [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_DEACT_SACCH(st.old_chan_nr)) {
1094 repeat;
1095 }
Harald Welte261af4b2018-02-12 21:20:39 +01001096 [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_REL_REQ(st.old_chan_nr, tr_RslLinkID_DCCH(0))) {
1097 RSL.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1098 repeat;
1099 }
1100 [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) {
1101 RSL.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr));
1102 /* unregister for old channel number in RSL emulation */
1103 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
1104 f_rslem_unregister(0, st.old_chan_nr);
Philipp Maierc1e95c82018-07-18 16:03:00 +02001105
1106 /* The channel release must not necessarly be synchronized to the RSL handover
1107 * procedure since those events may happen independently nearly at the same
1108 * time. When we receive the RSL_RF_CHAN_REL command the media negotiation on
1109 * IPACC or MGCP level may be still in progress. In order to make sure that
1110 * we do only stop when we have seen an MDCX on MGCP level and another a CRCX
1111 * as well as an MDCX on IPACC level. */
1112 if (g_media.mgcp_conn[0].mdcx_seen <= st.mdcx_seen_before_ho or
1113 g_media.bts1.ipa_mdcx_seen == false or g_media.bts1.ipa_crcx_seen == false) {
1114 repeat;
1115 } else {
1116 st.handover_done := true;
1117 }
Harald Welte261af4b2018-02-12 21:20:39 +01001118 }
1119}
1120
1121
Harald Weltec1a2fff2017-12-17 11:06:19 +01001122
Harald Welte28d943e2017-11-25 15:00:50 +01001123}