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