Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 1 | module MSC_ConnectionHandler { |
| 2 | |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 3 | /* 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 Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 14 | import from Misc_Helpers all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 15 | import from General_Types all; |
| 16 | import from Osmocom_Types all; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 17 | import from GSM_Types all; |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 18 | import from IPA_Emulation all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 19 | import from SCCPasp_Types all; |
| 20 | import from BSSAP_Types all; |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 21 | import from RAN_Emulation all; |
Harald Welte | 47cd0e3 | 2020-08-21 12:39:11 +0200 | [diff] [blame] | 22 | import from BSSAP_LE_Emulation all; |
| 23 | import from BSSAP_LE_Types all; |
| 24 | import from BSSMAP_LE_Templates all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 25 | import from BSSMAP_Templates all; |
| 26 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 27 | import from IPL4asp_Types all; |
| 28 | import from Native_Functions all; |
| 29 | |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 30 | import from MGCP_CodecPort all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 31 | import from MGCP_Types all; |
| 32 | import from MGCP_Templates all; |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 33 | import from MGCP_Emulation all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 34 | import from SDP_Types all; |
| 35 | |
Daniel Willmann | ebdecc0 | 2020-08-12 15:30:17 +0200 | [diff] [blame] | 36 | import from StatsD_Checker all; |
| 37 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 38 | import from RSL_Emulation all; |
| 39 | import from RSL_Types all; |
| 40 | |
| 41 | import from MobileL3_Types all; |
| 42 | import from MobileL3_CommonIE_Types all; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 43 | import from MobileL3_RRM_Types all; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 44 | import from L3_Templates all; |
| 45 | |
Harald Welte | c20b1c4 | 2018-02-12 20:50:08 +0100 | [diff] [blame] | 46 | import from TELNETasp_PortType all; |
| 47 | import from Osmocom_VTY_Functions all; |
Neels Hofmeyr | c2425cc | 2021-04-19 13:19:55 +0000 | [diff] [blame] | 48 | import from TCCConversion_Functions all; |
Harald Welte | c20b1c4 | 2018-02-12 20:50:08 +0100 | [diff] [blame] | 49 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 50 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 51 | /*********************************************************************** |
| 52 | * Media related handling |
| 53 | ***********************************************************************/ |
| 54 | |
Philipp Maier | 11a5894 | 2018-06-25 16:40:48 +0200 | [diff] [blame] | 55 | /* Get the matching payload type for a specified BSSAP codec type |
| 56 | * (see also: BSSAP_Types.ttcn */ |
| 57 | private function f_get_mgcp_pt(BSSMAP_FIELD_CodecType codecType) return SDP_FIELD_PayloadType { |
| 58 | if (codecType == GSM_FR) { |
| 59 | return PT_GSM; |
| 60 | } else if (codecType == GSM_HR) { |
| 61 | return PT_GSMHR; |
| 62 | } else if (codecType == GSM_EFR) { |
| 63 | return PT_GSMEFR; |
| 64 | } else if (codecType == FR_AMR or codecType == HR_AMR) { |
| 65 | return PT_AMR; |
| 66 | } else if (codecType == FR_AMR_WB or codecType == OHR_AMR or codecType == OFR_AMR_WB or codecType == OHR_AMR_WB) { |
| 67 | return PT_AMRWB; |
| 68 | } |
| 69 | |
| 70 | return PT_PCMU; |
| 71 | } |
| 72 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 73 | /* Tuple containing host/ip and port */ |
| 74 | type record HostPort { |
| 75 | HostName host, |
| 76 | PortNumber port_nr |
| 77 | }; |
| 78 | |
| 79 | /* State encapsulating one MGCP Connection */ |
| 80 | type record MgcpConnState { |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 81 | integer crcx_seen, /* Counts how many CRCX operations happend */ |
| 82 | integer mdcx_seen, /* Counts how many MDCX operations happend C */ |
| 83 | integer crcx_seen_exp, /* Sets the expected number of CRCX operations */ |
| 84 | integer mdcx_seen_exp, /* Sets the expected number of MDCX operations */ |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 85 | MgcpConnectionId conn_id, |
| 86 | charstring mime_type, /* e.g. AMR */ |
| 87 | integer sample_rate, /* 8000 */ |
| 88 | integer ptime, /* 20 */ |
| 89 | uint7_t rtp_pt, /* RTP Payload Type */ |
| 90 | HostPort mgw, /* MGW side */ |
| 91 | HostPort peer /* CA side */ |
| 92 | }; |
| 93 | |
| 94 | /* BTS media state */ |
| 95 | type record BtsMediaState { |
| 96 | boolean ipa_crcx_seen, |
Philipp Maier | c1e95c8 | 2018-07-18 16:03:00 +0200 | [diff] [blame] | 97 | boolean ipa_mdcx_seen, |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 98 | uint16_t conn_id, |
| 99 | uint7_t rtp_pt, |
| 100 | HostPort bts, |
| 101 | HostPort peer |
| 102 | }; |
| 103 | |
| 104 | type record MediaState { |
| 105 | MgcpEndpoint mgcp_ep, |
| 106 | MgcpConnState mgcp_conn[2], |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 107 | BtsMediaState bts, |
| 108 | BtsMediaState bts1 /* only during hand-over */ |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 109 | }; |
| 110 | |
Philipp Maier | 11a5894 | 2018-06-25 16:40:48 +0200 | [diff] [blame] | 111 | function f_MediaState_init(inout MediaState g_media, integer nr, HostName bts, HostName mgw, BSSMAP_FIELD_CodecType codecType) { |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 112 | /* BTS Side */ |
| 113 | g_media.bts := { |
| 114 | ipa_crcx_seen := false, |
Philipp Maier | c1e95c8 | 2018-07-18 16:03:00 +0200 | [diff] [blame] | 115 | ipa_mdcx_seen := false, |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 116 | conn_id := nr, |
| 117 | rtp_pt := 0, |
| 118 | bts := { |
| 119 | host := bts, |
| 120 | port_nr := 9000 + nr*2 |
| 121 | }, |
| 122 | peer := - |
| 123 | } |
| 124 | |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 125 | g_media.bts1 := { |
| 126 | ipa_crcx_seen := false, |
Philipp Maier | c1e95c8 | 2018-07-18 16:03:00 +0200 | [diff] [blame] | 127 | ipa_mdcx_seen := false, |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 128 | conn_id := nr, |
| 129 | rtp_pt := 0, |
| 130 | bts := { |
| 131 | host := bts, /* FIXME */ |
| 132 | port_nr := 9000 + nr*2 |
| 133 | }, |
| 134 | peer := - |
| 135 | } |
| 136 | |
Harald Welte | 363cb0a | 2018-01-30 19:35:53 +0100 | [diff] [blame] | 137 | g_media.mgcp_ep := "rtpbridge/" & int2str(nr) & "@mgw"; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 138 | |
| 139 | for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) { |
Philipp Maier | 11a5894 | 2018-06-25 16:40:48 +0200 | [diff] [blame] | 140 | g_media.mgcp_conn[i].mime_type := f_encoding_name_from_pt(f_get_mgcp_pt(codecType)); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 141 | g_media.mgcp_conn[i].sample_rate := 8000; |
| 142 | g_media.mgcp_conn[i].ptime := 20; |
Philipp Maier | 11a5894 | 2018-06-25 16:40:48 +0200 | [diff] [blame] | 143 | g_media.mgcp_conn[i].rtp_pt := enum2int(f_get_mgcp_pt(codecType)); |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 144 | g_media.mgcp_conn[i].crcx_seen := 0; |
| 145 | g_media.mgcp_conn[i].mdcx_seen := 0; |
| 146 | g_media.mgcp_conn[i].crcx_seen_exp := 0; |
| 147 | g_media.mgcp_conn[i].mdcx_seen_exp := 0; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 148 | g_media.mgcp_conn[i].conn_id := f_mgcp_alloc_conn_id(); |
| 149 | } |
| 150 | |
| 151 | g_media.mgcp_conn[0].mgw := { |
| 152 | host := mgw, |
| 153 | port_nr := 10000 + nr*2 |
| 154 | } |
| 155 | g_media.mgcp_conn[1].mgw := { |
| 156 | host := mgw, |
| 157 | port_nr := 11000 + nr*2 |
| 158 | } |
| 159 | } |
| 160 | |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 161 | /* Helper function to get the next free MGCP connection identifier. We can |
| 162 | * recognize free connection identifiers by the fact that no CRCX happend yet */ |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 163 | private function f_get_free_mgcp_conn() runs on MSC_ConnHdlr return integer { |
| 164 | for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) { |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 165 | if (not g_media.mgcp_conn[i].crcx_seen >= 1) { |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 166 | return i; |
| 167 | } |
| 168 | } |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 169 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Only 2 Connections per EP!"); |
| 170 | /* Should never be reached */ |
| 171 | return -1; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 174 | /* Helper function to pick a specific connection by its cid. Since we reach out |
| 175 | * for a connection that is in-use we also check if there was already exactly |
| 176 | * one CRCX happening on that connection. */ |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 177 | private function f_get_mgcp_conn(MgcpConnectionId cid) runs on MSC_ConnHdlr return integer { |
| 178 | for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) { |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 179 | if (g_media.mgcp_conn[i].conn_id == cid and g_media.mgcp_conn[i].crcx_seen == 1) { |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 180 | return i; |
| 181 | } |
| 182 | } |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 183 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No Connection for ID ", cid)); |
| 184 | /* Should not be reached */ |
| 185 | return -1; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 186 | } |
| 187 | |
Philipp Maier | b242235 | 2018-07-11 10:36:57 +0200 | [diff] [blame] | 188 | /* altstep for handling of IPACC media related commands. Activated by as_Media() to test |
| 189 | * RSL level media handling */ |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 190 | altstep as_Media_ipacc(RSL_DCHAN_PT rsl_pt := RSL, RSL_DCHAN_PT rsl_pt_ho_target := RSL1) runs on MSC_ConnHdlr { |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 191 | var RSL_Message rsl; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 192 | var RSL_IE_Body ie; |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 193 | var boolean b_unused; |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 194 | [not g_media.bts.ipa_crcx_seen] rsl_pt.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl { |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 195 | /* Extract parameters from request + use in response */ |
| 196 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 197 | g_media.bts.rtp_pt := ie.ipa_rtp_pt; |
| 198 | } |
| 199 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 200 | g_media.bts.rtp_pt := ie.ipa_rtp_pt2; |
| 201 | } |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 202 | rsl_pt.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts.conn_id, |
Vadim Yanitskiy | fc63164 | 2021-07-03 02:42:45 +0200 | [diff] [blame] | 203 | f_inet_addr(g_media.bts.bts.host), |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 204 | g_media.bts.bts.port_nr, |
| 205 | g_media.bts.rtp_pt)); |
| 206 | g_media.bts.ipa_crcx_seen := true; |
| 207 | repeat; |
| 208 | } |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 209 | [g_media.bts.ipa_crcx_seen] rsl_pt.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{ |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 210 | /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */ |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 211 | b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 212 | if (g_media.bts.conn_id != ie.ipa_conn_id) { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 213 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("IPA MDCX for unknown ConnId", rsl)); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 214 | } |
| 215 | /* mandatory */ |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 216 | b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_IP, ie); |
Vadim Yanitskiy | fc63164 | 2021-07-03 02:42:45 +0200 | [diff] [blame] | 217 | g_media.bts.peer.host := f_inet_ntoa(ie.ipa_remote_ip); |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 218 | b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_PORT, ie); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 219 | g_media.bts.peer.port_nr := ie.ipa_remote_port; |
| 220 | /* optional */ |
| 221 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 222 | g_media.bts.rtp_pt := ie.ipa_rtp_pt; |
| 223 | } |
| 224 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 225 | g_media.bts.rtp_pt := ie.ipa_rtp_pt2; |
| 226 | } |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 227 | rsl_pt.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts.conn_id, |
Vadim Yanitskiy | fc63164 | 2021-07-03 02:42:45 +0200 | [diff] [blame] | 228 | f_inet_addr(g_media.bts.peer.host), |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 229 | g_media.bts.peer.port_nr, |
| 230 | g_media.bts.rtp_pt)); |
Philipp Maier | c1e95c8 | 2018-07-18 16:03:00 +0200 | [diff] [blame] | 231 | g_media.bts.ipa_mdcx_seen := true; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 232 | repeat; |
| 233 | } |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 234 | |
| 235 | /* on second (new) BTS during hand-over */ |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 236 | [not g_media.bts1.ipa_crcx_seen] rsl_pt_ho_target.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl { |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 237 | /* Extract parameters from request + use in response */ |
| 238 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 239 | g_media.bts1.rtp_pt := ie.ipa_rtp_pt; |
| 240 | } |
| 241 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 242 | g_media.bts1.rtp_pt := ie.ipa_rtp_pt2; |
| 243 | } |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 244 | rsl_pt_ho_target.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts1.conn_id, |
Vadim Yanitskiy | fc63164 | 2021-07-03 02:42:45 +0200 | [diff] [blame] | 245 | f_inet_addr(g_media.bts1.bts.host), |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 246 | g_media.bts1.bts.port_nr, |
| 247 | g_media.bts1.rtp_pt)); |
| 248 | g_media.bts1.ipa_crcx_seen := true; |
| 249 | repeat; |
| 250 | } |
| 251 | /* on second (new) BTS during hand-over */ |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 252 | [g_media.bts1.ipa_crcx_seen] rsl_pt_ho_target.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{ |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 253 | /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */ |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 254 | b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie); |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 255 | if (g_media.bts1.conn_id != ie.ipa_conn_id) { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 256 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("IPA MDCX for unknown ConnId", rsl)); |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 257 | } |
| 258 | /* mandatory */ |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 259 | b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_IP, ie); |
Vadim Yanitskiy | fc63164 | 2021-07-03 02:42:45 +0200 | [diff] [blame] | 260 | g_media.bts1.peer.host := f_inet_ntoa(ie.ipa_remote_ip); |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 261 | b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_PORT, ie); |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 262 | g_media.bts1.peer.port_nr := ie.ipa_remote_port; |
| 263 | /* optional */ |
| 264 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 265 | g_media.bts1.rtp_pt := ie.ipa_rtp_pt; |
| 266 | } |
| 267 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 268 | g_media.bts1.rtp_pt := ie.ipa_rtp_pt2; |
| 269 | } |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 270 | rsl_pt_ho_target.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts1.conn_id, |
Vadim Yanitskiy | fc63164 | 2021-07-03 02:42:45 +0200 | [diff] [blame] | 271 | f_inet_addr(g_media.bts1.peer.host), |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 272 | g_media.bts1.peer.port_nr, |
| 273 | g_media.bts1.rtp_pt)); |
Philipp Maier | c1e95c8 | 2018-07-18 16:03:00 +0200 | [diff] [blame] | 274 | g_media.bts1.ipa_mdcx_seen := true; |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 275 | repeat; |
| 276 | } |
| 277 | |
Philipp Maier | b242235 | 2018-07-11 10:36:57 +0200 | [diff] [blame] | 278 | |
| 279 | } |
| 280 | |
Pau Espin Pedrol | 513b831 | 2019-06-18 17:37:36 +0200 | [diff] [blame] | 281 | function f_rx_crcx(MgcpCommand mgcp_cmd) |
| 282 | runs on MSC_ConnHdlr return template MgcpResponse { |
| 283 | var MgcpOsmuxCID osmux_cid; |
| 284 | var SDP_Message sdp; |
| 285 | var integer cid := f_get_free_mgcp_conn(); |
Philipp Maier | a208389 | 2020-09-21 14:18:36 +0200 | [diff] [blame] | 286 | var charstring local_rtp_addr; |
| 287 | |
| 288 | if (g_pars.media_mgw_offer_ipv6 == true) { |
| 289 | local_rtp_addr := host_mgw_rtp_v6; /* Use IPv6 by default if no remote addr is provided by client */ |
| 290 | } else { |
| 291 | local_rtp_addr := host_mgw_rtp_v4; /* Use IPv4 by default if no remote addr is provided by client */ |
| 292 | } |
| 293 | |
Pau Espin Pedrol | 513b831 | 2019-06-18 17:37:36 +0200 | [diff] [blame] | 294 | if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard)) { |
| 295 | if (cid != 0) { |
| 296 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "MGCP wildcard EP only works in first CRCX"); |
| 297 | } |
| 298 | /* we keep the endpoint name allocated during MediaState_init */ |
| 299 | } else { |
| 300 | /* Call Agent allocated endpoint, trust/use it always */ |
| 301 | g_media.mgcp_ep := mgcp_cmd.line.ep; |
| 302 | } |
| 303 | if (isvalue(mgcp_cmd.sdp)) { |
| 304 | sdp := mgcp_cmd.sdp; |
| 305 | g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr; |
| 306 | g_media.mgcp_conn[cid].peer.port_nr := sdp.media_list[0].media_field.ports.port_number; |
Pau Espin Pedrol | 0786663 | 2020-09-03 19:10:55 +0200 | [diff] [blame] | 307 | if (sdp.connection.addr_type == "IP6") { |
| 308 | local_rtp_addr := host_mgw_rtp_v6; |
| 309 | } else { |
| 310 | local_rtp_addr := host_mgw_rtp_v4; |
| 311 | } |
Pau Espin Pedrol | 513b831 | 2019-06-18 17:37:36 +0200 | [diff] [blame] | 312 | } |
| 313 | var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid]; |
Pau Espin Pedrol | 0786663 | 2020-09-03 19:10:55 +0200 | [diff] [blame] | 314 | sdp := valueof(ts_SDP(mgcp_conn.mgw.host, local_rtp_addr, "foo", "21", |
Pau Espin Pedrol | 513b831 | 2019-06-18 17:37:36 +0200 | [diff] [blame] | 315 | mgcp_conn.mgw.port_nr, { int2str(mgcp_conn.rtp_pt) }, |
| 316 | {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt, |
| 317 | mgcp_conn.mime_type & "/" & |
| 318 | int2str(mgcp_conn.sample_rate))), |
| 319 | valueof(ts_SDP_ptime(mgcp_conn.ptime)) } )); |
| 320 | var template MgcpResponse mgcp_resp; |
| 321 | if (g_pars.use_osmux and f_MgcpCmd_contains_par(mgcp_cmd, "X-OSMUX")) { |
| 322 | osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd); |
| 323 | mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, osmux_cid, sdp); |
| 324 | } else { |
| 325 | mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp); |
| 326 | } |
| 327 | f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(g_media.mgcp_ep)); |
| 328 | g_media.mgcp_conn[cid].crcx_seen := g_media.mgcp_conn[cid].crcx_seen + 1; |
| 329 | return mgcp_resp; |
| 330 | } |
| 331 | |
| 332 | function f_rx_mdcx(MgcpCommand mgcp_cmd) |
| 333 | runs on MSC_ConnHdlr return template MgcpResponse { |
| 334 | var SDP_Message sdp; |
| 335 | var integer cid := f_get_mgcp_conn(f_MgcpCmd_extract_conn_id(mgcp_cmd)); |
Pau Espin Pedrol | 0786663 | 2020-09-03 19:10:55 +0200 | [diff] [blame] | 336 | var charstring local_rtp_addr; |
Pau Espin Pedrol | 513b831 | 2019-06-18 17:37:36 +0200 | [diff] [blame] | 337 | if (isvalue(mgcp_cmd.sdp)) { |
| 338 | sdp := mgcp_cmd.sdp; |
| 339 | g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr; |
| 340 | g_media.mgcp_conn[cid].peer.port_nr := sdp.media_list[0].media_field.ports.port_number; |
Pau Espin Pedrol | 0786663 | 2020-09-03 19:10:55 +0200 | [diff] [blame] | 341 | if (sdp.connection.addr_type == "IP6") { |
| 342 | local_rtp_addr := host_mgw_rtp_v6; |
| 343 | } else { |
| 344 | local_rtp_addr := host_mgw_rtp_v4; |
| 345 | } |
Pau Espin Pedrol | 513b831 | 2019-06-18 17:37:36 +0200 | [diff] [blame] | 346 | } else { |
| 347 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "MDCX has no [recognizable] SDP"); |
| 348 | } |
| 349 | var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid]; |
Pau Espin Pedrol | 0786663 | 2020-09-03 19:10:55 +0200 | [diff] [blame] | 350 | sdp := valueof(ts_SDP(mgcp_conn.peer.host, local_rtp_addr, "foo", "21", |
Pau Espin Pedrol | 513b831 | 2019-06-18 17:37:36 +0200 | [diff] [blame] | 351 | mgcp_conn.peer.port_nr, { int2str(mgcp_conn.rtp_pt) }, |
| 352 | {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt, |
| 353 | mgcp_conn.mime_type & "/" & |
| 354 | int2str(mgcp_conn.sample_rate))), |
| 355 | valueof(ts_SDP_ptime(mgcp_conn.ptime)) } )); |
| 356 | g_media.mgcp_conn[cid].mdcx_seen := g_media.mgcp_conn[cid].mdcx_seen + 1; |
| 357 | return ts_MDCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp); |
| 358 | } |
| 359 | |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 360 | function tr_MGCP_RecvFrom_any(template MgcpMessage msg) |
| 361 | runs on MSC_ConnHdlr return template MGCP_RecvFrom { |
| 362 | var template MGCP_RecvFrom mrf := { |
| 363 | connId := ?, |
| 364 | remName := ?, |
| 365 | remPort := ?, |
| 366 | locName := ?, |
| 367 | locPort := ?, |
| 368 | msg := msg |
| 369 | } |
| 370 | return mrf; |
| 371 | } |
| 372 | |
Philipp Maier | b242235 | 2018-07-11 10:36:57 +0200 | [diff] [blame] | 373 | /* altstep for handling of MGCP media related commands. Activated by as_Media() to test |
| 374 | * MGW level media handling */ |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 375 | |
Philipp Maier | c1e95c8 | 2018-07-18 16:03:00 +0200 | [diff] [blame] | 376 | altstep as_Media_mgw(boolean norepeat := false) runs on MSC_ConnHdlr { |
Philipp Maier | b242235 | 2018-07-11 10:36:57 +0200 | [diff] [blame] | 377 | var MgcpCommand mgcp_cmd; |
Pau Espin Pedrol | 513b831 | 2019-06-18 17:37:36 +0200 | [diff] [blame] | 378 | var template MgcpResponse mgcp_resp; |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 379 | var MGCP_RecvFrom mrf; |
| 380 | var template MgcpMessage msg_crcx := { |
| 381 | command := tr_CRCX |
| 382 | } |
| 383 | var template MgcpMessage msg_mdcx := { |
| 384 | command := tr_MDCX |
| 385 | } |
| 386 | var template MgcpMessage msg_resp; |
Philipp Maier | b242235 | 2018-07-11 10:36:57 +0200 | [diff] [blame] | 387 | |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 388 | [g_pars.aoip] MGCP.receive(tr_CRCX) -> value mgcp_cmd { |
Pau Espin Pedrol | 513b831 | 2019-06-18 17:37:36 +0200 | [diff] [blame] | 389 | mgcp_resp := f_rx_crcx(mgcp_cmd); |
Harald Welte | 363cb0a | 2018-01-30 19:35:53 +0100 | [diff] [blame] | 390 | MGCP.send(mgcp_resp); |
Philipp Maier | c1e95c8 | 2018-07-18 16:03:00 +0200 | [diff] [blame] | 391 | if(norepeat == false) { |
| 392 | repeat; |
| 393 | } |
Pau Espin Pedrol | 513b831 | 2019-06-18 17:37:36 +0200 | [diff] [blame] | 394 | } |
| 395 | |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 396 | [not g_pars.aoip] MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_crcx)) -> value mrf { |
| 397 | mgcp_resp := f_rx_crcx(mrf.msg.command); |
| 398 | msg_resp := { |
| 399 | response := mgcp_resp |
| 400 | } |
| 401 | MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp)); |
| 402 | if(norepeat == false) { |
| 403 | repeat; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | [g_pars.aoip] MGCP.receive(tr_MDCX) -> value mgcp_cmd { |
Pau Espin Pedrol | 513b831 | 2019-06-18 17:37:36 +0200 | [diff] [blame] | 408 | mgcp_resp := f_rx_mdcx(mgcp_cmd); |
| 409 | MGCP.send(mgcp_resp); |
Philipp Maier | c1e95c8 | 2018-07-18 16:03:00 +0200 | [diff] [blame] | 410 | if(norepeat == false) { |
| 411 | repeat; |
| 412 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 413 | } |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 414 | |
| 415 | [not g_pars.aoip] MGCP_MULTI.receive(tr_MGCP_RecvFrom_any(msg_mdcx)) -> value mrf { |
| 416 | mgcp_resp := f_rx_mdcx(mrf.msg.command); |
| 417 | msg_resp := { |
| 418 | response := mgcp_resp |
| 419 | } |
| 420 | MGCP_MULTI.send(t_MGCP_SendToMrf(mrf, msg_resp)); |
| 421 | if(norepeat == false) { |
| 422 | repeat; |
| 423 | } |
| 424 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 425 | } |
| 426 | |
Philipp Maier | b242235 | 2018-07-11 10:36:57 +0200 | [diff] [blame] | 427 | /* Altsteps for handling of media related commands. Can be activated by a given |
| 428 | * test case if it expects to see media related handling (i.e. voice calls) */ |
| 429 | altstep as_Media() runs on MSC_ConnHdlr { |
| 430 | [] as_Media_ipacc(); |
| 431 | [] as_Media_mgw(); |
| 432 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 433 | |
Neels Hofmeyr | d36a82f | 2021-07-20 22:10:49 +0200 | [diff] [blame] | 434 | type port Coord_PT message |
| 435 | { |
| 436 | inout charstring; |
| 437 | } with { extension "internal" }; |
| 438 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 439 | /* this component represents a single subscriber connection at the MSC. |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 440 | * There is a 1:1 mapping between SCCP connections and RAN_ConnHdlr components. |
| 441 | * We inherit all component variables, ports, functions, ... from RAN_ConnHdlr */ |
Harald Welte | 47cd0e3 | 2020-08-21 12:39:11 +0200 | [diff] [blame] | 442 | type component MSC_ConnHdlr extends RAN_ConnHdlr, RSL_DchanHdlr, MGCP_ConnHdlr, BSSAP_LE_ConnHdlr, StatsD_ConnHdlr { |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 443 | /* SCCP Connecction Identifier for the underlying SCCP connection */ |
| 444 | var integer g_sccp_conn_id; |
| 445 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 446 | /* procedure port back to our parent (RAN_Emulation_CT) for control */ |
| 447 | port RAN_PROC_PT RAN; |
Harald Welte | c20b1c4 | 2018-02-12 20:50:08 +0100 | [diff] [blame] | 448 | port TELNETasp_PT BSCVTY; |
Neels Hofmeyr | d36a82f | 2021-07-20 22:10:49 +0200 | [diff] [blame] | 449 | port Coord_PT COORD; |
Vadim Yanitskiy | 5f14d34 | 2022-02-07 14:18:38 +0600 | [diff] [blame] | 450 | port Coord_PT COORD2; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 451 | |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 452 | /* Proxy MGCP-over-IPA and MGCP-over-UDP */ |
| 453 | port IPA_MGCP_PT MGCP_MSC_CLIENT; |
| 454 | var integer g_trans_id := 0; |
| 455 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 456 | var MediaState g_media; |
Harald Welte | a063003 | 2018-03-20 21:09:55 +0100 | [diff] [blame] | 457 | var TestHdlrParams g_pars; |
Harald Welte | e97eab4 | 2018-03-21 18:46:06 +0100 | [diff] [blame] | 458 | |
Pau Espin Pedrol | 392963f | 2019-06-18 17:17:19 +0200 | [diff] [blame] | 459 | var charstring host_bts := "127.0.0.2"; |
Pau Espin Pedrol | 0786663 | 2020-09-03 19:10:55 +0200 | [diff] [blame] | 460 | var charstring host_mgw_mgcp := "127.0.0.3"; |
| 461 | var charstring host_mgw_rtp_v4 := "127.0.0.5"; |
| 462 | var charstring host_mgw_rtp_v6 := "::1"; |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 463 | var charstring host_msc := "127.0.0.4"; |
| 464 | |
Harald Welte | e97eab4 | 2018-03-21 18:46:06 +0100 | [diff] [blame] | 465 | var boolean g_vty_initialized := false; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 466 | } |
| 467 | |
Harald Welte | eddf0e9 | 2020-06-21 19:42:15 +0200 | [diff] [blame] | 468 | function f_MscConnHdlr_init_vty() runs on MSC_ConnHdlr { |
Harald Welte | e97eab4 | 2018-03-21 18:46:06 +0100 | [diff] [blame] | 469 | if (not g_vty_initialized) { |
| 470 | map(self:BSCVTY, system:BSCVTY); |
| 471 | f_vty_set_prompts(BSCVTY); |
| 472 | f_vty_transceive(BSCVTY, "enable"); |
| 473 | g_vty_initialized := true; |
| 474 | } |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 475 | } |
| 476 | |
Harald Welte | eddf0e9 | 2020-06-21 19:42:15 +0200 | [diff] [blame] | 477 | /* initialize all parameters */ |
| 478 | function f_MscConnHdlr_init(integer i, HostName bts, HostName mgw, BSSMAP_FIELD_CodecType codecType) runs on MSC_ConnHdlr { |
| 479 | f_MediaState_init(g_media, i, bts, mgw, codecType); |
| 480 | f_MscConnHdlr_init_vty(); |
| 481 | } |
| 482 | |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 483 | private function get_next_trans_id() runs on MSC_ConnHdlr return MgcpTransId { |
| 484 | var MgcpTransId tid := int2str(g_trans_id); |
| 485 | g_trans_id := g_trans_id + 1; |
| 486 | return tid; |
| 487 | } |
| 488 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 489 | /* Callback function from general RAN_Emulation whenever a connectionless |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 490 | * BSSMAP message arrives. Can retunr a PDU_BSSAP that should be sent in return */ |
| 491 | private function UnitdataCallback(PDU_BSSAP bssap) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 492 | runs on RAN_Emulation_CT return template PDU_BSSAP { |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 493 | var template PDU_BSSAP resp := omit; |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 494 | var boolean append_osmux_support := g_ran_ops.use_osmux and |
| 495 | (g_ran_ops.transport == BSSAP_TRANSPORT_AoIP); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 496 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 497 | /* answer all RESET with a RESET ACK */ |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 498 | if (match(bssap, tr_BSSMAP_Reset(append_osmux_support))) { |
| 499 | resp := ts_BSSMAP_ResetAck(append_osmux_support); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | return resp; |
| 503 | } |
| 504 | |
Harald Welte | 47cd0e3 | 2020-08-21 12:39:11 +0200 | [diff] [blame] | 505 | /* Callback function from general BSSAP_LE_Emulation whenever a connectionless |
| 506 | * BSSAP_LE message arrives. Can return a PDU_BSSAP_LE that should be sent in return */ |
| 507 | private function BSSAP_LE_UnitdataCallback(PDU_BSSAP_LE bssap) |
| 508 | runs on BSSAP_LE_Emulation_CT return template PDU_BSSAP_LE { |
| 509 | var template PDU_BSSAP_LE resp := omit; |
| 510 | |
| 511 | /* answer all RESET with a RESET ACK */ |
| 512 | if (match(bssap, tr_BSSMAP_LE_Reset)) { |
| 513 | resp := ts_BSSMAP_LE_ResetAck; |
| 514 | } |
| 515 | |
| 516 | return resp; |
| 517 | } |
| 518 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 519 | const RanOps MSC_RanOps := { |
| 520 | create_cb := refers(RAN_Emulation.ExpectedCreateCallback), |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 521 | unitdata_cb := refers(UnitdataCallback), |
| 522 | decode_dtap := false, |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 523 | role_ms := false, |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 524 | protocol := RAN_PROTOCOL_BSSAP, |
Pau Espin Pedrol | c6b78ff | 2019-06-06 15:58:17 +0200 | [diff] [blame] | 525 | transport := BSSAP_TRANSPORT_AoIP, |
Pau Espin Pedrol | c6a53db | 2019-05-20 19:31:47 +0200 | [diff] [blame] | 526 | use_osmux := false, |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 527 | sccp_addr_local := omit, |
| 528 | sccp_addr_peer := omit |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 529 | } |
| 530 | |
Harald Welte | 47cd0e3 | 2020-08-21 12:39:11 +0200 | [diff] [blame] | 531 | const BssapLeOps SMLC_BssapLeOps := { |
| 532 | create_cb := refers(BSSAP_LE_Emulation.ExpectedCreateCallback), |
| 533 | unitdata_cb := refers(BSSAP_LE_UnitdataCallback), |
| 534 | decode_dtap := false, |
| 535 | role_ms := false, |
| 536 | sccp_addr_local := omit, |
| 537 | sccp_addr_peer := omit |
| 538 | } |
| 539 | |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 540 | const MGCPOps MSC_MGCPOps := { |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 541 | create_cb := refers(MGCP_Emulation.ExpectedCreateCallback), |
| 542 | unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback) |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 543 | } |
| 544 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 545 | /* register an expect with the BSSMAP core */ |
Neels Hofmeyr | 4f11841 | 2020-06-04 15:25:10 +0200 | [diff] [blame] | 546 | function f_create_bssmap_exp(octetstring l3_enc) runs on MSC_ConnHdlr { |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 547 | RAN.call(RAN_register:{l3_enc, self}) { |
| 548 | [] RAN.getreply(RAN_register:{?, ?}) {}; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | |
Harald Welte | 651fcdc | 2018-05-10 20:23:16 +0200 | [diff] [blame] | 552 | type record TestHdlrEncrParams { |
| 553 | OCT1 enc_alg, |
Neels Hofmeyr | 6c388f2 | 2021-06-11 02:36:56 +0200 | [diff] [blame] | 554 | octetstring enc_key, |
| 555 | octetstring enc_kc128 optional |
Harald Welte | 651fcdc | 2018-05-10 20:23:16 +0200 | [diff] [blame] | 556 | }; |
| 557 | |
Neels Hofmeyr | 6c388f2 | 2021-06-11 02:36:56 +0200 | [diff] [blame] | 558 | template (value) TestHdlrEncrParams t_EncrParams(OCT1 alg, octetstring key, template (omit) octetstring kc128 := omit) := { |
Harald Welte | 651fcdc | 2018-05-10 20:23:16 +0200 | [diff] [blame] | 559 | enc_alg := alg, |
Neels Hofmeyr | 6c388f2 | 2021-06-11 02:36:56 +0200 | [diff] [blame] | 560 | enc_key := key, |
| 561 | enc_kc128 := kc128 |
Harald Welte | 651fcdc | 2018-05-10 20:23:16 +0200 | [diff] [blame] | 562 | } |
| 563 | |
Harald Welte | cc0b014 | 2018-05-29 15:19:33 +0200 | [diff] [blame] | 564 | type record TestHdlrParamsLcls { |
| 565 | GlobalCallReferenceValue gcr optional, |
| 566 | /* LCLS Configuration */ |
| 567 | BIT4 cfg optional, |
| 568 | /* LCLS Connection Status Control */ |
| 569 | BIT4 csc optional, |
Max | 2eeb511 | 2018-11-06 19:21:41 +0100 | [diff] [blame] | 570 | BIT4 exp_sts optional, |
| 571 | /* Whether to adjust *cx_seen_exp for LCLS tests */ |
| 572 | boolean adjust_cx_exp |
Harald Welte | cc0b014 | 2018-05-29 15:19:33 +0200 | [diff] [blame] | 573 | } |
| 574 | |
Neels Hofmeyr | f246a92 | 2020-05-13 02:27:10 +0200 | [diff] [blame] | 575 | type record TestHdlrParamsMSCPool { |
Neels Hofmeyr | 4f11841 | 2020-06-04 15:25:10 +0200 | [diff] [blame] | 576 | integer bssap_idx, |
Neels Hofmeyr | 4f11841 | 2020-06-04 15:25:10 +0200 | [diff] [blame] | 577 | integer rsl_idx, |
| 578 | PDU_ML3_MS_NW l3_info optional |
Neels Hofmeyr | f246a92 | 2020-05-13 02:27:10 +0200 | [diff] [blame] | 579 | } |
| 580 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 581 | type record TestHdlrParams { |
| 582 | OCT1 ra, |
| 583 | GsmFrameNumber fn, |
| 584 | hexstring imsi, |
Harald Welte | 60aa576 | 2018-03-21 19:33:13 +0100 | [diff] [blame] | 585 | RslLinkId link_id, |
Harald Welte | cbe911c | 2018-06-01 18:23:07 +0200 | [diff] [blame] | 586 | integer media_nr, /* determins MGCP EP, port numbers */ |
Harald Welte | 651fcdc | 2018-05-10 20:23:16 +0200 | [diff] [blame] | 587 | BSSMAP_IE_SpeechCodecList ass_codec_list optional, |
Neels Hofmeyr | bcf62bc | 2018-07-04 00:24:33 +0200 | [diff] [blame] | 588 | RSL_IE_Body expect_mr_conf_ie optional, /* typically present for AMR codecs */ |
Philipp Maier | d0e64b0 | 2019-03-13 14:15:23 +0100 | [diff] [blame] | 589 | bitstring expect_mr_s0_s7 optional, /* typically present for AMR codecs */ |
Harald Welte | cc0b014 | 2018-05-29 15:19:33 +0200 | [diff] [blame] | 590 | TestHdlrEncrParams encr optional, |
Oliver Smith | 1dff88d | 2021-07-09 08:45:51 +0200 | [diff] [blame] | 591 | OCT1 encr_exp_enc_alg optional, /* if set, expect a different enc_alg than encr.enc_alg */ |
Neels Hofmeyr | bd0ef93 | 2018-03-19 14:58:46 +0100 | [diff] [blame] | 592 | TestHdlrParamsLcls lcls, |
Neels Hofmeyr | 90f8096 | 2020-06-12 16:16:55 +0200 | [diff] [blame] | 593 | SCCP_PAR_Address sccp_addr_msc optional, |
| 594 | SCCP_PAR_Address sccp_addr_bsc optional, |
Pau Espin Pedrol | f7630a6 | 2019-10-28 15:07:08 +0100 | [diff] [blame] | 595 | uint5_t exp_ms_power_level, |
Pau Espin Pedrol | 8f77363 | 2019-11-05 11:46:53 +0100 | [diff] [blame] | 596 | boolean exp_ms_power_params, |
Pau Espin Pedrol | c6a53db | 2019-05-20 19:31:47 +0200 | [diff] [blame] | 597 | boolean aoip, |
Neels Hofmeyr | f246a92 | 2020-05-13 02:27:10 +0200 | [diff] [blame] | 598 | boolean use_osmux, |
Pau Espin Pedrol | 0786663 | 2020-09-03 19:10:55 +0200 | [diff] [blame] | 599 | charstring host_aoip_tla, |
Philipp Maier | a208389 | 2020-09-21 14:18:36 +0200 | [diff] [blame] | 600 | TestHdlrParamsMSCPool mscpool, |
Pau Espin Pedrol | c08d552 | 2021-04-16 15:40:38 +0200 | [diff] [blame] | 601 | boolean media_mgw_offer_ipv6, |
Neels Hofmeyr | 559d5d0 | 2021-04-16 16:50:49 +0200 | [diff] [blame] | 602 | OCT3 last_used_eutran_plmn optional, |
Pau Espin Pedrol | 9ae36d5 | 2021-06-15 17:29:43 +0200 | [diff] [blame] | 603 | boolean exp_fast_return, /* RR Release expected to contain CellSelectInd ? */ |
Neels Hofmeyr | b5b7a6e | 2021-06-04 19:03:45 +0200 | [diff] [blame] | 604 | boolean expect_channel_mode_modify, |
| 605 | uint3_t expect_tsc optional |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 606 | }; |
| 607 | |
Philipp Maier | 4860473 | 2018-10-09 15:00:37 +0200 | [diff] [blame] | 608 | /* Note: Do not use valueof() to get a value of this template, use |
| 609 | * f_gen_test_hdlr_pars() instead in order to get a configuration that is |
Pau Espin Pedrol | 8df1011 | 2020-01-09 18:21:53 +0100 | [diff] [blame] | 610 | * matched to the current test situation (aoip vs. sccplite) */ |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 611 | template (value) TestHdlrParams t_def_TestHdlrPars := { |
| 612 | ra := '23'O, |
| 613 | fn := 23, |
| 614 | imsi := '001019876543210'H, |
Harald Welte | 60aa576 | 2018-03-21 19:33:13 +0100 | [diff] [blame] | 615 | link_id := valueof(ts_RslLinkID_DCCH(0)), |
Harald Welte | cbe911c | 2018-06-01 18:23:07 +0200 | [diff] [blame] | 616 | media_nr := 1, |
Harald Welte | 651fcdc | 2018-05-10 20:23:16 +0200 | [diff] [blame] | 617 | ass_codec_list := omit, |
Neels Hofmeyr | bcf62bc | 2018-07-04 00:24:33 +0200 | [diff] [blame] | 618 | expect_mr_conf_ie := omit, |
Philipp Maier | d0e64b0 | 2019-03-13 14:15:23 +0100 | [diff] [blame] | 619 | expect_mr_s0_s7 := omit, |
Harald Welte | cc0b014 | 2018-05-29 15:19:33 +0200 | [diff] [blame] | 620 | encr := omit, |
Oliver Smith | 1dff88d | 2021-07-09 08:45:51 +0200 | [diff] [blame] | 621 | encr_exp_enc_alg := omit, |
Harald Welte | cc0b014 | 2018-05-29 15:19:33 +0200 | [diff] [blame] | 622 | lcls := { |
| 623 | gcr := omit, |
| 624 | cfg := omit, |
| 625 | csc := omit, |
Max | 2eeb511 | 2018-11-06 19:21:41 +0100 | [diff] [blame] | 626 | exp_sts := omit, |
| 627 | adjust_cx_exp := true |
Neels Hofmeyr | bd0ef93 | 2018-03-19 14:58:46 +0100 | [diff] [blame] | 628 | }, |
Neels Hofmeyr | 90f8096 | 2020-06-12 16:16:55 +0200 | [diff] [blame] | 629 | sccp_addr_msc := omit, |
| 630 | sccp_addr_bsc := omit, |
Pau Espin Pedrol | f7630a6 | 2019-10-28 15:07:08 +0100 | [diff] [blame] | 631 | exp_ms_power_level := 7, /* calculated from osmo-bsc.cfg "ms max power" */ |
Pau Espin Pedrol | 8f77363 | 2019-11-05 11:46:53 +0100 | [diff] [blame] | 632 | exp_ms_power_params := false, |
Pau Espin Pedrol | c6a53db | 2019-05-20 19:31:47 +0200 | [diff] [blame] | 633 | aoip := true, |
Neels Hofmeyr | f246a92 | 2020-05-13 02:27:10 +0200 | [diff] [blame] | 634 | use_osmux := false, |
Pau Espin Pedrol | 0786663 | 2020-09-03 19:10:55 +0200 | [diff] [blame] | 635 | host_aoip_tla := "1.2.3.4", |
Neels Hofmeyr | f246a92 | 2020-05-13 02:27:10 +0200 | [diff] [blame] | 636 | mscpool := { |
Neels Hofmeyr | 4f11841 | 2020-06-04 15:25:10 +0200 | [diff] [blame] | 637 | bssap_idx := 0, |
Neels Hofmeyr | 4f11841 | 2020-06-04 15:25:10 +0200 | [diff] [blame] | 638 | rsl_idx := 0, |
| 639 | l3_info := omit |
Philipp Maier | a208389 | 2020-09-21 14:18:36 +0200 | [diff] [blame] | 640 | }, |
Pau Espin Pedrol | c08d552 | 2021-04-16 15:40:38 +0200 | [diff] [blame] | 641 | media_mgw_offer_ipv6 := true, |
Neels Hofmeyr | 559d5d0 | 2021-04-16 16:50:49 +0200 | [diff] [blame] | 642 | last_used_eutran_plmn := omit, |
Pau Espin Pedrol | 9ae36d5 | 2021-06-15 17:29:43 +0200 | [diff] [blame] | 643 | exp_fast_return := false, |
Neels Hofmeyr | b5b7a6e | 2021-06-04 19:03:45 +0200 | [diff] [blame] | 644 | expect_channel_mode_modify := false, |
| 645 | expect_tsc := omit |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 646 | } |
| 647 | |
Vadim Yanitskiy | a7fc5a6 | 2021-12-04 20:10:08 +0300 | [diff] [blame] | 648 | function f_create_chan_and_exp(template (present) PDU_BSSAP exp_l3_compl := ?) |
| 649 | runs on MSC_ConnHdlr { |
Harald Welte | a063003 | 2018-03-20 21:09:55 +0100 | [diff] [blame] | 650 | var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi)); |
Harald Welte | 6ed6bf9 | 2018-01-24 21:09:15 +0100 | [diff] [blame] | 651 | var PDU_ML3_MS_NW l3_info := valueof(ts_CM_SERV_REQ(CM_TYPE_MO_CALL, mi)); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 652 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info); |
Neels Hofmeyr | b5b7a6e | 2021-06-04 19:03:45 +0200 | [diff] [blame] | 653 | var template uint3_t tsc := ?; |
Vadim Yanitskiy | a7fc5a6 | 2021-12-04 20:10:08 +0300 | [diff] [blame] | 654 | timer T; |
Neels Hofmeyr | b5b7a6e | 2021-06-04 19:03:45 +0200 | [diff] [blame] | 655 | |
| 656 | if (not istemplatekind(g_pars.expect_tsc, "omit")) { |
| 657 | tsc := g_pars.expect_tsc; |
| 658 | } |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 659 | |
Vadim Yanitskiy | a7fc5a6 | 2021-12-04 20:10:08 +0300 | [diff] [blame] | 660 | if (istemplatekind(exp_l3_compl, "?")) { |
| 661 | if (g_pars.aoip == false) { |
| 662 | exp_l3_compl := tr_BSSMAP_ComplL3(l3_enc, codec_list := omit); |
| 663 | } else { |
| 664 | exp_l3_compl := tr_BSSMAP_ComplL3(l3_enc, codec_list := ?); |
| 665 | } |
| 666 | } |
| 667 | |
Neels Hofmeyr | d601f9c | 2021-06-04 22:46:06 +0200 | [diff] [blame] | 668 | f_create_bssmap_exp(l3_enc); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 669 | /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */ |
Neels Hofmeyr | b5b7a6e | 2021-06-04 19:03:45 +0200 | [diff] [blame] | 670 | RSL_Emulation.f_chan_est(g_pars.ra, l3_enc, g_pars.link_id, g_pars.fn, tsc); |
Vadim Yanitskiy | a7fc5a6 | 2021-12-04 20:10:08 +0300 | [diff] [blame] | 671 | /* wait for a COMPL_L3 from the BSC to ensure that the SCCP connection is up */ |
| 672 | T.start(2.0); |
| 673 | alt { |
| 674 | [] BSSAP.receive(exp_l3_compl); |
| 675 | [] BSSAP.receive(tr_BSSMAP_ComplL3) { |
| 676 | setverdict(fail, "Received non-matching COMPLETE LAYER 3 INFORMATION"); |
| 677 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__); |
| 678 | } |
| 679 | [] T.timeout { |
| 680 | setverdict(fail, "Timeout waiting for COMPLETE LAYER 3 INFORMATION"); |
| 681 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__); |
| 682 | } |
| 683 | } |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 684 | } |
| 685 | |
Harald Welte | 898113b | 2018-01-31 18:32:21 +0100 | [diff] [blame] | 686 | function f_rsl_send_l3(template PDU_ML3_MS_NW l3, template (omit) RslLinkId link_id := omit, |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 687 | template (omit) RslChannelNr chan_nr := omit, RSL_DCHAN_PT rsl_pt := RSL) runs on MSC_ConnHdlr { |
Harald Welte | 898113b | 2018-01-31 18:32:21 +0100 | [diff] [blame] | 688 | if (not isvalue(link_id)) { |
| 689 | link_id := ts_RslLinkID_DCCH(0); |
| 690 | } |
| 691 | if (not isvalue(chan_nr)) { |
| 692 | chan_nr := g_chan_nr; |
| 693 | } |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 694 | rsl_pt.send(ts_RSL_DATA_IND(valueof(chan_nr), valueof(link_id), enc_PDU_ML3_MS_NW(valueof(l3)))); |
Harald Welte | 898113b | 2018-01-31 18:32:21 +0100 | [diff] [blame] | 695 | } |
| 696 | |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 697 | function f_rsl_reply(template PDU_ML3_MS_NW l3, RSL_Message orig, RSL_DCHAN_PT rsl_pt := RSL) runs on MSC_ConnHdlr { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 698 | var RslChannelNr chan_nr := orig.ies[0].body.chan_nr; |
Harald Welte | 1a40de6 | 2017-12-23 02:28:34 +0100 | [diff] [blame] | 699 | var RslLinkId link_id; |
Harald Welte | 8d5eead | 2017-12-17 18:56:45 +0100 | [diff] [blame] | 700 | if (orig.msg_type == RSL_MT_ENCR_CMD) { |
| 701 | link_id := orig.ies[2].body.link_id; |
| 702 | } else { |
| 703 | link_id := orig.ies[1].body.link_id; |
| 704 | } |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 705 | f_rsl_send_l3(l3, link_id, chan_nr, rsl_pt := rsl_pt); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 706 | } |
| 707 | |
Oliver Smith | 598e1ed | 2021-07-09 10:28:40 +0200 | [diff] [blame] | 708 | /* Convert the cipher representation on BSSMAP to the representation used on RSL */ |
| 709 | function f_cipher_mode_bssmap_to_rsl(OCT1 alg_bssmap) return RSL_AlgId |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 710 | { |
| 711 | /* A5 0 */ |
| 712 | if (alg_bssmap == '01'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 713 | return RSL_ALG_ID_A5_0; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 714 | } |
| 715 | /* A5 1 */ |
| 716 | else if (alg_bssmap == '02'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 717 | return RSL_ALG_ID_A5_1; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 718 | } |
| 719 | /* A5 2 */ |
| 720 | else if (alg_bssmap == '04'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 721 | return RSL_ALG_ID_A5_2; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 722 | } |
| 723 | /* A5 3 */ |
| 724 | else if (alg_bssmap == '08'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 725 | return RSL_ALG_ID_A5_3; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 726 | } |
| 727 | /* A5 4 */ |
| 728 | else if (alg_bssmap == '10'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 729 | return RSL_ALG_ID_A5_4; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 730 | } |
| 731 | /* A5 5 */ |
| 732 | else if (alg_bssmap == '20'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 733 | return RSL_ALG_ID_A5_5; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 734 | } |
| 735 | /* A5 6 */ |
| 736 | else if (alg_bssmap == '40'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 737 | return RSL_ALG_ID_A5_6; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 738 | } |
| 739 | /* A5 7 */ |
| 740 | else if (alg_bssmap == '80'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 741 | return RSL_ALG_ID_A5_7; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 742 | } else { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 743 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Encryption Algorithm"); |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 744 | return RSL_ALG_ID_A5_0; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | |
Oliver Smith | 1dff88d | 2021-07-09 08:45:51 +0200 | [diff] [blame] | 748 | function f_cipher_mode_bssmap_to_rsl_exp_enc_alg() runs on MSC_ConnHdlr return RSL_AlgId |
| 749 | { |
| 750 | var OCT1 enc_alg; |
| 751 | |
| 752 | if (ispresent(g_pars.encr_exp_enc_alg)) { |
| 753 | enc_alg := g_pars.encr_exp_enc_alg; |
| 754 | } else { |
| 755 | enc_alg := g_pars.encr.enc_alg; |
| 756 | } |
| 757 | |
| 758 | return f_cipher_mode_bssmap_to_rsl(enc_alg); |
| 759 | } |
| 760 | |
Neels Hofmeyr | 58ffceb | 2021-06-21 02:17:30 +0200 | [diff] [blame] | 761 | function f_verify_encr_info(RSL_Message rsl) runs on MSC_ConnHdlr { |
| 762 | var RSL_IE_Body encr_info; |
| 763 | var RSL_AlgId alg_rsl; |
| 764 | var template octetstring expect_kc; |
| 765 | |
| 766 | /* If no encryption is enabled, then make sure there is no RSL_IE_ENCR_INFO */ |
| 767 | if (not ispresent(g_pars.encr)) { |
| 768 | if (f_rsl_find_ie(rsl, RSL_IE_ENCR_INFO, encr_info)) { |
| 769 | setverdict(fail, "Found Encryption IE, but expected no encryption in ", rsl.msg_type); |
| 770 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__); |
| 771 | return; |
| 772 | } |
| 773 | setverdict(pass); |
| 774 | return; |
| 775 | } |
| 776 | |
| 777 | /* RSL uses a different representation of the encryption algorithm, |
| 778 | * so we need to convert first */ |
Oliver Smith | 1dff88d | 2021-07-09 08:45:51 +0200 | [diff] [blame] | 779 | alg_rsl := f_cipher_mode_bssmap_to_rsl_exp_enc_alg(); |
Neels Hofmeyr | 58ffceb | 2021-06-21 02:17:30 +0200 | [diff] [blame] | 780 | |
| 781 | if (alg_rsl == RSL_ALG_ID_A5_4 and ispresent(g_pars.encr.enc_kc128)) { |
| 782 | expect_kc := g_pars.encr.enc_kc128; |
| 783 | } else if (alg_rsl == RSL_ALG_ID_A5_0) { |
| 784 | /* When A5/0 is chosen, no encryption is active, so technically, no key is needed. However, 3GPP TS |
| 785 | * 48.058 9.3.7 Encryption Information stays quite silent about presence or absence of a key for A5/0. |
| 786 | * The only thing specified is how to indicate the length of the key; the possibility that the key may |
| 787 | * be zero length is not explicitly mentioned. So it seems that we should always send the key along, |
| 788 | * even for A5/0. Still, let's also allow a zero length key for A5/0. */ |
| 789 | expect_kc := (g_pars.encr.enc_key, ''O); |
| 790 | } else { |
| 791 | expect_kc := g_pars.encr.enc_key; |
| 792 | } |
| 793 | log("for encryption algo ", alg_rsl, " expect kc = ", expect_kc); |
| 794 | |
| 795 | if (not f_rsl_find_ie(rsl, RSL_IE_ENCR_INFO, encr_info)) { |
| 796 | if (alg_rsl == RSL_ALG_ID_A5_0) { |
| 797 | /* For A5/0, encryption is not active. It is fine to omit the Encryption Information in this |
| 798 | * case. Note that the first channel may see an RSL Encryption Command with A5/0 indicated, and |
| 799 | * a subsequent handover may activate a new channel without any Encryption Information. */ |
| 800 | setverdict(pass); |
| 801 | return; |
| 802 | } |
| 803 | setverdict(fail, "Missing Encryption Information IE in ", rsl.msg_type); |
| 804 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__); |
| 805 | return; |
| 806 | } |
| 807 | |
| 808 | if (not match(encr_info, tr_EncrInfo(alg_rsl, expect_kc))) { |
| 809 | setverdict(fail, "Unexpected Kc in Encryption Information IE in ", rsl.msg_type); |
| 810 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__); |
| 811 | return; |
| 812 | } |
| 813 | setverdict(pass); |
| 814 | } |
| 815 | |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 816 | function f_cipher_mode(TestHdlrEncrParams enc, boolean exp_fail := false, |
| 817 | RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC) |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 818 | runs on MSC_ConnHdlr { |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 819 | var PDU_BSSAP bssap; |
| 820 | var RSL_Message rsl; |
| 821 | |
Neels Hofmeyr | 6c388f2 | 2021-06-11 02:36:56 +0200 | [diff] [blame] | 822 | if (isvalue(enc.enc_kc128)) { |
| 823 | BSSAP.send(ts_BSSMAP_CipherModeCmdKc128(enc.enc_alg, enc.enc_key, valueof(enc.enc_kc128))); |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 824 | } else { |
Neels Hofmeyr | 6c388f2 | 2021-06-11 02:36:56 +0200 | [diff] [blame] | 825 | BSSAP.send(ts_BSSMAP_CipherModeCmd(enc.enc_alg, enc.enc_key)); |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 826 | } |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 827 | |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 828 | alt { |
| 829 | /* RSL/UE Side */ |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 830 | [] rsl_pt.receive(tr_RSL_ENCR_CMD(g_chan_nr)) -> value rsl { |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 831 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[3].body.l3_info.payload); |
| 832 | log("Rx L3 from net: ", l3); |
Neels Hofmeyr | 7274934 | 2021-06-11 02:41:37 +0200 | [diff] [blame] | 833 | |
Neels Hofmeyr | 58ffceb | 2021-06-21 02:17:30 +0200 | [diff] [blame] | 834 | f_verify_encr_info(rsl); |
| 835 | |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 836 | if (ischosen(l3.msgs.rrm.cipheringModeCommand)) { |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 837 | f_rsl_reply(ts_RRM_CiphModeCompl, rsl, rsl_pt := rsl_pt); |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 838 | } |
| 839 | repeat; |
| 840 | } |
| 841 | [] BSSAP.receive(tr_BSSMAP_CipherModeCompl) -> value bssap { |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 842 | if (exp_fail == true) { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 843 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Cipher Mode Complete"); |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 844 | } else { |
| 845 | setverdict(pass); |
Oliver Smith | 1dff88d | 2021-07-09 08:45:51 +0200 | [diff] [blame] | 846 | var RSL_AlgId alg_rsl := f_cipher_mode_bssmap_to_rsl_exp_enc_alg(); |
Neels Hofmeyr | 5e31cfc | 2021-06-11 02:42:11 +0200 | [diff] [blame] | 847 | if (oct2int(bssap.pdu.bssmap.cipherModeComplete.chosenEncryptionAlgorithm.algorithmIdentifier) != enum2int(alg_rsl)) { |
| 848 | setverdict(fail, "Unexpected Encryption Algorithm ID in BSSMAP Cipher Mode Complete"); |
| 849 | } |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 850 | } |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 851 | } |
| 852 | [] BSSAP.receive(tr_BSSMAP_CipherModeRej) -> value bssap { |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 853 | if (exp_fail == false) { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 854 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Ciphering Mode Reject"); |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 855 | } else { |
| 856 | setverdict(pass); |
| 857 | } |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 858 | } |
| 859 | } |
| 860 | } |
| 861 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 862 | /* Convert from Ericsson ChanDesc2 format to Osmocom RslChannelNr format */ |
| 863 | function f_ChDesc2RslChanNr(ChannelDescription2_V ch_desc, out RslChannelNr chan_nr, out GsmArfcn arfcn) { |
| 864 | var BIT5 inp := ch_desc.channelTypeandTDMAOffset; |
Harald Welte | 6fa1f73 | 2018-03-21 22:46:16 +0100 | [diff] [blame] | 865 | var uint3_t tn := bit2int(ch_desc.timeslotNumber); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 866 | |
Vadim Yanitskiy | 2bcea3d | 2021-11-18 19:13:48 +0300 | [diff] [blame] | 867 | select (inp) { |
| 868 | case ('00001'B) { /* TCH/F */ |
Harald Welte | 6fa1f73 | 2018-03-21 22:46:16 +0100 | [diff] [blame] | 869 | chan_nr := valueof(t_RslChanNr_Bm(tn)); |
Vadim Yanitskiy | 2bcea3d | 2021-11-18 19:13:48 +0300 | [diff] [blame] | 870 | } |
| 871 | case ('11101'B) { /* VAMOS TCH/F */ |
Neels Hofmeyr | 9c3b82f | 2021-05-27 00:38:59 +0200 | [diff] [blame] | 872 | chan_nr := valueof(t_RslChanNr_Osmo_VAMOS_Bm(tn)); |
Vadim Yanitskiy | 2bcea3d | 2021-11-18 19:13:48 +0300 | [diff] [blame] | 873 | } |
| 874 | case ('0001?'B) { /* TCH/H */ |
Harald Welte | 6fa1f73 | 2018-03-21 22:46:16 +0100 | [diff] [blame] | 875 | chan_nr := valueof(t_RslChanNr_Lm(tn, bit2int(substr(inp, 4, 1)))); |
Vadim Yanitskiy | 2bcea3d | 2021-11-18 19:13:48 +0300 | [diff] [blame] | 876 | } |
| 877 | case ('1111?'B) { /* VAMOS TCH/H */ |
Neels Hofmeyr | 9c3b82f | 2021-05-27 00:38:59 +0200 | [diff] [blame] | 878 | chan_nr := valueof(t_RslChanNr_Osmo_VAMOS_Lm(tn, bit2int(substr(inp, 4, 1)))); |
Vadim Yanitskiy | 2bcea3d | 2021-11-18 19:13:48 +0300 | [diff] [blame] | 879 | } |
| 880 | case ('001??'B) { /* SDCCH/4 */ |
Harald Welte | 6fa1f73 | 2018-03-21 22:46:16 +0100 | [diff] [blame] | 881 | chan_nr := valueof(t_RslChanNr_SDCCH4(tn, bit2int(substr(inp, 3, 2)))); |
Vadim Yanitskiy | 2bcea3d | 2021-11-18 19:13:48 +0300 | [diff] [blame] | 882 | } |
| 883 | case ('01???'B) { /* SDCCH/8 */ |
Harald Welte | 6fa1f73 | 2018-03-21 22:46:16 +0100 | [diff] [blame] | 884 | chan_nr := valueof(t_RslChanNr_SDCCH8(tn, bit2int(substr(inp, 2, 3)))); |
Vadim Yanitskiy | 2bcea3d | 2021-11-18 19:13:48 +0300 | [diff] [blame] | 885 | } |
| 886 | case else { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 887 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unknown ChDesc!"); |
Vadim Yanitskiy | 2bcea3d | 2021-11-18 19:13:48 +0300 | [diff] [blame] | 888 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | if (ch_desc.octet3 and4b '10'O == '10'O) { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 892 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No support for Hopping"); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 893 | } else { |
| 894 | var OCT2 concat := ch_desc.octet3 & ch_desc.octet4; |
| 895 | arfcn := oct2int(concat); |
| 896 | } |
| 897 | } |
| 898 | |
| 899 | type record AssignmentState { |
| 900 | /* global */ |
| 901 | boolean voice_call, |
| 902 | boolean is_assignment, |
| 903 | /* Assignment related bits */ |
| 904 | boolean rr_ass_cmpl_seen, |
Neels Hofmeyr | a5302c8 | 2018-11-04 23:09:58 +0100 | [diff] [blame] | 905 | boolean old_lchan_deact_sacch_seen, |
| 906 | boolean old_lchan_rll_rel_req_seen, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 907 | boolean assignment_done, |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 908 | RslChannelNr old_chan_nr, |
| 909 | /* Modify related bits */ |
Neels Hofmeyr | 559d5d0 | 2021-04-16 16:50:49 +0200 | [diff] [blame] | 910 | PDU_ML3_NW_MS rr_channel_mode_modify_msg optional, |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 911 | boolean rr_modify_seen, |
Neels Hofmeyr | 559d5d0 | 2021-04-16 16:50:49 +0200 | [diff] [blame] | 912 | RSL_Message rsl_mode_modify_msg optional, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 913 | boolean modify_done |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | template (value) AssignmentState ts_AssignmentStateInit := { |
| 917 | voice_call := false, |
| 918 | is_assignment := false, |
| 919 | rr_ass_cmpl_seen := false, |
Neels Hofmeyr | a5302c8 | 2018-11-04 23:09:58 +0100 | [diff] [blame] | 920 | old_lchan_deact_sacch_seen := false, |
| 921 | old_lchan_rll_rel_req_seen := false, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 922 | assignment_done := false, |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 923 | old_chan_nr := -, |
Neels Hofmeyr | 559d5d0 | 2021-04-16 16:50:49 +0200 | [diff] [blame] | 924 | rr_channel_mode_modify_msg := omit, |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 925 | rr_modify_seen := false, |
Neels Hofmeyr | 559d5d0 | 2021-04-16 16:50:49 +0200 | [diff] [blame] | 926 | rsl_mode_modify_msg := omit, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 927 | modify_done := false |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 928 | } |
| 929 | |
Harald Welte | 8a9bf6f | 2018-05-10 22:00:49 +0200 | [diff] [blame] | 930 | private template RSL_IE_Body tr_EncrInfo(template RSL_AlgId alg, template octetstring key) := { |
| 931 | encr_info := { |
| 932 | len := ?, |
| 933 | alg_id := alg, |
| 934 | key := key |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | /* ensure the RSL CHAN ACT (during assignment) contains values we expect depending on test case */ |
| 939 | private function f_check_chan_act(AssignmentState st, RSL_Message chan_act) runs on MSC_ConnHdlr { |
| 940 | var RSL_IE_Body encr_info; |
Pau Espin Pedrol | 3d008ae | 2019-10-28 13:35:46 +0100 | [diff] [blame] | 941 | var RSL_IE_Body ms_power_param; |
Pau Espin Pedrol | f7630a6 | 2019-10-28 15:07:08 +0100 | [diff] [blame] | 942 | var RSL_IE_Body ms_power; |
Pau Espin Pedrol | 3d008ae | 2019-10-28 13:35:46 +0100 | [diff] [blame] | 943 | |
Harald Welte | 8a9bf6f | 2018-05-10 22:00:49 +0200 | [diff] [blame] | 944 | if (ispresent(g_pars.encr) and g_pars.encr.enc_alg != '01'O) { |
| 945 | if (not f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 946 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Missing Encryption IE in CHAN ACT"); |
Harald Welte | 8a9bf6f | 2018-05-10 22:00:49 +0200 | [diff] [blame] | 947 | } else { |
Oliver Smith | 1dff88d | 2021-07-09 08:45:51 +0200 | [diff] [blame] | 948 | var RSL_AlgId alg := f_cipher_mode_bssmap_to_rsl_exp_enc_alg(); |
Neels Hofmeyr | 0588cad | 2021-06-11 01:38:18 +0200 | [diff] [blame] | 949 | var octetstring expect_key; |
| 950 | if (alg == RSL_ALG_ID_A5_4) { |
| 951 | expect_key := g_pars.encr.enc_kc128; |
| 952 | } else { |
| 953 | expect_key := g_pars.encr.enc_key; |
| 954 | } |
| 955 | if (not match(encr_info, tr_EncrInfo(alg, expect_key))) { |
| 956 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 957 | "Unexpected Kc in Encryption IE in RSL ENCR CMD"); |
Harald Welte | 8a9bf6f | 2018-05-10 22:00:49 +0200 | [diff] [blame] | 958 | } |
| 959 | } |
| 960 | } else { |
| 961 | if (f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) { |
| 962 | if (encr_info.encr_info.alg_id != RSL_ALG_ID_A5_0) { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 963 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected Encryption in CHAN ACT"); |
Harald Welte | 8a9bf6f | 2018-05-10 22:00:49 +0200 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | } |
| 967 | /* FIXME: validate RSL_IE_ACT_TYPE, RSL_IE_CHAN_MODE, RSL_IE_CHAN_IDENT, RSL_IE_BS_POWER, |
Pau Espin Pedrol | 7a9ccf8 | 2019-11-05 11:33:33 +0100 | [diff] [blame] | 968 | * RSL_IE_TIMING_ADVANCE */ |
Pau Espin Pedrol | 3d008ae | 2019-10-28 13:35:46 +0100 | [diff] [blame] | 969 | |
Pau Espin Pedrol | 8f77363 | 2019-11-05 11:46:53 +0100 | [diff] [blame] | 970 | if (g_pars.exp_ms_power_params and not f_rsl_find_ie(chan_act, RSL_IE_MS_POWER_PARAM, ms_power_param)) { |
Pau Espin Pedrol | 3d008ae | 2019-10-28 13:35:46 +0100 | [diff] [blame] | 971 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "IE MS Power Parameters not found in CHAN ACT"); |
| 972 | } |
| 973 | |
Pau Espin Pedrol | f7630a6 | 2019-10-28 15:07:08 +0100 | [diff] [blame] | 974 | if (not f_rsl_find_ie(chan_act, RSL_IE_MS_POWER, ms_power)) { |
| 975 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "IE MS Power not found in CHAN ACT"); |
| 976 | } else { |
| 977 | if (not match(ms_power.ms_power, tr_RSL_IE_MS_Power(g_pars.exp_ms_power_level, false))) { |
Pau Espin Pedrol | 7a9ccf8 | 2019-11-05 11:33:33 +0100 | [diff] [blame] | 978 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Wrong MS Power IE in CHAN ACT, ", ms_power.ms_power.power_level, " vs exp ", g_pars.exp_ms_power_level)); |
Pau Espin Pedrol | f7630a6 | 2019-10-28 15:07:08 +0100 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | |
Harald Welte | 8a9bf6f | 2018-05-10 22:00:49 +0200 | [diff] [blame] | 982 | } |
| 983 | |
Neels Hofmeyr | 6a955cc | 2021-10-02 14:53:48 +0200 | [diff] [blame] | 984 | function rr_chan_desc_tsc(ChannelDescription2_V cd2) |
Neels Hofmeyr | b5b7a6e | 2021-06-04 19:03:45 +0200 | [diff] [blame] | 985 | return uint3_t |
| 986 | { |
| 987 | var uint3_t tsc := oct2int(cd2.octet3); |
| 988 | tsc := tsc / 32; /* shl 5 */ |
| 989 | return tsc; |
| 990 | } |
| 991 | |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 992 | altstep as_assignment(inout AssignmentState st, RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC) runs on MSC_ConnHdlr { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 993 | var RSL_Message rsl; |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 994 | [not st.rr_ass_cmpl_seen] rsl_pt.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl { |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 995 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload); |
| 996 | log("Rx L3 from net: ", l3); |
| 997 | if (ischosen(l3.msgs.rrm.assignmentCommand)) { |
| 998 | var RslChannelNr new_chan_nr; |
| 999 | var GsmArfcn arfcn; |
Neels Hofmeyr | b5b7a6e | 2021-06-04 19:03:45 +0200 | [diff] [blame] | 1000 | |
| 1001 | if (not istemplatekind(g_pars.expect_tsc, "omit")) { |
| 1002 | var uint3_t got_tsc := rr_chan_desc_tsc(l3.msgs.rrm.assignmentCommand.descrOf1stChAfterTime); |
| 1003 | if (not match(got_tsc, g_pars.expect_tsc)) { |
| 1004 | setverdict(fail, "RR Assignment: unexpected TSC in Channel Description: expected ", |
| 1005 | g_pars.expect_tsc, " got ", got_tsc); |
| 1006 | mtc.stop; |
| 1007 | } |
| 1008 | } |
| 1009 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1010 | f_ChDesc2RslChanNr(l3.msgs.rrm.assignmentCommand.descrOf1stChAfterTime, |
| 1011 | new_chan_nr, arfcn); |
| 1012 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1013 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1014 | /* register our component for this channel number at the RSL Emulation */ |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 1015 | f_rslem_register(0, new_chan_nr, PT := rsl_proc_pt); |
Vadim Yanitskiy | 539e630 | 2020-06-22 03:11:54 +0700 | [diff] [blame] | 1016 | /* dispatch queued messages for this channel (if any) */ |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 1017 | f_rslem_dchan_queue_dispatch(PT := rsl_proc_pt); |
Vadim Yanitskiy | 539e630 | 2020-06-22 03:11:54 +0700 | [diff] [blame] | 1018 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1019 | var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_AssignmentComplete('00'O)); |
| 1020 | /* send assignment complete over the new channel */ |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 1021 | rsl_pt.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)), |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1022 | enc_PDU_ML3_MS_NW(l3_tx))); |
| 1023 | /* by default, send via the new channel from now */ |
| 1024 | st.old_chan_nr := g_chan_nr; |
| 1025 | g_chan_nr := new_chan_nr; |
| 1026 | st.rr_ass_cmpl_seen := true; |
Harald Welte | 8a9bf6f | 2018-05-10 22:00:49 +0200 | [diff] [blame] | 1027 | /* obtain channel activation from RSL_Emulation for new channel */ |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 1028 | var RSL_Message chan_act := f_rslem_get_last_act(rsl_proc_pt, 0, g_chan_nr); |
Harald Welte | 8a9bf6f | 2018-05-10 22:00:49 +0200 | [diff] [blame] | 1029 | /* check it (e.g. for correct ciphering parameters) */ |
| 1030 | f_check_chan_act(st, chan_act); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1031 | repeat; |
| 1032 | } else { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 1033 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected L3 received", l3)); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1034 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1035 | } |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 1036 | [st.rr_ass_cmpl_seen] rsl_pt.receive(tr_RSL_DEACT_SACCH(st.old_chan_nr)) { |
Neels Hofmeyr | a5302c8 | 2018-11-04 23:09:58 +0100 | [diff] [blame] | 1037 | st.old_lchan_deact_sacch_seen := true; |
Neels Hofmeyr | 861a4c1 | 2018-11-07 01:23:17 +0100 | [diff] [blame] | 1038 | repeat; |
| 1039 | } |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 1040 | [st.rr_ass_cmpl_seen] rsl_pt.receive(tr_RSL_REL_REQ(st.old_chan_nr, tr_RslLinkID_DCCH(0))) { |
Neels Hofmeyr | a5302c8 | 2018-11-04 23:09:58 +0100 | [diff] [blame] | 1041 | st.old_lchan_rll_rel_req_seen := true; |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 1042 | rsl_pt.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0)))); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1043 | repeat; |
| 1044 | } |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 1045 | [st.rr_ass_cmpl_seen] rsl_pt.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) { |
| 1046 | rsl_pt.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr)); |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 1047 | /* unregister for old channel number in RSL emulation */ |
| 1048 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 1049 | f_rslem_unregister(0, st.old_chan_nr, PT := rsl_proc_pt); |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 1050 | st.assignment_done := true; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1051 | repeat; |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | altstep as_modify(inout AssignmentState st) runs on MSC_ConnHdlr { |
| 1056 | /* no assignment, just mode modify */ |
| 1057 | var RSL_Message rsl; |
| 1058 | |
| 1059 | [st.voice_call and not st.rr_modify_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1060 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload); |
| 1061 | log("Rx L3 from net: ", l3); |
| 1062 | if (ischosen(l3.msgs.rrm.channelModeModify)) { |
Neels Hofmeyr | 559d5d0 | 2021-04-16 16:50:49 +0200 | [diff] [blame] | 1063 | st.rr_channel_mode_modify_msg := l3; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1064 | f_rsl_reply(ts_RRM_ModeModifyAck(l3.msgs.rrm.channelModeModify.channelDescription, |
| 1065 | l3.msgs.rrm.channelModeModify.channelMode), rsl); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1066 | st.rr_modify_seen := true; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1067 | } |
| 1068 | repeat; |
| 1069 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1070 | [st.voice_call and st.rr_modify_seen] RSL.receive(tr_RSL_MsgTypeD(RSL_MT_MODE_MODIFY_REQ)) -> value rsl { |
Neels Hofmeyr | 559d5d0 | 2021-04-16 16:50:49 +0200 | [diff] [blame] | 1071 | st.rsl_mode_modify_msg := rsl; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1072 | RSL.send(ts_RSL_MODE_MODIFY_ACK(g_chan_nr)); |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 1073 | st.modify_done := true; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1074 | repeat; |
| 1075 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1076 | } |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 1077 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1078 | /* Determine if given rsl_chan_nr is compatible with given BSSMAP ChannelType */ |
| 1079 | function f_channel_compatible(BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr) |
| 1080 | return boolean { |
| 1081 | select (bssmap.speechOrDataIndicator) { |
| 1082 | case ('0011'B) { /* Signalling */ |
| 1083 | /* all channels support signalling */ |
| 1084 | return true; |
| 1085 | } |
| 1086 | case else { /* Speech, Speech+CTM or CSD */ |
| 1087 | select (bssmap.channelRateAndType) { |
| 1088 | case ('08'O) { /* TCH/F */ |
| 1089 | select (rsl_chan_nr) { |
| 1090 | case (t_RslChanNr_Bm(?)) { return true; } |
| 1091 | } |
| 1092 | } |
| 1093 | case ('09'O) { /* TCH/H */ |
| 1094 | select (rsl_chan_nr) { |
| 1095 | case (t_RslChanNr_Lm(?, ?)) { return true; } |
| 1096 | } |
| 1097 | } |
| 1098 | case else { /* full or half-rate */ |
| 1099 | select (rsl_chan_nr) { |
| 1100 | case (t_RslChanNr_Bm(?)) { return true; } |
| 1101 | case (t_RslChanNr_Lm(?, ?)) { return true; } |
| 1102 | } |
| 1103 | } |
| 1104 | } |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1105 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1106 | } |
| 1107 | return false; |
| 1108 | } |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 1109 | |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 1110 | /* Determine if the channel mode specified within rsl_chan_nr requires a |
| 1111 | * MODE MODIFY in to match the channel mode specified by given BSSMAP |
| 1112 | * ChannelType */ |
Neels Hofmeyr | c2425cc | 2021-04-19 13:19:55 +0000 | [diff] [blame] | 1113 | function f_channel_needs_modify(TELNETasp_PT vty, BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr) |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 1114 | return boolean { |
| 1115 | |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 1116 | var boolean current_signalling := false; |
| 1117 | var boolean desired_signalling := false; |
| 1118 | |
| 1119 | select (rsl_chan_nr) { |
| 1120 | case (t_RslChanNr_SDCCH4(?, ?)) { current_signalling := true; } |
| 1121 | case (t_RslChanNr_SDCCH8(?, ?)) { current_signalling := true; } |
Neels Hofmeyr | c2425cc | 2021-04-19 13:19:55 +0000 | [diff] [blame] | 1122 | case (t_RslChanNr_Bm(?)) { |
| 1123 | /* TCH/F, always subslot 0 */ |
| 1124 | var charstring res := f_vty_transceive_ret(vty, "show lchan 0 0 " & int2str(rsl_chan_nr.tn) & " 0"); |
| 1125 | if (f_strstr(res, "Channel Mode / Codec: SIGNALLING", 0) >= 0) { |
| 1126 | current_signalling := true; |
| 1127 | } |
| 1128 | } |
| 1129 | case (t_RslChanNr_Lm(?, ?)) { |
| 1130 | /* TCH/H */ |
| 1131 | var charstring res := f_vty_transceive_ret(vty, "show lchan 0 0 " & int2str(rsl_chan_nr.tn) |
| 1132 | & " " & int2str(rsl_chan_nr.u.lm.sub_chan)); |
| 1133 | if (f_strstr(res, "Channel Mode / Codec: SIGNALLING", 0) >= 0) { |
| 1134 | current_signalling := true; |
| 1135 | } |
| 1136 | } |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | if (bssmap.speechOrDataIndicator == '0011'B) { |
| 1140 | desired_signalling := true; |
| 1141 | } |
| 1142 | |
| 1143 | if (current_signalling == desired_signalling) { |
| 1144 | /* The desired channel mode is equal to the one we currently |
| 1145 | * have, there is no mode modification needed or expected */ |
| 1146 | return false; |
| 1147 | } else { |
| 1148 | /* The desired channel mode and the current channel mode do |
| 1149 | * not match. A mode modification is required */ |
| 1150 | return true; |
| 1151 | } |
| 1152 | } |
| 1153 | |
Harald Welte | cc0b014 | 2018-05-29 15:19:33 +0200 | [diff] [blame] | 1154 | /* patch an BSSMAP ASS REQ with LCLS related IEs, depending on g_params */ |
| 1155 | function f_ass_patch_lcls(inout template (omit) PDU_BSSAP ass_tpl, |
| 1156 | inout template PDU_BSSAP ass_cpl) runs on MSC_ConnHdlr { |
| 1157 | if (istemplatekind(ass_tpl, "omit")) { |
| 1158 | return; |
| 1159 | } |
| 1160 | if (ispresent(g_pars.lcls.gcr)) { |
| 1161 | ass_tpl.pdu.bssmap.assignmentRequest.globalCallReference := ts_BSSMAP_IE_GCR(g_pars.lcls.gcr); |
| 1162 | } |
| 1163 | if (ispresent(g_pars.lcls.cfg)) { |
| 1164 | ass_tpl.pdu.bssmap.assignmentRequest.lCLS_Configuration := ts_BSSMAP_IE_LclsCfg(g_pars.lcls.cfg); |
| 1165 | } |
| 1166 | if (ispresent(g_pars.lcls.csc)) { |
| 1167 | ass_tpl.pdu.bssmap.assignmentRequest.lCLS_ConnectionStatusControl := ts_BSSMAP_IE_LclsCsc(g_pars.lcls.csc); |
| 1168 | } |
Harald Welte | 343b774 | 2018-06-05 23:41:37 +0200 | [diff] [blame] | 1169 | if (ischosen(ass_cpl.pdu.bssmap.assignmentComplete)) { |
| 1170 | if (ispresent(g_pars.lcls.exp_sts)) { |
| 1171 | ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status := tr_BSSMAP_IE_LclsSts(g_pars.lcls.exp_sts); |
| 1172 | } else { |
| 1173 | ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status := omit; |
| 1174 | } |
Harald Welte | cc0b014 | 2018-05-29 15:19:33 +0200 | [diff] [blame] | 1175 | } |
| 1176 | } |
| 1177 | |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 1178 | /* Send a MGCP request through MGCP-over-IPA from MSC side and receive a (matching!) response */ |
| 1179 | function mgcp_transceive_mgw(template MgcpCommand cmd, template MgcpResponse resp := ?) runs on MSC_ConnHdlr { |
| 1180 | template MgcpResponse resp_any := ? |
| 1181 | var MgcpResponse resp_val; |
| 1182 | resp.line.trans_id := cmd.line.trans_id; |
| 1183 | timer T := 5.0; |
| 1184 | |
| 1185 | BSSAP.send(cmd); |
| 1186 | T.start; |
| 1187 | alt { |
| 1188 | [] as_Media_mgw(); |
| 1189 | [] BSSAP.receive(resp) -> value resp_val { } |
| 1190 | [] BSSAP.receive(resp_any) { |
| 1191 | setverdict(fail, "Response didn't match template"); |
| 1192 | mtc.stop; |
| 1193 | } |
| 1194 | [] BSSAP.receive { repeat; } |
| 1195 | [] T.timeout { |
| 1196 | setverdict(fail, "Timeout waiting for response to ", cmd); |
| 1197 | mtc.stop; |
| 1198 | } |
| 1199 | } |
| 1200 | T.stop; |
| 1201 | } |
| 1202 | |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 1203 | /* Helper function to check if the activity on the MGCP matches what we |
| 1204 | * expected */ |
| 1205 | function f_check_mgcp_expectations() runs on MSC_ConnHdlr { |
| 1206 | for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) { |
Philipp Maier | 0a5d7e7 | 2018-07-16 15:13:11 +0200 | [diff] [blame] | 1207 | log(testcasename(), ": Check MGCP test expectations for g_media.mgcp_conn[", i , "]:", |
| 1208 | " crcx_seen=", g_media.mgcp_conn[i].crcx_seen, ", crcx_seen_exp=", g_media.mgcp_conn[i].crcx_seen_exp, |
| 1209 | ", mdcx_seen=", g_media.mgcp_conn[i].mdcx_seen, ", mdcx_seen_exp=", g_media.mgcp_conn[i].mdcx_seen_exp); |
| 1210 | |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 1211 | if(g_media.mgcp_conn[i].crcx_seen != g_media.mgcp_conn[i].crcx_seen_exp) { |
Max | 4b0f496 | 2018-11-06 19:20:24 +0100 | [diff] [blame] | 1212 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unexpected number of MGW-CRCX transactions on g_media.mgcp_conn[" & int2str(i) & "]"); |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 1213 | } |
| 1214 | if(g_media.mgcp_conn[i].mdcx_seen != g_media.mgcp_conn[i].mdcx_seen_exp) { |
Max | 4b0f496 | 2018-11-06 19:20:24 +0100 | [diff] [blame] | 1215 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "unexpected number of MGW-MDCX transactions on g_media.mgcp_conn[" & int2str(i) & "]"); |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 1216 | } |
| 1217 | } |
| 1218 | } |
| 1219 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1220 | /* establish a channel fully, expecting an assignment matching 'exp' */ |
Harald Welte | 7a14fd5 | 2018-05-10 22:26:55 +0200 | [diff] [blame] | 1221 | function f_establish_fully(template (omit) PDU_BSSAP ass_tpl, template PDU_BSSAP exp_ass_cpl) |
| 1222 | runs on MSC_ConnHdlr { |
Philipp Maier | 11a5894 | 2018-06-25 16:40:48 +0200 | [diff] [blame] | 1223 | |
| 1224 | var BSSMAP_FIELD_CodecType codecType; |
Philipp Maier | 48aeeec | 2018-09-14 18:20:04 +0200 | [diff] [blame] | 1225 | timer T := 10.0; |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 1226 | |
Philipp Maier | 4ce978c | 2020-08-11 22:54:07 +0200 | [diff] [blame] | 1227 | if (not istemplatekind(ass_tpl, "omit") and isvalue(ass_tpl.pdu.bssmap.assignmentRequest.codecList)) { |
Philipp Maier | 11a5894 | 2018-06-25 16:40:48 +0200 | [diff] [blame] | 1228 | codecType := valueof(ass_tpl.pdu.bssmap.assignmentRequest.codecList.codecElements[0].codecType); |
| 1229 | } else { |
| 1230 | /* Make sure a meaningful default is assigned in case the |
| 1231 | * codecList is not populated */ |
| 1232 | codecType := FR_AMR; |
| 1233 | } |
| 1234 | |
Pau Espin Pedrol | 0786663 | 2020-09-03 19:10:55 +0200 | [diff] [blame] | 1235 | f_MscConnHdlr_init(g_pars.media_nr, host_bts, host_mgw_mgcp, codecType); |
Harald Welte | 7a14fd5 | 2018-05-10 22:26:55 +0200 | [diff] [blame] | 1236 | |
Harald Welte | cc0b014 | 2018-05-29 15:19:33 +0200 | [diff] [blame] | 1237 | /* patch in the LCLS related items, as needed */ |
| 1238 | f_ass_patch_lcls(ass_tpl, exp_ass_cpl); |
| 1239 | |
Harald Welte | 7a14fd5 | 2018-05-10 22:26:55 +0200 | [diff] [blame] | 1240 | f_create_chan_and_exp(); |
Harald Welte | 7a14fd5 | 2018-05-10 22:26:55 +0200 | [diff] [blame] | 1241 | |
| 1242 | /* start ciphering, if requested */ |
| 1243 | if (ispresent(g_pars.encr)) { |
Neels Hofmeyr | 6c388f2 | 2021-06-11 02:36:56 +0200 | [diff] [blame] | 1244 | f_cipher_mode(g_pars.encr); |
Harald Welte | 7a14fd5 | 2018-05-10 22:26:55 +0200 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | /* bail out early if no assignment requested */ |
| 1248 | if (istemplatekind(ass_tpl, "omit")) { |
| 1249 | return; |
| 1250 | } |
| 1251 | |
| 1252 | var PDU_BSSAP ass_cmd := valueof(ass_tpl); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1253 | var PDU_BSSAP bssap; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1254 | var boolean exp_compl := ischosen(exp_ass_cpl.pdu.bssmap.assignmentComplete); |
Philipp Maier | 86f3920 | 2018-02-07 14:40:09 +0100 | [diff] [blame] | 1255 | var boolean exp_fail := ischosen(exp_ass_cpl.pdu.bssmap.assignmentFailure); |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 1256 | var boolean exp_modify; |
Philipp Maier | 48aeeec | 2018-09-14 18:20:04 +0200 | [diff] [blame] | 1257 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1258 | var ExpectCriteria mgcpcrit := { |
| 1259 | connid := omit, |
| 1260 | endpoint := omit, |
| 1261 | transid := omit |
| 1262 | }; |
| 1263 | var AssignmentState st := valueof(ts_AssignmentStateInit); |
| 1264 | /* if the channel type is SIGNAL, we're not handling a voice call */ |
| 1265 | if (ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechOrDataIndicator != '0011'B) { |
| 1266 | st.voice_call := true; |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 1267 | exp_modify := true; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1268 | } |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 1269 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1270 | /* determine if the current channel can support the given service or not */ |
| 1271 | if (not f_channel_compatible(ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr)) { |
| 1272 | st.is_assignment := true; |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 1273 | |
| 1274 | /* We decided to assign a new channel, so we do not expect |
| 1275 | * any mode modify messages on RSL */ |
| 1276 | exp_modify := false; |
| 1277 | } else { |
| 1278 | /* We will continue working with the currently assigned |
| 1279 | * channel, we must now check if the mode of the current |
| 1280 | * channel is compatible. If not we expect the BSC to modify |
| 1281 | * the mode */ |
Neels Hofmeyr | 559d5d0 | 2021-04-16 16:50:49 +0200 | [diff] [blame] | 1282 | st.is_assignment := false; |
Neels Hofmeyr | c2425cc | 2021-04-19 13:19:55 +0000 | [diff] [blame] | 1283 | exp_modify := f_channel_needs_modify(BSCVTY, ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1284 | } |
| 1285 | |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 1286 | /* Some test situations will involve MGCP transactions on a media |
| 1287 | * gateway. Depending on the situation, we set up how many of each MGCP |
| 1288 | * message type are expected to be exchanged. */ |
| 1289 | if (isbound(exp_ass_cpl.pdu.bssmap.assignmentFailure)) { |
| 1290 | /* For tests that expect the assignment to fail, assume that |
| 1291 | * there will be no MGW communication as well. */ |
| 1292 | g_media.mgcp_conn[0].crcx_seen_exp := 0; |
| 1293 | g_media.mgcp_conn[0].mdcx_seen_exp := 0; |
| 1294 | g_media.mgcp_conn[1].crcx_seen_exp := 0; |
| 1295 | g_media.mgcp_conn[1].mdcx_seen_exp := 0; |
| 1296 | } else if (st.voice_call) { |
| 1297 | /* For voice calls we expect the following MGCP activity */ |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 1298 | g_media.mgcp_conn[0].crcx_seen_exp := 1; |
| 1299 | g_media.mgcp_conn[0].mdcx_seen_exp := 1; |
| 1300 | g_media.mgcp_conn[1].crcx_seen_exp := 1; |
| 1301 | g_media.mgcp_conn[1].mdcx_seen_exp := 0; |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 1302 | } |
| 1303 | |
Vadim Yanitskiy | 539e630 | 2020-06-22 03:11:54 +0700 | [diff] [blame] | 1304 | /* On receipt of the BSSAP Assignment Command, the IUT (osmo-bsc) will allocate |
| 1305 | * a channel and send us RR Assignment Command together with ip.access CRCX. |
| 1306 | * There is a risk that the RSL Emulation component would dequeue and process |
| 1307 | * ip.access CRCX faster than we process the Assignment Command and register |
| 1308 | * the corresponding handler for the indicated RSL channel number. This would |
| 1309 | * result in a failure, because at that moment there will be no handler for |
| 1310 | * ip.access CRCX. Let's guard against this and enable additional queueing. */ |
| 1311 | f_rslem_dchan_queue_enable(); |
| 1312 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1313 | f_create_mgcp_expect(mgcpcrit); |
| 1314 | BSSAP.send(ass_cmd); |
| 1315 | |
| 1316 | T.start; |
| 1317 | alt { |
| 1318 | /* assignment related bits */ |
| 1319 | [st.is_assignment] as_assignment(st); |
| 1320 | |
| 1321 | /* modify related bits */ |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 1322 | [not st.is_assignment and exp_modify] as_modify(st); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1323 | |
| 1324 | /* voice call related bits (IPA CRCX/MDCX + MGCP) */ |
| 1325 | [st.voice_call] as_Media(); |
| 1326 | |
| 1327 | /* if we receive exactly what we expected, always return + pass */ |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 1328 | [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 Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1329 | setverdict(pass); |
| 1330 | } |
Philipp Maier | 86f3920 | 2018-02-07 14:40:09 +0100 | [diff] [blame] | 1331 | [exp_fail] BSSAP.receive(exp_ass_cpl) -> value bssap { |
| 1332 | setverdict(pass); |
| 1333 | } |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 1334 | [(st.is_assignment and st.assignment_done or |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 1335 | (not st.is_assignment and (st.modify_done or not exp_modify))) and |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 1336 | exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 1337 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching ASSIGNMENT COMPLETE"); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1338 | } |
| 1339 | [exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 1340 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected ASSIGNMENT FAIL"); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1341 | } |
| 1342 | [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 1343 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received unexpected ASSIGNMENT COMPLETE"); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1344 | } |
| 1345 | [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 1346 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Received non-matching ASSIGNMENT FAIL"); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1347 | } |
| 1348 | [] T.timeout { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 1349 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Timeout waiting for ASSIGNMENT COMPLETE"); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1350 | } |
| 1351 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1352 | log("g_media ", g_media); |
| 1353 | if (not isbound(bssap)) { |
Daniel Willmann | afce866 | 2018-07-06 23:11:32 +0200 | [diff] [blame] | 1354 | mtc.stop; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 1355 | } |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 1356 | |
Neels Hofmeyr | 559d5d0 | 2021-04-16 16:50:49 +0200 | [diff] [blame] | 1357 | if (exp_modify) { |
| 1358 | /* Verify that the RR Channel Mode Modify and RSL MODE MODIFY message asked for the expected channel |
| 1359 | * mode. */ |
| 1360 | /* TODO: more precisely expect the different types of speech? */ |
| 1361 | var OCT1 rr_channel_mode := st.rr_channel_mode_modify_msg.msgs.rrm.channelModeModify.channelMode.mode; |
| 1362 | |
| 1363 | if (st.voice_call and rr_channel_mode == '00'O) { |
| 1364 | setverdict(fail, "f_establish_fully(): Expected RR Channel Mode Modify", |
| 1365 | " to a speech mode, but got channelMode == ", rr_channel_mode); |
| 1366 | mtc.stop; |
| 1367 | } else if (not st.voice_call and rr_channel_mode != '00'O) { |
| 1368 | setverdict(fail, "f_establish_fully(): Expected RR Channel Mode Modify", |
| 1369 | " to signalling mode, but got channelMode == ", rr_channel_mode); |
| 1370 | mtc.stop; |
| 1371 | } |
| 1372 | |
| 1373 | var RSL_IE_Body chan_mode_ie; |
| 1374 | if (not f_rsl_find_ie(st.rsl_mode_modify_msg, RSL_IE_CHAN_MODE, chan_mode_ie)) { |
| 1375 | setverdict(fail, "RSL MODE MODIFY message lacks a Channel Mode IE"); |
| 1376 | mtc.stop; |
| 1377 | } |
| 1378 | var RSL_SpeechDataInd rsl_spd_ind := chan_mode_ie.chan_mode.spd_ind; |
| 1379 | if (st.voice_call and rsl_spd_ind != RSL_SPDI_SPEECH) { |
| 1380 | setverdict(fail, "f_establish_fully(): Expected RSL MODE MODIFY", |
| 1381 | " to a speech mode, but got spd_ind == ", rsl_spd_ind); |
| 1382 | mtc.stop; |
| 1383 | } else if (not st.voice_call and rsl_spd_ind != RSL_SPDI_SIGN) { |
| 1384 | setverdict(fail, "f_establish_fully(): Expected RSL MODE MODIFY", |
| 1385 | " to signalling mode, but got spd_ind == ", rsl_spd_ind); |
| 1386 | mtc.stop; |
| 1387 | } |
Neels Hofmeyr | b5b7a6e | 2021-06-04 19:03:45 +0200 | [diff] [blame] | 1388 | |
| 1389 | if (not istemplatekind(g_pars.expect_tsc, "omit")) { |
| 1390 | var uint3_t got_tsc := rr_chan_desc_tsc(st.rr_channel_mode_modify_msg.msgs.rrm.channelModeModify.channelDescription); |
| 1391 | if (not match(got_tsc, g_pars.expect_tsc)) { |
| 1392 | setverdict(fail, "RR Channel Mode Modify: unexpected TSC in Channel Description: expected ", |
| 1393 | g_pars.expect_tsc, " got ", got_tsc); |
| 1394 | mtc.stop; |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | } else { |
| 1399 | /* not exp_modify, so this did a Channel Activate */ |
| 1400 | |
| 1401 | /* Check the TSC */ |
| 1402 | if (not istemplatekind(g_pars.expect_tsc, "omit")) { |
| 1403 | var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr); |
| 1404 | var RSL_IE_Body ie; |
| 1405 | if (f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, ie)) { |
| 1406 | var uint3_t got_tsc := ie.chan_ident.ch_desc.v.tsc; |
| 1407 | if (not match(got_tsc, g_pars.expect_tsc)) { |
| 1408 | setverdict(fail, "RSL CHANnel ACTIVation: unexpected TSC in Channel Description: expected ", |
| 1409 | g_pars.expect_tsc, " got ", got_tsc); |
| 1410 | mtc.stop; |
| 1411 | } |
| 1412 | } |
| 1413 | } |
Neels Hofmeyr | 559d5d0 | 2021-04-16 16:50:49 +0200 | [diff] [blame] | 1414 | } |
| 1415 | |
Philipp Maier | a0976e9 | 2018-07-16 15:19:42 +0200 | [diff] [blame] | 1416 | /* When the BSC detects that LCLS is possible it will cross the |
| 1417 | * connetions that point to the PBX side of the MGW. In our case this |
| 1418 | * is mgcp_conn[1]. The BSC performs this operation already before the |
| 1419 | * assignment complete is generated. This means we expect another MDCX |
| 1420 | * at mgcp_conn[1] when LCLS is expected. */ |
Max | 2eeb511 | 2018-11-06 19:21:41 +0100 | [diff] [blame] | 1421 | if (g_pars.lcls.adjust_cx_exp and ispresent(exp_ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status.lCLS_BSS_StatusValue)) { |
Philipp Maier | a0976e9 | 2018-07-16 15:19:42 +0200 | [diff] [blame] | 1422 | if (valueof(exp_ass_cpl.pdu.bssmap.assignmentComplete.lCLS_BSS_Status.lCLS_BSS_StatusValue) == LCLS_STS_locally_switched) { |
| 1423 | g_media.mgcp_conn[1].mdcx_seen_exp := g_media.mgcp_conn[1].mdcx_seen_exp + 1; |
| 1424 | |
| 1425 | } |
| 1426 | } |
| 1427 | |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 1428 | if (not exp_fail and st.voice_call and not g_pars.aoip) { |
| 1429 | /* With SCCPLite, connect to BSC-located MGW using a CRCX + SDP. |
| 1430 | It is sent in MGCP over IPA in the BSC<->MSC (BSC-NAT) |
| 1431 | connection. BSC will forward it to its MGW. */ |
| 1432 | var template MgcpCommand cmd; |
| 1433 | var template MgcpResponse resp; |
| 1434 | var integer cic := f_bssmap_ie_cic_2_int(ass_cmd.pdu.bssmap.assignmentRequest.circuitIdentityCode); |
| 1435 | var MgcpEndpoint ep := int2str(cic) & "@mgw"; /* 1: matches value configured in BSC_Tests.ttcn pass in AssignReq */ |
| 1436 | var MgcpCallId call_id := '51234'H; |
| 1437 | var SDP_attribute_list attributes := { valueof(ts_SDP_ptime(20)) }; |
| 1438 | if (g_pars.use_osmux) { |
| 1439 | cmd := ts_CRCX_osmux(get_next_trans_id(), ep, "sendrecv", call_id, cic); |
| 1440 | resp := tr_CRCX_ACK_osmux; |
| 1441 | } else { |
| 1442 | cmd := ts_CRCX(get_next_trans_id(), ep, "sendrecv", call_id); |
| 1443 | resp := tr_CRCX_ACK; |
| 1444 | } |
Pau Espin Pedrol | 0786663 | 2020-09-03 19:10:55 +0200 | [diff] [blame] | 1445 | cmd.sdp := ts_SDP(host_msc, host_mgw_rtp_v4, "23", "42", |
Pau Espin Pedrol | fd02ad4 | 2019-06-18 17:45:20 +0200 | [diff] [blame] | 1446 | 14000, { int2str(g_media.mgcp_conn[1].rtp_pt) }, |
| 1447 | { valueof(ts_SDP_ptime(20)) }); |
| 1448 | mgcp_transceive_mgw(cmd, resp); |
| 1449 | } |
| 1450 | |
Philipp Maier | 3e2af5d | 2018-07-11 17:01:05 +0200 | [diff] [blame] | 1451 | f_check_mgcp_expectations(); |
Neels Hofmeyr | a5302c8 | 2018-11-04 23:09:58 +0100 | [diff] [blame] | 1452 | |
| 1453 | if (st.is_assignment and st.assignment_done) { |
| 1454 | if (not st.old_lchan_deact_sacch_seen) { |
| 1455 | setverdict(fail, "f_establish_fully(): Assignment completed, but the old lchan was not", |
| 1456 | " released properly: expected a Deact SACCH on the old lchan, but saw none."); |
| 1457 | } |
| 1458 | if (st.old_lchan_rll_rel_req_seen) { |
| 1459 | setverdict(fail, "f_establish_fully(): Assignment completed, but the old lchan was not", |
| 1460 | " released properly: saw an RLL Release on the old lchan, but expecting none."); |
| 1461 | } |
| 1462 | } |
Neels Hofmeyr | 9d68630 | 2021-04-25 19:02:29 +0000 | [diff] [blame] | 1463 | |
| 1464 | var charstring lchan_info := f_vty_transceive_ret(BSCVTY, "show lchan 0 0 " & int2str(g_chan_nr.tn) & " 0"); |
| 1465 | if (f_strstr(lchan_info, "State: ESTABLISHED") < 0) { |
| 1466 | log("after f_establish_fully(), 'show lchan' replied: ", lchan_info); |
| 1467 | setverdict(fail, "lchan is not in state ESTABLISHED"); |
| 1468 | mtc.stop; |
| 1469 | } |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 1470 | } |
| 1471 | |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 1472 | type record HandoverState { |
| 1473 | /* Assignment related bits */ |
| 1474 | boolean rr_ho_cmpl_seen, |
Philipp Maier | c1e95c8 | 2018-07-18 16:03:00 +0200 | [diff] [blame] | 1475 | integer mdcx_seen_before_ho, |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 1476 | boolean handover_done, |
Neels Hofmeyr | c741fcb | 2021-10-02 14:52:28 +0200 | [diff] [blame] | 1477 | RslChannelNr old_chan_nr, |
| 1478 | uint3_t expect_target_tsc optional |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 1479 | }; |
| 1480 | |
| 1481 | altstep as_handover(inout HandoverState st) runs on MSC_ConnHdlr { |
| 1482 | var RSL_Message rsl; |
| 1483 | [not st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl { |
| 1484 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload); |
| 1485 | log("Rx L3 from net: ", l3); |
| 1486 | if (ischosen(l3.msgs.rrm.handoverCommand)) { |
| 1487 | var RslChannelNr new_chan_nr; |
| 1488 | var GsmArfcn arfcn; |
| 1489 | f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2, |
| 1490 | new_chan_nr, arfcn); |
| 1491 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
| 1492 | |
Neels Hofmeyr | c741fcb | 2021-10-02 14:52:28 +0200 | [diff] [blame] | 1493 | /* Verify correct TSC in handoverCommand */ |
| 1494 | if (ispresent(st.expect_target_tsc)) { |
| 1495 | var uint3_t got_tsc := rr_chan_desc_tsc(l3.msgs.rrm.handoverCommand.channelDescription2); |
| 1496 | if (not match(got_tsc, st.expect_target_tsc)) { |
| 1497 | setverdict(fail, "RR Handover Command: unexpected TSC in Channel Description: expected ", |
| 1498 | st.expect_target_tsc, " got ", got_tsc); |
| 1499 | mtc.stop; |
| 1500 | } else { |
| 1501 | log("handoverCommand: verified TSC = ", got_tsc, " (matches ", |
| 1502 | st.expect_target_tsc, ")"); |
| 1503 | } |
| 1504 | } |
| 1505 | |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 1506 | /* register our component for this channel number at the RSL Emulation */ |
| 1507 | f_rslem_register(0, new_chan_nr, RSL1_PROC); |
| 1508 | |
| 1509 | /* resume processing of RSL DChan messages, which was temporarily suspended |
| 1510 | * before performing a hand-over */ |
| 1511 | f_rslem_resume(RSL1_PROC); |
| 1512 | |
Neels Hofmeyr | 378a49c | 2018-06-15 22:18:43 +0200 | [diff] [blame] | 1513 | /* send handover detect */ |
| 1514 | RSL1.send(ts_RSL_HANDO_DET(new_chan_nr)); |
| 1515 | f_sleep(0.3); |
| 1516 | |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 1517 | /* send handover complete over the new channel */ |
| 1518 | var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O)); |
Neels Hofmeyr | d07ee13 | 2018-07-14 22:28:29 +0200 | [diff] [blame] | 1519 | RSL1.send(ts_RSL_EST_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)), |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 1520 | enc_PDU_ML3_MS_NW(l3_tx))); |
| 1521 | /* by default, send via the new channel from now */ |
| 1522 | st.old_chan_nr := g_chan_nr; |
| 1523 | g_chan_nr := new_chan_nr; |
| 1524 | st.rr_ho_cmpl_seen := true; |
Philipp Maier | c1e95c8 | 2018-07-18 16:03:00 +0200 | [diff] [blame] | 1525 | |
| 1526 | /* Memorize how many MDCX we have seen before. We need this number to detect |
| 1527 | * that we have received the handover related MDCX */ |
| 1528 | st.mdcx_seen_before_ho := g_media.mgcp_conn[0].mdcx_seen; |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 1529 | repeat; |
| 1530 | } else { |
Daniel Willmann | 0c9e3fa | 2018-10-29 15:55:12 +0100 | [diff] [blame] | 1531 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected L3 received", l3)); |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 1532 | } |
| 1533 | } |
Philipp Maier | c1e95c8 | 2018-07-18 16:03:00 +0200 | [diff] [blame] | 1534 | [st.rr_ho_cmpl_seen] as_Media_ipacc(); |
Philipp Maier | 09f1c6d | 2020-09-14 21:28:52 +0200 | [diff] [blame] | 1535 | [st.rr_ho_cmpl_seen] as_Media_mgw(); |
Neels Hofmeyr | 861a4c1 | 2018-11-07 01:23:17 +0100 | [diff] [blame] | 1536 | [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_DEACT_SACCH(st.old_chan_nr)) { |
| 1537 | repeat; |
| 1538 | } |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 1539 | [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_REL_REQ(st.old_chan_nr, tr_RslLinkID_DCCH(0))) { |
| 1540 | RSL.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0)))); |
| 1541 | repeat; |
| 1542 | } |
| 1543 | [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) { |
| 1544 | RSL.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr)); |
| 1545 | /* unregister for old channel number in RSL emulation */ |
| 1546 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
| 1547 | f_rslem_unregister(0, st.old_chan_nr); |
Philipp Maier | c1e95c8 | 2018-07-18 16:03:00 +0200 | [diff] [blame] | 1548 | |
| 1549 | /* The channel release must not necessarly be synchronized to the RSL handover |
| 1550 | * procedure since those events may happen independently nearly at the same |
| 1551 | * time. When we receive the RSL_RF_CHAN_REL command the media negotiation on |
| 1552 | * IPACC or MGCP level may be still in progress. In order to make sure that |
| 1553 | * we do only stop when we have seen an MDCX on MGCP level and another a CRCX |
Neels Hofmeyr | ffd2ef1 | 2020-10-12 18:45:58 +0000 | [diff] [blame] | 1554 | * as well as an MDCX on IPACC level. |
| 1555 | * If ipa_crcx_seen is false, this is not a voice channel and we need not check MGCP at all.. */ |
| 1556 | if (g_media.bts.ipa_crcx_seen |
| 1557 | and (g_media.mgcp_conn[0].mdcx_seen <= st.mdcx_seen_before_ho or |
| 1558 | g_media.bts1.ipa_mdcx_seen == false or g_media.bts1.ipa_crcx_seen == false)) { |
Philipp Maier | c1e95c8 | 2018-07-18 16:03:00 +0200 | [diff] [blame] | 1559 | repeat; |
| 1560 | } else { |
| 1561 | st.handover_done := true; |
| 1562 | } |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 1563 | } |
| 1564 | } |
| 1565 | |
| 1566 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 1567 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 1568 | } |