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