blob: 30adfba14bc07a28b6d0dfdde524e81440ccf902 [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
139/* establish a dedicated channel using 'ra' */
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200140function f_chan_est(OCT1 ra, octetstring est_l3, template RslLinkId link_id, GsmFrameNumber fn := 23,
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200141 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 +0100142runs on RSL_DchanHdlr {
143 var RSL_Message rx_rsl;
144 var GsmRrMessage rr;
145
146 /* request a channel to be established */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200147 rsl_pt.send(ts_RSLDC_ChanRqd(ra, fn));
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200148 /* At this point the BSC sends a CHAN ACTIV which we always ACK. Checking it below. */
Harald Welte714ded92017-12-08 14:00:22 +0100149 /* expect immediate assignment */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200150 rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN, rsl_pt := rsl_pt);
Harald Welte714ded92017-12-08 14:00:22 +0100151 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200152 if (not match(rr.payload.imm_ass.chan_desc.tsc, tsc)) {
153 setverdict(fail, "Immediate Assignment: unexpected TSC in Channel Description: expected ", tsc, " got ",
154 rr.payload.imm_ass.chan_desc.tsc);
155 mtc.stop;
156 }
Harald Welte714ded92017-12-08 14:00:22 +0100157 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200158 rsl_pt.send(ts_RSL_EST_IND(g_chan_nr, valueof(link_id), est_l3));
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200159
160 /* Check above CHAN ACTIV */
Neels Hofmeyr3222e0e2021-07-20 22:25:38 +0200161 var RSL_Message chan_act := f_rslem_get_last_act(rsl_proc_pt, 0, g_chan_nr);
Neels Hofmeyrb5b7a6e2021-06-04 19:03:45 +0200162 var RSL_IE_Body ie;
163 if (f_rsl_find_ie(chan_act, RSL_IE_CHAN_IDENT, ie)) {
164 var uint3_t got_tsc := ie.chan_ident.ch_desc.v.tsc;
165 if (not match(got_tsc, tsc)) {
166 setverdict(fail, "RSL CHANnel ACTIVation: unexpected TSC in Channel Description: expected ",
167 tsc, " got ", got_tsc);
168 mtc.stop;
169 }
170 }
Harald Welte714ded92017-12-08 14:00:22 +0100171}
172
173function f_deact_chan(RSL_Cause cause) runs on RSL_DchanHdlr
174{
175 var RSL_Message rx_rsl;
176
177 RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, cause));
178 rx_rsl := f_rx_or_fail(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL));
179 /* FIXME RSL.send(ts_RSL_RF_CHAN_REL_ACK()) */
180}
181
182
183
184/***********************************************************************
185 * Main Component
186 ***********************************************************************/
187
188private type record ConnectionData {
189 /* component reference to the client component */
190 RSL_DchanHdlr comp_ref,
191 /* RSL (dedicated) Channel number we're handling */
192 uint8_t trx_nr optional,
193 IpaStreamId stream_id optional,
194 RslChannelNr chan_nr optional,
195 /* Random Reference */
196 OCT1 ra optional,
197 GsmFrameNumber ra_fn optional
198};
199
200private function f_cid_by_comp_ref(RSL_DchanHdlr comp_ref)
201runs on RSL_Emulation_CT return integer {
202 var integer i;
203 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
Pau Espin Pedrol70965092020-06-23 14:29:56 +0200204 if (ispresent(ConnectionTable[i].comp_ref) and
Harald Welte714ded92017-12-08 14:00:22 +0100205 ConnectionTable[i].comp_ref == comp_ref) {
206 return i;
207 }
208 }
Vadim Yanitskiyf79d9362020-06-03 04:06:18 +0700209 log("No Dchan handler for comp_ref=", comp_ref);
Harald Welte714ded92017-12-08 14:00:22 +0100210 return -1;
211}
212
213private function f_cid_by_chan_nr(uint8_t trx_nr, RslChannelNr chan_nr)
214runs on RSL_Emulation_CT return integer {
215 var integer i;
216 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
Pau Espin Pedrol70965092020-06-23 14:29:56 +0200217 if (ispresent(ConnectionTable[i].chan_nr) and
Harald Welte714ded92017-12-08 14:00:22 +0100218 ConnectionTable[i].chan_nr == chan_nr and ConnectionTable[i].trx_nr == trx_nr) {
219 return i;
220 }
221 }
Vadim Yanitskiyf79d9362020-06-03 04:06:18 +0700222 log("No Dchan handler for trx_nr=", trx_nr, " and chan_nr=", chan_nr);
Harald Welte714ded92017-12-08 14:00:22 +0100223 return -1;
224}
225
226private function f_cid_by_ra_fn(OCT1 ra, GsmFrameNumber fn)
227runs on RSL_Emulation_CT return integer {
228 var integer i;
229 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
230 if (ispresent(ConnectionTable[i].ra) and
231 ConnectionTable[i].ra == ra and ConnectionTable[i].ra_fn == fn) {
232 return i;
233 }
234 }
Vadim Yanitskiyf79d9362020-06-03 04:06:18 +0700235 log("No Dchan handler for ra=", ra, " and fn=", fn);
Harald Welte714ded92017-12-08 14:00:22 +0100236 return -1;
237}
238
Pau Espin Pedrol6451b042018-10-24 20:36:16 +0200239/* Matches by only RA if FN is ommited in one of the connections allocated */
240private function f_cid_by_ra_fn2(OCT1 ra, RSL_IE_FrameNumber fn)
241runs on RSL_Emulation_CT return integer {
242 var integer i;
243 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
244 if (ispresent(ConnectionTable[i].ra) and
245 ConnectionTable[i].ra == ra) {
246 if (not ispresent(ConnectionTable[i].ra_fn) or
247 fn == valueof(ts_RSL_IE_FrameNumber(ConnectionTable[i].ra_fn))) {
248 return i;
249 }
250 }
251 }
Vadim Yanitskiyf79d9362020-06-03 04:06:18 +0700252 log("No Dchan handler for ra=", ra, " and fn=", fn);
Pau Espin Pedrol6451b042018-10-24 20:36:16 +0200253 return -1;
254}
255
Harald Welte714ded92017-12-08 14:00:22 +0100256/* create an ew client with given RA and FN */
Pau Espin Pedrol6451b042018-10-24 20:36:16 +0200257private function f_cid_create(OCT1 ra, template (omit) GsmFrameNumber fn, RSL_DchanHdlr comp_ref)
Harald Welte930d0a72018-03-22 22:08:40 +0100258runs on RSL_Emulation_CT {
Harald Welte714ded92017-12-08 14:00:22 +0100259 var integer i;
260 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
Harald Weltef70df652018-01-29 22:00:23 +0100261 if (not ispresent(ConnectionTable[i].ra) and
262 not ispresent(ConnectionTable[i].trx_nr)) {
Harald Welte714ded92017-12-08 14:00:22 +0100263 ConnectionTable[i].ra := ra;
Pau Espin Pedrol6451b042018-10-24 20:36:16 +0200264 if (ispresent(fn)) {
265 ConnectionTable[i].ra_fn := valueof(fn);
266 } else {
267 ConnectionTable[i].ra_fn := omit;
268 }
Harald Welte714ded92017-12-08 14:00:22 +0100269 ConnectionTable[i].comp_ref := comp_ref;
Harald Welte930d0a72018-03-22 22:08:40 +0100270 return;
Harald Welte714ded92017-12-08 14:00:22 +0100271 }
272 }
Daniel Willmann8273fb92018-07-05 17:31:20 +0200273 testcase.stop("No free entry in conn table for ", ra, fn);
Harald Welte714ded92017-12-08 14:00:22 +0100274}
275
Vadim Yanitskiyefc94132020-05-24 04:26:45 +0700276/* create a new client with given RA and FN */
Harald Weltef70df652018-01-29 22:00:23 +0100277private function f_cid_create_cnr(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr comp_ref)
Harald Welte930d0a72018-03-22 22:08:40 +0100278runs on RSL_Emulation_CT {
Harald Weltef70df652018-01-29 22:00:23 +0100279 var integer i;
280 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
281 if (not ispresent(ConnectionTable[i].ra) and
282 not ispresent(ConnectionTable[i].trx_nr)) {
283 ConnectionTable[i].stream_id := f_streamId_by_trx(trx_nr);
284 ConnectionTable[i].trx_nr := trx_nr;
285 ConnectionTable[i].chan_nr := chan_nr;
286 ConnectionTable[i].comp_ref := comp_ref;
Harald Welte930d0a72018-03-22 22:08:40 +0100287 return;
Harald Weltef70df652018-01-29 22:00:23 +0100288 }
289 }
Daniel Willmann8273fb92018-07-05 17:31:20 +0200290 testcase.stop("No free entry in conn table for ", trx_nr, chan_nr, comp_ref);
Harald Weltef70df652018-01-29 22:00:23 +0100291}
292
293
Vadim Yanitskiyefc94132020-05-24 04:26:45 +0700294/* delete client with given RA and FN */
Harald Weltef70df652018-01-29 22:00:23 +0100295private function f_cid_delete_cnr(IpaStreamId stream_id, RslChannelNr chan_nr, RSL_DchanHdlr comp_ref)
296runs on RSL_Emulation_CT return integer {
297 var integer i;
298 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
299 if (ConnectionTable[i].comp_ref == null) {
300 continue;
301 }
302 if (ConnectionTable[i].stream_id == stream_id and
303 ConnectionTable[i].chan_nr == chan_nr and
304 ConnectionTable[i].comp_ref == comp_ref) {
305 f_cid_clear(i);
306 }
307 }
308 log("Unable to find entry to delete for ", stream_id, chan_nr, comp_ref);
309 return -1;
310}
311
312
Harald Welte714ded92017-12-08 14:00:22 +0100313private function f_cid_clear(integer cid)
314runs on RSL_Emulation_CT {
315 ConnectionTable[cid].ra := omit;
316 ConnectionTable[cid].ra_fn := omit;
Harald Welte714ded92017-12-08 14:00:22 +0100317 ConnectionTable[cid].trx_nr := omit;
318 ConnectionTable[cid].stream_id := omit;
319 ConnectionTable[cid].chan_nr := omit;
Harald Weltef70df652018-01-29 22:00:23 +0100320 ConnectionTable[cid].comp_ref := null;
Harald Welte714ded92017-12-08 14:00:22 +0100321}
322
Harald Weltead2647b2018-03-22 19:53:55 +0100323/* last activation for a given channel number */
324type record LastActData {
325 uint8_t trx_nr optional,
326 RslChannelNr chan_nr optional,
327 RSL_Message chan_act optional
328}
329
330private function f_store_last_act_data(uint8_t trx_nr, RslChannelNr chan_nr, RSL_Message chan_act)
331runs on RSL_Emulation_CT {
332 for (var integer i := 0; i < sizeof(LastActTable); i := i+1) {
333 if (not ispresent(LastActTable[i].chan_nr) or
334 (LastActTable[i].chan_nr == chan_nr and LastActTable[i].trx_nr == trx_nr)) {
335 LastActTable[i].trx_nr := trx_nr;
336 LastActTable[i].chan_nr := chan_nr;
337 LastActTable[i].chan_act := chan_act;
338 return;
339 }
340 }
Daniel Willmann8273fb92018-07-05 17:31:20 +0200341 testcase.stop("No space left in LastActTable to store chan_act for ", chan_nr);
Harald Weltead2647b2018-03-22 19:53:55 +0100342}
343
344private function f_lookup_last_act(uint8_t trx_nr, RslChannelNr chan_nr)
345runs on RSL_Emulation_CT return RSL_Message {
346 for (var integer i := 0; i < sizeof(LastActTable); i := i+1) {
347 if (ispresent(LastActTable[i].chan_nr) and LastActTable[i].chan_nr == chan_nr
348 and LastActTable[i].trx_nr == trx_nr) {
349 return LastActTable[i].chan_act;
350 }
351 }
Daniel Willmann8273fb92018-07-05 17:31:20 +0200352 testcase.stop("No LastActTable entry found for TRX ", trx_nr, " ", chan_nr);
Harald Weltead2647b2018-03-22 19:53:55 +0100353}
354
355private function f_last_act_table_init() runs on RSL_Emulation_CT {
356 for (var integer i := 0; i < sizeof(LastActTable); i := i+1) {
357 LastActTable[i] := { omit, omit, omit };
358 }
359}
360
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700361private function f_trx_conn_map_init()
362runs on RSL_Emulation_CT {
363 for (var integer i := 0; i < sizeof(TrxConnMap); i := i + 1) {
364 TrxConnMap[i] := -1;
365 }
366}
367
368private function f_trx_conn_map_register(integer conn_id, in IpaCcmIdResp id_resp)
369runs on RSL_Emulation_CT return IpaStreamId {
370 var template charstring unit_id_fmt := pattern "(\d+)/(\d+)/(\d+)";
371 var charstring unit_id;
372 var integer trx_nr;
373 var integer idx;
374
375 /* Check if we have room for a new connection */
376 if (TrxConnNum >= sizeof(TrxConnMap)) {
377 testcase.stop("We cannot handle more than ", sizeof(TrxConnMap), " transceivers");
378 }
379
380 /* Find IPAC_IDTAG_UNITID in the IPA IDENTITY RESPONSE */
381 idx := f_ipa_id_resp_find_ie(id_resp, IPAC_IDTAG_UNITID);
382 if (idx < 0) {
383 testcase.stop("IPA IDENTITY RESPONSE contains no unit-id");
384 }
385
386 /* Make sure that IPA unit-id is valid */
387 unit_id := oct2char(id_resp[idx].data);
388 if (not match(unit_id, unit_id_fmt)) {
389 testcase.stop("IPA unit-id has unknown/unexpected format");
390 }
391
392 /* Parse transceiver number (site/bts/trx).
393 * TODO: implement and use declaratice types. */
394 unit_id := regexp(unit_id, unit_id_fmt, 2);
395 trx_nr := str2int(unit_id);
396
397 if (trx_nr >= sizeof(TrxConnMap)) {
398 testcase.stop("Transceiver #", trx_nr, " does not fit");
399 } else if (TrxConnMap[trx_nr] != -1) {
400 testcase.stop("Transceiver #", trx_nr, " is already connected?!?");
401 }
402
403 /* Finally, store the connection ID */
404 log("Mapped TRX#", trx_nr, " to TCP/IP conn_id=", conn_id);
405 TrxConnMap[trx_nr] := conn_id;
406 TrxConnNum := TrxConnNum + 1;
407
408 return f_streamId_by_trx(trx_nr);
409}
410
Pau Espin Pedrolabcdf782020-06-23 14:29:24 +0200411private function f_trx_conn_map_unregister(integer conn_id)
412runs on RSL_Emulation_CT return IpaStreamId {
413
414 for (var integer i := 0; i < sizeof(TrxConnMap); i := i + 1) {
415 if (conn_id == TrxConnMap[i]) {
416 TrxConnMap[i] := -1;
417 TrxConnNum := TrxConnNum - 1;
418 return f_streamId_by_trx(i);
419 }
420 }
421
422 testcase.stop("Trying to unregister an unknown conn_id=", conn_id);
423}
424
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700425private function f_trx_conn_map_resolve(IpaStreamId id)
426runs on RSL_Emulation_CT return integer {
427 var integer trx_nr := f_trx_by_streamId(id);
428
429 if (TrxConnMap[trx_nr] == -1) {
430 testcase.stop("Transceiver #", trx_nr, " is not connected");
431 }
432
433 return TrxConnMap[trx_nr];
434}
435
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700436private type record of ASP_RSL_Unitdata ASP_RSL_UDList;
437
Harald Welte714ded92017-12-08 14:00:22 +0100438type component RSL_Emulation_CT {
439 /* port facing down towards IPA emulation */
440 port IPA_RSL_PT IPA_PT;
441 /* port facing up towards dedicated channel handler */
442 port RSL_DCHAN_PT CLIENT_PT;
Harald Weltef70df652018-01-29 22:00:23 +0100443 port RSLEM_PROC_PT RSL_PROC;
Harald Welte714ded92017-12-08 14:00:22 +0100444
Harald Welte1c02fd12018-02-19 19:20:47 +0100445 /* port for Common Channel / TRX Management */
446 port RSL_CCHAN_PT CCHAN_PT;
447
Harald Welte714ded92017-12-08 14:00:22 +0100448 /* state of all concurrent connections / dedicated channels */
449 var ConnectionData ConnectionTable[64];
Harald Weltead2647b2018-03-22 19:53:55 +0100450
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700451 /* RSL messages for which no handler is currently registered */
452 var ASP_RSL_UDList WaitingQueue := { };
453
Harald Weltead2647b2018-03-22 19:53:55 +0100454 /* last RSL CHAN ACT for each chan_nr */
455 var LastActData LastActTable[64];
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700456
457 /* IPA stream ID -> TCP/IP connection ID mapping for transceivers */
458 var integer TrxConnNum := 0; /* number of connected transceivers */
459 var integer TrxConnMap[4]; /* up to 4 transceivers for now */
Harald Welte714ded92017-12-08 14:00:22 +0100460}
461
462
Harald Welte714ded92017-12-08 14:00:22 +0100463private function f_trx_by_streamId(IpaStreamId id) return integer {
464 return enum2int(id);
465}
466
Harald Weltef70df652018-01-29 22:00:23 +0100467private function f_streamId_by_trx(uint8_t trx_nr) return IpaStreamId {
468 select (trx_nr) {
469 case (0) { return IPAC_PROTO_RSL_TRX0; }
470 case (1) { return IPAC_PROTO_RSL_TRX1; }
471 case (2) { return IPAC_PROTO_RSL_TRX2; }
472 case (3) { return IPAC_PROTO_RSL_TRX3; }
473 }
Daniel Willmanna6ea2ef2018-07-24 09:55:52 +0200474 setverdict(fail, "Unknown stream ID ", trx_nr);
475 mtc.stop;
Harald Weltef70df652018-01-29 22:00:23 +0100476}
477
Harald Welte714ded92017-12-08 14:00:22 +0100478
Harald Welte1c02fd12018-02-19 19:20:47 +0100479function main(boolean bts_role := true) runs on RSL_Emulation_CT {
Harald Weltebb6aed32018-02-21 12:19:18 +0100480 var ASP_IPA_Event evt;
Harald Welte714ded92017-12-08 14:00:22 +0100481 var ASP_RSL_Unitdata rx_rsl;
482 var RSL_Message rx_rsl_msg;
483 var RSLDC_ChanRqd chan_rqd;
484 var RSL_DchanHdlr vc_conn;
Harald Weltef70df652018-01-29 22:00:23 +0100485 var RslChannelNr chan_nr;
486 var uint8_t trx_nr;
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700487 var integer conn_id;
Harald Welte714ded92017-12-08 14:00:22 +0100488 var integer cid;
489 var integer i;
Harald Welte70b52c92018-02-12 20:47:31 +0100490 /* special synchronization handling during hand-over */
491 var boolean dchan_suspended := false;
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700492 /* Whether to keep RSL messages, for which no handler is found in ConnectionTable,
493 * in a queue. These messages will remain in the queue until the appropriate
494 * connection handler is registered. */
495 var boolean wait_queue_enabled := false;
Neels Hofmeyrad26fc02021-09-28 18:30:17 +0200496 var boolean auto_chan_act_ack := true;
Harald Welte714ded92017-12-08 14:00:22 +0100497
Daniel Willmann17f970f2018-01-17 12:03:19 +0100498 f_conn_table_init();
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700499 f_trx_conn_map_init();
Harald Weltead2647b2018-03-22 19:53:55 +0100500 f_last_act_table_init();
Daniel Willmann17f970f2018-01-17 12:03:19 +0100501
Harald Welte714ded92017-12-08 14:00:22 +0100502 while (true) {
503 alt {
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700504 [bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_UP)) {
Harald Weltebb6aed32018-02-21 12:19:18 +0100505 }
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700506 [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_UP)) -> value evt {
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700507 log("A new IPA/RSL connection has been established (conn_id=",
508 evt.conn_id, "), waiting for IDENTITY RESPONSE...");
509 }
510 [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_RESP)) -> value evt {
511 log("Got IDENTITY RESPONSE (conn_id=", evt.conn_id, "): ", evt.id_resp);
512 /* Update [ IPA stream ID -> TCP/IP connection ID ] mapping */
513 var IpaStreamId sid := f_trx_conn_map_register(evt.conn_id, evt.id_resp);
514 /* Notify the upper layers about a new connection */
515 CCHAN_PT.send(ts_RSLEm_EV(RSLEM_EV_TRX_UP, sid));
Harald Welte624f9632017-12-16 19:26:04 +0100516 }
Pau Espin Pedrolabcdf782020-06-23 14:29:24 +0200517 [bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) -> value evt {
518 log("Lost IPA connection! (conn_id=", evt.conn_id, "): ", evt.id_resp);
519 /* Notify the upper layers about lost connection */
520 var IpaStreamId sid := f_trx_conn_map_unregister(evt.conn_id);
521 CCHAN_PT.send(ts_RSLEm_EV(RSLEM_EV_TRX_DOWN, sid));
Pau Espin Pedrola07cfd92018-10-22 15:54:41 +0200522 }
Pau Espin Pedrolabcdf782020-06-23 14:29:24 +0200523 [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_DOWN)) -> value evt {
524 log("Lost IPA connection! (conn_id=", evt.conn_id, ")");
525 /* Notify the upper layers about lost connection */
526 var IpaStreamId sid := f_trx_conn_map_unregister(evt.conn_id);
527 CCHAN_PT.send(ts_RSLEm_EV(RSLEM_EV_TRX_DOWN, sid));
Pau Espin Pedrola07cfd92018-10-22 15:54:41 +0200528 }
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700529 [bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) {
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700530 IPA_PT.send(ts_ASP_RSL_UD(ts_RSL_PAGING_LOAD_IND(23)));
Harald Welte714ded92017-12-08 14:00:22 +0100531 }
Vadim Yanitskiya2afacc2020-05-18 21:16:19 +0700532 [not bts_role] IPA_PT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_ID_ACK)) { }
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700533 [bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_IMM_ASSIGN, sid := ?)) -> value rx_rsl {
Harald Welte714ded92017-12-08 14:00:22 +0100534 var GsmRrMessage rr;
535 var OCT1 ra;
536 var GsmFrameNumber fn;
Harald Welte714ded92017-12-08 14:00:22 +0100537 rr := dec_GsmRrMessage(rx_rsl.rsl.ies[1].body.full_imm_ass_info.payload);
538 if (ischosen(rr.payload.imm_ass)) {
539 ra := bit2oct(rr.payload.imm_ass.req_ref.ra);
540 fn := 23; //FIXME(rr.payload.imm_ass);
541 /* lookup client based on RA+time, deliver to client */
542 cid := f_cid_by_ra_fn(ra, fn);
543 if (cid == -1) {
544 setverdict(fail, "IMM ASS for unknown DChan");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200545 mtc.stop;
Harald Welte714ded92017-12-08 14:00:22 +0100546 }
547 /* update client with trx_nr */
548 ConnectionTable[cid].trx_nr := f_trx_by_streamId(rx_rsl.streamId);
549 ConnectionTable[cid].stream_id := rx_rsl.streamId;
550 /* update client with chan_nr */
551 ConnectionTable[cid].chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
552 /* TODO: add timer to time-out ConnectionTable entries which
553 * never get followed-up to */
554 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref;
555 } else if (ischosen(rr.payload.imm_ass_rej)) {
556 for (i := 0; i < sizeof(rr.payload.imm_ass_rej.payload); i := i + 1) {
557 ra := bit2oct(rr.payload.imm_ass_rej.payload[i].req_ref.ra);
558 fn := 23; //FIXME();
559 /* lookup client based on RA+time, deliver to client */
560 cid := f_cid_by_ra_fn(ra, fn);
561 if (cid != -1) {
562 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref;
563 /* delete ClientTable entry, as it failed */
564 f_cid_clear(cid);
565 }
566 }
567 }
568 }
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700569 [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 +0200570 var RSL_IE_RequestRef req_ref;
571 req_ref := rx_rsl.rsl.ies[1].body.req_ref;
572 cid := f_cid_by_ra_fn2(req_ref.ra, req_ref.frame_nr);
573 if (cid != -1) {
574 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref;
575 f_cid_clear(cid);
576 } else {
577 CCHAN_PT.send(rx_rsl);
578 }
579 }
Harald Welte714ded92017-12-08 14:00:22 +0100580
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700581 [bts_role] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_PAGING_CMD(?, ?), sid := ?)) -> value rx_rsl {
Harald Welte714ded92017-12-08 14:00:22 +0100582 /* broadcast to all clients? */
583 for (i := 0; i < sizeof(ConnectionTable); i := i + 1) {
Neels Hofmeyrd7eabd62020-06-08 22:30:54 +0200584 if (ispresent(ConnectionTable[i].comp_ref) and ConnectionTable[i].comp_ref != null) {
Harald Welte714ded92017-12-08 14:00:22 +0100585 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[i].comp_ref;
586 }
587 }
588 }
589
Harald Welte1c02fd12018-02-19 19:20:47 +0100590 /* Forward common channel management to the special port for it */
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700591 [] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeT(?), sid := ?)) -> value rx_rsl {
Harald Welte1c02fd12018-02-19 19:20:47 +0100592 CCHAN_PT.send(rx_rsl);
Harald Welte714ded92017-12-08 14:00:22 +0100593 }
594
Harald Welte1c02fd12018-02-19 19:20:47 +0100595 /* Forward common channel management to the special port for it */
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700596 [] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeC(?), sid := ?)) -> value rx_rsl {
Harald Welte1c02fd12018-02-19 19:20:47 +0100597 CCHAN_PT.send(rx_rsl);
Harald Welte714ded92017-12-08 14:00:22 +0100598 }
599
Neels Hofmeyrad26fc02021-09-28 18:30:17 +0200600 /* Channel Activation: store in LastActTable, possibly ACK. */
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700601 [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 +0100602 chan_nr := rx_rsl.rsl.ies[0].body.chan_nr;
Harald Weltead2647b2018-03-22 19:53:55 +0100603 trx_nr := f_trx_by_streamId(rx_rsl.streamId);
604 f_store_last_act_data(trx_nr, chan_nr, rx_rsl.rsl);
Neels Hofmeyrad26fc02021-09-28 18:30:17 +0200605 if (auto_chan_act_ack) {
606 /* blindly acknowledge all channel activations */
607 IPA_PT.send(ts_ASP_RSL_UD(ts_RSL_CHAN_ACT_ACK(chan_nr, 23), rx_rsl.streamId));
608 } else {
609 CLIENT_PT.send(rx_rsl);
610 }
Harald Welte714ded92017-12-08 14:00:22 +0100611 }
612
Vadim Yanitskiya60e5cf2020-05-26 01:46:31 +0700613 [not dchan_suspended] IPA_PT.receive(tr_ASP_RSL_UD(tr_RSL_MsgTypeDR(?), sid := ?)) -> value rx_rsl {
Harald Welte714ded92017-12-08 14:00:22 +0100614 /* dispatch to channel based on ChanId */
615 cid := f_cid_by_chan_nr(f_trx_by_streamId(rx_rsl.streamId),
616 rx_rsl.rsl.ies[0].body.chan_nr);
617 if (cid != -1) {
618 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref;
Vadim Yanitskiye9c06352020-06-20 01:30:58 +0700619 } else if (wait_queue_enabled) {
620 log("Storing an RSL message in the waiting queue");
621 WaitingQueue := WaitingQueue & { rx_rsl };
Harald Welte714ded92017-12-08 14:00:22 +0100622 } else {
Neels Hofmeyrc0ef35c2021-07-22 16:22:25 +0200623 log("Error: RSL for unknown Dchan (streamId ", rx_rsl.streamId, ", chan_nr ",
624 rx_rsl.rsl.ies[0].body.chan_nr, "): ", rx_rsl);
Harald Welte714ded92017-12-08 14:00:22 +0100625 setverdict(fail, "RSL for unknown Dchan");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200626 mtc.stop;
Harald Welte714ded92017-12-08 14:00:22 +0100627 }
628 }
629
Harald Welte70b52c92018-02-12 20:47:31 +0100630 [not dchan_suspended] IPA_PT.receive {
Harald Welte714ded92017-12-08 14:00:22 +0100631 setverdict(fail, "Received unknown primitive from IPA");
Daniel Willmanne4ff5372018-07-05 17:35:03 +0200632 mtc.stop;
Harald Welte714ded92017-12-08 14:00:22 +0100633 }
634
Harald Welte1c02fd12018-02-19 19:20:47 +0100635 [bts_role] CLIENT_PT.receive(RSLDC_ChanRqd:?) -> value chan_rqd sender vc_conn {
Harald Welte714ded92017-12-08 14:00:22 +0100636 /* Store the knowledge that this sender has requested a certain RQ+time */
637 f_cid_create(chan_rqd.ra, chan_rqd.fn, vc_conn);
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700638 IPA_PT.send(ts_ASP_RSL_UD(ts_RSL_CHAN_RQD(chan_rqd.ra, chan_rqd.fn)));
Harald Welte714ded92017-12-08 14:00:22 +0100639 }
640
Pau Espin Pedrol6451b042018-10-24 20:36:16 +0200641 [not bts_role] CLIENT_PT.receive(RSLDC_ChanRqd:?) -> value chan_rqd sender vc_conn {
642 /* Store the knowledge that this sender has requested a certain RQ+time */
643 f_cid_create(chan_rqd.ra, chan_rqd.fn, vc_conn);
644 }
645
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700646 /* RSL message from a component that runs on RSL_DchanHdlr */
647 [bts_role] CLIENT_PT.receive(tr_RSL_MsgType(?)) -> value rx_rsl_msg sender vc_conn {
Harald Welte714ded92017-12-08 14:00:22 +0100648 cid := f_cid_by_comp_ref(vc_conn);
Vadim Yanitskiy9b4e3562020-05-25 21:40:52 +0700649 IPA_PT.send(ts_ASP_RSL_UD(rx_rsl_msg, ConnectionTable[cid].stream_id));
Harald Welte714ded92017-12-08 14:00:22 +0100650 }
Neels Hofmeyr1470fc62021-05-25 21:35:46 +0000651 [bts_role] CLIENT_PT.receive(tr_ASP_RSL_UD(?, sid := ?)) -> value rx_rsl {
652 IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.rsl, rx_rsl.streamId));
653 }
Vadim Yanitskiy6de2fcb2020-05-25 19:40:45 +0700654 [not bts_role] CLIENT_PT.receive(tr_RSL_MsgType(?)) -> value rx_rsl_msg sender vc_conn {
655 cid := f_cid_by_comp_ref(vc_conn);
656 conn_id := f_trx_conn_map_resolve(ConnectionTable[cid].stream_id);
657 IPA_PT.send(ts_ASP_RSL_UD(rx_rsl_msg, ConnectionTable[cid].stream_id, conn_id));
658 }
Harald Welte714ded92017-12-08 14:00:22 +0100659
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}