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 | |
Harald Welte | 473676b | 2018-01-27 20:38:01 +0100 | [diff] [blame] | 337 | if (ischosen(bssap.pdu.bssmap)) { |
| 338 | /* BSC Side: If this is an assignment command, store CIC */ |
| 339 | if (ischosen(bssap.pdu.bssmap.assignmentRequest) and |
| 340 | ispresent(bssap.pdu.bssmap.assignmentRequest.circuitIdentityCode)) { |
| 341 | var BSSMAP_IE_CircuitIdentityCode cic_ie := |
| 342 | bssap.pdu.bssmap.assignmentRequest.circuitIdentityCode; |
| 343 | var integer cic := (oct2int(cic_ie.cicHigh) * 256) + oct2int(cic_ie.cicLow); |
| 344 | f_comp_store_cic(client, cic); |
| 345 | } |
Harald Welte | 1b2748e | 2017-11-24 23:40:16 +0100 | [diff] [blame] | 346 | } |
| 347 | |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 348 | if (ischosen(bssap.pdu.dtap) and g_bssmap_ops.decode_dtap) { |
| 349 | if (g_bssmap_ops.role_ms) { |
| 350 | /* we are the MS, so any message to us must be MT */ |
| 351 | var PDU_DTAP_MT mt := { |
| 352 | dlci := bssap.dlci, |
| 353 | dtap := dec_PDU_ML3_NW_MS(bssap.pdu.dtap) |
| 354 | }; |
| 355 | CLIENT.send(mt) to client; |
| 356 | } else { |
| 357 | /* we are the Network, so any message to us must be MO */ |
| 358 | var PDU_DTAP_MO mo := { |
| 359 | dlci := bssap.dlci, |
| 360 | dtap := dec_PDU_ML3_MS_NW(bssap.pdu.dtap) |
| 361 | }; |
| 362 | CLIENT.send(mo) to client; |
| 363 | } |
| 364 | } else { |
| 365 | CLIENT.send(bssap) to client; |
| 366 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | /* call-back type, to be provided by specific implementation; called when new SCCP connection |
| 370 | * arrives */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 371 | type function BssmapCreateCallback(BSSAP_N_CONNECT_ind conn_ind, charstring id) |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 372 | runs on BSSMAP_Emulation_CT return BSSAP_ConnHdlr; |
| 373 | |
| 374 | type function BssmapUnitdataCallback(PDU_BSSAP bssap) |
| 375 | runs on BSSMAP_Emulation_CT return template PDU_BSSAP; |
| 376 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 377 | /* handle common Unitdata such as Paging */ |
| 378 | private function CommonBssmapUnitdataCallback(PDU_BSSAP bssap) |
| 379 | runs on BSSMAP_Emulation_CT return template PDU_BSSAP { |
| 380 | if (match(bssap, tr_BSSMAP_Paging)) { |
| 381 | var BSSAP_ConnHdlr client := null; |
| 382 | client := f_imsi_table_find(bssap.pdu.bssmap.paging.iMSI.digits, |
| 383 | bssap.pdu.bssmap.paging.tMSI.tmsiOctets); |
| 384 | if (isvalue(client)) { |
| 385 | log("CommonBssmapUnitdataCallback: IMSI/TMSI found in table, dispatching to ", |
| 386 | client); |
| 387 | CLIENT.send(bssap) to client; |
| 388 | return omit; |
| 389 | } |
| 390 | log("CommonBssmapUnitdataCallback: IMSI/TMSI not found in table"); |
| 391 | } else { |
| 392 | log("CommonBssmapUnitdataCallback: Not a paging message"); |
| 393 | } |
| 394 | /* ELSE: handle in user callback */ |
| 395 | return g_bssmap_ops.unitdata_cb.apply(bssap); |
| 396 | } |
| 397 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 398 | type record BssmapOps { |
| 399 | BssmapCreateCallback create_cb, |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 400 | BssmapUnitdataCallback unitdata_cb, |
| 401 | boolean decode_dtap, |
| 402 | boolean role_ms |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 403 | } |
| 404 | |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 405 | function main(BssmapOps ops, charstring id) runs on BSSMAP_Emulation_CT { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 406 | |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 407 | g_bssmap_id := id; |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 408 | g_bssmap_ops := ops; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 409 | f_conn_table_init(); |
Daniel Willmann | d47106b | 2018-01-17 12:20:56 +0100 | [diff] [blame] | 410 | f_expect_table_init(); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 411 | |
| 412 | while (true) { |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 413 | var BSSAP_N_UNITDATA_ind ud_ind; |
| 414 | var BSSAP_N_CONNECT_ind conn_ind; |
| 415 | var BSSAP_N_CONNECT_cfm conn_cfm; |
| 416 | var BSSAP_N_DATA_ind data_ind; |
| 417 | var BSSAP_N_DISCONNECT_ind disc_ind; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 418 | var BSSAP_Conn_Req creq; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 419 | var BSSAP_ConnHdlr vc_conn; |
| 420 | var PDU_BSSAP bssap; |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 421 | var PDU_DTAP_MO dtap_mo; |
| 422 | var PDU_DTAP_MT dtap_mt; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 423 | var MgcpCommand mgcp_req; |
| 424 | var MgcpResponse mgcp_resp; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 425 | var BSSAP_ConnHdlr vc_hdlr; |
| 426 | var octetstring l3_info; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 427 | var hexstring imsi; |
| 428 | var OCT4 tmsi; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 429 | |
| 430 | alt { |
| 431 | /* SCCP -> Client: UNIT-DATA (connectionless SCCP) from a BSC */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 432 | [] BSSAP.receive(BSSAP_N_UNITDATA_ind:?) -> value ud_ind { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 433 | /* Connectionless Procedures like RESET */ |
| 434 | var template PDU_BSSAP resp; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 435 | resp := CommonBssmapUnitdataCallback(ud_ind.userData); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 436 | if (isvalue(resp)) { |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 437 | BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, |
| 438 | ud_ind.calledAddress, resp)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | |
| 442 | /* SCCP -> Client: new connection from BSC */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 443 | [] BSSAP.receive(BSSAP_N_CONNECT_ind:?) -> value conn_ind { |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 444 | vc_conn := ops.create_cb.apply(conn_ind, id); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 445 | /* store mapping between client components and SCCP connectionId */ |
| 446 | f_conn_table_add(vc_conn, conn_ind.connectionId); |
| 447 | /* handle user payload */ |
| 448 | f_handle_userData(vc_conn, conn_ind.userData); |
| 449 | /* confirm connection establishment */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 450 | BSSAP.send(ts_BSSAP_CONNECT_res(conn_ind.connectionId, omit)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /* SCCP -> Client: connection-oriented data in existing connection */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 454 | [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value data_ind { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 455 | vc_conn := f_comp_by_conn_id(data_ind.connectionId); |
Harald Welte | 5cc4aa2 | 2017-11-23 18:51:28 +0100 | [diff] [blame] | 456 | if (ispresent(data_ind.userData)) { |
| 457 | f_handle_userData(vc_conn, data_ind.userData); |
| 458 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /* SCCP -> Client: disconnect of an existing connection */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 462 | [] BSSAP.receive(BSSAP_N_DISCONNECT_ind:?) -> value disc_ind { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 463 | vc_conn := f_comp_by_conn_id(disc_ind.connectionId); |
Harald Welte | 5cc4aa2 | 2017-11-23 18:51:28 +0100 | [diff] [blame] | 464 | if (ispresent(disc_ind.userData)) { |
| 465 | f_handle_userData(vc_conn, disc_ind.userData); |
| 466 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 467 | /* notify client about termination */ |
| 468 | var BSSAP_Conn_Prim prim := MSC_CONN_PRIM_DISC_IND; |
| 469 | CLIENT.send(prim) to vc_conn; |
| 470 | f_conn_table_del(disc_ind.connectionId); |
| 471 | /* TOOD: return confirm to other side? */ |
| 472 | } |
| 473 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 474 | /* SCCP -> Client: connection confirm for outbound connection */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 475 | [] BSSAP.receive(BSSAP_N_CONNECT_cfm:?) -> value conn_cfm { |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 476 | vc_conn := f_comp_by_conn_id(conn_cfm.connectionId); |
| 477 | var BSSAP_Conn_Prim prim := MSC_CONN_PRIM_CONF_IND; |
| 478 | CLIENT.send(prim) to vc_conn; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 479 | /* handle user payload */ |
Harald Welte | 5cc4aa2 | 2017-11-23 18:51:28 +0100 | [diff] [blame] | 480 | if (ispresent(conn_cfm.userData)) { |
| 481 | f_handle_userData(vc_conn, conn_cfm.userData); |
| 482 | } |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 483 | } |
| 484 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 485 | /* Disconnect request client -> SCCP */ |
| 486 | [] CLIENT.receive(BSSAP_Conn_Prim:MSC_CONN_PRIM_DISC_REQ) -> sender vc_conn { |
| 487 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 488 | BSSAP.send(ts_BSSAP_DISC_req(conn_id, 0)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 489 | f_conn_table_del(conn_id); |
| 490 | } |
| 491 | |
| 492 | /* BSSAP from client -> SCCP */ |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 493 | [] CLIENT.receive(BSSAP_Conn_Req:?) -> value creq sender vc_conn { |
| 494 | var integer conn_id; |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 495 | /* send to dispatcher */ |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 496 | |
| 497 | if (f_comp_known(vc_conn) == false) { |
| 498 | /* unknown client, create new connection */ |
| 499 | conn_id := f_gen_conn_id(); |
| 500 | |
| 501 | /* store mapping between client components and SCCP connectionId */ |
| 502 | f_conn_table_add(vc_conn, conn_id); |
| 503 | |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 504 | BSSAP.send(ts_BSSAP_CONNECT_req(creq.addr_peer, creq.addr_own, conn_id, |
| 505 | creq.bssap)); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 506 | } else { |
| 507 | /* known client, send via existing connection */ |
| 508 | conn_id := f_conn_id_by_comp(vc_conn); |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 509 | BSSAP.send(ts_BSSAP_DATA_req(conn_id, creq.bssap)); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | } |
| 513 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 514 | [] CLIENT.receive(PDU_BSSAP:?) -> value bssap sender vc_conn { |
| 515 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 516 | /* send it to dispatcher */ |
| 517 | BSSAP.send(ts_BSSAP_DATA_req(conn_id, bssap)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 518 | } |
| 519 | |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 520 | [g_bssmap_ops.role_ms] CLIENT.receive(PDU_DTAP_MO:?) -> value dtap_mo sender vc_conn { |
| 521 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
| 522 | /* convert from decoded DTAP to encoded DTAP */ |
| 523 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(dtap_mo.dtap); |
| 524 | bssap := valueof(ts_BSSAP_DTAP(l3_enc, dtap_mo.dlci)); |
| 525 | BSSAP.send(ts_BSSAP_DATA_req(conn_id, bssap)); |
| 526 | } |
| 527 | |
| 528 | [not g_bssmap_ops.role_ms] CLIENT.receive(PDU_DTAP_MT:?) -> value dtap_mt sender vc_conn { |
| 529 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
| 530 | /* convert from decoded DTAP to encoded DTAP */ |
| 531 | var octetstring l3_enc := enc_PDU_ML3_NW_MS(dtap_mt.dtap); |
| 532 | bssap := valueof(ts_BSSAP_DTAP(l3_enc, dtap_mo.dlci)); |
| 533 | BSSAP.send(ts_BSSAP_DATA_req(conn_id, bssap)); |
| 534 | } |
| 535 | |
| 536 | |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 537 | /* Handling of MGCP in IPA SCCPLite case. This predates 3GPP AoIP |
| 538 | * and uses a MGCP session in parallel to BSSAP. BSSAP uses CIC |
| 539 | * as usual, and MGCP uses "CIC@mgw" endpoint naming, where CIC |
| 540 | * is printed as hex string, e.g. a@mgw for CIC 10 */ |
| 541 | |
| 542 | /* CLIENT -> MGCP */ |
| 543 | [] CLIENT.receive(MgcpCommand:?) -> value mgcp_req sender vc_conn { |
| 544 | /* MGCP request from Handler (we're MSC) */ |
| 545 | /* store the transaction ID we've seen */ |
| 546 | f_comp_store_mgcp_tid(vc_conn, mgcp_req.line.trans_id); |
| 547 | /* simply forward any MGCP from the client to the port */ |
| 548 | MGCP.send(mgcp_req); |
| 549 | } |
| 550 | [] CLIENT.receive(MgcpResponse:?) -> value mgcp_resp sender vc_conn { |
| 551 | /* MGCP response from Handler (we're BSC/MGW) */ |
| 552 | /* simply forward any MGCP from the client to the port */ |
| 553 | MGCP.send(mgcp_resp); |
| 554 | } |
| 555 | |
| 556 | /* MGCP -> CLIENT */ |
| 557 | [] MGCP.receive(MgcpCommand:?) -> value mgcp_req { |
| 558 | /* MGCP request from network side (we're BSC/MGW) */ |
| 559 | /* Extract CIC from local part of endpoint name */ |
| 560 | var integer cic := f_mgcp_ep_extract_cic(mgcp_req.line.ep); |
Harald Welte | e98bb2e | 2017-11-29 12:09:48 +0100 | [diff] [blame] | 561 | if (match(mgcp_req, tr_RSIP) and f_cic_known(cic) == false) { |
| 562 | /* ignore RSIP for unknown CIC */ |
| 563 | } else { |
| 564 | /* Resolve the vc_conn by the CIC */ |
| 565 | vc_conn := f_comp_by_cic(cic); |
| 566 | CLIENT.send(mgcp_req) to vc_conn; |
| 567 | } |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 568 | } |
| 569 | [] MGCP.receive(MgcpResponse:?) -> value mgcp_resp { |
| 570 | /* MGCP response from network side (we're MSC) */ |
| 571 | /* Resolve the vc_conn by the transaction ID */ |
| 572 | vc_conn := f_comp_by_mgcp_tid(mgcp_resp.line.trans_id); |
| 573 | CLIENT.send(mgcp_resp) to vc_conn; |
| 574 | } |
| 575 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 576 | |
| 577 | [] PROC.getcall(BSSMAPEM_register:{?,?}) -> param(l3_info, vc_hdlr) { |
| 578 | f_create_expect(l3_info, vc_hdlr); |
| 579 | PROC.reply(BSSMAPEM_register:{l3_info, vc_hdlr}); |
| 580 | } |
| 581 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 582 | [] PROC.getcall(BSSMAPEM_register_imsi:{?,?,?}) -> param(imsi, tmsi, vc_hdlr) { |
| 583 | f_create_imsi(imsi, tmsi, vc_hdlr); |
| 584 | PROC.reply(BSSMAPEM_register_imsi:{imsi, tmsi, vc_hdlr}); |
| 585 | } |
| 586 | |
| 587 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | } |
| 591 | |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 592 | private function f_mgcp_ep_extract_cic(charstring inp) return integer { |
Harald Welte | 525a9c1 | 2017-11-24 23:40:41 +0100 | [diff] [blame] | 593 | var charstring local_part := regexp(inp, "(*)@*", 0); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 594 | return hex2int(str2hex(local_part)); |
| 595 | |
| 596 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 597 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 598 | /*********************************************************************** |
| 599 | * "Expect" Handling (mapping for expected incoming SCCP connections) |
| 600 | ***********************************************************************/ |
| 601 | |
| 602 | /* data about an expected future incoming connection */ |
| 603 | type record ExpectData { |
| 604 | /* L3 payload based on which we can match it */ |
| 605 | octetstring l3_payload optional, |
| 606 | /* component reference for this connection */ |
| 607 | BSSAP_ConnHdlr vc_conn |
| 608 | } |
| 609 | |
| 610 | /* procedure based port to register for incoming connections */ |
| 611 | signature BSSMAPEM_register(in octetstring l3, in BSSAP_ConnHdlr hdlr); |
| 612 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 613 | /* procedure based port to register for incoming IMSI/TMSI */ |
| 614 | signature BSSMAPEM_register_imsi(in hexstring imsi, in OCT4 tmsi, in BSSAP_ConnHdlr hdlr); |
| 615 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 616 | type port BSSMAPEM_PROC_PT procedure { |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 617 | inout BSSMAPEM_register, BSSMAPEM_register_imsi; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 618 | } with { extension "internal" }; |
| 619 | |
| 620 | /* CreateCallback that can be used as create_cb and will use the expectation table */ |
| 621 | function ExpectedCreateCallback(BSSAP_N_CONNECT_ind conn_ind, charstring id) |
| 622 | runs on BSSMAP_Emulation_CT return BSSAP_ConnHdlr { |
| 623 | var BSSAP_ConnHdlr ret := null; |
| 624 | var octetstring l3_info; |
| 625 | var integer i; |
| 626 | |
| 627 | if (not ischosen(conn_ind.userData.pdu.bssmap.completeLayer3Information)) { |
| 628 | setverdict(fail, "N-CONNECT.ind with L3 != COMPLETE L3"); |
| 629 | return ret; |
| 630 | } |
| 631 | l3_info := conn_ind.userData.pdu.bssmap.completeLayer3Information.layer3Information.layer3info; |
| 632 | |
| 633 | for (i := 0; i < sizeof(ExpectTable); i:= i+1) { |
| 634 | if (not ispresent(ExpectTable[i].l3_payload)) { |
| 635 | continue; |
| 636 | } |
| 637 | if (l3_info == ExpectTable[i].l3_payload) { |
| 638 | ret := ExpectTable[i].vc_conn; |
| 639 | /* release this entry to be used again */ |
| 640 | ExpectTable[i].l3_payload := omit; |
| 641 | ExpectTable[i].vc_conn := null; |
| 642 | log("Found Expect[", i, "] for ", l3_info, " handled at ", ret); |
| 643 | /* return the component reference */ |
| 644 | return ret; |
| 645 | } |
| 646 | } |
| 647 | setverdict(fail, "Couldn't find Expect for incoming connection ", conn_ind); |
| 648 | return ret; |
| 649 | } |
| 650 | |
| 651 | private function f_create_expect(octetstring l3, BSSAP_ConnHdlr hdlr) |
| 652 | runs on BSSMAP_Emulation_CT { |
| 653 | var integer i; |
| 654 | for (i := 0; i < sizeof(ExpectTable); i := i+1) { |
| 655 | if (not ispresent(ExpectTable[i].l3_payload)) { |
| 656 | ExpectTable[i].l3_payload := l3; |
| 657 | ExpectTable[i].vc_conn := hdlr; |
| 658 | log("Created Expect[", i, "] for ", l3, " to be handled at ", hdlr); |
| 659 | return; |
| 660 | } |
| 661 | } |
| 662 | setverdict(fail, "No space left in ExpectTable"); |
| 663 | } |
| 664 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 665 | private function f_create_imsi(hexstring imsi, OCT4 tmsi, BSSAP_ConnHdlr hdlr) |
| 666 | runs on BSSMAP_Emulation_CT { |
| 667 | for (var integer i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 668 | if (not ispresent(ImsiTable[i].imsi)) { |
| 669 | ImsiTable[i].imsi := imsi; |
| 670 | ImsiTable[i].tmsi := tmsi; |
| 671 | ImsiTable[i].comp_ref := hdlr; |
| 672 | log("Created IMSI[", i, "] for ", imsi, tmsi, " to be handled at ", hdlr); |
| 673 | return; |
| 674 | } |
| 675 | } |
| 676 | setverdict(fail, "No space left in ImsiTable"); |
| 677 | self.stop; |
| 678 | } |
| 679 | |
| 680 | |
Daniel Willmann | d47106b | 2018-01-17 12:20:56 +0100 | [diff] [blame] | 681 | private function f_expect_table_init() |
| 682 | runs on BSSMAP_Emulation_CT { |
| 683 | for (var integer i := 0; i < sizeof(ExpectTable); i := i+1) { |
| 684 | ExpectTable[i].l3_payload := omit; |
| 685 | } |
| 686 | } |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 687 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 688 | /* helper function for clients to register their IMSI/TMSI */ |
| 689 | function f_bssmap_register_imsi(hexstring imsi, OCT4 tmsi) |
| 690 | runs on BSSAP_ConnHdlr { |
| 691 | BSSAP_PROC.call(BSSMAPEM_register_imsi:{imsi, tmsi, self}) { |
| 692 | [] BSSAP_PROC.getreply(BSSMAPEM_register_imsi:{?,?,?}) {}; |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 697 | } |