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