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