blob: 0ea73a0af93e09dcd6d3820c2fc4149e42d52086 [file] [log] [blame]
Harald Welte28d943e2017-11-25 15:00:50 +01001module MSC_ConnectionHandler {
2
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01003import from Misc_Helpers all;
Harald Welte28d943e2017-11-25 15:00:50 +01004import from General_Types all;
5import from Osmocom_Types all;
Harald Weltec1a2fff2017-12-17 11:06:19 +01006import from GSM_Types all;
Harald Welte28d943e2017-11-25 15:00:50 +01007import from SCCPasp_Types all;
8import from BSSAP_Types all;
9import from BSSMAP_Emulation all;
10import from BSSMAP_Templates all;
11
Harald Welte211219e2018-01-29 22:03:36 +010012import from IPL4asp_Types all;
13import from Native_Functions all;
14
Harald Welte28d943e2017-11-25 15:00:50 +010015import from MGCP_Types all;
16import from MGCP_Templates all;
Daniel Willmann191e0d92018-01-17 12:44:35 +010017import from MGCP_Emulation all;
Harald Welte28d943e2017-11-25 15:00:50 +010018import from SDP_Types all;
19
Harald Weltec1a2fff2017-12-17 11:06:19 +010020import from RSL_Emulation all;
21import from RSL_Types all;
22
23import from MobileL3_Types all;
24import from MobileL3_CommonIE_Types all;
Harald Welte211219e2018-01-29 22:03:36 +010025import from MobileL3_RRM_Types all;
Harald Weltec1a2fff2017-12-17 11:06:19 +010026import from L3_Templates all;
27
Harald Weltec20b1c42018-02-12 20:50:08 +010028import from TELNETasp_PortType all;
29import from Osmocom_VTY_Functions all;
30
Harald Weltec1a2fff2017-12-17 11:06:19 +010031
Harald Welte211219e2018-01-29 22:03:36 +010032/***********************************************************************
33 * Media related handling
34 ***********************************************************************/
35
Philipp Maier11a58942018-06-25 16:40:48 +020036/* Get the matching payload type for a specified BSSAP codec type
37 * (see also: BSSAP_Types.ttcn */
38private function f_get_mgcp_pt(BSSMAP_FIELD_CodecType codecType) return SDP_FIELD_PayloadType {
39 if (codecType == GSM_FR) {
40 return PT_GSM;
41 } else if (codecType == GSM_HR) {
42 return PT_GSMHR;
43 } else if (codecType == GSM_EFR) {
44 return PT_GSMEFR;
45 } else if (codecType == FR_AMR or codecType == HR_AMR) {
46 return PT_AMR;
47 } else if (codecType == FR_AMR_WB or codecType == OHR_AMR or codecType == OFR_AMR_WB or codecType == OHR_AMR_WB) {
48 return PT_AMRWB;
49 }
50
51 return PT_PCMU;
52}
53
Harald Welte211219e2018-01-29 22:03:36 +010054/* Tuple containing host/ip and port */
55type record HostPort {
56 HostName host,
57 PortNumber port_nr
58};
59
60/* State encapsulating one MGCP Connection */
61type record MgcpConnState {
Philipp Maier3e2af5d2018-07-11 17:01:05 +020062 integer crcx_seen, /* Counts how many CRCX operations happend */
63 integer mdcx_seen, /* Counts how many MDCX operations happend C */
64 integer crcx_seen_exp, /* Sets the expected number of CRCX operations */
65 integer mdcx_seen_exp, /* Sets the expected number of MDCX operations */
Harald Welte211219e2018-01-29 22:03:36 +010066 MgcpConnectionId conn_id,
67 charstring mime_type, /* e.g. AMR */
68 integer sample_rate, /* 8000 */
69 integer ptime, /* 20 */
70 uint7_t rtp_pt, /* RTP Payload Type */
71 HostPort mgw, /* MGW side */
72 HostPort peer /* CA side */
73};
74
75/* BTS media state */
76type record BtsMediaState {
77 boolean ipa_crcx_seen,
Philipp Maierc1e95c82018-07-18 16:03:00 +020078 boolean ipa_mdcx_seen,
Harald Welte211219e2018-01-29 22:03:36 +010079 uint16_t conn_id,
80 uint7_t rtp_pt,
81 HostPort bts,
82 HostPort peer
83};
84
85type record MediaState {
86 MgcpEndpoint mgcp_ep,
87 MgcpConnState mgcp_conn[2],
Harald Welte261af4b2018-02-12 21:20:39 +010088 BtsMediaState bts,
89 BtsMediaState bts1 /* only during hand-over */
Harald Welte211219e2018-01-29 22:03:36 +010090};
91
Philipp Maier11a58942018-06-25 16:40:48 +020092function f_MediaState_init(inout MediaState g_media, integer nr, HostName bts, HostName mgw, BSSMAP_FIELD_CodecType codecType) {
Harald Welte211219e2018-01-29 22:03:36 +010093 /* BTS Side */
94 g_media.bts := {
95 ipa_crcx_seen := false,
Philipp Maierc1e95c82018-07-18 16:03:00 +020096 ipa_mdcx_seen := false,
Harald Welte211219e2018-01-29 22:03:36 +010097 conn_id := nr,
98 rtp_pt := 0,
99 bts := {
100 host := bts,
101 port_nr := 9000 + nr*2
102 },
103 peer := -
104 }
105
Harald Welte261af4b2018-02-12 21:20:39 +0100106 g_media.bts1 := {
107 ipa_crcx_seen := false,
Philipp Maierc1e95c82018-07-18 16:03:00 +0200108 ipa_mdcx_seen := false,
Harald Welte261af4b2018-02-12 21:20:39 +0100109 conn_id := nr,
110 rtp_pt := 0,
111 bts := {
112 host := bts, /* FIXME */
113 port_nr := 9000 + nr*2
114 },
115 peer := -
116 }
117
Harald Welte363cb0a2018-01-30 19:35:53 +0100118 g_media.mgcp_ep := "rtpbridge/" & int2str(nr) & "@mgw";
Harald Welte211219e2018-01-29 22:03:36 +0100119
120 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier11a58942018-06-25 16:40:48 +0200121 g_media.mgcp_conn[i].mime_type := f_encoding_name_from_pt(f_get_mgcp_pt(codecType));
Harald Welte211219e2018-01-29 22:03:36 +0100122 g_media.mgcp_conn[i].sample_rate := 8000;
123 g_media.mgcp_conn[i].ptime := 20;
Philipp Maier11a58942018-06-25 16:40:48 +0200124 g_media.mgcp_conn[i].rtp_pt := enum2int(f_get_mgcp_pt(codecType));
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200125 g_media.mgcp_conn[i].crcx_seen := 0;
126 g_media.mgcp_conn[i].mdcx_seen := 0;
127 g_media.mgcp_conn[i].crcx_seen_exp := 0;
128 g_media.mgcp_conn[i].mdcx_seen_exp := 0;
Harald Welte211219e2018-01-29 22:03:36 +0100129 g_media.mgcp_conn[i].conn_id := f_mgcp_alloc_conn_id();
130 }
131
132 g_media.mgcp_conn[0].mgw := {
133 host := mgw,
134 port_nr := 10000 + nr*2
135 }
136 g_media.mgcp_conn[1].mgw := {
137 host := mgw,
138 port_nr := 11000 + nr*2
139 }
140}
141
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200142/* Helper function to get the next free MGCP connection identifier. We can
143 * recognize free connection identifiers by the fact that no CRCX happend yet */
Harald Welte211219e2018-01-29 22:03:36 +0100144private function f_get_free_mgcp_conn() runs on MSC_ConnHdlr return integer {
145 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200146 if (not g_media.mgcp_conn[i].crcx_seen >= 1) {
Harald Welte211219e2018-01-29 22:03:36 +0100147 return i;
148 }
149 }
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100150 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Only 2 Connections per EP!");
151 /* Should never be reached */
152 return -1;
Harald Welte211219e2018-01-29 22:03:36 +0100153}
154
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200155/* Helper function to pick a specific connection by its cid. Since we reach out
156 * for a connection that is in-use we also check if there was already exactly
157 * one CRCX happening on that connection. */
Harald Welte211219e2018-01-29 22:03:36 +0100158private function f_get_mgcp_conn(MgcpConnectionId cid) runs on MSC_ConnHdlr return integer {
159 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200160 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 +0100161 return i;
162 }
163 }
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No Connection for ID ", cid));
165 /* Should not be reached */
166 return -1;
Harald Welte211219e2018-01-29 22:03:36 +0100167}
168
Philipp Maierb2422352018-07-11 10:36:57 +0200169/* altstep for handling of IPACC media related commands. Activated by as_Media() to test
170 * RSL level media handling */
171altstep as_Media_ipacc() runs on MSC_ConnHdlr {
Harald Welte211219e2018-01-29 22:03:36 +0100172 var RSL_Message rsl;
Harald Welte211219e2018-01-29 22:03:36 +0100173 var RSL_IE_Body ie;
Harald Welte930d0a72018-03-22 22:08:40 +0100174 var boolean b_unused;
Harald Welte211219e2018-01-29 22:03:36 +0100175 [not g_media.bts.ipa_crcx_seen] RSL.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl {
176 /* Extract parameters from request + use in response */
177 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
178 g_media.bts.rtp_pt := ie.ipa_rtp_pt;
179 }
180 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
181 g_media.bts.rtp_pt := ie.ipa_rtp_pt2;
182 }
183 RSL.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts.conn_id,
184 oct2int(f_inet_addr(g_media.bts.bts.host)),
185 g_media.bts.bts.port_nr,
186 g_media.bts.rtp_pt));
187 g_media.bts.ipa_crcx_seen := true;
188 repeat;
189 }
190 [g_media.bts.ipa_crcx_seen] RSL.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{
191 /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */
Harald Welte930d0a72018-03-22 22:08:40 +0100192 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie);
Harald Welte211219e2018-01-29 22:03:36 +0100193 if (g_media.bts.conn_id != ie.ipa_conn_id) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100194 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("IPA MDCX for unknown ConnId", rsl));
Harald Welte211219e2018-01-29 22:03:36 +0100195 }
196 /* mandatory */
Harald Welte930d0a72018-03-22 22:08:40 +0100197 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_IP, ie);
Harald Welte211219e2018-01-29 22:03:36 +0100198 g_media.bts.peer.host := f_inet_ntoa(int2oct(ie.ipa_remote_ip, 4));
Harald Welte930d0a72018-03-22 22:08:40 +0100199 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_PORT, ie);
Harald Welte211219e2018-01-29 22:03:36 +0100200 g_media.bts.peer.port_nr := ie.ipa_remote_port;
201 /* optional */
202 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
203 g_media.bts.rtp_pt := ie.ipa_rtp_pt;
204 }
205 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
206 g_media.bts.rtp_pt := ie.ipa_rtp_pt2;
207 }
208 RSL.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts.conn_id,
209 oct2int(f_inet_addr(g_media.bts.peer.host)),
210 g_media.bts.peer.port_nr,
211 g_media.bts.rtp_pt));
Philipp Maierc1e95c82018-07-18 16:03:00 +0200212 g_media.bts.ipa_mdcx_seen := true;
Harald Welte211219e2018-01-29 22:03:36 +0100213 repeat;
214 }
Harald Welte261af4b2018-02-12 21:20:39 +0100215
216 /* on second (new) BTS during hand-over */
217 [not g_media.bts1.ipa_crcx_seen] RSL1.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl {
218 /* Extract parameters from request + use in response */
219 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
220 g_media.bts1.rtp_pt := ie.ipa_rtp_pt;
221 }
222 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
223 g_media.bts1.rtp_pt := ie.ipa_rtp_pt2;
224 }
225 RSL1.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts1.conn_id,
226 oct2int(f_inet_addr(g_media.bts1.bts.host)),
227 g_media.bts1.bts.port_nr,
228 g_media.bts1.rtp_pt));
229 g_media.bts1.ipa_crcx_seen := true;
230 repeat;
231 }
232 /* on second (new) BTS during hand-over */
233 [g_media.bts1.ipa_crcx_seen] RSL1.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{
234 /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */
Harald Welte930d0a72018-03-22 22:08:40 +0100235 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie);
Harald Welte261af4b2018-02-12 21:20:39 +0100236 if (g_media.bts1.conn_id != ie.ipa_conn_id) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("IPA MDCX for unknown ConnId", rsl));
Harald Welte261af4b2018-02-12 21:20:39 +0100238 }
239 /* mandatory */
Harald Welte930d0a72018-03-22 22:08:40 +0100240 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_IP, ie);
Harald Welte261af4b2018-02-12 21:20:39 +0100241 g_media.bts1.peer.host := f_inet_ntoa(int2oct(ie.ipa_remote_ip, 4));
Harald Welte930d0a72018-03-22 22:08:40 +0100242 b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_PORT, ie);
Harald Welte261af4b2018-02-12 21:20:39 +0100243 g_media.bts1.peer.port_nr := ie.ipa_remote_port;
244 /* optional */
245 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) {
246 g_media.bts1.rtp_pt := ie.ipa_rtp_pt;
247 }
248 if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) {
249 g_media.bts1.rtp_pt := ie.ipa_rtp_pt2;
250 }
251 RSL1.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts1.conn_id,
252 oct2int(f_inet_addr(g_media.bts1.peer.host)),
253 g_media.bts1.peer.port_nr,
254 g_media.bts1.rtp_pt));
Philipp Maierc1e95c82018-07-18 16:03:00 +0200255 g_media.bts1.ipa_mdcx_seen := true;
Harald Welte261af4b2018-02-12 21:20:39 +0100256 repeat;
257 }
258
Philipp Maierb2422352018-07-11 10:36:57 +0200259
260}
261
262/* altstep for handling of MGCP media related commands. Activated by as_Media() to test
263 * MGW level media handling */
Philipp Maierc1e95c82018-07-18 16:03:00 +0200264altstep as_Media_mgw(boolean norepeat := false) runs on MSC_ConnHdlr {
Philipp Maierb2422352018-07-11 10:36:57 +0200265 var MgcpCommand mgcp_cmd;
266
Harald Welte211219e2018-01-29 22:03:36 +0100267 [] MGCP.receive(tr_CRCX) -> value mgcp_cmd {
268 var SDP_Message sdp;
269 var integer cid := f_get_free_mgcp_conn();
Harald Welte363cb0a2018-01-30 19:35:53 +0100270 if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard)) {
271 if (cid != 0) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100272 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "MGCP wildcard EP only works in first CRCX");
Harald Welte363cb0a2018-01-30 19:35:53 +0100273 }
274 /* we keep the endpoint name allocated during MediaState_init */
275 } else {
276 /* Call Agent allocated endpoint, trust/use it always */
277 g_media.mgcp_ep := mgcp_cmd.line.ep;
278 }
Harald Welte211219e2018-01-29 22:03:36 +0100279 if (isvalue(mgcp_cmd.sdp)) {
280 sdp := mgcp_cmd.sdp;
281 g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr;
282 g_media.mgcp_conn[cid].peer.port_nr := sdp.media_list[0].media_field.ports.port_number;
283 }
284 var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid];
285 sdp := valueof(ts_SDP(mgcp_conn.mgw.host, mgcp_conn.mgw.host, "foo", "21",
286 mgcp_conn.mgw.port_nr, { int2str(mgcp_conn.rtp_pt) },
287 {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt,
288 mgcp_conn.mime_type & "/" &
289 int2str(mgcp_conn.sample_rate))),
290 valueof(ts_SDP_ptime(mgcp_conn.ptime)) } ));
Harald Welte363cb0a2018-01-30 19:35:53 +0100291 var template MgcpResponse mgcp_resp;
292 mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp);
293 f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(g_media.mgcp_ep));
294 MGCP.send(mgcp_resp);
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200295 g_media.mgcp_conn[cid].crcx_seen := g_media.mgcp_conn[cid].crcx_seen + 1;
Philipp Maierc1e95c82018-07-18 16:03:00 +0200296 if(norepeat == false) {
297 repeat;
298 }
Harald Welte211219e2018-01-29 22:03:36 +0100299 }
300 [] MGCP.receive(tr_MDCX) -> value mgcp_cmd {
301 var SDP_Message sdp;
302 var integer cid := f_get_mgcp_conn(f_MgcpCmd_extract_conn_id(mgcp_cmd));
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;
307 } else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100308 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "MDCX has no [recognizable] SDP");
Harald Welte211219e2018-01-29 22:03:36 +0100309 }
310 var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid];
311 sdp := valueof(ts_SDP(mgcp_conn.peer.host, mgcp_conn.peer.host, "foo", "21",
312 mgcp_conn.peer.port_nr, { int2str(mgcp_conn.rtp_pt) },
313 {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt,
314 mgcp_conn.mime_type & "/" &
315 int2str(mgcp_conn.sample_rate))),
316 valueof(ts_SDP_ptime(mgcp_conn.ptime)) } ));
317 MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp));
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200318 g_media.mgcp_conn[cid].mdcx_seen := g_media.mgcp_conn[cid].mdcx_seen + 1;
Philipp Maierc1e95c82018-07-18 16:03:00 +0200319 if(norepeat == false) {
320 repeat;
321 }
Harald Welte211219e2018-01-29 22:03:36 +0100322 }
323}
324
Philipp Maierb2422352018-07-11 10:36:57 +0200325/* Altsteps for handling of media related commands. Can be activated by a given
326 * test case if it expects to see media related handling (i.e. voice calls) */
327altstep as_Media() runs on MSC_ConnHdlr {
328 [] as_Media_ipacc();
329 [] as_Media_mgw();
330}
Harald Welte211219e2018-01-29 22:03:36 +0100331
Harald Welte28d943e2017-11-25 15:00:50 +0100332/* this component represents a single subscriber connection at the MSC.
333 * There is a 1:1 mapping between SCCP connections and BSSAP_ConnHdlr components.
334 * We inherit all component variables, ports, functions, ... from BSSAP_ConnHdlr */
Daniel Willmann191e0d92018-01-17 12:44:35 +0100335type component MSC_ConnHdlr extends BSSAP_ConnHdlr, RSL_DchanHdlr, MGCP_ConnHdlr {
Harald Welte28d943e2017-11-25 15:00:50 +0100336 /* SCCP Connecction Identifier for the underlying SCCP connection */
337 var integer g_sccp_conn_id;
338
Harald Weltec1a2fff2017-12-17 11:06:19 +0100339 /* procedure port back to our parent (BSSMAP_Emulation_CT) for control */
340 port BSSMAPEM_PROC_PT BSSMAPEM;
Harald Weltec20b1c42018-02-12 20:50:08 +0100341 port TELNETasp_PT BSCVTY;
Harald Welte28d943e2017-11-25 15:00:50 +0100342
Harald Welte211219e2018-01-29 22:03:36 +0100343 var MediaState g_media;
Harald Weltea0630032018-03-20 21:09:55 +0100344 var TestHdlrParams g_pars;
Harald Weltee97eab42018-03-21 18:46:06 +0100345
346 var boolean g_vty_initialized := false;
Harald Welte211219e2018-01-29 22:03:36 +0100347}
348
349/* initialize all parameters */
Philipp Maier11a58942018-06-25 16:40:48 +0200350function f_MscConnHdlr_init(integer i, HostName bts, HostName mgw, BSSMAP_FIELD_CodecType codecType) runs on MSC_ConnHdlr {
351 f_MediaState_init(g_media, i, bts, mgw, codecType);
Harald Weltee97eab42018-03-21 18:46:06 +0100352 if (not g_vty_initialized) {
353 map(self:BSCVTY, system:BSCVTY);
354 f_vty_set_prompts(BSCVTY);
355 f_vty_transceive(BSCVTY, "enable");
356 g_vty_initialized := true;
357 }
Harald Welte28d943e2017-11-25 15:00:50 +0100358}
359
360/* Callback function from general BSSMAP_Emulation whenever a connectionless
361 * BSSMAP message arrives. Can retunr a PDU_BSSAP that should be sent in return */
362private function UnitdataCallback(PDU_BSSAP bssap)
363runs on BSSMAP_Emulation_CT return template PDU_BSSAP {
364 var template PDU_BSSAP resp := omit;
365
Harald Weltec1a2fff2017-12-17 11:06:19 +0100366 /* answer all RESET with a RESET ACK */
Harald Welte28d943e2017-11-25 15:00:50 +0100367 if (match(bssap, tr_BSSMAP_Reset)) {
368 resp := ts_BSSMAP_ResetAck;
369 }
370
371 return resp;
372}
373
374const BssmapOps MSC_BssmapOps := {
Harald Weltec1a2fff2017-12-17 11:06:19 +0100375 create_cb := refers(BSSMAP_Emulation.ExpectedCreateCallback),
Harald Welte0b476062018-01-21 19:07:32 +0100376 unitdata_cb := refers(UnitdataCallback),
377 decode_dtap := false,
Harald Welte930d0a72018-03-22 22:08:40 +0100378 role_ms := false,
379 sccp_addr_local := omit,
380 sccp_addr_peer := omit
Harald Welte28d943e2017-11-25 15:00:50 +0100381}
382
Daniel Willmann191e0d92018-01-17 12:44:35 +0100383const MGCPOps MSC_MGCPOps := {
Harald Welte930d0a72018-03-22 22:08:40 +0100384 create_cb := refers(MGCP_Emulation.ExpectedCreateCallback),
385 unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback)
Daniel Willmann191e0d92018-01-17 12:44:35 +0100386}
387
Harald Weltec1a2fff2017-12-17 11:06:19 +0100388/* register an expect with the BSSMAP core */
Daniel Willmann191e0d92018-01-17 12:44:35 +0100389private function f_create_bssmap_exp(octetstring l3_enc) runs on MSC_ConnHdlr {
Harald Weltec1a2fff2017-12-17 11:06:19 +0100390 BSSMAPEM.call(BSSMAPEM_register:{l3_enc, self}) {
391 [] BSSMAPEM.getreply(BSSMAPEM_register:{?, ?}) {};
Harald Welte28d943e2017-11-25 15:00:50 +0100392 }
393}
394
Harald Welte651fcdc2018-05-10 20:23:16 +0200395type record TestHdlrEncrParams {
396 OCT1 enc_alg,
397 octetstring enc_key
398};
399
400template (value) TestHdlrEncrParams t_EncrParams(OCT1 alg, octetstring key) := {
401 enc_alg := alg,
402 enc_key := key
403}
404
Harald Weltecc0b0142018-05-29 15:19:33 +0200405type record TestHdlrParamsLcls {
406 GlobalCallReferenceValue gcr optional,
407 /* LCLS Configuration */
408 BIT4 cfg optional,
409 /* LCLS Connection Status Control */
410 BIT4 csc optional,
Max2eeb5112018-11-06 19:21:41 +0100411 BIT4 exp_sts optional,
412 /* Whether to adjust *cx_seen_exp for LCLS tests */
413 boolean adjust_cx_exp
Harald Weltecc0b0142018-05-29 15:19:33 +0200414}
415
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100416type record TestHdlrParamsHandover {
417 SCCP_PAR_Address sccp_addr_msc,
418 SCCP_PAR_Address sccp_addr_bsc
419}
420
Harald Weltec1a2fff2017-12-17 11:06:19 +0100421type record TestHdlrParams {
422 OCT1 ra,
423 GsmFrameNumber fn,
424 hexstring imsi,
Harald Welte60aa5762018-03-21 19:33:13 +0100425 RslLinkId link_id,
Harald Weltecbe911c2018-06-01 18:23:07 +0200426 integer media_nr, /* determins MGCP EP, port numbers */
Harald Welte651fcdc2018-05-10 20:23:16 +0200427 BSSMAP_IE_SpeechCodecList ass_codec_list optional,
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +0200428 RSL_IE_Body expect_mr_conf_ie optional, /* typically present for AMR codecs */
Harald Weltecc0b0142018-05-29 15:19:33 +0200429 TestHdlrEncrParams encr optional,
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100430 TestHdlrParamsLcls lcls,
Philipp Maier48604732018-10-09 15:00:37 +0200431 TestHdlrParamsHandover handover optional,
432 boolean aoip
Harald Weltec1a2fff2017-12-17 11:06:19 +0100433};
434
Philipp Maier48604732018-10-09 15:00:37 +0200435/* Note: Do not use valueof() to get a value of this template, use
436 * f_gen_test_hdlr_pars() instead in order to get a configuration that is
Maxd4e56962018-10-31 19:08:25 +0100437 * matched to the current test situation (aoio vs. sccplite) */
Harald Weltec1a2fff2017-12-17 11:06:19 +0100438template (value) TestHdlrParams t_def_TestHdlrPars := {
439 ra := '23'O,
440 fn := 23,
441 imsi := '001019876543210'H,
Harald Welte60aa5762018-03-21 19:33:13 +0100442 link_id := valueof(ts_RslLinkID_DCCH(0)),
Harald Weltecbe911c2018-06-01 18:23:07 +0200443 media_nr := 1,
Harald Welte651fcdc2018-05-10 20:23:16 +0200444 ass_codec_list := omit,
Neels Hofmeyrbcf62bc2018-07-04 00:24:33 +0200445 expect_mr_conf_ie := omit,
Harald Weltecc0b0142018-05-29 15:19:33 +0200446 encr := omit,
447 lcls := {
448 gcr := omit,
449 cfg := omit,
450 csc := omit,
Max2eeb5112018-11-06 19:21:41 +0100451 exp_sts := omit,
452 adjust_cx_exp := true
Neels Hofmeyrbd0ef932018-03-19 14:58:46 +0100453 },
Philipp Maier48604732018-10-09 15:00:37 +0200454 handover := omit,
455 aoip := true
Harald Weltec1a2fff2017-12-17 11:06:19 +0100456}
457
Harald Weltea0630032018-03-20 21:09:55 +0100458function f_create_chan_and_exp() runs on MSC_ConnHdlr {
459 var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi));
Harald Welte6ed6bf92018-01-24 21:09:15 +0100460 var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi));
Harald Weltec1a2fff2017-12-17 11:06:19 +0100461 var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info);
462
463 /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */
Harald Weltea0630032018-03-20 21:09:55 +0100464 RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn);
Daniel Willmann191e0d92018-01-17 12:44:35 +0100465 f_create_bssmap_exp(l3_enc);
Harald Weltec1a2fff2017-12-17 11:06:19 +0100466}
467
Harald Welte898113b2018-01-31 18:32:21 +0100468function f_rsl_send_l3(template PDU_ML3_MS_NW l3, template (omit) RslLinkId link_id := omit,
469 template (omit) RslChannelNr chan_nr := omit) runs on MSC_ConnHdlr {
470 if (not isvalue(link_id)) {
471 link_id := ts_RslLinkID_DCCH(0);
472 }
473 if (not isvalue(chan_nr)) {
474 chan_nr := g_chan_nr;
475 }
476 RSL.send(ts_RSL_DATA_IND(valueof(chan_nr), valueof(link_id), enc_PDU_ML3_MS_NW(valueof(l3))));
477}
478
Harald Weltec1a2fff2017-12-17 11:06:19 +0100479function f_rsl_reply(template PDU_ML3_MS_NW l3, RSL_Message orig) runs on MSC_ConnHdlr {
480 var RslChannelNr chan_nr := orig.ies[0].body.chan_nr;
Harald Welte1a40de62017-12-23 02:28:34 +0100481 var RslLinkId link_id;
Harald Welte8d5eead2017-12-17 18:56:45 +0100482 if (orig.msg_type == RSL_MT_ENCR_CMD) {
483 link_id := orig.ies[2].body.link_id;
484 } else {
485 link_id := orig.ies[1].body.link_id;
486 }
Harald Welte898113b2018-01-31 18:32:21 +0100487 f_rsl_send_l3(l3, link_id, chan_nr);
Harald Weltec1a2fff2017-12-17 11:06:19 +0100488}
489
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100490/* Convert the chipher representation on BSSMAP to the representation used on RSL */
Harald Weltee613f962018-04-18 22:38:16 +0200491function f_chipher_mode_bssmap_to_rsl(OCT1 alg_bssmap) return RSL_AlgId
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100492{
493 /* A5 0 */
494 if (alg_bssmap == '01'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200495 return RSL_ALG_ID_A5_0;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100496 }
497 /* A5 1 */
498 else if (alg_bssmap == '02'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200499 return RSL_ALG_ID_A5_1;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100500 }
501 /* A5 2 */
502 else if (alg_bssmap == '04'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200503 return RSL_ALG_ID_A5_2;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100504 }
505 /* A5 3 */
506 else if (alg_bssmap == '08'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200507 return RSL_ALG_ID_A5_3;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100508 }
509 /* A5 4 */
510 else if (alg_bssmap == '10'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200511 return RSL_ALG_ID_A5_4;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100512 }
513 /* A5 5 */
514 else if (alg_bssmap == '20'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200515 return RSL_ALG_ID_A5_5;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100516 }
517 /* A5 6 */
518 else if (alg_bssmap == '40'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200519 return RSL_ALG_ID_A5_6;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100520 }
521 /* A5 7 */
522 else if (alg_bssmap == '80'O) {
Harald Weltee613f962018-04-18 22:38:16 +0200523 return RSL_ALG_ID_A5_7;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100524 } else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100525 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Encryption Algorithm");
Harald Weltee613f962018-04-18 22:38:16 +0200526 return RSL_ALG_ID_A5_0;
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100527 }
528}
529
Harald Welte38b2a102017-12-23 02:42:58 +0100530function f_cipher_mode(OCT1 alg, OCT8 key, template OCT16 kc128 := omit, boolean exp_fail := false)
531runs on MSC_ConnHdlr {
Harald Welte73cd2712017-12-17 00:44:52 +0100532 var PDU_BSSAP bssap;
533 var RSL_Message rsl;
Harald Weltee613f962018-04-18 22:38:16 +0200534 var RSL_AlgId alg_rsl;
Harald Welte73cd2712017-12-17 00:44:52 +0100535
536 if (isvalue(kc128)) {
537 BSSAP.send(ts_BSSMAP_CipherModeCmdKc128(alg, key, valueof(kc128)));
538 } else {
539 BSSAP.send(ts_BSSMAP_CipherModeCmd(alg, key));
540 }
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100541
542 /* RSL uses a different representation of the encryption algorithm,
543 * so we need to convert first */
544 alg_rsl := f_chipher_mode_bssmap_to_rsl(alg);
545
Harald Welte73cd2712017-12-17 00:44:52 +0100546 alt {
547 /* RSL/UE Side */
Philipp Maierb20c3dc2018-02-07 18:36:25 +0100548 [] RSL.receive(tr_RSL_ENCR_CMD(g_chan_nr, ?, alg_rsl, key)) -> value rsl {
Harald Welte73cd2712017-12-17 00:44:52 +0100549 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[3].body.l3_info.payload);
550 log("Rx L3 from net: ", l3);
551 if (ischosen(l3.msgs.rrm.cipheringModeCommand)) {
552 f_rsl_reply(ts_RRM_CiphModeCompl, rsl);
553 }
554 repeat;
555 }
556 [] BSSAP.receive(tr_BSSMAP_CipherModeCompl) -> value bssap {
557 // bssap.bssmap.cipherModeComplete.chosenEncryptionAlgorithm.algoritmhIdentifier
Harald Welte38b2a102017-12-23 02:42:58 +0100558 if (exp_fail == true) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100559 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Cipher Mode Complete");
Harald Welte38b2a102017-12-23 02:42:58 +0100560 } else {
561 setverdict(pass);
562 }
Harald Welte73cd2712017-12-17 00:44:52 +0100563 }
564 [] BSSAP.receive(tr_BSSMAP_CipherModeRej) -> value bssap {
Harald Welte38b2a102017-12-23 02:42:58 +0100565 if (exp_fail == false) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Ciphering Mode Reject");
Harald Welte38b2a102017-12-23 02:42:58 +0100567 } else {
568 setverdict(pass);
569 }
Harald Welte73cd2712017-12-17 00:44:52 +0100570 }
571 }
572}
573
Harald Welte211219e2018-01-29 22:03:36 +0100574/* Convert from Ericsson ChanDesc2 format to Osmocom RslChannelNr format */
575function f_ChDesc2RslChanNr(ChannelDescription2_V ch_desc, out RslChannelNr chan_nr, out GsmArfcn arfcn) {
576 var BIT5 inp := ch_desc.channelTypeandTDMAOffset;
Harald Welte6fa1f732018-03-21 22:46:16 +0100577 var uint3_t tn := bit2int(ch_desc.timeslotNumber);
Harald Welte211219e2018-01-29 22:03:36 +0100578
579 if (match(inp, '00001'B)) { /* TCH/F */
Harald Welte6fa1f732018-03-21 22:46:16 +0100580 chan_nr := valueof(t_RslChanNr_Bm(tn));
Harald Welte211219e2018-01-29 22:03:36 +0100581 }
582 else if (match(inp, '0001?'B)) { /* TCH/H */
Harald Welte6fa1f732018-03-21 22:46:16 +0100583 chan_nr := valueof(t_RslChanNr_Lm(tn, bit2int(substr(inp, 4, 1))));
Harald Welte211219e2018-01-29 22:03:36 +0100584 }
585 else if (match(inp, '001??'B)) { /* SDCCH/4 */
Harald Welte6fa1f732018-03-21 22:46:16 +0100586 chan_nr := valueof(t_RslChanNr_SDCCH4(tn, bit2int(substr(inp, 3, 2))));
Harald Welte211219e2018-01-29 22:03:36 +0100587 }
588 else if (match(inp, '01???'B)) { /* SDCCH/8 */
Harald Welte6fa1f732018-03-21 22:46:16 +0100589 chan_nr := valueof(t_RslChanNr_SDCCH8(tn, bit2int(substr(inp, 2, 3))));
Harald Welte211219e2018-01-29 22:03:36 +0100590 }
591 else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown ChDesc!");
Harald Welte211219e2018-01-29 22:03:36 +0100593 }
594
595 if (ch_desc.octet3 and4b '10'O == '10'O) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100596 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No support for Hopping");
Harald Welte211219e2018-01-29 22:03:36 +0100597 } else {
598 var OCT2 concat := ch_desc.octet3 & ch_desc.octet4;
599 arfcn := oct2int(concat);
600 }
601}
602
603type record AssignmentState {
604 /* global */
605 boolean voice_call,
606 boolean is_assignment,
607 /* Assignment related bits */
608 boolean rr_ass_cmpl_seen,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100609 boolean old_lchan_deact_sacch_seen,
610 boolean old_lchan_rll_rel_req_seen,
Harald Welte21583082018-01-29 22:28:26 +0100611 boolean assignment_done,
Harald Welte211219e2018-01-29 22:03:36 +0100612 RslChannelNr old_chan_nr,
613 /* Modify related bits */
614 boolean rr_modify_seen,
Harald Welte21583082018-01-29 22:28:26 +0100615 boolean modify_done
Harald Welte211219e2018-01-29 22:03:36 +0100616}
617
618template (value) AssignmentState ts_AssignmentStateInit := {
619 voice_call := false,
620 is_assignment := false,
621 rr_ass_cmpl_seen := false,
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100622 old_lchan_deact_sacch_seen := false,
623 old_lchan_rll_rel_req_seen := false,
Harald Welte21583082018-01-29 22:28:26 +0100624 assignment_done := false,
Harald Welte211219e2018-01-29 22:03:36 +0100625 old_chan_nr := -,
626 rr_modify_seen := false,
Harald Welte21583082018-01-29 22:28:26 +0100627 modify_done := false
Harald Welte211219e2018-01-29 22:03:36 +0100628}
629
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200630private template RSL_IE_Body tr_EncrInfo(template RSL_AlgId alg, template octetstring key) := {
631 encr_info := {
632 len := ?,
633 alg_id := alg,
634 key := key
635 }
636}
637
638/* ensure the RSL CHAN ACT (during assignment) contains values we expect depending on test case */
639private function f_check_chan_act(AssignmentState st, RSL_Message chan_act) runs on MSC_ConnHdlr {
640 var RSL_IE_Body encr_info;
641 if (ispresent(g_pars.encr) and g_pars.encr.enc_alg != '01'O) {
642 if (not f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100643 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Missing Encryption IE in CHAN ACT");
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200644 } else {
645 var RSL_AlgId alg := f_chipher_mode_bssmap_to_rsl(g_pars.encr.enc_alg);
646 if (not match(encr_info, tr_EncrInfo(alg, g_pars.encr.enc_key))) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100647 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Wrong Encryption IE in CHAN ACT");
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200648 }
649 }
650 } else {
651 if (f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) {
652 if (encr_info.encr_info.alg_id != RSL_ALG_ID_A5_0) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100653 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Encryption in CHAN ACT");
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200654 }
655 }
656 }
657 /* FIXME: validate RSL_IE_ACT_TYPE, RSL_IE_CHAN_MODE, RSL_IE_CHAN_IDENT, RSL_IE_BS_POWER,
658 * RSL_IE_MS_POWER, RSL_IE_TIMING_ADVANCE */
659}
660
Harald Welte211219e2018-01-29 22:03:36 +0100661altstep as_assignment(inout AssignmentState st) runs on MSC_ConnHdlr {
Harald Weltec1a2fff2017-12-17 11:06:19 +0100662 var RSL_Message rsl;
Harald Welte211219e2018-01-29 22:03:36 +0100663 [not st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
664 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
665 log("Rx L3 from net: ", l3);
666 if (ischosen(l3.msgs.rrm.assignmentCommand)) {
667 var RslChannelNr new_chan_nr;
668 var GsmArfcn arfcn;
669 f_ChDesc2RslChanNr(l3.msgs.rrm.assignmentCommand.descrOf1stChAfterTime,
670 new_chan_nr, arfcn);
671 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
Harald Weltec1a2fff2017-12-17 11:06:19 +0100672
Harald Welte211219e2018-01-29 22:03:36 +0100673 /* register our component for this channel number at the RSL Emulation */
674 f_rslem_register(0, new_chan_nr);
675 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_AssignmentComplete('00'O));
676 /* send assignment complete over the new channel */
Neels Hofmeyrb0e73652018-07-14 21:56:51 +0200677 RSL.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
Harald Welte211219e2018-01-29 22:03:36 +0100678 enc_PDU_ML3_MS_NW(l3_tx)));
679 /* by default, send via the new channel from now */
680 st.old_chan_nr := g_chan_nr;
681 g_chan_nr := new_chan_nr;
682 st.rr_ass_cmpl_seen := true;
Harald Welte8a9bf6f2018-05-10 22:00:49 +0200683 /* obtain channel activation from RSL_Emulation for new channel */
684 var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr);
685 /* check it (e.g. for correct ciphering parameters) */
686 f_check_chan_act(st, chan_act);
Harald Welte211219e2018-01-29 22:03:36 +0100687 repeat;
688 } else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected L3 received", l3));
Harald Weltec1a2fff2017-12-17 11:06:19 +0100690 }
Harald Welte211219e2018-01-29 22:03:36 +0100691 }
Neels Hofmeyr861a4c12018-11-07 01:23:17 +0100692 [st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_DEACT_SACCH(st.old_chan_nr)) {
Neels Hofmeyra5302c82018-11-04 23:09:58 +0100693 st.old_lchan_deact_sacch_seen := true;
Neels Hofmeyr861a4c12018-11-07 01:23:17 +0100694 repeat;
695 }
Harald Welte211219e2018-01-29 22:03:36 +0100696 [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 +0100697 st.old_lchan_rll_rel_req_seen := true;
Harald Welte211219e2018-01-29 22:03:36 +0100698 RSL.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
699 repeat;
700 }
701 [st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) {
702 RSL.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr));
Harald Welte1909f462018-01-29 22:29:29 +0100703 /* unregister for old channel number in RSL emulation */
704 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
705 f_rslem_unregister(0, st.old_chan_nr);
Harald Welte21583082018-01-29 22:28:26 +0100706 st.assignment_done := true;
Harald Welte211219e2018-01-29 22:03:36 +0100707 repeat;
708 }
709}
710
711altstep as_modify(inout AssignmentState st) runs on MSC_ConnHdlr {
712 /* no assignment, just mode modify */
713 var RSL_Message rsl;
714
715 [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 +0100716 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
717 log("Rx L3 from net: ", l3);
718 if (ischosen(l3.msgs.rrm.channelModeModify)) {
719 f_rsl_reply(ts_RRM_ModeModifyAck(l3.msgs.rrm.channelModeModify.channelDescription,
720 l3.msgs.rrm.channelModeModify.channelMode), rsl);
Harald Welte211219e2018-01-29 22:03:36 +0100721 st.rr_modify_seen := true;
Harald Weltec1a2fff2017-12-17 11:06:19 +0100722 }
723 repeat;
724 }
Harald Welte211219e2018-01-29 22:03:36 +0100725 [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 +0100726 RSL.send(ts_RSL_MODE_MODIFY_ACK(g_chan_nr));
Harald Welte21583082018-01-29 22:28:26 +0100727 st.modify_done := true;
Harald Weltec1a2fff2017-12-17 11:06:19 +0100728 repeat;
729 }
Harald Welte211219e2018-01-29 22:03:36 +0100730}
Daniel Willmann191e0d92018-01-17 12:44:35 +0100731
Harald Welte211219e2018-01-29 22:03:36 +0100732/* Determine if given rsl_chan_nr is compatible with given BSSMAP ChannelType */
733function f_channel_compatible(BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr)
734return boolean {
735 select (bssmap.speechOrDataIndicator) {
736 case ('0011'B) { /* Signalling */
737 /* all channels support signalling */
738 return true;
739 }
740 case else { /* Speech, Speech+CTM or CSD */
741 select (bssmap.channelRateAndType) {
742 case ('08'O) { /* TCH/F */
743 select (rsl_chan_nr) {
744 case (t_RslChanNr_Bm(?)) { return true; }
745 }
746 }
747 case ('09'O) { /* TCH/H */
748 select (rsl_chan_nr) {
749 case (t_RslChanNr_Lm(?, ?)) { return true; }
750 }
751 }
752 case else { /* full or half-rate */
753 select (rsl_chan_nr) {
754 case (t_RslChanNr_Bm(?)) { return true; }
755 case (t_RslChanNr_Lm(?, ?)) { return true; }
756 }
757 }
758 }
Harald Weltec1a2fff2017-12-17 11:06:19 +0100759 }
Harald Welte211219e2018-01-29 22:03:36 +0100760 }
761 return false;
762}
Daniel Willmann191e0d92018-01-17 12:44:35 +0100763
Philipp Maier8ef527e2018-05-18 11:12:50 +0200764/* Determine if the channel mode specified within rsl_chan_nr requires a
765 * MODE MODIFY in to match the channel mode specified by given BSSMAP
766 * ChannelType */
767function f_channel_needs_modify(BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr)
768return boolean {
769
770 /* FIXME: This tests the rsl_chan_nr to determine if we are on a
771 * signalling channel or not. Unfortunately this may lead to false
772 * results if we are on a TCH. The problem is that a TCH may be also
773 * used in signalling mode, but this function assumes that only SDCCH4
774 * and SDCCH8 are used as signalling channels at all. */
775
776 var boolean current_signalling := false;
777 var boolean desired_signalling := false;
778
779 select (rsl_chan_nr) {
780 case (t_RslChanNr_SDCCH4(?, ?)) { current_signalling := true; }
781 case (t_RslChanNr_SDCCH8(?, ?)) { current_signalling := true; }
782 }
783
784 if (bssmap.speechOrDataIndicator == '0011'B) {
785 desired_signalling := true;
786 }
787
788 if (current_signalling == desired_signalling) {
789 /* The desired channel mode is equal to the one we currently
790 * have, there is no mode modification needed or expected */
791 return false;
792 } else {
793 /* The desired channel mode and the current channel mode do
794 * not match. A mode modification is required */
795 return true;
796 }
797}
798
Harald Weltecc0b0142018-05-29 15:19:33 +0200799/* patch an BSSMAP ASS REQ with LCLS related IEs, depending on g_params */
800function f_ass_patch_lcls(inout template (omit) PDU_BSSAP ass_tpl,
801 inout template PDU_BSSAP ass_cpl) runs on MSC_ConnHdlr {
802 if (istemplatekind(ass_tpl, "omit")) {
803 return;
804 }
805 if (ispresent(g_pars.lcls.gcr)) {
806 ass_tpl.pdu.bssmap.assignmentRequest.globalCallReference := ts_BSSMAP_IE_GCR(g_pars.lcls.gcr);
807 }
808 if (ispresent(g_pars.lcls.cfg)) {
809 ass_tpl.pdu.bssmap.assignmentRequest.lCLS_Configuration := ts_BSSMAP_IE_LclsCfg(g_pars.lcls.cfg);
810 }
811 if (ispresent(g_pars.lcls.csc)) {
812 ass_tpl.pdu.bssmap.assignmentRequest.lCLS_ConnectionStatusControl := ts_BSSMAP_IE_LclsCsc(g_pars.lcls.csc);
813 }
Harald Welte343b7742018-06-05 23:41:37 +0200814 if (ischosen(ass_cpl.pdu.bssmap.assignmentComplete)) {
815 if (ispresent(g_pars.lcls.exp_sts)) {
816 ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status := tr_BSSMAP_IE_LclsSts(g_pars.lcls.exp_sts);
817 } else {
818 ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status := omit;
819 }
Harald Weltecc0b0142018-05-29 15:19:33 +0200820 }
821}
822
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200823/* Helper function to check if the activity on the MGCP matches what we
824 * expected */
825function f_check_mgcp_expectations() runs on MSC_ConnHdlr {
826 for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) {
Philipp Maier0a5d7e72018-07-16 15:13:11 +0200827 log(testcasename(), ": Check MGCP test expectations for g_media.mgcp_conn[", i , "]:",
828 " crcx_seen=", g_media.mgcp_conn[i].crcx_seen, ", crcx_seen_exp=", g_media.mgcp_conn[i].crcx_seen_exp,
829 ", mdcx_seen=", g_media.mgcp_conn[i].mdcx_seen, ", mdcx_seen_exp=", g_media.mgcp_conn[i].mdcx_seen_exp);
830
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200831 if(g_media.mgcp_conn[i].crcx_seen != g_media.mgcp_conn[i].crcx_seen_exp) {
Max4b0f4962018-11-06 19:20:24 +0100832 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 +0200833 }
834 if(g_media.mgcp_conn[i].mdcx_seen != g_media.mgcp_conn[i].mdcx_seen_exp) {
Max4b0f4962018-11-06 19:20:24 +0100835 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 +0200836 }
837 }
838}
839
Harald Welte211219e2018-01-29 22:03:36 +0100840/* establish a channel fully, expecting an assignment matching 'exp' */
Harald Welte7a14fd52018-05-10 22:26:55 +0200841function f_establish_fully(template (omit) PDU_BSSAP ass_tpl, template PDU_BSSAP exp_ass_cpl)
842runs on MSC_ConnHdlr {
Philipp Maier11a58942018-06-25 16:40:48 +0200843
844 var BSSMAP_FIELD_CodecType codecType;
Philipp Maier48aeeec2018-09-14 18:20:04 +0200845 timer T := 10.0;
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200846
Philipp Maier11a58942018-06-25 16:40:48 +0200847 if (isvalue(ass_tpl.pdu.bssmap.assignmentRequest.codecList)) {
848 codecType := valueof(ass_tpl.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType);
849 } else {
850 /* Make sure a meaningful default is assigned in case the
851 * codecList is not populated */
852 codecType := FR_AMR;
853 }
854
855 f_MscConnHdlr_init(g_pars.media_nr, "127.0.0.2", "127.0.0.3", codecType);
Harald Welte7a14fd52018-05-10 22:26:55 +0200856
Harald Weltecc0b0142018-05-29 15:19:33 +0200857 /* patch in the LCLS related items, as needed */
858 f_ass_patch_lcls(ass_tpl, exp_ass_cpl);
859
Harald Welte7a14fd52018-05-10 22:26:55 +0200860 f_create_chan_and_exp();
861 /* we should now have a COMPL_L3 at the MSC */
Philipp Maier48aeeec2018-09-14 18:20:04 +0200862
863 var template PDU_BSSAP exp_l3_compl;
864 exp_l3_compl := tr_BSSMAP_ComplL3()
Philipp Maier48604732018-10-09 15:00:37 +0200865 if (g_pars.aoip == false) {
Philipp Maier48aeeec2018-09-14 18:20:04 +0200866 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := omit;
867 } else {
868 exp_l3_compl.pdu.bssmap.completeLayer3Information.codecList := ?;
869 }
870 T.start;
871 alt {
872 [] BSSAP.receive(exp_l3_compl);
873 [] BSSAP.receive(tr_BSSMAP_ComplL3) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100874 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching COMPLETE LAYER 3 INFORMATION");
Philipp Maier48aeeec2018-09-14 18:20:04 +0200875 }
876 [] T.timeout {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100877 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION");
Philipp Maier48aeeec2018-09-14 18:20:04 +0200878 }
879 }
Harald Welte7a14fd52018-05-10 22:26:55 +0200880
881 /* start ciphering, if requested */
882 if (ispresent(g_pars.encr)) {
883 f_cipher_mode(g_pars.encr.enc_alg, g_pars.encr.enc_key);
884 }
885
886 /* bail out early if no assignment requested */
887 if (istemplatekind(ass_tpl, "omit")) {
888 return;
889 }
890
891 var PDU_BSSAP ass_cmd := valueof(ass_tpl);
Harald Welte211219e2018-01-29 22:03:36 +0100892 var PDU_BSSAP bssap;
Harald Welte211219e2018-01-29 22:03:36 +0100893 var boolean exp_compl := ischosen(exp_ass_cpl.pdu.bssmap.assignmentComplete);
Philipp Maier86f39202018-02-07 14:40:09 +0100894 var boolean exp_fail := ischosen(exp_ass_cpl.pdu.bssmap.assignmentFailure);
Philipp Maier8ef527e2018-05-18 11:12:50 +0200895 var boolean exp_modify;
Philipp Maier48aeeec2018-09-14 18:20:04 +0200896
Harald Welte211219e2018-01-29 22:03:36 +0100897 var ExpectCriteria mgcpcrit := {
898 connid := omit,
899 endpoint := omit,
900 transid := omit
901 };
902 var AssignmentState st := valueof(ts_AssignmentStateInit);
903 /* if the channel type is SIGNAL, we're not handling a voice call */
904 if (ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechOrDataIndicator != '0011'B) {
905 st.voice_call := true;
Philipp Maier8ef527e2018-05-18 11:12:50 +0200906 exp_modify := true;
Harald Welte211219e2018-01-29 22:03:36 +0100907 }
Philipp Maier8ef527e2018-05-18 11:12:50 +0200908
Harald Welte211219e2018-01-29 22:03:36 +0100909 /* determine if the current channel can support the given service or not */
910 if (not f_channel_compatible(ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr)) {
911 st.is_assignment := true;
Philipp Maier8ef527e2018-05-18 11:12:50 +0200912
913 /* We decided to assign a new channel, so we do not expect
914 * any mode modify messages on RSL */
915 exp_modify := false;
916 } else {
917 /* We will continue working with the currently assigned
918 * channel, we must now check if the mode of the current
919 * channel is compatible. If not we expect the BSC to modify
920 * the mode */
921 exp_modify := f_channel_needs_modify(ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr);
Harald Welte211219e2018-01-29 22:03:36 +0100922 }
923
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200924 /* Some test situations will involve MGCP transactions on a media
925 * gateway. Depending on the situation, we set up how many of each MGCP
926 * message type are expected to be exchanged. */
927 if (isbound(exp_ass_cpl.pdu.bssmap.assignmentFailure)) {
928 /* For tests that expect the assignment to fail, assume that
929 * there will be no MGW communication as well. */
930 g_media.mgcp_conn[0].crcx_seen_exp := 0;
931 g_media.mgcp_conn[0].mdcx_seen_exp := 0;
932 g_media.mgcp_conn[1].crcx_seen_exp := 0;
933 g_media.mgcp_conn[1].mdcx_seen_exp := 0;
934 } else if (st.voice_call) {
935 /* For voice calls we expect the following MGCP activity */
Philipp Maier48604732018-10-09 15:00:37 +0200936 if (g_pars.aoip == false) {
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200937 g_media.mgcp_conn[0].crcx_seen_exp := 1;
938 g_media.mgcp_conn[0].mdcx_seen_exp := 1;
939 g_media.mgcp_conn[1].crcx_seen_exp := 0;
940 g_media.mgcp_conn[1].mdcx_seen_exp := 0;
941 } else {
942 g_media.mgcp_conn[0].crcx_seen_exp := 1;
943 g_media.mgcp_conn[0].mdcx_seen_exp := 1;
944 g_media.mgcp_conn[1].crcx_seen_exp := 1;
945 g_media.mgcp_conn[1].mdcx_seen_exp := 0;
946 }
947 }
948
Harald Welte211219e2018-01-29 22:03:36 +0100949 f_create_mgcp_expect(mgcpcrit);
950 BSSAP.send(ass_cmd);
951
952 T.start;
953 alt {
954 /* assignment related bits */
955 [st.is_assignment] as_assignment(st);
956
957 /* modify related bits */
Philipp Maier8ef527e2018-05-18 11:12:50 +0200958 [not st.is_assignment and exp_modify] as_modify(st);
Harald Welte211219e2018-01-29 22:03:36 +0100959
960 /* voice call related bits (IPA CRCX/MDCX + MGCP) */
961 [st.voice_call] as_Media();
962
963 /* if we receive exactly what we expected, always return + pass */
Philipp Maier8ef527e2018-05-18 11:12:50 +0200964 [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 +0100965 setverdict(pass);
966 }
Philipp Maier86f39202018-02-07 14:40:09 +0100967 [exp_fail] BSSAP.receive(exp_ass_cpl) -> value bssap {
968 setverdict(pass);
969 }
Harald Welte21583082018-01-29 22:28:26 +0100970 [(st.is_assignment and st.assignment_done or
Philipp Maier8ef527e2018-05-18 11:12:50 +0200971 (not st.is_assignment and (st.modify_done or not exp_modify))) and
Harald Welte21583082018-01-29 22:28:26 +0100972 exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching ASSIGNMENT COMPLETE");
Harald Weltec1a2fff2017-12-17 11:06:19 +0100974 }
975 [exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected ASSIGNMENT FAIL");
Harald Weltec1a2fff2017-12-17 11:06:19 +0100977 }
978 [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100979 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected ASSIGNMENT COMPLETE");
Harald Weltec1a2fff2017-12-17 11:06:19 +0100980 }
981 [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100982 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching ASSIGNMENT FAIL");
Harald Weltec1a2fff2017-12-17 11:06:19 +0100983 }
984 [] T.timeout {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +0100985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASSIGNMENT COMPLETE");
Harald Weltec1a2fff2017-12-17 11:06:19 +0100986 }
987 }
Harald Welte211219e2018-01-29 22:03:36 +0100988 log("g_media ", g_media);
989 if (not isbound(bssap)) {
Daniel Willmannafce8662018-07-06 23:11:32 +0200990 mtc.stop;
Harald Welte211219e2018-01-29 22:03:36 +0100991 }
Philipp Maier3e2af5d2018-07-11 17:01:05 +0200992
Philipp Maiera0976e92018-07-16 15:19:42 +0200993 /* When the BSC detects that LCLS is possible it will cross the
994 * connetions that point to the PBX side of the MGW. In our case this
995 * is mgcp_conn[1]. The BSC performs this operation already before the
996 * assignment complete is generated. This means we expect another MDCX
997 * at mgcp_conn[1] when LCLS is expected. */
Max2eeb5112018-11-06 19:21:41 +0100998 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 +0200999 if (valueof(exp_ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status.lCLS_BSS_StatusValue) == LCLS_STS_locally_switched) {
1000 g_media.mgcp_conn[1].mdcx_seen_exp := g_media.mgcp_conn[1].mdcx_seen_exp + 1;
1001
1002 }
1003 }
1004
Philipp Maier3e2af5d2018-07-11 17:01:05 +02001005 f_check_mgcp_expectations();
Neels Hofmeyra5302c82018-11-04 23:09:58 +01001006
1007 if (st.is_assignment and st.assignment_done) {
1008 if (not st.old_lchan_deact_sacch_seen) {
1009 setverdict(fail, "f_establish_fully(): Assignment completed, but the old lchan was not",
1010 " released properly: expected a Deact SACCH on the old lchan, but saw none.");
1011 }
1012 if (st.old_lchan_rll_rel_req_seen) {
1013 setverdict(fail, "f_establish_fully(): Assignment completed, but the old lchan was not",
1014 " released properly: saw an RLL Release on the old lchan, but expecting none.");
1015 }
1016 }
Harald Welte930d0a72018-03-22 22:08:40 +01001017}
1018
Harald Welte261af4b2018-02-12 21:20:39 +01001019type record HandoverState {
1020 /* Assignment related bits */
1021 boolean rr_ho_cmpl_seen,
Philipp Maierc1e95c82018-07-18 16:03:00 +02001022 integer mdcx_seen_before_ho,
Harald Welte261af4b2018-02-12 21:20:39 +01001023 boolean handover_done,
1024 RslChannelNr old_chan_nr
1025};
1026
1027altstep as_handover(inout HandoverState st) runs on MSC_ConnHdlr {
1028 var RSL_Message rsl;
1029 [not st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl {
1030 var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload);
1031 log("Rx L3 from net: ", l3);
1032 if (ischosen(l3.msgs.rrm.handoverCommand)) {
1033 var RslChannelNr new_chan_nr;
1034 var GsmArfcn arfcn;
1035 f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2,
1036 new_chan_nr, arfcn);
1037 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
1038
1039 /* register our component for this channel number at the RSL Emulation */
1040 f_rslem_register(0, new_chan_nr, RSL1_PROC);
1041
1042 /* resume processing of RSL DChan messages, which was temporarily suspended
1043 * before performing a hand-over */
1044 f_rslem_resume(RSL1_PROC);
1045
Neels Hofmeyr378a49c2018-06-15 22:18:43 +02001046 /* send handover detect */
1047 RSL1.send(ts_RSL_HANDO_DET(new_chan_nr));
1048 f_sleep(0.3);
1049
Harald Welte261af4b2018-02-12 21:20:39 +01001050 /* send handover complete over the new channel */
1051 var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O));
Neels Hofmeyrd07ee132018-07-14 22:28:29 +02001052 RSL1.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)),
Harald Welte261af4b2018-02-12 21:20:39 +01001053 enc_PDU_ML3_MS_NW(l3_tx)));
1054 /* by default, send via the new channel from now */
1055 st.old_chan_nr := g_chan_nr;
1056 g_chan_nr := new_chan_nr;
1057 st.rr_ho_cmpl_seen := true;
Philipp Maierc1e95c82018-07-18 16:03:00 +02001058
1059 /* Memorize how many MDCX we have seen before. We need this number to detect
1060 * that we have received the handover related MDCX */
1061 st.mdcx_seen_before_ho := g_media.mgcp_conn[0].mdcx_seen;
Harald Welte261af4b2018-02-12 21:20:39 +01001062 repeat;
1063 } else {
Daniel Willmann0c9e3fa2018-10-29 15:55:12 +01001064 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected L3 received", l3));
Harald Welte261af4b2018-02-12 21:20:39 +01001065 }
1066 }
Philipp Maierc1e95c82018-07-18 16:03:00 +02001067 [st.rr_ho_cmpl_seen] as_Media_ipacc();
1068 [st.rr_ho_cmpl_seen] as_Media_mgw(true);
Neels Hofmeyr861a4c12018-11-07 01:23:17 +01001069 [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_DEACT_SACCH(st.old_chan_nr)) {
1070 repeat;
1071 }
Harald Welte261af4b2018-02-12 21:20:39 +01001072 [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_REL_REQ(st.old_chan_nr, tr_RslLinkID_DCCH(0))) {
1073 RSL.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0))));
1074 repeat;
1075 }
1076 [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) {
1077 RSL.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr));
1078 /* unregister for old channel number in RSL emulation */
1079 /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */
1080 f_rslem_unregister(0, st.old_chan_nr);
Philipp Maierc1e95c82018-07-18 16:03:00 +02001081
1082 /* The channel release must not necessarly be synchronized to the RSL handover
1083 * procedure since those events may happen independently nearly at the same
1084 * time. When we receive the RSL_RF_CHAN_REL command the media negotiation on
1085 * IPACC or MGCP level may be still in progress. In order to make sure that
1086 * we do only stop when we have seen an MDCX on MGCP level and another a CRCX
1087 * as well as an MDCX on IPACC level. */
1088 if (g_media.mgcp_conn[0].mdcx_seen <= st.mdcx_seen_before_ho or
1089 g_media.bts1.ipa_mdcx_seen == false or g_media.bts1.ipa_crcx_seen == false) {
1090 repeat;
1091 } else {
1092 st.handover_done := true;
1093 }
Harald Welte261af4b2018-02-12 21:20:39 +01001094 }
1095}
1096
1097
Harald Weltec1a2fff2017-12-17 11:06:19 +01001098
Harald Welte28d943e2017-11-25 15:00:50 +01001099}