Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 1 | module BSSMAP_Emulation { |
| 2 | |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 3 | /* BSSMAP Emulation, runs on top of BSSAP_CodecPort. It multiplexes/demultiplexes |
| 4 | * the individual connections, so there can be separate TTCN-3 components handling |
| 5 | * each of the connections. |
| 6 | * |
| 7 | * The BSSMAP_Emulation.main() function processes SCCP primitives from the SCCP |
| 8 | * 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 |
| 11 | * to the component running the BSSMAP_Emulation.main() function. |
| 12 | * |
| 13 | * For each new inbound connections, the BssmapOps.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 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 | * |
| 22 | * Inbound Unit Data messages (such as are dispatched to the BssmapOps.unitdata_cb() callback, |
| 23 | * which is registered with an argument to the main() function below. |
| 24 | * |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 25 | * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 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. |
| 30 | */ |
| 31 | |
| 32 | |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 33 | import from General_Types all; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 34 | import from SCCP_Emulation all; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 35 | import from SCCPasp_Types all; |
| 36 | import from BSSAP_Types all; |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 37 | import from BSSAP_CodecPort all; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 38 | import from BSSMAP_Templates all; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 39 | import from MGCP_Types all; |
| 40 | import from MGCP_Templates all; |
| 41 | import from IPA_Emulation all; |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 42 | import from MobileL3_Types all; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 43 | |
| 44 | /* General "base class" component definition, of which specific implementations |
| 45 | * derive themselves by means of the "extends" feature */ |
| 46 | type component BSSAP_ConnHdlr { |
| 47 | /* port towards MSC Emulator core / SCCP connection dispatchar */ |
| 48 | port BSSAP_Conn_PT BSSAP; |
Harald Welte | ca51998 | 2018-01-21 19:28:26 +0100 | [diff] [blame] | 49 | /* procedure based port to register for incoming connections */ |
| 50 | port BSSMAPEM_PROC_PT BSSAP_PROC; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /* Auxiliary primitive that can happen on the port between per-connection client and this dispatcher */ |
| 54 | type enumerated BSSAP_Conn_Prim { |
| 55 | /* SCCP tell us that connection was released */ |
| 56 | MSC_CONN_PRIM_DISC_IND, |
| 57 | /* we tell SCCP to release connection */ |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 58 | MSC_CONN_PRIM_DISC_REQ, |
| 59 | /* Connection confirmed indication */ |
| 60 | MSC_CONN_PRIM_CONF_IND |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 61 | } |
| 62 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 63 | type record BSSAP_Conn_Req { |
| 64 | SCCP_PAR_Address addr_peer, |
| 65 | SCCP_PAR_Address addr_own, |
| 66 | PDU_BSSAP bssap |
| 67 | } |
| 68 | |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 69 | /* similar to PDU_BSSAP with DTAP, but DTAP is already decoded! */ |
| 70 | type record PDU_DTAP_MO { |
| 71 | OCT1 dlci optional, |
| 72 | PDU_ML3_MS_NW dtap |
| 73 | } |
| 74 | |
| 75 | /* similar to PDU_BSSAP with DTAP, but DTAP is already decoded! */ |
| 76 | type record PDU_DTAP_MT { |
| 77 | OCT1 dlci optional, |
| 78 | PDU_ML3_NW_MS dtap |
| 79 | } |
| 80 | |
| 81 | template PDU_DTAP_MT ts_PDU_DTAP_MT(template PDU_ML3_NW_MS dtap, template OCT1 dlci := omit) := { |
| 82 | dlci := dlci, |
| 83 | dtap := dtap |
| 84 | } |
| 85 | |
| 86 | template PDU_DTAP_MO ts_PDU_DTAP_MO(template PDU_ML3_MS_NW dtap, template OCT1 dlci := '00'O) := { |
| 87 | dlci := dlci, |
| 88 | dtap := dtap |
| 89 | } |
| 90 | |
| 91 | template PDU_DTAP_MT tr_PDU_DTAP_MT(template PDU_ML3_NW_MS dtap, template OCT1 dlci := *) := { |
| 92 | dlci := dlci, |
| 93 | dtap := dtap |
| 94 | } |
| 95 | |
| 96 | template PDU_DTAP_MO tr_PDU_DTAP_MO(template PDU_ML3_MS_NW dtap, template OCT1 dlci := *) := { |
| 97 | dlci := dlci, |
| 98 | dtap := dtap |
| 99 | } |
| 100 | |
| 101 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 102 | /* port between individual per-connection components and this dispatcher */ |
| 103 | type port BSSAP_Conn_PT message { |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 104 | inout PDU_BSSAP, PDU_DTAP_MO, PDU_DTAP_MT, BSSAP_Conn_Prim, BSSAP_Conn_Req, MgcpCommand, MgcpResponse; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 105 | } with { extension "internal" }; |
| 106 | |
| 107 | |
| 108 | /* represents a single BSSAP connection over SCCP */ |
| 109 | type record ConnectionData { |
| 110 | /* reference to the instance of the per-connection component */ |
| 111 | BSSAP_ConnHdlr comp_ref, |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 112 | integer sccp_conn_id, |
| 113 | /* most recent MGCP transaction ID (Used on MSC side) */ |
| 114 | MgcpTransId mgcp_trans_id optional, |
| 115 | /* CIC that has been used for voice of this channel (BSC side) */ |
| 116 | integer cic optional |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 117 | } |
| 118 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 119 | type record ImsiMapping { |
| 120 | BSSAP_ConnHdlr comp_ref, |
| 121 | hexstring imsi optional, |
| 122 | OCT4 tmsi |
| 123 | } |
| 124 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 125 | type component BSSMAP_Emulation_CT { |
| 126 | /* SCCP port on the bottom side, using ASP primitives */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 127 | port BSSAP_CODEC_PT BSSAP; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 128 | /* BSSAP port to the per-connection clients */ |
| 129 | port BSSAP_Conn_PT CLIENT; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 130 | /* MGCP port */ |
| 131 | port IPA_MGCP_PT MGCP; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 132 | |
| 133 | /* use 16 as this is also the number of SCCP connections that SCCP_Emulation can handle */ |
| 134 | var ConnectionData ConnectionTable[16]; |
Harald Welte | 66fecd4 | 2017-11-24 23:53:23 +0100 | [diff] [blame] | 135 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 136 | /* pending expected incoming connections */ |
| 137 | var ExpectData ExpectTable[8]; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 138 | |
| 139 | /* tables for mapping inbound unitdata (like paging) */ |
| 140 | var ImsiMapping ImsiTable[16]; |
| 141 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 142 | /* procedure based port to register for incoming connections */ |
| 143 | port BSSMAPEM_PROC_PT PROC; |
| 144 | |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 145 | var charstring g_bssmap_id; |
Harald Welte | 66fecd4 | 2017-11-24 23:53:23 +0100 | [diff] [blame] | 146 | var integer g_next_e1_ts := 1; |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 147 | var BssmapOps g_bssmap_ops; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 150 | private function f_conn_id_known(integer sccp_conn_id) |
| 151 | runs on BSSMAP_Emulation_CT return boolean { |
| 152 | var integer i; |
| 153 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 154 | if (ConnectionTable[i].sccp_conn_id == sccp_conn_id){ |
| 155 | return true; |
| 156 | } |
| 157 | } |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | private function f_comp_known(BSSAP_ConnHdlr client) |
| 162 | runs on BSSMAP_Emulation_CT return boolean { |
| 163 | var integer i; |
| 164 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 165 | if (ConnectionTable[i].comp_ref == client) { |
| 166 | return true; |
| 167 | } |
| 168 | } |
| 169 | return false; |
| 170 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 171 | |
Harald Welte | e98bb2e | 2017-11-29 12:09:48 +0100 | [diff] [blame] | 172 | private function f_cic_known(integer cic) |
| 173 | runs on BSSMAP_Emulation_CT return boolean { |
| 174 | var integer i; |
| 175 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 176 | if (ConnectionTable[i].cic == cic) { |
| 177 | return true; |
| 178 | } |
| 179 | } |
| 180 | return false; |
| 181 | } |
| 182 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 183 | /* resolve component reference by connection ID */ |
| 184 | private function f_comp_by_conn_id(integer sccp_conn_id) |
| 185 | runs on BSSMAP_Emulation_CT return BSSAP_ConnHdlr { |
| 186 | var integer i; |
| 187 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 188 | if (ConnectionTable[i].sccp_conn_id == sccp_conn_id) { |
| 189 | return ConnectionTable[i].comp_ref; |
| 190 | } |
| 191 | } |
| 192 | log("BSSMAP Connection table not found by SCCP Connection ID ", sccp_conn_id); |
Harald Welte | 9ca9eb1 | 2017-11-25 00:50:43 +0100 | [diff] [blame] | 193 | setverdict(fail); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 194 | self.stop; |
| 195 | } |
| 196 | |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 197 | /* resolve component reference by CIC */ |
| 198 | private function f_comp_by_mgcp_tid(MgcpTransId tid) |
| 199 | runs on BSSMAP_Emulation_CT return BSSAP_ConnHdlr { |
| 200 | var integer i; |
| 201 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 202 | if (ConnectionTable[i].mgcp_trans_id == tid) { |
| 203 | return ConnectionTable[i].comp_ref; |
| 204 | } |
| 205 | } |
| 206 | log("BSSMAP Connection table not found by MGCP Transaction ID ", tid); |
Harald Welte | 9ca9eb1 | 2017-11-25 00:50:43 +0100 | [diff] [blame] | 207 | setverdict(fail); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 208 | self.stop; |
| 209 | } |
| 210 | |
| 211 | private function f_comp_store_mgcp_tid(BSSAP_ConnHdlr client, MgcpTransId tid) |
| 212 | runs on BSSMAP_Emulation_CT { |
| 213 | var integer i; |
| 214 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 215 | if (ConnectionTable[i].comp_ref == client) { |
| 216 | ConnectionTable[i].mgcp_trans_id := tid; |
| 217 | return; |
| 218 | } |
| 219 | } |
| 220 | log("BSSMAP Connection table not found by component ", client); |
Harald Welte | 9ca9eb1 | 2017-11-25 00:50:43 +0100 | [diff] [blame] | 221 | setverdict(fail); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 222 | self.stop; |
| 223 | } |
| 224 | |
| 225 | private function f_comp_by_cic(integer cic) |
| 226 | runs on BSSMAP_Emulation_CT return BSSAP_ConnHdlr { |
| 227 | var integer i; |
| 228 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 229 | if (ConnectionTable[i].cic == cic) { |
| 230 | return ConnectionTable[i].comp_ref; |
| 231 | } |
| 232 | } |
| 233 | log("BSSMAP Connection table not found by CIC ", cic); |
Harald Welte | 9ca9eb1 | 2017-11-25 00:50:43 +0100 | [diff] [blame] | 234 | setverdict(fail); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 235 | self.stop; |
| 236 | } |
| 237 | |
| 238 | private function f_comp_store_cic(BSSAP_ConnHdlr client, integer cic) |
| 239 | runs on BSSMAP_Emulation_CT { |
| 240 | var integer i; |
| 241 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 242 | if (ConnectionTable[i].comp_ref == client) { |
| 243 | ConnectionTable[i].cic := cic; |
| 244 | return; |
| 245 | } |
| 246 | } |
| 247 | log("BSSMAP Connection table not found by component ", client); |
Harald Welte | 9ca9eb1 | 2017-11-25 00:50:43 +0100 | [diff] [blame] | 248 | setverdict(fail); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 249 | } |
| 250 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 251 | /* resolve connection ID by component reference */ |
| 252 | private function f_conn_id_by_comp(BSSAP_ConnHdlr client) |
| 253 | runs on BSSMAP_Emulation_CT return integer { |
| 254 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 255 | if (ConnectionTable[i].comp_ref == client) { |
| 256 | return ConnectionTable[i].sccp_conn_id; |
| 257 | } |
| 258 | } |
| 259 | log("BSSMAP Connection table not found by component ", client); |
Harald Welte | 9ca9eb1 | 2017-11-25 00:50:43 +0100 | [diff] [blame] | 260 | setverdict(fail); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 261 | self.stop; |
| 262 | } |
| 263 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 264 | private function f_gen_conn_id() |
| 265 | runs on BSSMAP_Emulation_CT return integer { |
| 266 | var integer conn_id; |
| 267 | |
| 268 | do { |
| 269 | conn_id := float2int(rnd()*SCCP_Emulation.tsp_max_ConnectionId); |
| 270 | } while (f_conn_id_known(conn_id) == true); |
| 271 | |
| 272 | return conn_id; |
| 273 | } |
| 274 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 275 | private function f_conn_table_init() |
| 276 | runs on BSSMAP_Emulation_CT { |
| 277 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 278 | ConnectionTable[i].comp_ref := null; |
| 279 | ConnectionTable[i].sccp_conn_id := -1; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 280 | ConnectionTable[i].mgcp_trans_id := omit; |
| 281 | ConnectionTable[i].cic := omit; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 282 | } |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 283 | for (var integer i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 284 | ImsiTable[i].comp_ref := null; |
| 285 | ImsiTable[i].imsi := omit; |
| 286 | ImsiTable[i].tmsi := 'FFFFFFFF'O; |
| 287 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | private function f_conn_table_add(BSSAP_ConnHdlr comp_ref, integer sccp_conn_id) |
| 291 | runs on BSSMAP_Emulation_CT { |
| 292 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 293 | if (ConnectionTable[i].sccp_conn_id == -1) { |
| 294 | ConnectionTable[i].comp_ref := comp_ref; |
| 295 | ConnectionTable[i].sccp_conn_id := sccp_conn_id; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 296 | log("Added conn table entry ", i, comp_ref, sccp_conn_id); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 297 | return; |
| 298 | } |
| 299 | } |
| 300 | log("BSSMAP Connection table full!"); |
Harald Welte | 9ca9eb1 | 2017-11-25 00:50:43 +0100 | [diff] [blame] | 301 | setverdict(fail); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 302 | self.stop; |
| 303 | } |
| 304 | |
| 305 | private function f_conn_table_del(integer sccp_conn_id) |
| 306 | runs on BSSMAP_Emulation_CT { |
| 307 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 308 | if (ConnectionTable[i].sccp_conn_id == sccp_conn_id) { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 309 | log("Deleted conn table entry ", i, |
| 310 | ConnectionTable[i].comp_ref, sccp_conn_id); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 311 | ConnectionTable[i].sccp_conn_id := -1; |
| 312 | ConnectionTable[i].comp_ref := null; |
Harald Welte | 0a4317a | 2017-11-25 00:32:46 +0100 | [diff] [blame] | 313 | return |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | log("BSSMAP Connection table attempt to delete non-existant ", sccp_conn_id); |
Harald Welte | 9ca9eb1 | 2017-11-25 00:50:43 +0100 | [diff] [blame] | 317 | setverdict(fail); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 318 | self.stop; |
| 319 | } |
| 320 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 321 | private function f_imsi_table_find(hexstring imsi, template OCT4 tmsi) |
| 322 | runs on BSSMAP_Emulation_CT return BSSAP_ConnHdlr { |
| 323 | for (var integer i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 324 | if (ImsiTable[i].imsi == imsi or |
| 325 | isvalue(tmsi) and match(ImsiTable[i].tmsi, tmsi)) { |
| 326 | return ImsiTable[i].comp_ref; |
| 327 | } |
| 328 | } |
| 329 | return null; |
| 330 | } |
| 331 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 332 | /* handle (optional) userData portion of various primitives and dispatch it to the client */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 333 | private function f_handle_userData(BSSAP_ConnHdlr client, PDU_BSSAP bssap) |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 334 | runs on BSSMAP_Emulation_CT { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 335 | /* decode + send decoded BSSAP to client */ |
Harald Welte | 1b2748e | 2017-11-24 23:40:16 +0100 | [diff] [blame] | 336 | |
| 337 | /* BSC Side: If this is an assignment command, store CIC */ |
| 338 | if (ischosen(bssap.pdu.bssmap.assignmentRequest) and |
| 339 | ispresent(bssap.pdu.bssmap.assignmentRequest.circuitIdentityCode)) { |
| 340 | var BSSMAP_IE_CircuitIdentityCode cic_ie := |
| 341 | bssap.pdu.bssmap.assignmentRequest.circuitIdentityCode; |
| 342 | var integer cic := (oct2int(cic_ie.cicHigh) * 256) + oct2int(cic_ie.cicLow); |
| 343 | f_comp_store_cic(client, cic); |
| 344 | } |
| 345 | |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 346 | if (ischosen(bssap.pdu.dtap) and g_bssmap_ops.decode_dtap) { |
| 347 | if (g_bssmap_ops.role_ms) { |
| 348 | /* we are the MS, so any message to us must be MT */ |
| 349 | var PDU_DTAP_MT mt := { |
| 350 | dlci := bssap.dlci, |
| 351 | dtap := dec_PDU_ML3_NW_MS(bssap.pdu.dtap) |
| 352 | }; |
| 353 | CLIENT.send(mt) to client; |
| 354 | } else { |
| 355 | /* we are the Network, so any message to us must be MO */ |
| 356 | var PDU_DTAP_MO mo := { |
| 357 | dlci := bssap.dlci, |
| 358 | dtap := dec_PDU_ML3_MS_NW(bssap.pdu.dtap) |
| 359 | }; |
| 360 | CLIENT.send(mo) to client; |
| 361 | } |
| 362 | } else { |
| 363 | CLIENT.send(bssap) to client; |
| 364 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | /* call-back type, to be provided by specific implementation; called when new SCCP connection |
| 368 | * arrives */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 369 | type function BssmapCreateCallback(BSSAP_N_CONNECT_ind conn_ind, charstring id) |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 370 | runs on BSSMAP_Emulation_CT return BSSAP_ConnHdlr; |
| 371 | |
| 372 | type function BssmapUnitdataCallback(PDU_BSSAP bssap) |
| 373 | runs on BSSMAP_Emulation_CT return template PDU_BSSAP; |
| 374 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 375 | /* handle common Unitdata such as Paging */ |
| 376 | private function CommonBssmapUnitdataCallback(PDU_BSSAP bssap) |
| 377 | runs on BSSMAP_Emulation_CT return template PDU_BSSAP { |
| 378 | if (match(bssap, tr_BSSMAP_Paging)) { |
| 379 | var BSSAP_ConnHdlr client := null; |
| 380 | client := f_imsi_table_find(bssap.pdu.bssmap.paging.iMSI.digits, |
| 381 | bssap.pdu.bssmap.paging.tMSI.tmsiOctets); |
| 382 | if (isvalue(client)) { |
| 383 | log("CommonBssmapUnitdataCallback: IMSI/TMSI found in table, dispatching to ", |
| 384 | client); |
| 385 | CLIENT.send(bssap) to client; |
| 386 | return omit; |
| 387 | } |
| 388 | log("CommonBssmapUnitdataCallback: IMSI/TMSI not found in table"); |
| 389 | } else { |
| 390 | log("CommonBssmapUnitdataCallback: Not a paging message"); |
| 391 | } |
| 392 | /* ELSE: handle in user callback */ |
| 393 | return g_bssmap_ops.unitdata_cb.apply(bssap); |
| 394 | } |
| 395 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 396 | type record BssmapOps { |
| 397 | BssmapCreateCallback create_cb, |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 398 | BssmapUnitdataCallback unitdata_cb, |
| 399 | boolean decode_dtap, |
| 400 | boolean role_ms |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 401 | } |
| 402 | |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 403 | function main(BssmapOps ops, charstring id) runs on BSSMAP_Emulation_CT { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 404 | |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 405 | g_bssmap_id := id; |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 406 | g_bssmap_ops := ops; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 407 | f_conn_table_init(); |
Daniel Willmann | d47106b | 2018-01-17 12:20:56 +0100 | [diff] [blame] | 408 | f_expect_table_init(); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 409 | |
| 410 | while (true) { |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 411 | var BSSAP_N_UNITDATA_ind ud_ind; |
| 412 | var BSSAP_N_CONNECT_ind conn_ind; |
| 413 | var BSSAP_N_CONNECT_cfm conn_cfm; |
| 414 | var BSSAP_N_DATA_ind data_ind; |
| 415 | var BSSAP_N_DISCONNECT_ind disc_ind; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 416 | var BSSAP_Conn_Req creq; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 417 | var BSSAP_ConnHdlr vc_conn; |
| 418 | var PDU_BSSAP bssap; |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 419 | var PDU_DTAP_MO dtap_mo; |
| 420 | var PDU_DTAP_MT dtap_mt; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 421 | var MgcpCommand mgcp_req; |
| 422 | var MgcpResponse mgcp_resp; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 423 | var BSSAP_ConnHdlr vc_hdlr; |
| 424 | var octetstring l3_info; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 425 | var hexstring imsi; |
| 426 | var OCT4 tmsi; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 427 | |
| 428 | alt { |
| 429 | /* SCCP -> Client: UNIT-DATA (connectionless SCCP) from a BSC */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 430 | [] BSSAP.receive(BSSAP_N_UNITDATA_ind:?) -> value ud_ind { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 431 | /* Connectionless Procedures like RESET */ |
| 432 | var template PDU_BSSAP resp; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 433 | resp := CommonBssmapUnitdataCallback(ud_ind.userData); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 434 | if (isvalue(resp)) { |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 435 | BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, |
| 436 | ud_ind.calledAddress, resp)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 437 | } |
| 438 | } |
| 439 | |
| 440 | /* SCCP -> Client: new connection from BSC */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 441 | [] BSSAP.receive(BSSAP_N_CONNECT_ind:?) -> value conn_ind { |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 442 | vc_conn := ops.create_cb.apply(conn_ind, id); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 443 | /* store mapping between client components and SCCP connectionId */ |
| 444 | f_conn_table_add(vc_conn, conn_ind.connectionId); |
| 445 | /* handle user payload */ |
| 446 | f_handle_userData(vc_conn, conn_ind.userData); |
| 447 | /* confirm connection establishment */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 448 | BSSAP.send(ts_BSSAP_CONNECT_res(conn_ind.connectionId, omit)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | /* SCCP -> Client: connection-oriented data in existing connection */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 452 | [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value data_ind { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 453 | vc_conn := f_comp_by_conn_id(data_ind.connectionId); |
Harald Welte | 5cc4aa2 | 2017-11-23 18:51:28 +0100 | [diff] [blame] | 454 | if (ispresent(data_ind.userData)) { |
| 455 | f_handle_userData(vc_conn, data_ind.userData); |
| 456 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | /* SCCP -> Client: disconnect of an existing connection */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 460 | [] BSSAP.receive(BSSAP_N_DISCONNECT_ind:?) -> value disc_ind { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 461 | vc_conn := f_comp_by_conn_id(disc_ind.connectionId); |
Harald Welte | 5cc4aa2 | 2017-11-23 18:51:28 +0100 | [diff] [blame] | 462 | if (ispresent(disc_ind.userData)) { |
| 463 | f_handle_userData(vc_conn, disc_ind.userData); |
| 464 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 465 | /* notify client about termination */ |
| 466 | var BSSAP_Conn_Prim prim := MSC_CONN_PRIM_DISC_IND; |
| 467 | CLIENT.send(prim) to vc_conn; |
| 468 | f_conn_table_del(disc_ind.connectionId); |
| 469 | /* TOOD: return confirm to other side? */ |
| 470 | } |
| 471 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 472 | /* SCCP -> Client: connection confirm for outbound connection */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 473 | [] BSSAP.receive(BSSAP_N_CONNECT_cfm:?) -> value conn_cfm { |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 474 | vc_conn := f_comp_by_conn_id(conn_cfm.connectionId); |
| 475 | var BSSAP_Conn_Prim prim := MSC_CONN_PRIM_CONF_IND; |
| 476 | CLIENT.send(prim) to vc_conn; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 477 | /* handle user payload */ |
Harald Welte | 5cc4aa2 | 2017-11-23 18:51:28 +0100 | [diff] [blame] | 478 | if (ispresent(conn_cfm.userData)) { |
| 479 | f_handle_userData(vc_conn, conn_cfm.userData); |
| 480 | } |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 481 | } |
| 482 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 483 | /* Disconnect request client -> SCCP */ |
| 484 | [] CLIENT.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_REQ) -> sender vc_conn { |
| 485 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 486 | BSSAP.send(ts_BSSAP_DISC_req(conn_id, 0)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 487 | f_conn_table_del(conn_id); |
| 488 | } |
| 489 | |
| 490 | /* BSSAP from client -> SCCP */ |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 491 | [] CLIENT.receive(BSSAP_Conn_Req:?) -> value creq sender vc_conn { |
| 492 | var integer conn_id; |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 493 | /* send to dispatcher */ |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 494 | |
| 495 | if (f_comp_known(vc_conn) == false) { |
| 496 | /* unknown client, create new connection */ |
| 497 | conn_id := f_gen_conn_id(); |
| 498 | |
| 499 | /* store mapping between client components and SCCP connectionId */ |
| 500 | f_conn_table_add(vc_conn, conn_id); |
| 501 | |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 502 | BSSAP.send(ts_BSSAP_CONNECT_req(creq.addr_peer, creq.addr_own, conn_id, |
| 503 | creq.bssap)); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 504 | } else { |
| 505 | /* known client, send via existing connection */ |
| 506 | conn_id := f_conn_id_by_comp(vc_conn); |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 507 | BSSAP.send(ts_BSSAP_DATA_req(conn_id, creq.bssap)); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | } |
| 511 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 512 | [] CLIENT.receive(PDU_BSSAP:?) -> value bssap sender vc_conn { |
| 513 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 514 | /* send it to dispatcher */ |
| 515 | BSSAP.send(ts_BSSAP_DATA_req(conn_id, bssap)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 516 | } |
| 517 | |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 518 | [g_bssmap_ops.role_ms] CLIENT.receive(PDU_DTAP_MO:?) -> value dtap_mo sender vc_conn { |
| 519 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
| 520 | /* convert from decoded DTAP to encoded DTAP */ |
| 521 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(dtap_mo.dtap); |
| 522 | bssap := valueof(ts_BSSAP_DTAP(l3_enc, dtap_mo.dlci)); |
| 523 | BSSAP.send(ts_BSSAP_DATA_req(conn_id, bssap)); |
| 524 | } |
| 525 | |
| 526 | [not g_bssmap_ops.role_ms] CLIENT.receive(PDU_DTAP_MT:?) -> value dtap_mt sender vc_conn { |
| 527 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
| 528 | /* convert from decoded DTAP to encoded DTAP */ |
| 529 | var octetstring l3_enc := enc_PDU_ML3_NW_MS(dtap_mt.dtap); |
| 530 | bssap := valueof(ts_BSSAP_DTAP(l3_enc, dtap_mo.dlci)); |
| 531 | BSSAP.send(ts_BSSAP_DATA_req(conn_id, bssap)); |
| 532 | } |
| 533 | |
| 534 | |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 535 | /* Handling of MGCP in IPA SCCPLite case. This predates 3GPP AoIP |
| 536 | * and uses a MGCP session in parallel to BSSAP. BSSAP uses CIC |
| 537 | * as usual, and MGCP uses "CIC@mgw" endpoint naming, where CIC |
| 538 | * is printed as hex string, e.g. a@mgw for CIC 10 */ |
| 539 | |
| 540 | /* CLIENT -> MGCP */ |
| 541 | [] CLIENT.receive(MgcpCommand:?) -> value mgcp_req sender vc_conn { |
| 542 | /* MGCP request from Handler (we're MSC) */ |
| 543 | /* store the transaction ID we've seen */ |
| 544 | f_comp_store_mgcp_tid(vc_conn, mgcp_req.line.trans_id); |
| 545 | /* simply forward any MGCP from the client to the port */ |
| 546 | MGCP.send(mgcp_req); |
| 547 | } |
| 548 | [] CLIENT.receive(MgcpResponse:?) -> value mgcp_resp sender vc_conn { |
| 549 | /* MGCP response from Handler (we're BSC/MGW) */ |
| 550 | /* simply forward any MGCP from the client to the port */ |
| 551 | MGCP.send(mgcp_resp); |
| 552 | } |
| 553 | |
| 554 | /* MGCP -> CLIENT */ |
| 555 | [] MGCP.receive(MgcpCommand:?) -> value mgcp_req { |
| 556 | /* MGCP request from network side (we're BSC/MGW) */ |
| 557 | /* Extract CIC from local part of endpoint name */ |
| 558 | var integer cic := f_mgcp_ep_extract_cic(mgcp_req.line.ep); |
Harald Welte | e98bb2e | 2017-11-29 12:09:48 +0100 | [diff] [blame] | 559 | if (match(mgcp_req, tr_RSIP) and f_cic_known(cic) == false) { |
| 560 | /* ignore RSIP for unknown CIC */ |
| 561 | } else { |
| 562 | /* Resolve the vc_conn by the CIC */ |
| 563 | vc_conn := f_comp_by_cic(cic); |
| 564 | CLIENT.send(mgcp_req) to vc_conn; |
| 565 | } |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 566 | } |
| 567 | [] MGCP.receive(MgcpResponse:?) -> value mgcp_resp { |
| 568 | /* MGCP response from network side (we're MSC) */ |
| 569 | /* Resolve the vc_conn by the transaction ID */ |
| 570 | vc_conn := f_comp_by_mgcp_tid(mgcp_resp.line.trans_id); |
| 571 | CLIENT.send(mgcp_resp) to vc_conn; |
| 572 | } |
| 573 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 574 | |
| 575 | [] PROC.getcall(BSSMAPEM_register:{?,?}) -> param(l3_info, vc_hdlr) { |
| 576 | f_create_expect(l3_info, vc_hdlr); |
| 577 | PROC.reply(BSSMAPEM_register:{l3_info, vc_hdlr}); |
| 578 | } |
| 579 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 580 | [] PROC.getcall(BSSMAPEM_register_imsi:{?,?,?}) -> param(imsi, tmsi, vc_hdlr) { |
| 581 | f_create_imsi(imsi, tmsi, vc_hdlr); |
| 582 | PROC.reply(BSSMAPEM_register_imsi:{imsi, tmsi, vc_hdlr}); |
| 583 | } |
| 584 | |
| 585 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | } |
| 589 | |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 590 | private function f_mgcp_ep_extract_cic(charstring inp) return integer { |
Harald Welte | 525a9c1 | 2017-11-24 23:40:41 +0100 | [diff] [blame] | 591 | var charstring local_part := regexp(inp, "(*)@*", 0); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 592 | return hex2int(str2hex(local_part)); |
| 593 | |
| 594 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 595 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 596 | /*********************************************************************** |
| 597 | * "Expect" Handling (mapping for expected incoming SCCP connections) |
| 598 | ***********************************************************************/ |
| 599 | |
| 600 | /* data about an expected future incoming connection */ |
| 601 | type record ExpectData { |
| 602 | /* L3 payload based on which we can match it */ |
| 603 | octetstring l3_payload optional, |
| 604 | /* component reference for this connection */ |
| 605 | BSSAP_ConnHdlr vc_conn |
| 606 | } |
| 607 | |
| 608 | /* procedure based port to register for incoming connections */ |
| 609 | signature BSSMAPEM_register(in octetstring l3, in BSSAP_ConnHdlr hdlr); |
| 610 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 611 | /* procedure based port to register for incoming IMSI/TMSI */ |
| 612 | signature BSSMAPEM_register_imsi(in hexstring imsi, in OCT4 tmsi, in BSSAP_ConnHdlr hdlr); |
| 613 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 614 | type port BSSMAPEM_PROC_PT procedure { |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 615 | inout BSSMAPEM_register, BSSMAPEM_register_imsi; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 616 | } with { extension "internal" }; |
| 617 | |
| 618 | /* CreateCallback that can be used as create_cb and will use the expectation table */ |
| 619 | function ExpectedCreateCallback(BSSAP_N_CONNECT_ind conn_ind, charstring id) |
| 620 | runs on BSSMAP_Emulation_CT return BSSAP_ConnHdlr { |
| 621 | var BSSAP_ConnHdlr ret := null; |
| 622 | var octetstring l3_info; |
| 623 | var integer i; |
| 624 | |
| 625 | if (not ischosen(conn_ind.userData.pdu.bssmap.completeLayer3Information)) { |
| 626 | setverdict(fail, "N-CONNECT.ind with L3 != COMPLETE L3"); |
| 627 | return ret; |
| 628 | } |
| 629 | l3_info := conn_ind.userData.pdu.bssmap.completeLayer3Information.layer3Information.layer3info; |
| 630 | |
| 631 | for (i := 0; i < sizeof(ExpectTable); i:= i+1) { |
| 632 | if (not ispresent(ExpectTable[i].l3_payload)) { |
| 633 | continue; |
| 634 | } |
| 635 | if (l3_info == ExpectTable[i].l3_payload) { |
| 636 | ret := ExpectTable[i].vc_conn; |
| 637 | /* release this entry to be used again */ |
| 638 | ExpectTable[i].l3_payload := omit; |
| 639 | ExpectTable[i].vc_conn := null; |
| 640 | log("Found Expect[", i, "] for ", l3_info, " handled at ", ret); |
| 641 | /* return the component reference */ |
| 642 | return ret; |
| 643 | } |
| 644 | } |
| 645 | setverdict(fail, "Couldn't find Expect for incoming connection ", conn_ind); |
| 646 | return ret; |
| 647 | } |
| 648 | |
| 649 | private function f_create_expect(octetstring l3, BSSAP_ConnHdlr hdlr) |
| 650 | runs on BSSMAP_Emulation_CT { |
| 651 | var integer i; |
| 652 | for (i := 0; i < sizeof(ExpectTable); i := i+1) { |
| 653 | if (not ispresent(ExpectTable[i].l3_payload)) { |
| 654 | ExpectTable[i].l3_payload := l3; |
| 655 | ExpectTable[i].vc_conn := hdlr; |
| 656 | log("Created Expect[", i, "] for ", l3, " to be handled at ", hdlr); |
| 657 | return; |
| 658 | } |
| 659 | } |
| 660 | setverdict(fail, "No space left in ExpectTable"); |
| 661 | } |
| 662 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 663 | private function f_create_imsi(hexstring imsi, OCT4 tmsi, BSSAP_ConnHdlr hdlr) |
| 664 | runs on BSSMAP_Emulation_CT { |
| 665 | for (var integer i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 666 | if (not ispresent(ImsiTable[i].imsi)) { |
| 667 | ImsiTable[i].imsi := imsi; |
| 668 | ImsiTable[i].tmsi := tmsi; |
| 669 | ImsiTable[i].comp_ref := hdlr; |
| 670 | log("Created IMSI[", i, "] for ", imsi, tmsi, " to be handled at ", hdlr); |
| 671 | return; |
| 672 | } |
| 673 | } |
| 674 | setverdict(fail, "No space left in ImsiTable"); |
| 675 | self.stop; |
| 676 | } |
| 677 | |
| 678 | |
Daniel Willmann | d47106b | 2018-01-17 12:20:56 +0100 | [diff] [blame] | 679 | private function f_expect_table_init() |
| 680 | runs on BSSMAP_Emulation_CT { |
| 681 | for (var integer i := 0; i < sizeof(ExpectTable); i := i+1) { |
| 682 | ExpectTable[i].l3_payload := omit; |
| 683 | } |
| 684 | } |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 685 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 686 | /* helper function for clients to register their IMSI/TMSI */ |
| 687 | function f_bssmap_register_imsi(hexstring imsi, OCT4 tmsi) |
| 688 | runs on BSSAP_ConnHdlr { |
| 689 | BSSAP_PROC.call(BSSMAPEM_register_imsi:{imsi, tmsi, self}) { |
| 690 | [] BSSAP_PROC.getreply(BSSMAPEM_register_imsi:{?,?,?}) {}; |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 695 | } |