Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 1 | module MNCC_Emulation { |
| 2 | |
| 3 | /* MNCC Emulation, runs on top of MNCC_CodecPort. It multiplexes/demultiplexes |
| 4 | * the individual calls, so there can be separate TTCN-3 components handling |
| 5 | * each of the calls |
| 6 | * |
| 7 | * The MNCC_Emulation.main() function processes MNCC primitives from the MNCC |
| 8 | * socket via the MNCC_CodecPort, and dispatches them to the per-connection components. |
| 9 | * |
| 10 | * Outbound MNCC connections are initiated by sending a MNCC_Call_Req primitive |
| 11 | * to the component running the MNCC_Emulation.main() function. |
| 12 | * |
| 13 | * For each new inbound connections, the MnccOps.create_cb() is called. It can create |
| 14 | * or resolve a TTCN-3 component, and returns a component reference to which that inbound |
| 15 | * connection is routed/dispatched. |
| 16 | * |
| 17 | * If a pre-existing component wants to register to handle a future inbound call, it can |
| 18 | * do so by registering an "expect" with the expected destination phone number. This is e.g. useful |
| 19 | * if you are simulating BSC + MNCC, and first trigger a connection from BSC side in a |
| 20 | * component which then subsequently should also handle the MNCC emulation. |
| 21 | * |
| 22 | * Inbound Unit Data messages (such as are dispatched to the MnccOps.unitdata_cb() callback, |
| 23 | * which is registered with an argument to the main() function below. |
| 24 | * |
| 25 | * (C) 2018 by Harald Welte <laforge@gnumonks.org> |
| 26 | * All rights reserved. |
| 27 | * |
| 28 | * Released under the terms of GNU General Public License, Version 2 or |
| 29 | * (at your option) any later version. |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 30 | * |
| 31 | * SPDX-License-Identifier: GPL-2.0-or-later |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 32 | */ |
| 33 | |
| 34 | |
| 35 | import from Osmocom_Types all; |
| 36 | import from MNCC_CodecPort all; |
| 37 | import from MNCC_Types all; |
| 38 | import from UD_Types all; |
| 39 | |
Neels Hofmeyr | 5e3b5d9 | 2019-11-28 20:34:57 +0100 | [diff] [blame] | 40 | modulepar { |
Pau Espin Pedrol | 563b3d0 | 2020-09-09 20:19:52 +0200 | [diff] [blame] | 41 | int mp_mncc_version := 7; |
Neels Hofmeyr | 5e3b5d9 | 2019-11-28 20:34:57 +0100 | [diff] [blame] | 42 | } |
| 43 | |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 44 | /* General "base class" component definition, of which specific implementations |
| 45 | * derive themselves by means of the "extends" feature */ |
| 46 | type component MNCC_ConnHdlr { |
| 47 | /* ports towards MNCC Emulator core / call dispatchar */ |
| 48 | port MNCC_Conn_PT MNCC; |
| 49 | port MNCCEM_PROC_PT MNCC_PROC; |
| 50 | } |
| 51 | |
| 52 | /* Auxiliary primitive that can happen on the port between per-connection client and this dispatcher */ |
| 53 | type enumerated MNCC_Conn_Prim { |
| 54 | /* MNCC tell us that connection was released */ |
| 55 | MNCC_CONN_PRIM_DISC_IND, |
| 56 | /* we tell MNCC to release connection */ |
| 57 | MNCC_CONN_PRIM_DISC_REQ |
| 58 | } |
| 59 | |
| 60 | type record MNCC_Conn_Req { |
| 61 | MNCC_PDU mncc |
| 62 | } |
| 63 | |
| 64 | /* port between individual per-connection components and this dispatcher */ |
| 65 | type port MNCC_Conn_PT message { |
| 66 | inout MNCC_PDU, MNCC_Conn_Prim, MNCC_Conn_Req; |
| 67 | } with { extension "internal" }; |
| 68 | |
| 69 | |
| 70 | /* represents a single MNCC call */ |
| 71 | type record ConnectionData { |
| 72 | /* reference to the instance of the per-connection component */ |
| 73 | MNCC_ConnHdlr comp_ref, |
| 74 | integer mncc_call_id |
| 75 | } |
| 76 | |
| 77 | type component MNCC_Emulation_CT { |
| 78 | /* UNIX DOMAIN socket on the bottom side, using primitives */ |
| 79 | port MNCC_CODEC_PT MNCC; |
| 80 | /* MNCC port to the per-connection clients */ |
| 81 | port MNCC_Conn_PT MNCC_CLIENT; |
| 82 | |
| 83 | /* use 16 as this is also the number of SCCP connections that SCCP_Emulation can handle */ |
| 84 | var ConnectionData MnccCallTable[16]; |
| 85 | |
| 86 | /* pending expected incoming connections */ |
| 87 | var ExpectData MnccExpectTable[8]; |
| 88 | /* procedure based port to register for incoming connections */ |
| 89 | port MNCCEM_PROC_PT MNCC_PROC; |
| 90 | |
| 91 | var integer g_mncc_ud_id; |
| 92 | }; |
| 93 | |
| 94 | private function f_call_id_known(uint32_t mncc_call_id) |
| 95 | runs on MNCC_Emulation_CT return boolean { |
| 96 | var integer i; |
| 97 | for (i := 0; i < sizeof(MnccCallTable); i := i+1) { |
| 98 | if (MnccCallTable[i].mncc_call_id == mncc_call_id){ |
| 99 | return true; |
| 100 | } |
| 101 | } |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | private function f_comp_known(MNCC_ConnHdlr client) |
| 106 | runs on MNCC_Emulation_CT return boolean { |
| 107 | var integer i; |
| 108 | for (i := 0; i < sizeof(MnccCallTable); i := i+1) { |
| 109 | if (MnccCallTable[i].comp_ref == client) { |
| 110 | return true; |
| 111 | } |
| 112 | } |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | /* resolve component reference by connection ID */ |
| 117 | private function f_comp_by_call_id(uint32_t mncc_call_id) |
| 118 | runs on MNCC_Emulation_CT return MNCC_ConnHdlr { |
| 119 | var integer i; |
| 120 | for (i := 0; i < sizeof(MnccCallTable); i := i+1) { |
| 121 | if (MnccCallTable[i].mncc_call_id == mncc_call_id) { |
| 122 | return MnccCallTable[i].comp_ref; |
| 123 | } |
| 124 | } |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 125 | setverdict(fail, "MNCC Call table not found by MNCC Call ID ", mncc_call_id); |
| 126 | mtc.stop; |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /* resolve connection ID by component reference */ |
| 130 | private function f_call_id_by_comp(MNCC_ConnHdlr client) |
| 131 | runs on MNCC_Emulation_CT return integer { |
| 132 | for (var integer i := 0; i < sizeof(MnccCallTable); i := i+1) { |
| 133 | if (MnccCallTable[i].comp_ref == client) { |
| 134 | return MnccCallTable[i].mncc_call_id; |
| 135 | } |
| 136 | } |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 137 | setverdict(fail, "MNCC Call table not found by component ", client); |
| 138 | mtc.stop; |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | private function f_gen_call_id() |
| 142 | runs on MNCC_Emulation_CT return integer { |
| 143 | var uint32_t call_id; |
| 144 | |
| 145 | do { |
| 146 | call_id := float2int(rnd()*4294967296.0); |
| 147 | } while (f_call_id_known(call_id) == true); |
| 148 | |
| 149 | return call_id; |
| 150 | } |
| 151 | |
Daniel Willmann | ff6abf0 | 2018-02-02 18:26:05 +0100 | [diff] [blame] | 152 | private function f_expect_table_init() |
| 153 | runs on MNCC_Emulation_CT { |
| 154 | for (var integer i := 0; i < sizeof(MnccExpectTable); i := i+1) { |
| 155 | MnccExpectTable[i].dest_number := omit; |
| 156 | MnccExpectTable[i].vc_conn := null; |
| 157 | } |
| 158 | } |
| 159 | |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 160 | private function f_call_table_init() |
| 161 | runs on MNCC_Emulation_CT { |
| 162 | for (var integer i := 0; i < sizeof(MnccCallTable); i := i+1) { |
| 163 | MnccCallTable[i].comp_ref := null; |
| 164 | MnccCallTable[i].mncc_call_id := -1; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | private function f_call_table_add(MNCC_ConnHdlr comp_ref, uint32_t mncc_call_id) |
| 169 | runs on MNCC_Emulation_CT { |
| 170 | for (var integer i := 0; i < sizeof(MnccCallTable); i := i+1) { |
| 171 | if (MnccCallTable[i].mncc_call_id == -1) { |
| 172 | MnccCallTable[i].comp_ref := comp_ref; |
| 173 | MnccCallTable[i].mncc_call_id := mncc_call_id; |
| 174 | log("Added conn table entry ", i, comp_ref, mncc_call_id); |
| 175 | return; |
| 176 | } |
| 177 | } |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 178 | testcase.stop("MNCC Call table full!"); |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | private function f_call_table_del(uint32_t mncc_call_id) |
| 182 | runs on MNCC_Emulation_CT { |
| 183 | for (var integer i := 0; i < sizeof(MnccCallTable); i := i+1) { |
| 184 | if (MnccCallTable[i].mncc_call_id == mncc_call_id) { |
| 185 | log("Deleted conn table entry ", i, |
| 186 | MnccCallTable[i].comp_ref, mncc_call_id); |
| 187 | MnccCallTable[i].mncc_call_id := -1; |
| 188 | MnccCallTable[i].comp_ref := null; |
| 189 | return |
| 190 | } |
| 191 | } |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 192 | setverdict(fail, "MNCC Call table attempt to delete non-existant ", mncc_call_id); |
| 193 | mtc.stop; |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 197 | private function f_connect(charstring sock) runs on MNCC_Emulation_CT { |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 198 | var UD_connect_result res; |
| 199 | timer T := 5.0; |
| 200 | |
| 201 | T.start; |
| 202 | MNCC.send(UD_connect:{sock, -1}); |
| 203 | alt { |
| 204 | [] MNCC.receive(UD_connect_result:?) -> value res { |
| 205 | if (ispresent(res.result) and ispresent(res.result.result_code) and res.result.result_code == ERROR) { |
| 206 | setverdict(fail, "Error connecting to MNCC socket", res); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 207 | mtc.stop; |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 208 | } else { |
| 209 | g_mncc_ud_id := res.id; |
| 210 | } |
| 211 | } |
| 212 | [] T.timeout { |
| 213 | setverdict(fail, "Timeout connecting to MNCC socket"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 214 | mtc.stop; |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 219 | private function f_listen(charstring sock) runs on MNCC_Emulation_CT { |
| 220 | var UD_listen_result res; |
| 221 | var UD_connected udc; |
| 222 | timer T := 5.0; |
| 223 | |
| 224 | T.start; |
| 225 | MNCC.send(UD_listen:{sock}); |
| 226 | alt { |
| 227 | [] MNCC.receive(UD_listen_result:?) -> value res { |
| 228 | if (ispresent(res.result) and ispresent(res.result.result_code) and res.result.result_code == ERROR) { |
| 229 | setverdict(fail, "Error listening to MNCC socket", res); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 230 | mtc.stop; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 231 | } else { |
| 232 | g_mncc_ud_id := res.id; |
| 233 | } |
| 234 | } |
| 235 | [] T.timeout { |
| 236 | setverdict(fail, "Timeout listening to MNCC socket"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 237 | mtc.stop; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
| 241 | T.start; |
| 242 | alt { |
| 243 | [] MNCC.receive(UD_connected:?) -> value udc { |
| 244 | g_mncc_ud_id := res.id; |
| 245 | } |
| 246 | [] T.timeout { |
| 247 | setverdict(fail, "Timeout waiting for MNCC connection"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 248 | mtc.stop; |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 253 | /* call-back type, to be provided by specific implementation; called when new SCCP connection |
| 254 | * arrives */ |
| 255 | type function MnccCreateCallback(MNCC_PDU conn_ind, charstring id) |
| 256 | runs on MNCC_Emulation_CT return MNCC_ConnHdlr; |
| 257 | |
| 258 | type function MnccUnitdataCallback(MNCC_PDU mncc) |
| 259 | runs on MNCC_Emulation_CT return template MNCC_PDU; |
| 260 | |
| 261 | type record MnccOps { |
| 262 | MnccCreateCallback create_cb, |
| 263 | MnccUnitdataCallback unitdata_cb |
| 264 | } |
| 265 | |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 266 | function main(MnccOps ops, charstring id, charstring sock, boolean role_server := false) |
| 267 | runs on MNCC_Emulation_CT { |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 268 | |
Pau Espin Pedrol | 563b3d0 | 2020-09-09 20:19:52 +0200 | [diff] [blame] | 269 | if (not set_MNCC_version(mp_mncc_version)) { |
| 270 | setverdict(fail, "Failed configuring MNCC enc/dec to version ", mp_mncc_version); |
| 271 | return; |
| 272 | } |
| 273 | |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 274 | if (role_server) { |
| 275 | f_listen(sock); |
Neels Hofmeyr | 5e3b5d9 | 2019-11-28 20:34:57 +0100 | [diff] [blame] | 276 | MNCC.send(t_SD_MNCC(g_mncc_ud_id, ts_MNCC_HELLO(version := mp_mncc_version))); |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 277 | } else { |
| 278 | f_connect(sock); |
| 279 | } |
Daniel Willmann | ff6abf0 | 2018-02-02 18:26:05 +0100 | [diff] [blame] | 280 | f_expect_table_init(); |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 281 | f_call_table_init(); |
| 282 | |
| 283 | while (true) { |
| 284 | var MNCC_send_data sd; |
| 285 | var MNCC_Conn_Req creq; |
| 286 | var MNCC_ConnHdlr vc_conn; |
| 287 | var MNCC_PDU mncc; |
| 288 | var MNCC_ConnHdlr vc_hdlr; |
| 289 | var charstring dest_nr; |
| 290 | |
| 291 | alt { |
| 292 | /* MNCC -> Client: UNIT-DATA (connectionless SCCP) from a BSC */ |
| 293 | [] MNCC.receive(t_SD_MNCC_MSGT(g_mncc_ud_id, MNCC_SOCKET_HELLO)) -> value sd { |
| 294 | /* Connectionless Procedures like HELLO */ |
| 295 | var template MNCC_PDU resp; |
| 296 | resp := ops.unitdata_cb.apply(sd.data); |
| 297 | if (isvalue(resp)) { |
| 298 | MNCC.send(t_SD_MNCC(g_mncc_ud_id, resp)); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | /* MNCC -> Client: Release Indication / confirmation */ |
| 303 | [] MNCC.receive(t_SD_MNCC_MSGT(g_mncc_ud_id, (MNCC_REL_IND, MNCC_REL_CNF))) -> value sd { |
| 304 | var uint32_t call_id := f_mncc_get_call_id(sd.data); |
| 305 | /* forward to respective client */ |
| 306 | vc_conn := f_comp_by_call_id(call_id); |
| 307 | MNCC_CLIENT.send(sd.data) to vc_conn; |
| 308 | /* remove from call table */ |
| 309 | f_call_table_del(call_id); |
| 310 | } |
| 311 | |
| 312 | /* MNCC -> Client: call related messages */ |
| 313 | [] MNCC.receive(t_SD_MNCC_MSGT(g_mncc_ud_id, ?)) -> value sd { |
| 314 | var uint32_t call_id := f_mncc_get_call_id(sd.data); |
| 315 | |
| 316 | if (f_call_id_known(call_id)) { |
| 317 | vc_conn := f_comp_by_call_id(call_id); |
| 318 | MNCC_CLIENT.send(sd.data) to vc_conn; |
| 319 | } else { |
| 320 | /* TODO: Only accept this for SETUP.req? */ |
| 321 | vc_conn := ops.create_cb.apply(sd.data, id) |
| 322 | /* store mapping between client components and SCCP connectionId */ |
| 323 | f_call_table_add(vc_conn, call_id); |
| 324 | /* handle user payload */ |
| 325 | MNCC_CLIENT.send(sd.data) to vc_conn; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | /* Client -> MNCC Socket: RELEASE.ind or RELEASE.cnf: forward + drop call table entry */ |
| 330 | [] MNCC_CLIENT.receive(MNCC_PDU:{msg_type := (MNCC_REL_IND, MNCC_REL_CNF), u:=?}) -> value mncc sender vc_conn { |
| 331 | var integer call_id := f_call_id_by_comp(vc_conn); |
| 332 | /* forward to MNCC socket */ |
| 333 | MNCC.send(t_SD_MNCC(g_mncc_ud_id, mncc)); |
| 334 | /* remove from call table */ |
| 335 | f_call_table_del(call_id); |
| 336 | } |
| 337 | |
Harald Welte | afec471 | 2018-03-19 22:52:17 +0100 | [diff] [blame] | 338 | /* Client -> MNCC Socket: Normal message */ |
| 339 | [] MNCC_CLIENT.receive(MNCC_PDU:?) -> value mncc sender vc_conn { |
| 340 | if (mncc.msg_type == MNCC_SETUP_REQ and not role_server) { |
| 341 | /* ConnHdlr -> MNCC Server: SETUP.req: add to call table */ |
| 342 | f_call_table_add(vc_conn, f_mncc_get_call_id(mncc)); |
| 343 | } else if (mncc.msg_type == MNCC_SETUP_IND and role_server) { |
| 344 | /* ConnHdlr -> MNCC Client: SETUP.ind: add to call table */ |
| 345 | f_call_table_add(vc_conn, f_mncc_get_call_id(mncc)); |
| 346 | } |
Harald Welte | 812f7a4 | 2018-01-27 00:49:18 +0100 | [diff] [blame] | 347 | /* forward to MNCC socket */ |
| 348 | MNCC.send(t_SD_MNCC(g_mncc_ud_id, mncc)); |
| 349 | } |
| 350 | |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 351 | [] MNCC_CLIENT.receive(MNCC_PDU:?) -> value mncc sender vc_conn { |
| 352 | /* forward to MNCC socket */ |
| 353 | MNCC.send(t_SD_MNCC(g_mncc_ud_id, mncc)); |
| 354 | } |
| 355 | |
| 356 | |
| 357 | /* Client -> us: procedure call to register expect */ |
| 358 | [] MNCC_PROC.getcall(MNCCEM_register:{?,?}) -> param(dest_nr, vc_hdlr) { |
| 359 | f_create_expect(dest_nr, vc_hdlr); |
Harald Welte | e32ad99 | 2018-05-31 22:17:46 +0200 | [diff] [blame] | 360 | MNCC_PROC.reply(MNCCEM_register:{dest_nr, vc_hdlr}) to vc_hdlr; |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | private function f_mgcp_ep_extract_cic(charstring inp) return integer { |
| 368 | var charstring local_part := regexp(inp, "(*)@*", 0); |
| 369 | return hex2int(str2hex(local_part)); |
| 370 | |
| 371 | } |
| 372 | |
| 373 | /*********************************************************************** |
| 374 | * "Expect" Handling (mapping for expected incoming MNCC calls from IUT) |
| 375 | ***********************************************************************/ |
| 376 | |
| 377 | /* data about an expected future incoming connection */ |
| 378 | type record ExpectData { |
| 379 | /* destination number based on which we can match it */ |
| 380 | charstring dest_number optional, |
| 381 | /* component reference for this connection */ |
| 382 | MNCC_ConnHdlr vc_conn |
| 383 | } |
| 384 | |
| 385 | /* procedure based port to register for incoming calls */ |
| 386 | signature MNCCEM_register(in charstring dest_nr, in MNCC_ConnHdlr hdlr); |
| 387 | |
| 388 | type port MNCCEM_PROC_PT procedure { |
| 389 | inout MNCCEM_register; |
| 390 | } with { extension "internal" }; |
| 391 | |
| 392 | /* CreateCallback that can be used as create_cb and will use the expectation table */ |
| 393 | function ExpectedCreateCallback(MNCC_PDU conn_ind, charstring id) |
| 394 | runs on MNCC_Emulation_CT return MNCC_ConnHdlr { |
| 395 | var MNCC_ConnHdlr ret := null; |
| 396 | var charstring dest_number; |
| 397 | var integer i; |
| 398 | |
Harald Welte | 9edea88 | 2018-03-24 22:32:20 +0100 | [diff] [blame] | 399 | if (not ischosen(conn_ind.u.signal) or |
| 400 | (conn_ind.msg_type != MNCC_SETUP_IND and conn_ind.msg_type != MNCC_SETUP_REQ)) { |
| 401 | setverdict(fail, "MNCC ExpectedCreateCallback needs MNCC_SETUP_{IND,REQ}"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 402 | mtc.stop; |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 403 | return ret; |
| 404 | } |
| 405 | dest_number := conn_ind.u.signal.called.number; |
| 406 | |
| 407 | for (i := 0; i < sizeof(MnccExpectTable); i:= i+1) { |
| 408 | if (not ispresent(MnccExpectTable[i].dest_number)) { |
| 409 | continue; |
| 410 | } |
| 411 | if (dest_number == MnccExpectTable[i].dest_number) { |
| 412 | ret := MnccExpectTable[i].vc_conn; |
| 413 | /* release this entry to be used again */ |
| 414 | MnccExpectTable[i].dest_number := omit; |
| 415 | MnccExpectTable[i].vc_conn := null; |
| 416 | log("Found MnccExpect[", i, "] for ", dest_number, " handled at ", ret); |
| 417 | /* return the component reference */ |
| 418 | return ret; |
| 419 | } |
| 420 | } |
| 421 | setverdict(fail, "Couldn't find MnccExpect for incoming call ", dest_number); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 422 | mtc.stop; |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 423 | return ret; |
| 424 | } |
| 425 | |
| 426 | /* server/emulation side function to create expect */ |
| 427 | private function f_create_expect(charstring dest_number, MNCC_ConnHdlr hdlr) |
| 428 | runs on MNCC_Emulation_CT { |
| 429 | var integer i; |
| 430 | for (i := 0; i < sizeof(MnccExpectTable); i := i+1) { |
| 431 | if (not ispresent(MnccExpectTable[i].dest_number)) { |
| 432 | MnccExpectTable[i].dest_number := dest_number; |
| 433 | MnccExpectTable[i].vc_conn := hdlr; |
| 434 | log("Created MnccExpect[", i, "] for ", dest_number, " to be handled at ", hdlr); |
| 435 | return; |
| 436 | } |
| 437 | } |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 438 | testcase.stop("No space left in MnccMnccExpectTable"); |
Harald Welte | 876bf9d | 2018-01-21 19:28:59 +0100 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | /* client/conn_hdlr side function to use procedure port to create expect in emulation */ |
| 442 | function f_create_mncc_expect(charstring dest_number) runs on MNCC_ConnHdlr { |
| 443 | MNCC_PROC.call(MNCCEM_register:{dest_number, self}) { |
| 444 | [] MNCC_PROC.getreply(MNCCEM_register:{?,?}) {}; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | function DummyUnitdataCallback(MNCC_PDU mncc) |
| 449 | runs on MNCC_Emulation_CT return template MNCC_PDU { |
| 450 | log("Ignoring MNCC ", mncc); |
| 451 | return omit; |
| 452 | } |
| 453 | |
| 454 | } |