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