blob: effe83bc2789455cb0410d16618d88aa5eafc814 [file] [log] [blame]
Harald Welte714ded92017-12-08 14:00:22 +01001module RSL_Emulation {
2
Harald Welte35bb7162018-01-03 21:07:52 +01003/* 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 Weltead2647b2018-03-22 19:53:55 +010013 * 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 Welte35bb7162018-01-03 21:07:52 +010020 * 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 Welte34b5a952019-05-27 11:54:11 +020024 *
25 * SPDX-License-Identifier: GPL-2.0-or-later
Harald Welte35bb7162018-01-03 21:07:52 +010026 */
27
Pau Espin Pedrola07cfd92018-10-22 15:54:41 +020028import from Misc_Helpers all;
Harald Welte714ded92017-12-08 14:00:22 +010029import from General_Types all;
30import from Osmocom_Types all;
31import from GSM_Types all;
32import from GSM_RR_Types all;
33import from RSL_Types all;
34import from IPA_Types all;
35import from IPA_Emulation all;
36
Harald Welte714ded92017-12-08 14:00:22 +010037/* General "base class" component definition, of which specific implementations
38 * derive themselves by means of the "extends" feature */
39type component RSL_DchanHdlr {
40 /* port facing up towards dedicated channel handler */
41 port RSL_DCHAN_PT RSL;
Harald Weltef70df652018-01-29 22:00:23 +010042 port RSLEM_PROC_PT RSL_PROC;
Harald Welte714ded92017-12-08 14:00:22 +010043 var RslChannelNr g_chan_nr;
Harald Welte421e4d42018-02-12 20:04:50 +010044 /* second BTS / DChan during hand-over */
45 port RSL_DCHAN_PT RSL1;
46 port RSLEM_PROC_PT RSL1_PROC;
Neels Hofmeyr91401012019-07-11 00:42:35 +020047 port RSL_DCHAN_PT RSL2;
48 port RSLEM_PROC_PT RSL2_PROC;
Harald Welte714ded92017-12-08 14:00:22 +010049};
50
51type record RSLDC_ChanRqd {
52 OCT1 ra,
Pau Espin Pedrol6451b042018-10-24 20:36:16 +020053 GsmFrameNumber fn optional
Harald Welte714ded92017-12-08 14:00:22 +010054};
55
Pau Espin Pedrol6451b042018-10-24 20:36:16 +020056template (value) RSLDC_ChanRqd ts_RSLDC_ChanRqd(OCT1 ra, GsmFrameNumber fn) := {
Harald Welte714ded92017-12-08 14:00:22 +010057 ra := ra,
58 fn := fn
59}
60
Pau Espin Pedrol6451b042018-10-24 20:36:16 +020061template (value) RSLDC_ChanRqd ts_RSLDC_ChanRqd_anyFN(OCT1 ra) := {
62 ra := ra,
63 fn := omit
64}
65
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +070066type enumerated RSLEm_EventType {
67 RSLEM_EV_TRX_UP,
68 RSLEM_EV_TRX_DOWN
69};
70
71type record RSLEm_Event {
72 RSLEm_EventType ev_type,
73 IpaStreamId sid
74};
75
76template (value) RSLEm_Event ts_RSLEm_EV(RSLEm_EventType ev_type,
77 IpaStreamId sid) := {
78 ev_type := ev_type,
79 sid := sid
80};
81template 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 Welte714ded92017-12-08 14:00:22 +010087type port RSL_DCHAN_PT message {
Neels Hofmeyr1470fc62021-05-25 21:35:46 +000088 inout RSLDC_ChanRqd, RSL_Message, ASP_RSL_Unitdata;
Harald Welte714ded92017-12-08 14:00:22 +010089} with { extension "internal" };
90
Harald Welte1c02fd12018-02-19 19:20:47 +010091type port RSL_CCHAN_PT message {
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +070092 inout ASP_RSL_Unitdata, RSLEm_Event;
Harald Welte1c02fd12018-02-19 19:20:47 +010093} with { extension "internal" };
94
95
Harald Weltef70df652018-01-29 22:00:23 +010096signature RSLEM_register(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr hdlr);
Harald Welte1909f462018-01-29 22:29:29 +010097signature RSLEM_unregister(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr hdlr);
Harald Welte70b52c92018-02-12 20:47:31 +010098signature RSLEM_suspend(boolean suspend);
Vadim Yanitskiye9c06352020-06-20 01:30:58 +070099signature RSLEM_wait_queue(boolean enable);
Harald Weltead2647b2018-03-22 19:53:55 +0100100signature RSLEM_get_last_act(in uint8_t trx_nr, in RslChannelNr chan_nr, out RSL_Message chan_act);
Neels Hofmeyrad26fc02021-09-28 18:30:17 +0200101signature RSLEM_set_auto_chan_act_ack(boolean enable);
Harald Weltef70df652018-01-29 22:00:23 +0100102
103type port RSLEM_PROC_PT procedure {
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700104 inout RSLEM_register, RSLEM_unregister,
105 RSLEM_suspend, RSLEM_wait_queue,
Neels Hofmeyrad26fc02021-09-28 18:30:17 +0200106 RSLEM_get_last_act,
107 RSLEM_set_auto_chan_act_ack;
Harald Weltef70df652018-01-29 22:00:23 +0100108} with { extension "internal" };
109
Harald Welte714ded92017-12-08 14:00:22 +0100110/***********************************************************************
111 * Client Component for a single dedicated channel
112 ***********************************************************************/
113
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200114private function f_rx_or_fail(template RSL_Message exp_rx, RSL_DCHAN_PT rsl_pt := RSL) runs on RSL_DchanHdlr return RSL_Message
Harald Welte714ded92017-12-08 14:00:22 +0100115{
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 Hofmeyr3222e0e2021-07-20 22:25:38 +0200122 [] rsl_pt.receive(exp_rx) -> value rx_rsl {
Harald Welte714ded92017-12-08 14:00:22 +0100123 T.stop;
124 return rx_rsl;
125 }
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200126 [] rsl_pt.receive {
Harald Welte714ded92017-12-08 14:00:22 +0100127 setverdict(fail, "Unexpected RSL message on DCHAN");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200128 mtc.stop;
Harald Welte714ded92017-12-08 14:00:22 +0100129 }
130 [] T.timeout {
131 setverdict(fail, "Timeout waiting for RSL on DCHAN");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200132 mtc.stop;
Harald Welte714ded92017-12-08 14:00:22 +0100133 }
134 }
135 /* never reached */
136 return rx_rsl;
137}
138
Neels Hofmeyr596393a2021-10-02 13:01:04 +0200139function 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 Welte714ded92017-12-08 14:00:22 +0100151/* establish a dedicated channel using 'ra' */
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200152function f_chan_est(OCT1 ra, octetstring est_l3, template RslLinkId link_id, GsmFrameNumber fn := 23,
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200153 template uint3_t tsc := ?, RSL_DCHAN_PT rsl_pt := RSL, RSLEM_PROC_PT rsl_proc_pt := RSL_PROC)
Harald Welte714ded92017-12-08 14:00:22 +0100154runs on RSL_DchanHdlr {
155 var RSL_Message rx_rsl;
156 var GsmRrMessage rr;
157
158 /* request a channel to be established */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200159 rsl_pt.send(ts_RSLDC_ChanRqd(ra, fn));
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200160 /* At this point the BSC sends a CHAN ACTIV which we always ACK. Checking it below. */
Harald Welte714ded92017-12-08 14:00:22 +0100161 /* expect immediate assignment */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200162 rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN, rsl_pt := rsl_pt);
Harald Welte714ded92017-12-08 14:00:22 +0100163 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200164 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 Welte714ded92017-12-08 14:00:22 +0100169 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200170 rsl_pt.send(ts_RSL_EST_IND(g_chan_nr, valueof(link_id), est_l3));
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200171
172 /* Check above CHAN ACTIV */
Neels Hofmeyr596393a2021-10-02 13:01:04 +0200173 f_chan_act_verify_tsc(f_rslem_get_last_act(rsl_proc_pt, 0, g_chan_nr), tsc);
Harald Welte714ded92017-12-08 14:00:22 +0100174}
175
176function 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
191private 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
203private function f_cid_by_comp_ref(RSL_DchanHdlr comp_ref)
204runs on RSL_Emulation_CT return integer {
205 var integer i;
206 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
Pau Espin Pedrol70965092020-06-23 14:29:56 +0200207 if (ispresent(ConnectionTable[i].comp_ref) and
Harald Welte714ded92017-12-08 14:00:22 +0100208 ConnectionTable[i].comp_ref == comp_ref) {
209 return i;
210 }
211 }
Vadim Yanitskiyf79d9362020-06-03 04:06:18 +0700212 log("No Dchan handler for comp_ref=", comp_ref);
Harald Welte714ded92017-12-08 14:00:22 +0100213 return -1;
214}
215
216private function f_cid_by_chan_nr(uint8_t trx_nr, RslChannelNr chan_nr)
217runs on RSL_Emulation_CT return integer {
218 var integer i;
219 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
Pau Espin Pedrol70965092020-06-23 14:29:56 +0200220 if (ispresent(ConnectionTable[i].chan_nr) and
Harald Welte714ded92017-12-08 14:00:22 +0100221 ConnectionTable[i].chan_nr == chan_nr and ConnectionTable[i].trx_nr == trx_nr) {
222 return i;
223 }
224 }
Vadim Yanitskiyf79d9362020-06-03 04:06:18 +0700225 log("No Dchan handler for trx_nr=", trx_nr, " and chan_nr=", chan_nr);
Harald Welte714ded92017-12-08 14:00:22 +0100226 return -1;
227}
228
229private function f_cid_by_ra_fn(OCT1 ra, GsmFrameNumber fn)
230runs 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 Yanitskiyf79d9362020-06-03 04:06:18 +0700238 log("No Dchan handler for ra=", ra, " and fn=", fn);
Harald Welte714ded92017-12-08 14:00:22 +0100239 return -1;
240}
241
Pau Espin Pedrol6451b042018-10-24 20:36:16 +0200242/* Matches by only RA if FN is ommited in one of the connections allocated */
243private function f_cid_by_ra_fn2(OCT1 ra, RSL_IE_FrameNumber fn)
244runs 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 Yanitskiyf79d9362020-06-03 04:06:18 +0700255 log("No Dchan handler for ra=", ra, " and fn=", fn);
Pau Espin Pedrol6451b042018-10-24 20:36:16 +0200256 return -1;
257}
258
Harald Welte714ded92017-12-08 14:00:22 +0100259/* create an ew client with given RA and FN */
Pau Espin Pedrol6451b042018-10-24 20:36:16 +0200260private function f_cid_create(OCT1 ra, template (omit) GsmFrameNumber fn, RSL_DchanHdlr comp_ref)
Harald Welte930d0a72018-03-22 22:08:40 +0100261runs on RSL_Emulation_CT {
Harald Welte714ded92017-12-08 14:00:22 +0100262 var integer i;
263 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
Harald Weltef70df652018-01-29 22:00:23 +0100264 if (not ispresent(ConnectionTable[i].ra) and
265 not ispresent(ConnectionTable[i].trx_nr)) {
Harald Welte714ded92017-12-08 14:00:22 +0100266 ConnectionTable[i].ra := ra;
Pau Espin Pedrol6451b042018-10-24 20:36:16 +0200267 if (ispresent(fn)) {
268 ConnectionTable[i].ra_fn := valueof(fn);
269 } else {
270 ConnectionTable[i].ra_fn := omit;
271 }
Harald Welte714ded92017-12-08 14:00:22 +0100272 ConnectionTable[i].comp_ref := comp_ref;
Harald Welte930d0a72018-03-22 22:08:40 +0100273 return;
Harald Welte714ded92017-12-08 14:00:22 +0100274 }
275 }
Daniel Willmann8273fb92018-07-05 17:31:20 +0200276 testcase.stop("No free entry in conn table for ", ra, fn);
Harald Welte714ded92017-12-08 14:00:22 +0100277}
278
Vadim Yanitskiyefc94132020-05-24 04:26:45 +0700279/* create a new client with given RA and FN */
Harald Weltef70df652018-01-29 22:00:23 +0100280private function f_cid_create_cnr(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr comp_ref)
Harald Welte930d0a72018-03-22 22:08:40 +0100281runs on RSL_Emulation_CT {
Harald Weltef70df652018-01-29 22:00:23 +0100282 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 Welte930d0a72018-03-22 22:08:40 +0100290 return;
Harald Weltef70df652018-01-29 22:00:23 +0100291 }
292 }
Daniel Willmann8273fb92018-07-05 17:31:20 +0200293 testcase.stop("No free entry in conn table for ", trx_nr, chan_nr, comp_ref);
Harald Weltef70df652018-01-29 22:00:23 +0100294}
295
296
Vadim Yanitskiyefc94132020-05-24 04:26:45 +0700297/* delete client with given RA and FN */
Harald Weltef70df652018-01-29 22:00:23 +0100298private function f_cid_delete_cnr(IpaStreamId stream_id, RslChannelNr chan_nr, RSL_DchanHdlr comp_ref)
299runs 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 Welte714ded92017-12-08 14:00:22 +0100316private function f_cid_clear(integer cid)
317runs on RSL_Emulation_CT {
318 ConnectionTable[cid].ra := omit;
319 ConnectionTable[cid].ra_fn := omit;
Harald Welte714ded92017-12-08 14:00:22 +0100320 ConnectionTable[cid].trx_nr := omit;
321 ConnectionTable[cid].stream_id := omit;
322 ConnectionTable[cid].chan_nr := omit;
Harald Weltef70df652018-01-29 22:00:23 +0100323 ConnectionTable[cid].comp_ref := null;
Harald Welte714ded92017-12-08 14:00:22 +0100324}
325
Harald Weltead2647b2018-03-22 19:53:55 +0100326/* last activation for a given channel number */
327type record LastActData {
328 uint8_t trx_nr optional,
329 RslChannelNr chan_nr optional,
330 RSL_Message chan_act optional
331}
332
333private function f_store_last_act_data(uint8_t trx_nr, RslChannelNr chan_nr, RSL_Message chan_act)
334runs 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 Willmann8273fb92018-07-05 17:31:20 +0200344 testcase.stop("No space left in LastActTable to store chan_act for ", chan_nr);
Harald Weltead2647b2018-03-22 19:53:55 +0100345}
346
347private function f_lookup_last_act(uint8_t trx_nr, RslChannelNr chan_nr)
348runs 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 Willmann8273fb92018-07-05 17:31:20 +0200355 testcase.stop("No LastActTable entry found for TRX ", trx_nr, " ", chan_nr);
Harald Weltead2647b2018-03-22 19:53:55 +0100356}
357
358private 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 Yanitskiy6de2fcb2020-05-25 19:40:45 +0700364private function f_trx_conn_map_init()
365runs on RSL_Emulation_CT {
366 for (var integer i := 0; i < sizeof(TrxConnMap); i := i + 1) {
367 TrxConnMap[i] := -1;
368 }
369}
370
371private function f_trx_conn_map_register(integer conn_id, in IpaCcmIdResp id_resp)
372runs 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 Pedrolabcdf782020-06-23 14:29:24 +0200414private function f_trx_conn_map_unregister(integer conn_id)
415runs 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 Yanitskiy6de2fcb2020-05-25 19:40:45 +0700428private function f_trx_conn_map_resolve(IpaStreamId id)
429runs 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 Yanitskiye9c06352020-06-20 01:30:58 +0700439private type record of ASP_RSL_Unitdata ASP_RSL_UDList;
440
Harald Welte714ded92017-12-08 14:00:22 +0100441type 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 Weltef70df652018-01-29 22:00:23 +0100446 port RSLEM_PROC_PT RSL_PROC;
Harald Welte714ded92017-12-08 14:00:22 +0100447
Harald Welte1c02fd12018-02-19 19:20:47 +0100448 /* port for Common Channel / TRX Management */
449 port RSL_CCHAN_PT CCHAN_PT;
450
Harald Welte714ded92017-12-08 14:00:22 +0100451 /* state of all concurrent connections / dedicated channels */
452 var ConnectionData ConnectionTable[64];
Harald Weltead2647b2018-03-22 19:53:55 +0100453
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700454 /* RSL messages for which no handler is currently registered */
455 var ASP_RSL_UDList WaitingQueue := { };
456
Harald Weltead2647b2018-03-22 19:53:55 +0100457 /* last RSL CHAN ACT for each chan_nr */
458 var LastActData LastActTable[64];
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700459
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 Welte714ded92017-12-08 14:00:22 +0100463}
464
465
Harald Welte714ded92017-12-08 14:00:22 +0100466private function f_trx_by_streamId(IpaStreamId id) return integer {
467 return enum2int(id);
468}
469
Harald Weltef70df652018-01-29 22:00:23 +0100470private 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 Willmanna6ea2ef2018-07-24 09:55:52 +0200477 setverdict(fail, "Unknown stream ID ", trx_nr);
478 mtc.stop;
Harald Weltef70df652018-01-29 22:00:23 +0100479}
480
Harald Welte714ded92017-12-08 14:00:22 +0100481
Harald Welte1c02fd12018-02-19 19:20:47 +0100482function main(boolean bts_role := true) runs on RSL_Emulation_CT {
Harald Weltebb6aed32018-02-21 12:19:18 +0100483 var ASP_IPA_Event evt;
Harald Welte714ded92017-12-08 14:00:22 +0100484 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 Weltef70df652018-01-29 22:00:23 +0100488 var RslChannelNr chan_nr;
489 var uint8_t trx_nr;
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700490 var integer conn_id;
Harald Welte714ded92017-12-08 14:00:22 +0100491 var integer cid;
492 var integer i;
Harald Welte70b52c92018-02-12 20:47:31 +0100493 /* special synchronization handling during hand-over */
494 var boolean dchan_suspended := false;
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700495 /* 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 Hofmeyrad26fc02021-09-28 18:30:17 +0200499 var boolean auto_chan_act_ack := true;
Harald Welte714ded92017-12-08 14:00:22 +0100500
Daniel Willmann17f970f2018-01-17 12:03:19 +0100501 f_conn_table_init();
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700502 f_trx_conn_map_init();
Harald Weltead2647b2018-03-22 19:53:55 +0100503 f_last_act_table_init();
Daniel Willmann17f970f2018-01-17 12:03:19 +0100504
Harald Welte714ded92017-12-08 14:00:22 +0100505 while (true) {
506 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700507 [bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_UP)) {
Harald Weltebb6aed32018-02-21 12:19:18 +0100508 }
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700509 [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_UP)) -> value evt {
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700510 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 Welte624f9632017-12-16 19:26:04 +0100519 }
Pau Espin Pedrolabcdf782020-06-23 14:29:24 +0200520 [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 Pedrola07cfd92018-10-22 15:54:41 +0200525 }
Pau Espin Pedrolabcdf782020-06-23 14:29:24 +0200526 [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 Pedrola07cfd92018-10-22 15:54:41 +0200531 }
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700532 [bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700533 IPA_PT.send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23)));
Harald Welte714ded92017-12-08 14:00:22 +0100534 }
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700535 [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) { }
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700536 [bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN, sid := ?)) -> value rx_rsl {
Harald Welte714ded92017-12-08 14:00:22 +0100537 var GsmRrMessage rr;
538 var OCT1 ra;
539 var GsmFrameNumber fn;
Harald Welte714ded92017-12-08 14:00:22 +0100540 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 Willmanne4ff5372018-07-05 17:35:03 +0200548 mtc.stop;
Harald Welte714ded92017-12-08 14:00:22 +0100549 }
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 Yanitskiya60e5cf2020-05-26 01:46:31 +0700572 [not bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_CHAN_RQD(?), sid := ?)) -> value rx_rsl {
Pau Espin Pedrol6451b042018-10-24 20:36:16 +0200573 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 Welte714ded92017-12-08 14:00:22 +0100583
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700584 [bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?, ?), sid := ?)) -> value rx_rsl {
Harald Welte714ded92017-12-08 14:00:22 +0100585 /* broadcast to all clients? */
586 for (i := 0; i < sizeof(ConnectionTable); i := i + 1) {
Neels Hofmeyrd7eabd62020-06-08 22:30:54 +0200587 if (ispresent(ConnectionTable[i].comp_ref) and ConnectionTable[i].comp_ref != null) {
Harald Welte714ded92017-12-08 14:00:22 +0100588 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[i].comp_ref;
589 }
590 }
591 }
592
Harald Welte1c02fd12018-02-19 19:20:47 +0100593 /* Forward common channel management to the special port for it */
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700594 [] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeT(?), sid := ?)) -> value rx_rsl {
Harald Welte1c02fd12018-02-19 19:20:47 +0100595 CCHAN_PT.send(rx_rsl);
Harald Welte714ded92017-12-08 14:00:22 +0100596 }
597
Harald Welte1c02fd12018-02-19 19:20:47 +0100598 /* Forward common channel management to the special port for it */
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700599 [] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeC(?), sid := ?)) -> value rx_rsl {
Harald Welte1c02fd12018-02-19 19:20:47 +0100600 CCHAN_PT.send(rx_rsl);
Harald Welte714ded92017-12-08 14:00:22 +0100601 }
602
Neels Hofmeyrad26fc02021-09-28 18:30:17 +0200603 /* Channel Activation: store in LastActTable, possibly ACK. */
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700604 [bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV), sid := ?)) -> value rx_rsl {
Harald Weltef70df652018-01-29 22:00:23 +0100605 chan_nr := rx_rsl.rsl.ies[0].body.chan_nr;
Harald Weltead2647b2018-03-22 19:53:55 +0100606 trx_nr := f_trx_by_streamId(rx_rsl.streamId);
607 f_store_last_act_data(trx_nr, chan_nr, rx_rsl.rsl);
Neels Hofmeyrad26fc02021-09-28 18:30:17 +0200608 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 Welte714ded92017-12-08 14:00:22 +0100614 }
615
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700616 [not dchan_suspended] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeDR(?), sid := ?)) -> value rx_rsl {
Harald Welte714ded92017-12-08 14:00:22 +0100617 /* 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 Yanitskiye9c06352020-06-20 01:30:58 +0700622 } else if (wait_queue_enabled) {
623 log("Storing an RSL message in the waiting queue");
624 WaitingQueue := WaitingQueue & { rx_rsl };
Harald Welte714ded92017-12-08 14:00:22 +0100625 } else {
Neels Hofmeyrc0ef35c2021-07-22 16:22:25 +0200626 log("Error: RSL for unknown Dchan (streamId ", rx_rsl.streamId, ", chan_nr ",
627 rx_rsl.rsl.ies[0].body.chan_nr, "): ", rx_rsl);
Harald Welte714ded92017-12-08 14:00:22 +0100628 setverdict(fail, "RSL for unknown Dchan");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200629 mtc.stop;
Harald Welte714ded92017-12-08 14:00:22 +0100630 }
631 }
632
Harald Welte70b52c92018-02-12 20:47:31 +0100633 [not dchan_suspended] IPA_PT.receive {
Harald Welte714ded92017-12-08 14:00:22 +0100634 setverdict(fail, "Received unknown primitive from IPA");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200635 mtc.stop;
Harald Welte714ded92017-12-08 14:00:22 +0100636 }
637
Harald Welte1c02fd12018-02-19 19:20:47 +0100638 [bts_role] CLIENT_PT.receive(RSLDC_ChanRqd:?) -> value chan_rqd sender vc_conn {
Harald Welte714ded92017-12-08 14:00:22 +0100639 /* 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 Yanitskiy9b4e3562020-05-25 21:40:52 +0700641 IPA_PT.send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD(chan_rqd.ra, chan_rqd.fn)));
Harald Welte714ded92017-12-08 14:00:22 +0100642 }
643
Pau Espin Pedrol6451b042018-10-24 20:36:16 +0200644 [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 Yanitskiy6de2fcb2020-05-25 19:40:45 +0700649 /* 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 Welte714ded92017-12-08 14:00:22 +0100651 cid := f_cid_by_comp_ref(vc_conn);
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700652 IPA_PT.send(ts_ASP_RSL_UD(rx_rsl_msg, ConnectionTable[cid].stream_id));
Harald Welte714ded92017-12-08 14:00:22 +0100653 }
Neels Hofmeyr1470fc62021-05-25 21:35:46 +0000654 [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 Yanitskiy6de2fcb2020-05-25 19:40:45 +0700657 [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 Welte714ded92017-12-08 14:00:22 +0100662
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700663 /* RSL message from MTC */
664 [bts_role] CCHAN_PT.receive(tr_ASP_RSL_UD(?, sid := ?)) -> value rx_rsl {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700665 IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.rsl, rx_rsl.streamId));
Harald Welte34252c52018-02-24 04:51:50 +0100666 }
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700667 [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 Welte34252c52018-02-24 04:51:50 +0100671
Harald Weltef70df652018-01-29 22:00:23 +0100672 /* 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 Weltee32ad992018-05-31 22:17:46 +0200675 RSL_PROC.reply(RSLEM_register:{trx_nr, chan_nr, vc_conn}) to vc_conn;
Harald Weltef70df652018-01-29 22:00:23 +0100676 }
677
Harald Welte1909f462018-01-29 22:29:29 +0100678 [] 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 Weltee32ad992018-05-31 22:17:46 +0200681 RSL_PROC.reply(RSLEM_unregister:{trx_nr, chan_nr, vc_conn}) to vc_conn;
Harald Welte1909f462018-01-29 22:29:29 +0100682 }
683
Harald Weltee32ad992018-05-31 22:17:46 +0200684 [] RSL_PROC.getcall(RSLEM_suspend:{true}) -> sender vc_conn {
Harald Welte70b52c92018-02-12 20:47:31 +0100685 log("Suspending DChan");
686 dchan_suspended := true;
Harald Weltee32ad992018-05-31 22:17:46 +0200687 RSL_PROC.reply(RSLEM_suspend:{true}) to vc_conn;
Harald Welte70b52c92018-02-12 20:47:31 +0100688 }
689
Harald Weltee32ad992018-05-31 22:17:46 +0200690 [] RSL_PROC.getcall(RSLEM_suspend:{false}) -> sender vc_conn {
Harald Welte70b52c92018-02-12 20:47:31 +0100691 log("Resuming DChan");
692 dchan_suspended := false;
Harald Weltee32ad992018-05-31 22:17:46 +0200693 RSL_PROC.reply(RSLEM_suspend:{false}) to vc_conn;
Harald Welte70b52c92018-02-12 20:47:31 +0100694 }
Harald Welte1909f462018-01-29 22:29:29 +0100695
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700696 [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 Weltee32ad992018-05-31 22:17:46 +0200716 [] RSL_PROC.getcall(RSLEM_get_last_act:{?,?,?}) -> param(trx_nr, chan_nr) sender vc_conn {
Harald Weltead2647b2018-03-22 19:53:55 +0100717 var RSL_Message last_chan_act := f_lookup_last_act(trx_nr, chan_nr);
Harald Weltee32ad992018-05-31 22:17:46 +0200718 RSL_PROC.reply(RSLEM_get_last_act:{trx_nr, chan_nr, last_chan_act}) to vc_conn;
Harald Weltead2647b2018-03-22 19:53:55 +0100719 }
Neels Hofmeyrad26fc02021-09-28 18:30:17 +0200720
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 Welte714ded92017-12-08 14:00:22 +0100724 }
725 }
726}
727
Daniel Willmann17f970f2018-01-17 12:03:19 +0100728private function f_conn_table_init()
729runs 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 Welte714ded92017-12-08 14:00:22 +0100737
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700738private function f_WaitingQueue_dispatch()
739runs 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 Yanitskiye9c06352020-06-20 01:30:58 +0700748 }
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 Weltef70df652018-01-29 22:00:23 +0100758/* client/conn_hdlr side function to use procedure port to register stream_id/chan_nr */
Harald Welte421e4d42018-02-12 20:04:50 +0100759function f_rslem_register(uint8_t trx_nr, RslChannelNr chan_nr, RSLEM_PROC_PT PT := RSL_PROC)
760runs on RSL_DchanHdlr {
761 PT.call(RSLEM_register:{trx_nr, chan_nr, self}) {
762 [] PT.getreply(RSLEM_register:{?,?,?}) {};
Harald Weltef70df652018-01-29 22:00:23 +0100763 }
764}
765
Harald Welte1909f462018-01-29 22:29:29 +0100766/* client/conn_hdlr side function to use procedure port to unregister stream_id/chan_nr */
Harald Welte421e4d42018-02-12 20:04:50 +0100767function f_rslem_unregister(uint8_t trx_nr, RslChannelNr chan_nr, RSLEM_PROC_PT PT := RSL_PROC)
768runs on RSL_DchanHdlr {
769 PT.call(RSLEM_unregister:{trx_nr, chan_nr, self}) {
770 [] PT.getreply(RSLEM_unregister:{?,?,?}) {};
Harald Welte1909f462018-01-29 22:29:29 +0100771 }
772}
773
Vadim Yanitskiya38c2652020-06-21 19:47:00 +0700774/* suspend handling of RSL DChan messages from IPA until f_rslem_resume() is called */
Harald Welte70b52c92018-02-12 20:47:31 +0100775function f_rslem_suspend(RSLEM_PROC_PT PT)
776runs 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 */
783function f_rslem_resume(RSLEM_PROC_PT PT)
784runs on RSL_DchanHdlr {
785 PT.call(RSLEM_suspend:{false}) {
786 [] PT.getreply(RSLEM_suspend:{false}) {};
787 }
788}
789
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700790/* Enable queueing of RSL DChan messages from IPA until f_rslem_dchan_queue_disable() is called. */
791function f_rslem_dchan_queue_enable(RSLEM_PROC_PT PT := RSL_PROC)
792runs 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). */
801function f_rslem_dchan_queue_dispatch(RSLEM_PROC_PT PT := RSL_PROC)
802runs on RSL_DchanHdlr {
803 PT.call(RSLEM_wait_queue:{false}) {
804 [] PT.getreply(RSLEM_wait_queue:{false}) {};
805 }
806}
807
Harald Weltead2647b2018-03-22 19:53:55 +0100808/* obtain the last RSL_CHAN_ACT message for the given chan_nr */
809function f_rslem_get_last_act(RSLEM_PROC_PT PT, uint8_t trx_nr, RslChannelNr chan_nr)
810runs 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 Hofmeyrad26fc02021-09-28 18:30:17 +0200818function f_rslem_set_auto_chan_act_ack(RSLEM_PROC_PT PT, boolean enable)
819runs 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 Welte1909f462018-01-29 22:29:29 +0100824
Harald Welte714ded92017-12-08 14:00:22 +0100825}