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; |
Pau Espin Pedrol | 4d0e5e5 | 2019-06-07 19:38:28 +0200 | [diff] [blame] | 39 | import from Misc_Helpers all; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 40 | |
| 41 | #ifdef RAN_EMULATION_BSSAP |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 42 | import from BSSAP_Types all; |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 43 | import from BSSAP_CodecPort all; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 44 | import from BSSMAP_Templates all; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 45 | #endif |
| 46 | |
| 47 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 48 | import from MGCP_Types all; |
| 49 | import from MGCP_Templates all; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 50 | #endif |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 51 | |
Pau Espin Pedrol | 4d0e5e5 | 2019-06-07 19:38:28 +0200 | [diff] [blame] | 52 | #ifdef RAN_EMULATION_CTRL |
| 53 | import from Osmocom_CTRL_Types all; |
| 54 | import from Osmocom_CTRL_Adapter all; |
| 55 | #endif |
| 56 | |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 57 | #ifdef RAN_EMULATION_RANAP |
| 58 | import from RANAP_CodecPort all; |
| 59 | import from RANAP_PDU_Descriptions all; |
| 60 | import from RANAP_Constants all; |
| 61 | import from RANAP_IEs all; |
| 62 | import from RANAP_Templates all; |
| 63 | #endif |
| 64 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 65 | /* General "base class" component definition, of which specific implementations |
| 66 | * derive themselves by means of the "extends" feature */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 67 | type component RAN_ConnHdlr { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 68 | /* port towards MSC Emulator core / SCCP connection dispatchar */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 69 | port RAN_Conn_PT BSSAP; |
Harald Welte | ca51998 | 2018-01-21 19:28:26 +0100 | [diff] [blame] | 70 | /* procedure based port to register for incoming connections */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 71 | port RAN_PROC_PT BSSAP_PROC; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /* 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] | 75 | type enumerated RAN_Conn_Prim { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 76 | /* SCCP tell us that connection was released */ |
| 77 | MSC_CONN_PRIM_DISC_IND, |
| 78 | /* we tell SCCP to release connection */ |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 79 | MSC_CONN_PRIM_DISC_REQ, |
| 80 | /* Connection confirmed indication */ |
| 81 | MSC_CONN_PRIM_CONF_IND |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 82 | } |
| 83 | |
Pau Espin Pedrol | c6b78ff | 2019-06-06 15:58:17 +0200 | [diff] [blame] | 84 | type enumerated RAN_Transport { |
| 85 | BSSAP_TRANSPORT_AoIP, /* 3GPP AoIP: SCCP over M3UA over SCTP */ |
| 86 | BSSAP_TRANSPORT_SCCPlite_SERVER, /* SCCPlite: SCCP over IPA over TCP */ |
| 87 | BSSAP_TRANSPORT_SCCPlite_CLIENT, /* SCCPlite: SCCP over IPA over TCP */ |
| 88 | RANAP_TRANSPORT_IuCS /* 3GPP IuCS: SCCP over M3UA over SCTP */ |
| 89 | }; |
| 90 | |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 91 | /* similar to PDU_BSSAP with DTAP, but DTAP is already decoded! */ |
| 92 | type record PDU_DTAP_MO { |
| 93 | OCT1 dlci optional, |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 94 | boolean skip_seq_patching optional, |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 95 | PDU_ML3_MS_NW dtap |
| 96 | } |
| 97 | |
| 98 | /* similar to PDU_BSSAP with DTAP, but DTAP is already decoded! */ |
| 99 | type record PDU_DTAP_MT { |
| 100 | OCT1 dlci optional, |
| 101 | PDU_ML3_NW_MS dtap |
| 102 | } |
| 103 | |
Harald Welte | 717c730 | 2019-04-23 20:31:55 +0200 | [diff] [blame] | 104 | type record PDU_DTAP_PS_MO { |
| 105 | OCT1 dlci optional, |
| 106 | boolean skip_seq_patching optional, |
| 107 | PDU_L3_MS_SGSN dtap |
| 108 | } |
| 109 | |
| 110 | type record PDU_DTAP_PS_MT { |
| 111 | OCT1 dlci optional, |
| 112 | PDU_L3_SGSN_MS dtap |
| 113 | } |
| 114 | |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 115 | template PDU_DTAP_MT ts_PDU_DTAP_MT(template PDU_ML3_NW_MS dtap, template OCT1 dlci := omit) := { |
| 116 | dlci := dlci, |
| 117 | dtap := dtap |
| 118 | } |
| 119 | |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 120 | 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] | 121 | dlci := dlci, |
Daniel Willmann | 92f6627 | 2018-02-06 15:50:52 +0100 | [diff] [blame] | 122 | skip_seq_patching := skip_seq_patching, |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 123 | dtap := dtap |
| 124 | } |
| 125 | |
| 126 | template PDU_DTAP_MT tr_PDU_DTAP_MT(template PDU_ML3_NW_MS dtap, template OCT1 dlci := *) := { |
| 127 | dlci := dlci, |
| 128 | dtap := dtap |
| 129 | } |
| 130 | |
| 131 | template PDU_DTAP_MO tr_PDU_DTAP_MO(template PDU_ML3_MS_NW dtap, template OCT1 dlci := *) := { |
| 132 | dlci := dlci, |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 133 | skip_seq_patching := ?, |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 134 | dtap := dtap |
| 135 | } |
| 136 | |
Harald Welte | 717c730 | 2019-04-23 20:31:55 +0200 | [diff] [blame] | 137 | template (value) PDU_DTAP_PS_MT ts_PDU_DTAP_PS_MT(template (value) PDU_L3_SGSN_MS dtap, template (omit) OCT1 dlci := omit) := { |
| 138 | dlci := dlci, |
| 139 | dtap := dtap |
| 140 | } |
| 141 | |
| 142 | template (value) PDU_DTAP_PS_MO ts_PDU_DTAP_PS_MO(template (value) PDU_L3_MS_SGSN dtap, template (value) OCT1 dlci := '00'O, |
| 143 | boolean skip_seq_patching := false) := { |
| 144 | dlci := dlci, |
| 145 | skip_seq_patching := skip_seq_patching, |
| 146 | dtap := dtap |
| 147 | } |
| 148 | |
| 149 | template PDU_DTAP_PS_MT tr_PDU_DTAP_PS_MT(template PDU_L3_SGSN_MS dtap, template OCT1 dlci := *) := { |
| 150 | dlci := dlci, |
| 151 | dtap := dtap |
| 152 | } |
| 153 | |
| 154 | template PDU_DTAP_PS_MO tr_PDU_DTAP_PS_MO(template PDU_L3_MS_SGSN dtap, template OCT1 dlci := *) := { |
| 155 | dlci := dlci, |
| 156 | skip_seq_patching := ?, |
| 157 | dtap := dtap |
| 158 | } |
| 159 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 160 | /* port between individual per-connection components and this dispatcher */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 161 | type port RAN_Conn_PT message { |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 162 | inout |
| 163 | #ifdef RAN_EMULATION_BSSAP |
| 164 | PDU_BSSAP, |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 165 | /* Client requests us to create SCCP Connection */ |
| 166 | BSSAP_Conn_Req, |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 167 | #endif |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 168 | #ifdef RAN_EMULATION_RANAP |
| 169 | RANAP_PDU, |
| 170 | /* Client requests us to create SCCP Connection */ |
| 171 | RANAP_Conn_Req, |
| 172 | #endif |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 173 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 174 | /* MGCP, only used for IPA SCCPlite (MGCP in IPA mux) */ |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 175 | MgcpCommand, MgcpResponse, |
| 176 | #endif |
| 177 | /* direct DTAP messages from/to clients */ |
| 178 | PDU_DTAP_MO, PDU_DTAP_MT, |
Harald Welte | 717c730 | 2019-04-23 20:31:55 +0200 | [diff] [blame] | 179 | PDU_DTAP_PS_MO, PDU_DTAP_PS_MT, |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 180 | /* misc indications / requests between SCCP and client */ |
| 181 | RAN_Conn_Prim; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 182 | } with { extension "internal" }; |
| 183 | |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 184 | type uint2_t N_Sd_Array[4]; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 185 | |
| 186 | /* represents a single BSSAP connection over SCCP */ |
| 187 | type record ConnectionData { |
| 188 | /* reference to the instance of the per-connection component */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 189 | RAN_ConnHdlr comp_ref, |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 190 | integer sccp_conn_id, |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 191 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 192 | /* most recent MGCP transaction ID (Used on MSC side) */ |
| 193 | MgcpTransId mgcp_trans_id optional, |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 194 | #endif |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 195 | /* CIC that has been used for voice of this channel (BSC side) */ |
Harald Welte | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 196 | integer cic optional, |
| 197 | /* array of N(SD) values for MO DTAP messages, indexed by discriminator */ |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 198 | N_Sd_Array n_sd |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 199 | } |
| 200 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 201 | type record ImsiMapping { |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 202 | RAN_ConnHdlr comp_ref, |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 203 | hexstring imsi optional, |
| 204 | OCT4 tmsi |
| 205 | } |
| 206 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 207 | type component RAN_Emulation_CT { |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 208 | /* SCCP ports on the bottom side, using ASP primitives */ |
| 209 | #ifdef RAN_EMULATION_BSSAP |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 210 | port BSSAP_CODEC_PT BSSAP; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 211 | #endif |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 212 | #ifdef RAN_EMULATION_RANAP |
| 213 | port RANAP_CODEC_PT RANAP; |
| 214 | #endif |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 215 | /* BSSAP port to the per-connection clients */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 216 | port RAN_Conn_PT CLIENT; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 217 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 218 | /* MGCP port */ |
| 219 | port IPA_MGCP_PT MGCP; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 220 | #endif |
Pau Espin Pedrol | 4d0e5e5 | 2019-06-07 19:38:28 +0200 | [diff] [blame] | 221 | #ifdef RAN_EMULATION_CTRL |
| 222 | /* CTRL port */ |
| 223 | port IPA_CTRL_PT CTRL; |
| 224 | port IPA_CTRL_PT CTRL_CLIENT; |
| 225 | #endif |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 226 | |
| 227 | /* use 16 as this is also the number of SCCP connections that SCCP_Emulation can handle */ |
| 228 | var ConnectionData ConnectionTable[16]; |
Harald Welte | 66fecd4 | 2017-11-24 23:53:23 +0100 | [diff] [blame] | 229 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 230 | /* pending expected incoming connections */ |
| 231 | var ExpectData ExpectTable[8]; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 232 | |
| 233 | /* tables for mapping inbound unitdata (like paging) */ |
| 234 | var ImsiMapping ImsiTable[16]; |
| 235 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 236 | /* procedure based port to register for incoming connections */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 237 | port RAN_PROC_PT PROC; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 238 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 239 | var charstring g_ran_id; |
Harald Welte | 66fecd4 | 2017-11-24 23:53:23 +0100 | [diff] [blame] | 240 | var integer g_next_e1_ts := 1; |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 241 | var RanOps g_ran_ops; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 242 | }; |
| 243 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 244 | private function f_conn_id_known(integer sccp_conn_id) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 245 | runs on RAN_Emulation_CT return boolean { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 246 | var integer i; |
| 247 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 248 | if (ConnectionTable[i].sccp_conn_id == sccp_conn_id){ |
| 249 | return true; |
| 250 | } |
| 251 | } |
| 252 | return false; |
| 253 | } |
| 254 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 255 | private function f_comp_known(RAN_ConnHdlr client) |
| 256 | runs on RAN_Emulation_CT return boolean { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 257 | var integer i; |
| 258 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 259 | if (ConnectionTable[i].comp_ref == client) { |
| 260 | return true; |
| 261 | } |
| 262 | } |
| 263 | return false; |
| 264 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 265 | |
Harald Welte | e98bb2e | 2017-11-29 12:09:48 +0100 | [diff] [blame] | 266 | private function f_cic_known(integer cic) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 267 | runs on RAN_Emulation_CT return boolean { |
Harald Welte | e98bb2e | 2017-11-29 12:09:48 +0100 | [diff] [blame] | 268 | var integer i; |
| 269 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 270 | if (ConnectionTable[i].cic == cic) { |
| 271 | return true; |
| 272 | } |
| 273 | } |
| 274 | return false; |
| 275 | } |
| 276 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 277 | /* resolve component reference by connection ID */ |
| 278 | private function f_comp_by_conn_id(integer sccp_conn_id) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 279 | runs on RAN_Emulation_CT return RAN_ConnHdlr { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 280 | var integer i; |
| 281 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 282 | if (ConnectionTable[i].sccp_conn_id == sccp_conn_id) { |
| 283 | return ConnectionTable[i].comp_ref; |
| 284 | } |
| 285 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 286 | 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] | 287 | mtc.stop; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 288 | } |
| 289 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 290 | |
| 291 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 292 | /* resolve component reference by CIC */ |
| 293 | private function f_comp_by_mgcp_tid(MgcpTransId tid) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 294 | runs on RAN_Emulation_CT return RAN_ConnHdlr { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 295 | var integer i; |
| 296 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 297 | if (ConnectionTable[i].mgcp_trans_id == tid) { |
| 298 | return ConnectionTable[i].comp_ref; |
| 299 | } |
| 300 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 301 | setverdict(fail, "RAN Connection table not found by MGCP Transaction ID ", tid); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 302 | mtc.stop; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 303 | } |
| 304 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 305 | private function f_comp_store_mgcp_tid(RAN_ConnHdlr client, MgcpTransId tid) |
| 306 | runs on RAN_Emulation_CT { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 307 | var integer i; |
| 308 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 309 | if (ConnectionTable[i].comp_ref == client) { |
| 310 | ConnectionTable[i].mgcp_trans_id := tid; |
| 311 | return; |
| 312 | } |
| 313 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 314 | setverdict(fail, "RAN Connection table not found by component ", client); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 315 | mtc.stop; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 316 | } |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 317 | #endif |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 318 | |
| 319 | private function f_comp_by_cic(integer cic) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 320 | runs on RAN_Emulation_CT return RAN_ConnHdlr { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 321 | var integer i; |
| 322 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 323 | if (ConnectionTable[i].cic == cic) { |
| 324 | return ConnectionTable[i].comp_ref; |
| 325 | } |
| 326 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 327 | setverdict(fail, "RAN Connection table not found by CIC ", cic); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 328 | mtc.stop; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 329 | } |
| 330 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 331 | private function f_comp_store_cic(RAN_ConnHdlr client, integer cic) |
| 332 | runs on RAN_Emulation_CT { |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 333 | var integer i; |
| 334 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 335 | if (ConnectionTable[i].comp_ref == client) { |
| 336 | ConnectionTable[i].cic := cic; |
| 337 | return; |
| 338 | } |
| 339 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 340 | setverdict(fail, "RAN Connection table not found by component ", client); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 341 | mtc.stop; |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 342 | } |
| 343 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 344 | /* resolve connection ID by component reference */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 345 | private function f_conn_id_by_comp(RAN_ConnHdlr client) |
| 346 | runs on RAN_Emulation_CT return integer { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 347 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 348 | if (ConnectionTable[i].comp_ref == client) { |
| 349 | return ConnectionTable[i].sccp_conn_id; |
| 350 | } |
| 351 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 352 | setverdict(fail, "RAN Connection table not found by component ", client); |
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 | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 356 | /* resolve ConnectionTable index component reference */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 357 | private function f_idx_by_comp(RAN_ConnHdlr client) |
| 358 | runs on RAN_Emulation_CT return integer { |
Harald Welte | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 359 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 360 | if (ConnectionTable[i].comp_ref == client) { |
| 361 | return i; |
| 362 | } |
| 363 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 364 | setverdict(fail, "RAN Connection table not found by component ", client); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 365 | mtc.stop; |
Harald Welte | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 366 | } |
| 367 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 368 | private function f_gen_conn_id() |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 369 | runs on RAN_Emulation_CT return integer { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 370 | var integer conn_id; |
| 371 | |
| 372 | do { |
| 373 | conn_id := float2int(rnd()*SCCP_Emulation.tsp_max_ConnectionId); |
| 374 | } while (f_conn_id_known(conn_id) == true); |
| 375 | |
| 376 | return conn_id; |
| 377 | } |
| 378 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 379 | private function f_conn_table_init() |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 380 | runs on RAN_Emulation_CT { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 381 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 382 | ConnectionTable[i].comp_ref := null; |
| 383 | ConnectionTable[i].sccp_conn_id := -1; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 384 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 385 | ConnectionTable[i].mgcp_trans_id := omit; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 386 | #endif |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 387 | ConnectionTable[i].cic := omit; |
Harald Welte | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 388 | ConnectionTable[i].n_sd := { 0, 0, 0, 0 }; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 389 | } |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 390 | for (var integer i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 391 | ImsiTable[i].comp_ref := null; |
| 392 | ImsiTable[i].imsi := omit; |
| 393 | ImsiTable[i].tmsi := 'FFFFFFFF'O; |
| 394 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 395 | } |
| 396 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 397 | private function f_conn_table_add(RAN_ConnHdlr comp_ref, integer sccp_conn_id) |
| 398 | runs on RAN_Emulation_CT { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 399 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 400 | if (ConnectionTable[i].sccp_conn_id == -1) { |
| 401 | ConnectionTable[i].comp_ref := comp_ref; |
| 402 | ConnectionTable[i].sccp_conn_id := sccp_conn_id; |
Harald Welte | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 403 | ConnectionTable[i].n_sd := { 0, 0, 0, 0 }; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 404 | log("Added conn table entry ", i, comp_ref, sccp_conn_id); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 405 | return; |
| 406 | } |
| 407 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 408 | testcase.stop("RAN Connection table full!"); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | private function f_conn_table_del(integer sccp_conn_id) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 412 | runs on RAN_Emulation_CT { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 413 | for (var integer i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 414 | if (ConnectionTable[i].sccp_conn_id == sccp_conn_id) { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 415 | log("Deleted conn table entry ", i, |
| 416 | ConnectionTable[i].comp_ref, sccp_conn_id); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 417 | ConnectionTable[i].sccp_conn_id := -1; |
| 418 | ConnectionTable[i].comp_ref := null; |
Harald Welte | 0a4317a | 2017-11-25 00:32:46 +0100 | [diff] [blame] | 419 | return |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 420 | } |
| 421 | } |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 422 | 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] | 423 | mtc.stop; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 424 | } |
| 425 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 426 | private function f_imsi_table_find(hexstring imsi, template OCT4 tmsi) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 427 | runs on RAN_Emulation_CT return RAN_ConnHdlr { |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 428 | for (var integer i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 429 | if (ImsiTable[i].imsi == imsi or |
| 430 | isvalue(tmsi) and match(ImsiTable[i].tmsi, tmsi)) { |
| 431 | return ImsiTable[i].comp_ref; |
| 432 | } |
| 433 | } |
| 434 | return null; |
| 435 | } |
| 436 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 437 | #ifdef RAN_EMULATION_BSSAP |
| 438 | type record BSSAP_Conn_Req { |
| 439 | SCCP_PAR_Address addr_peer, |
| 440 | SCCP_PAR_Address addr_own, |
| 441 | PDU_BSSAP bssap |
| 442 | } |
| 443 | template BSSAP_Conn_Req ts_BSSAP_Conn_Req(SCCP_PAR_Address peer, SCCP_PAR_Address own, PDU_BSSAP bssap) := { |
| 444 | addr_peer := peer, |
| 445 | addr_own := own, |
| 446 | bssap := bssap |
| 447 | }; |
| 448 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 449 | /* 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] | 450 | private function f_handle_userData(RAN_ConnHdlr client, PDU_BSSAP bssap) |
| 451 | runs on RAN_Emulation_CT { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 452 | /* decode + send decoded BSSAP to client */ |
Harald Welte | 1b2748e | 2017-11-24 23:40:16 +0100 | [diff] [blame] | 453 | |
Harald Welte | 473676b | 2018-01-27 20:38:01 +0100 | [diff] [blame] | 454 | if (ischosen(bssap.pdu.bssmap)) { |
| 455 | /* BSC Side: If this is an assignment command, store CIC */ |
| 456 | if (ischosen(bssap.pdu.bssmap.assignmentRequest) and |
| 457 | ispresent(bssap.pdu.bssmap.assignmentRequest.circuitIdentityCode)) { |
| 458 | var BSSMAP_IE_CircuitIdentityCode cic_ie := |
| 459 | bssap.pdu.bssmap.assignmentRequest.circuitIdentityCode; |
Pau Espin Pedrol | 43021cb | 2019-06-18 17:32:15 +0200 | [diff] [blame] | 460 | var integer cic := f_bssmap_ie_cic_2_int(cic_ie); |
Harald Welte | 473676b | 2018-01-27 20:38:01 +0100 | [diff] [blame] | 461 | f_comp_store_cic(client, cic); |
| 462 | } |
Harald Welte | 1b2748e | 2017-11-24 23:40:16 +0100 | [diff] [blame] | 463 | } |
| 464 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 465 | if (ischosen(bssap.pdu.dtap) and g_ran_ops.decode_dtap) { |
| 466 | if (g_ran_ops.role_ms) { |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 467 | /* we are the MS, so any message to us must be MT */ |
| 468 | var PDU_DTAP_MT mt := { |
| 469 | dlci := bssap.dlci, |
| 470 | dtap := dec_PDU_ML3_NW_MS(bssap.pdu.dtap) |
| 471 | }; |
| 472 | CLIENT.send(mt) to client; |
| 473 | } else { |
| 474 | /* we are the Network, so any message to us must be MO */ |
| 475 | var PDU_DTAP_MO mo := { |
| 476 | dlci := bssap.dlci, |
| 477 | dtap := dec_PDU_ML3_MS_NW(bssap.pdu.dtap) |
| 478 | }; |
| 479 | CLIENT.send(mo) to client; |
| 480 | } |
| 481 | } else { |
| 482 | CLIENT.send(bssap) to client; |
| 483 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /* call-back type, to be provided by specific implementation; called when new SCCP connection |
| 487 | * arrives */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 488 | type function BssmapCreateCallback(BSSAP_N_CONNECT_ind conn_ind, charstring id) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 489 | runs on RAN_Emulation_CT return RAN_ConnHdlr; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 490 | |
| 491 | type function BssmapUnitdataCallback(PDU_BSSAP bssap) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 492 | runs on RAN_Emulation_CT return template PDU_BSSAP; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 493 | |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 494 | private function append_osmux_ie() |
| 495 | runs on RAN_Emulation_CT return boolean { |
| 496 | return g_ran_ops.use_osmux and (g_ran_ops.transport == BSSAP_TRANSPORT_AoIP); |
| 497 | } |
| 498 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 499 | /* handle common Unitdata such as Paging */ |
| 500 | private function CommonBssmapUnitdataCallback(PDU_BSSAP bssap) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 501 | runs on RAN_Emulation_CT return template PDU_BSSAP { |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 502 | if (match(bssap, tr_BSSMAP_Paging)) { |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 503 | var RAN_ConnHdlr client := null; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 504 | client := f_imsi_table_find(bssap.pdu.bssmap.paging.iMSI.digits, |
| 505 | bssap.pdu.bssmap.paging.tMSI.tmsiOctets); |
Daniel Willmann | abc73e1 | 2019-04-15 17:25:56 +0200 | [diff] [blame] | 506 | if (client != null) { |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 507 | log("CommonBssmapUnitdataCallback: IMSI/TMSI found in table, dispatching to ", |
| 508 | client); |
| 509 | CLIENT.send(bssap) to client; |
| 510 | return omit; |
| 511 | } |
| 512 | log("CommonBssmapUnitdataCallback: IMSI/TMSI not found in table"); |
| 513 | } else { |
| 514 | log("CommonBssmapUnitdataCallback: Not a paging message"); |
| 515 | } |
| 516 | /* ELSE: handle in user callback */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 517 | return g_ran_ops.unitdata_cb.apply(bssap); |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 518 | } |
| 519 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 520 | private function f_bssap_wait_for_reset() runs on RAN_Emulation_CT { |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 521 | var BSSAP_N_UNITDATA_ind ud_ind; |
| 522 | timer T := 20.0; |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 523 | var boolean append_osmux_support := append_osmux_ie(); |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 524 | |
| 525 | T.start; |
| 526 | alt { |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 527 | [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(append_osmux_support))) -> value ud_ind { |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 528 | BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress, |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 529 | ts_BSSMAP_ResetAck(append_osmux_support))); |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 530 | } |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 531 | [] as_reset_ack(append_osmux_support); |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 532 | [] BSSAP.receive { |
| 533 | repeat; |
| 534 | } |
| 535 | [] T.timeout { |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 536 | setverdict(fail, "Timeout waiting for BSSAP RESET"); |
| 537 | mtc.stop; |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 538 | } |
| 539 | } |
| 540 | } |
| 541 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 542 | 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] | 543 | timer T := 5.0; |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 544 | var boolean append_osmux_support := append_osmux_ie(); |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 545 | |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 546 | BSSAP.send(ts_BSSAP_UNITDATA_req(peer, own, ts_BSSMAP_Reset(0, append_osmux_support))); |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 547 | T.start; |
| 548 | alt { |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 549 | [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(own, peer, tr_BSSMAP_ResetAck(append_osmux_support))) { |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 550 | log("Received RESET-ACK in response to RESET, we're ready to go!"); |
| 551 | } |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 552 | [] as_reset_ack(append_osmux_support); |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 553 | [] BSSAP.receive { repeat }; |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 554 | [] T.timeout { |
| 555 | setverdict(fail, "Timeout waiting for RESET-ACK after sending RESET"); |
| 556 | mtc.stop; |
| 557 | } |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 558 | } |
| 559 | } |
| 560 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 561 | private function f_bssap_l3_is_rr(PDU_BSSAP bssap) return boolean { |
| 562 | var template octetstring l3 := f_bssap_extract_l3(bssap); |
| 563 | return f_L3_is_rr(l3); |
| 564 | } |
| 565 | #endif |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 566 | |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 567 | #ifdef RAN_EMULATION_RANAP |
| 568 | type record RANAP_Conn_Req { |
| 569 | SCCP_PAR_Address addr_peer, |
| 570 | SCCP_PAR_Address addr_own, |
| 571 | RANAP_PDU ranap |
| 572 | } |
| 573 | template (value) RANAP_Conn_Req ts_RANAP_Conn_Req(SCCP_PAR_Address peer, SCCP_PAR_Address own, RANAP_PDU ranap) := { |
| 574 | addr_peer := peer, |
| 575 | addr_own := own, |
| 576 | ranap := ranap |
| 577 | }; |
| 578 | |
| 579 | private function fake_dlci_from_sapi(template (omit) SAPI sapi) return template (omit) OCT1 |
| 580 | { |
| 581 | if (istemplatekind(sapi, "omit")) { |
| 582 | return omit; |
| 583 | } else if (valueof(sapi) == sapi_3) { |
| 584 | return '03'O; |
| 585 | } |
| 586 | return '00'O; |
| 587 | } |
| 588 | |
| 589 | private function f_handle_userData_RANAP(RAN_ConnHdlr client, RANAP_PDU ranap) |
| 590 | runs on RAN_Emulation_CT { |
| 591 | /* decode + send decoded RANAP to client */ |
| 592 | var template (omit) octetstring l3 := f_ranap_extract_l3(ranap); |
| 593 | if (istemplatekind(l3, "omit")) { |
| 594 | CLIENT.send(ranap) to client; |
| 595 | } else { |
| 596 | var template (omit) SAPI sapi := f_ranap_extract_sapi(ranap); |
| 597 | var template (omit) OCT1 dlci := fake_dlci_from_sapi(sapi); |
| 598 | if (g_ran_ops.role_ms) { |
| 599 | /* we are the MS, so any message to us must be MT */ |
Harald Welte | 717c730 | 2019-04-23 20:31:55 +0200 | [diff] [blame] | 600 | if (g_ran_ops.ps_domain) { |
| 601 | var PDU_DTAP_PS_MT mt := { |
| 602 | dlci := omit, |
| 603 | dtap := dec_PDU_L3_SGSN_MS(valueof(l3)) |
| 604 | }; |
| 605 | if (isvalue(dlci)) { |
| 606 | mt.dlci := valueof(dlci); |
| 607 | } |
| 608 | CLIENT.send(mt) to client; |
| 609 | } else { |
| 610 | var PDU_DTAP_MT mt := { |
| 611 | dlci := omit, |
| 612 | dtap := dec_PDU_ML3_NW_MS(valueof(l3)) |
| 613 | }; |
| 614 | if (isvalue(dlci)) { |
| 615 | mt.dlci := valueof(dlci) |
| 616 | } |
| 617 | CLIENT.send(mt) to client; |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 618 | } |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 619 | } else { |
| 620 | /* we are the Network, so any message to us must be MO */ |
Harald Welte | 717c730 | 2019-04-23 20:31:55 +0200 | [diff] [blame] | 621 | if (g_ran_ops.ps_domain) { |
| 622 | var PDU_DTAP_PS_MO mo := { |
| 623 | dlci := omit, |
| 624 | dtap := dec_PDU_L3_MS_SGSN(valueof(l3)) |
| 625 | }; |
| 626 | if (isvalue(dlci)) { |
| 627 | mo.dlci := valueof(dlci); |
| 628 | } |
| 629 | CLIENT.send(mo) to client; |
| 630 | } else { |
| 631 | var PDU_DTAP_MO mo := { |
| 632 | dlci := omit, |
| 633 | dtap := dec_PDU_ML3_MS_NW(valueof(l3)) |
| 634 | }; |
| 635 | if (isvalue(dlci)) { |
| 636 | mo.dlci := valueof(dlci) |
| 637 | } |
| 638 | CLIENT.send(mo) to client; |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 639 | } |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | /* call-back type, to be provided by specific implementation; called when new SCCP connection |
| 645 | * arrives */ |
| 646 | type function RanapCreateCallback(RANAP_N_CONNECT_ind conn_ind, charstring id) |
| 647 | runs on RAN_Emulation_CT return RAN_ConnHdlr; |
| 648 | |
| 649 | type function RanapUnitdataCallback(RANAP_PDU ranap) |
| 650 | runs on RAN_Emulation_CT return template RANAP_PDU; |
| 651 | |
| 652 | private function CommonRanapUnitdataCallback(RANAP_PDU ranap) |
| 653 | runs on RAN_Emulation_CT return template RANAP_PDU { |
| 654 | if (match(ranap, tr_RANAP_Paging(?, ?))) { |
| 655 | var RAN_ConnHdlr client := null; |
| 656 | /* extract IMSI and (if present) TMSI */ |
| 657 | var IMSI imsi := ranap.initiatingMessage.value_.paging.protocolIEs[1].value_.permanentNAS_UE_ID.iMSI; |
| 658 | var template OCT4 tmsi := omit; |
| 659 | if (lengthof(ranap.initiatingMessage.value_.paging.protocolIEs) > 2 and |
| 660 | ranap.initiatingMessage.value_.paging.protocolIEs[2].id == id_TemporaryUE_ID) { |
| 661 | var TemporaryUE_ID ue_id; |
| 662 | ue_id := ranap.initiatingMessage.value_.paging.protocolIEs[2].value_.temporaryUE_ID; |
| 663 | if (ischosen(ue_id.tMSI)) { |
| 664 | tmsi := ue_id.tMSI; |
| 665 | } else { |
| 666 | tmsi := ue_id.p_TMSI; |
| 667 | } |
| 668 | } |
| 669 | client := f_imsi_table_find(oct2hex(imsi), tmsi); |
Harald Welte | 03d4e2b | 2019-05-10 00:42:33 +0200 | [diff] [blame] | 670 | if (client != null) { |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 671 | log("CommonRanapUnitdataCallback: IMSI/TMSI found in table, dispatching to ", |
| 672 | client); |
| 673 | CLIENT.send(ranap) to client; |
| 674 | return omit; |
| 675 | } |
| 676 | log("CommonRanapUnitdataCallback: IMSI/TMSI not found in table"); |
| 677 | } else { |
| 678 | log("CommonRanapUnitdataCallback: Not a paging message"); |
| 679 | } |
| 680 | |
| 681 | /* ELSE: handle in user callback */ |
| 682 | return g_ran_ops.ranap_unitdata_cb.apply(ranap); |
| 683 | } |
| 684 | |
| 685 | private function f_ranap_l3_is_rr(RANAP_PDU ranap) return boolean { |
| 686 | var template (omit) SAPI sapi; |
| 687 | var template octetstring l3 := f_ranap_extract_l3(ranap); |
| 688 | return f_L3_is_rr(l3); |
| 689 | } |
| 690 | |
| 691 | function f_ranap_reset(SCCP_PAR_Address peer, SCCP_PAR_Address own) runs on RAN_Emulation_CT { |
| 692 | timer T := 5.0; |
| 693 | var CN_DomainIndicator dom; |
| 694 | if (g_ran_ops.ps_domain) { |
| 695 | dom := ps_domain; |
| 696 | } else { |
| 697 | dom := cs_domain; |
| 698 | } |
| 699 | |
| 700 | RANAP.send(ts_RANAP_UNITDATA_req(peer, own, ts_RANAP_Reset(ts_RanapCause_om_intervention, dom))); |
| 701 | T.start; |
| 702 | alt { |
| 703 | [] RANAP.receive(tr_RANAP_UNITDATA_ind(own, peer, tr_RANAP_ResetAck)) { |
| 704 | log("Received RESET-ACK in response to RESET, we're ready to go!"); |
| 705 | } |
| 706 | [] as_reset_ack(); |
| 707 | [] RANAP.receive { repeat }; |
| 708 | [] T.timeout { |
| 709 | setverdict(fail, "Timeout waiting for RESET-ACK after sending RESET"); |
| 710 | mtc.stop; |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | #endif |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 715 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 716 | |
| 717 | type enumerated RanProtocol { |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 718 | RAN_PROTOCOL_BSSAP, |
| 719 | RAN_PROTOCOL_RANAP |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | type record RanOps { |
| 723 | #ifdef RAN_EMULATION_BSSAP |
| 724 | BssmapCreateCallback create_cb optional, |
| 725 | BssmapUnitdataCallback unitdata_cb optional, |
| 726 | #endif |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 727 | #ifdef RAN_EMULATION_RANAP |
| 728 | RanapCreateCallback ranap_create_cb optional, |
| 729 | RanapUnitdataCallback ranap_unitdata_cb optional, |
| 730 | boolean ps_domain, |
| 731 | #endif |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 732 | boolean decode_dtap, |
| 733 | boolean role_ms, |
| 734 | RanProtocol protocol, |
Pau Espin Pedrol | c6b78ff | 2019-06-06 15:58:17 +0200 | [diff] [blame] | 735 | RAN_Transport transport, |
Pau Espin Pedrol | c6a53db | 2019-05-20 19:31:47 +0200 | [diff] [blame] | 736 | boolean use_osmux, |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 737 | /* needed for performing BSSMAP RESET */ |
| 738 | SCCP_PAR_Address sccp_addr_local optional, |
| 739 | SCCP_PAR_Address sccp_addr_peer optional |
| 740 | } |
| 741 | |
| 742 | template BIT4 t_ML3_DISC_CC_MM_SS := ('0011'B, '0101'B, '1011'B); |
| 743 | |
| 744 | private function f_L3_is_rr(template octetstring l3) return boolean { |
| 745 | if (not isvalue(l3)) { |
| 746 | return false; |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 747 | } |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 748 | var octetstring l3v := valueof(l3); |
| 749 | if (lengthof(l3v) < 1) { |
| 750 | return false; |
| 751 | } |
| 752 | /* lower 4 bits of first octet are protocol discriminator */ |
| 753 | if ((oct2bit(l3v[0]) and4b '00001111'B) == '00000110'B) { |
| 754 | return true; |
| 755 | } |
| 756 | return false; |
| 757 | } |
Harald Welte | a4ca446 | 2018-02-09 00:17:14 +0100 | [diff] [blame] | 758 | |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 759 | function f_next_n_sd(inout N_Sd_Array n_sd, in integer n_sd_idx) return uint2_t { |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 760 | var uint2_t seq_nr; |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 761 | if (n_sd_idx == 0) { |
| 762 | seq_nr := n_sd[0]; |
| 763 | n_sd[0] := (n_sd[0] + 1) mod 4; |
| 764 | } else if (n_sd_idx >= 1 and n_sd_idx <= 3) { |
| 765 | seq_nr := n_sd[n_sd_idx]; |
| 766 | n_sd[n_sd_idx] := (n_sd[n_sd_idx] + 1) mod 2; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 767 | } else { |
| 768 | /* no sequence number to patch */ |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 769 | seq_nr := 0; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 770 | } |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 771 | return seq_nr; |
| 772 | } |
| 773 | |
| 774 | /* patch N(SD) into enc_l3, according to 24.007 11.2.3.2 */ |
| 775 | function f_ML3_patch_seq_nr(in uint2_t seq_nr, inout octetstring enc_l3) { |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 776 | log("patching N(SD)=", seq_nr, " into dtap ", enc_l3); |
| 777 | enc_l3[1] := (enc_l3[1] and4b '3f'O) or4b bit2oct(int2bit(seq_nr, 8) << 6); |
| 778 | log("patched enc_l3: ", enc_l3); |
| 779 | } |
| 780 | |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 781 | function f_ML3_n_sd_idx(in PDU_ML3_MS_NW dtap) return integer { |
| 782 | var uint2_t seq_nr; |
| 783 | if (ischosen(dtap.msgs.cc) or ischosen(dtap.msgs.mm) or ischosen(dtap.msgs.ss)) { |
| 784 | return 0; |
| 785 | } else if (ischosen(dtap.msgs.gcc)) { |
| 786 | return 1; |
| 787 | } else if (ischosen(dtap.msgs.bcc)) { |
| 788 | return 2; |
| 789 | } else if (ischosen(dtap.msgs.loc)) { |
| 790 | return 3; |
| 791 | } |
| 792 | /* no sequence number to patch */ |
| 793 | return -1; |
| 794 | } |
| 795 | |
| 796 | /* patch N(SD) into enc_l3, according to 24.007 11.2.3.2 */ |
| 797 | function f_ML3_patch_seq(inout ConnectionData cd, in PDU_ML3_MS_NW dtap, inout octetstring enc_l3) { |
| 798 | var integer n_sd_idx := f_ML3_n_sd_idx(dtap); |
| 799 | if (n_sd_idx < 0) { |
| 800 | return; |
| 801 | } |
| 802 | var uint2_t seq_nr := f_next_n_sd(cd.n_sd, n_sd_idx); |
| 803 | f_ML3_patch_seq_nr(seq_nr, enc_l3); |
| 804 | } |
| 805 | |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 806 | private altstep as_reset_ack(boolean append_osmux_support := false) runs on RAN_Emulation_CT { |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 807 | #ifdef RAN_EMULATION_BSSAP |
| 808 | var BSSAP_N_UNITDATA_ind ud_ind; |
| 809 | #endif |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 810 | #ifdef RAN_EMULATION_RANAP |
| 811 | var RANAP_N_UNITDATA_ind rud_ind; |
| 812 | #endif |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 813 | #ifdef RAN_EMULATION_BSSAP |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 814 | [] BSSAP.receive(tr_BSSAP_UNITDATA_ind(?, ?, tr_BSSMAP_Reset(append_osmux_support))) -> value ud_ind { |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 815 | log("Respoding to inbound RESET with RESET-ACK"); |
| 816 | BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, ud_ind.calledAddress, |
Pau Espin Pedrol | 9554918 | 2019-06-06 16:17:30 +0200 | [diff] [blame] | 817 | ts_BSSMAP_ResetAck(append_osmux_support))); |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 818 | repeat; |
| 819 | } |
| 820 | #endif |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 821 | #ifdef RAN_EMULATION_RANAP |
| 822 | [] RANAP.receive(tr_RANAP_UNITDATA_ind(?, ?, tr_RANAP_Reset)) -> value rud_ind { |
| 823 | log("Respoding to inbound IuRESET with IuRESET-ACK"); |
| 824 | var CN_DomainIndicator dom; |
| 825 | dom := rud_ind.userData.initiatingMessage.value_.Reset.protocolIEs[1].value_.cN_DomainIndicator; |
| 826 | RANAP.send(ts_RANAP_UNITDATA_req(rud_ind.callingAddress, rud_ind.calledAddress, |
| 827 | ts_RANAP_ResetAck(dom))); |
| 828 | } |
| 829 | #endif |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | |
| 833 | private altstep as_main_bssap() runs on RAN_Emulation_CT { |
| 834 | #ifdef RAN_EMULATION_BSSAP |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 835 | var BSSAP_N_UNITDATA_ind ud_ind; |
| 836 | var BSSAP_N_CONNECT_ind conn_ind; |
| 837 | var BSSAP_N_CONNECT_cfm conn_cfm; |
| 838 | var BSSAP_N_DATA_ind data_ind; |
| 839 | var BSSAP_N_DISCONNECT_ind disc_ind; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 840 | var BSSAP_Conn_Req creq; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 841 | var PDU_BSSAP bssap; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 842 | var RAN_ConnHdlr vc_conn; |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 843 | var integer targetPointCode; |
| 844 | var N_Sd_Array last_n_sd; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 845 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 846 | /* SCCP -> Client: UNIT-DATA (connectionless SCCP) from a BSC */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 847 | [] BSSAP.receive(BSSAP_N_UNITDATA_ind:?) -> value ud_ind { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 848 | /* Connectionless Procedures like RESET */ |
| 849 | var template PDU_BSSAP resp; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 850 | resp := CommonBssmapUnitdataCallback(ud_ind.userData); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 851 | if (isvalue(resp)) { |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 852 | BSSAP.send(ts_BSSAP_UNITDATA_req(ud_ind.callingAddress, |
| 853 | ud_ind.calledAddress, resp)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 854 | } |
| 855 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 856 | /* SCCP -> Client: new connection from BSC */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 857 | [] BSSAP.receive(BSSAP_N_CONNECT_ind:?) -> value conn_ind { |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 858 | 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] | 859 | /* store mapping between client components and SCCP connectionId */ |
| 860 | f_conn_table_add(vc_conn, conn_ind.connectionId); |
| 861 | /* handle user payload */ |
| 862 | f_handle_userData(vc_conn, conn_ind.userData); |
| 863 | /* confirm connection establishment */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 864 | BSSAP.send(ts_BSSAP_CONNECT_res(conn_ind.connectionId, omit)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 865 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 866 | /* SCCP -> Client: connection-oriented data in existing connection */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 867 | [] BSSAP.receive(BSSAP_N_DATA_ind:?) -> value data_ind { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 868 | vc_conn := f_comp_by_conn_id(data_ind.connectionId); |
Harald Welte | 5cc4aa2 | 2017-11-23 18:51:28 +0100 | [diff] [blame] | 869 | if (ispresent(data_ind.userData)) { |
| 870 | f_handle_userData(vc_conn, data_ind.userData); |
| 871 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 872 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 873 | /* SCCP -> Client: disconnect of an existing connection */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 874 | [] BSSAP.receive(BSSAP_N_DISCONNECT_ind:?) -> value disc_ind { |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 875 | vc_conn := f_comp_by_conn_id(disc_ind.connectionId); |
Harald Welte | 5cc4aa2 | 2017-11-23 18:51:28 +0100 | [diff] [blame] | 876 | if (ispresent(disc_ind.userData)) { |
| 877 | f_handle_userData(vc_conn, disc_ind.userData); |
| 878 | } |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 879 | /* notify client about termination */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 880 | var RAN_Conn_Prim prim := MSC_CONN_PRIM_DISC_IND; |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 881 | CLIENT.send(prim) to vc_conn; |
| 882 | f_conn_table_del(disc_ind.connectionId); |
| 883 | /* TOOD: return confirm to other side? */ |
| 884 | } |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 885 | /* SCCP -> Client: connection confirm for outbound connection */ |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 886 | [] BSSAP.receive(BSSAP_N_CONNECT_cfm:?) -> value conn_cfm { |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 887 | vc_conn := f_comp_by_conn_id(conn_cfm.connectionId); |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 888 | var RAN_Conn_Prim prim := MSC_CONN_PRIM_CONF_IND; |
Harald Welte | 71b6933 | 2018-01-21 20:43:53 +0100 | [diff] [blame] | 889 | CLIENT.send(prim) to vc_conn; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 890 | /* handle user payload */ |
Harald Welte | 5cc4aa2 | 2017-11-23 18:51:28 +0100 | [diff] [blame] | 891 | if (ispresent(conn_cfm.userData)) { |
| 892 | f_handle_userData(vc_conn, conn_cfm.userData); |
| 893 | } |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 894 | } |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 895 | [] CLIENT.receive(PDU_BSSAP:?) -> value bssap sender vc_conn { |
| 896 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
| 897 | /* send it to dispatcher */ |
| 898 | BSSAP.send(ts_BSSAP_DATA_req(conn_id, bssap)); |
| 899 | } |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 900 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 901 | /* Disconnect request client -> SCCP */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 902 | [] 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] | 903 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 904 | BSSAP.send(ts_BSSAP_DISC_req(conn_id, 0)); |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 905 | f_conn_table_del(conn_id); |
| 906 | } |
| 907 | |
| 908 | /* BSSAP from client -> SCCP */ |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 909 | [] CLIENT.receive(BSSAP_Conn_Req:?) -> value creq sender vc_conn { |
| 910 | var integer conn_id; |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 911 | /* send to dispatcher */ |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 912 | |
| 913 | if (f_comp_known(vc_conn) == false) { |
| 914 | /* unknown client, create new connection */ |
| 915 | conn_id := f_gen_conn_id(); |
| 916 | |
| 917 | /* store mapping between client components and SCCP connectionId */ |
| 918 | f_conn_table_add(vc_conn, conn_id); |
| 919 | |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 920 | BSSAP.send(ts_BSSAP_CONNECT_req(creq.addr_peer, creq.addr_own, conn_id, |
| 921 | creq.bssap)); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 922 | } else { |
| 923 | /* known client, send via existing connection */ |
| 924 | conn_id := f_conn_id_by_comp(vc_conn); |
Harald Welte | 004f5fb | 2017-12-16 17:54:40 +0100 | [diff] [blame] | 925 | BSSAP.send(ts_BSSAP_DATA_req(conn_id, creq.bssap)); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 926 | } |
| 927 | |
Harald Welte | 49518bf | 2018-02-10 11:39:19 +0100 | [diff] [blame] | 928 | /* InitialL3 contains RR (PAG RESP) or MM (CM SRV REQ), we must increment |
| 929 | * counter only on MM/CC/SS, but not on RR */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 930 | 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] | 931 | /* we have just sent the first MM message, increment the counter */ |
| 932 | var integer idx := f_idx_by_comp(vc_conn); |
| 933 | ConnectionTable[idx].n_sd[0] := 1; |
| 934 | log("patch: N(SD) for ConnIdx ", idx, " set to 1"); |
| 935 | } |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 936 | } |
Harald Welte | 9dadc52 | 2018-02-06 13:56:04 +0100 | [diff] [blame] | 937 | |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 938 | [] PROC.getcall(RAN_last_n_sd:{?,-}) -> param(vc_conn) { |
| 939 | var integer idx := f_idx_by_comp(vc_conn); |
| 940 | last_n_sd := ConnectionTable[idx].n_sd; |
| 941 | PROC.reply(RAN_last_n_sd:{vc_conn, last_n_sd}) to vc_conn; |
| 942 | } |
| 943 | |
| 944 | [] PROC.getcall(RAN_continue_after_n_sd:{?,?}) -> param(last_n_sd, vc_conn) { |
| 945 | var integer idx := f_idx_by_comp(vc_conn); |
| 946 | ConnectionTable[idx].n_sd := last_n_sd; |
| 947 | PROC.reply(RAN_continue_after_n_sd:{last_n_sd, vc_conn}) to vc_conn; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 948 | } |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 949 | #else |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 950 | [false] CLIENT.receive {} |
| 951 | #endif |
| 952 | } |
| 953 | |
| 954 | private altstep as_main_ranap() runs on RAN_Emulation_CT { |
| 955 | #ifdef RAN_EMULATION_RANAP |
| 956 | var RANAP_N_UNITDATA_ind rud_ind; |
| 957 | var RANAP_N_CONNECT_ind rconn_ind; |
| 958 | var RANAP_N_CONNECT_cfm rconn_cfm; |
| 959 | var RANAP_N_DATA_ind rdata_ind; |
| 960 | var RANAP_N_DISCONNECT_ind rdisc_ind; |
| 961 | var RANAP_Conn_Req creq; |
| 962 | var RANAP_PDU ranap; |
| 963 | var RAN_ConnHdlr vc_conn; |
Harald Welte | 717c730 | 2019-04-23 20:31:55 +0200 | [diff] [blame] | 964 | var PDU_DTAP_PS_MO ps_mo; |
| 965 | var PDU_DTAP_PS_MT ps_mt; |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 966 | |
| 967 | /* SCCP -> Client: UNIT-DATA (connectionless SCCP) from a BSC */ |
| 968 | [] RANAP.receive(RANAP_N_UNITDATA_ind:?) -> value rud_ind { |
| 969 | /* Connectionless Procedures like RESET */ |
| 970 | var template RANAP_PDU resp; |
| 971 | resp := CommonRanapUnitdataCallback(rud_ind.userData); |
| 972 | if (isvalue(resp)) { |
| 973 | RANAP.send(ts_RANAP_UNITDATA_req(rud_ind.callingAddress, |
| 974 | rud_ind.calledAddress, resp)); |
| 975 | } |
| 976 | } |
| 977 | /* SCCP -> Client: new connection from BSC */ |
| 978 | [] RANAP.receive(RANAP_N_CONNECT_ind:?) -> value rconn_ind { |
| 979 | vc_conn := g_ran_ops.ranap_create_cb.apply(rconn_ind, g_ran_id); |
| 980 | /* store mapping between client components and SCCP connectionId */ |
| 981 | f_conn_table_add(vc_conn, rconn_ind.connectionId); |
| 982 | /* handle user payload */ |
| 983 | f_handle_userData_RANAP(vc_conn, rconn_ind.userData); |
| 984 | /* confirm connection establishment */ |
| 985 | RANAP.send(ts_RANAP_CONNECT_res(rconn_ind.connectionId, omit)); |
| 986 | } |
| 987 | /* SCCP -> Client: connection-oriented data in existing connection */ |
| 988 | [] RANAP.receive(RANAP_N_DATA_ind:?) -> value rdata_ind { |
| 989 | vc_conn := f_comp_by_conn_id(rdata_ind.connectionId); |
| 990 | if (ispresent(rdata_ind.userData)) { |
| 991 | f_handle_userData_RANAP(vc_conn, rdata_ind.userData); |
| 992 | } |
| 993 | } |
| 994 | /* SCCP -> Client: disconnect of an existing connection */ |
| 995 | [] RANAP.receive(RANAP_N_DISCONNECT_ind:?) -> value rdisc_ind { |
| 996 | vc_conn := f_comp_by_conn_id(rdisc_ind.connectionId); |
| 997 | if (ispresent(rdisc_ind.userData)) { |
| 998 | f_handle_userData_RANAP(vc_conn, rdisc_ind.userData); |
| 999 | } |
| 1000 | /* notify client about termination */ |
| 1001 | var RAN_Conn_Prim prim := MSC_CONN_PRIM_DISC_IND; |
| 1002 | CLIENT.send(prim) to vc_conn; |
| 1003 | f_conn_table_del(rdisc_ind.connectionId); |
| 1004 | /* TOOD: return confirm to other side? */ |
| 1005 | } |
| 1006 | /* SCCP -> Client: connection confirm for outbound connection */ |
| 1007 | [] RANAP.receive(RANAP_N_CONNECT_cfm:?) -> value rconn_cfm { |
| 1008 | vc_conn := f_comp_by_conn_id(rconn_cfm.connectionId); |
| 1009 | var RAN_Conn_Prim prim := MSC_CONN_PRIM_CONF_IND; |
| 1010 | CLIENT.send(prim) to vc_conn; |
| 1011 | /* handle user payload */ |
| 1012 | if (ispresent(rconn_cfm.userData)) { |
| 1013 | f_handle_userData_RANAP(vc_conn, rconn_cfm.userData); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | [] CLIENT.receive(RANAP_PDU:?) -> value ranap sender vc_conn { |
| 1018 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
| 1019 | /* send it to dispatcher */ |
| 1020 | RANAP.send(ts_RANAP_DATA_req(conn_id, ranap)); |
| 1021 | } |
| 1022 | |
| 1023 | /* Disconnect request client -> SCCP */ |
| 1024 | [] CLIENT.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_REQ) -> sender vc_conn { |
| 1025 | var integer conn_id := f_conn_id_by_comp(vc_conn); |
| 1026 | RANAP.send(ts_RANAP_DISC_req(conn_id, 0)); |
| 1027 | f_conn_table_del(conn_id); |
| 1028 | } |
| 1029 | |
| 1030 | /* BSSAP from client -> SCCP */ |
| 1031 | [] CLIENT.receive(RANAP_Conn_Req:?) -> value creq sender vc_conn { |
| 1032 | var integer conn_id; |
| 1033 | /* send to dispatcher */ |
| 1034 | |
| 1035 | if (f_comp_known(vc_conn) == false) { |
| 1036 | /* unknown client, create new connection */ |
| 1037 | conn_id := f_gen_conn_id(); |
| 1038 | |
| 1039 | /* store mapping between client components and SCCP connectionId */ |
| 1040 | f_conn_table_add(vc_conn, conn_id); |
| 1041 | |
| 1042 | RANAP.send(ts_RANAP_CONNECT_req(creq.addr_peer, creq.addr_own, conn_id, |
| 1043 | creq.ranap)); |
| 1044 | } else { |
| 1045 | /* known client, send via existing connection */ |
| 1046 | conn_id := f_conn_id_by_comp(vc_conn); |
| 1047 | RANAP.send(ts_RANAP_DATA_req(conn_id, creq.ranap)); |
| 1048 | } |
| 1049 | |
| 1050 | /* InitialL3 contains RR (PAG RESP) or MM (CM SRV REQ), we must increment |
| 1051 | * counter only on MM/CC/SS, but not on RR */ |
| 1052 | if (g_ran_ops.role_ms and not f_ranap_l3_is_rr(creq.ranap)) { |
| 1053 | /* we have just sent the first MM message, increment the counter */ |
| 1054 | var integer idx := f_idx_by_comp(vc_conn); |
| 1055 | ConnectionTable[idx].n_sd[0] := 1; |
| 1056 | log("patch: N(SD) for ConnIdx ", idx, " set to 1"); |
| 1057 | } |
| 1058 | } |
| 1059 | |
Harald Welte | 717c730 | 2019-04-23 20:31:55 +0200 | [diff] [blame] | 1060 | [g_ran_ops.role_ms] CLIENT.receive(PDU_DTAP_PS_MO:?) -> value ps_mo sender vc_conn { |
| 1061 | var integer idx := f_idx_by_comp(vc_conn); |
| 1062 | /* convert from decoded DTAP to encoded DTAP */ |
| 1063 | var octetstring l3_enc := enc_PDU_L3_MS_SGSN(ps_mo.dtap); |
| 1064 | /* patch correct L3 send sequence number N(SD) into l3_enc */ |
| 1065 | if (ps_mo.skip_seq_patching == false) { |
| 1066 | //f_ML3_patch_seq(ConnectionTable[idx], ps_mo.dtap, l3_enc); |
| 1067 | } |
| 1068 | f_xmit_raw_l3(ConnectionTable[idx].sccp_conn_id, ps_mo.dlci, l3_enc); |
| 1069 | } |
| 1070 | |
| 1071 | [not g_ran_ops.role_ms] CLIENT.receive(PDU_DTAP_PS_MT:?) -> value ps_mt sender vc_conn { |
| 1072 | var integer idx := f_idx_by_comp(vc_conn); |
| 1073 | /* convert from decoded DTAP to encoded DTAP */ |
| 1074 | var octetstring l3_enc := enc_PDU_L3_SGSN_MS(ps_mt.dtap); |
| 1075 | f_xmit_raw_l3(ConnectionTable[idx].sccp_conn_id, ps_mt.dlci, l3_enc); |
| 1076 | } |
| 1077 | |
| 1078 | |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 1079 | #else |
| 1080 | [false] CLIENT.receive {} |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 1081 | #endif |
| 1082 | } |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 1083 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 1084 | private altstep as_main_mgcp() runs on RAN_Emulation_CT { |
| 1085 | #ifdef RAN_EMULATION_MGCP |
| 1086 | var MgcpCommand mgcp_req; |
| 1087 | var MgcpResponse mgcp_resp; |
| 1088 | var RAN_ConnHdlr vc_conn; |
Harald Welte | 0b47606 | 2018-01-21 19:07:32 +0100 | [diff] [blame] | 1089 | |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 1090 | /* Handling of MGCP in IPA SCCPLite case. This predates 3GPP AoIP |
| 1091 | * and uses a MGCP session in parallel to BSSAP. BSSAP uses CIC |
| 1092 | * as usual, and MGCP uses "CIC@mgw" endpoint naming, where CIC |
| 1093 | * is printed as hex string, e.g. a@mgw for CIC 10 */ |
| 1094 | |
| 1095 | /* CLIENT -> MGCP */ |
| 1096 | [] CLIENT.receive(MgcpCommand:?) -> value mgcp_req sender vc_conn { |
| 1097 | /* MGCP request from Handler (we're MSC) */ |
| 1098 | /* store the transaction ID we've seen */ |
| 1099 | f_comp_store_mgcp_tid(vc_conn, mgcp_req.line.trans_id); |
| 1100 | /* simply forward any MGCP from the client to the port */ |
| 1101 | MGCP.send(mgcp_req); |
| 1102 | } |
| 1103 | [] CLIENT.receive(MgcpResponse:?) -> value mgcp_resp sender vc_conn { |
| 1104 | /* MGCP response from Handler (we're BSC/MGW) */ |
| 1105 | /* simply forward any MGCP from the client to the port */ |
| 1106 | MGCP.send(mgcp_resp); |
| 1107 | } |
| 1108 | |
| 1109 | /* MGCP -> CLIENT */ |
| 1110 | [] MGCP.receive(MgcpCommand:?) -> value mgcp_req { |
| 1111 | /* MGCP request from network side (we're BSC/MGW) */ |
| 1112 | /* Extract CIC from local part of endpoint name */ |
| 1113 | var integer cic := f_mgcp_ep_extract_cic(mgcp_req.line.ep); |
Harald Welte | e98bb2e | 2017-11-29 12:09:48 +0100 | [diff] [blame] | 1114 | if (match(mgcp_req, tr_RSIP) and f_cic_known(cic) == false) { |
| 1115 | /* ignore RSIP for unknown CIC */ |
| 1116 | } else { |
| 1117 | /* Resolve the vc_conn by the CIC */ |
| 1118 | vc_conn := f_comp_by_cic(cic); |
| 1119 | CLIENT.send(mgcp_req) to vc_conn; |
| 1120 | } |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 1121 | } |
| 1122 | [] MGCP.receive(MgcpResponse:?) -> value mgcp_resp { |
| 1123 | /* MGCP response from network side (we're MSC) */ |
| 1124 | /* Resolve the vc_conn by the transaction ID */ |
| 1125 | vc_conn := f_comp_by_mgcp_tid(mgcp_resp.line.trans_id); |
| 1126 | CLIENT.send(mgcp_resp) to vc_conn; |
| 1127 | } |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 1128 | #else |
| 1129 | [false] CLIENT.receive {} |
| 1130 | #endif |
| 1131 | } |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 1132 | |
Pau Espin Pedrol | 4d0e5e5 | 2019-06-07 19:38:28 +0200 | [diff] [blame] | 1133 | private altstep as_main_ctrl() runs on RAN_Emulation_CT { |
| 1134 | #ifdef RAN_EMULATION_CTRL |
| 1135 | var CtrlMessage ctrl; |
| 1136 | var RAN_ConnHdlr vc_conn; |
| 1137 | var ASP_IPA_Event evt; |
| 1138 | |
| 1139 | /* Handling of CTRL in IPA SCCPLite case. This predates 3GPP AoIP |
| 1140 | * and uses a CTRL session in parallel to BSSAP. */ |
| 1141 | |
| 1142 | /* CTRL_CLIENT -> CTRL */ |
| 1143 | [] CTRL_CLIENT.receive(CtrlMessage:?) -> value ctrl sender vc_conn { |
| 1144 | CTRL.send(ctrl); |
| 1145 | } |
| 1146 | |
| 1147 | /* CTRL -> CTRL_CLIENT */ |
| 1148 | [] CTRL.receive(CtrlMessage:?) -> value ctrl { |
| 1149 | CTRL_CLIENT.send(ctrl); |
| 1150 | } |
| 1151 | |
| 1152 | [] CTRL.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP}) -> value evt { |
| 1153 | CTRL_CLIENT.send(evt); |
| 1154 | } |
| 1155 | [] CTRL.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_DOWN}) { |
| 1156 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Lost IPA connection!"); |
| 1157 | } |
| 1158 | [] CTRL.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {} |
| 1159 | #else |
| 1160 | [false] CLIENT.receive {} |
| 1161 | #endif |
| 1162 | } |
| 1163 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 1164 | /* send a raw (encoded) L3 message over given SCCP connection */ |
| 1165 | private function f_xmit_raw_l3(integer sccp_conn_id, OCT1 dlci, octetstring l3_enc) runs on RAN_Emulation_CT |
| 1166 | { |
| 1167 | select (g_ran_ops.protocol) { |
| 1168 | #ifdef RAN_EMULATION_BSSAP |
| 1169 | case (RAN_PROTOCOL_BSSAP) { |
| 1170 | var PDU_BSSAP bssap; |
| 1171 | bssap := valueof(ts_BSSAP_DTAP(l3_enc, dlci)); |
| 1172 | BSSAP.send(ts_BSSAP_DATA_req(sccp_conn_id, bssap)); |
| 1173 | } |
| 1174 | #endif |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 1175 | #ifdef RAN_EMULATION_RANAP |
| 1176 | case (RAN_PROTOCOL_RANAP) { |
Vadim Yanitskiy | f2c3fa9 | 2019-06-20 05:18:15 +0700 | [diff] [blame] | 1177 | var template (omit) RANAP_IEs.SAPI sapi := omit; |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 1178 | var RANAP_PDU ranap; |
Vadim Yanitskiy | f2c3fa9 | 2019-06-20 05:18:15 +0700 | [diff] [blame] | 1179 | |
| 1180 | /* Perform DLCI -> SAPI transformation (x & 0x07) */ |
| 1181 | if (dlci and4b '07'O == '03'O) { |
| 1182 | sapi := sapi_3; |
| 1183 | } |
| 1184 | |
| 1185 | ranap := valueof(ts_RANAP_DirectTransfer(l3_enc, sapi := sapi)); |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 1186 | RANAP.send(ts_RANAP_DATA_req(sccp_conn_id, ranap)); |
| 1187 | } |
| 1188 | #endif |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 1189 | } |
| 1190 | } |
| 1191 | |
| 1192 | function main(RanOps ops, charstring id) runs on RAN_Emulation_CT { |
| 1193 | |
| 1194 | g_ran_id := id; |
| 1195 | g_ran_ops := ops; |
| 1196 | f_conn_table_init(); |
| 1197 | f_expect_table_init(); |
| 1198 | |
| 1199 | if (isvalue(ops.sccp_addr_peer) and isvalue(ops.sccp_addr_local)) { |
| 1200 | f_sleep(1.0); /* HACK to wait for M3UA/ASP to be ACTIVE */ |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 1201 | select (g_ran_ops.protocol) { |
| 1202 | #ifdef RAN_EMULATION_BSSAP |
| 1203 | case (RAN_PROTOCOL_BSSAP) { |
| 1204 | f_bssap_reset(ops.sccp_addr_peer, ops.sccp_addr_local); |
| 1205 | } |
| 1206 | #endif |
| 1207 | #ifdef RAN_EMULATION_RANAP |
| 1208 | case (RAN_PROTOCOL_RANAP) { |
| 1209 | f_ranap_reset(ops.sccp_addr_peer, ops.sccp_addr_local); |
| 1210 | } |
| 1211 | #endif |
| 1212 | } |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | while (true) { |
| 1216 | var RAN_ConnHdlr vc_conn; |
| 1217 | var PDU_DTAP_MO dtap_mo; |
| 1218 | var PDU_DTAP_MT dtap_mt; |
| 1219 | var RAN_ConnHdlr vc_hdlr; |
| 1220 | var octetstring l3_info; |
| 1221 | var hexstring imsi; |
| 1222 | var OCT4 tmsi; |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1223 | var integer targetPointCode; |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 1224 | |
| 1225 | alt { |
| 1226 | [g_ran_ops.protocol == RAN_PROTOCOL_BSSAP] as_main_bssap(); |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 1227 | [g_ran_ops.protocol == RAN_PROTOCOL_RANAP] as_main_ranap(); |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 1228 | |
| 1229 | [g_ran_ops.role_ms] CLIENT.receive(PDU_DTAP_MO:?) -> value dtap_mo sender vc_conn { |
| 1230 | var integer idx := f_idx_by_comp(vc_conn); |
| 1231 | /* convert from decoded DTAP to encoded DTAP */ |
| 1232 | var octetstring l3_enc := enc_PDU_ML3_MS_NW(dtap_mo.dtap); |
| 1233 | /* patch correct L3 send sequence number N(SD) into l3_enc */ |
| 1234 | if (dtap_mo.skip_seq_patching == false) { |
| 1235 | f_ML3_patch_seq(ConnectionTable[idx], dtap_mo.dtap, l3_enc); |
| 1236 | } |
| 1237 | f_xmit_raw_l3(ConnectionTable[idx].sccp_conn_id, dtap_mo.dlci, l3_enc); |
| 1238 | } |
| 1239 | |
| 1240 | [not g_ran_ops.role_ms] CLIENT.receive(PDU_DTAP_MT:?) -> value dtap_mt sender vc_conn { |
| 1241 | var integer idx := f_idx_by_comp(vc_conn); |
| 1242 | /* convert from decoded DTAP to encoded DTAP */ |
| 1243 | var octetstring l3_enc := enc_PDU_ML3_NW_MS(dtap_mt.dtap); |
| 1244 | f_xmit_raw_l3(ConnectionTable[idx].sccp_conn_id, dtap_mt.dlci, l3_enc); |
| 1245 | } |
| 1246 | |
| 1247 | [] as_main_mgcp(); |
Pau Espin Pedrol | 4d0e5e5 | 2019-06-07 19:38:28 +0200 | [diff] [blame] | 1248 | [] as_main_ctrl(); |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1249 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1250 | [] PROC.getcall(RAN_register:{?,?}) -> param(l3_info, vc_hdlr) { |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1251 | f_create_expect(l3_info, vc_hdlr); |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1252 | PROC.reply(RAN_register:{l3_info, vc_hdlr}) to vc_hdlr; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1253 | } |
| 1254 | |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1255 | [] PROC.getcall(RAN_register_handoverRequest:{?,?}) -> param(targetPointCode, vc_hdlr) { |
| 1256 | f_create_expect(omit, vc_hdlr, targetPointCode); |
| 1257 | PROC.reply(RAN_register_handoverRequest:{targetPointCode, vc_hdlr}) to vc_hdlr; |
| 1258 | } |
| 1259 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1260 | [] PROC.getcall(RAN_register_imsi:{?,?,?}) -> param(imsi, tmsi, vc_hdlr) { |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 1261 | f_create_imsi(imsi, tmsi, vc_hdlr); |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1262 | PROC.reply(RAN_register_imsi:{imsi, tmsi, vc_hdlr}) to vc_hdlr; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 1270 | #ifdef RAN_EMULATION_MGCP |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 1271 | private function f_mgcp_ep_extract_cic(charstring inp) return integer { |
Harald Welte | 525a9c1 | 2017-11-24 23:40:41 +0100 | [diff] [blame] | 1272 | var charstring local_part := regexp(inp, "(*)@*", 0); |
Harald Welte | c82eef4 | 2017-11-24 20:40:12 +0100 | [diff] [blame] | 1273 | return hex2int(str2hex(local_part)); |
| 1274 | |
| 1275 | } |
Harald Welte | 2fce788 | 2019-04-15 11:48:05 +0200 | [diff] [blame] | 1276 | #endif |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 1277 | |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1278 | /*********************************************************************** |
| 1279 | * "Expect" Handling (mapping for expected incoming SCCP connections) |
| 1280 | ***********************************************************************/ |
| 1281 | |
| 1282 | /* data about an expected future incoming connection */ |
| 1283 | type record ExpectData { |
| 1284 | /* L3 payload based on which we can match it */ |
| 1285 | octetstring l3_payload optional, |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1286 | integer handoverRequestPointCode optional, |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1287 | /* component reference for this connection */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1288 | RAN_ConnHdlr vc_conn |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | /* procedure based port to register for incoming connections */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1292 | signature RAN_register(in octetstring l3, in RAN_ConnHdlr hdlr); |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1293 | signature RAN_register_handoverRequest(in integer targetPointCode, in RAN_ConnHdlr hdlr); |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1294 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 1295 | /* procedure based port to register for incoming IMSI/TMSI */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1296 | 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] | 1297 | |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1298 | /* If DTAP happens across other channels (e.g. GSUP), provide manual advancing of the n_sd sequence number */ |
| 1299 | signature RAN_last_n_sd(in RAN_ConnHdlr hdlr, out N_Sd_Array last_n_sd); |
| 1300 | |
| 1301 | /* Update conn's n_sd sequence nr after the connection was taken over from elsewhere */ |
| 1302 | signature RAN_continue_after_n_sd(N_Sd_Array last_n_sd, in RAN_ConnHdlr hdlr); |
| 1303 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1304 | type port RAN_PROC_PT procedure { |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1305 | inout RAN_register, RAN_register_imsi, RAN_register_handoverRequest, RAN_last_n_sd, RAN_continue_after_n_sd; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1306 | } with { extension "internal" }; |
| 1307 | |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 1308 | #ifdef RAN_EMULATION_BSSAP |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1309 | /* CreateCallback that can be used as create_cb and will use the expectation table */ |
| 1310 | function ExpectedCreateCallback(BSSAP_N_CONNECT_ind conn_ind, charstring id) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1311 | runs on RAN_Emulation_CT return RAN_ConnHdlr { |
| 1312 | var RAN_ConnHdlr ret := null; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1313 | var octetstring l3_info; |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1314 | var boolean handoverRequest := false; |
| 1315 | var integer handoverRequestPointCode; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1316 | var integer i; |
| 1317 | |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1318 | if (ischosen(conn_ind.userData.pdu.bssmap.completeLayer3Information)) { |
| 1319 | l3_info := conn_ind.userData.pdu.bssmap.completeLayer3Information.layer3Information.layer3info; |
| 1320 | log("ExpectedCreateCallback completeLayer3Information"); |
| 1321 | } else if (ischosen(conn_ind.userData.pdu.bssmap.handoverRequest)) { |
| 1322 | handoverRequest := true; |
| 1323 | handoverRequestPointCode := bit2int(conn_ind.calledAddress.signPointCode); |
| 1324 | log("ExpectedCreateCallback handoverRequest ", handoverRequestPointCode); |
| 1325 | } else { |
| 1326 | setverdict(fail, "N-CONNECT.ind with L3 != COMPLETE L3 nor a Handover Request"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 1327 | mtc.stop; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1328 | return ret; |
| 1329 | } |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1330 | |
| 1331 | for (i := 0; i < sizeof(ExpectTable); i:= i+1) { |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1332 | if (handoverRequest) { |
| 1333 | log("ExpectTable[", i, "].handoverRequestPointCode = ", ExpectTable[i].handoverRequestPointCode, |
| 1334 | " ==? ", handoverRequestPointCode); |
| 1335 | if (ExpectTable[i].handoverRequestPointCode == handoverRequestPointCode) { |
| 1336 | ret := ExpectTable[i].vc_conn; |
| 1337 | log("Found Expect[", i, "] for handoverRequest handled at ", ret); |
| 1338 | return ret; |
| 1339 | } else { |
| 1340 | continue; |
| 1341 | } |
| 1342 | } |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1343 | if (not ispresent(ExpectTable[i].l3_payload)) { |
| 1344 | continue; |
| 1345 | } |
| 1346 | if (l3_info == ExpectTable[i].l3_payload) { |
| 1347 | ret := ExpectTable[i].vc_conn; |
| 1348 | /* release this entry to be used again */ |
| 1349 | ExpectTable[i].l3_payload := omit; |
| 1350 | ExpectTable[i].vc_conn := null; |
| 1351 | log("Found Expect[", i, "] for ", l3_info, " handled at ", ret); |
| 1352 | /* return the component reference */ |
| 1353 | return ret; |
| 1354 | } |
| 1355 | } |
| 1356 | setverdict(fail, "Couldn't find Expect for incoming connection ", conn_ind); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 1357 | mtc.stop; |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1358 | return ret; |
| 1359 | } |
Harald Welte | 5b02762 | 2019-04-14 23:40:17 +0200 | [diff] [blame] | 1360 | #endif |
| 1361 | |
| 1362 | #ifdef RAN_EMULATION_RANAP |
| 1363 | /* CreateCallback that can be used as create_cb and will use the expectation table */ |
| 1364 | function RanapExpectedCreateCallback(RANAP_N_CONNECT_ind conn_ind, charstring id) |
| 1365 | runs on RAN_Emulation_CT return RAN_ConnHdlr { |
| 1366 | var RAN_ConnHdlr ret := null; |
| 1367 | var template (omit) octetstring l3_info; |
| 1368 | var integer i; |
| 1369 | |
| 1370 | l3_info := f_ranap_extract_l3(conn_ind.userData); |
| 1371 | if (istemplatekind(l3_info, "omit")) { |
| 1372 | setverdict(fail, "N-CONNECT.ind without NAS payload"); |
| 1373 | mtc.stop; |
| 1374 | return ret; |
| 1375 | } |
| 1376 | |
| 1377 | for (i := 0; i < sizeof(ExpectTable); i:= i+1) { |
| 1378 | if (not ispresent(ExpectTable[i].l3_payload)) { |
| 1379 | continue; |
| 1380 | } |
| 1381 | if (valueof(l3_info) == ExpectTable[i].l3_payload) { |
| 1382 | ret := ExpectTable[i].vc_conn; |
| 1383 | /* release this entry to be used again */ |
| 1384 | ExpectTable[i].l3_payload := omit; |
| 1385 | ExpectTable[i].vc_conn := null; |
| 1386 | log("Found Expect[", i, "] for ", l3_info, " handled at ", ret); |
| 1387 | /* return the component reference */ |
| 1388 | return ret; |
| 1389 | } |
| 1390 | } |
| 1391 | setverdict(fail, "Couldn't find Expect for incoming connection ", conn_ind); |
| 1392 | mtc.stop; |
| 1393 | return ret; |
| 1394 | } |
| 1395 | #endif |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1396 | |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1397 | private function f_create_expect(template octetstring l3, RAN_ConnHdlr hdlr, |
| 1398 | template integer handoverRequestPointCode := omit) |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1399 | runs on RAN_Emulation_CT { |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1400 | var integer i; |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1401 | log("f_create_expect(l3 := ", l3, ", handoverRequest := ", handoverRequestPointCode); |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1402 | for (i := 0; i < sizeof(ExpectTable); i := i+1) { |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1403 | if (not ispresent(ExpectTable[i].l3_payload) |
| 1404 | and not ispresent(ExpectTable[i].handoverRequestPointCode)) { |
| 1405 | if (ispresent(l3)) { |
| 1406 | ExpectTable[i].l3_payload := valueof(l3); |
| 1407 | } |
| 1408 | if (ispresent(handoverRequestPointCode)) { |
| 1409 | ExpectTable[i].handoverRequestPointCode := valueof(handoverRequestPointCode); |
| 1410 | } |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1411 | ExpectTable[i].vc_conn := hdlr; |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1412 | if (ispresent(handoverRequestPointCode)) { |
| 1413 | log("Created Expect[", i, "] for handoverRequest to be handled at ", hdlr); |
| 1414 | } else { |
| 1415 | log("Created Expect[", i, "] for ", l3, " to be handled at ", hdlr); |
| 1416 | } |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1417 | return; |
| 1418 | } |
| 1419 | } |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 1420 | testcase.stop("No space left in ExpectTable"); |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1421 | } |
| 1422 | |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1423 | private function f_create_imsi(hexstring imsi, OCT4 tmsi, RAN_ConnHdlr hdlr) |
| 1424 | runs on RAN_Emulation_CT { |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 1425 | for (var integer i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 1426 | if (not ispresent(ImsiTable[i].imsi)) { |
| 1427 | ImsiTable[i].imsi := imsi; |
| 1428 | ImsiTable[i].tmsi := tmsi; |
| 1429 | ImsiTable[i].comp_ref := hdlr; |
| 1430 | log("Created IMSI[", i, "] for ", imsi, tmsi, " to be handled at ", hdlr); |
| 1431 | return; |
| 1432 | } |
| 1433 | } |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 1434 | testcase.stop("No space left in ImsiTable"); |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | |
Daniel Willmann | d47106b | 2018-01-17 12:20:56 +0100 | [diff] [blame] | 1438 | private function f_expect_table_init() |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1439 | runs on RAN_Emulation_CT { |
Daniel Willmann | d47106b | 2018-01-17 12:20:56 +0100 | [diff] [blame] | 1440 | for (var integer i := 0; i < sizeof(ExpectTable); i := i+1) { |
| 1441 | ExpectTable[i].l3_payload := omit; |
Neels Hofmeyr | 0ac6315 | 2019-05-07 01:20:17 +0200 | [diff] [blame] | 1442 | ExpectTable[i].handoverRequestPointCode := omit; |
Daniel Willmann | d47106b | 2018-01-17 12:20:56 +0100 | [diff] [blame] | 1443 | } |
| 1444 | } |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 1445 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 1446 | /* helper function for clients to register their IMSI/TMSI */ |
Harald Welte | 6811d10 | 2019-04-14 22:23:14 +0200 | [diff] [blame] | 1447 | function f_ran_register_imsi(hexstring imsi, OCT4 tmsi) |
| 1448 | runs on RAN_ConnHdlr { |
| 1449 | BSSAP_PROC.call(RAN_register_imsi:{imsi, tmsi, self}) { |
| 1450 | [] BSSAP_PROC.getreply(RAN_register_imsi:{?,?,?}) {}; |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 1451 | } |
| 1452 | } |
| 1453 | |
Harald Welte | 475a2c1 | 2019-05-02 19:05:48 +0200 | [diff] [blame] | 1454 | #ifdef RAN_EMULATION_RANAP |
| 1455 | /* expect a IuReleaseCommand; Confirm that; expect SCCP-level N-DISCONNET.ind */ |
| 1456 | altstep as_iu_release_compl_disc(float t := 5.0) runs on RAN_ConnHdlr { |
| 1457 | var RANAP_PDU ranap; |
| 1458 | [] BSSAP.receive(tr_RANAP_IuReleaseCommand(?)) { |
| 1459 | BSSAP.send(ts_RANAP_IuReleaseComplete); |
| 1460 | alt { |
| 1461 | [] BSSAP.receive(RAN_Conn_Prim:MSC_CONN_PRIM_DISC_IND) { |
| 1462 | setverdict(pass); |
| 1463 | } |
| 1464 | [] BSSAP.receive { |
| 1465 | setverdict(fail, "Unexpected RANAP while waiting for SCCP Release "); |
| 1466 | mtc.stop; |
| 1467 | } |
| 1468 | } |
| 1469 | } |
| 1470 | [] BSSAP.receive(RANAP_PDU:?) -> value ranap{ |
| 1471 | setverdict(fail, "Unexpected RANAP while waiting for IuReleaseCommand", ranap); |
| 1472 | mtc.stop; |
| 1473 | } |
| 1474 | } |
| 1475 | #endif |
| 1476 | |
Harald Welte | 17d2115 | 2018-01-27 00:47:11 +0100 | [diff] [blame] | 1477 | |
Harald Welte | 365f4ed | 2017-11-23 00:00:43 +0100 | [diff] [blame] | 1478 | } |