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