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 | |
| 35 | /* Tuple containing host/ip and port */ |
| 36 | type record HostPort { |
| 37 | HostName host, |
| 38 | PortNumber port_nr |
| 39 | }; |
| 40 | |
| 41 | /* State encapsulating one MGCP Connection */ |
| 42 | type record MgcpConnState { |
| 43 | boolean crcx_seen, |
| 44 | MgcpConnectionId conn_id, |
| 45 | charstring mime_type, /* e.g. AMR */ |
| 46 | integer sample_rate, /* 8000 */ |
| 47 | integer ptime, /* 20 */ |
| 48 | uint7_t rtp_pt, /* RTP Payload Type */ |
| 49 | HostPort mgw, /* MGW side */ |
| 50 | HostPort peer /* CA side */ |
| 51 | }; |
| 52 | |
| 53 | /* BTS media state */ |
| 54 | type record BtsMediaState { |
| 55 | boolean ipa_crcx_seen, |
| 56 | uint16_t conn_id, |
| 57 | uint7_t rtp_pt, |
| 58 | HostPort bts, |
| 59 | HostPort peer |
| 60 | }; |
| 61 | |
| 62 | type record MediaState { |
| 63 | MgcpEndpoint mgcp_ep, |
| 64 | MgcpConnState mgcp_conn[2], |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 65 | BtsMediaState bts, |
| 66 | BtsMediaState bts1 /* only during hand-over */ |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | function f_MediaState_init(inout MediaState g_media, integer nr, HostName bts, HostName mgw) { |
| 70 | /* BTS Side */ |
| 71 | g_media.bts := { |
| 72 | ipa_crcx_seen := false, |
| 73 | conn_id := nr, |
| 74 | rtp_pt := 0, |
| 75 | bts := { |
| 76 | host := bts, |
| 77 | port_nr := 9000 + nr*2 |
| 78 | }, |
| 79 | peer := - |
| 80 | } |
| 81 | |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 82 | g_media.bts1 := { |
| 83 | ipa_crcx_seen := false, |
| 84 | conn_id := nr, |
| 85 | rtp_pt := 0, |
| 86 | bts := { |
| 87 | host := bts, /* FIXME */ |
| 88 | port_nr := 9000 + nr*2 |
| 89 | }, |
| 90 | peer := - |
| 91 | } |
| 92 | |
Harald Welte | 363cb0a | 2018-01-30 19:35:53 +0100 | [diff] [blame] | 93 | g_media.mgcp_ep := "rtpbridge/" & int2str(nr) & "@mgw"; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 94 | |
| 95 | for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) { |
| 96 | g_media.mgcp_conn[i].mime_type := "AMR"; |
| 97 | g_media.mgcp_conn[i].sample_rate := 8000; |
| 98 | g_media.mgcp_conn[i].ptime := 20; |
| 99 | g_media.mgcp_conn[i].rtp_pt := 98; |
| 100 | g_media.mgcp_conn[i].crcx_seen := false; |
| 101 | g_media.mgcp_conn[i].conn_id := f_mgcp_alloc_conn_id(); |
| 102 | } |
| 103 | |
| 104 | g_media.mgcp_conn[0].mgw := { |
| 105 | host := mgw, |
| 106 | port_nr := 10000 + nr*2 |
| 107 | } |
| 108 | g_media.mgcp_conn[1].mgw := { |
| 109 | host := mgw, |
| 110 | port_nr := 11000 + nr*2 |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | private function f_get_free_mgcp_conn() runs on MSC_ConnHdlr return integer { |
| 115 | for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) { |
| 116 | if (not g_media.mgcp_conn[i].crcx_seen) { |
| 117 | return i; |
| 118 | } |
| 119 | } |
| 120 | setverdict(fail, "Only 2 Connections per EP!"); |
| 121 | self.stop; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | private function f_get_mgcp_conn(MgcpConnectionId cid) runs on MSC_ConnHdlr return integer { |
| 125 | for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) { |
| 126 | if (g_media.mgcp_conn[i].conn_id == cid and g_media.mgcp_conn[i].crcx_seen) { |
| 127 | return i; |
| 128 | } |
| 129 | } |
| 130 | setverdict(fail, "No Connection for ID ", cid); |
| 131 | self.stop; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | |
| 135 | /* altstep for handling of IPA + MGCP media related commands. Can be activated by a given |
| 136 | * test case if it expects to see media related handling (i.e. voice calls */ |
| 137 | altstep as_Media() runs on MSC_ConnHdlr { |
| 138 | var RSL_Message rsl; |
| 139 | var MgcpCommand mgcp_cmd; |
| 140 | var RSL_IE_Body ie; |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 141 | var boolean b_unused; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 142 | [not g_media.bts.ipa_crcx_seen] RSL.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl { |
| 143 | /* Extract parameters from request + use in response */ |
| 144 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 145 | g_media.bts.rtp_pt := ie.ipa_rtp_pt; |
| 146 | } |
| 147 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 148 | g_media.bts.rtp_pt := ie.ipa_rtp_pt2; |
| 149 | } |
| 150 | RSL.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts.conn_id, |
| 151 | oct2int(f_inet_addr(g_media.bts.bts.host)), |
| 152 | g_media.bts.bts.port_nr, |
| 153 | g_media.bts.rtp_pt)); |
| 154 | g_media.bts.ipa_crcx_seen := true; |
| 155 | repeat; |
| 156 | } |
| 157 | [g_media.bts.ipa_crcx_seen] RSL.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{ |
| 158 | /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */ |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 159 | 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] | 160 | if (g_media.bts.conn_id != ie.ipa_conn_id) { |
| 161 | setverdict(fail, "IPA MDCX for unknown ConnId", rsl); |
| 162 | self.stop; |
| 163 | } |
| 164 | /* mandatory */ |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 165 | 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] | 166 | 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] | 167 | 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] | 168 | g_media.bts.peer.port_nr := ie.ipa_remote_port; |
| 169 | /* optional */ |
| 170 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 171 | g_media.bts.rtp_pt := ie.ipa_rtp_pt; |
| 172 | } |
| 173 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 174 | g_media.bts.rtp_pt := ie.ipa_rtp_pt2; |
| 175 | } |
| 176 | RSL.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts.conn_id, |
| 177 | oct2int(f_inet_addr(g_media.bts.peer.host)), |
| 178 | g_media.bts.peer.port_nr, |
| 179 | g_media.bts.rtp_pt)); |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 180 | //g_media.bts.ipa_mdcx_seen := true; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 181 | repeat; |
| 182 | } |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 183 | |
| 184 | /* on second (new) BTS during hand-over */ |
| 185 | [not g_media.bts1.ipa_crcx_seen] RSL1.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl { |
| 186 | /* Extract parameters from request + use in response */ |
| 187 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 188 | g_media.bts1.rtp_pt := ie.ipa_rtp_pt; |
| 189 | } |
| 190 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 191 | g_media.bts1.rtp_pt := ie.ipa_rtp_pt2; |
| 192 | } |
| 193 | RSL1.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts1.conn_id, |
| 194 | oct2int(f_inet_addr(g_media.bts1.bts.host)), |
| 195 | g_media.bts1.bts.port_nr, |
| 196 | g_media.bts1.rtp_pt)); |
| 197 | g_media.bts1.ipa_crcx_seen := true; |
| 198 | repeat; |
| 199 | } |
| 200 | /* on second (new) BTS during hand-over */ |
| 201 | [g_media.bts1.ipa_crcx_seen] RSL1.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{ |
| 202 | /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */ |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 203 | b_unused := f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie); |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 204 | if (g_media.bts1.conn_id != ie.ipa_conn_id) { |
| 205 | setverdict(fail, "IPA MDCX for unknown ConnId", rsl); |
| 206 | self.stop; |
| 207 | } |
| 208 | /* mandatory */ |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 209 | 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] | 210 | 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] | 211 | 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] | 212 | g_media.bts1.peer.port_nr := ie.ipa_remote_port; |
| 213 | /* optional */ |
| 214 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 215 | g_media.bts1.rtp_pt := ie.ipa_rtp_pt; |
| 216 | } |
| 217 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 218 | g_media.bts1.rtp_pt := ie.ipa_rtp_pt2; |
| 219 | } |
| 220 | RSL1.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts1.conn_id, |
| 221 | oct2int(f_inet_addr(g_media.bts1.peer.host)), |
| 222 | g_media.bts1.peer.port_nr, |
| 223 | g_media.bts1.rtp_pt)); |
| 224 | //g_media.bts1.ipa_mdcx_seen := true; |
| 225 | repeat; |
| 226 | } |
| 227 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 228 | [] MGCP.receive(tr_CRCX) -> value mgcp_cmd { |
| 229 | var SDP_Message sdp; |
| 230 | var integer cid := f_get_free_mgcp_conn(); |
Harald Welte | 363cb0a | 2018-01-30 19:35:53 +0100 | [diff] [blame] | 231 | if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard)) { |
| 232 | if (cid != 0) { |
| 233 | setverdict(fail, "MGCP wildcard EP only works in first CRCX"); |
| 234 | self.stop; |
| 235 | } |
| 236 | /* we keep the endpoint name allocated during MediaState_init */ |
| 237 | } else { |
| 238 | /* Call Agent allocated endpoint, trust/use it always */ |
| 239 | g_media.mgcp_ep := mgcp_cmd.line.ep; |
| 240 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 241 | if (isvalue(mgcp_cmd.sdp)) { |
| 242 | sdp := mgcp_cmd.sdp; |
| 243 | g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr; |
| 244 | g_media.mgcp_conn[cid].peer.port_nr := sdp.media_list[0].media_field.ports.port_number; |
| 245 | } |
| 246 | var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid]; |
| 247 | sdp := valueof(ts_SDP(mgcp_conn.mgw.host, mgcp_conn.mgw.host, "foo", "21", |
| 248 | mgcp_conn.mgw.port_nr, { int2str(mgcp_conn.rtp_pt) }, |
| 249 | {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt, |
| 250 | mgcp_conn.mime_type & "/" & |
| 251 | int2str(mgcp_conn.sample_rate))), |
| 252 | valueof(ts_SDP_ptime(mgcp_conn.ptime)) } )); |
Harald Welte | 363cb0a | 2018-01-30 19:35:53 +0100 | [diff] [blame] | 253 | var template MgcpResponse mgcp_resp; |
| 254 | mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp); |
| 255 | f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(g_media.mgcp_ep)); |
| 256 | MGCP.send(mgcp_resp); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 257 | g_media.mgcp_conn[cid].crcx_seen := true; |
| 258 | repeat; |
| 259 | } |
| 260 | [] MGCP.receive(tr_MDCX) -> value mgcp_cmd { |
| 261 | var SDP_Message sdp; |
| 262 | var integer cid := f_get_mgcp_conn(f_MgcpCmd_extract_conn_id(mgcp_cmd)); |
| 263 | if (isvalue(mgcp_cmd.sdp)) { |
| 264 | sdp := mgcp_cmd.sdp; |
| 265 | g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr; |
| 266 | g_media.mgcp_conn[cid].peer.port_nr := sdp.media_list[0].media_field.ports.port_number; |
| 267 | } else { |
| 268 | setverdict(fail, "MDCX has no [recognizable] SDP"); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 269 | } |
| 270 | var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid]; |
| 271 | sdp := valueof(ts_SDP(mgcp_conn.peer.host, mgcp_conn.peer.host, "foo", "21", |
| 272 | mgcp_conn.peer.port_nr, { int2str(mgcp_conn.rtp_pt) }, |
| 273 | {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt, |
| 274 | mgcp_conn.mime_type & "/" & |
| 275 | int2str(mgcp_conn.sample_rate))), |
| 276 | valueof(ts_SDP_ptime(mgcp_conn.ptime)) } )); |
| 277 | MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp)); |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 278 | //g_media.mgcp_mdcx_seen := true; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 279 | repeat; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 286 | /* this component represents a single subscriber connection at the MSC. |
| 287 | * There is a 1:1 mapping between SCCP connections and BSSAP_ConnHdlr components. |
| 288 | * We inherit all component variables, ports, functions, ... from BSSAP_ConnHdlr */ |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 289 | type component MSC_ConnHdlr extends BSSAP_ConnHdlr, RSL_DchanHdlr, MGCP_ConnHdlr { |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 290 | /* SCCP Connecction Identifier for the underlying SCCP connection */ |
| 291 | var integer g_sccp_conn_id; |
| 292 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 293 | /* procedure port back to our parent (BSSMAP_Emulation_CT) for control */ |
| 294 | port BSSMAPEM_PROC_PT BSSMAPEM; |
Harald Welte | c20b1c4 | 2018-02-12 20:50:08 +0100 | [diff] [blame] | 295 | port TELNETasp_PT BSCVTY; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 296 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 297 | var MediaState g_media; |
Harald Welte | a063003 | 2018-03-20 21:09:55 +0100 | [diff] [blame] | 298 | var TestHdlrParams g_pars; |
Harald Welte | e97eab4 | 2018-03-21 18:46:06 +0100 | [diff] [blame] | 299 | |
| 300 | var boolean g_vty_initialized := false; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | /* initialize all parameters */ |
| 304 | function f_MscConnHdlr_init(integer i, HostName bts, HostName mgw) runs on MSC_ConnHdlr { |
| 305 | f_MediaState_init(g_media, i, bts, mgw); |
Harald Welte | e97eab4 | 2018-03-21 18:46:06 +0100 | [diff] [blame] | 306 | if (not g_vty_initialized) { |
| 307 | map(self:BSCVTY, system:BSCVTY); |
| 308 | f_vty_set_prompts(BSCVTY); |
| 309 | f_vty_transceive(BSCVTY, "enable"); |
| 310 | g_vty_initialized := true; |
| 311 | } |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /* Callback function from general BSSMAP_Emulation whenever a connectionless |
| 315 | * BSSMAP message arrives. Can retunr a PDU_BSSAP that should be sent in return */ |
| 316 | private function UnitdataCallback(PDU_BSSAP bssap) |
| 317 | runs on BSSMAP_Emulation_CT return template PDU_BSSAP { |
| 318 | var template PDU_BSSAP resp := omit; |
| 319 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 320 | /* answer all RESET with a RESET ACK */ |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 321 | if (match(bssap, tr_BSSMAP_Reset)) { |
| 322 | resp := ts_BSSMAP_ResetAck; |
| 323 | } |
| 324 | |
| 325 | return resp; |
| 326 | } |
| 327 | |
| 328 | const BssmapOps MSC_BssmapOps := { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 329 | create_cb := refers(BSSMAP_Emulation.ExpectedCreateCallback), |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 330 | unitdata_cb := refers(UnitdataCallback), |
| 331 | decode_dtap := false, |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 332 | role_ms := false, |
| 333 | sccp_addr_local := omit, |
| 334 | sccp_addr_peer := omit |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 335 | } |
| 336 | |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 337 | const MGCPOps MSC_MGCPOps := { |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 338 | create_cb := refers(MGCP_Emulation.ExpectedCreateCallback), |
| 339 | unitdata_cb := refers(MGCP_Emulation.DummyUnitdataCallback) |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 340 | } |
| 341 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 342 | /* register an expect with the BSSMAP core */ |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 343 | 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] | 344 | BSSMAPEM.call(BSSMAPEM_register:{l3_enc, self}) { |
| 345 | [] BSSMAPEM.getreply(BSSMAPEM_register:{?, ?}) {}; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
Harald Welte | 651fcdc | 2018-05-10 20:23:16 +0200 | [diff] [blame] | 349 | type record TestHdlrEncrParams { |
| 350 | OCT1 enc_alg, |
| 351 | octetstring enc_key |
| 352 | }; |
| 353 | |
| 354 | template (value) TestHdlrEncrParams t_EncrParams(OCT1 alg, octetstring key) := { |
| 355 | enc_alg := alg, |
| 356 | enc_key := key |
| 357 | } |
| 358 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 359 | type record TestHdlrParams { |
| 360 | OCT1 ra, |
| 361 | GsmFrameNumber fn, |
| 362 | hexstring imsi, |
Harald Welte | 60aa576 | 2018-03-21 19:33:13 +0100 | [diff] [blame] | 363 | RslLinkId link_id, |
Harald Welte | 651fcdc | 2018-05-10 20:23:16 +0200 | [diff] [blame] | 364 | BSSMAP_IE_SpeechCodecList ass_codec_list optional, |
| 365 | TestHdlrEncrParams encr optional |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 366 | }; |
| 367 | |
| 368 | template (value) TestHdlrParams t_def_TestHdlrPars := { |
| 369 | ra := '23'O, |
| 370 | fn := 23, |
| 371 | imsi := '001019876543210'H, |
Harald Welte | 60aa576 | 2018-03-21 19:33:13 +0100 | [diff] [blame] | 372 | link_id := valueof(ts_RslLinkID_DCCH(0)), |
Harald Welte | 651fcdc | 2018-05-10 20:23:16 +0200 | [diff] [blame] | 373 | ass_codec_list := omit, |
| 374 | encr := omit |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 375 | } |
| 376 | |
Harald Welte | a063003 | 2018-03-20 21:09:55 +0100 | [diff] [blame] | 377 | function f_create_chan_and_exp() runs on MSC_ConnHdlr { |
| 378 | var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi)); |
Harald Welte | 6ed6bf9 | 2018-01-24 21:09:15 +0100 | [diff] [blame] | 379 | 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] | 380 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info); |
| 381 | |
| 382 | /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */ |
Harald Welte | a063003 | 2018-03-20 21:09:55 +0100 | [diff] [blame] | 383 | 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] | 384 | f_create_bssmap_exp(l3_enc); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 385 | } |
| 386 | |
Harald Welte | 898113b | 2018-01-31 18:32:21 +0100 | [diff] [blame] | 387 | function f_rsl_send_l3(template PDU_ML3_MS_NW l3, template (omit) RslLinkId link_id := omit, |
| 388 | template (omit) RslChannelNr chan_nr := omit) runs on MSC_ConnHdlr { |
| 389 | if (not isvalue(link_id)) { |
| 390 | link_id := ts_RslLinkID_DCCH(0); |
| 391 | } |
| 392 | if (not isvalue(chan_nr)) { |
| 393 | chan_nr := g_chan_nr; |
| 394 | } |
| 395 | RSL.send(ts_RSL_DATA_IND(valueof(chan_nr), valueof(link_id), enc_PDU_ML3_MS_NW(valueof(l3)))); |
| 396 | } |
| 397 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 398 | function f_rsl_reply(template PDU_ML3_MS_NW l3, RSL_Message orig) runs on MSC_ConnHdlr { |
| 399 | var RslChannelNr chan_nr := orig.ies[0].body.chan_nr; |
Harald Welte | 1a40de6 | 2017-12-23 02:28:34 +0100 | [diff] [blame] | 400 | var RslLinkId link_id; |
Harald Welte | 8d5eead | 2017-12-17 18:56:45 +0100 | [diff] [blame] | 401 | if (orig.msg_type == RSL_MT_ENCR_CMD) { |
| 402 | link_id := orig.ies[2].body.link_id; |
| 403 | } else { |
| 404 | link_id := orig.ies[1].body.link_id; |
| 405 | } |
Harald Welte | 898113b | 2018-01-31 18:32:21 +0100 | [diff] [blame] | 406 | f_rsl_send_l3(l3, link_id, chan_nr); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 407 | } |
| 408 | |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 409 | /* Convert the chipher representation on BSSMAP to the representation used on RSL */ |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 410 | 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] | 411 | { |
| 412 | /* A5 0 */ |
| 413 | if (alg_bssmap == '01'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 414 | return RSL_ALG_ID_A5_0; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 415 | } |
| 416 | /* A5 1 */ |
| 417 | else if (alg_bssmap == '02'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 418 | return RSL_ALG_ID_A5_1; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 419 | } |
| 420 | /* A5 2 */ |
| 421 | else if (alg_bssmap == '04'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 422 | return RSL_ALG_ID_A5_2; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 423 | } |
| 424 | /* A5 3 */ |
| 425 | else if (alg_bssmap == '08'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 426 | return RSL_ALG_ID_A5_3; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 427 | } |
| 428 | /* A5 4 */ |
| 429 | else if (alg_bssmap == '10'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 430 | return RSL_ALG_ID_A5_4; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 431 | } |
| 432 | /* A5 5 */ |
| 433 | else if (alg_bssmap == '20'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 434 | return RSL_ALG_ID_A5_5; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 435 | } |
| 436 | /* A5 6 */ |
| 437 | else if (alg_bssmap == '40'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 438 | return RSL_ALG_ID_A5_6; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 439 | } |
| 440 | /* A5 7 */ |
| 441 | else if (alg_bssmap == '80'O) { |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 442 | return RSL_ALG_ID_A5_7; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 443 | } else { |
| 444 | setverdict(fail, "Unexpected Encryption Algorithm"); |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 445 | return RSL_ALG_ID_A5_0; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 449 | function f_cipher_mode(OCT1 alg, OCT8 key, template OCT16 kc128 := omit, boolean exp_fail := false) |
| 450 | runs on MSC_ConnHdlr { |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 451 | var PDU_BSSAP bssap; |
| 452 | var RSL_Message rsl; |
Harald Welte | e613f96 | 2018-04-18 22:38:16 +0200 | [diff] [blame] | 453 | var RSL_AlgId alg_rsl; |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 454 | |
| 455 | if (isvalue(kc128)) { |
| 456 | BSSAP.send(ts_BSSMAP_CipherModeCmdKc128(alg, key, valueof(kc128))); |
| 457 | } else { |
| 458 | BSSAP.send(ts_BSSMAP_CipherModeCmd(alg, key)); |
| 459 | } |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 460 | |
| 461 | /* RSL uses a different representation of the encryption algorithm, |
| 462 | * so we need to convert first */ |
| 463 | alg_rsl := f_chipher_mode_bssmap_to_rsl(alg); |
| 464 | |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 465 | alt { |
| 466 | /* RSL/UE Side */ |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 467 | [] 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] | 468 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[3].body.l3_info.payload); |
| 469 | log("Rx L3 from net: ", l3); |
| 470 | if (ischosen(l3.msgs.rrm.cipheringModeCommand)) { |
| 471 | f_rsl_reply(ts_RRM_CiphModeCompl, rsl); |
| 472 | } |
| 473 | repeat; |
| 474 | } |
| 475 | [] BSSAP.receive(tr_BSSMAP_CipherModeCompl) -> value bssap { |
| 476 | // bssap.bssmap.cipherModeComplete.chosenEncryptionAlgorithm.algoritmhIdentifier |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 477 | if (exp_fail == true) { |
| 478 | setverdict(fail, "Unexpected Cipher Mode Complete"); |
| 479 | } else { |
| 480 | setverdict(pass); |
| 481 | } |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 482 | } |
| 483 | [] BSSAP.receive(tr_BSSMAP_CipherModeRej) -> value bssap { |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 484 | if (exp_fail == false) { |
| 485 | setverdict(fail, "Ciphering Mode Reject"); |
| 486 | } else { |
| 487 | setverdict(pass); |
| 488 | } |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | } |
| 492 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 493 | /* Convert from Ericsson ChanDesc2 format to Osmocom RslChannelNr format */ |
| 494 | function f_ChDesc2RslChanNr(ChannelDescription2_V ch_desc, out RslChannelNr chan_nr, out GsmArfcn arfcn) { |
| 495 | var BIT5 inp := ch_desc.channelTypeandTDMAOffset; |
Harald Welte | 6fa1f73 | 2018-03-21 22:46:16 +0100 | [diff] [blame] | 496 | var uint3_t tn := bit2int(ch_desc.timeslotNumber); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 497 | |
| 498 | if (match(inp, '00001'B)) { /* TCH/F */ |
Harald Welte | 6fa1f73 | 2018-03-21 22:46:16 +0100 | [diff] [blame] | 499 | chan_nr := valueof(t_RslChanNr_Bm(tn)); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 500 | } |
| 501 | else if (match(inp, '0001?'B)) { /* TCH/H */ |
Harald Welte | 6fa1f73 | 2018-03-21 22:46:16 +0100 | [diff] [blame] | 502 | chan_nr := valueof(t_RslChanNr_Lm(tn, bit2int(substr(inp, 4, 1)))); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 503 | } |
| 504 | else if (match(inp, '001??'B)) { /* SDCCH/4 */ |
Harald Welte | 6fa1f73 | 2018-03-21 22:46:16 +0100 | [diff] [blame] | 505 | chan_nr := valueof(t_RslChanNr_SDCCH4(tn, bit2int(substr(inp, 3, 2)))); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 506 | } |
| 507 | else if (match(inp, '01???'B)) { /* SDCCH/8 */ |
Harald Welte | 6fa1f73 | 2018-03-21 22:46:16 +0100 | [diff] [blame] | 508 | chan_nr := valueof(t_RslChanNr_SDCCH8(tn, bit2int(substr(inp, 2, 3)))); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 509 | } |
| 510 | else { |
| 511 | setverdict(fail, "Unknown ChDesc!"); |
| 512 | self.stop; |
| 513 | } |
| 514 | |
| 515 | if (ch_desc.octet3 and4b '10'O == '10'O) { |
| 516 | setverdict(fail, "No support for Hopping"); |
| 517 | self.stop; |
| 518 | } else { |
| 519 | var OCT2 concat := ch_desc.octet3 & ch_desc.octet4; |
| 520 | arfcn := oct2int(concat); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | type record AssignmentState { |
| 525 | /* global */ |
| 526 | boolean voice_call, |
| 527 | boolean is_assignment, |
| 528 | /* Assignment related bits */ |
| 529 | boolean rr_ass_cmpl_seen, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 530 | boolean assignment_done, |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 531 | RslChannelNr old_chan_nr, |
| 532 | /* Modify related bits */ |
| 533 | boolean rr_modify_seen, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 534 | boolean modify_done |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | template (value) AssignmentState ts_AssignmentStateInit := { |
| 538 | voice_call := false, |
| 539 | is_assignment := false, |
| 540 | rr_ass_cmpl_seen := false, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 541 | assignment_done := false, |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 542 | old_chan_nr := -, |
| 543 | rr_modify_seen := false, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 544 | modify_done := false |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 545 | } |
| 546 | |
Harald Welte | 8a9bf6f | 2018-05-10 22:00:49 +0200 | [diff] [blame] | 547 | private template RSL_IE_Body tr_EncrInfo(template RSL_AlgId alg, template octetstring key) := { |
| 548 | encr_info := { |
| 549 | len := ?, |
| 550 | alg_id := alg, |
| 551 | key := key |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | /* ensure the RSL CHAN ACT (during assignment) contains values we expect depending on test case */ |
| 556 | private function f_check_chan_act(AssignmentState st, RSL_Message chan_act) runs on MSC_ConnHdlr { |
| 557 | var RSL_IE_Body encr_info; |
| 558 | if (ispresent(g_pars.encr) and g_pars.encr.enc_alg != '01'O) { |
| 559 | if (not f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) { |
| 560 | setverdict(fail, "Missing Encryption IE in CHAN ACT"); |
| 561 | } else { |
| 562 | var RSL_AlgId alg := f_chipher_mode_bssmap_to_rsl(g_pars.encr.enc_alg); |
| 563 | if (not match(encr_info, tr_EncrInfo(alg, g_pars.encr.enc_key))) { |
| 564 | setverdict(fail, "Wrong Encryption IE in CHAN ACT"); |
| 565 | } |
| 566 | } |
| 567 | } else { |
| 568 | if (f_rsl_find_ie(chan_act, RSL_IE_ENCR_INFO, encr_info)) { |
| 569 | if (encr_info.encr_info.alg_id != RSL_ALG_ID_A5_0) { |
| 570 | setverdict(fail, "Unexpected Encryption in CHAN ACT"); |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | /* FIXME: validate RSL_IE_ACT_TYPE, RSL_IE_CHAN_MODE, RSL_IE_CHAN_IDENT, RSL_IE_BS_POWER, |
| 575 | * RSL_IE_MS_POWER, RSL_IE_TIMING_ADVANCE */ |
| 576 | } |
| 577 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 578 | altstep as_assignment(inout AssignmentState st) runs on MSC_ConnHdlr { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 579 | var RSL_Message rsl; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 580 | [not st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl { |
| 581 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload); |
| 582 | log("Rx L3 from net: ", l3); |
| 583 | if (ischosen(l3.msgs.rrm.assignmentCommand)) { |
| 584 | var RslChannelNr new_chan_nr; |
| 585 | var GsmArfcn arfcn; |
| 586 | f_ChDesc2RslChanNr(l3.msgs.rrm.assignmentCommand.descrOf1stChAfterTime, |
| 587 | new_chan_nr, arfcn); |
| 588 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 589 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 590 | /* register our component for this channel number at the RSL Emulation */ |
| 591 | f_rslem_register(0, new_chan_nr); |
| 592 | var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_AssignmentComplete('00'O)); |
| 593 | /* send assignment complete over the new channel */ |
| 594 | RSL.send(ts_RSL_DATA_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)), |
| 595 | enc_PDU_ML3_MS_NW(l3_tx))); |
| 596 | /* by default, send via the new channel from now */ |
| 597 | st.old_chan_nr := g_chan_nr; |
| 598 | g_chan_nr := new_chan_nr; |
| 599 | st.rr_ass_cmpl_seen := true; |
Harald Welte | 8a9bf6f | 2018-05-10 22:00:49 +0200 | [diff] [blame] | 600 | /* obtain channel activation from RSL_Emulation for new channel */ |
| 601 | var RSL_Message chan_act := f_rslem_get_last_act(RSL_PROC, 0, g_chan_nr); |
| 602 | /* check it (e.g. for correct ciphering parameters) */ |
| 603 | f_check_chan_act(st, chan_act); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 604 | repeat; |
| 605 | } else { |
| 606 | setverdict(fail, "Unexpected L3 received", l3); |
| 607 | self.stop; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 608 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 609 | } |
| 610 | [st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_REL_REQ(st.old_chan_nr, tr_RslLinkID_DCCH(0))) { |
| 611 | RSL.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0)))); |
| 612 | repeat; |
| 613 | } |
| 614 | [st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) { |
| 615 | RSL.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr)); |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 616 | /* unregister for old channel number in RSL emulation */ |
| 617 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
| 618 | f_rslem_unregister(0, st.old_chan_nr); |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 619 | st.assignment_done := true; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 620 | repeat; |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | altstep as_modify(inout AssignmentState st) runs on MSC_ConnHdlr { |
| 625 | /* no assignment, just mode modify */ |
| 626 | var RSL_Message rsl; |
| 627 | |
| 628 | [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] | 629 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload); |
| 630 | log("Rx L3 from net: ", l3); |
| 631 | if (ischosen(l3.msgs.rrm.channelModeModify)) { |
| 632 | f_rsl_reply(ts_RRM_ModeModifyAck(l3.msgs.rrm.channelModeModify.channelDescription, |
| 633 | l3.msgs.rrm.channelModeModify.channelMode), rsl); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 634 | st.rr_modify_seen := true; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 635 | } |
| 636 | repeat; |
| 637 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 638 | [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] | 639 | RSL.send(ts_RSL_MODE_MODIFY_ACK(g_chan_nr)); |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 640 | st.modify_done := true; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 641 | repeat; |
| 642 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 643 | } |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 644 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 645 | /* Determine if given rsl_chan_nr is compatible with given BSSMAP ChannelType */ |
| 646 | function f_channel_compatible(BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr) |
| 647 | return boolean { |
| 648 | select (bssmap.speechOrDataIndicator) { |
| 649 | case ('0011'B) { /* Signalling */ |
| 650 | /* all channels support signalling */ |
| 651 | return true; |
| 652 | } |
| 653 | case else { /* Speech, Speech+CTM or CSD */ |
| 654 | select (bssmap.channelRateAndType) { |
| 655 | case ('08'O) { /* TCH/F */ |
| 656 | select (rsl_chan_nr) { |
| 657 | case (t_RslChanNr_Bm(?)) { return true; } |
| 658 | } |
| 659 | } |
| 660 | case ('09'O) { /* TCH/H */ |
| 661 | select (rsl_chan_nr) { |
| 662 | case (t_RslChanNr_Lm(?, ?)) { return true; } |
| 663 | } |
| 664 | } |
| 665 | case else { /* full or half-rate */ |
| 666 | select (rsl_chan_nr) { |
| 667 | case (t_RslChanNr_Bm(?)) { return true; } |
| 668 | case (t_RslChanNr_Lm(?, ?)) { return true; } |
| 669 | } |
| 670 | } |
| 671 | } |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 672 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 673 | } |
| 674 | return false; |
| 675 | } |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 676 | |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 677 | /* Determine if the channel mode specified within rsl_chan_nr requires a |
| 678 | * MODE MODIFY in to match the channel mode specified by given BSSMAP |
| 679 | * ChannelType */ |
| 680 | function f_channel_needs_modify(BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr) |
| 681 | return boolean { |
| 682 | |
| 683 | /* FIXME: This tests the rsl_chan_nr to determine if we are on a |
| 684 | * signalling channel or not. Unfortunately this may lead to false |
| 685 | * results if we are on a TCH. The problem is that a TCH may be also |
| 686 | * used in signalling mode, but this function assumes that only SDCCH4 |
| 687 | * and SDCCH8 are used as signalling channels at all. */ |
| 688 | |
| 689 | var boolean current_signalling := false; |
| 690 | var boolean desired_signalling := false; |
| 691 | |
| 692 | select (rsl_chan_nr) { |
| 693 | case (t_RslChanNr_SDCCH4(?, ?)) { current_signalling := true; } |
| 694 | case (t_RslChanNr_SDCCH8(?, ?)) { current_signalling := true; } |
| 695 | } |
| 696 | |
| 697 | if (bssmap.speechOrDataIndicator == '0011'B) { |
| 698 | desired_signalling := true; |
| 699 | } |
| 700 | |
| 701 | if (current_signalling == desired_signalling) { |
| 702 | /* The desired channel mode is equal to the one we currently |
| 703 | * have, there is no mode modification needed or expected */ |
| 704 | return false; |
| 705 | } else { |
| 706 | /* The desired channel mode and the current channel mode do |
| 707 | * not match. A mode modification is required */ |
| 708 | return true; |
| 709 | } |
| 710 | } |
| 711 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 712 | /* establish a channel fully, expecting an assignment matching 'exp' */ |
Harald Welte | 7a14fd5 | 2018-05-10 22:26:55 +0200 | [diff] [blame] | 713 | function f_establish_fully(template (omit) PDU_BSSAP ass_tpl, template PDU_BSSAP exp_ass_cpl) |
| 714 | runs on MSC_ConnHdlr { |
| 715 | f_MscConnHdlr_init(1, "127.0.0.2", "127.0.0.3"); |
| 716 | |
| 717 | f_create_chan_and_exp(); |
| 718 | /* we should now have a COMPL_L3 at the MSC */ |
| 719 | BSSAP.receive(tr_BSSMAP_ComplL3); |
| 720 | |
| 721 | /* start ciphering, if requested */ |
| 722 | if (ispresent(g_pars.encr)) { |
| 723 | f_cipher_mode(g_pars.encr.enc_alg, g_pars.encr.enc_key); |
| 724 | } |
| 725 | |
| 726 | /* bail out early if no assignment requested */ |
| 727 | if (istemplatekind(ass_tpl, "omit")) { |
| 728 | return; |
| 729 | } |
| 730 | |
| 731 | var PDU_BSSAP ass_cmd := valueof(ass_tpl); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 732 | var PDU_BSSAP bssap; |
| 733 | timer T := 10.0; |
| 734 | var boolean exp_compl := ischosen(exp_ass_cpl.pdu.bssmap.assignmentComplete); |
Philipp Maier | 86f3920 | 2018-02-07 14:40:09 +0100 | [diff] [blame] | 735 | var boolean exp_fail := ischosen(exp_ass_cpl.pdu.bssmap.assignmentFailure); |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 736 | var boolean exp_modify; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 737 | var ExpectCriteria mgcpcrit := { |
| 738 | connid := omit, |
| 739 | endpoint := omit, |
| 740 | transid := omit |
| 741 | }; |
| 742 | var AssignmentState st := valueof(ts_AssignmentStateInit); |
| 743 | /* if the channel type is SIGNAL, we're not handling a voice call */ |
| 744 | if (ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechOrDataIndicator != '0011'B) { |
| 745 | st.voice_call := true; |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 746 | exp_modify := true; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 747 | } |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 748 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 749 | /* determine if the current channel can support the given service or not */ |
| 750 | if (not f_channel_compatible(ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr)) { |
| 751 | st.is_assignment := true; |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 752 | |
| 753 | /* We decided to assign a new channel, so we do not expect |
| 754 | * any mode modify messages on RSL */ |
| 755 | exp_modify := false; |
| 756 | } else { |
| 757 | /* We will continue working with the currently assigned |
| 758 | * channel, we must now check if the mode of the current |
| 759 | * channel is compatible. If not we expect the BSC to modify |
| 760 | * the mode */ |
| 761 | 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] | 762 | } |
| 763 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 764 | f_create_mgcp_expect(mgcpcrit); |
| 765 | BSSAP.send(ass_cmd); |
| 766 | |
| 767 | T.start; |
| 768 | alt { |
| 769 | /* assignment related bits */ |
| 770 | [st.is_assignment] as_assignment(st); |
| 771 | |
| 772 | /* modify related bits */ |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 773 | [not st.is_assignment and exp_modify] as_modify(st); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 774 | |
| 775 | /* voice call related bits (IPA CRCX/MDCX + MGCP) */ |
| 776 | [st.voice_call] as_Media(); |
| 777 | |
| 778 | /* if we receive exactly what we expected, always return + pass */ |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 779 | [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] | 780 | setverdict(pass); |
| 781 | } |
Philipp Maier | 86f3920 | 2018-02-07 14:40:09 +0100 | [diff] [blame] | 782 | [exp_fail] BSSAP.receive(exp_ass_cpl) -> value bssap { |
| 783 | setverdict(pass); |
| 784 | } |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 785 | [(st.is_assignment and st.assignment_done or |
Philipp Maier | 8ef527e | 2018-05-18 11:12:50 +0200 | [diff] [blame] | 786 | (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] | 787 | exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 788 | setverdict(fail, "Received non-matching ASSIGNMENT COMPLETE"); |
| 789 | } |
| 790 | [exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) { |
| 791 | setverdict(fail, "Received unexpected ASSIGNMENT FAIL"); |
| 792 | } |
| 793 | [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) { |
| 794 | setverdict(fail, "Received unexpected ASSIGNMENT COMPLETE"); |
| 795 | } |
| 796 | [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) { |
| 797 | setverdict(fail, "Received non-matching ASSIGNMENT FAIL"); |
| 798 | } |
| 799 | [] T.timeout { |
Harald Welte | 458fd37 | 2018-03-21 11:26:23 +0100 | [diff] [blame] | 800 | setverdict(fail, "Timeout waiting for ASSIGNMENT COMPLETE"); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 801 | } |
| 802 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 803 | log("g_media ", g_media); |
| 804 | if (not isbound(bssap)) { |
| 805 | self.stop; |
| 806 | } |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 807 | } |
| 808 | |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 809 | type record HandoverState { |
| 810 | /* Assignment related bits */ |
| 811 | boolean rr_ho_cmpl_seen, |
| 812 | boolean handover_done, |
| 813 | RslChannelNr old_chan_nr |
| 814 | }; |
| 815 | |
| 816 | altstep as_handover(inout HandoverState st) runs on MSC_ConnHdlr { |
| 817 | var RSL_Message rsl; |
| 818 | [not st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl { |
| 819 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload); |
| 820 | log("Rx L3 from net: ", l3); |
| 821 | if (ischosen(l3.msgs.rrm.handoverCommand)) { |
| 822 | var RslChannelNr new_chan_nr; |
| 823 | var GsmArfcn arfcn; |
| 824 | f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2, |
| 825 | new_chan_nr, arfcn); |
| 826 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
| 827 | |
| 828 | /* register our component for this channel number at the RSL Emulation */ |
| 829 | f_rslem_register(0, new_chan_nr, RSL1_PROC); |
| 830 | |
| 831 | /* resume processing of RSL DChan messages, which was temporarily suspended |
| 832 | * before performing a hand-over */ |
| 833 | f_rslem_resume(RSL1_PROC); |
| 834 | |
| 835 | /* send handover complete over the new channel */ |
| 836 | var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O)); |
| 837 | RSL1.send(ts_RSL_DATA_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)), |
| 838 | enc_PDU_ML3_MS_NW(l3_tx))); |
| 839 | /* by default, send via the new channel from now */ |
| 840 | st.old_chan_nr := g_chan_nr; |
| 841 | g_chan_nr := new_chan_nr; |
| 842 | st.rr_ho_cmpl_seen := true; |
| 843 | repeat; |
| 844 | } else { |
| 845 | setverdict(fail, "Unexpected L3 received", l3); |
| 846 | self.stop; |
| 847 | } |
| 848 | } |
| 849 | [st.rr_ho_cmpl_seen] as_Media(); |
| 850 | [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_REL_REQ(st.old_chan_nr, tr_RslLinkID_DCCH(0))) { |
| 851 | RSL.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0)))); |
| 852 | repeat; |
| 853 | } |
| 854 | [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) { |
| 855 | RSL.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr)); |
| 856 | /* unregister for old channel number in RSL emulation */ |
| 857 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
| 858 | f_rslem_unregister(0, st.old_chan_nr); |
| 859 | st.handover_done := true; |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 860 | } |
| 861 | } |
| 862 | |
| 863 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 864 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 865 | } |