blob: d6d74e26798668d1b32b079e4885648efe860b36 [file] [log] [blame]
Harald Welte6811d102019-04-14 22:23:14 +02001module RAN_Emulation {
Harald Welte365f4ed2017-11-23 00:00:43 +01002
Harald Welte6811d102019-04-14 22:23:14 +02003/* RAN Emulation, runs on top of BSSAP_CodecPort. It multiplexes/demultiplexes
Harald Welte35bb7162018-01-03 21:07:52 +01004 * the individual connections, so there can be separate TTCN-3 components handling
5 * each of the connections.
6 *
Harald Welte6811d102019-04-14 22:23:14 +02007 * The RAN_Emulation.main() function processes SCCP primitives from the SCCP
Harald Welte35bb7162018-01-03 21:07:52 +01008 * stack via the BSSAP_CodecPort, and dispatches them to the per-connection components.
9 *
10 * Outbound BSSAP/SCCP connections are initiated by sending a BSSAP_Conn_Req primitive
Harald Welte6811d102019-04-14 22:23:14 +020011 * to the component running the RAN_Emulation.main() function.
Harald Welte35bb7162018-01-03 21:07:52 +010012 *
Harald Welte6811d102019-04-14 22:23:14 +020013 * For each new inbound connections, the RanOps.create_cb() is called. It can create
Harald Welte35bb7162018-01-03 21:07:52 +010014 * 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 connection, it can
18 * do so by registering an "expect" with the expected Layer 3 (DTAP) payload. This is e.g. useful
19 * if you are simulating BTS + MSC, and first trigger a connection from BTS/RSL side in a
20 * component which then subsequently should also handle the MSC emulation.
21 *
Harald Welte6811d102019-04-14 22:23:14 +020022 * Inbound Unit Data messages (such as are dispatched to the RanOps.unitdata_cb() callback,
Harald Welte35bb7162018-01-03 21:07:52 +010023 * which is registered with an argument to the main() function below.
24 *
Harald Welte2fce7882019-04-15 11:48:05 +020025 * (C) 2017-2019 by Harald Welte <laforge@gnumonks.org>
Harald Welte35bb7162018-01-03 21:07:52 +010026 * All rights reserved.
27 *
28 * Released under the terms of GNU General Public License, Version 2 or
29 * (at your option) any later version.
30 */
31
32
Harald Welte0b476062018-01-21 19:07:32 +010033import from General_Types all;
Harald Welte9dadc522018-02-06 13:56:04 +010034import from Osmocom_Types all;
Harald Welteb3414b22017-11-23 18:22:10 +010035import from SCCP_Emulation all;
Harald Welte365f4ed2017-11-23 00:00:43 +010036import from SCCPasp_Types all;
Harald Welte2fce7882019-04-15 11:48:05 +020037import from IPA_Emulation all;
38import from MobileL3_Types all;
39
40#ifdef RAN_EMULATION_BSSAP
Harald Welte365f4ed2017-11-23 00:00:43 +010041import from BSSAP_Types all;
Harald Welte004f5fb2017-12-16 17:54:40 +010042import from BSSAP_CodecPort all;
Harald Welte365f4ed2017-11-23 00:00:43 +010043import from BSSMAP_Templates all;
Harald Welte2fce7882019-04-15 11:48:05 +020044#endif
45
46#ifdef RAN_EMULATION_MGCP
Harald Weltec82eef42017-11-24 20:40:12 +010047import from MGCP_Types all;
48import from MGCP_Templates all;
Harald Welte2fce7882019-04-15 11:48:05 +020049#endif
Harald Welte365f4ed2017-11-23 00:00:43 +010050
Harald Welte5b027622019-04-14 23:40:17 +020051#ifdef RAN_EMULATION_RANAP
52import from RANAP_CodecPort all;
53import from RANAP_PDU_Descriptions all;
54import from RANAP_Constants all;
55import from RANAP_IEs all;
56import from RANAP_Templates all;
57#endif
58
Harald Welte365f4ed2017-11-23 00:00:43 +010059/* General "base class" component definition, of which specific implementations
60 * derive themselves by means of the "extends" feature */
Harald Welte6811d102019-04-14 22:23:14 +020061type component RAN_ConnHdlr {
Harald Welte365f4ed2017-11-23 00:00:43 +010062 /* port towards MSC Emulator core / SCCP connection dispatchar */
Harald Welte6811d102019-04-14 22:23:14 +020063 port RAN_Conn_PT BSSAP;
Harald Welteca519982018-01-21 19:28:26 +010064 /* procedure based port to register for incoming connections */
Harald Welte6811d102019-04-14 22:23:14 +020065 port RAN_PROC_PT BSSAP_PROC;
Harald Welte365f4ed2017-11-23 00:00:43 +010066}
67
68/* Auxiliary primitive that can happen on the port between per-connection client and this dispatcher */
Harald Welte6811d102019-04-14 22:23:14 +020069type enumerated RAN_Conn_Prim {
Harald Welte365f4ed2017-11-23 00:00:43 +010070 /* SCCP tell us that connection was released */
71 MSC_CONN_PRIM_DISC_IND,
72 /* we tell SCCP to release connection */
Harald Welte71b69332018-01-21 20:43:53 +010073 MSC_CONN_PRIM_DISC_REQ,
74 /* Connection confirmed indication */
75 MSC_CONN_PRIM_CONF_IND
Harald Welte365f4ed2017-11-23 00:00:43 +010076}
77
Harald Welte0b476062018-01-21 19:07:32 +010078/* similar to PDU_BSSAP with DTAP, but DTAP is already decoded! */
79type record PDU_DTAP_MO {
80 OCT1 dlci optional,
Daniel Willmann92f66272018-02-06 15:50:52 +010081 boolean skip_seq_patching optional,
Harald Welte0b476062018-01-21 19:07:32 +010082 PDU_ML3_MS_NW dtap
83}
84
85/* similar to PDU_BSSAP with DTAP, but DTAP is already decoded! */
86type record PDU_DTAP_MT {
87 OCT1 dlci optional,
88 PDU_ML3_NW_MS dtap
89}
90
91template PDU_DTAP_MT ts_PDU_DTAP_MT(template PDU_ML3_NW_MS dtap, template OCT1 dlci := omit) := {
92 dlci := dlci,
93 dtap := dtap
94}
95
Daniel Willmann92f66272018-02-06 15:50:52 +010096template PDU_DTAP_MO ts_PDU_DTAP_MO(template PDU_ML3_MS_NW dtap, template OCT1 dlci := '00'O, boolean skip_seq_patching := false) := {
Harald Welte0b476062018-01-21 19:07:32 +010097 dlci := dlci,
Daniel Willmann92f66272018-02-06 15:50:52 +010098 skip_seq_patching := skip_seq_patching,
Harald Welte0b476062018-01-21 19:07:32 +010099 dtap := dtap
100}
101
102template PDU_DTAP_MT tr_PDU_DTAP_MT(template PDU_ML3_NW_MS dtap, template OCT1 dlci := *) := {
103 dlci := dlci,
104 dtap := dtap
105}
106
107template PDU_DTAP_MO tr_PDU_DTAP_MO(template PDU_ML3_MS_NW dtap, template OCT1 dlci := *) := {
108 dlci := dlci,
Harald Welte930d0a72018-03-22 22:08:40 +0100109 skip_seq_patching := ?,
Harald Welte0b476062018-01-21 19:07:32 +0100110 dtap := dtap
111}
112
Harald Welte365f4ed2017-11-23 00:00:43 +0100113/* port between individual per-connection components and this dispatcher */
Harald Welte6811d102019-04-14 22:23:14 +0200114type port RAN_Conn_PT message {
Harald Welte2fce7882019-04-15 11:48:05 +0200115 inout
116#ifdef RAN_EMULATION_BSSAP
117 PDU_BSSAP,
Harald Weltea4ca4462018-02-09 00:17:14 +0100118 /* Client requests us to create SCCP Connection */
119 BSSAP_Conn_Req,
Harald Welte2fce7882019-04-15 11:48:05 +0200120#endif
Harald Welte5b027622019-04-14 23:40:17 +0200121#ifdef RAN_EMULATION_RANAP
122 RANAP_PDU,
123 /* Client requests us to create SCCP Connection */
124 RANAP_Conn_Req,
125#endif
Harald Welte2fce7882019-04-15 11:48:05 +0200126#ifdef RAN_EMULATION_MGCP
Harald Weltea4ca4462018-02-09 00:17:14 +0100127 /* MGCP, only used for IPA SCCPlite (MGCP in IPA mux) */
Harald Welte2fce7882019-04-15 11:48:05 +0200128 MgcpCommand, MgcpResponse,
129#endif
130 /* direct DTAP messages from/to clients */
131 PDU_DTAP_MO, PDU_DTAP_MT,
132 /* misc indications / requests between SCCP and client */
133 RAN_Conn_Prim;
Harald Welte365f4ed2017-11-23 00:00:43 +0100134} with { extension "internal" };
135
136
137/* represents a single BSSAP connection over SCCP */
138type record ConnectionData {
139 /* reference to the instance of the per-connection component */
Harald Welte6811d102019-04-14 22:23:14 +0200140 RAN_ConnHdlr comp_ref,
Harald Weltec82eef42017-11-24 20:40:12 +0100141 integer sccp_conn_id,
Harald Welte2fce7882019-04-15 11:48:05 +0200142#ifdef RAN_EMULATION_MGCP
Harald Weltec82eef42017-11-24 20:40:12 +0100143 /* most recent MGCP transaction ID (Used on MSC side) */
144 MgcpTransId mgcp_trans_id optional,
Harald Welte2fce7882019-04-15 11:48:05 +0200145#endif
Harald Weltec82eef42017-11-24 20:40:12 +0100146 /* CIC that has been used for voice of this channel (BSC side) */
Harald Welte9dadc522018-02-06 13:56:04 +0100147 integer cic optional,
148 /* array of N(SD) values for MO DTAP messages, indexed by discriminator */
149 uint2_t n_sd[4]
Harald Welte365f4ed2017-11-23 00:00:43 +0100150}
151
Harald Welte17d21152018-01-27 00:47:11 +0100152type record ImsiMapping {
Harald Welte6811d102019-04-14 22:23:14 +0200153 RAN_ConnHdlr comp_ref,
Harald Welte17d21152018-01-27 00:47:11 +0100154 hexstring imsi optional,
155 OCT4 tmsi
156}
157
Harald Welte6811d102019-04-14 22:23:14 +0200158type component RAN_Emulation_CT {
Harald Welte2fce7882019-04-15 11:48:05 +0200159 /* SCCP ports on the bottom side, using ASP primitives */
160#ifdef RAN_EMULATION_BSSAP
Harald Welte004f5fb2017-12-16 17:54:40 +0100161 port BSSAP_CODEC_PT BSSAP;
Harald Welte2fce7882019-04-15 11:48:05 +0200162#endif
Harald Welte5b027622019-04-14 23:40:17 +0200163#ifdef RAN_EMULATION_RANAP
164 port RANAP_CODEC_PT RANAP;
165#endif
Harald Welte365f4ed2017-11-23 00:00:43 +0100166 /* BSSAP port to the per-connection clients */
Harald Welte6811d102019-04-14 22:23:14 +0200167 port RAN_Conn_PT CLIENT;
Harald Welte2fce7882019-04-15 11:48:05 +0200168#ifdef RAN_EMULATION_MGCP
Harald Weltec82eef42017-11-24 20:40:12 +0100169 /* MGCP port */
170 port IPA_MGCP_PT MGCP;
Harald Welte2fce7882019-04-15 11:48:05 +0200171#endif
Harald Welte365f4ed2017-11-23 00:00:43 +0100172
173 /* use 16 as this is also the number of SCCP connections that SCCP_Emulation can handle */
174 var ConnectionData ConnectionTable[16];
Harald Welte66fecd42017-11-24 23:53:23 +0100175
Harald Welte624f9632017-12-16 19:26:04 +0100176 /* pending expected incoming connections */
177 var ExpectData ExpectTable[8];
Harald Welte17d21152018-01-27 00:47:11 +0100178
179 /* tables for mapping inbound unitdata (like paging) */
180 var ImsiMapping ImsiTable[16];
181
Harald Welte624f9632017-12-16 19:26:04 +0100182 /* procedure based port to register for incoming connections */
Harald Welte6811d102019-04-14 22:23:14 +0200183 port RAN_PROC_PT PROC;
Harald Welte624f9632017-12-16 19:26:04 +0100184
Harald Welte6811d102019-04-14 22:23:14 +0200185 var charstring g_ran_id;
Harald Welte66fecd42017-11-24 23:53:23 +0100186 var integer g_next_e1_ts := 1;
Harald Welte6811d102019-04-14 22:23:14 +0200187 var RanOps g_ran_ops;
Harald Welte365f4ed2017-11-23 00:00:43 +0100188};
189
Harald Welteb3414b22017-11-23 18:22:10 +0100190private function f_conn_id_known(integer sccp_conn_id)
Harald Welte6811d102019-04-14 22:23:14 +0200191runs on RAN_Emulation_CT return boolean {
Harald Welteb3414b22017-11-23 18:22:10 +0100192 var integer i;
193 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
194 if (ConnectionTable[i].sccp_conn_id == sccp_conn_id){
195 return true;
196 }
197 }
198 return false;
199}
200
Harald Welte6811d102019-04-14 22:23:14 +0200201private function f_comp_known(RAN_ConnHdlr client)
202runs on RAN_Emulation_CT return boolean {
Harald Welteb3414b22017-11-23 18:22:10 +0100203 var integer i;
204 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
205 if (ConnectionTable[i].comp_ref == client) {
206 return true;
207 }
208 }
209 return false;
210}
Harald Welte365f4ed2017-11-23 00:00:43 +0100211
Harald Weltee98bb2e2017-11-29 12:09:48 +0100212private function f_cic_known(integer cic)
Harald Welte6811d102019-04-14 22:23:14 +0200213runs on RAN_Emulation_CT return boolean {
Harald Weltee98bb2e2017-11-29 12:09:48 +0100214 var integer i;
215 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
216 if (ConnectionTable[i].cic == cic) {
217 return true;
218 }
219 }
220 return false;
221}
222
Harald Welte365f4ed2017-11-23 00:00:43 +0100223/* resolve component reference by connection ID */
224private function f_comp_by_conn_id(integer sccp_conn_id)
Harald Welte6811d102019-04-14 22:23:14 +0200225runs on RAN_Emulation_CT return RAN_ConnHdlr {
Harald Welte365f4ed2017-11-23 00:00:43 +0100226 var integer i;
227 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
228 if (ConnectionTable[i].sccp_conn_id == sccp_conn_id) {
229 return ConnectionTable[i].comp_ref;
230 }
231 }
Harald Welte6811d102019-04-14 22:23:14 +0200232 setverdict(fail, "RAN Connection table not found by SCCP Connection ID ", sccp_conn_id);
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200233 mtc.stop;
Harald Welte365f4ed2017-11-23 00:00:43 +0100234}
235
Harald Welte2fce7882019-04-15 11:48:05 +0200236
237#ifdef RAN_EMULATION_MGCP
Harald Weltec82eef42017-11-24 20:40:12 +0100238/* resolve component reference by CIC */
239private function f_comp_by_mgcp_tid(MgcpTransId tid)
Harald Welte6811d102019-04-14 22:23:14 +0200240runs on RAN_Emulation_CT return RAN_ConnHdlr {
Harald Weltec82eef42017-11-24 20:40:12 +0100241 var integer i;
242 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
243 if (ConnectionTable[i].mgcp_trans_id == tid) {
244 return ConnectionTable[i].comp_ref;
245 }
246 }
Harald Welte6811d102019-04-14 22:23:14 +0200247 setverdict(fail, "RAN Connection table not found by MGCP Transaction ID ", tid);
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200248 mtc.stop;
Harald Weltec82eef42017-11-24 20:40:12 +0100249}
250
Harald Welte6811d102019-04-14 22:23:14 +0200251private function f_comp_store_mgcp_tid(RAN_ConnHdlr client, MgcpTransId tid)
252runs on RAN_Emulation_CT {
Harald Weltec82eef42017-11-24 20:40:12 +0100253 var integer i;
254 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
255 if (ConnectionTable[i].comp_ref == client) {
256 ConnectionTable[i].mgcp_trans_id := tid;
257 return;
258 }
259 }
Harald Welte6811d102019-04-14 22:23:14 +0200260 setverdict(fail, "RAN Connection table not found by component ", client);
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200261 mtc.stop;
Harald Weltec82eef42017-11-24 20:40:12 +0100262}
Harald Welte2fce7882019-04-15 11:48:05 +0200263#endif
Harald Weltec82eef42017-11-24 20:40:12 +0100264
265private function f_comp_by_cic(integer cic)
Harald Welte6811d102019-04-14 22:23:14 +0200266runs on RAN_Emulation_CT return RAN_ConnHdlr {
Harald Weltec82eef42017-11-24 20:40:12 +0100267 var integer i;
268 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
269 if (ConnectionTable[i].cic == cic) {
270 return ConnectionTable[i].comp_ref;
271 }
272 }
Harald Welte6811d102019-04-14 22:23:14 +0200273 setverdict(fail, "RAN Connection table not found by CIC ", cic);
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200274 mtc.stop;
Harald Weltec82eef42017-11-24 20:40:12 +0100275}
276
Harald Welte6811d102019-04-14 22:23:14 +0200277private function f_comp_store_cic(RAN_ConnHdlr client, integer cic)
278runs on RAN_Emulation_CT {
Harald Weltec82eef42017-11-24 20:40:12 +0100279 var integer i;
280 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
281 if (ConnectionTable[i].comp_ref == client) {
282 ConnectionTable[i].cic := cic;
283 return;
284 }
285 }
Harald Welte6811d102019-04-14 22:23:14 +0200286 setverdict(fail, "RAN Connection table not found by component ", client);
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200287 mtc.stop;
Harald Weltec82eef42017-11-24 20:40:12 +0100288}
289
Harald Welte365f4ed2017-11-23 00:00:43 +0100290/* resolve connection ID by component reference */
Harald Welte6811d102019-04-14 22:23:14 +0200291private function f_conn_id_by_comp(RAN_ConnHdlr client)
292runs on RAN_Emulation_CT return integer {
Harald Welte365f4ed2017-11-23 00:00:43 +0100293 for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) {
294 if (ConnectionTable[i].comp_ref == client) {
295 return ConnectionTable[i].sccp_conn_id;
296 }
297 }
Harald Welte6811d102019-04-14 22:23:14 +0200298 setverdict(fail, "RAN Connection table not found by component ", client);
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200299 mtc.stop;
Harald Welte365f4ed2017-11-23 00:00:43 +0100300}
301
Harald Welte9dadc522018-02-06 13:56:04 +0100302/* resolve ConnectionTable index component reference */
Harald Welte6811d102019-04-14 22:23:14 +0200303private function f_idx_by_comp(RAN_ConnHdlr client)
304runs on RAN_Emulation_CT return integer {
Harald Welte9dadc522018-02-06 13:56:04 +0100305 for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) {
306 if (ConnectionTable[i].comp_ref == client) {
307 return i;
308 }
309 }
Harald Welte6811d102019-04-14 22:23:14 +0200310 setverdict(fail, "RAN Connection table not found by component ", client);
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200311 mtc.stop;
Harald Welte9dadc522018-02-06 13:56:04 +0100312}
313
Harald Welteb3414b22017-11-23 18:22:10 +0100314private function f_gen_conn_id()
Harald Welte6811d102019-04-14 22:23:14 +0200315runs on RAN_Emulation_CT return integer {
Harald Welteb3414b22017-11-23 18:22:10 +0100316 var integer conn_id;
317
318 do {
319 conn_id := float2int(rnd()*SCCP_Emulation.tsp_max_ConnectionId);
320 } while (f_conn_id_known(conn_id) == true);
321
322 return conn_id;
323}
324
Harald Welte365f4ed2017-11-23 00:00:43 +0100325private function f_conn_table_init()
Harald Welte6811d102019-04-14 22:23:14 +0200326runs on RAN_Emulation_CT {
Harald Welte365f4ed2017-11-23 00:00:43 +0100327 for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) {
328 ConnectionTable[i].comp_ref := null;
329 ConnectionTable[i].sccp_conn_id := -1;
Harald Welte2fce7882019-04-15 11:48:05 +0200330#ifdef RAN_EMULATION_MGCP
Harald Weltec82eef42017-11-24 20:40:12 +0100331 ConnectionTable[i].mgcp_trans_id := omit;
Harald Welte2fce7882019-04-15 11:48:05 +0200332#endif
Harald Weltec82eef42017-11-24 20:40:12 +0100333 ConnectionTable[i].cic := omit;
Harald Welte9dadc522018-02-06 13:56:04 +0100334 ConnectionTable[i].n_sd := { 0, 0, 0, 0 };
Harald Welte365f4ed2017-11-23 00:00:43 +0100335 }
Harald Welte17d21152018-01-27 00:47:11 +0100336 for (var integer i := 0; i < sizeof(ImsiTable); i := i+1) {
337 ImsiTable[i].comp_ref := null;
338 ImsiTable[i].imsi := omit;
339 ImsiTable[i].tmsi := 'FFFFFFFF'O;
340 }
Harald Welte365f4ed2017-11-23 00:00:43 +0100341}
342
Harald Welte6811d102019-04-14 22:23:14 +0200343private function f_conn_table_add(RAN_ConnHdlr comp_ref, integer sccp_conn_id)
344runs on RAN_Emulation_CT {
Harald Welte365f4ed2017-11-23 00:00:43 +0100345 for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) {
346 if (ConnectionTable[i].sccp_conn_id == -1) {
347 ConnectionTable[i].comp_ref := comp_ref;
348 ConnectionTable[i].sccp_conn_id := sccp_conn_id;
Harald Welte9dadc522018-02-06 13:56:04 +0100349 ConnectionTable[i].n_sd := { 0, 0, 0, 0 };
Harald Welteb3414b22017-11-23 18:22:10 +0100350 log("Added conn table entry ", i, comp_ref, sccp_conn_id);
Harald Welte365f4ed2017-11-23 00:00:43 +0100351 return;
352 }
353 }
Harald Welte6811d102019-04-14 22:23:14 +0200354 testcase.stop("RAN Connection table full!");
Harald Welte365f4ed2017-11-23 00:00:43 +0100355}
356
357private function f_conn_table_del(integer sccp_conn_id)
Harald Welte6811d102019-04-14 22:23:14 +0200358runs on RAN_Emulation_CT {
Harald Welte365f4ed2017-11-23 00:00:43 +0100359 for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) {
360 if (ConnectionTable[i].sccp_conn_id == sccp_conn_id) {
Harald Welteb3414b22017-11-23 18:22:10 +0100361 log("Deleted conn table entry ", i,
362 ConnectionTable[i].comp_ref, sccp_conn_id);
Harald Welte365f4ed2017-11-23 00:00:43 +0100363 ConnectionTable[i].sccp_conn_id := -1;
364 ConnectionTable[i].comp_ref := null;
Harald Welte0a4317a2017-11-25 00:32:46 +0100365 return
Harald Welte365f4ed2017-11-23 00:00:43 +0100366 }
367 }
Harald Welte6811d102019-04-14 22:23:14 +0200368 setverdict(fail, "RAN Connection table attempt to delete non-existant ", sccp_conn_id);
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200369 mtc.stop;
Harald Welte365f4ed2017-11-23 00:00:43 +0100370}
371
Harald Welte17d21152018-01-27 00:47:11 +0100372private function f_imsi_table_find(hexstring imsi, template OCT4 tmsi)
Harald Welte6811d102019-04-14 22:23:14 +0200373runs on RAN_Emulation_CT return RAN_ConnHdlr {
Harald Welte17d21152018-01-27 00:47:11 +0100374 for (var integer i := 0; i < sizeof(ImsiTable); i := i+1) {
375 if (ImsiTable[i].imsi == imsi or
376 isvalue(tmsi) and match(ImsiTable[i].tmsi, tmsi)) {
377 return ImsiTable[i].comp_ref;
378 }
379 }
380 return null;
381}
382
Harald Welte2fce7882019-04-15 11:48:05 +0200383#ifdef RAN_EMULATION_BSSAP
384type record BSSAP_Conn_Req {
385 SCCP_PAR_Address addr_peer,
386 SCCP_PAR_Address addr_own,
387 PDU_BSSAP bssap
388}
389template BSSAP_Conn_Req ts_BSSAP_Conn_Req(SCCP_PAR_Address peer, SCCP_PAR_Address own, PDU_BSSAP bssap) := {
390 addr_peer := peer,
391 addr_own := own,
392 bssap := bssap
393};
394
Harald Welte365f4ed2017-11-23 00:00:43 +0100395/* handle (optional) userData portion of various primitives and dispatch it to the client */
Harald Welte6811d102019-04-14 22:23:14 +0200396private function f_handle_userData(RAN_ConnHdlr client, PDU_BSSAP bssap)
397runs on RAN_Emulation_CT {
Harald Welte365f4ed2017-11-23 00:00:43 +0100398 /* decode + send decoded BSSAP to client */
Harald Welte1b2748e2017-11-24 23:40:16 +0100399
Harald Welte473676b2018-01-27 20:38:01 +0100400 if (ischosen(bssap.pdu.bssmap)) {
401 /* BSC Side: If this is an assignment command, store CIC */
402 if (ischosen(bssap.pdu.bssmap.assignmentRequest) and
403 ispresent(bssap.pdu.bssmap.assignmentRequest.circuitIdentityCode)) {
404 var BSSMAP_IE_CircuitIdentityCode cic_ie :=
405 bssap.pdu.bssmap.assignmentRequest.circuitIdentityCode;
406 var integer cic := (oct2int(cic_ie.cicHigh) * 256) + oct2int(cic_ie.cicLow);
407 f_comp_store_cic(client, cic);
408 }
Harald Welte1b2748e2017-11-24 23:40:16 +0100409 }
410
Harald Welte6811d102019-04-14 22:23:14 +0200411 if (ischosen(bssap.pdu.dtap) and g_ran_ops.decode_dtap) {
412 if (g_ran_ops.role_ms) {
Harald Welte0b476062018-01-21 19:07:32 +0100413 /* we are the MS, so any message to us must be MT */
414 var PDU_DTAP_MT mt := {
415 dlci := bssap.dlci,
416 dtap := dec_PDU_ML3_NW_MS(bssap.pdu.dtap)
417 };
418 CLIENT.send(mt) to client;
419 } else {
420 /* we are the Network, so any message to us must be MO */
421 var PDU_DTAP_MO mo := {
422 dlci := bssap.dlci,
423 dtap := dec_PDU_ML3_MS_NW(bssap.pdu.dtap)
424 };
425 CLIENT.send(mo) to client;
426 }
427 } else {
428 CLIENT.send(bssap) to client;
429 }
Harald Welte365f4ed2017-11-23 00:00:43 +0100430}
431
432/* call-back type, to be provided by specific implementation; called when new SCCP connection
433 * arrives */
Harald Welte004f5fb2017-12-16 17:54:40 +0100434type function BssmapCreateCallback(BSSAP_N_CONNECT_ind conn_ind, charstring id)
Harald Welte6811d102019-04-14 22:23:14 +0200435runs on RAN_Emulation_CT return RAN_ConnHdlr;
Harald Welte365f4ed2017-11-23 00:00:43 +0100436
437type function BssmapUnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200438runs on RAN_Emulation_CT return template PDU_BSSAP;
Harald Welte365f4ed2017-11-23 00:00:43 +0100439
Harald Welte17d21152018-01-27 00:47:11 +0100440/* handle common Unitdata such as Paging */
441private function CommonBssmapUnitdataCallback(PDU_BSSAP bssap)
Harald Welte6811d102019-04-14 22:23:14 +0200442runs on RAN_Emulation_CT return template PDU_BSSAP {
Harald Welte17d21152018-01-27 00:47:11 +0100443 if (match(bssap, tr_BSSMAP_Paging)) {
Harald Welte6811d102019-04-14 22:23:14 +0200444 var RAN_ConnHdlr client := null;
Harald Welte17d21152018-01-27 00:47:11 +0100445 client := f_imsi_table_find(bssap.pdu.bssmap.paging.iMSI.digits,
446 bssap.pdu.bssmap.paging.tMSI.tmsiOctets);
Daniel Willmannabc73e12019-04-15 17:25:56 +0200447 if (client != null) {
Harald Welte17d21152018-01-27 00:47:11 +0100448 log("CommonBssmapUnitdataCallback: IMSI/TMSI found in table, dispatching to ",
449 client);
450 CLIENT.send(bssap) to client;
451 return omit;
452 }
453 log("CommonBssmapUnitdataCallback: IMSI/TMSI not found in table");
454 } else {
455 log("CommonBssmapUnitdataCallback: Not a paging message");
456 }
457 /* ELSE: handle in user callback */
Harald Welte6811d102019-04-14 22:23:14 +0200458 return g_ran_ops.unitdata_cb.apply(bssap);
Harald Welte17d21152018-01-27 00:47:11 +0100459}
460
Harald Welte6811d102019-04-14 22:23:14 +0200461private function f_bssap_wait_for_reset() runs on RAN_Emulation_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +0100462 var BSSAP_N_UNITDATA_ind ud_ind;
463 timer T := 20.0;
464
465 T.start;
466 alt {
467 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
468 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
469 ts_BSSMAP_ResetAck));
470 }
471 [] as_reset_ack();
472 [] BSSAP.receive {
473 repeat;
474 }
475 [] T.timeout {
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200476 setverdict(fail, "Timeout waiting for BSSAP RESET");
477 mtc.stop;
Harald Weltea4ca4462018-02-09 00:17:14 +0100478 }
479 }
480}
481
Harald Welte6811d102019-04-14 22:23:14 +0200482function f_bssap_reset(SCCP_PAR_Address peer, SCCP_PAR_Address own) runs on RAN_Emulation_CT {
Harald Weltea4ca4462018-02-09 00:17:14 +0100483 timer T := 5.0;
484
485 BSSAP.send(ts_BSSAP_UNITDATA_req(peer, own, ts_BSSMAP_Reset(0)));
486 T.start;
487 alt {
488 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(own, peer, tr_BSSMAP_ResetAck)) {
489 log("Received RESET-ACK in response to RESET, we're ready to go!");
490 }
491 [] as_reset_ack();
492 [] BSSAP.receive { repeat };
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200493 [] T.timeout {
494 setverdict(fail, "Timeout waiting for RESET-ACK after sending RESET");
495 mtc.stop;
496 }
Harald Weltea4ca4462018-02-09 00:17:14 +0100497 }
498}
499
Harald Welte2fce7882019-04-15 11:48:05 +0200500private function f_bssap_l3_is_rr(PDU_BSSAP bssap) return boolean {
501 var template octetstring l3 := f_bssap_extract_l3(bssap);
502 return f_L3_is_rr(l3);
503}
504#endif
Harald Welte365f4ed2017-11-23 00:00:43 +0100505
Harald Welte5b027622019-04-14 23:40:17 +0200506#ifdef RAN_EMULATION_RANAP
507type record RANAP_Conn_Req {
508 SCCP_PAR_Address addr_peer,
509 SCCP_PAR_Address addr_own,
510 RANAP_PDU ranap
511}
512template (value) RANAP_Conn_Req ts_RANAP_Conn_Req(SCCP_PAR_Address peer, SCCP_PAR_Address own, RANAP_PDU ranap) := {
513 addr_peer := peer,
514 addr_own := own,
515 ranap := ranap
516};
517
518private function fake_dlci_from_sapi(template (omit) SAPI sapi) return template (omit) OCT1
519{
520 if (istemplatekind(sapi, "omit")) {
521 return omit;
522 } else if (valueof(sapi) == sapi_3) {
523 return '03'O;
524 }
525 return '00'O;
526}
527
528private function f_handle_userData_RANAP(RAN_ConnHdlr client, RANAP_PDU ranap)
529runs on RAN_Emulation_CT {
530 /* decode + send decoded RANAP to client */
531 var template (omit) octetstring l3 := f_ranap_extract_l3(ranap);
532 if (istemplatekind(l3, "omit")) {
533 CLIENT.send(ranap) to client;
534 } else {
535 var template (omit) SAPI sapi := f_ranap_extract_sapi(ranap);
536 var template (omit) OCT1 dlci := fake_dlci_from_sapi(sapi);
537 if (g_ran_ops.role_ms) {
538 /* we are the MS, so any message to us must be MT */
539 var PDU_DTAP_MT mt := {
540 dlci := omit,
541 dtap := dec_PDU_ML3_NW_MS(valueof(l3))
542 };
543 if (isvalue(dlci)) {
544 mt.dlci := valueof(dlci)
545 }
546 CLIENT.send(mt) to client;
547 } else {
548 /* we are the Network, so any message to us must be MO */
549 var PDU_DTAP_MO mo := {
550 dlci := omit,
551 dtap := dec_PDU_ML3_MS_NW(valueof(l3))
552 };
553 if (isvalue(dlci)) {
554 mo.dlci := valueof(dlci)
555 }
556 CLIENT.send(mo) to client;
557 }
558 }
559}
560
561/* call-back type, to be provided by specific implementation; called when new SCCP connection
562 * arrives */
563type function RanapCreateCallback(RANAP_N_CONNECT_ind conn_ind, charstring id)
564runs on RAN_Emulation_CT return RAN_ConnHdlr;
565
566type function RanapUnitdataCallback(RANAP_PDU ranap)
567runs on RAN_Emulation_CT return template RANAP_PDU;
568
569private function CommonRanapUnitdataCallback(RANAP_PDU ranap)
570runs on RAN_Emulation_CT return template RANAP_PDU {
571 if (match(ranap, tr_RANAP_Paging(?, ?))) {
572 var RAN_ConnHdlr client := null;
573 /* extract IMSI and (if present) TMSI */
574 var IMSI imsi := ranap.initiatingMessage.value_.paging.protocolIEs[1].value_.permanentNAS_UE_ID.iMSI;
575 var template OCT4 tmsi := omit;
576 if (lengthof(ranap.initiatingMessage.value_.paging.protocolIEs) > 2 and
577 ranap.initiatingMessage.value_.paging.protocolIEs[2].id == id_TemporaryUE_ID) {
578 var TemporaryUE_ID ue_id;
579 ue_id := ranap.initiatingMessage.value_.paging.protocolIEs[2].value_.temporaryUE_ID;
580 if (ischosen(ue_id.tMSI)) {
581 tmsi := ue_id.tMSI;
582 } else {
583 tmsi := ue_id.p_TMSI;
584 }
585 }
586 client := f_imsi_table_find(oct2hex(imsi), tmsi);
587 if (isvalue(client)) {
588 log("CommonRanapUnitdataCallback: IMSI/TMSI found in table, dispatching to ",
589 client);
590 CLIENT.send(ranap) to client;
591 return omit;
592 }
593 log("CommonRanapUnitdataCallback: IMSI/TMSI not found in table");
594 } else {
595 log("CommonRanapUnitdataCallback: Not a paging message");
596 }
597
598 /* ELSE: handle in user callback */
599 return g_ran_ops.ranap_unitdata_cb.apply(ranap);
600}
601
602private function f_ranap_l3_is_rr(RANAP_PDU ranap) return boolean {
603 var template (omit) SAPI sapi;
604 var template octetstring l3 := f_ranap_extract_l3(ranap);
605 return f_L3_is_rr(l3);
606}
607
608function f_ranap_reset(SCCP_PAR_Address peer, SCCP_PAR_Address own) runs on RAN_Emulation_CT {
609 timer T := 5.0;
610 var CN_DomainIndicator dom;
611 if (g_ran_ops.ps_domain) {
612 dom := ps_domain;
613 } else {
614 dom := cs_domain;
615 }
616
617 RANAP.send(ts_RANAP_UNITDATA_req(peer, own, ts_RANAP_Reset(ts_RanapCause_om_intervention, dom)));
618 T.start;
619 alt {
620 [] RANAP.receive(tr_RANAP_UNITDATA_ind(own, peer, tr_RANAP_ResetAck)) {
621 log("Received RESET-ACK in response to RESET, we're ready to go!");
622 }
623 [] as_reset_ack();
624 [] RANAP.receive { repeat };
625 [] T.timeout {
626 setverdict(fail, "Timeout waiting for RESET-ACK after sending RESET");
627 mtc.stop;
628 }
629 }
630}
631#endif
Harald Welte365f4ed2017-11-23 00:00:43 +0100632
Harald Welte2fce7882019-04-15 11:48:05 +0200633
634type enumerated RanProtocol {
Harald Welte5b027622019-04-14 23:40:17 +0200635 RAN_PROTOCOL_BSSAP,
636 RAN_PROTOCOL_RANAP
Harald Welte2fce7882019-04-15 11:48:05 +0200637}
638
639type record RanOps {
640#ifdef RAN_EMULATION_BSSAP
641 BssmapCreateCallback create_cb optional,
642 BssmapUnitdataCallback unitdata_cb optional,
643#endif
Harald Welte5b027622019-04-14 23:40:17 +0200644#ifdef RAN_EMULATION_RANAP
645 RanapCreateCallback ranap_create_cb optional,
646 RanapUnitdataCallback ranap_unitdata_cb optional,
647 boolean ps_domain,
648#endif
Harald Welte2fce7882019-04-15 11:48:05 +0200649 boolean decode_dtap,
650 boolean role_ms,
651 RanProtocol protocol,
652 /* needed for performing BSSMAP RESET */
653 SCCP_PAR_Address sccp_addr_local optional,
654 SCCP_PAR_Address sccp_addr_peer optional
655}
656
657template BIT4 t_ML3_DISC_CC_MM_SS := ('0011'B, '0101'B, '1011'B);
658
659private function f_L3_is_rr(template octetstring l3) return boolean {
660 if (not isvalue(l3)) {
661 return false;
Harald Weltea4ca4462018-02-09 00:17:14 +0100662 }
Harald Welte2fce7882019-04-15 11:48:05 +0200663 var octetstring l3v := valueof(l3);
664 if (lengthof(l3v) < 1) {
665 return false;
666 }
667 /* lower 4 bits of first octet are protocol discriminator */
668 if ((oct2bit(l3v[0]) and4b '00001111'B) == '00000110'B) {
669 return true;
670 }
671 return false;
672}
Harald Weltea4ca4462018-02-09 00:17:14 +0100673
Harald Welte2fce7882019-04-15 11:48:05 +0200674/* patch N(SD) into enc_l3, according to 24.007 11.2.3.2 */
675function f_ML3_patch_seq(inout ConnectionData cd, in PDU_ML3_MS_NW dtap, inout octetstring enc_l3) {
676 var uint2_t seq_nr;
677 if (ischosen(dtap.msgs.cc) or ischosen(dtap.msgs.mm) or ischosen(dtap.msgs.ss)) {
678 seq_nr := cd.n_sd[0];
679 cd.n_sd[0] := (cd.n_sd[0] + 1) mod 4;
680 } else if (ischosen(dtap.msgs.gcc)) {
681 seq_nr := cd.n_sd[1];
682 cd.n_sd[1] := (cd.n_sd[1] + 1) mod 2;
683 } else if (ischosen(dtap.msgs.bcc)) {
684 seq_nr := cd.n_sd[2];
685 cd.n_sd[2] := (cd.n_sd[2] + 1) mod 2;
686 } else if (ischosen(dtap.msgs.loc)) {
687 seq_nr := cd.n_sd[3];
688 cd.n_sd[3] := (cd.n_sd[3] + 1) mod 2;
689 } else {
690 /* no sequence number to patch */
691 return;
692 }
693 log("patching N(SD)=", seq_nr, " into dtap ", enc_l3);
694 enc_l3[1] := (enc_l3[1] and4b '3f'O) or4b bit2oct(int2bit(seq_nr, 8) << 6);
695 log("patched enc_l3: ", enc_l3);
696}
697
698private altstep as_reset_ack() runs on RAN_Emulation_CT {
699#ifdef RAN_EMULATION_BSSAP
700 var BSSAP_N_UNITDATA_ind ud_ind;
701#endif
Harald Welte5b027622019-04-14 23:40:17 +0200702#ifdef RAN_EMULATION_RANAP
703 var RANAP_N_UNITDATA_ind rud_ind;
704#endif
Harald Welte2fce7882019-04-15 11:48:05 +0200705#ifdef RAN_EMULATION_BSSAP
706 [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind {
707 log("Respoding to inbound RESET with RESET-ACK");
708 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress,
709 ts_BSSMAP_ResetAck));
710 repeat;
711 }
712#endif
Harald Welte5b027622019-04-14 23:40:17 +0200713#ifdef RAN_EMULATION_RANAP
714 [] RANAP.receive(tr_RANAP_UNITDATA_ind(?, ?, tr_RANAP_Reset)) -> value rud_ind {
715 log("Respoding to inbound IuRESET with IuRESET-ACK");
716 var CN_DomainIndicator dom;
717 dom := rud_ind.userData.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator;
718 RANAP.send(ts_RANAP_UNITDATA_req(rud_ind.callingAddress, rud_ind.calledAddress,
719 ts_RANAP_ResetAck(dom)));
720 }
721#endif
Harald Welte2fce7882019-04-15 11:48:05 +0200722}
723
724
725private altstep as_main_bssap() runs on RAN_Emulation_CT {
726#ifdef RAN_EMULATION_BSSAP
Harald Welte004f5fb2017-12-16 17:54:40 +0100727 var BSSAP_N_UNITDATA_ind ud_ind;
728 var BSSAP_N_CONNECT_ind conn_ind;
729 var BSSAP_N_CONNECT_cfm conn_cfm;
730 var BSSAP_N_DATA_ind data_ind;
731 var BSSAP_N_DISCONNECT_ind disc_ind;
Harald Welteb3414b22017-11-23 18:22:10 +0100732 var BSSAP_Conn_Req creq;
Harald Welte365f4ed2017-11-23 00:00:43 +0100733 var PDU_BSSAP bssap;
Harald Welte2fce7882019-04-15 11:48:05 +0200734 var RAN_ConnHdlr vc_conn;
Harald Welte365f4ed2017-11-23 00:00:43 +0100735
Harald Welte365f4ed2017-11-23 00:00:43 +0100736 /* SCCP -> Client: UNIT-DATA (connectionless SCCP) from a BSC */
Harald Welte004f5fb2017-12-16 17:54:40 +0100737 [] BSSAP.receive(BSSAP_N_UNITDATA_ind:?) -> value ud_ind {
Harald Welte365f4ed2017-11-23 00:00:43 +0100738 /* Connectionless Procedures like RESET */
739 var template PDU_BSSAP resp;
Harald Welte17d21152018-01-27 00:47:11 +0100740 resp := CommonBssmapUnitdataCallback(ud_ind.userData);
Harald Welte365f4ed2017-11-23 00:00:43 +0100741 if (isvalue(resp)) {
Harald Welte004f5fb2017-12-16 17:54:40 +0100742 BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress,
743 ud_ind.calledAddress, resp));
Harald Welte365f4ed2017-11-23 00:00:43 +0100744 }
745 }
Harald Welte365f4ed2017-11-23 00:00:43 +0100746 /* SCCP -> Client: new connection from BSC */
Harald Welte004f5fb2017-12-16 17:54:40 +0100747 [] BSSAP.receive(BSSAP_N_CONNECT_ind:?) -> value conn_ind {
Harald Welte2fce7882019-04-15 11:48:05 +0200748 vc_conn := g_ran_ops.create_cb.apply(conn_ind, g_ran_id);
Harald Welte365f4ed2017-11-23 00:00:43 +0100749 /* store mapping between client components and SCCP connectionId */
750 f_conn_table_add(vc_conn, conn_ind.connectionId);
751 /* handle user payload */
752 f_handle_userData(vc_conn, conn_ind.userData);
753 /* confirm connection establishment */
Harald Welte004f5fb2017-12-16 17:54:40 +0100754 BSSAP.send(ts_BSSAP_CONNECT_res(conn_ind.connectionId, omit));
Harald Welte365f4ed2017-11-23 00:00:43 +0100755 }
Harald Welte365f4ed2017-11-23 00:00:43 +0100756 /* SCCP -> Client: connection-oriented data in existing connection */
Harald Welte004f5fb2017-12-16 17:54:40 +0100757 [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value data_ind {
Harald Welte365f4ed2017-11-23 00:00:43 +0100758 vc_conn := f_comp_by_conn_id(data_ind.connectionId);
Harald Welte5cc4aa22017-11-23 18:51:28 +0100759 if (ispresent(data_ind.userData)) {
760 f_handle_userData(vc_conn, data_ind.userData);
761 }
Harald Welte365f4ed2017-11-23 00:00:43 +0100762 }
Harald Welte365f4ed2017-11-23 00:00:43 +0100763 /* SCCP -> Client: disconnect of an existing connection */
Harald Welte004f5fb2017-12-16 17:54:40 +0100764 [] BSSAP.receive(BSSAP_N_DISCONNECT_ind:?) -> value disc_ind {
Harald Welte365f4ed2017-11-23 00:00:43 +0100765 vc_conn := f_comp_by_conn_id(disc_ind.connectionId);
Harald Welte5cc4aa22017-11-23 18:51:28 +0100766 if (ispresent(disc_ind.userData)) {
767 f_handle_userData(vc_conn, disc_ind.userData);
768 }
Harald Welte365f4ed2017-11-23 00:00:43 +0100769 /* notify client about termination */
Harald Welte6811d102019-04-14 22:23:14 +0200770 var RAN_Conn_Prim prim := MSC_CONN_PRIM_DISC_IND;
Harald Welte365f4ed2017-11-23 00:00:43 +0100771 CLIENT.send(prim) to vc_conn;
772 f_conn_table_del(disc_ind.connectionId);
773 /* TOOD: return confirm to other side? */
774 }
Harald Welteb3414b22017-11-23 18:22:10 +0100775 /* SCCP -> Client: connection confirm for outbound connection */
Harald Welte004f5fb2017-12-16 17:54:40 +0100776 [] BSSAP.receive(BSSAP_N_CONNECT_cfm:?) -> value conn_cfm {
Harald Welte71b69332018-01-21 20:43:53 +0100777 vc_conn := f_comp_by_conn_id(conn_cfm.connectionId);
Harald Welte6811d102019-04-14 22:23:14 +0200778 var RAN_Conn_Prim prim := MSC_CONN_PRIM_CONF_IND;
Harald Welte71b69332018-01-21 20:43:53 +0100779 CLIENT.send(prim) to vc_conn;
Harald Welteb3414b22017-11-23 18:22:10 +0100780 /* handle user payload */
Harald Welte5cc4aa22017-11-23 18:51:28 +0100781 if (ispresent(conn_cfm.userData)) {
782 f_handle_userData(vc_conn, conn_cfm.userData);
783 }
Harald Welteb3414b22017-11-23 18:22:10 +0100784 }
Harald Welte2fce7882019-04-15 11:48:05 +0200785 [] CLIENT.receive(PDU_BSSAP:?) -> value bssap sender vc_conn {
786 var integer conn_id := f_conn_id_by_comp(vc_conn);
787 /* send it to dispatcher */
788 BSSAP.send(ts_BSSAP_DATA_req(conn_id, bssap));
789 }
Harald Welteb3414b22017-11-23 18:22:10 +0100790
Harald Welte365f4ed2017-11-23 00:00:43 +0100791 /* Disconnect request client -> SCCP */
Harald Welte6811d102019-04-14 22:23:14 +0200792 [] CLIENT.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ) -> sender vc_conn {
Harald Welte365f4ed2017-11-23 00:00:43 +0100793 var integer conn_id := f_conn_id_by_comp(vc_conn);
Harald Welte004f5fb2017-12-16 17:54:40 +0100794 BSSAP.send(ts_BSSAP_DISC_req(conn_id, 0));
Harald Welte365f4ed2017-11-23 00:00:43 +0100795 f_conn_table_del(conn_id);
796 }
797
798 /* BSSAP from client -> SCCP */
Harald Welteb3414b22017-11-23 18:22:10 +0100799 [] CLIENT.receive(BSSAP_Conn_Req:?) -> value creq sender vc_conn {
800 var integer conn_id;
Harald Welte004f5fb2017-12-16 17:54:40 +0100801 /* send to dispatcher */
Harald Welteb3414b22017-11-23 18:22:10 +0100802
803 if (f_comp_known(vc_conn) == false) {
804 /* unknown client, create new connection */
805 conn_id := f_gen_conn_id();
806
807 /* store mapping between client components and SCCP connectionId */
808 f_conn_table_add(vc_conn, conn_id);
809
Harald Welte004f5fb2017-12-16 17:54:40 +0100810 BSSAP.send(ts_BSSAP_CONNECT_req(creq.addr_peer, creq.addr_own, conn_id,
811 creq.bssap));
Harald Welteb3414b22017-11-23 18:22:10 +0100812 } else {
813 /* known client, send via existing connection */
814 conn_id := f_conn_id_by_comp(vc_conn);
Harald Welte004f5fb2017-12-16 17:54:40 +0100815 BSSAP.send(ts_BSSAP_DATA_req(conn_id, creq.bssap));
Harald Welteb3414b22017-11-23 18:22:10 +0100816 }
817
Harald Welte49518bf2018-02-10 11:39:19 +0100818 /* InitialL3 contains RR (PAG RESP) or MM (CM SRV REQ), we must increment
819 * counter only on MM/CC/SS, but not on RR */
Harald Welte6811d102019-04-14 22:23:14 +0200820 if (g_ran_ops.role_ms and not f_bssap_l3_is_rr(creq.bssap)) {
Harald Welte9dadc522018-02-06 13:56:04 +0100821 /* we have just sent the first MM message, increment the counter */
822 var integer idx := f_idx_by_comp(vc_conn);
823 ConnectionTable[idx].n_sd[0] := 1;
824 log("patch: N(SD) for ConnIdx ", idx, " set to 1");
825 }
826
Harald Welteb3414b22017-11-23 18:22:10 +0100827 }
Harald Welte2fce7882019-04-15 11:48:05 +0200828#else
Harald Welte5b027622019-04-14 23:40:17 +0200829 [false] CLIENT.receive {}
830#endif
831}
832
833private altstep as_main_ranap() runs on RAN_Emulation_CT {
834#ifdef RAN_EMULATION_RANAP
835 var RANAP_N_UNITDATA_ind rud_ind;
836 var RANAP_N_CONNECT_ind rconn_ind;
837 var RANAP_N_CONNECT_cfm rconn_cfm;
838 var RANAP_N_DATA_ind rdata_ind;
839 var RANAP_N_DISCONNECT_ind rdisc_ind;
840 var RANAP_Conn_Req creq;
841 var RANAP_PDU ranap;
842 var RAN_ConnHdlr vc_conn;
843
844 /* SCCP -> Client: UNIT-DATA (connectionless SCCP) from a BSC */
845 [] RANAP.receive(RANAP_N_UNITDATA_ind:?) -> value rud_ind {
846 /* Connectionless Procedures like RESET */
847 var template RANAP_PDU resp;
848 resp := CommonRanapUnitdataCallback(rud_ind.userData);
849 if (isvalue(resp)) {
850 RANAP.send(ts_RANAP_UNITDATA_req(rud_ind.callingAddress,
851 rud_ind.calledAddress, resp));
852 }
853 }
854 /* SCCP -> Client: new connection from BSC */
855 [] RANAP.receive(RANAP_N_CONNECT_ind:?) -> value rconn_ind {
856 vc_conn := g_ran_ops.ranap_create_cb.apply(rconn_ind, g_ran_id);
857 /* store mapping between client components and SCCP connectionId */
858 f_conn_table_add(vc_conn, rconn_ind.connectionId);
859 /* handle user payload */
860 f_handle_userData_RANAP(vc_conn, rconn_ind.userData);
861 /* confirm connection establishment */
862 RANAP.send(ts_RANAP_CONNECT_res(rconn_ind.connectionId, omit));
863 }
864 /* SCCP -> Client: connection-oriented data in existing connection */
865 [] RANAP.receive(RANAP_N_DATA_ind:?) -> value rdata_ind {
866 vc_conn := f_comp_by_conn_id(rdata_ind.connectionId);
867 if (ispresent(rdata_ind.userData)) {
868 f_handle_userData_RANAP(vc_conn, rdata_ind.userData);
869 }
870 }
871 /* SCCP -> Client: disconnect of an existing connection */
872 [] RANAP.receive(RANAP_N_DISCONNECT_ind:?) -> value rdisc_ind {
873 vc_conn := f_comp_by_conn_id(rdisc_ind.connectionId);
874 if (ispresent(rdisc_ind.userData)) {
875 f_handle_userData_RANAP(vc_conn, rdisc_ind.userData);
876 }
877 /* notify client about termination */
878 var RAN_Conn_Prim prim := MSC_CONN_PRIM_DISC_IND;
879 CLIENT.send(prim) to vc_conn;
880 f_conn_table_del(rdisc_ind.connectionId);
881 /* TOOD: return confirm to other side? */
882 }
883 /* SCCP -> Client: connection confirm for outbound connection */
884 [] RANAP.receive(RANAP_N_CONNECT_cfm:?) -> value rconn_cfm {
885 vc_conn := f_comp_by_conn_id(rconn_cfm.connectionId);
886 var RAN_Conn_Prim prim := MSC_CONN_PRIM_CONF_IND;
887 CLIENT.send(prim) to vc_conn;
888 /* handle user payload */
889 if (ispresent(rconn_cfm.userData)) {
890 f_handle_userData_RANAP(vc_conn, rconn_cfm.userData);
891 }
892 }
893
894 [] CLIENT.receive(RANAP_PDU:?) -> value ranap sender vc_conn {
895 var integer conn_id := f_conn_id_by_comp(vc_conn);
896 /* send it to dispatcher */
897 RANAP.send(ts_RANAP_DATA_req(conn_id, ranap));
898 }
899
900 /* Disconnect request client -> SCCP */
901 [] CLIENT.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ) -> sender vc_conn {
902 var integer conn_id := f_conn_id_by_comp(vc_conn);
903 RANAP.send(ts_RANAP_DISC_req(conn_id, 0));
904 f_conn_table_del(conn_id);
905 }
906
907 /* BSSAP from client -> SCCP */
908 [] CLIENT.receive(RANAP_Conn_Req:?) -> value creq sender vc_conn {
909 var integer conn_id;
910 /* send to dispatcher */
911
912 if (f_comp_known(vc_conn) == false) {
913 /* unknown client, create new connection */
914 conn_id := f_gen_conn_id();
915
916 /* store mapping between client components and SCCP connectionId */
917 f_conn_table_add(vc_conn, conn_id);
918
919 RANAP.send(ts_RANAP_CONNECT_req(creq.addr_peer, creq.addr_own, conn_id,
920 creq.ranap));
921 } else {
922 /* known client, send via existing connection */
923 conn_id := f_conn_id_by_comp(vc_conn);
924 RANAP.send(ts_RANAP_DATA_req(conn_id, creq.ranap));
925 }
926
927 /* InitialL3 contains RR (PAG RESP) or MM (CM SRV REQ), we must increment
928 * counter only on MM/CC/SS, but not on RR */
929 if (g_ran_ops.role_ms and not f_ranap_l3_is_rr(creq.ranap)) {
930 /* we have just sent the first MM message, increment the counter */
931 var integer idx := f_idx_by_comp(vc_conn);
932 ConnectionTable[idx].n_sd[0] := 1;
933 log("patch: N(SD) for ConnIdx ", idx, " set to 1");
934 }
935 }
936
937#else
938 [false] CLIENT.receive {}
Harald Welte2fce7882019-04-15 11:48:05 +0200939#endif
940}
Harald Welteb3414b22017-11-23 18:22:10 +0100941
Harald Welte2fce7882019-04-15 11:48:05 +0200942private altstep as_main_mgcp() runs on RAN_Emulation_CT {
943#ifdef RAN_EMULATION_MGCP
944 var MgcpCommand mgcp_req;
945 var MgcpResponse mgcp_resp;
946 var RAN_ConnHdlr vc_conn;
Harald Welte0b476062018-01-21 19:07:32 +0100947
Harald Weltec82eef42017-11-24 20:40:12 +0100948 /* Handling of MGCP in IPA SCCPLite case. This predates 3GPP AoIP
949 * and uses a MGCP session in parallel to BSSAP. BSSAP uses CIC
950 * as usual, and MGCP uses "CIC@mgw" endpoint naming, where CIC
951 * is printed as hex string, e.g. a@mgw for CIC 10 */
952
953 /* CLIENT -> MGCP */
954 [] CLIENT.receive(MgcpCommand:?) -> value mgcp_req sender vc_conn {
955 /* MGCP request from Handler (we're MSC) */
956 /* store the transaction ID we've seen */
957 f_comp_store_mgcp_tid(vc_conn, mgcp_req.line.trans_id);
958 /* simply forward any MGCP from the client to the port */
959 MGCP.send(mgcp_req);
960 }
961 [] CLIENT.receive(MgcpResponse:?) -> value mgcp_resp sender vc_conn {
962 /* MGCP response from Handler (we're BSC/MGW) */
963 /* simply forward any MGCP from the client to the port */
964 MGCP.send(mgcp_resp);
965 }
966
967 /* MGCP -> CLIENT */
968 [] MGCP.receive(MgcpCommand:?) -> value mgcp_req {
969 /* MGCP request from network side (we're BSC/MGW) */
970 /* Extract CIC from local part of endpoint name */
971 var integer cic := f_mgcp_ep_extract_cic(mgcp_req.line.ep);
Harald Weltee98bb2e2017-11-29 12:09:48 +0100972 if (match(mgcp_req, tr_RSIP) and f_cic_known(cic) == false) {
973 /* ignore RSIP for unknown CIC */
974 } else {
975 /* Resolve the vc_conn by the CIC */
976 vc_conn := f_comp_by_cic(cic);
977 CLIENT.send(mgcp_req) to vc_conn;
978 }
Harald Weltec82eef42017-11-24 20:40:12 +0100979 }
980 [] MGCP.receive(MgcpResponse:?) -> value mgcp_resp {
981 /* MGCP response from network side (we're MSC) */
982 /* Resolve the vc_conn by the transaction ID */
983 vc_conn := f_comp_by_mgcp_tid(mgcp_resp.line.trans_id);
984 CLIENT.send(mgcp_resp) to vc_conn;
985 }
Harald Welte2fce7882019-04-15 11:48:05 +0200986#else
987 [false] CLIENT.receive {}
988#endif
989}
Harald Weltec82eef42017-11-24 20:40:12 +0100990
Harald Welte2fce7882019-04-15 11:48:05 +0200991/* send a raw (encoded) L3 message over given SCCP connection */
992private function f_xmit_raw_l3(integer sccp_conn_id, OCT1 dlci, octetstring l3_enc) runs on RAN_Emulation_CT
993{
994 select (g_ran_ops.protocol) {
995#ifdef RAN_EMULATION_BSSAP
996 case (RAN_PROTOCOL_BSSAP) {
997 var PDU_BSSAP bssap;
998 bssap := valueof(ts_BSSAP_DTAP(l3_enc, dlci));
999 BSSAP.send(ts_BSSAP_DATA_req(sccp_conn_id, bssap));
1000 }
1001#endif
Harald Welte5b027622019-04-14 23:40:17 +02001002#ifdef RAN_EMULATION_RANAP
1003 case (RAN_PROTOCOL_RANAP) {
1004 var RANAP_PDU ranap;
1005 if (false /* SAPI */) {
1006 var RANAP_IEs.SAPI sapi := sapi_0;
1007 ranap := valueof(ts_RANAP_DirectTransferSAPI(l3_enc, sapi));
1008 } else {
1009 ranap := valueof(ts_RANAP_DirectTransfer(l3_enc));
1010 }
1011 RANAP.send(ts_RANAP_DATA_req(sccp_conn_id, ranap));
1012 }
1013#endif
Harald Welte2fce7882019-04-15 11:48:05 +02001014 }
1015}
1016
1017function main(RanOps ops, charstring id) runs on RAN_Emulation_CT {
1018
1019 g_ran_id := id;
1020 g_ran_ops := ops;
1021 f_conn_table_init();
1022 f_expect_table_init();
1023
1024 if (isvalue(ops.sccp_addr_peer) and isvalue(ops.sccp_addr_local)) {
1025 f_sleep(1.0); /* HACK to wait for M3UA/ASP to be ACTIVE */
Harald Welte5b027622019-04-14 23:40:17 +02001026 select (g_ran_ops.protocol) {
1027#ifdef RAN_EMULATION_BSSAP
1028 case (RAN_PROTOCOL_BSSAP) {
1029 f_bssap_reset(ops.sccp_addr_peer, ops.sccp_addr_local);
1030 }
1031#endif
1032#ifdef RAN_EMULATION_RANAP
1033 case (RAN_PROTOCOL_RANAP) {
1034 f_ranap_reset(ops.sccp_addr_peer, ops.sccp_addr_local);
1035 }
1036#endif
1037 }
Harald Welte2fce7882019-04-15 11:48:05 +02001038 }
1039
1040 while (true) {
1041 var RAN_ConnHdlr vc_conn;
1042 var PDU_DTAP_MO dtap_mo;
1043 var PDU_DTAP_MT dtap_mt;
1044 var RAN_ConnHdlr vc_hdlr;
1045 var octetstring l3_info;
1046 var hexstring imsi;
1047 var OCT4 tmsi;
1048
1049 alt {
1050 [g_ran_ops.protocol == RAN_PROTOCOL_BSSAP] as_main_bssap();
Harald Welte5b027622019-04-14 23:40:17 +02001051 [g_ran_ops.protocol == RAN_PROTOCOL_RANAP] as_main_ranap();
Harald Welte2fce7882019-04-15 11:48:05 +02001052
1053 [g_ran_ops.role_ms] CLIENT.receive(PDU_DTAP_MO:?) -> value dtap_mo sender vc_conn {
1054 var integer idx := f_idx_by_comp(vc_conn);
1055 /* convert from decoded DTAP to encoded DTAP */
1056 var octetstring l3_enc := enc_PDU_ML3_MS_NW(dtap_mo.dtap);
1057 /* patch correct L3 send sequence number N(SD) into l3_enc */
1058 if (dtap_mo.skip_seq_patching == false) {
1059 f_ML3_patch_seq(ConnectionTable[idx], dtap_mo.dtap, l3_enc);
1060 }
1061 f_xmit_raw_l3(ConnectionTable[idx].sccp_conn_id, dtap_mo.dlci, l3_enc);
1062 }
1063
1064 [not g_ran_ops.role_ms] CLIENT.receive(PDU_DTAP_MT:?) -> value dtap_mt sender vc_conn {
1065 var integer idx := f_idx_by_comp(vc_conn);
1066 /* convert from decoded DTAP to encoded DTAP */
1067 var octetstring l3_enc := enc_PDU_ML3_NW_MS(dtap_mt.dtap);
1068 f_xmit_raw_l3(ConnectionTable[idx].sccp_conn_id, dtap_mt.dlci, l3_enc);
1069 }
1070
1071 [] as_main_mgcp();
Harald Welte624f9632017-12-16 19:26:04 +01001072
Harald Welte6811d102019-04-14 22:23:14 +02001073 [] PROC.getcall(RAN_register:{?,?}) -> param(l3_info, vc_hdlr) {
Harald Welte624f9632017-12-16 19:26:04 +01001074 f_create_expect(l3_info, vc_hdlr);
Harald Welte6811d102019-04-14 22:23:14 +02001075 PROC.reply(RAN_register:{l3_info, vc_hdlr}) to vc_hdlr;
Harald Welte624f9632017-12-16 19:26:04 +01001076 }
1077
Harald Welte6811d102019-04-14 22:23:14 +02001078 [] PROC.getcall(RAN_register_imsi:{?,?,?}) -> param(imsi, tmsi, vc_hdlr) {
Harald Welte17d21152018-01-27 00:47:11 +01001079 f_create_imsi(imsi, tmsi, vc_hdlr);
Harald Welte6811d102019-04-14 22:23:14 +02001080 PROC.reply(RAN_register_imsi:{imsi, tmsi, vc_hdlr}) to vc_hdlr;
Harald Welte17d21152018-01-27 00:47:11 +01001081 }
1082
1083
Harald Welte365f4ed2017-11-23 00:00:43 +01001084 }
1085 }
1086}
1087
Harald Welte2fce7882019-04-15 11:48:05 +02001088#ifdef RAN_EMULATION_MGCP
Harald Weltec82eef42017-11-24 20:40:12 +01001089private function f_mgcp_ep_extract_cic(charstring inp) return integer {
Harald Welte525a9c12017-11-24 23:40:41 +01001090 var charstring local_part := regexp(inp, "(*)@*", 0);
Harald Weltec82eef42017-11-24 20:40:12 +01001091 return hex2int(str2hex(local_part));
1092
1093}
Harald Welte2fce7882019-04-15 11:48:05 +02001094#endif
Harald Welte365f4ed2017-11-23 00:00:43 +01001095
Harald Welte624f9632017-12-16 19:26:04 +01001096/***********************************************************************
1097 * "Expect" Handling (mapping for expected incoming SCCP connections)
1098 ***********************************************************************/
1099
1100/* data about an expected future incoming connection */
1101type record ExpectData {
1102 /* L3 payload based on which we can match it */
1103 octetstring l3_payload optional,
1104 /* component reference for this connection */
Harald Welte6811d102019-04-14 22:23:14 +02001105 RAN_ConnHdlr vc_conn
Harald Welte624f9632017-12-16 19:26:04 +01001106}
1107
1108/* procedure based port to register for incoming connections */
Harald Welte6811d102019-04-14 22:23:14 +02001109signature RAN_register(in octetstring l3, in RAN_ConnHdlr hdlr);
Harald Welte624f9632017-12-16 19:26:04 +01001110
Harald Welte17d21152018-01-27 00:47:11 +01001111/* procedure based port to register for incoming IMSI/TMSI */
Harald Welte6811d102019-04-14 22:23:14 +02001112signature RAN_register_imsi(in hexstring imsi, in OCT4 tmsi, in RAN_ConnHdlr hdlr);
Harald Welte17d21152018-01-27 00:47:11 +01001113
Harald Welte6811d102019-04-14 22:23:14 +02001114type port RAN_PROC_PT procedure {
1115 inout RAN_register, RAN_register_imsi;
Harald Welte624f9632017-12-16 19:26:04 +01001116} with { extension "internal" };
1117
Harald Welte5b027622019-04-14 23:40:17 +02001118#ifdef RAN_EMULATION_BSSAP
Harald Welte624f9632017-12-16 19:26:04 +01001119/* CreateCallback that can be used as create_cb and will use the expectation table */
1120function ExpectedCreateCallback(BSSAP_N_CONNECT_ind conn_ind, charstring id)
Harald Welte6811d102019-04-14 22:23:14 +02001121runs on RAN_Emulation_CT return RAN_ConnHdlr {
1122 var RAN_ConnHdlr ret := null;
Harald Welte624f9632017-12-16 19:26:04 +01001123 var octetstring l3_info;
1124 var integer i;
1125
1126 if (not ischosen(conn_ind.userData.pdu.bssmap.completeLayer3Information)) {
1127 setverdict(fail, "N-CONNECT.ind with L3 != COMPLETE L3");
Daniel Willmanne4ff5372018-07-05 17:35:03 +02001128 mtc.stop;
Harald Welte624f9632017-12-16 19:26:04 +01001129 return ret;
1130 }
1131 l3_info := conn_ind.userData.pdu.bssmap.completeLayer3Information.layer3Information.layer3info;
1132
1133 for (i := 0; i < sizeof(ExpectTable); i:= i+1) {
1134 if (not ispresent(ExpectTable[i].l3_payload)) {
1135 continue;
1136 }
1137 if (l3_info == ExpectTable[i].l3_payload) {
1138 ret := ExpectTable[i].vc_conn;
1139 /* release this entry to be used again */
1140 ExpectTable[i].l3_payload := omit;
1141 ExpectTable[i].vc_conn := null;
1142 log("Found Expect[", i, "] for ", l3_info, " handled at ", ret);
1143 /* return the component reference */
1144 return ret;
1145 }
1146 }
1147 setverdict(fail, "Couldn't find Expect for incoming connection ", conn_ind);
Daniel Willmanne4ff5372018-07-05 17:35:03 +02001148 mtc.stop;
Harald Welte624f9632017-12-16 19:26:04 +01001149 return ret;
1150}
Harald Welte5b027622019-04-14 23:40:17 +02001151#endif
1152
1153#ifdef RAN_EMULATION_RANAP
1154/* CreateCallback that can be used as create_cb and will use the expectation table */
1155function RanapExpectedCreateCallback(RANAP_N_CONNECT_ind conn_ind, charstring id)
1156runs on RAN_Emulation_CT return RAN_ConnHdlr {
1157 var RAN_ConnHdlr ret := null;
1158 var template (omit) octetstring l3_info;
1159 var integer i;
1160
1161 l3_info := f_ranap_extract_l3(conn_ind.userData);
1162 if (istemplatekind(l3_info, "omit")) {
1163 setverdict(fail, "N-CONNECT.ind without NAS payload");
1164 mtc.stop;
1165 return ret;
1166 }
1167
1168 for (i := 0; i < sizeof(ExpectTable); i:= i+1) {
1169 if (not ispresent(ExpectTable[i].l3_payload)) {
1170 continue;
1171 }
1172 if (valueof(l3_info) == ExpectTable[i].l3_payload) {
1173 ret := ExpectTable[i].vc_conn;
1174 /* release this entry to be used again */
1175 ExpectTable[i].l3_payload := omit;
1176 ExpectTable[i].vc_conn := null;
1177 log("Found Expect[", i, "] for ", l3_info, " handled at ", ret);
1178 /* return the component reference */
1179 return ret;
1180 }
1181 }
1182 setverdict(fail, "Couldn't find Expect for incoming connection ", conn_ind);
1183 mtc.stop;
1184 return ret;
1185}
1186#endif
Harald Welte624f9632017-12-16 19:26:04 +01001187
Harald Welte6811d102019-04-14 22:23:14 +02001188private function f_create_expect(octetstring l3, RAN_ConnHdlr hdlr)
1189runs on RAN_Emulation_CT {
Harald Welte624f9632017-12-16 19:26:04 +01001190 var integer i;
1191 for (i := 0; i < sizeof(ExpectTable); i := i+1) {
1192 if (not ispresent(ExpectTable[i].l3_payload)) {
1193 ExpectTable[i].l3_payload := l3;
1194 ExpectTable[i].vc_conn := hdlr;
1195 log("Created Expect[", i, "] for ", l3, " to be handled at ", hdlr);
1196 return;
1197 }
1198 }
Daniel Willmanne4ff5372018-07-05 17:35:03 +02001199 testcase.stop("No space left in ExpectTable");
Harald Welte624f9632017-12-16 19:26:04 +01001200}
1201
Harald Welte6811d102019-04-14 22:23:14 +02001202private function f_create_imsi(hexstring imsi, OCT4 tmsi, RAN_ConnHdlr hdlr)
1203runs on RAN_Emulation_CT {
Harald Welte17d21152018-01-27 00:47:11 +01001204 for (var integer i := 0; i < sizeof(ImsiTable); i := i+1) {
1205 if (not ispresent(ImsiTable[i].imsi)) {
1206 ImsiTable[i].imsi := imsi;
1207 ImsiTable[i].tmsi := tmsi;
1208 ImsiTable[i].comp_ref := hdlr;
1209 log("Created IMSI[", i, "] for ", imsi, tmsi, " to be handled at ", hdlr);
1210 return;
1211 }
1212 }
Daniel Willmanne4ff5372018-07-05 17:35:03 +02001213 testcase.stop("No space left in ImsiTable");
Harald Welte17d21152018-01-27 00:47:11 +01001214}
1215
1216
Daniel Willmannd47106b2018-01-17 12:20:56 +01001217private function f_expect_table_init()
Harald Welte6811d102019-04-14 22:23:14 +02001218runs on RAN_Emulation_CT {
Daniel Willmannd47106b2018-01-17 12:20:56 +01001219 for (var integer i := 0; i < sizeof(ExpectTable); i := i+1) {
1220 ExpectTable[i].l3_payload := omit;
1221 }
1222}
Harald Welte624f9632017-12-16 19:26:04 +01001223
Harald Welte17d21152018-01-27 00:47:11 +01001224/* helper function for clients to register their IMSI/TMSI */
Harald Welte6811d102019-04-14 22:23:14 +02001225function f_ran_register_imsi(hexstring imsi, OCT4 tmsi)
1226runs on RAN_ConnHdlr {
1227 BSSAP_PROC.call(RAN_register_imsi:{imsi, tmsi, self}) {
1228 [] BSSAP_PROC.getreply(RAN_register_imsi:{?,?,?}) {};
Harald Welte17d21152018-01-27 00:47:11 +01001229 }
1230}
1231
Harald Welte475a2c12019-05-02 19:05:48 +02001232#ifdef RAN_EMULATION_RANAP
1233/* expect a IuReleaseCommand; Confirm that; expect SCCP-level N-DISCONNET.ind */
1234altstep as_iu_release_compl_disc(float t := 5.0) runs on RAN_ConnHdlr {
1235 var RANAP_PDU ranap;
1236 [] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) {
1237 BSSAP.send(ts_RANAP_IuReleaseComplete);
1238 alt {
1239 [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) {
1240 setverdict(pass);
1241 }
1242 [] BSSAP.receive {
1243 setverdict(fail, "Unexpected RANAP while waiting for SCCP Release ");
1244 mtc.stop;
1245 }
1246 }
1247 }
1248 [] BSSAP.receive(RANAP_PDU:?) -> value ranap{
1249 setverdict(fail, "Unexpected RANAP while waiting for IuReleaseCommand", ranap);
1250 mtc.stop;
1251 }
1252}
1253#endif
1254
Harald Welte17d21152018-01-27 00:47:11 +01001255
Harald Welte365f4ed2017-11-23 00:00:43 +01001256}