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