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; |
| 122 | return -1; |
| 123 | } |
| 124 | |
| 125 | private function f_get_mgcp_conn(MgcpConnectionId cid) runs on MSC_ConnHdlr return integer { |
| 126 | for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) { |
| 127 | if (g_media.mgcp_conn[i].conn_id == cid and g_media.mgcp_conn[i].crcx_seen) { |
| 128 | return i; |
| 129 | } |
| 130 | } |
| 131 | setverdict(fail, "No Connection for ID ", cid); |
| 132 | self.stop; |
| 133 | return -1; |
| 134 | } |
| 135 | |
| 136 | |
| 137 | /* altstep for handling of IPA + MGCP media related commands. Can be activated by a given |
| 138 | * test case if it expects to see media related handling (i.e. voice calls */ |
| 139 | altstep as_Media() runs on MSC_ConnHdlr { |
| 140 | var RSL_Message rsl; |
| 141 | var MgcpCommand mgcp_cmd; |
| 142 | var RSL_IE_Body ie; |
| 143 | [not g_media.bts.ipa_crcx_seen] RSL.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl { |
| 144 | /* Extract parameters from request + use in response */ |
| 145 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 146 | g_media.bts.rtp_pt := ie.ipa_rtp_pt; |
| 147 | } |
| 148 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 149 | g_media.bts.rtp_pt := ie.ipa_rtp_pt2; |
| 150 | } |
| 151 | RSL.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts.conn_id, |
| 152 | oct2int(f_inet_addr(g_media.bts.bts.host)), |
| 153 | g_media.bts.bts.port_nr, |
| 154 | g_media.bts.rtp_pt)); |
| 155 | g_media.bts.ipa_crcx_seen := true; |
| 156 | repeat; |
| 157 | } |
| 158 | [g_media.bts.ipa_crcx_seen] RSL.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{ |
| 159 | /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */ |
| 160 | f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie); |
| 161 | if (g_media.bts.conn_id != ie.ipa_conn_id) { |
| 162 | setverdict(fail, "IPA MDCX for unknown ConnId", rsl); |
| 163 | self.stop; |
| 164 | } |
| 165 | /* mandatory */ |
| 166 | f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_IP, ie); |
| 167 | g_media.bts.peer.host := f_inet_ntoa(int2oct(ie.ipa_remote_ip, 4)); |
| 168 | f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_PORT, ie); |
| 169 | g_media.bts.peer.port_nr := ie.ipa_remote_port; |
| 170 | /* optional */ |
| 171 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 172 | g_media.bts.rtp_pt := ie.ipa_rtp_pt; |
| 173 | } |
| 174 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 175 | g_media.bts.rtp_pt := ie.ipa_rtp_pt2; |
| 176 | } |
| 177 | RSL.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts.conn_id, |
| 178 | oct2int(f_inet_addr(g_media.bts.peer.host)), |
| 179 | g_media.bts.peer.port_nr, |
| 180 | g_media.bts.rtp_pt)); |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 181 | //g_media.bts.ipa_mdcx_seen := true; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 182 | repeat; |
| 183 | } |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 184 | |
| 185 | /* on second (new) BTS during hand-over */ |
| 186 | [not g_media.bts1.ipa_crcx_seen] RSL1.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl { |
| 187 | /* Extract parameters from request + use in response */ |
| 188 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 189 | g_media.bts1.rtp_pt := ie.ipa_rtp_pt; |
| 190 | } |
| 191 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 192 | g_media.bts1.rtp_pt := ie.ipa_rtp_pt2; |
| 193 | } |
| 194 | RSL1.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts1.conn_id, |
| 195 | oct2int(f_inet_addr(g_media.bts1.bts.host)), |
| 196 | g_media.bts1.bts.port_nr, |
| 197 | g_media.bts1.rtp_pt)); |
| 198 | g_media.bts1.ipa_crcx_seen := true; |
| 199 | repeat; |
| 200 | } |
| 201 | /* on second (new) BTS during hand-over */ |
| 202 | [g_media.bts1.ipa_crcx_seen] RSL1.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{ |
| 203 | /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */ |
| 204 | f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie); |
| 205 | if (g_media.bts1.conn_id != ie.ipa_conn_id) { |
| 206 | setverdict(fail, "IPA MDCX for unknown ConnId", rsl); |
| 207 | self.stop; |
| 208 | } |
| 209 | /* mandatory */ |
| 210 | f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_IP, ie); |
| 211 | g_media.bts1.peer.host := f_inet_ntoa(int2oct(ie.ipa_remote_ip, 4)); |
| 212 | f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_PORT, ie); |
| 213 | g_media.bts1.peer.port_nr := ie.ipa_remote_port; |
| 214 | /* optional */ |
| 215 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 216 | g_media.bts1.rtp_pt := ie.ipa_rtp_pt; |
| 217 | } |
| 218 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 219 | g_media.bts1.rtp_pt := ie.ipa_rtp_pt2; |
| 220 | } |
| 221 | RSL1.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts1.conn_id, |
| 222 | oct2int(f_inet_addr(g_media.bts1.peer.host)), |
| 223 | g_media.bts1.peer.port_nr, |
| 224 | g_media.bts1.rtp_pt)); |
| 225 | //g_media.bts1.ipa_mdcx_seen := true; |
| 226 | repeat; |
| 227 | } |
| 228 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 229 | [] MGCP.receive(tr_CRCX) -> value mgcp_cmd { |
| 230 | var SDP_Message sdp; |
| 231 | var integer cid := f_get_free_mgcp_conn(); |
Harald Welte | 363cb0a | 2018-01-30 19:35:53 +0100 | [diff] [blame] | 232 | if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard)) { |
| 233 | if (cid != 0) { |
| 234 | setverdict(fail, "MGCP wildcard EP only works in first CRCX"); |
| 235 | self.stop; |
| 236 | } |
| 237 | /* we keep the endpoint name allocated during MediaState_init */ |
| 238 | } else { |
| 239 | /* Call Agent allocated endpoint, trust/use it always */ |
| 240 | g_media.mgcp_ep := mgcp_cmd.line.ep; |
| 241 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 242 | if (isvalue(mgcp_cmd.sdp)) { |
| 243 | sdp := mgcp_cmd.sdp; |
| 244 | g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr; |
| 245 | g_media.mgcp_conn[cid].peer.port_nr := sdp.media_list[0].media_field.ports.port_number; |
| 246 | } |
| 247 | var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid]; |
| 248 | sdp := valueof(ts_SDP(mgcp_conn.mgw.host, mgcp_conn.mgw.host, "foo", "21", |
| 249 | mgcp_conn.mgw.port_nr, { int2str(mgcp_conn.rtp_pt) }, |
| 250 | {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt, |
| 251 | mgcp_conn.mime_type & "/" & |
| 252 | int2str(mgcp_conn.sample_rate))), |
| 253 | valueof(ts_SDP_ptime(mgcp_conn.ptime)) } )); |
Harald Welte | 363cb0a | 2018-01-30 19:35:53 +0100 | [diff] [blame] | 254 | var template MgcpResponse mgcp_resp; |
| 255 | mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp); |
| 256 | f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(g_media.mgcp_ep)); |
| 257 | MGCP.send(mgcp_resp); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 258 | g_media.mgcp_conn[cid].crcx_seen := true; |
| 259 | repeat; |
| 260 | } |
| 261 | [] MGCP.receive(tr_MDCX) -> value mgcp_cmd { |
| 262 | var SDP_Message sdp; |
| 263 | var integer cid := f_get_mgcp_conn(f_MgcpCmd_extract_conn_id(mgcp_cmd)); |
| 264 | if (isvalue(mgcp_cmd.sdp)) { |
| 265 | sdp := mgcp_cmd.sdp; |
| 266 | g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr; |
| 267 | g_media.mgcp_conn[cid].peer.port_nr := sdp.media_list[0].media_field.ports.port_number; |
| 268 | } else { |
| 269 | setverdict(fail, "MDCX has no [recognizable] SDP"); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 270 | } |
| 271 | var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid]; |
| 272 | sdp := valueof(ts_SDP(mgcp_conn.peer.host, mgcp_conn.peer.host, "foo", "21", |
| 273 | mgcp_conn.peer.port_nr, { int2str(mgcp_conn.rtp_pt) }, |
| 274 | {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt, |
| 275 | mgcp_conn.mime_type & "/" & |
| 276 | int2str(mgcp_conn.sample_rate))), |
| 277 | valueof(ts_SDP_ptime(mgcp_conn.ptime)) } )); |
| 278 | 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] | 279 | //g_media.mgcp_mdcx_seen := true; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 280 | repeat; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 287 | /* this component represents a single subscriber connection at the MSC. |
| 288 | * There is a 1:1 mapping between SCCP connections and BSSAP_ConnHdlr components. |
| 289 | * We inherit all component variables, ports, functions, ... from BSSAP_ConnHdlr */ |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 290 | type component MSC_ConnHdlr extends BSSAP_ConnHdlr, RSL_DchanHdlr, MGCP_ConnHdlr { |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 291 | /* SCCP Connecction Identifier for the underlying SCCP connection */ |
| 292 | var integer g_sccp_conn_id; |
| 293 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 294 | /* procedure port back to our parent (BSSMAP_Emulation_CT) for control */ |
| 295 | port BSSMAPEM_PROC_PT BSSMAPEM; |
Harald Welte | c20b1c4 | 2018-02-12 20:50:08 +0100 | [diff] [blame] | 296 | port TELNETasp_PT BSCVTY; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 297 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 298 | var MediaState g_media; |
Harald Welte | a063003 | 2018-03-20 21:09:55 +0100 | [diff] [blame] | 299 | var TestHdlrParams g_pars; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | /* initialize all parameters */ |
| 303 | function f_MscConnHdlr_init(integer i, HostName bts, HostName mgw) runs on MSC_ConnHdlr { |
| 304 | f_MediaState_init(g_media, i, bts, mgw); |
Harald Welte | c20b1c4 | 2018-02-12 20:50:08 +0100 | [diff] [blame] | 305 | map(self:BSCVTY, system:BSCVTY); |
| 306 | f_vty_set_prompts(BSCVTY); |
| 307 | f_vty_transceive(BSCVTY, "enable"); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /* Callback function from general BSSMAP_Emulation whenever a connectionless |
| 311 | * BSSMAP message arrives. Can retunr a PDU_BSSAP that should be sent in return */ |
| 312 | private function UnitdataCallback(PDU_BSSAP bssap) |
| 313 | runs on BSSMAP_Emulation_CT return template PDU_BSSAP { |
| 314 | var template PDU_BSSAP resp := omit; |
| 315 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 316 | /* answer all RESET with a RESET ACK */ |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 317 | if (match(bssap, tr_BSSMAP_Reset)) { |
| 318 | resp := ts_BSSMAP_ResetAck; |
| 319 | } |
| 320 | |
| 321 | return resp; |
| 322 | } |
| 323 | |
| 324 | const BssmapOps MSC_BssmapOps := { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 325 | create_cb := refers(BSSMAP_Emulation.ExpectedCreateCallback), |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 326 | unitdata_cb := refers(UnitdataCallback), |
| 327 | decode_dtap := false, |
| 328 | role_ms := false |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 329 | } |
| 330 | |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 331 | const MGCPOps MSC_MGCPOps := { |
| 332 | create_cb := refers(MGCP_Emulation.ExpectedCreateCallback) |
| 333 | } |
| 334 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 335 | /* register an expect with the BSSMAP core */ |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 336 | 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] | 337 | BSSMAPEM.call(BSSMAPEM_register:{l3_enc, self}) { |
| 338 | [] BSSMAPEM.getreply(BSSMAPEM_register:{?, ?}) {}; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 339 | } |
| 340 | } |
| 341 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 342 | type record TestHdlrParams { |
| 343 | OCT1 ra, |
| 344 | GsmFrameNumber fn, |
| 345 | hexstring imsi, |
| 346 | RslLinkId link_id |
| 347 | }; |
| 348 | |
| 349 | template (value) TestHdlrParams t_def_TestHdlrPars := { |
| 350 | ra := '23'O, |
| 351 | fn := 23, |
| 352 | imsi := '001019876543210'H, |
| 353 | link_id := valueof(ts_RslLinkID_DCCH(0)) |
| 354 | } |
| 355 | |
Harald Welte | a063003 | 2018-03-20 21:09:55 +0100 | [diff] [blame] | 356 | function f_create_chan_and_exp() runs on MSC_ConnHdlr { |
| 357 | var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(g_pars.imsi)); |
Harald Welte | 6ed6bf9 | 2018-01-24 21:09:15 +0100 | [diff] [blame] | 358 | 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] | 359 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info); |
| 360 | |
| 361 | /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */ |
Harald Welte | a063003 | 2018-03-20 21:09:55 +0100 | [diff] [blame] | 362 | 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] | 363 | f_create_bssmap_exp(l3_enc); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 364 | } |
| 365 | |
Harald Welte | 898113b | 2018-01-31 18:32:21 +0100 | [diff] [blame] | 366 | function f_rsl_send_l3(template PDU_ML3_MS_NW l3, template (omit) RslLinkId link_id := omit, |
| 367 | template (omit) RslChannelNr chan_nr := omit) runs on MSC_ConnHdlr { |
| 368 | if (not isvalue(link_id)) { |
| 369 | link_id := ts_RslLinkID_DCCH(0); |
| 370 | } |
| 371 | if (not isvalue(chan_nr)) { |
| 372 | chan_nr := g_chan_nr; |
| 373 | } |
| 374 | RSL.send(ts_RSL_DATA_IND(valueof(chan_nr), valueof(link_id), enc_PDU_ML3_MS_NW(valueof(l3)))); |
| 375 | } |
| 376 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 377 | function f_rsl_reply(template PDU_ML3_MS_NW l3, RSL_Message orig) runs on MSC_ConnHdlr { |
| 378 | var RslChannelNr chan_nr := orig.ies[0].body.chan_nr; |
Harald Welte | 1a40de6 | 2017-12-23 02:28:34 +0100 | [diff] [blame] | 379 | var RslLinkId link_id; |
Harald Welte | 8d5eead | 2017-12-17 18:56:45 +0100 | [diff] [blame] | 380 | if (orig.msg_type == RSL_MT_ENCR_CMD) { |
| 381 | link_id := orig.ies[2].body.link_id; |
| 382 | } else { |
| 383 | link_id := orig.ies[1].body.link_id; |
| 384 | } |
Harald Welte | 898113b | 2018-01-31 18:32:21 +0100 | [diff] [blame] | 385 | f_rsl_send_l3(l3, link_id, chan_nr); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 388 | /* Convert the chipher representation on BSSMAP to the representation used on RSL */ |
| 389 | function f_chipher_mode_bssmap_to_rsl(OCT1 alg_bssmap) return OCT1 |
| 390 | { |
| 391 | /* A5 0 */ |
| 392 | if (alg_bssmap == '01'O) { |
| 393 | return '01'O; |
| 394 | } |
| 395 | /* A5 1 */ |
| 396 | else if (alg_bssmap == '02'O) { |
| 397 | return '02'O; |
| 398 | } |
| 399 | /* A5 2 */ |
| 400 | else if (alg_bssmap == '04'O) { |
| 401 | return '03'O; |
| 402 | } |
| 403 | /* A5 3 */ |
| 404 | else if (alg_bssmap == '08'O) { |
| 405 | return '04'O; |
| 406 | } |
| 407 | /* A5 4 */ |
| 408 | else if (alg_bssmap == '10'O) { |
| 409 | return '05'O; |
| 410 | } |
| 411 | /* A5 5 */ |
| 412 | else if (alg_bssmap == '20'O) { |
| 413 | return '06'O; |
| 414 | } |
| 415 | /* A5 6 */ |
| 416 | else if (alg_bssmap == '40'O) { |
| 417 | return '07'O; |
| 418 | } |
| 419 | /* A5 7 */ |
| 420 | else if (alg_bssmap == '80'O) { |
| 421 | return '08'O; |
| 422 | } else { |
| 423 | setverdict(fail, "Unexpected Encryption Algorithm"); |
| 424 | return '00'O; |
| 425 | } |
| 426 | } |
| 427 | |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 428 | function f_cipher_mode(OCT1 alg, OCT8 key, template OCT16 kc128 := omit, boolean exp_fail := false) |
| 429 | runs on MSC_ConnHdlr { |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 430 | var PDU_BSSAP bssap; |
| 431 | var RSL_Message rsl; |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 432 | var OCT1 alg_rsl; |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 433 | |
| 434 | if (isvalue(kc128)) { |
| 435 | BSSAP.send(ts_BSSMAP_CipherModeCmdKc128(alg, key, valueof(kc128))); |
| 436 | } else { |
| 437 | BSSAP.send(ts_BSSMAP_CipherModeCmd(alg, key)); |
| 438 | } |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 439 | |
| 440 | /* RSL uses a different representation of the encryption algorithm, |
| 441 | * so we need to convert first */ |
| 442 | alg_rsl := f_chipher_mode_bssmap_to_rsl(alg); |
| 443 | |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 444 | alt { |
| 445 | /* RSL/UE Side */ |
Philipp Maier | b20c3dc | 2018-02-07 18:36:25 +0100 | [diff] [blame] | 446 | [] 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] | 447 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[3].body.l3_info.payload); |
| 448 | log("Rx L3 from net: ", l3); |
| 449 | if (ischosen(l3.msgs.rrm.cipheringModeCommand)) { |
| 450 | f_rsl_reply(ts_RRM_CiphModeCompl, rsl); |
| 451 | } |
| 452 | repeat; |
| 453 | } |
| 454 | [] BSSAP.receive(tr_BSSMAP_CipherModeCompl) -> value bssap { |
| 455 | // bssap.bssmap.cipherModeComplete.chosenEncryptionAlgorithm.algoritmhIdentifier |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 456 | if (exp_fail == true) { |
| 457 | setverdict(fail, "Unexpected Cipher Mode Complete"); |
| 458 | } else { |
| 459 | setverdict(pass); |
| 460 | } |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 461 | } |
| 462 | [] BSSAP.receive(tr_BSSMAP_CipherModeRej) -> value bssap { |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 463 | if (exp_fail == false) { |
| 464 | setverdict(fail, "Ciphering Mode Reject"); |
| 465 | } else { |
| 466 | setverdict(pass); |
| 467 | } |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 472 | /* Convert from Ericsson ChanDesc2 format to Osmocom RslChannelNr format */ |
| 473 | function f_ChDesc2RslChanNr(ChannelDescription2_V ch_desc, out RslChannelNr chan_nr, out GsmArfcn arfcn) { |
| 474 | var BIT5 inp := ch_desc.channelTypeandTDMAOffset; |
| 475 | |
| 476 | chan_nr.tn := bit2int(ch_desc.timeslotNumber); |
| 477 | |
| 478 | if (match(inp, '00001'B)) { /* TCH/F */ |
| 479 | chan_nr.u.ch0 := RSL_CHAN_NR_Bm_ACCH; |
| 480 | } |
| 481 | else if (match(inp, '0001?'B)) { /* TCH/H */ |
| 482 | chan_nr.u.lm.sub_chan := bit2int(substr(inp, 4, 1)); |
| 483 | } |
| 484 | else if (match(inp, '001??'B)) { /* SDCCH/4 */ |
| 485 | chan_nr.u.sdcch4.sub_chan := bit2int(substr(inp, 3, 2)); |
| 486 | } |
| 487 | else if (match(inp, '01???'B)) { /* SDCCH/8 */ |
| 488 | chan_nr.u.sdcch8.sub_chan := bit2int(substr(inp, 2, 3)); |
| 489 | } |
| 490 | else { |
| 491 | setverdict(fail, "Unknown ChDesc!"); |
| 492 | self.stop; |
| 493 | } |
| 494 | |
| 495 | if (ch_desc.octet3 and4b '10'O == '10'O) { |
| 496 | setverdict(fail, "No support for Hopping"); |
| 497 | self.stop; |
| 498 | } else { |
| 499 | var OCT2 concat := ch_desc.octet3 & ch_desc.octet4; |
| 500 | arfcn := oct2int(concat); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | type record AssignmentState { |
| 505 | /* global */ |
| 506 | boolean voice_call, |
| 507 | boolean is_assignment, |
| 508 | /* Assignment related bits */ |
| 509 | boolean rr_ass_cmpl_seen, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 510 | boolean assignment_done, |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 511 | RslChannelNr old_chan_nr, |
| 512 | /* Modify related bits */ |
| 513 | boolean rr_modify_seen, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 514 | boolean modify_done |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | template (value) AssignmentState ts_AssignmentStateInit := { |
| 518 | voice_call := false, |
| 519 | is_assignment := false, |
| 520 | rr_ass_cmpl_seen := false, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 521 | assignment_done := false, |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 522 | old_chan_nr := -, |
| 523 | rr_modify_seen := false, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 524 | modify_done := false |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | altstep as_assignment(inout AssignmentState st) runs on MSC_ConnHdlr { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 528 | var RSL_Message rsl; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 529 | [not st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl { |
| 530 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload); |
| 531 | log("Rx L3 from net: ", l3); |
| 532 | if (ischosen(l3.msgs.rrm.assignmentCommand)) { |
| 533 | var RslChannelNr new_chan_nr; |
| 534 | var GsmArfcn arfcn; |
| 535 | f_ChDesc2RslChanNr(l3.msgs.rrm.assignmentCommand.descrOf1stChAfterTime, |
| 536 | new_chan_nr, arfcn); |
| 537 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 538 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 539 | /* register our component for this channel number at the RSL Emulation */ |
| 540 | f_rslem_register(0, new_chan_nr); |
| 541 | var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_AssignmentComplete('00'O)); |
| 542 | /* send assignment complete over the new channel */ |
| 543 | RSL.send(ts_RSL_DATA_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)), |
| 544 | enc_PDU_ML3_MS_NW(l3_tx))); |
| 545 | /* by default, send via the new channel from now */ |
| 546 | st.old_chan_nr := g_chan_nr; |
| 547 | g_chan_nr := new_chan_nr; |
| 548 | st.rr_ass_cmpl_seen := true; |
| 549 | repeat; |
| 550 | } else { |
| 551 | setverdict(fail, "Unexpected L3 received", l3); |
| 552 | self.stop; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 553 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 554 | } |
| 555 | [st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_REL_REQ(st.old_chan_nr, tr_RslLinkID_DCCH(0))) { |
| 556 | RSL.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0)))); |
| 557 | repeat; |
| 558 | } |
| 559 | [st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) { |
| 560 | RSL.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr)); |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 561 | /* unregister for old channel number in RSL emulation */ |
| 562 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
| 563 | f_rslem_unregister(0, st.old_chan_nr); |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 564 | st.assignment_done := true; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 565 | repeat; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | altstep as_modify(inout AssignmentState st) runs on MSC_ConnHdlr { |
| 570 | /* no assignment, just mode modify */ |
| 571 | var RSL_Message rsl; |
| 572 | |
| 573 | [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] | 574 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload); |
| 575 | log("Rx L3 from net: ", l3); |
| 576 | if (ischosen(l3.msgs.rrm.channelModeModify)) { |
| 577 | f_rsl_reply(ts_RRM_ModeModifyAck(l3.msgs.rrm.channelModeModify.channelDescription, |
| 578 | l3.msgs.rrm.channelModeModify.channelMode), rsl); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 579 | st.rr_modify_seen := true; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 580 | } |
| 581 | repeat; |
| 582 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 583 | [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] | 584 | RSL.send(ts_RSL_MODE_MODIFY_ACK(g_chan_nr)); |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 585 | st.modify_done := true; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 586 | repeat; |
| 587 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 588 | } |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 589 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 590 | /* Determine if given rsl_chan_nr is compatible with given BSSMAP ChannelType */ |
| 591 | function f_channel_compatible(BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr) |
| 592 | return boolean { |
| 593 | select (bssmap.speechOrDataIndicator) { |
| 594 | case ('0011'B) { /* Signalling */ |
| 595 | /* all channels support signalling */ |
| 596 | return true; |
| 597 | } |
| 598 | case else { /* Speech, Speech+CTM or CSD */ |
| 599 | select (bssmap.channelRateAndType) { |
| 600 | case ('08'O) { /* TCH/F */ |
| 601 | select (rsl_chan_nr) { |
| 602 | case (t_RslChanNr_Bm(?)) { return true; } |
| 603 | } |
| 604 | } |
| 605 | case ('09'O) { /* TCH/H */ |
| 606 | select (rsl_chan_nr) { |
| 607 | case (t_RslChanNr_Lm(?, ?)) { return true; } |
| 608 | } |
| 609 | } |
| 610 | case else { /* full or half-rate */ |
| 611 | select (rsl_chan_nr) { |
| 612 | case (t_RslChanNr_Bm(?)) { return true; } |
| 613 | case (t_RslChanNr_Lm(?, ?)) { return true; } |
| 614 | } |
| 615 | } |
| 616 | } |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 617 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 618 | } |
| 619 | return false; |
| 620 | } |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 621 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 622 | /* establish a channel fully, expecting an assignment matching 'exp' */ |
Harald Welte | a063003 | 2018-03-20 21:09:55 +0100 | [diff] [blame] | 623 | function f_establish_fully(PDU_BSSAP ass_cmd, template PDU_BSSAP exp_ass_cpl) |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 624 | runs on MSC_ConnHdlr return PDU_BSSAP { |
| 625 | var PDU_BSSAP bssap; |
| 626 | timer T := 10.0; |
| 627 | var boolean exp_compl := ischosen(exp_ass_cpl.pdu.bssmap.assignmentComplete); |
Philipp Maier | 86f3920 | 2018-02-07 14:40:09 +0100 | [diff] [blame] | 628 | var boolean exp_fail := ischosen(exp_ass_cpl.pdu.bssmap.assignmentFailure); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 629 | var ExpectCriteria mgcpcrit := { |
| 630 | connid := omit, |
| 631 | endpoint := omit, |
| 632 | transid := omit |
| 633 | }; |
| 634 | var AssignmentState st := valueof(ts_AssignmentStateInit); |
| 635 | /* if the channel type is SIGNAL, we're not handling a voice call */ |
| 636 | if (ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechOrDataIndicator != '0011'B) { |
| 637 | st.voice_call := true; |
| 638 | } |
| 639 | /* determine if the current channel can support the given service or not */ |
| 640 | if (not f_channel_compatible(ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr)) { |
| 641 | st.is_assignment := true; |
| 642 | } |
| 643 | |
Harald Welte | c20b1c4 | 2018-02-12 20:50:08 +0100 | [diff] [blame] | 644 | f_MscConnHdlr_init(1, "127.0.0.2", "127.0.0.3"); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 645 | |
Harald Welte | a063003 | 2018-03-20 21:09:55 +0100 | [diff] [blame] | 646 | f_create_chan_and_exp(); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 647 | /* we should now have a COMPL_L3 at the MSC */ |
| 648 | BSSAP.receive(tr_BSSMAP_ComplL3); |
| 649 | f_create_mgcp_expect(mgcpcrit); |
| 650 | BSSAP.send(ass_cmd); |
| 651 | |
| 652 | T.start; |
| 653 | alt { |
| 654 | /* assignment related bits */ |
| 655 | [st.is_assignment] as_assignment(st); |
| 656 | |
| 657 | /* modify related bits */ |
| 658 | [not st.is_assignment] as_modify(st); |
| 659 | |
| 660 | /* voice call related bits (IPA CRCX/MDCX + MGCP) */ |
| 661 | [st.voice_call] as_Media(); |
| 662 | |
| 663 | /* if we receive exactly what we expected, always return + pass */ |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 664 | [st.is_assignment and st.assignment_done or |
| 665 | (not st.is_assignment and st.modify_done)] BSSAP.receive(exp_ass_cpl) -> value bssap { |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 666 | setverdict(pass); |
| 667 | } |
Philipp Maier | 86f3920 | 2018-02-07 14:40:09 +0100 | [diff] [blame] | 668 | [exp_fail] BSSAP.receive(exp_ass_cpl) -> value bssap { |
| 669 | setverdict(pass); |
| 670 | } |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 671 | [(st.is_assignment and st.assignment_done or |
| 672 | (not st.is_assignment and st.modify_done)) and |
| 673 | exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 674 | setverdict(fail, "Received non-matching ASSIGNMENT COMPLETE"); |
| 675 | } |
| 676 | [exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) { |
| 677 | setverdict(fail, "Received unexpected ASSIGNMENT FAIL"); |
| 678 | } |
| 679 | [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) { |
| 680 | setverdict(fail, "Received unexpected ASSIGNMENT COMPLETE"); |
| 681 | } |
| 682 | [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) { |
| 683 | setverdict(fail, "Received non-matching ASSIGNMENT FAIL"); |
| 684 | } |
| 685 | [] T.timeout { |
Harald Welte | 458fd37 | 2018-03-21 11:26:23 +0100 | [diff] [blame] | 686 | setverdict(fail, "Timeout waiting for ASSIGNMENT COMPLETE"); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 687 | } |
| 688 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 689 | log("g_media ", g_media); |
| 690 | if (not isbound(bssap)) { |
| 691 | self.stop; |
| 692 | } |
| 693 | return bssap; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 694 | } |
| 695 | |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 696 | type record HandoverState { |
| 697 | /* Assignment related bits */ |
| 698 | boolean rr_ho_cmpl_seen, |
| 699 | boolean handover_done, |
| 700 | RslChannelNr old_chan_nr |
| 701 | }; |
| 702 | |
| 703 | altstep as_handover(inout HandoverState st) runs on MSC_ConnHdlr { |
| 704 | var RSL_Message rsl; |
| 705 | [not st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl { |
| 706 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload); |
| 707 | log("Rx L3 from net: ", l3); |
| 708 | if (ischosen(l3.msgs.rrm.handoverCommand)) { |
| 709 | var RslChannelNr new_chan_nr; |
| 710 | var GsmArfcn arfcn; |
| 711 | f_ChDesc2RslChanNr(l3.msgs.rrm.handoverCommand.channelDescription2, |
| 712 | new_chan_nr, arfcn); |
| 713 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
| 714 | |
| 715 | /* register our component for this channel number at the RSL Emulation */ |
| 716 | f_rslem_register(0, new_chan_nr, RSL1_PROC); |
| 717 | |
| 718 | /* resume processing of RSL DChan messages, which was temporarily suspended |
| 719 | * before performing a hand-over */ |
| 720 | f_rslem_resume(RSL1_PROC); |
| 721 | |
| 722 | /* send handover complete over the new channel */ |
| 723 | var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_HandoverComplete('00'O)); |
| 724 | RSL1.send(ts_RSL_DATA_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)), |
| 725 | enc_PDU_ML3_MS_NW(l3_tx))); |
| 726 | /* by default, send via the new channel from now */ |
| 727 | st.old_chan_nr := g_chan_nr; |
| 728 | g_chan_nr := new_chan_nr; |
| 729 | st.rr_ho_cmpl_seen := true; |
| 730 | repeat; |
| 731 | } else { |
| 732 | setverdict(fail, "Unexpected L3 received", l3); |
| 733 | self.stop; |
| 734 | } |
| 735 | } |
| 736 | [st.rr_ho_cmpl_seen] as_Media(); |
| 737 | [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_REL_REQ(st.old_chan_nr, tr_RslLinkID_DCCH(0))) { |
| 738 | RSL.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0)))); |
| 739 | repeat; |
| 740 | } |
| 741 | [st.rr_ho_cmpl_seen] RSL.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) { |
| 742 | RSL.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr)); |
| 743 | /* unregister for old channel number in RSL emulation */ |
| 744 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
| 745 | f_rslem_unregister(0, st.old_chan_nr); |
| 746 | st.handover_done := true; |
Harald Welte | 261af4b | 2018-02-12 21:20:39 +0100 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
| 750 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 751 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 752 | } |