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