blob: 20a54a978cfee3038663d6e2c809703164b574c1 [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.
24 */
25
Harald Welte714ded92017-12-08 14:00:22 +010026import from General_Types all;
27import from Osmocom_Types all;
28import from GSM_Types all;
29import from GSM_RR_Types all;
30import from RSL_Types all;
31import from IPA_Types all;
32import from IPA_Emulation all;
33
34
35/* General "base class" component definition, of which specific implementations
36 * derive themselves by means of the "extends" feature */
37type component RSL_DchanHdlr {
38 /* port facing up towards dedicated channel handler */
39 port RSL_DCHAN_PT RSL;
Harald Weltef70df652018-01-29 22:00:23 +010040 port RSLEM_PROC_PT RSL_PROC;
Harald Welte714ded92017-12-08 14:00:22 +010041 var RslChannelNr g_chan_nr;
Harald Welte421e4d42018-02-12 20:04:50 +010042 /* second BTS / DChan during hand-over */
43 port RSL_DCHAN_PT RSL1;
44 port RSLEM_PROC_PT RSL1_PROC;
Harald Welte714ded92017-12-08 14:00:22 +010045};
46
47type record RSLDC_ChanRqd {
48 OCT1 ra,
49 GsmFrameNumber fn
50};
51
52template RSLDC_ChanRqd ts_RSLDC_ChanRqd(OCT1 ra, GsmFrameNumber fn) := {
53 ra := ra,
54 fn := fn
55}
56
57type port RSL_DCHAN_PT message {
58 inout RSLDC_ChanRqd, RSL_Message;
59} with { extension "internal" };
60
Harald Welte1c02fd12018-02-19 19:20:47 +010061type port RSL_CCHAN_PT message {
Harald Weltebb6aed32018-02-21 12:19:18 +010062 inout ASP_RSL_Unitdata, ASP_IPA_Event;
Harald Welte1c02fd12018-02-19 19:20:47 +010063} with { extension "internal" };
64
65
Harald Weltef70df652018-01-29 22:00:23 +010066signature RSLEM_register(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr hdlr);
Harald Welte1909f462018-01-29 22:29:29 +010067signature RSLEM_unregister(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr hdlr);
Harald Welte70b52c92018-02-12 20:47:31 +010068signature RSLEM_suspend(boolean suspend);
Harald Weltead2647b2018-03-22 19:53:55 +010069signature RSLEM_get_last_act(in uint8_t trx_nr, in RslChannelNr chan_nr, out RSL_Message chan_act);
Harald Weltef70df652018-01-29 22:00:23 +010070
71type port RSLEM_PROC_PT procedure {
Harald Weltead2647b2018-03-22 19:53:55 +010072 inout RSLEM_register, RSLEM_unregister, RSLEM_suspend, RSLEM_get_last_act;
Harald Weltef70df652018-01-29 22:00:23 +010073} with { extension "internal" };
74
Harald Welte714ded92017-12-08 14:00:22 +010075/***********************************************************************
76 * Client Component for a single dedicated channel
77 ***********************************************************************/
78
79private function f_rx_or_fail(template RSL_Message exp_rx) runs on RSL_DchanHdlr return RSL_Message
80{
81 var RSL_Message rx_rsl;
82 timer T := 10.0;
83
84 /* request a channel to be established */
85 T.start;
86 alt {
87 [] RSL.receive(exp_rx) -> value rx_rsl {
88 T.stop;
89 return rx_rsl;
90 }
91 [] RSL.receive {
92 setverdict(fail, "Unexpected RSL message on DCHAN");
93 self.stop;
94 }
95 [] T.timeout {
96 setverdict(fail, "Timeout waiting for RSL on DCHAN");
97 self.stop;
98 }
99 }
100 /* never reached */
101 return rx_rsl;
102}
103
104/* establish a dedicated channel using 'ra' */
105function f_chan_est(OCT1 ra, octetstring est_l3, template RslLinkId link_id, GsmFrameNumber fn := 23)
106runs on RSL_DchanHdlr {
107 var RSL_Message rx_rsl;
108 var GsmRrMessage rr;
109
110 /* request a channel to be established */
111 RSL.send(ts_RSLDC_ChanRqd(ra, fn));
112 /* expect immediate assignment */
113 rx_rsl := f_rx_or_fail(tr_RSL_IMM_ASSIGN);
114 rr := dec_GsmRrMessage(rx_rsl.ies[1].body.full_imm_ass_info.payload);
115 g_chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
116 RSL.send(ts_RSL_EST_IND(g_chan_nr, valueof(link_id), est_l3));
117}
118
119function f_deact_chan(RSL_Cause cause) runs on RSL_DchanHdlr
120{
121 var RSL_Message rx_rsl;
122
123 RSL.send(ts_RSL_CONN_FAIL_IND(g_chan_nr, cause));
124 rx_rsl := f_rx_or_fail(tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL));
125 /* FIXME RSL.send(ts_RSL_RF_CHAN_REL_ACK()) */
126}
127
128
129
130/***********************************************************************
131 * Main Component
132 ***********************************************************************/
133
134private type record ConnectionData {
135 /* component reference to the client component */
136 RSL_DchanHdlr comp_ref,
137 /* RSL (dedicated) Channel number we're handling */
138 uint8_t trx_nr optional,
139 IpaStreamId stream_id optional,
140 RslChannelNr chan_nr optional,
141 /* Random Reference */
142 OCT1 ra optional,
143 GsmFrameNumber ra_fn optional
144};
145
146private function f_cid_by_comp_ref(RSL_DchanHdlr comp_ref)
147runs on RSL_Emulation_CT return integer {
148 var integer i;
149 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
150 if (ispresent(ConnectionTable[i].comp_ref) and
151 ConnectionTable[i].comp_ref == comp_ref) {
152 return i;
153 }
154 }
155 log("No Dchan handler for ", comp_ref);
156 return -1;
157}
158
159private function f_cid_by_chan_nr(uint8_t trx_nr, RslChannelNr chan_nr)
160runs on RSL_Emulation_CT return integer {
161 var integer i;
162 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
163 if (ispresent(ConnectionTable[i].chan_nr) and
164 ConnectionTable[i].chan_nr == chan_nr and ConnectionTable[i].trx_nr == trx_nr) {
165 return i;
166 }
167 }
168 log("No Dchan handler for ", trx_nr, chan_nr);
169 return -1;
170}
171
172private function f_cid_by_ra_fn(OCT1 ra, GsmFrameNumber fn)
173runs on RSL_Emulation_CT return integer {
174 var integer i;
175 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
176 if (ispresent(ConnectionTable[i].ra) and
177 ConnectionTable[i].ra == ra and ConnectionTable[i].ra_fn == fn) {
178 return i;
179 }
180 }
181 log("No Dchan handler for ", ra, fn);
182 return -1;
183}
184
185/* create an ew client with given RA and FN */
186private function f_cid_create(OCT1 ra, GsmFrameNumber fn, RSL_DchanHdlr comp_ref)
187runs on RSL_Emulation_CT return integer {
188 var integer i;
189 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
Harald Weltef70df652018-01-29 22:00:23 +0100190 if (not ispresent(ConnectionTable[i].ra) and
191 not ispresent(ConnectionTable[i].trx_nr)) {
Harald Welte714ded92017-12-08 14:00:22 +0100192 ConnectionTable[i].ra := ra;
193 ConnectionTable[i].ra_fn := fn;
194 ConnectionTable[i].comp_ref := comp_ref;
195 return i;
196 }
197 }
198 log("No free entry in conn table for ", ra, fn);
199 return -1;
200}
201
Harald Weltef70df652018-01-29 22:00:23 +0100202/* create an ew client with given RA and FN */
203private function f_cid_create_cnr(uint8_t trx_nr, RslChannelNr chan_nr, 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) {
207 if (not ispresent(ConnectionTable[i].ra) and
208 not ispresent(ConnectionTable[i].trx_nr)) {
209 ConnectionTable[i].stream_id := f_streamId_by_trx(trx_nr);
210 ConnectionTable[i].trx_nr := trx_nr;
211 ConnectionTable[i].chan_nr := chan_nr;
212 ConnectionTable[i].comp_ref := comp_ref;
213 return i;
214 }
215 }
216 log("No free entry in conn table for ", trx_nr, chan_nr, comp_ref);
217 return -1;
218}
219
220
221/* create an ew client with given RA and FN */
222private function f_cid_delete_cnr(IpaStreamId stream_id, RslChannelNr chan_nr, RSL_DchanHdlr comp_ref)
223runs on RSL_Emulation_CT return integer {
224 var integer i;
225 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
226 if (ConnectionTable[i].comp_ref == null) {
227 continue;
228 }
229 if (ConnectionTable[i].stream_id == stream_id and
230 ConnectionTable[i].chan_nr == chan_nr and
231 ConnectionTable[i].comp_ref == comp_ref) {
232 f_cid_clear(i);
233 }
234 }
235 log("Unable to find entry to delete for ", stream_id, chan_nr, comp_ref);
236 return -1;
237}
238
239
Harald Welte714ded92017-12-08 14:00:22 +0100240private function f_cid_clear(integer cid)
241runs on RSL_Emulation_CT {
242 ConnectionTable[cid].ra := omit;
243 ConnectionTable[cid].ra_fn := omit;
Harald Welte714ded92017-12-08 14:00:22 +0100244 ConnectionTable[cid].trx_nr := omit;
245 ConnectionTable[cid].stream_id := omit;
246 ConnectionTable[cid].chan_nr := omit;
Harald Weltef70df652018-01-29 22:00:23 +0100247 ConnectionTable[cid].comp_ref := null;
Harald Welte714ded92017-12-08 14:00:22 +0100248}
249
Harald Weltead2647b2018-03-22 19:53:55 +0100250/* last activation for a given channel number */
251type record LastActData {
252 uint8_t trx_nr optional,
253 RslChannelNr chan_nr optional,
254 RSL_Message chan_act optional
255}
256
257private function f_store_last_act_data(uint8_t trx_nr, RslChannelNr chan_nr, RSL_Message chan_act)
258runs on RSL_Emulation_CT {
259 for (var integer i := 0; i < sizeof(LastActTable); i := i+1) {
260 if (not ispresent(LastActTable[i].chan_nr) or
261 (LastActTable[i].chan_nr == chan_nr and LastActTable[i].trx_nr == trx_nr)) {
262 LastActTable[i].trx_nr := trx_nr;
263 LastActTable[i].chan_nr := chan_nr;
264 LastActTable[i].chan_act := chan_act;
265 return;
266 }
267 }
268 setverdict(fail, "No space left in LastActTable to store chan_act for ", chan_nr);
269 self.stop;
270}
271
272private function f_lookup_last_act(uint8_t trx_nr, RslChannelNr chan_nr)
273runs on RSL_Emulation_CT return RSL_Message {
274 for (var integer i := 0; i < sizeof(LastActTable); i := i+1) {
275 if (ispresent(LastActTable[i].chan_nr) and LastActTable[i].chan_nr == chan_nr
276 and LastActTable[i].trx_nr == trx_nr) {
277 return LastActTable[i].chan_act;
278 }
279 }
280 setverdict(fail, "No LastActTable entry found for TRX ", trx_nr, " ", chan_nr);
281 self.stop;
282}
283
284private function f_last_act_table_init() runs on RSL_Emulation_CT {
285 for (var integer i := 0; i < sizeof(LastActTable); i := i+1) {
286 LastActTable[i] := { omit, omit, omit };
287 }
288}
289
Harald Welte714ded92017-12-08 14:00:22 +0100290type component RSL_Emulation_CT {
291 /* port facing down towards IPA emulation */
292 port IPA_RSL_PT IPA_PT;
293 /* port facing up towards dedicated channel handler */
294 port RSL_DCHAN_PT CLIENT_PT;
Harald Weltef70df652018-01-29 22:00:23 +0100295 port RSLEM_PROC_PT RSL_PROC;
Harald Welte714ded92017-12-08 14:00:22 +0100296
Harald Welte1c02fd12018-02-19 19:20:47 +0100297 /* port for Common Channel / TRX Management */
298 port RSL_CCHAN_PT CCHAN_PT;
299
Harald Welte714ded92017-12-08 14:00:22 +0100300 /* state of all concurrent connections / dedicated channels */
301 var ConnectionData ConnectionTable[64];
Harald Weltead2647b2018-03-22 19:53:55 +0100302
303 /* last RSL CHAN ACT for each chan_nr */
304 var LastActData LastActTable[64];
Harald Welte714ded92017-12-08 14:00:22 +0100305}
306
307
308/* template for an ASP_RSL_Unitdata as we receive it from the IPA_Emulateion component */
309private template ASP_RSL_Unitdata tr_RSL(template RSL_Message rsl, template IpaStreamId sid := ?) := {
310 streamId := sid,
311 rsl := rsl
312}
313
Harald Welte714ded92017-12-08 14:00:22 +0100314private function f_trx_by_streamId(IpaStreamId id) return integer {
315 return enum2int(id);
316}
317
Harald Weltef70df652018-01-29 22:00:23 +0100318private function f_streamId_by_trx(uint8_t trx_nr) return IpaStreamId {
319 select (trx_nr) {
320 case (0) { return IPAC_PROTO_RSL_TRX0; }
321 case (1) { return IPAC_PROTO_RSL_TRX1; }
322 case (2) { return IPAC_PROTO_RSL_TRX2; }
323 case (3) { return IPAC_PROTO_RSL_TRX3; }
324 }
325 self.stop;
326}
327
Harald Welte714ded92017-12-08 14:00:22 +0100328
Harald Welte1c02fd12018-02-19 19:20:47 +0100329function main(boolean bts_role := true) runs on RSL_Emulation_CT {
Harald Weltebb6aed32018-02-21 12:19:18 +0100330 var ASP_IPA_Event evt;
Harald Welte714ded92017-12-08 14:00:22 +0100331 var ASP_RSL_Unitdata rx_rsl;
332 var RSL_Message rx_rsl_msg;
333 var RSLDC_ChanRqd chan_rqd;
334 var RSL_DchanHdlr vc_conn;
Harald Weltef70df652018-01-29 22:00:23 +0100335 var RslChannelNr chan_nr;
336 var uint8_t trx_nr;
Harald Welte714ded92017-12-08 14:00:22 +0100337 var integer cid;
338 var integer i;
Harald Welte70b52c92018-02-12 20:47:31 +0100339 /* special synchronization handling during hand-over */
340 var boolean dchan_suspended := false;
Harald Welte714ded92017-12-08 14:00:22 +0100341
Daniel Willmann17f970f2018-01-17 12:03:19 +0100342 f_conn_table_init();
Harald Weltead2647b2018-03-22 19:53:55 +0100343 f_last_act_table_init();
Daniel Willmann17f970f2018-01-17 12:03:19 +0100344
Harald Welte714ded92017-12-08 14:00:22 +0100345 while (true) {
346 alt {
Harald Weltebb6aed32018-02-21 12:19:18 +0100347 [bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP}) {
348 }
349 [not bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP}) -> value evt {
350 CCHAN_PT.send(evt);
Harald Welte624f9632017-12-16 19:26:04 +0100351 }
Harald Welte1c02fd12018-02-19 19:20:47 +0100352 [bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) {
Harald Welte7ae019e2017-12-09 00:54:15 +0100353 IPA_PT.send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23)));
Harald Welte714ded92017-12-08 14:00:22 +0100354 }
Harald Welte1c02fd12018-02-19 19:20:47 +0100355 [bts_role] IPA_PT.receive(tr_RSL(tr_RSL_IMM_ASSIGN)) -> value rx_rsl {
Harald Welte714ded92017-12-08 14:00:22 +0100356 var GsmRrMessage rr;
357 var OCT1 ra;
358 var GsmFrameNumber fn;
359 log("IMM ASS INFO ", rx_rsl.rsl.ies[1].body);
360 rr := dec_GsmRrMessage(rx_rsl.rsl.ies[1].body.full_imm_ass_info.payload);
361 if (ischosen(rr.payload.imm_ass)) {
362 ra := bit2oct(rr.payload.imm_ass.req_ref.ra);
363 fn := 23; //FIXME(rr.payload.imm_ass);
364 /* lookup client based on RA+time, deliver to client */
365 cid := f_cid_by_ra_fn(ra, fn);
366 if (cid == -1) {
367 setverdict(fail, "IMM ASS for unknown DChan");
Harald Weltef70df652018-01-29 22:00:23 +0100368 self.stop;
Harald Welte714ded92017-12-08 14:00:22 +0100369 }
370 /* update client with trx_nr */
371 ConnectionTable[cid].trx_nr := f_trx_by_streamId(rx_rsl.streamId);
372 ConnectionTable[cid].stream_id := rx_rsl.streamId;
373 /* update client with chan_nr */
374 ConnectionTable[cid].chan_nr := rr.payload.imm_ass.chan_desc.chan_nr;
375 /* TODO: add timer to time-out ConnectionTable entries which
376 * never get followed-up to */
377 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref;
378 } else if (ischosen(rr.payload.imm_ass_rej)) {
379 for (i := 0; i < sizeof(rr.payload.imm_ass_rej.payload); i := i + 1) {
380 ra := bit2oct(rr.payload.imm_ass_rej.payload[i].req_ref.ra);
381 fn := 23; //FIXME();
382 /* lookup client based on RA+time, deliver to client */
383 cid := f_cid_by_ra_fn(ra, fn);
384 if (cid != -1) {
385 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref;
386 /* delete ClientTable entry, as it failed */
387 f_cid_clear(cid);
388 }
389 }
390 }
391 }
392
Harald Welte1c02fd12018-02-19 19:20:47 +0100393 [bts_role] IPA_PT.receive(tr_RSL(tr_RSL_PAGING_CMD(?, ?))) -> value rx_rsl {
Harald Welte714ded92017-12-08 14:00:22 +0100394 log("PAGING IDENTITY ", rx_rsl.rsl.ies[2].body.other);
395 /* broadcast to all clients? */
396 for (i := 0; i < sizeof(ConnectionTable); i := i + 1) {
397 if (ispresent(ConnectionTable[i].comp_ref)) {
398 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[i].comp_ref;
399 }
400 }
401 }
402
Harald Welte1c02fd12018-02-19 19:20:47 +0100403 /* Forward common channel management to the special port for it */
Harald Welte714ded92017-12-08 14:00:22 +0100404 [] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeT(?))) -> value rx_rsl {
Harald Welte1c02fd12018-02-19 19:20:47 +0100405 log("Forwarding TRX Mgmt ", rx_rsl.rsl);
406 CCHAN_PT.send(rx_rsl);
Harald Welte714ded92017-12-08 14:00:22 +0100407 }
408
Harald Welte1c02fd12018-02-19 19:20:47 +0100409 /* Forward common channel management to the special port for it */
Harald Welte714ded92017-12-08 14:00:22 +0100410 [] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeC(?))) -> value rx_rsl {
Harald Welte1c02fd12018-02-19 19:20:47 +0100411 log("Forwarding Common Channel Mgmt ", rx_rsl.rsl);
412 CCHAN_PT.send(rx_rsl);
Harald Welte714ded92017-12-08 14:00:22 +0100413 }
414
415 /* blindly acknowledge all channel activations */
Harald Welte1c02fd12018-02-19 19:20:47 +0100416 [bts_role] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) -> value rx_rsl {
Harald Weltef70df652018-01-29 22:00:23 +0100417 chan_nr := rx_rsl.rsl.ies[0].body.chan_nr;
Harald Weltead2647b2018-03-22 19:53:55 +0100418 trx_nr := f_trx_by_streamId(rx_rsl.streamId);
419 f_store_last_act_data(trx_nr, chan_nr, rx_rsl.rsl);
Harald Welte7ae019e2017-12-09 00:54:15 +0100420 IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.streamId, ts_RSL_CHAN_ACT_ACK(chan_nr, 23)));
Harald Welte714ded92017-12-08 14:00:22 +0100421 }
422
Harald Welte70b52c92018-02-12 20:47:31 +0100423 [not dchan_suspended] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeDR(?))) -> value rx_rsl {
Harald Welte714ded92017-12-08 14:00:22 +0100424 /* dispatch to channel based on ChanId */
425 cid := f_cid_by_chan_nr(f_trx_by_streamId(rx_rsl.streamId),
426 rx_rsl.rsl.ies[0].body.chan_nr);
427 if (cid != -1) {
428 CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref;
429 } else {
430 setverdict(fail, "RSL for unknown Dchan");
431 }
432 }
433
Harald Welte70b52c92018-02-12 20:47:31 +0100434 [not dchan_suspended] IPA_PT.receive {
Harald Welte714ded92017-12-08 14:00:22 +0100435 setverdict(fail, "Received unknown primitive from IPA");
436 self.stop;
437 }
438
Harald Welte1c02fd12018-02-19 19:20:47 +0100439 [bts_role] CLIENT_PT.receive(RSLDC_ChanRqd:?) -> value chan_rqd sender vc_conn {
Harald Welte714ded92017-12-08 14:00:22 +0100440 /* Store the knowledge that this sender has requested a certain RQ+time */
441 f_cid_create(chan_rqd.ra, chan_rqd.fn, vc_conn);
Harald Welte7ae019e2017-12-09 00:54:15 +0100442 IPA_PT.send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,
Harald Welte714ded92017-12-08 14:00:22 +0100443 ts_RSL_CHAN_RQD(chan_rqd.ra, chan_rqd.fn)));
444 }
445
446 [] CLIENT_PT.receive(tr_RSL_MsgType(?)) -> value rx_rsl_msg sender vc_conn {
447 /* forward to BSC */
448 cid := f_cid_by_comp_ref(vc_conn);
Harald Welte7ae019e2017-12-09 00:54:15 +0100449 IPA_PT.send(ts_ASP_RSL_UD(ConnectionTable[cid].stream_id, rx_rsl_msg));
Harald Welte714ded92017-12-08 14:00:22 +0100450 }
451
Harald Welte34252c52018-02-24 04:51:50 +0100452 [] CCHAN_PT.receive(tr_RSL(?)) -> value rx_rsl {
453 IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.streamId, rx_rsl.rsl));
454 }
455
Harald Weltef70df652018-01-29 22:00:23 +0100456 /* explicit registration, e.g. in (non-immediate) assignment case */
457 [] RSL_PROC.getcall(RSLEM_register:{?,?,?}) -> param(trx_nr, chan_nr, vc_conn) {
458 f_cid_create_cnr(trx_nr, chan_nr, vc_conn);
459 RSL_PROC.reply(RSLEM_register:{trx_nr, chan_nr, vc_conn});
460 }
461
Harald Welte1909f462018-01-29 22:29:29 +0100462 [] RSL_PROC.getcall(RSLEM_unregister:{?,?,?}) -> param(trx_nr, chan_nr, vc_conn) {
463 cid := f_cid_by_chan_nr(trx_nr, chan_nr);
464 f_cid_clear(cid);
465 RSL_PROC.reply(RSLEM_unregister:{trx_nr, chan_nr, vc_conn});
466 }
467
Harald Welte70b52c92018-02-12 20:47:31 +0100468 [] RSL_PROC.getcall(RSLEM_suspend:{true}) {
469 log("Suspending DChan");
470 dchan_suspended := true;
471 RSL_PROC.reply(RSLEM_suspend:{true});
472 }
473
474 [] RSL_PROC.getcall(RSLEM_suspend:{false}) {
475 log("Resuming DChan");
476 dchan_suspended := false;
477 RSL_PROC.reply(RSLEM_suspend:{false});
478 }
Harald Welte1909f462018-01-29 22:29:29 +0100479
Harald Weltead2647b2018-03-22 19:53:55 +0100480 [] RSL_PROC.getcall(RSLEM_get_last_act:{?,?,?}) -> param(trx_nr, chan_nr) {
481 var RSL_Message last_chan_act := f_lookup_last_act(trx_nr, chan_nr);
482 RSL_PROC.reply(RSLEM_get_last_act:{trx_nr, chan_nr, last_chan_act});
483 }
Harald Welte714ded92017-12-08 14:00:22 +0100484 }
485 }
486}
487
Daniel Willmann17f970f2018-01-17 12:03:19 +0100488private function f_conn_table_init()
489runs on RSL_Emulation_CT {
490 var integer i;
491
492 /* Initialize the ConnectionTable */
493 for (i := 0; i < sizeof(ConnectionTable); i := i+1) {
494 f_cid_clear(i);
495 }
496}
Harald Welte714ded92017-12-08 14:00:22 +0100497
Harald Weltef70df652018-01-29 22:00:23 +0100498/* client/conn_hdlr side function to use procedure port to register stream_id/chan_nr */
Harald Welte421e4d42018-02-12 20:04:50 +0100499function f_rslem_register(uint8_t trx_nr, RslChannelNr chan_nr, RSLEM_PROC_PT PT := RSL_PROC)
500runs on RSL_DchanHdlr {
501 PT.call(RSLEM_register:{trx_nr, chan_nr, self}) {
502 [] PT.getreply(RSLEM_register:{?,?,?}) {};
Harald Weltef70df652018-01-29 22:00:23 +0100503 }
504}
505
Harald Welte1909f462018-01-29 22:29:29 +0100506/* client/conn_hdlr side function to use procedure port to unregister stream_id/chan_nr */
Harald Welte421e4d42018-02-12 20:04:50 +0100507function f_rslem_unregister(uint8_t trx_nr, RslChannelNr chan_nr, RSLEM_PROC_PT PT := RSL_PROC)
508runs on RSL_DchanHdlr {
509 PT.call(RSLEM_unregister:{trx_nr, chan_nr, self}) {
510 [] PT.getreply(RSLEM_unregister:{?,?,?}) {};
Harald Welte1909f462018-01-29 22:29:29 +0100511 }
512}
513
Harald Welte70b52c92018-02-12 20:47:31 +0100514/* resume handling of RSL DChan messages from IPA until f_rslem_resume() is called */
515function f_rslem_suspend(RSLEM_PROC_PT PT)
516runs on RSL_DchanHdlr {
517 PT.call(RSLEM_suspend:{true}) {
518 [] PT.getreply(RSLEM_suspend:{true}) {};
519 }
520}
521
522/* resume handling of RSL DChan messages after f_rslem_suspend() is called */
523function f_rslem_resume(RSLEM_PROC_PT PT)
524runs on RSL_DchanHdlr {
525 PT.call(RSLEM_suspend:{false}) {
526 [] PT.getreply(RSLEM_suspend:{false}) {};
527 }
528}
529
Harald Weltead2647b2018-03-22 19:53:55 +0100530/* obtain the last RSL_CHAN_ACT message for the given chan_nr */
531function f_rslem_get_last_act(RSLEM_PROC_PT PT, uint8_t trx_nr, RslChannelNr chan_nr)
532runs on RSL_DchanHdlr return RSL_Message {
533 var RSL_Message chan_act;
534 PT.call(RSLEM_get_last_act:{trx_nr, chan_nr, -}) {
535 [] PT.getreply(RSLEM_get_last_act:{trx_nr, chan_nr, ?}) -> param(chan_act) {};
536 }
537 return chan_act;
538}
539
540
Harald Welte70b52c92018-02-12 20:47:31 +0100541
Harald Welte1909f462018-01-29 22:29:29 +0100542
Harald Welte714ded92017-12-08 14:00:22 +0100543}