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