blob: 17e35ab74f6c1c03123ed1bc15ea109ad9e30610 [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 {
Vadim Yanitskiy73468c82024-04-20 03:20:17 +0700373 var IpaUnitId unit_id;
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700374 var integer idx;
375
376 /* Check if we have room for a new connection */
377 if (TrxConnNum >= sizeof(TrxConnMap)) {
378 testcase.stop("We cannot handle more than ", sizeof(TrxConnMap), " transceivers");
379 }
380
381 /* Find IPAC_IDTAG_UNITID in the IPA IDENTITY RESPONSE */
382 idx := f_ipa_id_resp_find_ie(id_resp, IPAC_IDTAG_UNITID);
383 if (idx < 0) {
384 testcase.stop("IPA IDENTITY RESPONSE contains no unit-id");
385 }
386
Vadim Yanitskiy73468c82024-04-20 03:20:17 +0700387 /* Parse IPA unit-id */
388 unit_id := dec_IpaUnitId(oct2char(id_resp[idx].data));
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700389
Vadim Yanitskiy73468c82024-04-20 03:20:17 +0700390 if (unit_id.trx_id >= sizeof(TrxConnMap)) {
391 testcase.stop("Transceiver #", unit_id.trx_id, " does not fit");
392 } else if (TrxConnMap[unit_id.trx_id] != -1) {
393 testcase.stop("Transceiver #", unit_id.trx_id, " is already connected?!?");
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700394 }
395
396 /* Finally, store the connection ID */
Vadim Yanitskiy73468c82024-04-20 03:20:17 +0700397 log("Mapped TRX#", unit_id.trx_id, " to TCP/IP conn_id=", conn_id);
398 TrxConnMap[unit_id.trx_id] := conn_id;
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700399 TrxConnNum := TrxConnNum + 1;
400
Vadim Yanitskiy73468c82024-04-20 03:20:17 +0700401 return f_streamId_by_trx(unit_id.trx_id);
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700402}
403
Pau Espin Pedrolabcdf782020-06-23 14:29:24 +0200404private function f_trx_conn_map_unregister(integer conn_id)
405runs on RSL_Emulation_CT return IpaStreamId {
406
407 for (var integer i := 0; i < sizeof(TrxConnMap); i := i + 1) {
408 if (conn_id == TrxConnMap[i]) {
409 TrxConnMap[i] := -1;
410 TrxConnNum := TrxConnNum - 1;
411 return f_streamId_by_trx(i);
412 }
413 }
414
415 testcase.stop("Trying to unregister an unknown conn_id=", conn_id);
416}
417
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700418private function f_trx_conn_map_resolve(IpaStreamId id)
419runs on RSL_Emulation_CT return integer {
420 var integer trx_nr := f_trx_by_streamId(id);
421
422 if (TrxConnMap[trx_nr] == -1) {
423 testcase.stop("Transceiver #", trx_nr, " is not connected");
424 }
425
426 return TrxConnMap[trx_nr];
427}
428
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700429private type record of ASP_RSL_Unitdata ASP_RSL_UDList;
430
Harald Welte714ded92017-12-08 14:00:22 +0100431type component RSL_Emulation_CT {
432 /* port facing down towards IPA emulation */
433 port IPA_RSL_PT IPA_PT;
434 /* port facing up towards dedicated channel handler */
435 port RSL_DCHAN_PT CLIENT_PT;
Harald Weltef70df652018-01-29 22:00:23 +0100436 port RSLEM_PROC_PT RSL_PROC;
Harald Welte714ded92017-12-08 14:00:22 +0100437
Harald Welte1c02fd12018-02-19 19:20:47 +0100438 /* port for Common Channel / TRX Management */
439 port RSL_CCHAN_PT CCHAN_PT;
440
Harald Welte714ded92017-12-08 14:00:22 +0100441 /* state of all concurrent connections / dedicated channels */
442 var ConnectionData ConnectionTable[64];
Harald Weltead2647b2018-03-22 19:53:55 +0100443
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700444 /* RSL messages for which no handler is currently registered */
445 var ASP_RSL_UDList WaitingQueue := { };
446
Harald Weltead2647b2018-03-22 19:53:55 +0100447 /* last RSL CHAN ACT for each chan_nr */
448 var LastActData LastActTable[64];
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700449
450 /* IPA stream ID -> TCP/IP connection ID mapping for transceivers */
451 var integer TrxConnNum := 0; /* number of connected transceivers */
452 var integer TrxConnMap[4]; /* up to 4 transceivers for now */
Harald Welte714ded92017-12-08 14:00:22 +0100453}
454
455
Harald Welte714ded92017-12-08 14:00:22 +0100456private function f_trx_by_streamId(IpaStreamId id) return integer {
457 return enum2int(id);
458}
459
Harald Weltef70df652018-01-29 22:00:23 +0100460private function f_streamId_by_trx(uint8_t trx_nr) return IpaStreamId {
461 select (trx_nr) {
462 case (0) { return IPAC_PROTO_RSL_TRX0; }
463 case (1) { return IPAC_PROTO_RSL_TRX1; }
464 case (2) { return IPAC_PROTO_RSL_TRX2; }
465 case (3) { return IPAC_PROTO_RSL_TRX3; }
466 }
Daniel Willmanna6ea2ef2018-07-24 09:55:52 +0200467 setverdict(fail, "Unknown stream ID ", trx_nr);
468 mtc.stop;
Harald Weltef70df652018-01-29 22:00:23 +0100469}
470
Harald Welte714ded92017-12-08 14:00:22 +0100471
Harald Welte1c02fd12018-02-19 19:20:47 +0100472function main(boolean bts_role := true) runs on RSL_Emulation_CT {
Harald Weltebb6aed32018-02-21 12:19:18 +0100473 var ASP_IPA_Event evt;
Harald Welte714ded92017-12-08 14:00:22 +0100474 var ASP_RSL_Unitdata rx_rsl;
475 var RSL_Message rx_rsl_msg;
476 var RSLDC_ChanRqd chan_rqd;
477 var RSL_DchanHdlr vc_conn;
Harald Weltef70df652018-01-29 22:00:23 +0100478 var RslChannelNr chan_nr;
479 var uint8_t trx_nr;
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700480 var integer conn_id;
Harald Welte714ded92017-12-08 14:00:22 +0100481 var integer cid;
482 var integer i;
Harald Welte70b52c92018-02-12 20:47:31 +0100483 /* special synchronization handling during hand-over */
484 var boolean dchan_suspended := false;
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700485 /* Whether to keep RSL messages, for which no handler is found in ConnectionTable,
486 * in a queue. These messages will remain in the queue until the appropriate
487 * connection handler is registered. */
488 var boolean wait_queue_enabled := false;
Neels Hofmeyrad26fc02021-09-28 18:30:17 +0200489 var boolean auto_chan_act_ack := true;
Harald Welte714ded92017-12-08 14:00:22 +0100490
Daniel Willmann17f970f2018-01-17 12:03:19 +0100491 f_conn_table_init();
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700492 f_trx_conn_map_init();
Harald Weltead2647b2018-03-22 19:53:55 +0100493 f_last_act_table_init();
Daniel Willmann17f970f2018-01-17 12:03:19 +0100494
Harald Welte714ded92017-12-08 14:00:22 +0100495 while (true) {
496 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700497 [bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_UP)) {
Harald Weltebb6aed32018-02-21 12:19:18 +0100498 }
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700499 [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_UP)) -> value evt {
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700500 log("A new IPA/RSL connection has been established (conn_id=",
501 evt.conn_id, "), waiting for IDENTITY RESPONSE...");
502 }
503 [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_RESP)) -> value evt {
504 log("Got IDENTITY RESPONSE (conn_id=", evt.conn_id, "): ", evt.id_resp);
505 /* Update [ IPA stream ID -> TCP/IP connection ID ] mapping */
506 var IpaStreamId sid := f_trx_conn_map_register(evt.conn_id, evt.id_resp);
507 /* Notify the upper layers about a new connection */
508 CCHAN_PT.send(ts_RSLEm_EV(RSLEM_EV_TRX_UP, sid));
Harald Welte624f9632017-12-16 19:26:04 +0100509 }
Pau Espin Pedrolabcdf782020-06-23 14:29:24 +0200510 [bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) -> value evt {
511 log("Lost IPA connection! (conn_id=", evt.conn_id, "): ", evt.id_resp);
512 /* Notify the upper layers about lost connection */
513 var IpaStreamId sid := f_trx_conn_map_unregister(evt.conn_id);
514 CCHAN_PT.send(ts_RSLEm_EV(RSLEM_EV_TRX_DOWN, sid));
Pau Espin Pedrola07cfd92018-10-22 15:54:41 +0200515 }
Pau Espin Pedrolabcdf782020-06-23 14:29:24 +0200516 [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) -> value evt {
517 log("Lost IPA connection! (conn_id=", evt.conn_id, ")");
518 /* Notify the upper layers about lost connection */
519 var IpaStreamId sid := f_trx_conn_map_unregister(evt.conn_id);
520 CCHAN_PT.send(ts_RSLEm_EV(RSLEM_EV_TRX_DOWN, sid));
Pau Espin Pedrola07cfd92018-10-22 15:54:41 +0200521 }
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700522 [bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700523 IPA_PT.send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23)));
Harald Welte714ded92017-12-08 14:00:22 +0100524 }
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700525 [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) { }
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700526 [bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN, sid := ?)) -> value rx_rsl {
Harald Welte714ded92017-12-08 14:00:22 +0100527 var GsmRrMessage rr;
528 var OCT1 ra;
529 var GsmFrameNumber fn;
Harald Welte714ded92017-12-08 14:00:22 +0100530 rr := dec_GsmRrMessage(rx_rsl.rsl.ies[1].body.full_imm_ass_info.payload);
531 if (ischosen(rr.payload.imm_ass)) {
532 ra := bit2oct(rr.payload.imm_ass.req_ref.ra);
533 fn := 23; //FIXME(rr.payload.imm_ass);
534 /* lookup client based on RA+time, deliver to client */
535 cid := f_cid_by_ra_fn(ra, fn);
536 if (cid == -1) {
537 setverdict(fail, "IMM ASS for unknown DChan");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200538 mtc.stop;
Harald Welte714ded92017-12-08 14:00:22 +0100539 }
540 /* update client with trx_nr */
541 ConnectionTable[cid].trx_nr := f_trx_by_streamId(rx_rsl.streamId);
542 ConnectionTable[cid].stream_id := rx_rsl.streamId;
543 /* update client with chan_nr */
544 ConnectionTable[cid].chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
545 /* TODO: add timer to time-out ConnectionTable entries which
546 * never get followed-up to */
547 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref;
548 } else if (ischosen(rr.payload.imm_ass_rej)) {
549 for (i := 0; i < sizeof(rr.payload.imm_ass_rej.payload); i := i + 1) {
550 ra := bit2oct(rr.payload.imm_ass_rej.payload[i].req_ref.ra);
551 fn := 23; //FIXME();
552 /* lookup client based on RA+time, deliver to client */
553 cid := f_cid_by_ra_fn(ra, fn);
554 if (cid != -1) {
555 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref;
556 /* delete ClientTable entry, as it failed */
557 f_cid_clear(cid);
558 }
559 }
560 }
561 }
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700562 [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 +0200563 var RSL_IE_RequestRef req_ref;
564 req_ref := rx_rsl.rsl.ies[1].body.req_ref;
565 cid := f_cid_by_ra_fn2(req_ref.ra, req_ref.frame_nr);
566 if (cid != -1) {
567 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref;
568 f_cid_clear(cid);
569 } else {
570 CCHAN_PT.send(rx_rsl);
571 }
572 }
Harald Welte714ded92017-12-08 14:00:22 +0100573
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700574 [bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?, ?), sid := ?)) -> value rx_rsl {
Harald Welte714ded92017-12-08 14:00:22 +0100575 /* broadcast to all clients? */
576 for (i := 0; i < sizeof(ConnectionTable); i := i + 1) {
Neels Hofmeyrd7eabd62020-06-08 22:30:54 +0200577 if (ispresent(ConnectionTable[i].comp_ref) and ConnectionTable[i].comp_ref != null) {
Harald Welte714ded92017-12-08 14:00:22 +0100578 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[i].comp_ref;
579 }
580 }
581 }
582
Harald Welte1c02fd12018-02-19 19:20:47 +0100583 /* Forward common channel management to the special port for it */
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700584 [] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeT(?), sid := ?)) -> value rx_rsl {
Harald Welte1c02fd12018-02-19 19:20:47 +0100585 CCHAN_PT.send(rx_rsl);
Harald Welte714ded92017-12-08 14:00:22 +0100586 }
587
Harald Welte1c02fd12018-02-19 19:20:47 +0100588 /* Forward common channel management to the special port for it */
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700589 [] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeC(?), sid := ?)) -> value rx_rsl {
Harald Welte1c02fd12018-02-19 19:20:47 +0100590 CCHAN_PT.send(rx_rsl);
Harald Welte714ded92017-12-08 14:00:22 +0100591 }
592
Neels Hofmeyrad26fc02021-09-28 18:30:17 +0200593 /* Channel Activation: store in LastActTable, possibly ACK. */
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700594 [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 +0100595 chan_nr := rx_rsl.rsl.ies[0].body.chan_nr;
Harald Weltead2647b2018-03-22 19:53:55 +0100596 trx_nr := f_trx_by_streamId(rx_rsl.streamId);
597 f_store_last_act_data(trx_nr, chan_nr, rx_rsl.rsl);
Neels Hofmeyrad26fc02021-09-28 18:30:17 +0200598 if (auto_chan_act_ack) {
599 /* blindly acknowledge all channel activations */
600 IPA_PT.send(ts_ASP_RSL_UD(ts_RSL_CHAN_ACT_ACK(chan_nr, 23), rx_rsl.streamId));
601 } else {
602 CLIENT_PT.send(rx_rsl);
603 }
Harald Welte714ded92017-12-08 14:00:22 +0100604 }
605
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700606 [not dchan_suspended] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeDR(?), sid := ?)) -> value rx_rsl {
Harald Welte714ded92017-12-08 14:00:22 +0100607 /* dispatch to channel based on ChanId */
608 cid := f_cid_by_chan_nr(f_trx_by_streamId(rx_rsl.streamId),
609 rx_rsl.rsl.ies[0].body.chan_nr);
610 if (cid != -1) {
611 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref;
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700612 } else if (wait_queue_enabled) {
613 log("Storing an RSL message in the waiting queue");
614 WaitingQueue := WaitingQueue & { rx_rsl };
Harald Welte714ded92017-12-08 14:00:22 +0100615 } else {
Neels Hofmeyrc0ef35c2021-07-22 16:22:25 +0200616 log("Error: RSL for unknown Dchan (streamId ", rx_rsl.streamId, ", chan_nr ",
617 rx_rsl.rsl.ies[0].body.chan_nr, "): ", rx_rsl);
Harald Welte714ded92017-12-08 14:00:22 +0100618 setverdict(fail, "RSL for unknown Dchan");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200619 mtc.stop;
Harald Welte714ded92017-12-08 14:00:22 +0100620 }
621 }
622
Harald Welte70b52c92018-02-12 20:47:31 +0100623 [not dchan_suspended] IPA_PT.receive {
Harald Welte714ded92017-12-08 14:00:22 +0100624 setverdict(fail, "Received unknown primitive from IPA");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200625 mtc.stop;
Harald Welte714ded92017-12-08 14:00:22 +0100626 }
627
Harald Welte1c02fd12018-02-19 19:20:47 +0100628 [bts_role] CLIENT_PT.receive(RSLDC_ChanRqd:?) -> value chan_rqd sender vc_conn {
Harald Welte714ded92017-12-08 14:00:22 +0100629 /* Store the knowledge that this sender has requested a certain RQ+time */
630 f_cid_create(chan_rqd.ra, chan_rqd.fn, vc_conn);
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700631 IPA_PT.send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD(chan_rqd.ra, chan_rqd.fn)));
Harald Welte714ded92017-12-08 14:00:22 +0100632 }
633
Pau Espin Pedrol6451b042018-10-24 20:36:16 +0200634 [not bts_role] CLIENT_PT.receive(RSLDC_ChanRqd:?) -> value chan_rqd sender vc_conn {
635 /* Store the knowledge that this sender has requested a certain RQ+time */
636 f_cid_create(chan_rqd.ra, chan_rqd.fn, vc_conn);
637 }
638
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700639 /* RSL message from a component that runs on RSL_DchanHdlr */
640 [bts_role] CLIENT_PT.receive(tr_RSL_MsgType(?)) -> value rx_rsl_msg sender vc_conn {
Harald Welte714ded92017-12-08 14:00:22 +0100641 cid := f_cid_by_comp_ref(vc_conn);
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700642 IPA_PT.send(ts_ASP_RSL_UD(rx_rsl_msg, ConnectionTable[cid].stream_id));
Harald Welte714ded92017-12-08 14:00:22 +0100643 }
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700644 [not bts_role] CLIENT_PT.receive(tr_RSL_MsgType(?)) -> value rx_rsl_msg sender vc_conn {
645 cid := f_cid_by_comp_ref(vc_conn);
646 conn_id := f_trx_conn_map_resolve(ConnectionTable[cid].stream_id);
647 IPA_PT.send(ts_ASP_RSL_UD(rx_rsl_msg, ConnectionTable[cid].stream_id, conn_id));
648 }
Harald Welte714ded92017-12-08 14:00:22 +0100649
Vadim Yanitskiya120d032023-11-22 02:37:39 +0700650 /* allow the RSL_DchanHdlr components to "escape the sandbox" by sending RSL messages
651 * to other transceivers than they're bound to (determined by rx_rsl.streamId) */
652 [bts_role] CLIENT_PT.receive(tr_ASP_RSL_UD(?, sid := ?)) -> value rx_rsl {
653 IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.rsl, rx_rsl.streamId));
654 }
655 [not bts_role] CLIENT_PT.receive(tr_ASP_RSL_UD(?, sid := ?)) -> value rx_rsl {
656 conn_id := f_trx_conn_map_resolve(rx_rsl.streamId);
657 IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.rsl, rx_rsl.streamId, conn_id));
658 }
659
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700660 /* RSL message from MTC */
661 [bts_role] CCHAN_PT.receive(tr_ASP_RSL_UD(?, sid := ?)) -> value rx_rsl {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700662 IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.rsl, rx_rsl.streamId));
Harald Welte34252c52018-02-24 04:51:50 +0100663 }
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700664 [not bts_role] CCHAN_PT.receive(tr_ASP_RSL_UD(?, sid := ?)) -> value rx_rsl {
665 conn_id := f_trx_conn_map_resolve(rx_rsl.streamId);
666 IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.rsl, rx_rsl.streamId, conn_id));
667 }
Harald Welte34252c52018-02-24 04:51:50 +0100668
Harald Weltef70df652018-01-29 22:00:23 +0100669 /* explicit registration, e.g. in (non-immediate) assignment case */
670 [] RSL_PROC.getcall(RSLEM_register:{?,?,?}) -> param(trx_nr, chan_nr, vc_conn) {
671 f_cid_create_cnr(trx_nr, chan_nr, vc_conn);
Harald Weltee32ad992018-05-31 22:17:46 +0200672 RSL_PROC.reply(RSLEM_register:{trx_nr, chan_nr, vc_conn}) to vc_conn;
Harald Weltef70df652018-01-29 22:00:23 +0100673 }
674
Harald Welte1909f462018-01-29 22:29:29 +0100675 [] RSL_PROC.getcall(RSLEM_unregister:{?,?,?}) -> param(trx_nr, chan_nr, vc_conn) {
676 cid := f_cid_by_chan_nr(trx_nr, chan_nr);
677 f_cid_clear(cid);
Harald Weltee32ad992018-05-31 22:17:46 +0200678 RSL_PROC.reply(RSLEM_unregister:{trx_nr, chan_nr, vc_conn}) to vc_conn;
Harald Welte1909f462018-01-29 22:29:29 +0100679 }
680
Harald Weltee32ad992018-05-31 22:17:46 +0200681 [] RSL_PROC.getcall(RSLEM_suspend:{true}) -> sender vc_conn {
Harald Welte70b52c92018-02-12 20:47:31 +0100682 log("Suspending DChan");
683 dchan_suspended := true;
Harald Weltee32ad992018-05-31 22:17:46 +0200684 RSL_PROC.reply(RSLEM_suspend:{true}) to vc_conn;
Harald Welte70b52c92018-02-12 20:47:31 +0100685 }
686
Harald Weltee32ad992018-05-31 22:17:46 +0200687 [] RSL_PROC.getcall(RSLEM_suspend:{false}) -> sender vc_conn {
Harald Welte70b52c92018-02-12 20:47:31 +0100688 log("Resuming DChan");
689 dchan_suspended := false;
Harald Weltee32ad992018-05-31 22:17:46 +0200690 RSL_PROC.reply(RSLEM_suspend:{false}) to vc_conn;
Harald Welte70b52c92018-02-12 20:47:31 +0100691 }
Harald Welte1909f462018-01-29 22:29:29 +0100692
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700693 [not wait_queue_enabled] RSL_PROC.getcall(RSLEM_wait_queue:{true}) -> sender vc_conn {
694 wait_queue_enabled := true;
695 log("Enabled queueing of DChan messages");
696 RSL_PROC.reply(RSLEM_wait_queue:{wait_queue_enabled}) to vc_conn;
697 }
698
699 [wait_queue_enabled] RSL_PROC.getcall(RSLEM_wait_queue:{false}) -> sender vc_conn {
700 /* Dispatch stalled messages (if any) */
701 f_WaitingQueue_dispatch();
702
703 wait_queue_enabled := false;
704 log("Disabled queueing of DChan messages");
705 RSL_PROC.reply(RSLEM_wait_queue:{wait_queue_enabled}) to vc_conn;
706 }
707
708 [] RSL_PROC.getcall(RSLEM_wait_queue:{?}) -> sender vc_conn {
709 log("Queueing of DChan messages is already enabled/disabled");
710 RSL_PROC.reply(RSLEM_wait_queue:{wait_queue_enabled}) to vc_conn;
711 }
712
Harald Weltee32ad992018-05-31 22:17:46 +0200713 [] RSL_PROC.getcall(RSLEM_get_last_act:{?,?,?}) -> param(trx_nr, chan_nr) sender vc_conn {
Harald Weltead2647b2018-03-22 19:53:55 +0100714 var RSL_Message last_chan_act := f_lookup_last_act(trx_nr, chan_nr);
Harald Weltee32ad992018-05-31 22:17:46 +0200715 RSL_PROC.reply(RSLEM_get_last_act:{trx_nr, chan_nr, last_chan_act}) to vc_conn;
Harald Weltead2647b2018-03-22 19:53:55 +0100716 }
Neels Hofmeyrad26fc02021-09-28 18:30:17 +0200717
718 [] RSL_PROC.getcall(RSLEM_set_auto_chan_act_ack:{?}) -> param(auto_chan_act_ack) sender vc_conn {
719 RSL_PROC.reply(RSLEM_set_auto_chan_act_ack:{auto_chan_act_ack}) to vc_conn;
720 }
Harald Welte714ded92017-12-08 14:00:22 +0100721 }
722 }
723}
724
Daniel Willmann17f970f2018-01-17 12:03:19 +0100725private function f_conn_table_init()
726runs on RSL_Emulation_CT {
727 var integer i;
728
729 /* Initialize the ConnectionTable */
730 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
731 f_cid_clear(i);
732 }
733}
Harald Welte714ded92017-12-08 14:00:22 +0100734
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700735private function f_WaitingQueue_dispatch()
736runs on RSL_Emulation_CT {
737 var integer cid;
738
739 for (var integer i := 0; i < lengthof(WaitingQueue); i := i + 1) {
740 cid := f_cid_by_chan_nr(f_trx_by_streamId(WaitingQueue[i].streamId),
741 WaitingQueue[i].rsl.ies[0].body.chan_nr);
742 if (cid == -1) {
743 setverdict(fail, "No Dchan handler found for: ", WaitingQueue[i]);
744 mtc.stop;
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700745 }
746
747 /* Dispatch a stalled message to the appropriate handler */
748 CLIENT_PT.send(WaitingQueue[i].rsl) to ConnectionTable[cid].comp_ref;
749 }
750
751 /* All messages dispatched, clear the queue */
752 WaitingQueue := { };
753}
754
Harald Weltef70df652018-01-29 22:00:23 +0100755/* client/conn_hdlr side function to use procedure port to register stream_id/chan_nr */
Harald Welte421e4d42018-02-12 20:04:50 +0100756function f_rslem_register(uint8_t trx_nr, RslChannelNr chan_nr, RSLEM_PROC_PT PT := RSL_PROC)
757runs on RSL_DchanHdlr {
758 PT.call(RSLEM_register:{trx_nr, chan_nr, self}) {
759 [] PT.getreply(RSLEM_register:{?,?,?}) {};
Harald Weltef70df652018-01-29 22:00:23 +0100760 }
761}
762
Harald Welte1909f462018-01-29 22:29:29 +0100763/* client/conn_hdlr side function to use procedure port to unregister stream_id/chan_nr */
Harald Welte421e4d42018-02-12 20:04:50 +0100764function f_rslem_unregister(uint8_t trx_nr, RslChannelNr chan_nr, RSLEM_PROC_PT PT := RSL_PROC)
765runs on RSL_DchanHdlr {
766 PT.call(RSLEM_unregister:{trx_nr, chan_nr, self}) {
767 [] PT.getreply(RSLEM_unregister:{?,?,?}) {};
Harald Welte1909f462018-01-29 22:29:29 +0100768 }
769}
770
Vadim Yanitskiya38c2652020-06-21 19:47:00 +0700771/* suspend handling of RSL DChan messages from IPA until f_rslem_resume() is called */
Harald Welte70b52c92018-02-12 20:47:31 +0100772function f_rslem_suspend(RSLEM_PROC_PT PT)
773runs on RSL_DchanHdlr {
774 PT.call(RSLEM_suspend:{true}) {
775 [] PT.getreply(RSLEM_suspend:{true}) {};
776 }
777}
778
779/* resume handling of RSL DChan messages after f_rslem_suspend() is called */
780function f_rslem_resume(RSLEM_PROC_PT PT)
781runs on RSL_DchanHdlr {
782 PT.call(RSLEM_suspend:{false}) {
783 [] PT.getreply(RSLEM_suspend:{false}) {};
784 }
785}
786
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700787/* Enable queueing of RSL DChan messages from IPA until f_rslem_dchan_queue_disable() is called. */
788function f_rslem_dchan_queue_enable(RSLEM_PROC_PT PT := RSL_PROC)
789runs on RSL_DchanHdlr {
790 PT.call(RSLEM_wait_queue:{true}) {
791 [] PT.getreply(RSLEM_wait_queue:{true}) {};
792 }
793}
794
795/* Disable queueing of RSL DChan messages after f_rslem_dchan_queue_enable() is called.
796 * Dispatch all stalled messages to the registered handlers. Make sure that no
797 * messages for which there is no handler are left in the queue (mtc.stop if so). */
798function f_rslem_dchan_queue_dispatch(RSLEM_PROC_PT PT := RSL_PROC)
799runs on RSL_DchanHdlr {
800 PT.call(RSLEM_wait_queue:{false}) {
801 [] PT.getreply(RSLEM_wait_queue:{false}) {};
802 }
803}
804
Harald Weltead2647b2018-03-22 19:53:55 +0100805/* obtain the last RSL_CHAN_ACT message for the given chan_nr */
806function f_rslem_get_last_act(RSLEM_PROC_PT PT, uint8_t trx_nr, RslChannelNr chan_nr)
807runs on RSL_DchanHdlr return RSL_Message {
808 var RSL_Message chan_act;
809 PT.call(RSLEM_get_last_act:{trx_nr, chan_nr, -}) {
810 [] PT.getreply(RSLEM_get_last_act:{trx_nr, chan_nr, ?}) -> param(chan_act) {};
811 }
812 return chan_act;
813}
814
Neels Hofmeyrad26fc02021-09-28 18:30:17 +0200815function f_rslem_set_auto_chan_act_ack(RSLEM_PROC_PT PT, boolean enable)
816runs on RSL_DchanHdlr {
817 PT.call(RSLEM_set_auto_chan_act_ack:{enable}) {
818 [] PT.getreply(RSLEM_set_auto_chan_act_ack:{enable}) {};
819 }
820}
Harald Welte1909f462018-01-29 22:29:29 +0100821
Harald Welte714ded92017-12-08 14:00:22 +0100822}