Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1 | module RAN_Emulation { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 2 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 3 | /* RAN Emulation, runs on top of BSSAP_CodecPort. It multiplexes/demultiplexes |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 4 | * the individual connections, so there can be separate TTCN-3 components handling |
| 5 | * each of the connections. |
| 6 | * |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 7 | * The RAN_Emulation.main() function processes SCCP primitives from the SCCP |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 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 |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 11 | * to the component running the RAN_Emulation.main() function. |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 12 | * |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 13 | * For each new inbound connections, the RanOps.create_cb() is called. It can create |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 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 | * |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 22 | * Inbound Unit Data messages (such as are dispatched to the RanOps.unitdata_cb() callback, |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 23 | * which is registered with an argument to the main() function below. |
| 24 | * |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 25 | * (C) 2017-2019 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 | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 34 | import from Osmocom_Types all; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 35 | import from SCCP_Emulation all; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 36 | import from SCCPasp_Types all; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 37 | import from IPA_Emulation all; |
| 38 | import from MobileL3_Types all; |
| 39 | |
| 40 | #ifdef RAN_EMULATION_BSSAP |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 41 | import from BSSAP_Types all; |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 42 | import from BSSAP_CodecPort all; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 43 | import from BSSMAP_Templates all; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 44 | #endif |
| 45 | |
| 46 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 47 | import from MGCP_Types all; |
| 48 | import from MGCP_Templates all; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 49 | #endif |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 50 | |
| 51 | /* General "base class" component definition, of which specific implementations |
| 52 | * derive themselves by means of the "extends" feature */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 53 | type component RAN_ConnHdlr { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 54 | /* port towards MSC Emulator core / SCCP connection dispatchar */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 55 | port RAN_Conn_PT BSSAP; |
Harald Welte | ca51998 | 2018-01-21 19:28:26 +0100 | [diff] [blame] | 56 | /* procedure based port to register for incoming connections */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 57 | port RAN_PROC_PT BSSAP_PROC; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /* Auxiliary primitive that can happen on the port between per-connection client and this dispatcher */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 61 | type enumerated RAN_Conn_Prim { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 62 | /* SCCP tell us that connection was released */ |
| 63 | MSC_CONN_PRIM_DISC_IND, |
| 64 | /* we tell SCCP to release connection */ |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 65 | MSC_CONN_PRIM_DISC_REQ, |
| 66 | /* Connection confirmed indication */ |
| 67 | MSC_CONN_PRIM_CONF_IND |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 70 | /* similar to PDU_BSSAP with DTAP, but DTAP is already decoded! */ |
| 71 | type record PDU_DTAP_MO { |
| 72 | OCT1 dlci optional, |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 73 | boolean skip_seq_patching optional, |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 74 | PDU_ML3_MS_NW dtap |
| 75 | } |
| 76 | |
| 77 | /* similar to PDU_BSSAP with DTAP, but DTAP is already decoded! */ |
| 78 | type record PDU_DTAP_MT { |
| 79 | OCT1 dlci optional, |
| 80 | PDU_ML3_NW_MS dtap |
| 81 | } |
| 82 | |
| 83 | template PDU_DTAP_MT ts_PDU_DTAP_MT(template PDU_ML3_NW_MS dtap, template OCT1 dlci := omit) := { |
| 84 | dlci := dlci, |
| 85 | dtap := dtap |
| 86 | } |
| 87 | |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 88 | template PDU_DTAP_MO ts_PDU_DTAP_MO(template PDU_ML3_MS_NW dtap, template OCT1 dlci := '00'O, boolean skip_seq_patching := false) := { |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 89 | dlci := dlci, |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 90 | skip_seq_patching := skip_seq_patching, |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 91 | dtap := dtap |
| 92 | } |
| 93 | |
| 94 | template PDU_DTAP_MT tr_PDU_DTAP_MT(template PDU_ML3_NW_MS dtap, template OCT1 dlci := *) := { |
| 95 | dlci := dlci, |
| 96 | dtap := dtap |
| 97 | } |
| 98 | |
| 99 | template PDU_DTAP_MO tr_PDU_DTAP_MO(template PDU_ML3_MS_NW dtap, template OCT1 dlci := *) := { |
| 100 | dlci := dlci, |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 101 | skip_seq_patching := ?, |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 102 | dtap := dtap |
| 103 | } |
| 104 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 105 | /* port between individual per-connection components and this dispatcher */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 106 | type port RAN_Conn_PT message { |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 107 | inout |
| 108 | #ifdef RAN_EMULATION_BSSAP |
| 109 | PDU_BSSAP, |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 110 | /* Client requests us to create SCCP Connection */ |
| 111 | BSSAP_Conn_Req, |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 112 | #endif |
| 113 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 114 | /* MGCP, only used for IPA SCCPlite (MGCP in IPA mux) */ |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 115 | MgcpCommand, MgcpResponse, |
| 116 | #endif |
| 117 | /* direct DTAP messages from/to clients */ |
| 118 | PDU_DTAP_MO, PDU_DTAP_MT, |
| 119 | /* misc indications / requests between SCCP and client */ |
| 120 | RAN_Conn_Prim; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 121 | } with { extension "internal" }; |
| 122 | |
| 123 | |
| 124 | /* represents a single BSSAP connection over SCCP */ |
| 125 | type record ConnectionData { |
| 126 | /* reference to the instance of the per-connection component */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 127 | RAN_ConnHdlr comp_ref, |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 128 | integer sccp_conn_id, |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 129 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 130 | /* most recent MGCP transaction ID (Used on MSC side) */ |
| 131 | MgcpTransId mgcp_trans_id optional, |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 132 | #endif |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 133 | /* CIC that has been used for voice of this channel (BSC side) */ |
Harald Welte | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 134 | integer cic optional, |
| 135 | /* array of N(SD) values for MO DTAP messages, indexed by discriminator */ |
| 136 | uint2_t n_sd[4] |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 139 | type record ImsiMapping { |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 140 | RAN_ConnHdlr comp_ref, |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 141 | hexstring imsi optional, |
| 142 | OCT4 tmsi |
| 143 | } |
| 144 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 145 | type component RAN_Emulation_CT { |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 146 | /* SCCP ports on the bottom side, using ASP primitives */ |
| 147 | #ifdef RAN_EMULATION_BSSAP |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 148 | port BSSAP_CODEC_PT BSSAP; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 149 | #endif |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 150 | /* BSSAP port to the per-connection clients */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 151 | port RAN_Conn_PT CLIENT; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 152 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 153 | /* MGCP port */ |
| 154 | port IPA_MGCP_PT MGCP; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 155 | #endif |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 156 | |
| 157 | /* use 16 as this is also the number of SCCP connections that SCCP_Emulation can handle */ |
| 158 | var ConnectionData ConnectionTable[16]; |
Harald Welte | 66fecd4 | 2017-11-24 23:53:23 +0100 | [diff] [blame] | 159 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 160 | /* pending expected incoming connections */ |
| 161 | var ExpectData ExpectTable[8]; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 162 | |
| 163 | /* tables for mapping inbound unitdata (like paging) */ |
| 164 | var ImsiMapping ImsiTable[16]; |
| 165 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 166 | /* procedure based port to register for incoming connections */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 167 | port RAN_PROC_PT PROC; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 168 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 169 | var charstring g_ran_id; |
Harald Welte | 66fecd4 | 2017-11-24 23:53:23 +0100 | [diff] [blame] | 170 | var integer g_next_e1_ts := 1; |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 171 | var RanOps g_ran_ops; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 172 | }; |
| 173 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 174 | private function f_conn_id_known(integer sccp_conn_id) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 175 | runs on RAN_Emulation_CT return boolean { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 176 | var integer i; |
| 177 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 178 | if (ConnectionTable[i].sccp_conn_id == sccp_conn_id){ |
| 179 | return true; |
| 180 | } |
| 181 | } |
| 182 | return false; |
| 183 | } |
| 184 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 185 | private function f_comp_known(RAN_ConnHdlr client) |
| 186 | runs on RAN_Emulation_CT return boolean { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 187 | var integer i; |
| 188 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 189 | if (ConnectionTable[i].comp_ref == client) { |
| 190 | return true; |
| 191 | } |
| 192 | } |
| 193 | return false; |
| 194 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 195 | |
Harald Welte | e98bb2e | 2017-11-29 12:09:48 +0100 | [diff] [blame] | 196 | private function f_cic_known(integer cic) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 197 | runs on RAN_Emulation_CT return boolean { |
Harald Welte | e98bb2e | 2017-11-29 12:09:48 +0100 | [diff] [blame] | 198 | var integer i; |
| 199 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 200 | if (ConnectionTable[i].cic == cic) { |
| 201 | return true; |
| 202 | } |
| 203 | } |
| 204 | return false; |
| 205 | } |
| 206 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 207 | /* resolve component reference by connection ID */ |
| 208 | private function f_comp_by_conn_id(integer sccp_conn_id) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 209 | runs on RAN_Emulation_CT return RAN_ConnHdlr { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 210 | var integer i; |
| 211 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 212 | if (ConnectionTable[i].sccp_conn_id == sccp_conn_id) { |
| 213 | return ConnectionTable[i].comp_ref; |
| 214 | } |
| 215 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 216 | setverdict(fail, "RAN Connection table not found by SCCP Connection ID ", sccp_conn_id); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 217 | mtc.stop; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 218 | } |
| 219 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 220 | |
| 221 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 222 | /* resolve component reference by CIC */ |
| 223 | private function f_comp_by_mgcp_tid(MgcpTransId tid) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 224 | runs on RAN_Emulation_CT return RAN_ConnHdlr { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 225 | var integer i; |
| 226 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 227 | if (ConnectionTable[i].mgcp_trans_id == tid) { |
| 228 | return ConnectionTable[i].comp_ref; |
| 229 | } |
| 230 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 231 | setverdict(fail, "RAN Connection table not found by MGCP Transaction ID ", tid); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 232 | mtc.stop; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 233 | } |
| 234 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 235 | private function f_comp_store_mgcp_tid(RAN_ConnHdlr client, MgcpTransId tid) |
| 236 | runs on RAN_Emulation_CT { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 237 | var integer i; |
| 238 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 239 | if (ConnectionTable[i].comp_ref == client) { |
| 240 | ConnectionTable[i].mgcp_trans_id := tid; |
| 241 | return; |
| 242 | } |
| 243 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 244 | setverdict(fail, "RAN Connection table not found by component ", client); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 245 | mtc.stop; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 246 | } |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 247 | #endif |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 248 | |
| 249 | private function f_comp_by_cic(integer cic) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 250 | runs on RAN_Emulation_CT return RAN_ConnHdlr { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 251 | var integer i; |
| 252 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 253 | if (ConnectionTable[i].cic == cic) { |
| 254 | return ConnectionTable[i].comp_ref; |
| 255 | } |
| 256 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 257 | setverdict(fail, "RAN Connection table not found by CIC ", cic); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 258 | mtc.stop; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 259 | } |
| 260 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 261 | private function f_comp_store_cic(RAN_ConnHdlr client, integer cic) |
| 262 | runs on RAN_Emulation_CT { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 263 | var integer i; |
| 264 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 265 | if (ConnectionTable[i].comp_ref == client) { |
| 266 | ConnectionTable[i].cic := cic; |
| 267 | return; |
| 268 | } |
| 269 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 270 | setverdict(fail, "RAN Connection table not found by component ", client); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 271 | mtc.stop; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 272 | } |
| 273 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 274 | /* resolve connection ID by component reference */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 275 | private function f_conn_id_by_comp(RAN_ConnHdlr client) |
| 276 | runs on RAN_Emulation_CT return integer { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 277 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 278 | if (ConnectionTable[i].comp_ref == client) { |
| 279 | return ConnectionTable[i].sccp_conn_id; |
| 280 | } |
| 281 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 282 | setverdict(fail, "RAN Connection table not found by component ", client); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 283 | mtc.stop; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 284 | } |
| 285 | |
Harald Welte | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 286 | /* resolve ConnectionTable index component reference */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 287 | private function f_idx_by_comp(RAN_ConnHdlr client) |
| 288 | runs on RAN_Emulation_CT return integer { |
Harald Welte | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 289 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 290 | if (ConnectionTable[i].comp_ref == client) { |
| 291 | return i; |
| 292 | } |
| 293 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 294 | setverdict(fail, "RAN Connection table not found by component ", client); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 295 | mtc.stop; |
Harald Welte | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 296 | } |
| 297 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 298 | private function f_gen_conn_id() |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 299 | runs on RAN_Emulation_CT return integer { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 300 | var integer conn_id; |
| 301 | |
| 302 | do { |
| 303 | conn_id := float2int(rnd()*SCCP_Emulation.tsp_max_ConnectionId); |
| 304 | } while (f_conn_id_known(conn_id) == true); |
| 305 | |
| 306 | return conn_id; |
| 307 | } |
| 308 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 309 | private function f_conn_table_init() |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 310 | runs on RAN_Emulation_CT { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 311 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 312 | ConnectionTable[i].comp_ref := null; |
| 313 | ConnectionTable[i].sccp_conn_id := -1; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 314 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 315 | ConnectionTable[i].mgcp_trans_id := omit; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 316 | #endif |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 317 | ConnectionTable[i].cic := omit; |
Harald Welte | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 318 | ConnectionTable[i].n_sd := { 0, 0, 0, 0 }; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 319 | } |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 320 | for (var integer i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 321 | ImsiTable[i].comp_ref := null; |
| 322 | ImsiTable[i].imsi := omit; |
| 323 | ImsiTable[i].tmsi := 'FFFFFFFF'O; |
| 324 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 325 | } |
| 326 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 327 | private function f_conn_table_add(RAN_ConnHdlr comp_ref, integer sccp_conn_id) |
| 328 | runs on RAN_Emulation_CT { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 329 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 330 | if (ConnectionTable[i].sccp_conn_id == -1) { |
| 331 | ConnectionTable[i].comp_ref := comp_ref; |
| 332 | ConnectionTable[i].sccp_conn_id := sccp_conn_id; |
Harald Welte | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 333 | ConnectionTable[i].n_sd := { 0, 0, 0, 0 }; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 334 | log("Added conn table entry ", i, comp_ref, sccp_conn_id); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 335 | return; |
| 336 | } |
| 337 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 338 | testcase.stop("RAN Connection table full!"); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | private function f_conn_table_del(integer sccp_conn_id) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 342 | runs on RAN_Emulation_CT { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 343 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 344 | if (ConnectionTable[i].sccp_conn_id == sccp_conn_id) { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 345 | log("Deleted conn table entry ", i, |
| 346 | ConnectionTable[i].comp_ref, sccp_conn_id); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 347 | ConnectionTable[i].sccp_conn_id := -1; |
| 348 | ConnectionTable[i].comp_ref := null; |
Harald Welte | 0a4317a | 2017-11-25 00:32:46 +0100 | [diff] [blame] | 349 | return |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 350 | } |
| 351 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 352 | setverdict(fail, "RAN Connection table attempt to delete non-existant ", sccp_conn_id); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 353 | mtc.stop; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 354 | } |
| 355 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 356 | private function f_imsi_table_find(hexstring imsi, template OCT4 tmsi) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 357 | runs on RAN_Emulation_CT return RAN_ConnHdlr { |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 358 | for (var integer i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 359 | if (ImsiTable[i].imsi == imsi or |
| 360 | isvalue(tmsi) and match(ImsiTable[i].tmsi, tmsi)) { |
| 361 | return ImsiTable[i].comp_ref; |
| 362 | } |
| 363 | } |
| 364 | return null; |
| 365 | } |
| 366 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 367 | #ifdef RAN_EMULATION_BSSAP |
| 368 | type record BSSAP_Conn_Req { |
| 369 | SCCP_PAR_Address addr_peer, |
| 370 | SCCP_PAR_Address addr_own, |
| 371 | PDU_BSSAP bssap |
| 372 | } |
| 373 | template BSSAP_Conn_Req ts_BSSAP_Conn_Req(SCCP_PAR_Address peer, SCCP_PAR_Address own, PDU_BSSAP bssap) := { |
| 374 | addr_peer := peer, |
| 375 | addr_own := own, |
| 376 | bssap := bssap |
| 377 | }; |
| 378 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 379 | /* handle (optional) userData portion of various primitives and dispatch it to the client */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 380 | private function f_handle_userData(RAN_ConnHdlr client, PDU_BSSAP bssap) |
| 381 | runs on RAN_Emulation_CT { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 382 | /* decode + send decoded BSSAP to client */ |
Harald Welte | 1b2748e | 2017-11-24 23:40:16 +0100 | [diff] [blame] | 383 | |
Harald Welte | 473676b | 2018-01-27 20:38:01 +0100 | [diff] [blame] | 384 | if (ischosen(bssap.pdu.bssmap)) { |
| 385 | /* BSC Side: If this is an assignment command, store CIC */ |
| 386 | if (ischosen(bssap.pdu.bssmap.assignmentRequest) and |
| 387 | ispresent(bssap.pdu.bssmap.assignmentRequest.circuitIdentityCode)) { |
| 388 | var BSSMAP_IE_CircuitIdentityCode cic_ie := |
| 389 | bssap.pdu.bssmap.assignmentRequest.circuitIdentityCode; |
| 390 | var integer cic := (oct2int(cic_ie.cicHigh) * 256) + oct2int(cic_ie.cicLow); |
| 391 | f_comp_store_cic(client, cic); |
| 392 | } |
Harald Welte | 1b2748e | 2017-11-24 23:40:16 +0100 | [diff] [blame] | 393 | } |
| 394 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 395 | if (ischosen(bssap.pdu.dtap) and g_ran_ops.decode_dtap) { |
| 396 | if (g_ran_ops.role_ms) { |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 397 | /* we are the MS, so any message to us must be MT */ |
| 398 | var PDU_DTAP_MT mt := { |
| 399 | dlci := bssap.dlci, |
| 400 | dtap := dec_PDU_ML3_NW_MS(bssap.pdu.dtap) |
| 401 | }; |
| 402 | CLIENT.send(mt) to client; |
| 403 | } else { |
| 404 | /* we are the Network, so any message to us must be MO */ |
| 405 | var PDU_DTAP_MO mo := { |
| 406 | dlci := bssap.dlci, |
| 407 | dtap := dec_PDU_ML3_MS_NW(bssap.pdu.dtap) |
| 408 | }; |
| 409 | CLIENT.send(mo) to client; |
| 410 | } |
| 411 | } else { |
| 412 | CLIENT.send(bssap) to client; |
| 413 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /* call-back type, to be provided by specific implementation; called when new SCCP connection |
| 417 | * arrives */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 418 | type function BssmapCreateCallback(BSSAP_N_CONNECT_ind conn_ind, charstring id) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 419 | runs on RAN_Emulation_CT return RAN_ConnHdlr; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 420 | |
| 421 | type function BssmapUnitdataCallback(PDU_BSSAP bssap) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 422 | runs on RAN_Emulation_CT return template PDU_BSSAP; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 423 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 424 | /* handle common Unitdata such as Paging */ |
| 425 | private function CommonBssmapUnitdataCallback(PDU_BSSAP bssap) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 426 | runs on RAN_Emulation_CT return template PDU_BSSAP { |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 427 | if (match(bssap, tr_BSSMAP_Paging)) { |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 428 | var RAN_ConnHdlr client := null; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 429 | client := f_imsi_table_find(bssap.pdu.bssmap.paging.iMSI.digits, |
| 430 | bssap.pdu.bssmap.paging.tMSI.tmsiOctets); |
Daniel Willmann | abc73e1 | 2019-04-15 17:25:56 +0200 | [diff] [blame] | 431 | if (client != null) { |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 432 | log("CommonBssmapUnitdataCallback: IMSI/TMSI found in table, dispatching to ", |
| 433 | client); |
| 434 | CLIENT.send(bssap) to client; |
| 435 | return omit; |
| 436 | } |
| 437 | log("CommonBssmapUnitdataCallback: IMSI/TMSI not found in table"); |
| 438 | } else { |
| 439 | log("CommonBssmapUnitdataCallback: Not a paging message"); |
| 440 | } |
| 441 | /* ELSE: handle in user callback */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 442 | return g_ran_ops.unitdata_cb.apply(bssap); |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 443 | } |
| 444 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 445 | private function f_bssap_wait_for_reset() runs on RAN_Emulation_CT { |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 446 | var BSSAP_N_UNITDATA_ind ud_ind; |
| 447 | timer T := 20.0; |
| 448 | |
| 449 | T.start; |
| 450 | alt { |
| 451 | [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind { |
| 452 | BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress, |
| 453 | ts_BSSMAP_ResetAck)); |
| 454 | } |
| 455 | [] as_reset_ack(); |
| 456 | [] BSSAP.receive { |
| 457 | repeat; |
| 458 | } |
| 459 | [] T.timeout { |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 460 | setverdict(fail, "Timeout waiting for BSSAP RESET"); |
| 461 | mtc.stop; |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | } |
| 465 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 466 | function f_bssap_reset(SCCP_PAR_Address peer, SCCP_PAR_Address own) runs on RAN_Emulation_CT { |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 467 | timer T := 5.0; |
| 468 | |
| 469 | BSSAP.send(ts_BSSAP_UNITDATA_req(peer, own, ts_BSSMAP_Reset(0))); |
| 470 | T.start; |
| 471 | alt { |
| 472 | [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(own, peer, tr_BSSMAP_ResetAck)) { |
| 473 | log("Received RESET-ACK in response to RESET, we're ready to go!"); |
| 474 | } |
| 475 | [] as_reset_ack(); |
| 476 | [] BSSAP.receive { repeat }; |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 477 | [] T.timeout { |
| 478 | setverdict(fail, "Timeout waiting for RESET-ACK after sending RESET"); |
| 479 | mtc.stop; |
| 480 | } |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 484 | private function f_bssap_l3_is_rr(PDU_BSSAP bssap) return boolean { |
| 485 | var template octetstring l3 := f_bssap_extract_l3(bssap); |
| 486 | return f_L3_is_rr(l3); |
| 487 | } |
| 488 | #endif |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 489 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 490 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 491 | |
| 492 | type enumerated RanProtocol { |
| 493 | RAN_PROTOCOL_BSSAP |
| 494 | } |
| 495 | |
| 496 | type record RanOps { |
| 497 | #ifdef RAN_EMULATION_BSSAP |
| 498 | BssmapCreateCallback create_cb optional, |
| 499 | BssmapUnitdataCallback unitdata_cb optional, |
| 500 | #endif |
| 501 | boolean decode_dtap, |
| 502 | boolean role_ms, |
| 503 | RanProtocol protocol, |
| 504 | /* needed for performing BSSMAP RESET */ |
| 505 | SCCP_PAR_Address sccp_addr_local optional, |
| 506 | SCCP_PAR_Address sccp_addr_peer optional |
| 507 | } |
| 508 | |
| 509 | template BIT4 t_ML3_DISC_CC_MM_SS := ('0011'B, '0101'B, '1011'B); |
| 510 | |
| 511 | private function f_L3_is_rr(template octetstring l3) return boolean { |
| 512 | if (not isvalue(l3)) { |
| 513 | return false; |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 514 | } |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 515 | var octetstring l3v := valueof(l3); |
| 516 | if (lengthof(l3v) < 1) { |
| 517 | return false; |
| 518 | } |
| 519 | /* lower 4 bits of first octet are protocol discriminator */ |
| 520 | if ((oct2bit(l3v[0]) and4b '00001111'B) == '00000110'B) { |
| 521 | return true; |
| 522 | } |
| 523 | return false; |
| 524 | } |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 525 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 526 | /* patch N(SD) into enc_l3, according to 24.007 11.2.3.2 */ |
| 527 | function f_ML3_patch_seq(inout ConnectionData cd, in PDU_ML3_MS_NW dtap, inout octetstring enc_l3) { |
| 528 | var uint2_t seq_nr; |
| 529 | if (ischosen(dtap.msgs.cc) or ischosen(dtap.msgs.mm) or ischosen(dtap.msgs.ss)) { |
| 530 | seq_nr := cd.n_sd[0]; |
| 531 | cd.n_sd[0] := (cd.n_sd[0] + 1) mod 4; |
| 532 | } else if (ischosen(dtap.msgs.gcc)) { |
| 533 | seq_nr := cd.n_sd[1]; |
| 534 | cd.n_sd[1] := (cd.n_sd[1] + 1) mod 2; |
| 535 | } else if (ischosen(dtap.msgs.bcc)) { |
| 536 | seq_nr := cd.n_sd[2]; |
| 537 | cd.n_sd[2] := (cd.n_sd[2] + 1) mod 2; |
| 538 | } else if (ischosen(dtap.msgs.loc)) { |
| 539 | seq_nr := cd.n_sd[3]; |
| 540 | cd.n_sd[3] := (cd.n_sd[3] + 1) mod 2; |
| 541 | } else { |
| 542 | /* no sequence number to patch */ |
| 543 | return; |
| 544 | } |
| 545 | log("patching N(SD)=", seq_nr, " into dtap ", enc_l3); |
| 546 | enc_l3[1] := (enc_l3[1] and4b '3f'O) or4b bit2oct(int2bit(seq_nr, 8) << 6); |
| 547 | log("patched enc_l3: ", enc_l3); |
| 548 | } |
| 549 | |
| 550 | private altstep as_reset_ack() runs on RAN_Emulation_CT { |
| 551 | #ifdef RAN_EMULATION_BSSAP |
| 552 | var BSSAP_N_UNITDATA_ind ud_ind; |
| 553 | #endif |
| 554 | #ifdef RAN_EMULATION_BSSAP |
| 555 | [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset)) -> value ud_ind { |
| 556 | log("Respoding to inbound RESET with RESET-ACK"); |
| 557 | BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress, |
| 558 | ts_BSSMAP_ResetAck)); |
| 559 | repeat; |
| 560 | } |
| 561 | #endif |
| 562 | } |
| 563 | |
| 564 | |
| 565 | private altstep as_main_bssap() runs on RAN_Emulation_CT { |
| 566 | #ifdef RAN_EMULATION_BSSAP |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 567 | var BSSAP_N_UNITDATA_ind ud_ind; |
| 568 | var BSSAP_N_CONNECT_ind conn_ind; |
| 569 | var BSSAP_N_CONNECT_cfm conn_cfm; |
| 570 | var BSSAP_N_DATA_ind data_ind; |
| 571 | var BSSAP_N_DISCONNECT_ind disc_ind; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 572 | var BSSAP_Conn_Req creq; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 573 | var PDU_BSSAP bssap; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 574 | var RAN_ConnHdlr vc_conn; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 575 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 576 | /* SCCP -> Client: UNIT-DATA (connectionless SCCP) from a BSC */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 577 | [] BSSAP.receive(BSSAP_N_UNITDATA_ind:?) -> value ud_ind { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 578 | /* Connectionless Procedures like RESET */ |
| 579 | var template PDU_BSSAP resp; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 580 | resp := CommonBssmapUnitdataCallback(ud_ind.userData); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 581 | if (isvalue(resp)) { |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 582 | BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, |
| 583 | ud_ind.calledAddress, resp)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 584 | } |
| 585 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 586 | /* SCCP -> Client: new connection from BSC */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 587 | [] BSSAP.receive(BSSAP_N_CONNECT_ind:?) -> value conn_ind { |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 588 | vc_conn := g_ran_ops.create_cb.apply(conn_ind, g_ran_id); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 589 | /* store mapping between client components and SCCP connectionId */ |
| 590 | f_conn_table_add(vc_conn, conn_ind.connectionId); |
| 591 | /* handle user payload */ |
| 592 | f_handle_userData(vc_conn, conn_ind.userData); |
| 593 | /* confirm connection establishment */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 594 | BSSAP.send(ts_BSSAP_CONNECT_res(conn_ind.connectionId, omit)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 595 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 596 | /* SCCP -> Client: connection-oriented data in existing connection */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 597 | [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value data_ind { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 598 | vc_conn := f_comp_by_conn_id(data_ind.connectionId); |
Harald Welte | 5cc4aa2 | 2017-11-23 18:51:28 +0100 | [diff] [blame] | 599 | if (ispresent(data_ind.userData)) { |
| 600 | f_handle_userData(vc_conn, data_ind.userData); |
| 601 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 602 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 603 | /* SCCP -> Client: disconnect of an existing connection */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 604 | [] BSSAP.receive(BSSAP_N_DISCONNECT_ind:?) -> value disc_ind { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 605 | vc_conn := f_comp_by_conn_id(disc_ind.connectionId); |
Harald Welte | 5cc4aa2 | 2017-11-23 18:51:28 +0100 | [diff] [blame] | 606 | if (ispresent(disc_ind.userData)) { |
| 607 | f_handle_userData(vc_conn, disc_ind.userData); |
| 608 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 609 | /* notify client about termination */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 610 | var RAN_Conn_Prim prim := MSC_CONN_PRIM_DISC_IND; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 611 | CLIENT.send(prim) to vc_conn; |
| 612 | f_conn_table_del(disc_ind.connectionId); |
| 613 | /* TOOD: return confirm to other side? */ |
| 614 | } |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 615 | /* SCCP -> Client: connection confirm for outbound connection */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 616 | [] BSSAP.receive(BSSAP_N_CONNECT_cfm:?) -> value conn_cfm { |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 617 | vc_conn := f_comp_by_conn_id(conn_cfm.connectionId); |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 618 | var RAN_Conn_Prim prim := MSC_CONN_PRIM_CONF_IND; |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 619 | CLIENT.send(prim) to vc_conn; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 620 | /* handle user payload */ |
Harald Welte | 5cc4aa2 | 2017-11-23 18:51:28 +0100 | [diff] [blame] | 621 | if (ispresent(conn_cfm.userData)) { |
| 622 | f_handle_userData(vc_conn, conn_cfm.userData); |
| 623 | } |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 624 | } |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 625 | [] CLIENT.receive(PDU_BSSAP:?) -> value bssap sender vc_conn { |
| 626 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
| 627 | /* send it to dispatcher */ |
| 628 | BSSAP.send(ts_BSSAP_DATA_req(conn_id, bssap)); |
| 629 | } |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 630 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 631 | /* Disconnect request client -> SCCP */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 632 | [] CLIENT.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ) -> sender vc_conn { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 633 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 634 | BSSAP.send(ts_BSSAP_DISC_req(conn_id, 0)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 635 | f_conn_table_del(conn_id); |
| 636 | } |
| 637 | |
| 638 | /* BSSAP from client -> SCCP */ |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 639 | [] CLIENT.receive(BSSAP_Conn_Req:?) -> value creq sender vc_conn { |
| 640 | var integer conn_id; |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 641 | /* send to dispatcher */ |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 642 | |
| 643 | if (f_comp_known(vc_conn) == false) { |
| 644 | /* unknown client, create new connection */ |
| 645 | conn_id := f_gen_conn_id(); |
| 646 | |
| 647 | /* store mapping between client components and SCCP connectionId */ |
| 648 | f_conn_table_add(vc_conn, conn_id); |
| 649 | |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 650 | BSSAP.send(ts_BSSAP_CONNECT_req(creq.addr_peer, creq.addr_own, conn_id, |
| 651 | creq.bssap)); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 652 | } else { |
| 653 | /* known client, send via existing connection */ |
| 654 | conn_id := f_conn_id_by_comp(vc_conn); |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 655 | BSSAP.send(ts_BSSAP_DATA_req(conn_id, creq.bssap)); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 656 | } |
| 657 | |
Harald Welte | 49518bf | 2018-02-10 11:39:19 +0100 | [diff] [blame] | 658 | /* InitialL3 contains RR (PAG RESP) or MM (CM SRV REQ), we must increment |
| 659 | * counter only on MM/CC/SS, but not on RR */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 660 | if (g_ran_ops.role_ms and not f_bssap_l3_is_rr(creq.bssap)) { |
Harald Welte | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 661 | /* we have just sent the first MM message, increment the counter */ |
| 662 | var integer idx := f_idx_by_comp(vc_conn); |
| 663 | ConnectionTable[idx].n_sd[0] := 1; |
| 664 | log("patch: N(SD) for ConnIdx ", idx, " set to 1"); |
| 665 | } |
| 666 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 667 | } |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 668 | #else |
| 669 | [false] CLIENT.receive(false) {} |
| 670 | #endif |
| 671 | } |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 672 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 673 | private altstep as_main_mgcp() runs on RAN_Emulation_CT { |
| 674 | #ifdef RAN_EMULATION_MGCP |
| 675 | var MgcpCommand mgcp_req; |
| 676 | var MgcpResponse mgcp_resp; |
| 677 | var RAN_ConnHdlr vc_conn; |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 678 | |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 679 | /* Handling of MGCP in IPA SCCPLite case. This predates 3GPP AoIP |
| 680 | * and uses a MGCP session in parallel to BSSAP. BSSAP uses CIC |
| 681 | * as usual, and MGCP uses "CIC@mgw" endpoint naming, where CIC |
| 682 | * is printed as hex string, e.g. a@mgw for CIC 10 */ |
| 683 | |
| 684 | /* CLIENT -> MGCP */ |
| 685 | [] CLIENT.receive(MgcpCommand:?) -> value mgcp_req sender vc_conn { |
| 686 | /* MGCP request from Handler (we're MSC) */ |
| 687 | /* store the transaction ID we've seen */ |
| 688 | f_comp_store_mgcp_tid(vc_conn, mgcp_req.line.trans_id); |
| 689 | /* simply forward any MGCP from the client to the port */ |
| 690 | MGCP.send(mgcp_req); |
| 691 | } |
| 692 | [] CLIENT.receive(MgcpResponse:?) -> value mgcp_resp sender vc_conn { |
| 693 | /* MGCP response from Handler (we're BSC/MGW) */ |
| 694 | /* simply forward any MGCP from the client to the port */ |
| 695 | MGCP.send(mgcp_resp); |
| 696 | } |
| 697 | |
| 698 | /* MGCP -> CLIENT */ |
| 699 | [] MGCP.receive(MgcpCommand:?) -> value mgcp_req { |
| 700 | /* MGCP request from network side (we're BSC/MGW) */ |
| 701 | /* Extract CIC from local part of endpoint name */ |
| 702 | var integer cic := f_mgcp_ep_extract_cic(mgcp_req.line.ep); |
Harald Welte | e98bb2e | 2017-11-29 12:09:48 +0100 | [diff] [blame] | 703 | if (match(mgcp_req, tr_RSIP) and f_cic_known(cic) == false) { |
| 704 | /* ignore RSIP for unknown CIC */ |
| 705 | } else { |
| 706 | /* Resolve the vc_conn by the CIC */ |
| 707 | vc_conn := f_comp_by_cic(cic); |
| 708 | CLIENT.send(mgcp_req) to vc_conn; |
| 709 | } |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 710 | } |
| 711 | [] MGCP.receive(MgcpResponse:?) -> value mgcp_resp { |
| 712 | /* MGCP response from network side (we're MSC) */ |
| 713 | /* Resolve the vc_conn by the transaction ID */ |
| 714 | vc_conn := f_comp_by_mgcp_tid(mgcp_resp.line.trans_id); |
| 715 | CLIENT.send(mgcp_resp) to vc_conn; |
| 716 | } |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 717 | #else |
| 718 | [false] CLIENT.receive {} |
| 719 | #endif |
| 720 | } |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 721 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 722 | /* send a raw (encoded) L3 message over given SCCP connection */ |
| 723 | private function f_xmit_raw_l3(integer sccp_conn_id, OCT1 dlci, octetstring l3_enc) runs on RAN_Emulation_CT |
| 724 | { |
| 725 | select (g_ran_ops.protocol) { |
| 726 | #ifdef RAN_EMULATION_BSSAP |
| 727 | case (RAN_PROTOCOL_BSSAP) { |
| 728 | var PDU_BSSAP bssap; |
| 729 | bssap := valueof(ts_BSSAP_DTAP(l3_enc, dlci)); |
| 730 | BSSAP.send(ts_BSSAP_DATA_req(sccp_conn_id, bssap)); |
| 731 | } |
| 732 | #endif |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | function main(RanOps ops, charstring id) runs on RAN_Emulation_CT { |
| 737 | |
| 738 | g_ran_id := id; |
| 739 | g_ran_ops := ops; |
| 740 | f_conn_table_init(); |
| 741 | f_expect_table_init(); |
| 742 | |
| 743 | if (isvalue(ops.sccp_addr_peer) and isvalue(ops.sccp_addr_local)) { |
| 744 | f_sleep(1.0); /* HACK to wait for M3UA/ASP to be ACTIVE */ |
| 745 | f_bssap_reset(ops.sccp_addr_peer, ops.sccp_addr_local); |
| 746 | } |
| 747 | |
| 748 | while (true) { |
| 749 | var RAN_ConnHdlr vc_conn; |
| 750 | var PDU_DTAP_MO dtap_mo; |
| 751 | var PDU_DTAP_MT dtap_mt; |
| 752 | var RAN_ConnHdlr vc_hdlr; |
| 753 | var octetstring l3_info; |
| 754 | var hexstring imsi; |
| 755 | var OCT4 tmsi; |
| 756 | |
| 757 | alt { |
| 758 | [g_ran_ops.protocol == RAN_PROTOCOL_BSSAP] as_main_bssap(); |
| 759 | |
| 760 | [g_ran_ops.role_ms] CLIENT.receive(PDU_DTAP_MO:?) -> value dtap_mo sender vc_conn { |
| 761 | var integer idx := f_idx_by_comp(vc_conn); |
| 762 | /* convert from decoded DTAP to encoded DTAP */ |
| 763 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(dtap_mo.dtap); |
| 764 | /* patch correct L3 send sequence number N(SD) into l3_enc */ |
| 765 | if (dtap_mo.skip_seq_patching == false) { |
| 766 | f_ML3_patch_seq(ConnectionTable[idx], dtap_mo.dtap, l3_enc); |
| 767 | } |
| 768 | f_xmit_raw_l3(ConnectionTable[idx].sccp_conn_id, dtap_mo.dlci, l3_enc); |
| 769 | } |
| 770 | |
| 771 | [not g_ran_ops.role_ms] CLIENT.receive(PDU_DTAP_MT:?) -> value dtap_mt sender vc_conn { |
| 772 | var integer idx := f_idx_by_comp(vc_conn); |
| 773 | /* convert from decoded DTAP to encoded DTAP */ |
| 774 | var octetstring l3_enc := enc_PDU_ML3_NW_MS(dtap_mt.dtap); |
| 775 | f_xmit_raw_l3(ConnectionTable[idx].sccp_conn_id, dtap_mt.dlci, l3_enc); |
| 776 | } |
| 777 | |
| 778 | [] as_main_mgcp(); |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 779 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 780 | [] PROC.getcall(RAN_register:{?,?}) -> param(l3_info, vc_hdlr) { |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 781 | f_create_expect(l3_info, vc_hdlr); |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 782 | PROC.reply(RAN_register:{l3_info, vc_hdlr}) to vc_hdlr; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 783 | } |
| 784 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 785 | [] PROC.getcall(RAN_register_imsi:{?,?,?}) -> param(imsi, tmsi, vc_hdlr) { |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 786 | f_create_imsi(imsi, tmsi, vc_hdlr); |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 787 | PROC.reply(RAN_register_imsi:{imsi, tmsi, vc_hdlr}) to vc_hdlr; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | } |
| 794 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 795 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 796 | private function f_mgcp_ep_extract_cic(charstring inp) return integer { |
Harald Welte | 525a9c1 | 2017-11-24 23:40:41 +0100 | [diff] [blame] | 797 | var charstring local_part := regexp(inp, "(*)@*", 0); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 798 | return hex2int(str2hex(local_part)); |
| 799 | |
| 800 | } |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame^] | 801 | #endif |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 802 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 803 | /*********************************************************************** |
| 804 | * "Expect" Handling (mapping for expected incoming SCCP connections) |
| 805 | ***********************************************************************/ |
| 806 | |
| 807 | /* data about an expected future incoming connection */ |
| 808 | type record ExpectData { |
| 809 | /* L3 payload based on which we can match it */ |
| 810 | octetstring l3_payload optional, |
| 811 | /* component reference for this connection */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 812 | RAN_ConnHdlr vc_conn |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | /* procedure based port to register for incoming connections */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 816 | signature RAN_register(in octetstring l3, in RAN_ConnHdlr hdlr); |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 817 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 818 | /* procedure based port to register for incoming IMSI/TMSI */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 819 | signature RAN_register_imsi(in hexstring imsi, in OCT4 tmsi, in RAN_ConnHdlr hdlr); |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 820 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 821 | type port RAN_PROC_PT procedure { |
| 822 | inout RAN_register, RAN_register_imsi; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 823 | } with { extension "internal" }; |
| 824 | |
| 825 | /* CreateCallback that can be used as create_cb and will use the expectation table */ |
| 826 | function ExpectedCreateCallback(BSSAP_N_CONNECT_ind conn_ind, charstring id) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 827 | runs on RAN_Emulation_CT return RAN_ConnHdlr { |
| 828 | var RAN_ConnHdlr ret := null; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 829 | var octetstring l3_info; |
| 830 | var integer i; |
| 831 | |
| 832 | if (not ischosen(conn_ind.userData.pdu.bssmap.completeLayer3Information)) { |
| 833 | setverdict(fail, "N-CONNECT.ind with L3 != COMPLETE L3"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 834 | mtc.stop; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 835 | return ret; |
| 836 | } |
| 837 | l3_info := conn_ind.userData.pdu.bssmap.completeLayer3Information.layer3Information.layer3info; |
| 838 | |
| 839 | for (i := 0; i < sizeof(ExpectTable); i:= i+1) { |
| 840 | if (not ispresent(ExpectTable[i].l3_payload)) { |
| 841 | continue; |
| 842 | } |
| 843 | if (l3_info == ExpectTable[i].l3_payload) { |
| 844 | ret := ExpectTable[i].vc_conn; |
| 845 | /* release this entry to be used again */ |
| 846 | ExpectTable[i].l3_payload := omit; |
| 847 | ExpectTable[i].vc_conn := null; |
| 848 | log("Found Expect[", i, "] for ", l3_info, " handled at ", ret); |
| 849 | /* return the component reference */ |
| 850 | return ret; |
| 851 | } |
| 852 | } |
| 853 | setverdict(fail, "Couldn't find Expect for incoming connection ", conn_ind); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 854 | mtc.stop; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 855 | return ret; |
| 856 | } |
| 857 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 858 | private function f_create_expect(octetstring l3, RAN_ConnHdlr hdlr) |
| 859 | runs on RAN_Emulation_CT { |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 860 | var integer i; |
| 861 | for (i := 0; i < sizeof(ExpectTable); i := i+1) { |
| 862 | if (not ispresent(ExpectTable[i].l3_payload)) { |
| 863 | ExpectTable[i].l3_payload := l3; |
| 864 | ExpectTable[i].vc_conn := hdlr; |
| 865 | log("Created Expect[", i, "] for ", l3, " to be handled at ", hdlr); |
| 866 | return; |
| 867 | } |
| 868 | } |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 869 | testcase.stop("No space left in ExpectTable"); |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 870 | } |
| 871 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 872 | private function f_create_imsi(hexstring imsi, OCT4 tmsi, RAN_ConnHdlr hdlr) |
| 873 | runs on RAN_Emulation_CT { |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 874 | for (var integer i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 875 | if (not ispresent(ImsiTable[i].imsi)) { |
| 876 | ImsiTable[i].imsi := imsi; |
| 877 | ImsiTable[i].tmsi := tmsi; |
| 878 | ImsiTable[i].comp_ref := hdlr; |
| 879 | log("Created IMSI[", i, "] for ", imsi, tmsi, " to be handled at ", hdlr); |
| 880 | return; |
| 881 | } |
| 882 | } |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 883 | testcase.stop("No space left in ImsiTable"); |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | |
Daniel Willmann | d47106b | 2018-01-17 12:20:56 +0100 | [diff] [blame] | 887 | private function f_expect_table_init() |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 888 | runs on RAN_Emulation_CT { |
Daniel Willmann | d47106b | 2018-01-17 12:20:56 +0100 | [diff] [blame] | 889 | for (var integer i := 0; i < sizeof(ExpectTable); i := i+1) { |
| 890 | ExpectTable[i].l3_payload := omit; |
| 891 | } |
| 892 | } |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 893 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 894 | /* helper function for clients to register their IMSI/TMSI */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 895 | function f_ran_register_imsi(hexstring imsi, OCT4 tmsi) |
| 896 | runs on RAN_ConnHdlr { |
| 897 | BSSAP_PROC.call(RAN_register_imsi:{imsi, tmsi, self}) { |
| 898 | [] BSSAP_PROC.getreply(RAN_register_imsi:{?,?,?}) {}; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 899 | } |
| 900 | } |
| 901 | |
| 902 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 903 | } |