Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 1 | module RSL_Emulation { |
| 2 | |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 3 | /* RSL Emulation, runs on top of IPA_Emulation. It multiplexes/demultiplexes |
| 4 | * the individual connections (logical channels), so there can be separate TTCN-3 components |
| 5 | * handling each of the connections. |
| 6 | * |
| 7 | * The RSL_Emulation.main() function processes RSL messages from the IPA demultiplex |
| 8 | * stack via the IPA_RSL_PT, and dispatches them to the per-connection components. |
| 9 | * |
| 10 | * Outbound RSL connections are initiated by sending a RSLDC_ChanRqd primitive |
| 11 | * to the component running the RSL_Emulation.main() function. |
| 12 | * |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 13 | * in case we're emulating the BTS-side of RSL: We have no clue as to which particular logical |
| 14 | * channel the BSC may decide to activate at which point, so we have to blindly acknowledge all |
| 15 | * channel activations. Still, a test case might be interested in the exact assignment message to |
| 16 | * determine the type of activation, encryption, codec flags etc. at some later point, when it's |
| 17 | * clear for which transaction this activation happened. We keep this in the LastChanAct table. |
| 18 | * |
| 19 | * (C) 2017-2018 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 20 | * All rights reserved. |
| 21 | * |
| 22 | * Released under the terms of GNU General Public License, Version 2 or |
| 23 | * (at your option) any later version. |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 24 | * |
| 25 | * SPDX-License-Identifier: GPL-2.0-or-later |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 26 | */ |
| 27 | |
Pau Espin Pedrol | a07cfd9 | 2018-10-22 15:54:41 +0200 | [diff] [blame] | 28 | import from Misc_Helpers all; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 29 | import from General_Types all; |
| 30 | import from Osmocom_Types all; |
| 31 | import from GSM_Types all; |
| 32 | import from GSM_RR_Types all; |
| 33 | import from RSL_Types all; |
| 34 | import from IPA_Types all; |
| 35 | import from IPA_Emulation all; |
| 36 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 37 | /* General "base class" component definition, of which specific implementations |
| 38 | * derive themselves by means of the "extends" feature */ |
| 39 | type component RSL_DchanHdlr { |
| 40 | /* port facing up towards dedicated channel handler */ |
| 41 | port RSL_DCHAN_PT RSL; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 42 | port RSLEM_PROC_PT RSL_PROC; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 43 | var RslChannelNr g_chan_nr; |
Harald Welte | 421e4d4 | 2018-02-12 20:04:50 +0100 | [diff] [blame] | 44 | /* second BTS / DChan during hand-over */ |
| 45 | port RSL_DCHAN_PT RSL1; |
| 46 | port RSLEM_PROC_PT RSL1_PROC; |
Neels Hofmeyr | 9140101 | 2019-07-11 00:42:35 +0200 | [diff] [blame] | 47 | port RSL_DCHAN_PT RSL2; |
| 48 | port RSLEM_PROC_PT RSL2_PROC; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | type record RSLDC_ChanRqd { |
| 52 | OCT1 ra, |
Pau Espin Pedrol | 6451b04 | 2018-10-24 20:36:16 +0200 | [diff] [blame] | 53 | GsmFrameNumber fn optional |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 54 | }; |
| 55 | |
Pau Espin Pedrol | 6451b04 | 2018-10-24 20:36:16 +0200 | [diff] [blame] | 56 | template (value) RSLDC_ChanRqd ts_RSLDC_ChanRqd(OCT1 ra, GsmFrameNumber fn) := { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 57 | ra := ra, |
| 58 | fn := fn |
| 59 | } |
| 60 | |
Pau Espin Pedrol | 6451b04 | 2018-10-24 20:36:16 +0200 | [diff] [blame] | 61 | template (value) RSLDC_ChanRqd ts_RSLDC_ChanRqd_anyFN(OCT1 ra) := { |
| 62 | ra := ra, |
| 63 | fn := omit |
| 64 | } |
| 65 | |
Vadim Yanitskiy | 6de2fcb | 2020-05-25 19:40:45 +0700 | [diff] [blame] | 66 | type enumerated RSLEm_EventType { |
| 67 | RSLEM_EV_TRX_UP, |
| 68 | RSLEM_EV_TRX_DOWN |
| 69 | }; |
| 70 | |
| 71 | type record RSLEm_Event { |
| 72 | RSLEm_EventType ev_type, |
| 73 | IpaStreamId sid |
| 74 | }; |
| 75 | |
| 76 | template (value) RSLEm_Event ts_RSLEm_EV(RSLEm_EventType ev_type, |
| 77 | IpaStreamId sid) := { |
| 78 | ev_type := ev_type, |
| 79 | sid := sid |
| 80 | }; |
| 81 | template RSLEm_Event tr_RSLEm_EV(template RSLEm_EventType ev_type, |
| 82 | template IpaStreamId sid := ?) := { |
| 83 | ev_type := ev_type, |
| 84 | sid := sid |
| 85 | }; |
| 86 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 87 | type port RSL_DCHAN_PT message { |
Neels Hofmeyr | 1470fc6 | 2021-05-25 21:35:46 +0000 | [diff] [blame] | 88 | inout RSLDC_ChanRqd, RSL_Message, ASP_RSL_Unitdata; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 89 | } with { extension "internal" }; |
| 90 | |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 91 | type port RSL_CCHAN_PT message { |
Vadim Yanitskiy | 6de2fcb | 2020-05-25 19:40:45 +0700 | [diff] [blame] | 92 | inout ASP_RSL_Unitdata, RSLEm_Event; |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 93 | } with { extension "internal" }; |
| 94 | |
| 95 | |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 96 | signature RSLEM_register(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr hdlr); |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 97 | signature RSLEM_unregister(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr hdlr); |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 98 | signature RSLEM_suspend(boolean suspend); |
Vadim Yanitskiy | e9c0635 | 2020-06-20 01:30:58 +0700 | [diff] [blame] | 99 | signature RSLEM_wait_queue(boolean enable); |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 100 | signature RSLEM_get_last_act(in uint8_t trx_nr, in RslChannelNr chan_nr, out RSL_Message chan_act); |
Neels Hofmeyr | ad26fc0 | 2021-09-28 18:30:17 +0200 | [diff] [blame] | 101 | signature RSLEM_set_auto_chan_act_ack(boolean enable); |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 102 | |
| 103 | type port RSLEM_PROC_PT procedure { |
Vadim Yanitskiy | e9c0635 | 2020-06-20 01:30:58 +0700 | [diff] [blame] | 104 | inout RSLEM_register, RSLEM_unregister, |
| 105 | RSLEM_suspend, RSLEM_wait_queue, |
Neels Hofmeyr | ad26fc0 | 2021-09-28 18:30:17 +0200 | [diff] [blame] | 106 | RSLEM_get_last_act, |
| 107 | RSLEM_set_auto_chan_act_ack; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 108 | } with { extension "internal" }; |
| 109 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 110 | /*********************************************************************** |
| 111 | * Client Component for a single dedicated channel |
| 112 | ***********************************************************************/ |
| 113 | |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 114 | private function f_rx_or_fail(template RSL_Message exp_rx, RSL_DCHAN_PT rsl_pt := RSL) runs on RSL_DchanHdlr return RSL_Message |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 115 | { |
| 116 | var RSL_Message rx_rsl; |
| 117 | timer T := 10.0; |
| 118 | |
| 119 | /* request a channel to be established */ |
| 120 | T.start; |
| 121 | alt { |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 122 | [] rsl_pt.receive(exp_rx) -> value rx_rsl { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 123 | T.stop; |
| 124 | return rx_rsl; |
| 125 | } |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 126 | [] rsl_pt.receive { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 127 | setverdict(fail, "Unexpected RSL message on DCHAN"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 128 | mtc.stop; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 129 | } |
| 130 | [] T.timeout { |
| 131 | setverdict(fail, "Timeout waiting for RSL on DCHAN"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 132 | mtc.stop; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | /* never reached */ |
| 136 | return rx_rsl; |
| 137 | } |
| 138 | |
Neels Hofmeyr | 596393a | 2021-10-02 13:01:04 +0200 | [diff] [blame] | 139 | function f_chan_act_verify_tsc(RSL_Message chan_act, template uint3_t tsc) { |
| 140 | var RSL_IE_Body ie; |
| 141 | if (f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, ie)) { |
| 142 | var uint3_t got_tsc := ie.chan_ident.ch_desc.v.tsc; |
| 143 | if (not match(got_tsc, tsc)) { |
| 144 | setverdict(fail, "RSL CHANnel ACTIVation: unexpected TSC in Channel Description: expected ", |
| 145 | tsc, " got ", got_tsc); |
| 146 | mtc.stop; |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 151 | /* establish a dedicated channel using 'ra' */ |
Neels Hofmeyr | b5b7a6e | 2021-06-04 19:03:45 +0200 | [diff] [blame] | 152 | function f_chan_est(OCT1 ra, octetstring est_l3, template RslLinkId link_id, GsmFrameNumber fn := 23, |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 153 | template uint3_t tsc := ?, RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC) |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 154 | runs on RSL_DchanHdlr { |
| 155 | var RSL_Message rx_rsl; |
| 156 | var GsmRrMessage rr; |
| 157 | |
| 158 | /* request a channel to be established */ |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 159 | rsl_pt.send(ts_RSLDC_ChanRqd(ra, fn)); |
Neels Hofmeyr | b5b7a6e | 2021-06-04 19:03:45 +0200 | [diff] [blame] | 160 | /* At this point the BSC sends a CHAN ACTIV which we always ACK. Checking it below. */ |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 161 | /* expect immediate assignment */ |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 162 | rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN, rsl_pt := rsl_pt); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 163 | rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload); |
Neels Hofmeyr | b5b7a6e | 2021-06-04 19:03:45 +0200 | [diff] [blame] | 164 | if (not match(rr.payload.imm_ass.chan_desc.tsc, tsc)) { |
| 165 | setverdict(fail, "Immediate Assignment: unexpected TSC in Channel Description: expected ", tsc, " got ", |
| 166 | rr.payload.imm_ass.chan_desc.tsc); |
| 167 | mtc.stop; |
| 168 | } |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 169 | g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr; |
Neels Hofmeyr | 3222e0e | 2021-07-20 22:25:38 +0200 | [diff] [blame] | 170 | rsl_pt.send(ts_RSL_EST_IND(g_chan_nr, valueof(link_id), est_l3)); |
Neels Hofmeyr | b5b7a6e | 2021-06-04 19:03:45 +0200 | [diff] [blame] | 171 | |
| 172 | /* Check above CHAN ACTIV */ |
Neels Hofmeyr | 596393a | 2021-10-02 13:01:04 +0200 | [diff] [blame] | 173 | f_chan_act_verify_tsc(f_rslem_get_last_act(rsl_proc_pt, 0, g_chan_nr), tsc); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | function f_deact_chan(RSL_Cause cause) runs on RSL_DchanHdlr |
| 177 | { |
| 178 | var RSL_Message rx_rsl; |
| 179 | |
| 180 | RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, cause)); |
| 181 | rx_rsl := f_rx_or_fail(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL)); |
| 182 | /* FIXME RSL.send(ts_RSL_RF_CHAN_REL_ACK()) */ |
| 183 | } |
| 184 | |
| 185 | |
| 186 | |
| 187 | /*********************************************************************** |
| 188 | * Main Component |
| 189 | ***********************************************************************/ |
| 190 | |
| 191 | private type record ConnectionData { |
| 192 | /* component reference to the client component */ |
| 193 | RSL_DchanHdlr comp_ref, |
| 194 | /* RSL (dedicated) Channel number we're handling */ |
| 195 | uint8_t trx_nr optional, |
| 196 | IpaStreamId stream_id optional, |
| 197 | RslChannelNr chan_nr optional, |
| 198 | /* Random Reference */ |
| 199 | OCT1 ra optional, |
| 200 | GsmFrameNumber ra_fn optional |
| 201 | }; |
| 202 | |
| 203 | private function f_cid_by_comp_ref(RSL_DchanHdlr comp_ref) |
| 204 | runs on RSL_Emulation_CT return integer { |
| 205 | var integer i; |
| 206 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
Pau Espin Pedrol | 7096509 | 2020-06-23 14:29:56 +0200 | [diff] [blame] | 207 | if (ispresent(ConnectionTable[i].comp_ref) and |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 208 | ConnectionTable[i].comp_ref == comp_ref) { |
| 209 | return i; |
| 210 | } |
| 211 | } |
Vadim Yanitskiy | f79d936 | 2020-06-03 04:06:18 +0700 | [diff] [blame] | 212 | log("No Dchan handler for comp_ref=", comp_ref); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 213 | return -1; |
| 214 | } |
| 215 | |
| 216 | private function f_cid_by_chan_nr(uint8_t trx_nr, RslChannelNr chan_nr) |
| 217 | runs on RSL_Emulation_CT return integer { |
| 218 | var integer i; |
| 219 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
Pau Espin Pedrol | 7096509 | 2020-06-23 14:29:56 +0200 | [diff] [blame] | 220 | if (ispresent(ConnectionTable[i].chan_nr) and |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 221 | ConnectionTable[i].chan_nr == chan_nr and ConnectionTable[i].trx_nr == trx_nr) { |
| 222 | return i; |
| 223 | } |
| 224 | } |
Vadim Yanitskiy | f79d936 | 2020-06-03 04:06:18 +0700 | [diff] [blame] | 225 | log("No Dchan handler for trx_nr=", trx_nr, " and chan_nr=", chan_nr); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 226 | return -1; |
| 227 | } |
| 228 | |
| 229 | private function f_cid_by_ra_fn(OCT1 ra, GsmFrameNumber fn) |
| 230 | runs on RSL_Emulation_CT return integer { |
| 231 | var integer i; |
| 232 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 233 | if (ispresent(ConnectionTable[i].ra) and |
| 234 | ConnectionTable[i].ra == ra and ConnectionTable[i].ra_fn == fn) { |
| 235 | return i; |
| 236 | } |
| 237 | } |
Vadim Yanitskiy | f79d936 | 2020-06-03 04:06:18 +0700 | [diff] [blame] | 238 | log("No Dchan handler for ra=", ra, " and fn=", fn); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 239 | return -1; |
| 240 | } |
| 241 | |
Pau Espin Pedrol | 6451b04 | 2018-10-24 20:36:16 +0200 | [diff] [blame] | 242 | /* Matches by only RA if FN is ommited in one of the connections allocated */ |
| 243 | private function f_cid_by_ra_fn2(OCT1 ra, RSL_IE_FrameNumber fn) |
| 244 | runs on RSL_Emulation_CT return integer { |
| 245 | var integer i; |
| 246 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 247 | if (ispresent(ConnectionTable[i].ra) and |
| 248 | ConnectionTable[i].ra == ra) { |
| 249 | if (not ispresent(ConnectionTable[i].ra_fn) or |
| 250 | fn == valueof(ts_RSL_IE_FrameNumber(ConnectionTable[i].ra_fn))) { |
| 251 | return i; |
| 252 | } |
| 253 | } |
| 254 | } |
Vadim Yanitskiy | f79d936 | 2020-06-03 04:06:18 +0700 | [diff] [blame] | 255 | log("No Dchan handler for ra=", ra, " and fn=", fn); |
Pau Espin Pedrol | 6451b04 | 2018-10-24 20:36:16 +0200 | [diff] [blame] | 256 | return -1; |
| 257 | } |
| 258 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 259 | /* create an ew client with given RA and FN */ |
Pau Espin Pedrol | 6451b04 | 2018-10-24 20:36:16 +0200 | [diff] [blame] | 260 | private function f_cid_create(OCT1 ra, template (omit) GsmFrameNumber fn, RSL_DchanHdlr comp_ref) |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 261 | runs on RSL_Emulation_CT { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 262 | var integer i; |
| 263 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 264 | if (not ispresent(ConnectionTable[i].ra) and |
| 265 | not ispresent(ConnectionTable[i].trx_nr)) { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 266 | ConnectionTable[i].ra := ra; |
Pau Espin Pedrol | 6451b04 | 2018-10-24 20:36:16 +0200 | [diff] [blame] | 267 | if (ispresent(fn)) { |
| 268 | ConnectionTable[i].ra_fn := valueof(fn); |
| 269 | } else { |
| 270 | ConnectionTable[i].ra_fn := omit; |
| 271 | } |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 272 | ConnectionTable[i].comp_ref := comp_ref; |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 273 | return; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 274 | } |
| 275 | } |
Daniel Willmann | 8273fb9 | 2018-07-05 17:31:20 +0200 | [diff] [blame] | 276 | testcase.stop("No free entry in conn table for ", ra, fn); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 277 | } |
| 278 | |
Vadim Yanitskiy | efc9413 | 2020-05-24 04:26:45 +0700 | [diff] [blame] | 279 | /* create a new client with given RA and FN */ |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 280 | private function f_cid_create_cnr(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr comp_ref) |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 281 | runs on RSL_Emulation_CT { |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 282 | var integer i; |
| 283 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 284 | if (not ispresent(ConnectionTable[i].ra) and |
| 285 | not ispresent(ConnectionTable[i].trx_nr)) { |
| 286 | ConnectionTable[i].stream_id := f_streamId_by_trx(trx_nr); |
| 287 | ConnectionTable[i].trx_nr := trx_nr; |
| 288 | ConnectionTable[i].chan_nr := chan_nr; |
| 289 | ConnectionTable[i].comp_ref := comp_ref; |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 290 | return; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 291 | } |
| 292 | } |
Daniel Willmann | 8273fb9 | 2018-07-05 17:31:20 +0200 | [diff] [blame] | 293 | testcase.stop("No free entry in conn table for ", trx_nr, chan_nr, comp_ref); |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | |
Vadim Yanitskiy | efc9413 | 2020-05-24 04:26:45 +0700 | [diff] [blame] | 297 | /* delete client with given RA and FN */ |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 298 | private function f_cid_delete_cnr(IpaStreamId stream_id, RslChannelNr chan_nr, RSL_DchanHdlr comp_ref) |
| 299 | runs on RSL_Emulation_CT return integer { |
| 300 | var integer i; |
| 301 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 302 | if (ConnectionTable[i].comp_ref == null) { |
| 303 | continue; |
| 304 | } |
| 305 | if (ConnectionTable[i].stream_id == stream_id and |
| 306 | ConnectionTable[i].chan_nr == chan_nr and |
| 307 | ConnectionTable[i].comp_ref == comp_ref) { |
| 308 | f_cid_clear(i); |
| 309 | } |
| 310 | } |
| 311 | log("Unable to find entry to delete for ", stream_id, chan_nr, comp_ref); |
| 312 | return -1; |
| 313 | } |
| 314 | |
| 315 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 316 | private function f_cid_clear(integer cid) |
| 317 | runs on RSL_Emulation_CT { |
| 318 | ConnectionTable[cid].ra := omit; |
| 319 | ConnectionTable[cid].ra_fn := omit; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 320 | ConnectionTable[cid].trx_nr := omit; |
| 321 | ConnectionTable[cid].stream_id := omit; |
| 322 | ConnectionTable[cid].chan_nr := omit; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 323 | ConnectionTable[cid].comp_ref := null; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 326 | /* last activation for a given channel number */ |
| 327 | type record LastActData { |
| 328 | uint8_t trx_nr optional, |
| 329 | RslChannelNr chan_nr optional, |
| 330 | RSL_Message chan_act optional |
| 331 | } |
| 332 | |
| 333 | private function f_store_last_act_data(uint8_t trx_nr, RslChannelNr chan_nr, RSL_Message chan_act) |
| 334 | runs on RSL_Emulation_CT { |
| 335 | for (var integer i := 0; i < sizeof(LastActTable); i := i+1) { |
| 336 | if (not ispresent(LastActTable[i].chan_nr) or |
| 337 | (LastActTable[i].chan_nr == chan_nr and LastActTable[i].trx_nr == trx_nr)) { |
| 338 | LastActTable[i].trx_nr := trx_nr; |
| 339 | LastActTable[i].chan_nr := chan_nr; |
| 340 | LastActTable[i].chan_act := chan_act; |
| 341 | return; |
| 342 | } |
| 343 | } |
Daniel Willmann | 8273fb9 | 2018-07-05 17:31:20 +0200 | [diff] [blame] | 344 | testcase.stop("No space left in LastActTable to store chan_act for ", chan_nr); |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | private function f_lookup_last_act(uint8_t trx_nr, RslChannelNr chan_nr) |
| 348 | runs on RSL_Emulation_CT return RSL_Message { |
| 349 | for (var integer i := 0; i < sizeof(LastActTable); i := i+1) { |
| 350 | if (ispresent(LastActTable[i].chan_nr) and LastActTable[i].chan_nr == chan_nr |
| 351 | and LastActTable[i].trx_nr == trx_nr) { |
| 352 | return LastActTable[i].chan_act; |
| 353 | } |
| 354 | } |
Daniel Willmann | 8273fb9 | 2018-07-05 17:31:20 +0200 | [diff] [blame] | 355 | testcase.stop("No LastActTable entry found for TRX ", trx_nr, " ", chan_nr); |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | private function f_last_act_table_init() runs on RSL_Emulation_CT { |
| 359 | for (var integer i := 0; i < sizeof(LastActTable); i := i+1) { |
| 360 | LastActTable[i] := { omit, omit, omit }; |
| 361 | } |
| 362 | } |
| 363 | |
Vadim Yanitskiy | 6de2fcb | 2020-05-25 19:40:45 +0700 | [diff] [blame] | 364 | private function f_trx_conn_map_init() |
| 365 | runs on RSL_Emulation_CT { |
| 366 | for (var integer i := 0; i < sizeof(TrxConnMap); i := i + 1) { |
| 367 | TrxConnMap[i] := -1; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | private function f_trx_conn_map_register(integer conn_id, in IpaCcmIdResp id_resp) |
| 372 | runs on RSL_Emulation_CT return IpaStreamId { |
| 373 | var template charstring unit_id_fmt := pattern "(\d+)/(\d+)/(\d+)"; |
| 374 | var charstring unit_id; |
| 375 | var integer trx_nr; |
| 376 | var integer idx; |
| 377 | |
| 378 | /* Check if we have room for a new connection */ |
| 379 | if (TrxConnNum >= sizeof(TrxConnMap)) { |
| 380 | testcase.stop("We cannot handle more than ", sizeof(TrxConnMap), " transceivers"); |
| 381 | } |
| 382 | |
| 383 | /* Find IPAC_IDTAG_UNITID in the IPA IDENTITY RESPONSE */ |
| 384 | idx := f_ipa_id_resp_find_ie(id_resp, IPAC_IDTAG_UNITID); |
| 385 | if (idx < 0) { |
| 386 | testcase.stop("IPA IDENTITY RESPONSE contains no unit-id"); |
| 387 | } |
| 388 | |
| 389 | /* Make sure that IPA unit-id is valid */ |
| 390 | unit_id := oct2char(id_resp[idx].data); |
| 391 | if (not match(unit_id, unit_id_fmt)) { |
| 392 | testcase.stop("IPA unit-id has unknown/unexpected format"); |
| 393 | } |
| 394 | |
| 395 | /* Parse transceiver number (site/bts/trx). |
| 396 | * TODO: implement and use declaratice types. */ |
| 397 | unit_id := regexp(unit_id, unit_id_fmt, 2); |
| 398 | trx_nr := str2int(unit_id); |
| 399 | |
| 400 | if (trx_nr >= sizeof(TrxConnMap)) { |
| 401 | testcase.stop("Transceiver #", trx_nr, " does not fit"); |
| 402 | } else if (TrxConnMap[trx_nr] != -1) { |
| 403 | testcase.stop("Transceiver #", trx_nr, " is already connected?!?"); |
| 404 | } |
| 405 | |
| 406 | /* Finally, store the connection ID */ |
| 407 | log("Mapped TRX#", trx_nr, " to TCP/IP conn_id=", conn_id); |
| 408 | TrxConnMap[trx_nr] := conn_id; |
| 409 | TrxConnNum := TrxConnNum + 1; |
| 410 | |
| 411 | return f_streamId_by_trx(trx_nr); |
| 412 | } |
| 413 | |
Pau Espin Pedrol | abcdf78 | 2020-06-23 14:29:24 +0200 | [diff] [blame] | 414 | private function f_trx_conn_map_unregister(integer conn_id) |
| 415 | runs on RSL_Emulation_CT return IpaStreamId { |
| 416 | |
| 417 | for (var integer i := 0; i < sizeof(TrxConnMap); i := i + 1) { |
| 418 | if (conn_id == TrxConnMap[i]) { |
| 419 | TrxConnMap[i] := -1; |
| 420 | TrxConnNum := TrxConnNum - 1; |
| 421 | return f_streamId_by_trx(i); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | testcase.stop("Trying to unregister an unknown conn_id=", conn_id); |
| 426 | } |
| 427 | |
Vadim Yanitskiy | 6de2fcb | 2020-05-25 19:40:45 +0700 | [diff] [blame] | 428 | private function f_trx_conn_map_resolve(IpaStreamId id) |
| 429 | runs on RSL_Emulation_CT return integer { |
| 430 | var integer trx_nr := f_trx_by_streamId(id); |
| 431 | |
| 432 | if (TrxConnMap[trx_nr] == -1) { |
| 433 | testcase.stop("Transceiver #", trx_nr, " is not connected"); |
| 434 | } |
| 435 | |
| 436 | return TrxConnMap[trx_nr]; |
| 437 | } |
| 438 | |
Vadim Yanitskiy | e9c0635 | 2020-06-20 01:30:58 +0700 | [diff] [blame] | 439 | private type record of ASP_RSL_Unitdata ASP_RSL_UDList; |
| 440 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 441 | type component RSL_Emulation_CT { |
| 442 | /* port facing down towards IPA emulation */ |
| 443 | port IPA_RSL_PT IPA_PT; |
| 444 | /* port facing up towards dedicated channel handler */ |
| 445 | port RSL_DCHAN_PT CLIENT_PT; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 446 | port RSLEM_PROC_PT RSL_PROC; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 447 | |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 448 | /* port for Common Channel / TRX Management */ |
| 449 | port RSL_CCHAN_PT CCHAN_PT; |
| 450 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 451 | /* state of all concurrent connections / dedicated channels */ |
| 452 | var ConnectionData ConnectionTable[64]; |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 453 | |
Vadim Yanitskiy | e9c0635 | 2020-06-20 01:30:58 +0700 | [diff] [blame] | 454 | /* RSL messages for which no handler is currently registered */ |
| 455 | var ASP_RSL_UDList WaitingQueue := { }; |
| 456 | |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 457 | /* last RSL CHAN ACT for each chan_nr */ |
| 458 | var LastActData LastActTable[64]; |
Vadim Yanitskiy | 6de2fcb | 2020-05-25 19:40:45 +0700 | [diff] [blame] | 459 | |
| 460 | /* IPA stream ID -> TCP/IP connection ID mapping for transceivers */ |
| 461 | var integer TrxConnNum := 0; /* number of connected transceivers */ |
| 462 | var integer TrxConnMap[4]; /* up to 4 transceivers for now */ |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 466 | private function f_trx_by_streamId(IpaStreamId id) return integer { |
| 467 | return enum2int(id); |
| 468 | } |
| 469 | |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 470 | private function f_streamId_by_trx(uint8_t trx_nr) return IpaStreamId { |
| 471 | select (trx_nr) { |
| 472 | case (0) { return IPAC_PROTO_RSL_TRX0; } |
| 473 | case (1) { return IPAC_PROTO_RSL_TRX1; } |
| 474 | case (2) { return IPAC_PROTO_RSL_TRX2; } |
| 475 | case (3) { return IPAC_PROTO_RSL_TRX3; } |
| 476 | } |
Daniel Willmann | a6ea2ef | 2018-07-24 09:55:52 +0200 | [diff] [blame] | 477 | setverdict(fail, "Unknown stream ID ", trx_nr); |
| 478 | mtc.stop; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 479 | } |
| 480 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 481 | |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 482 | function main(boolean bts_role := true) runs on RSL_Emulation_CT { |
Harald Welte | bb6aed3 | 2018-02-21 12:19:18 +0100 | [diff] [blame] | 483 | var ASP_IPA_Event evt; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 484 | var ASP_RSL_Unitdata rx_rsl; |
| 485 | var RSL_Message rx_rsl_msg; |
| 486 | var RSLDC_ChanRqd chan_rqd; |
| 487 | var RSL_DchanHdlr vc_conn; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 488 | var RslChannelNr chan_nr; |
| 489 | var uint8_t trx_nr; |
Vadim Yanitskiy | 6de2fcb | 2020-05-25 19:40:45 +0700 | [diff] [blame] | 490 | var integer conn_id; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 491 | var integer cid; |
| 492 | var integer i; |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 493 | /* special synchronization handling during hand-over */ |
| 494 | var boolean dchan_suspended := false; |
Vadim Yanitskiy | e9c0635 | 2020-06-20 01:30:58 +0700 | [diff] [blame] | 495 | /* Whether to keep RSL messages, for which no handler is found in ConnectionTable, |
| 496 | * in a queue. These messages will remain in the queue until the appropriate |
| 497 | * connection handler is registered. */ |
| 498 | var boolean wait_queue_enabled := false; |
Neels Hofmeyr | ad26fc0 | 2021-09-28 18:30:17 +0200 | [diff] [blame] | 499 | var boolean auto_chan_act_ack := true; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 500 | |
Daniel Willmann | 17f970f | 2018-01-17 12:03:19 +0100 | [diff] [blame] | 501 | f_conn_table_init(); |
Vadim Yanitskiy | 6de2fcb | 2020-05-25 19:40:45 +0700 | [diff] [blame] | 502 | f_trx_conn_map_init(); |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 503 | f_last_act_table_init(); |
Daniel Willmann | 17f970f | 2018-01-17 12:03:19 +0100 | [diff] [blame] | 504 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 505 | while (true) { |
| 506 | alt { |
Vadim Yanitskiy | a2afacc | 2020-05-18 21:16:19 +0700 | [diff] [blame] | 507 | [bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_UP)) { |
Harald Welte | bb6aed3 | 2018-02-21 12:19:18 +0100 | [diff] [blame] | 508 | } |
Vadim Yanitskiy | a2afacc | 2020-05-18 21:16:19 +0700 | [diff] [blame] | 509 | [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_UP)) -> value evt { |
Vadim Yanitskiy | 6de2fcb | 2020-05-25 19:40:45 +0700 | [diff] [blame] | 510 | log("A new IPA/RSL connection has been established (conn_id=", |
| 511 | evt.conn_id, "), waiting for IDENTITY RESPONSE..."); |
| 512 | } |
| 513 | [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_RESP)) -> value evt { |
| 514 | log("Got IDENTITY RESPONSE (conn_id=", evt.conn_id, "): ", evt.id_resp); |
| 515 | /* Update [ IPA stream ID -> TCP/IP connection ID ] mapping */ |
| 516 | var IpaStreamId sid := f_trx_conn_map_register(evt.conn_id, evt.id_resp); |
| 517 | /* Notify the upper layers about a new connection */ |
| 518 | CCHAN_PT.send(ts_RSLEm_EV(RSLEM_EV_TRX_UP, sid)); |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 519 | } |
Pau Espin Pedrol | abcdf78 | 2020-06-23 14:29:24 +0200 | [diff] [blame] | 520 | [bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) -> value evt { |
| 521 | log("Lost IPA connection! (conn_id=", evt.conn_id, "): ", evt.id_resp); |
| 522 | /* Notify the upper layers about lost connection */ |
| 523 | var IpaStreamId sid := f_trx_conn_map_unregister(evt.conn_id); |
| 524 | CCHAN_PT.send(ts_RSLEm_EV(RSLEM_EV_TRX_DOWN, sid)); |
Pau Espin Pedrol | a07cfd9 | 2018-10-22 15:54:41 +0200 | [diff] [blame] | 525 | } |
Pau Espin Pedrol | abcdf78 | 2020-06-23 14:29:24 +0200 | [diff] [blame] | 526 | [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) -> value evt { |
| 527 | log("Lost IPA connection! (conn_id=", evt.conn_id, ")"); |
| 528 | /* Notify the upper layers about lost connection */ |
| 529 | var IpaStreamId sid := f_trx_conn_map_unregister(evt.conn_id); |
| 530 | CCHAN_PT.send(ts_RSLEm_EV(RSLEM_EV_TRX_DOWN, sid)); |
Pau Espin Pedrol | a07cfd9 | 2018-10-22 15:54:41 +0200 | [diff] [blame] | 531 | } |
Vadim Yanitskiy | a2afacc | 2020-05-18 21:16:19 +0700 | [diff] [blame] | 532 | [bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) { |
Vadim Yanitskiy | 9b4e356 | 2020-05-25 21:40:52 +0700 | [diff] [blame] | 533 | IPA_PT.send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23))); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 534 | } |
Vadim Yanitskiy | a2afacc | 2020-05-18 21:16:19 +0700 | [diff] [blame] | 535 | [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) { } |
Vadim Yanitskiy | a60e5cf | 2020-05-26 01:46:31 +0700 | [diff] [blame] | 536 | [bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN, sid := ?)) -> value rx_rsl { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 537 | var GsmRrMessage rr; |
| 538 | var OCT1 ra; |
| 539 | var GsmFrameNumber fn; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 540 | rr := dec_GsmRrMessage(rx_rsl.rsl.ies[1].body.full_imm_ass_info.payload); |
| 541 | if (ischosen(rr.payload.imm_ass)) { |
| 542 | ra := bit2oct(rr.payload.imm_ass.req_ref.ra); |
| 543 | fn := 23; //FIXME(rr.payload.imm_ass); |
| 544 | /* lookup client based on RA+time, deliver to client */ |
| 545 | cid := f_cid_by_ra_fn(ra, fn); |
| 546 | if (cid == -1) { |
| 547 | setverdict(fail, "IMM ASS for unknown DChan"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 548 | mtc.stop; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 549 | } |
| 550 | /* update client with trx_nr */ |
| 551 | ConnectionTable[cid].trx_nr := f_trx_by_streamId(rx_rsl.streamId); |
| 552 | ConnectionTable[cid].stream_id := rx_rsl.streamId; |
| 553 | /* update client with chan_nr */ |
| 554 | ConnectionTable[cid].chan_nr := rr.payload.imm_ass.chan_desc.chan_nr; |
| 555 | /* TODO: add timer to time-out ConnectionTable entries which |
| 556 | * never get followed-up to */ |
| 557 | CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref; |
| 558 | } else if (ischosen(rr.payload.imm_ass_rej)) { |
| 559 | for (i := 0; i < sizeof(rr.payload.imm_ass_rej.payload); i := i + 1) { |
| 560 | ra := bit2oct(rr.payload.imm_ass_rej.payload[i].req_ref.ra); |
| 561 | fn := 23; //FIXME(); |
| 562 | /* lookup client based on RA+time, deliver to client */ |
| 563 | cid := f_cid_by_ra_fn(ra, fn); |
| 564 | if (cid != -1) { |
| 565 | CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref; |
| 566 | /* delete ClientTable entry, as it failed */ |
| 567 | f_cid_clear(cid); |
| 568 | } |
| 569 | } |
| 570 | } |
| 571 | } |
Vadim Yanitskiy | a60e5cf | 2020-05-26 01:46:31 +0700 | [diff] [blame] | 572 | [not bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?), sid := ?)) -> value rx_rsl { |
Pau Espin Pedrol | 6451b04 | 2018-10-24 20:36:16 +0200 | [diff] [blame] | 573 | var RSL_IE_RequestRef req_ref; |
| 574 | req_ref := rx_rsl.rsl.ies[1].body.req_ref; |
| 575 | cid := f_cid_by_ra_fn2(req_ref.ra, req_ref.frame_nr); |
| 576 | if (cid != -1) { |
| 577 | CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref; |
| 578 | f_cid_clear(cid); |
| 579 | } else { |
| 580 | CCHAN_PT.send(rx_rsl); |
| 581 | } |
| 582 | } |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 583 | |
Vadim Yanitskiy | a60e5cf | 2020-05-26 01:46:31 +0700 | [diff] [blame] | 584 | [bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?, ?), sid := ?)) -> value rx_rsl { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 585 | /* broadcast to all clients? */ |
| 586 | for (i := 0; i < sizeof(ConnectionTable); i := i + 1) { |
Neels Hofmeyr | d7eabd6 | 2020-06-08 22:30:54 +0200 | [diff] [blame] | 587 | if (ispresent(ConnectionTable[i].comp_ref) and ConnectionTable[i].comp_ref != null) { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 588 | CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[i].comp_ref; |
| 589 | } |
| 590 | } |
| 591 | } |
| 592 | |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 593 | /* Forward common channel management to the special port for it */ |
Vadim Yanitskiy | a60e5cf | 2020-05-26 01:46:31 +0700 | [diff] [blame] | 594 | [] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeT(?), sid := ?)) -> value rx_rsl { |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 595 | CCHAN_PT.send(rx_rsl); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 596 | } |
| 597 | |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 598 | /* Forward common channel management to the special port for it */ |
Vadim Yanitskiy | a60e5cf | 2020-05-26 01:46:31 +0700 | [diff] [blame] | 599 | [] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeC(?), sid := ?)) -> value rx_rsl { |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 600 | CCHAN_PT.send(rx_rsl); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 601 | } |
| 602 | |
Neels Hofmeyr | ad26fc0 | 2021-09-28 18:30:17 +0200 | [diff] [blame] | 603 | /* Channel Activation: store in LastActTable, possibly ACK. */ |
Vadim Yanitskiy | a60e5cf | 2020-05-26 01:46:31 +0700 | [diff] [blame] | 604 | [bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV), sid := ?)) -> value rx_rsl { |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 605 | chan_nr := rx_rsl.rsl.ies[0].body.chan_nr; |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 606 | trx_nr := f_trx_by_streamId(rx_rsl.streamId); |
| 607 | f_store_last_act_data(trx_nr, chan_nr, rx_rsl.rsl); |
Neels Hofmeyr | ad26fc0 | 2021-09-28 18:30:17 +0200 | [diff] [blame] | 608 | if (auto_chan_act_ack) { |
| 609 | /* blindly acknowledge all channel activations */ |
| 610 | IPA_PT.send(ts_ASP_RSL_UD(ts_RSL_CHAN_ACT_ACK(chan_nr, 23), rx_rsl.streamId)); |
| 611 | } else { |
| 612 | CLIENT_PT.send(rx_rsl); |
| 613 | } |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 614 | } |
| 615 | |
Vadim Yanitskiy | a60e5cf | 2020-05-26 01:46:31 +0700 | [diff] [blame] | 616 | [not dchan_suspended] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeDR(?), sid := ?)) -> value rx_rsl { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 617 | /* dispatch to channel based on ChanId */ |
| 618 | cid := f_cid_by_chan_nr(f_trx_by_streamId(rx_rsl.streamId), |
| 619 | rx_rsl.rsl.ies[0].body.chan_nr); |
| 620 | if (cid != -1) { |
| 621 | CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref; |
Vadim Yanitskiy | e9c0635 | 2020-06-20 01:30:58 +0700 | [diff] [blame] | 622 | } else if (wait_queue_enabled) { |
| 623 | log("Storing an RSL message in the waiting queue"); |
| 624 | WaitingQueue := WaitingQueue & { rx_rsl }; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 625 | } else { |
Neels Hofmeyr | c0ef35c | 2021-07-22 16:22:25 +0200 | [diff] [blame] | 626 | log("Error: RSL for unknown Dchan (streamId ", rx_rsl.streamId, ", chan_nr ", |
| 627 | rx_rsl.rsl.ies[0].body.chan_nr, "): ", rx_rsl); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 628 | setverdict(fail, "RSL for unknown Dchan"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 629 | mtc.stop; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 633 | [not dchan_suspended] IPA_PT.receive { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 634 | setverdict(fail, "Received unknown primitive from IPA"); |
Daniel Willmann | e4ff537 | 2018-07-05 17:35:03 +0200 | [diff] [blame] | 635 | mtc.stop; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 636 | } |
| 637 | |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 638 | [bts_role] CLIENT_PT.receive(RSLDC_ChanRqd:?) -> value chan_rqd sender vc_conn { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 639 | /* Store the knowledge that this sender has requested a certain RQ+time */ |
| 640 | f_cid_create(chan_rqd.ra, chan_rqd.fn, vc_conn); |
Vadim Yanitskiy | 9b4e356 | 2020-05-25 21:40:52 +0700 | [diff] [blame] | 641 | IPA_PT.send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD(chan_rqd.ra, chan_rqd.fn))); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 642 | } |
| 643 | |
Pau Espin Pedrol | 6451b04 | 2018-10-24 20:36:16 +0200 | [diff] [blame] | 644 | [not bts_role] CLIENT_PT.receive(RSLDC_ChanRqd:?) -> value chan_rqd sender vc_conn { |
| 645 | /* Store the knowledge that this sender has requested a certain RQ+time */ |
| 646 | f_cid_create(chan_rqd.ra, chan_rqd.fn, vc_conn); |
| 647 | } |
| 648 | |
Vadim Yanitskiy | 6de2fcb | 2020-05-25 19:40:45 +0700 | [diff] [blame] | 649 | /* RSL message from a component that runs on RSL_DchanHdlr */ |
| 650 | [bts_role] CLIENT_PT.receive(tr_RSL_MsgType(?)) -> value rx_rsl_msg sender vc_conn { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 651 | cid := f_cid_by_comp_ref(vc_conn); |
Vadim Yanitskiy | 9b4e356 | 2020-05-25 21:40:52 +0700 | [diff] [blame] | 652 | IPA_PT.send(ts_ASP_RSL_UD(rx_rsl_msg, ConnectionTable[cid].stream_id)); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 653 | } |
Neels Hofmeyr | 1470fc6 | 2021-05-25 21:35:46 +0000 | [diff] [blame] | 654 | [bts_role] CLIENT_PT.receive(tr_ASP_RSL_UD(?, sid := ?)) -> value rx_rsl { |
| 655 | IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.rsl, rx_rsl.streamId)); |
| 656 | } |
Vadim Yanitskiy | 6de2fcb | 2020-05-25 19:40:45 +0700 | [diff] [blame] | 657 | [not bts_role] CLIENT_PT.receive(tr_RSL_MsgType(?)) -> value rx_rsl_msg sender vc_conn { |
| 658 | cid := f_cid_by_comp_ref(vc_conn); |
| 659 | conn_id := f_trx_conn_map_resolve(ConnectionTable[cid].stream_id); |
| 660 | IPA_PT.send(ts_ASP_RSL_UD(rx_rsl_msg, ConnectionTable[cid].stream_id, conn_id)); |
| 661 | } |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 662 | |
Vadim Yanitskiy | 6de2fcb | 2020-05-25 19:40:45 +0700 | [diff] [blame] | 663 | /* RSL message from MTC */ |
| 664 | [bts_role] CCHAN_PT.receive(tr_ASP_RSL_UD(?, sid := ?)) -> value rx_rsl { |
Vadim Yanitskiy | 9b4e356 | 2020-05-25 21:40:52 +0700 | [diff] [blame] | 665 | IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.rsl, rx_rsl.streamId)); |
Harald Welte | 34252c5 | 2018-02-24 04:51:50 +0100 | [diff] [blame] | 666 | } |
Vadim Yanitskiy | 6de2fcb | 2020-05-25 19:40:45 +0700 | [diff] [blame] | 667 | [not bts_role] CCHAN_PT.receive(tr_ASP_RSL_UD(?, sid := ?)) -> value rx_rsl { |
| 668 | conn_id := f_trx_conn_map_resolve(rx_rsl.streamId); |
| 669 | IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.rsl, rx_rsl.streamId, conn_id)); |
| 670 | } |
Harald Welte | 34252c5 | 2018-02-24 04:51:50 +0100 | [diff] [blame] | 671 | |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 672 | /* explicit registration, e.g. in (non-immediate) assignment case */ |
| 673 | [] RSL_PROC.getcall(RSLEM_register:{?,?,?}) -> param(trx_nr, chan_nr, vc_conn) { |
| 674 | f_cid_create_cnr(trx_nr, chan_nr, vc_conn); |
Harald Welte | e32ad99 | 2018-05-31 22:17:46 +0200 | [diff] [blame] | 675 | RSL_PROC.reply(RSLEM_register:{trx_nr, chan_nr, vc_conn}) to vc_conn; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 676 | } |
| 677 | |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 678 | [] RSL_PROC.getcall(RSLEM_unregister:{?,?,?}) -> param(trx_nr, chan_nr, vc_conn) { |
| 679 | cid := f_cid_by_chan_nr(trx_nr, chan_nr); |
| 680 | f_cid_clear(cid); |
Harald Welte | e32ad99 | 2018-05-31 22:17:46 +0200 | [diff] [blame] | 681 | RSL_PROC.reply(RSLEM_unregister:{trx_nr, chan_nr, vc_conn}) to vc_conn; |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 682 | } |
| 683 | |
Harald Welte | e32ad99 | 2018-05-31 22:17:46 +0200 | [diff] [blame] | 684 | [] RSL_PROC.getcall(RSLEM_suspend:{true}) -> sender vc_conn { |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 685 | log("Suspending DChan"); |
| 686 | dchan_suspended := true; |
Harald Welte | e32ad99 | 2018-05-31 22:17:46 +0200 | [diff] [blame] | 687 | RSL_PROC.reply(RSLEM_suspend:{true}) to vc_conn; |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 688 | } |
| 689 | |
Harald Welte | e32ad99 | 2018-05-31 22:17:46 +0200 | [diff] [blame] | 690 | [] RSL_PROC.getcall(RSLEM_suspend:{false}) -> sender vc_conn { |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 691 | log("Resuming DChan"); |
| 692 | dchan_suspended := false; |
Harald Welte | e32ad99 | 2018-05-31 22:17:46 +0200 | [diff] [blame] | 693 | RSL_PROC.reply(RSLEM_suspend:{false}) to vc_conn; |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 694 | } |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 695 | |
Vadim Yanitskiy | e9c0635 | 2020-06-20 01:30:58 +0700 | [diff] [blame] | 696 | [not wait_queue_enabled] RSL_PROC.getcall(RSLEM_wait_queue:{true}) -> sender vc_conn { |
| 697 | wait_queue_enabled := true; |
| 698 | log("Enabled queueing of DChan messages"); |
| 699 | RSL_PROC.reply(RSLEM_wait_queue:{wait_queue_enabled}) to vc_conn; |
| 700 | } |
| 701 | |
| 702 | [wait_queue_enabled] RSL_PROC.getcall(RSLEM_wait_queue:{false}) -> sender vc_conn { |
| 703 | /* Dispatch stalled messages (if any) */ |
| 704 | f_WaitingQueue_dispatch(); |
| 705 | |
| 706 | wait_queue_enabled := false; |
| 707 | log("Disabled queueing of DChan messages"); |
| 708 | RSL_PROC.reply(RSLEM_wait_queue:{wait_queue_enabled}) to vc_conn; |
| 709 | } |
| 710 | |
| 711 | [] RSL_PROC.getcall(RSLEM_wait_queue:{?}) -> sender vc_conn { |
| 712 | log("Queueing of DChan messages is already enabled/disabled"); |
| 713 | RSL_PROC.reply(RSLEM_wait_queue:{wait_queue_enabled}) to vc_conn; |
| 714 | } |
| 715 | |
Harald Welte | e32ad99 | 2018-05-31 22:17:46 +0200 | [diff] [blame] | 716 | [] RSL_PROC.getcall(RSLEM_get_last_act:{?,?,?}) -> param(trx_nr, chan_nr) sender vc_conn { |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 717 | var RSL_Message last_chan_act := f_lookup_last_act(trx_nr, chan_nr); |
Harald Welte | e32ad99 | 2018-05-31 22:17:46 +0200 | [diff] [blame] | 718 | RSL_PROC.reply(RSLEM_get_last_act:{trx_nr, chan_nr, last_chan_act}) to vc_conn; |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 719 | } |
Neels Hofmeyr | ad26fc0 | 2021-09-28 18:30:17 +0200 | [diff] [blame] | 720 | |
| 721 | [] RSL_PROC.getcall(RSLEM_set_auto_chan_act_ack:{?}) -> param(auto_chan_act_ack) sender vc_conn { |
| 722 | RSL_PROC.reply(RSLEM_set_auto_chan_act_ack:{auto_chan_act_ack}) to vc_conn; |
| 723 | } |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 724 | } |
| 725 | } |
| 726 | } |
| 727 | |
Daniel Willmann | 17f970f | 2018-01-17 12:03:19 +0100 | [diff] [blame] | 728 | private function f_conn_table_init() |
| 729 | runs on RSL_Emulation_CT { |
| 730 | var integer i; |
| 731 | |
| 732 | /* Initialize the ConnectionTable */ |
| 733 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 734 | f_cid_clear(i); |
| 735 | } |
| 736 | } |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 737 | |
Vadim Yanitskiy | e9c0635 | 2020-06-20 01:30:58 +0700 | [diff] [blame] | 738 | private function f_WaitingQueue_dispatch() |
| 739 | runs on RSL_Emulation_CT { |
| 740 | var integer cid; |
| 741 | |
| 742 | for (var integer i := 0; i < lengthof(WaitingQueue); i := i + 1) { |
| 743 | cid := f_cid_by_chan_nr(f_trx_by_streamId(WaitingQueue[i].streamId), |
| 744 | WaitingQueue[i].rsl.ies[0].body.chan_nr); |
| 745 | if (cid == -1) { |
| 746 | setverdict(fail, "No Dchan handler found for: ", WaitingQueue[i]); |
| 747 | mtc.stop; |
Vadim Yanitskiy | e9c0635 | 2020-06-20 01:30:58 +0700 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | /* Dispatch a stalled message to the appropriate handler */ |
| 751 | CLIENT_PT.send(WaitingQueue[i].rsl) to ConnectionTable[cid].comp_ref; |
| 752 | } |
| 753 | |
| 754 | /* All messages dispatched, clear the queue */ |
| 755 | WaitingQueue := { }; |
| 756 | } |
| 757 | |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 758 | /* client/conn_hdlr side function to use procedure port to register stream_id/chan_nr */ |
Harald Welte | 421e4d4 | 2018-02-12 20:04:50 +0100 | [diff] [blame] | 759 | function f_rslem_register(uint8_t trx_nr, RslChannelNr chan_nr, RSLEM_PROC_PT PT := RSL_PROC) |
| 760 | runs on RSL_DchanHdlr { |
| 761 | PT.call(RSLEM_register:{trx_nr, chan_nr, self}) { |
| 762 | [] PT.getreply(RSLEM_register:{?,?,?}) {}; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 766 | /* client/conn_hdlr side function to use procedure port to unregister stream_id/chan_nr */ |
Harald Welte | 421e4d4 | 2018-02-12 20:04:50 +0100 | [diff] [blame] | 767 | function f_rslem_unregister(uint8_t trx_nr, RslChannelNr chan_nr, RSLEM_PROC_PT PT := RSL_PROC) |
| 768 | runs on RSL_DchanHdlr { |
| 769 | PT.call(RSLEM_unregister:{trx_nr, chan_nr, self}) { |
| 770 | [] PT.getreply(RSLEM_unregister:{?,?,?}) {}; |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | |
Vadim Yanitskiy | a38c265 | 2020-06-21 19:47:00 +0700 | [diff] [blame] | 774 | /* suspend handling of RSL DChan messages from IPA until f_rslem_resume() is called */ |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 775 | function f_rslem_suspend(RSLEM_PROC_PT PT) |
| 776 | runs on RSL_DchanHdlr { |
| 777 | PT.call(RSLEM_suspend:{true}) { |
| 778 | [] PT.getreply(RSLEM_suspend:{true}) {}; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | /* resume handling of RSL DChan messages after f_rslem_suspend() is called */ |
| 783 | function f_rslem_resume(RSLEM_PROC_PT PT) |
| 784 | runs on RSL_DchanHdlr { |
| 785 | PT.call(RSLEM_suspend:{false}) { |
| 786 | [] PT.getreply(RSLEM_suspend:{false}) {}; |
| 787 | } |
| 788 | } |
| 789 | |
Vadim Yanitskiy | e9c0635 | 2020-06-20 01:30:58 +0700 | [diff] [blame] | 790 | /* Enable queueing of RSL DChan messages from IPA until f_rslem_dchan_queue_disable() is called. */ |
| 791 | function f_rslem_dchan_queue_enable(RSLEM_PROC_PT PT := RSL_PROC) |
| 792 | runs on RSL_DchanHdlr { |
| 793 | PT.call(RSLEM_wait_queue:{true}) { |
| 794 | [] PT.getreply(RSLEM_wait_queue:{true}) {}; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | /* Disable queueing of RSL DChan messages after f_rslem_dchan_queue_enable() is called. |
| 799 | * Dispatch all stalled messages to the registered handlers. Make sure that no |
| 800 | * messages for which there is no handler are left in the queue (mtc.stop if so). */ |
| 801 | function f_rslem_dchan_queue_dispatch(RSLEM_PROC_PT PT := RSL_PROC) |
| 802 | runs on RSL_DchanHdlr { |
| 803 | PT.call(RSLEM_wait_queue:{false}) { |
| 804 | [] PT.getreply(RSLEM_wait_queue:{false}) {}; |
| 805 | } |
| 806 | } |
| 807 | |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 808 | /* obtain the last RSL_CHAN_ACT message for the given chan_nr */ |
| 809 | function f_rslem_get_last_act(RSLEM_PROC_PT PT, uint8_t trx_nr, RslChannelNr chan_nr) |
| 810 | runs on RSL_DchanHdlr return RSL_Message { |
| 811 | var RSL_Message chan_act; |
| 812 | PT.call(RSLEM_get_last_act:{trx_nr, chan_nr, -}) { |
| 813 | [] PT.getreply(RSLEM_get_last_act:{trx_nr, chan_nr, ?}) -> param(chan_act) {}; |
| 814 | } |
| 815 | return chan_act; |
| 816 | } |
| 817 | |
Neels Hofmeyr | ad26fc0 | 2021-09-28 18:30:17 +0200 | [diff] [blame] | 818 | function f_rslem_set_auto_chan_act_ack(RSLEM_PROC_PT PT, boolean enable) |
| 819 | runs on RSL_DchanHdlr { |
| 820 | PT.call(RSLEM_set_auto_chan_act_ack:{enable}) { |
| 821 | [] PT.getreply(RSLEM_set_auto_chan_act_ack:{enable}) {}; |
| 822 | } |
| 823 | } |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 824 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 825 | } |