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 | |
| 27 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 28 | /*********************************************************************** |
| 29 | * Media related handling |
| 30 | ***********************************************************************/ |
| 31 | |
| 32 | /* Tuple containing host/ip and port */ |
| 33 | type record HostPort { |
| 34 | HostName host, |
| 35 | PortNumber port_nr |
| 36 | }; |
| 37 | |
| 38 | /* State encapsulating one MGCP Connection */ |
| 39 | type record MgcpConnState { |
| 40 | boolean crcx_seen, |
| 41 | MgcpConnectionId conn_id, |
| 42 | charstring mime_type, /* e.g. AMR */ |
| 43 | integer sample_rate, /* 8000 */ |
| 44 | integer ptime, /* 20 */ |
| 45 | uint7_t rtp_pt, /* RTP Payload Type */ |
| 46 | HostPort mgw, /* MGW side */ |
| 47 | HostPort peer /* CA side */ |
| 48 | }; |
| 49 | |
| 50 | /* BTS media state */ |
| 51 | type record BtsMediaState { |
| 52 | boolean ipa_crcx_seen, |
| 53 | uint16_t conn_id, |
| 54 | uint7_t rtp_pt, |
| 55 | HostPort bts, |
| 56 | HostPort peer |
| 57 | }; |
| 58 | |
| 59 | type record MediaState { |
| 60 | MgcpEndpoint mgcp_ep, |
| 61 | MgcpConnState mgcp_conn[2], |
| 62 | BtsMediaState bts |
| 63 | }; |
| 64 | |
| 65 | function f_MediaState_init(inout MediaState g_media, integer nr, HostName bts, HostName mgw) { |
| 66 | /* BTS Side */ |
| 67 | g_media.bts := { |
| 68 | ipa_crcx_seen := false, |
| 69 | conn_id := nr, |
| 70 | rtp_pt := 0, |
| 71 | bts := { |
| 72 | host := bts, |
| 73 | port_nr := 9000 + nr*2 |
| 74 | }, |
| 75 | peer := - |
| 76 | } |
| 77 | |
Harald Welte | 363cb0a | 2018-01-30 19:35:53 +0100 | [diff] [blame] | 78 | g_media.mgcp_ep := "rtpbridge/" & int2str(nr) & "@mgw"; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 79 | |
| 80 | for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) { |
| 81 | g_media.mgcp_conn[i].mime_type := "AMR"; |
| 82 | g_media.mgcp_conn[i].sample_rate := 8000; |
| 83 | g_media.mgcp_conn[i].ptime := 20; |
| 84 | g_media.mgcp_conn[i].rtp_pt := 98; |
| 85 | g_media.mgcp_conn[i].crcx_seen := false; |
| 86 | g_media.mgcp_conn[i].conn_id := f_mgcp_alloc_conn_id(); |
| 87 | } |
| 88 | |
| 89 | g_media.mgcp_conn[0].mgw := { |
| 90 | host := mgw, |
| 91 | port_nr := 10000 + nr*2 |
| 92 | } |
| 93 | g_media.mgcp_conn[1].mgw := { |
| 94 | host := mgw, |
| 95 | port_nr := 11000 + nr*2 |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | private function f_get_free_mgcp_conn() runs on MSC_ConnHdlr return integer { |
| 100 | for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) { |
| 101 | if (not g_media.mgcp_conn[i].crcx_seen) { |
| 102 | return i; |
| 103 | } |
| 104 | } |
| 105 | setverdict(fail, "Only 2 Connections per EP!"); |
| 106 | self.stop; |
| 107 | return -1; |
| 108 | } |
| 109 | |
| 110 | private function f_get_mgcp_conn(MgcpConnectionId cid) runs on MSC_ConnHdlr return integer { |
| 111 | for (var integer i:= 0; i < sizeof(g_media.mgcp_conn); i := i+1) { |
| 112 | if (g_media.mgcp_conn[i].conn_id == cid and g_media.mgcp_conn[i].crcx_seen) { |
| 113 | return i; |
| 114 | } |
| 115 | } |
| 116 | setverdict(fail, "No Connection for ID ", cid); |
| 117 | self.stop; |
| 118 | return -1; |
| 119 | } |
| 120 | |
| 121 | |
| 122 | /* altstep for handling of IPA + MGCP media related commands. Can be activated by a given |
| 123 | * test case if it expects to see media related handling (i.e. voice calls */ |
| 124 | altstep as_Media() runs on MSC_ConnHdlr { |
| 125 | var RSL_Message rsl; |
| 126 | var MgcpCommand mgcp_cmd; |
| 127 | var RSL_IE_Body ie; |
| 128 | [not g_media.bts.ipa_crcx_seen] RSL.receive(tr_RSL_IPA_CRCX(g_chan_nr)) -> value rsl { |
| 129 | /* Extract parameters from request + use in response */ |
| 130 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 131 | g_media.bts.rtp_pt := ie.ipa_rtp_pt; |
| 132 | } |
| 133 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 134 | g_media.bts.rtp_pt := ie.ipa_rtp_pt2; |
| 135 | } |
| 136 | RSL.send(ts_RSL_IPA_CRCX_ACK(g_chan_nr, g_media.bts.conn_id, |
| 137 | oct2int(f_inet_addr(g_media.bts.bts.host)), |
| 138 | g_media.bts.bts.port_nr, |
| 139 | g_media.bts.rtp_pt)); |
| 140 | g_media.bts.ipa_crcx_seen := true; |
| 141 | repeat; |
| 142 | } |
| 143 | [g_media.bts.ipa_crcx_seen] RSL.receive(tr_RSL_IPA_MDCX(g_chan_nr, ?)) -> value rsl{ |
| 144 | /* Extract conn_id, ip, port, rtp_pt2 from request + use in response */ |
| 145 | f_rsl_find_ie(rsl, RSL_IE_IPAC_CONN_ID, ie); |
| 146 | if (g_media.bts.conn_id != ie.ipa_conn_id) { |
| 147 | setverdict(fail, "IPA MDCX for unknown ConnId", rsl); |
| 148 | self.stop; |
| 149 | } |
| 150 | /* mandatory */ |
| 151 | f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_IP, ie); |
| 152 | g_media.bts.peer.host := f_inet_ntoa(int2oct(ie.ipa_remote_ip, 4)); |
| 153 | f_rsl_find_ie(rsl, RSL_IE_IPAC_REMOTE_PORT, ie); |
| 154 | g_media.bts.peer.port_nr := ie.ipa_remote_port; |
| 155 | /* optional */ |
| 156 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD, ie)) { |
| 157 | g_media.bts.rtp_pt := ie.ipa_rtp_pt; |
| 158 | } |
| 159 | if (f_rsl_find_ie(rsl, RSL_IE_IPAC_RTP_PAYLOAD2, ie)) { |
| 160 | g_media.bts.rtp_pt := ie.ipa_rtp_pt2; |
| 161 | } |
| 162 | RSL.send(ts_RSL_IPA_MDCX_ACK(g_chan_nr, g_media.bts.conn_id, |
| 163 | oct2int(f_inet_addr(g_media.bts.peer.host)), |
| 164 | g_media.bts.peer.port_nr, |
| 165 | g_media.bts.rtp_pt)); |
| 166 | //g_media.ipa_mdcx_seen := true; |
| 167 | repeat; |
| 168 | } |
| 169 | [] MGCP.receive(tr_CRCX) -> value mgcp_cmd { |
| 170 | var SDP_Message sdp; |
| 171 | var integer cid := f_get_free_mgcp_conn(); |
Harald Welte | 363cb0a | 2018-01-30 19:35:53 +0100 | [diff] [blame] | 172 | if (match(mgcp_cmd.line.ep, t_MGCP_EP_wildcard)) { |
| 173 | if (cid != 0) { |
| 174 | setverdict(fail, "MGCP wildcard EP only works in first CRCX"); |
| 175 | self.stop; |
| 176 | } |
| 177 | /* we keep the endpoint name allocated during MediaState_init */ |
| 178 | } else { |
| 179 | /* Call Agent allocated endpoint, trust/use it always */ |
| 180 | g_media.mgcp_ep := mgcp_cmd.line.ep; |
| 181 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 182 | if (isvalue(mgcp_cmd.sdp)) { |
| 183 | sdp := mgcp_cmd.sdp; |
| 184 | g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr; |
| 185 | g_media.mgcp_conn[cid].peer.port_nr := sdp.media_list[0].media_field.ports.port_number; |
| 186 | } |
| 187 | var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid]; |
| 188 | sdp := valueof(ts_SDP(mgcp_conn.mgw.host, mgcp_conn.mgw.host, "foo", "21", |
| 189 | mgcp_conn.mgw.port_nr, { int2str(mgcp_conn.rtp_pt) }, |
| 190 | {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt, |
| 191 | mgcp_conn.mime_type & "/" & |
| 192 | int2str(mgcp_conn.sample_rate))), |
| 193 | valueof(ts_SDP_ptime(mgcp_conn.ptime)) } )); |
Harald Welte | 363cb0a | 2018-01-30 19:35:53 +0100 | [diff] [blame] | 194 | var template MgcpResponse mgcp_resp; |
| 195 | mgcp_resp := ts_CRCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp); |
| 196 | f_mgcp_par_append(mgcp_resp.params, ts_MgcpParSpecEP(g_media.mgcp_ep)); |
| 197 | MGCP.send(mgcp_resp); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 198 | g_media.mgcp_conn[cid].crcx_seen := true; |
| 199 | repeat; |
| 200 | } |
| 201 | [] MGCP.receive(tr_MDCX) -> value mgcp_cmd { |
| 202 | var SDP_Message sdp; |
| 203 | var integer cid := f_get_mgcp_conn(f_MgcpCmd_extract_conn_id(mgcp_cmd)); |
| 204 | if (isvalue(mgcp_cmd.sdp)) { |
| 205 | sdp := mgcp_cmd.sdp; |
| 206 | g_media.mgcp_conn[cid].peer.host := sdp.connection.conn_addr.addr; |
| 207 | g_media.mgcp_conn[cid].peer.port_nr := sdp.media_list[0].media_field.ports.port_number; |
| 208 | } else { |
| 209 | setverdict(fail, "MDCX has no [recognizable] SDP"); |
| 210 | /* HACK HACK HACK */ |
| 211 | g_media.mgcp_conn[cid].peer.host := "8.8.8.8"; |
| 212 | g_media.mgcp_conn[cid].peer.port_nr := 2342; |
| 213 | } |
| 214 | var MgcpConnState mgcp_conn := g_media.mgcp_conn[cid]; |
| 215 | sdp := valueof(ts_SDP(mgcp_conn.peer.host, mgcp_conn.peer.host, "foo", "21", |
| 216 | mgcp_conn.peer.port_nr, { int2str(mgcp_conn.rtp_pt) }, |
| 217 | {valueof(ts_SDP_rtpmap(mgcp_conn.rtp_pt, |
| 218 | mgcp_conn.mime_type & "/" & |
| 219 | int2str(mgcp_conn.sample_rate))), |
| 220 | valueof(ts_SDP_ptime(mgcp_conn.ptime)) } )); |
| 221 | MGCP.send(ts_MDCX_ACK(mgcp_cmd.line.trans_id, mgcp_conn.conn_id, sdp)); |
| 222 | //mgcp_mdcx_seen := true; |
| 223 | repeat; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 230 | /* this component represents a single subscriber connection at the MSC. |
| 231 | * There is a 1:1 mapping between SCCP connections and BSSAP_ConnHdlr components. |
| 232 | * We inherit all component variables, ports, functions, ... from BSSAP_ConnHdlr */ |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 233 | type component MSC_ConnHdlr extends BSSAP_ConnHdlr, RSL_DchanHdlr, MGCP_ConnHdlr { |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 234 | /* SCCP Connecction Identifier for the underlying SCCP connection */ |
| 235 | var integer g_sccp_conn_id; |
| 236 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 237 | /* procedure port back to our parent (BSSMAP_Emulation_CT) for control */ |
| 238 | port BSSMAPEM_PROC_PT BSSMAPEM; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 239 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 240 | var MediaState g_media; |
| 241 | } |
| 242 | |
| 243 | /* initialize all parameters */ |
| 244 | function f_MscConnHdlr_init(integer i, HostName bts, HostName mgw) runs on MSC_ConnHdlr { |
| 245 | f_MediaState_init(g_media, i, bts, mgw); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /* Callback function from general BSSMAP_Emulation whenever a connectionless |
| 249 | * BSSMAP message arrives. Can retunr a PDU_BSSAP that should be sent in return */ |
| 250 | private function UnitdataCallback(PDU_BSSAP bssap) |
| 251 | runs on BSSMAP_Emulation_CT return template PDU_BSSAP { |
| 252 | var template PDU_BSSAP resp := omit; |
| 253 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 254 | /* answer all RESET with a RESET ACK */ |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 255 | if (match(bssap, tr_BSSMAP_Reset)) { |
| 256 | resp := ts_BSSMAP_ResetAck; |
| 257 | } |
| 258 | |
| 259 | return resp; |
| 260 | } |
| 261 | |
| 262 | const BssmapOps MSC_BssmapOps := { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 263 | create_cb := refers(BSSMAP_Emulation.ExpectedCreateCallback), |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 264 | unitdata_cb := refers(UnitdataCallback), |
| 265 | decode_dtap := false, |
| 266 | role_ms := false |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 267 | } |
| 268 | |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 269 | const MGCPOps MSC_MGCPOps := { |
| 270 | create_cb := refers(MGCP_Emulation.ExpectedCreateCallback) |
| 271 | } |
| 272 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 273 | /* register an expect with the BSSMAP core */ |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 274 | 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] | 275 | BSSMAPEM.call(BSSMAPEM_register:{l3_enc, self}) { |
| 276 | [] BSSMAPEM.getreply(BSSMAPEM_register:{?, ?}) {}; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 280 | type record TestHdlrParams { |
| 281 | OCT1 ra, |
| 282 | GsmFrameNumber fn, |
| 283 | hexstring imsi, |
| 284 | RslLinkId link_id |
| 285 | }; |
| 286 | |
| 287 | template (value) TestHdlrParams t_def_TestHdlrPars := { |
| 288 | ra := '23'O, |
| 289 | fn := 23, |
| 290 | imsi := '001019876543210'H, |
| 291 | link_id := valueof(ts_RslLinkID_DCCH(0)) |
| 292 | } |
| 293 | |
| 294 | function f_create_chan_and_exp(TestHdlrParams pars) runs on MSC_ConnHdlr { |
| 295 | var MobileIdentityLV mi := valueof(ts_MI_IMSI_LV(pars.imsi)); |
Harald Welte | 6ed6bf9 | 2018-01-24 21:09:15 +0100 | [diff] [blame] | 296 | 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] | 297 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(l3_info); |
| 298 | |
| 299 | /* call helper function for CHAN_RQD -> IMM ASS ->EST_IND */ |
| 300 | RSL_Emulation.f_chan_est(pars.ra, l3_enc, pars.link_id, pars.fn); |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 301 | f_create_bssmap_exp(l3_enc); |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | function f_rsl_reply(template PDU_ML3_MS_NW l3, RSL_Message orig) runs on MSC_ConnHdlr { |
| 305 | var RslChannelNr chan_nr := orig.ies[0].body.chan_nr; |
Harald Welte | 1a40de6 | 2017-12-23 02:28:34 +0100 | [diff] [blame] | 306 | var RslLinkId link_id; |
Harald Welte | 8d5eead | 2017-12-17 18:56:45 +0100 | [diff] [blame] | 307 | if (orig.msg_type == RSL_MT_ENCR_CMD) { |
| 308 | link_id := orig.ies[2].body.link_id; |
| 309 | } else { |
| 310 | link_id := orig.ies[1].body.link_id; |
| 311 | } |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 312 | RSL.send(ts_RSL_DATA_IND(chan_nr, link_id, enc_PDU_ML3_MS_NW(valueof(l3)))); |
| 313 | } |
| 314 | |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 315 | function f_cipher_mode(OCT1 alg, OCT8 key, template OCT16 kc128 := omit, boolean exp_fail := false) |
| 316 | runs on MSC_ConnHdlr { |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 317 | var PDU_BSSAP bssap; |
| 318 | var RSL_Message rsl; |
| 319 | |
| 320 | if (isvalue(kc128)) { |
| 321 | BSSAP.send(ts_BSSMAP_CipherModeCmdKc128(alg, key, valueof(kc128))); |
| 322 | } else { |
| 323 | BSSAP.send(ts_BSSMAP_CipherModeCmd(alg, key)); |
| 324 | } |
| 325 | alt { |
| 326 | /* RSL/UE Side */ |
| 327 | [] RSL.receive(tr_RSL_ENCR_CMD(g_chan_nr, ?, alg, key)) -> value rsl { |
| 328 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[3].body.l3_info.payload); |
| 329 | log("Rx L3 from net: ", l3); |
| 330 | if (ischosen(l3.msgs.rrm.cipheringModeCommand)) { |
| 331 | f_rsl_reply(ts_RRM_CiphModeCompl, rsl); |
| 332 | } |
| 333 | repeat; |
| 334 | } |
| 335 | [] BSSAP.receive(tr_BSSMAP_CipherModeCompl) -> value bssap { |
| 336 | // bssap.bssmap.cipherModeComplete.chosenEncryptionAlgorithm.algoritmhIdentifier |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 337 | if (exp_fail == true) { |
| 338 | setverdict(fail, "Unexpected Cipher Mode Complete"); |
| 339 | } else { |
| 340 | setverdict(pass); |
| 341 | } |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 342 | } |
| 343 | [] BSSAP.receive(tr_BSSMAP_CipherModeRej) -> value bssap { |
Harald Welte | 38b2a10 | 2017-12-23 02:42:58 +0100 | [diff] [blame] | 344 | if (exp_fail == false) { |
| 345 | setverdict(fail, "Ciphering Mode Reject"); |
| 346 | } else { |
| 347 | setverdict(pass); |
| 348 | } |
Harald Welte | 73cd271 | 2017-12-17 00:44:52 +0100 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | } |
| 352 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 353 | /* Convert from Ericsson ChanDesc2 format to Osmocom RslChannelNr format */ |
| 354 | function f_ChDesc2RslChanNr(ChannelDescription2_V ch_desc, out RslChannelNr chan_nr, out GsmArfcn arfcn) { |
| 355 | var BIT5 inp := ch_desc.channelTypeandTDMAOffset; |
| 356 | |
| 357 | chan_nr.tn := bit2int(ch_desc.timeslotNumber); |
| 358 | |
| 359 | if (match(inp, '00001'B)) { /* TCH/F */ |
| 360 | chan_nr.u.ch0 := RSL_CHAN_NR_Bm_ACCH; |
| 361 | } |
| 362 | else if (match(inp, '0001?'B)) { /* TCH/H */ |
| 363 | chan_nr.u.lm.sub_chan := bit2int(substr(inp, 4, 1)); |
| 364 | } |
| 365 | else if (match(inp, '001??'B)) { /* SDCCH/4 */ |
| 366 | chan_nr.u.sdcch4.sub_chan := bit2int(substr(inp, 3, 2)); |
| 367 | } |
| 368 | else if (match(inp, '01???'B)) { /* SDCCH/8 */ |
| 369 | chan_nr.u.sdcch8.sub_chan := bit2int(substr(inp, 2, 3)); |
| 370 | } |
| 371 | else { |
| 372 | setverdict(fail, "Unknown ChDesc!"); |
| 373 | self.stop; |
| 374 | } |
| 375 | |
| 376 | if (ch_desc.octet3 and4b '10'O == '10'O) { |
| 377 | setverdict(fail, "No support for Hopping"); |
| 378 | self.stop; |
| 379 | } else { |
| 380 | var OCT2 concat := ch_desc.octet3 & ch_desc.octet4; |
| 381 | arfcn := oct2int(concat); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | type record AssignmentState { |
| 386 | /* global */ |
| 387 | boolean voice_call, |
| 388 | boolean is_assignment, |
| 389 | /* Assignment related bits */ |
| 390 | boolean rr_ass_cmpl_seen, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 391 | boolean assignment_done, |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 392 | RslChannelNr old_chan_nr, |
| 393 | /* Modify related bits */ |
| 394 | boolean rr_modify_seen, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 395 | boolean modify_done |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | template (value) AssignmentState ts_AssignmentStateInit := { |
| 399 | voice_call := false, |
| 400 | is_assignment := false, |
| 401 | rr_ass_cmpl_seen := false, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 402 | assignment_done := false, |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 403 | old_chan_nr := -, |
| 404 | rr_modify_seen := false, |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 405 | modify_done := false |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | altstep as_assignment(inout AssignmentState st) runs on MSC_ConnHdlr { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 409 | var RSL_Message rsl; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 410 | [not st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_DATA_REQ(g_chan_nr)) -> value rsl { |
| 411 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload); |
| 412 | log("Rx L3 from net: ", l3); |
| 413 | if (ischosen(l3.msgs.rrm.assignmentCommand)) { |
| 414 | var RslChannelNr new_chan_nr; |
| 415 | var GsmArfcn arfcn; |
| 416 | f_ChDesc2RslChanNr(l3.msgs.rrm.assignmentCommand.descrOf1stChAfterTime, |
| 417 | new_chan_nr, arfcn); |
| 418 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 419 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 420 | /* register our component for this channel number at the RSL Emulation */ |
| 421 | f_rslem_register(0, new_chan_nr); |
| 422 | var PDU_ML3_MS_NW l3_tx := valueof(ts_RRM_AssignmentComplete('00'O)); |
| 423 | /* send assignment complete over the new channel */ |
| 424 | RSL.send(ts_RSL_DATA_IND(new_chan_nr, valueof(ts_RslLinkID_DCCH(0)), |
| 425 | enc_PDU_ML3_MS_NW(l3_tx))); |
| 426 | /* by default, send via the new channel from now */ |
| 427 | st.old_chan_nr := g_chan_nr; |
| 428 | g_chan_nr := new_chan_nr; |
| 429 | st.rr_ass_cmpl_seen := true; |
| 430 | repeat; |
| 431 | } else { |
| 432 | setverdict(fail, "Unexpected L3 received", l3); |
| 433 | self.stop; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 434 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 435 | } |
| 436 | [st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_REL_REQ(st.old_chan_nr, tr_RslLinkID_DCCH(0))) { |
| 437 | RSL.send(ts_RSL_REL_CONF(st.old_chan_nr, valueof(ts_RslLinkID_DCCH(0)))); |
| 438 | repeat; |
| 439 | } |
| 440 | [st.rr_ass_cmpl_seen] RSL.receive(tr_RSL_RF_CHAN_REL(st.old_chan_nr)) { |
| 441 | RSL.send(ts_RSL_RF_CHAN_REL_ACK(st.old_chan_nr)); |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 442 | /* unregister for old channel number in RSL emulation */ |
| 443 | /* FIXME: Determine TRX NR by ARFCN, instead of hard-coded TRX0! */ |
| 444 | f_rslem_unregister(0, st.old_chan_nr); |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 445 | st.assignment_done := true; |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 446 | repeat; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | altstep as_modify(inout AssignmentState st) runs on MSC_ConnHdlr { |
| 451 | /* no assignment, just mode modify */ |
| 452 | var RSL_Message rsl; |
| 453 | |
| 454 | [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] | 455 | var PDU_ML3_NW_MS l3 := dec_PDU_ML3_NW_MS(rsl.ies[2].body.l3_info.payload); |
| 456 | log("Rx L3 from net: ", l3); |
| 457 | if (ischosen(l3.msgs.rrm.channelModeModify)) { |
| 458 | f_rsl_reply(ts_RRM_ModeModifyAck(l3.msgs.rrm.channelModeModify.channelDescription, |
| 459 | l3.msgs.rrm.channelModeModify.channelMode), rsl); |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 460 | st.rr_modify_seen := true; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 461 | } |
| 462 | repeat; |
| 463 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 464 | [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] | 465 | RSL.send(ts_RSL_MODE_MODIFY_ACK(g_chan_nr)); |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 466 | st.modify_done := true; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 467 | repeat; |
| 468 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 469 | } |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 470 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 471 | /* Determine if given rsl_chan_nr is compatible with given BSSMAP ChannelType */ |
| 472 | function f_channel_compatible(BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr) |
| 473 | return boolean { |
| 474 | select (bssmap.speechOrDataIndicator) { |
| 475 | case ('0011'B) { /* Signalling */ |
| 476 | /* all channels support signalling */ |
| 477 | return true; |
| 478 | } |
| 479 | case else { /* Speech, Speech+CTM or CSD */ |
| 480 | select (bssmap.channelRateAndType) { |
| 481 | case ('08'O) { /* TCH/F */ |
| 482 | select (rsl_chan_nr) { |
| 483 | case (t_RslChanNr_Bm(?)) { return true; } |
| 484 | } |
| 485 | } |
| 486 | case ('09'O) { /* TCH/H */ |
| 487 | select (rsl_chan_nr) { |
| 488 | case (t_RslChanNr_Lm(?, ?)) { return true; } |
| 489 | } |
| 490 | } |
| 491 | case else { /* full or half-rate */ |
| 492 | select (rsl_chan_nr) { |
| 493 | case (t_RslChanNr_Bm(?)) { return true; } |
| 494 | case (t_RslChanNr_Lm(?, ?)) { return true; } |
| 495 | } |
| 496 | } |
| 497 | } |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 498 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 499 | } |
| 500 | return false; |
| 501 | } |
Daniel Willmann | 191e0d9 | 2018-01-17 12:44:35 +0100 | [diff] [blame] | 502 | |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 503 | /* establish a channel fully, expecting an assignment matching 'exp' */ |
| 504 | function f_establish_fully(TestHdlrParams pars, PDU_BSSAP ass_cmd, template PDU_BSSAP exp_ass_cpl) |
| 505 | runs on MSC_ConnHdlr return PDU_BSSAP { |
| 506 | var PDU_BSSAP bssap; |
| 507 | timer T := 10.0; |
| 508 | var boolean exp_compl := ischosen(exp_ass_cpl.pdu.bssmap.assignmentComplete); |
| 509 | var ExpectCriteria mgcpcrit := { |
| 510 | connid := omit, |
| 511 | endpoint := omit, |
| 512 | transid := omit |
| 513 | }; |
| 514 | var AssignmentState st := valueof(ts_AssignmentStateInit); |
| 515 | /* if the channel type is SIGNAL, we're not handling a voice call */ |
| 516 | if (ass_cmd.pdu.bssmap.assignmentRequest.channelType.speechOrDataIndicator != '0011'B) { |
| 517 | st.voice_call := true; |
| 518 | } |
| 519 | /* determine if the current channel can support the given service or not */ |
| 520 | if (not f_channel_compatible(ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr)) { |
| 521 | st.is_assignment := true; |
| 522 | } |
| 523 | |
| 524 | f_MediaState_init(g_media, 1, "127.0.0.2", "127.0.0.3"); |
| 525 | |
| 526 | f_create_chan_and_exp(pars); |
| 527 | /* we should now have a COMPL_L3 at the MSC */ |
| 528 | BSSAP.receive(tr_BSSMAP_ComplL3); |
| 529 | f_create_mgcp_expect(mgcpcrit); |
| 530 | BSSAP.send(ass_cmd); |
| 531 | |
| 532 | T.start; |
| 533 | alt { |
| 534 | /* assignment related bits */ |
| 535 | [st.is_assignment] as_assignment(st); |
| 536 | |
| 537 | /* modify related bits */ |
| 538 | [not st.is_assignment] as_modify(st); |
| 539 | |
| 540 | /* voice call related bits (IPA CRCX/MDCX + MGCP) */ |
| 541 | [st.voice_call] as_Media(); |
| 542 | |
| 543 | /* if we receive exactly what we expected, always return + pass */ |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 544 | [st.is_assignment and st.assignment_done or |
| 545 | (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] | 546 | setverdict(pass); |
| 547 | } |
Harald Welte | 2158308 | 2018-01-29 22:28:26 +0100 | [diff] [blame] | 548 | [(st.is_assignment and st.assignment_done or |
| 549 | (not st.is_assignment and st.modify_done)) and |
| 550 | exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) { |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 551 | setverdict(fail, "Received non-matching ASSIGNMENT COMPLETE"); |
| 552 | } |
| 553 | [exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) { |
| 554 | setverdict(fail, "Received unexpected ASSIGNMENT FAIL"); |
| 555 | } |
| 556 | [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentComplete) { |
| 557 | setverdict(fail, "Received unexpected ASSIGNMENT COMPLETE"); |
| 558 | } |
| 559 | [not exp_compl] BSSAP.receive(tr_BSSMAP_AssignmentFail) { |
| 560 | setverdict(fail, "Received non-matching ASSIGNMENT FAIL"); |
| 561 | } |
| 562 | [] T.timeout { |
| 563 | setverdict(inconc, "Timeout waiting for ASSIGNMENT COMPLETE"); |
| 564 | } |
| 565 | } |
Harald Welte | 211219e | 2018-01-29 22:03:36 +0100 | [diff] [blame] | 566 | log("g_media ", g_media); |
| 567 | if (not isbound(bssap)) { |
| 568 | self.stop; |
| 569 | } |
| 570 | return bssap; |
Harald Welte | c1a2fff | 2017-12-17 11:06:19 +0100 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 574 | } |