blob: aa2ab42246a1991682d63874b02658f76fd1ea44 [file] [log] [blame]
Pau Espin Pedrol8dd59fb2020-04-29 15:08:16 +02001module PCUIF_Components {
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +02002
3/*
4 * Components for (RAW) PCU test cases.
5 *
6 * (C) 2019 Vadim Yanitskiy <axilirator@gmail.com>
7 *
8 * All rights reserved.
9 *
10 * Released under the terms of GNU General Public License, Version 2 or
11 * (at your option) any later version.
12 *
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 */
15
16import from IPL4asp_Types all;
17import from UD_Types all;
18
19import from PCUIF_Types all;
20import from PCUIF_CodecPort all;
21
22/* Component communication diagram:
23 *
24 * +-----+ +----------+ +---------+
25 * | MTC +---------------+ PCUIF_CT +------+ OsmoPCU |
26 * +--+--+ +----+-----+ +---------+
27 * | |
28 * | |
29 * | |
30 * | +-----------+ | +---------------+
31 * +----+ BTS_CT #1 +------+ | ClckGen_CT #1 |
32 * | +-----+-----+ | +-------+-------+
33 * | | | |
34 * | +---------------------------+
35 * | |
36 * | +-----------+ | +---------------+
37 * +----+ BTS_CT #2 +------+ | ClckGen_CT #2 |
38 * | +-----+-----+ | +-------+-------+
39 * | | | |
40 * | +---------------------------+
41 * | |
42 * | +-----------+ | +---------------+
43 * +----+ BTS_CT #N +------+ | ClckGen_CT #N |
44 * +-----+-----+ +-------+-------+
45 * | |
46 * +---------------------------+
47 */
48
49/* Events are used by the components to indicate that something
50 * has happened, e.g. we have got a connection from the PCU. */
51type enumerated RAW_PCU_EventType {
52 /* Events related to RAW_PCUIF_CT */
53 PCU_EV_DISCONNECT, /*!< OsmoPCU has disconnected */
54 PCU_EV_CONNECT, /*!< OsmoPCU is now connected */
55
56 /* Events related to RAW_PCU_BTS_CT */
57 BTS_EV_SI13_NEGO, /*!< SI13 negotiation complete */
58
59 /* TDMA clock related events (TDMA frame-number in parameters) */
60 TDMA_EV_PDTCH_BLOCK_BEG, /*!< 1/4 bursts of a PDTCH block on both Uplink and Downlink */
61 TDMA_EV_PDTCH_BLOCK_END, /*!< 4/4 bursts of a PDTCH block on both Uplink and Downlink */
62 TDMA_EV_PTCCH_DL_BLOCK, /*!< 4/4 bursts of a PTCCH block on Downlink */
63 TDMA_EV_PTCCH_UL_BURST, /*!< One Access Burst on PTCCH/U */
64
65 TDMA_EV_PDTCH_BLOCK_SENT /*!< A PDTCH block has been sent to the PCU */
66};
67
68/* Union of all possible parameters of the events */
69type union RAW_PCU_EventParam {
70 integer tdma_fn
71};
72
73type record RAW_PCU_Event {
74 RAW_PCU_EventType event,
75 /* TODO: can we use 'anytype' here? */
76 RAW_PCU_EventParam data optional
77};
78
79template (value) RAW_PCU_Event ts_RAW_PCU_EV(RAW_PCU_EventType event) := {
80 event := event,
81 data := omit
82}
83template RAW_PCU_Event tr_RAW_PCU_EV(template RAW_PCU_EventType event := ?,
84 template RAW_PCU_EventParam data := *) := {
85 event := event,
86 data := data
87}
88
89template (value) RAW_PCU_Event ts_RAW_PCU_CLCK_EV(RAW_PCU_EventType event, integer fn) := {
90 event := event,
91 data := { tdma_fn := fn }
92}
93template RAW_PCU_Event tr_RAW_PCU_CLCK_EV := {
94 event := (TDMA_EV_PDTCH_BLOCK_BEG, TDMA_EV_PDTCH_BLOCK_END,
95 TDMA_EV_PTCCH_DL_BLOCK, TDMA_EV_PTCCH_UL_BURST,
96 TDMA_EV_PDTCH_BLOCK_SENT),
97 data := { tdma_fn := ? }
98}
99
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700100/* Commands are mostly used by the MTC to configure the components
101 * at run-time, e.g. to enable or disable some optional features. */
102type enumerated RAW_PCU_CommandType {
Vadim Yanitskiy91f8a092020-05-06 21:41:05 +0700103 GENERAL_CMD_SHUTDOWN, /*!< Shut down component and all its child components */
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700104 TDMA_CMD_ENABLE_PTCCH_UL_FWD /*!< Enable forwarding of TDMA_EV_PTCCH_UL_BURST to the MTC */
105};
106
107type record RAW_PCU_Command {
108 RAW_PCU_CommandType cmd,
109 anytype data optional
110};
111
112template (value) RAW_PCU_Command ts_RAW_PCU_CMD(RAW_PCU_CommandType cmd) := {
113 cmd := cmd,
114 data := omit
115}
116template RAW_PCU_Command tr_RAW_PCU_CMD(template RAW_PCU_CommandType cmd := ?,
117 template anytype data := *) := {
118 cmd := cmd,
119 data := data
120}
121
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200122/* Generic port for messages and events */
123type port RAW_PCU_MSG_PT message {
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700124 inout RAW_PCU_Command;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200125 inout RAW_PCU_Event;
126 inout PCUIF_Message;
127} with { extension "internal" };
128
129/* TDMA frame clock generator */
130type component RAW_PCU_ClckGen_CT {
131 /* One TDMA frame is 4.615 ms long */
132 timer T_TDMAClock := 4.615 / 1000.0;
133 port RAW_PCU_MSG_PT CLCK;
134 var integer fn := 0;
135}
136
Vadim Yanitskiy20f87002019-10-06 00:51:50 +0700137/* Derive PTCCH/U sub-slot from a given TDMA frame-number */
138function f_tdma_ptcch_fn2ss(integer fn) return integer
139{
140 var integer ss := -1;
141
142 /* See 3GPP TS 45.002, table 6 */
143 select (fn mod 416) {
144 case (12) { ss := 0; }
145 case (38) { ss := 1; }
146 case (64) { ss := 2; }
147 case (90) { ss := 3; }
148
149 case (116) { ss := 4; }
150 case (142) { ss := 5; }
151 case (168) { ss := 6; }
152 case (194) { ss := 7; }
153
154 case (220) { ss := 8; }
155 case (246) { ss := 9; }
156 case (272) { ss := 10; }
157 case (298) { ss := 11; }
158
159 case (324) { ss := 12; }
160 case (350) { ss := 13; }
161 case (376) { ss := 14; }
162 case (402) { ss := 15; }
163 }
164
165 return ss;
166}
167
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200168function f_ClckGen_CT_handler()
169runs on RAW_PCU_ClckGen_CT {
170 var integer fn104, fn52, fn13;
171
172 while (true) {
173 fn104 := fn mod 104;
174 fn52 := fn mod 52;
175 fn13 := fn mod 13;
176
177 if (fn13 == 0 or fn13 == 4 or fn13 == 8) {
178 /* 1/4 bursts of a PDTCH block on both Uplink and Downlink */
179 CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_BEG, fn));
180 } else if (fn13 == 3 or fn13 == 7 or fn13 == 11) {
181 /* 4/4 bursts of a PDTCH block on both Uplink and Downlink */
182 CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_END, fn));
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200183 } else if (fn52 == 12 or fn52 == 38) {
Vadim Yanitskiyb58b7302019-10-06 01:01:48 +0700184 /* 4/4 bursts of a PTCCH (Timing Advance Control) block on Downlink */
185 if (fn104 == 90) {
186 CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PTCCH_DL_BLOCK, fn));
187 }
188 /* One Access Burst on PTCCH/U (goes 3 time-slots after PTCCH/D) */
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200189 CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PTCCH_UL_BURST, fn));
190 }
191
192 /* TDMA hyperframe period is (2048 * 51 * 26) frames */
193 fn := (fn + 1) mod (2048 * 51 * 26);
194
195 /* (Re)start TDMA clock timer and wait */
196 T_TDMAClock.start;
197 T_TDMAClock.timeout;
198 }
199}
200
201type record of PCUIF_Message PCUIF_MsgQueue;
202
203/* Enqueue a given message to the end of a given queue */
204private function f_PCUIF_MsgQueue_enqueue(inout PCUIF_MsgQueue queue,
205 in PCUIF_Message msg)
206{
207 queue := queue & { msg };
208}
209
210/* Dequeue the first message of a given queue */
211private function f_PCUIF_MsgQueue_dequeue(inout PCUIF_MsgQueue queue,
212 out PCUIF_Message msg)
213{
214 var integer len := lengthof(queue);
215
216 if (len == 0) {
217 setverdict(fail, "Failed to dequeue a message: the queue is empty!");
218 mtc.stop;
219 }
220
221 /* Store the first message */
222 msg := queue[0];
223
224 /* Remove the first message from queue */
225 if (len > 1) {
226 queue := substr(queue, 1, len - 1);
227 } else {
228 queue := { };
229 }
230}
231
Pau Espin Pedrol65bab9e2019-12-04 21:05:10 +0100232/* Get first message from queue. true if non-empty, false otherwise */
233private function f_PCUIF_MsgQueue_first(inout PCUIF_MsgQueue queue,
234 out PCUIF_Message msg) return boolean
235{
236 if (lengthof(queue) == 0) {
237 return false;
238 }
239
240 msg := queue[0];
241 return true;
242}
243
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200244/* Multiple base stations can be connected to the PCU. This component
245 * represents one BTS with an associated TDMA clock generator. */
246type component RAW_PCU_BTS_CT {
247 /* TDMA clock generator */
248 var RAW_PCU_ClckGen_CT vc_CLCK_GEN;
249 port RAW_PCU_MSG_PT CLCK;
250
251 /* Queues of PCUIF messages to be sent
252 * TODO: we may have multiple PDCH time-slots */
253 var PCUIF_MsgQueue pdtch_data_queue := { };
254 var PCUIF_MsgQueue pdtch_rts_queue := { };
255 var PCUIF_MsgQueue ptcch_rts_queue := { };
256
257 /* Connection towards the PCU interface */
258 port RAW_PCU_MSG_PT PCUIF;
259 /* Connection towards the test case */
260 port RAW_PCU_MSG_PT TC;
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700261
262 /* Whether to forward PTCCH/U burst events to the TC */
263 var boolean cfg_ptcch_burst_fwd := false;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200264}
265
Pau Espin Pedrol65bab9e2019-12-04 21:05:10 +0100266/* Queue received messages from Test Case, they will eventually be scheduled and
267 * sent according to their FN. FN value of 0 has the special meaning of "schedule
268 * as soon as possible". */
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200269private altstep as_BTS_CT_MsgQueue(integer bts_nr)
270runs on RAW_PCU_BTS_CT {
271 var PCUIF_Message pcu_msg;
272
273 /* Enqueue DATA.ind and RTS.req messages */
274 [] TC.receive(tr_PCUIF_MSG(PCU_IF_MSG_DATA_IND, bts_nr)) -> value pcu_msg {
275 f_PCUIF_MsgQueue_enqueue(pdtch_data_queue, pcu_msg);
276 repeat;
277 }
278 [] TC.receive(tr_PCUIF_RTS_REQ(bts_nr, sapi := PCU_IF_SAPI_PDTCH)) -> value pcu_msg {
279 f_PCUIF_MsgQueue_enqueue(pdtch_rts_queue, pcu_msg);
280 repeat;
281 }
282 [] TC.receive(tr_PCUIF_RTS_REQ(bts_nr, sapi := PCU_IF_SAPI_PTCCH)) -> value pcu_msg {
283 f_PCUIF_MsgQueue_enqueue(ptcch_rts_queue, pcu_msg);
284 repeat;
285 }
286 /* Forward other messages directly to the PCU */
287 [] TC.receive(tr_PCUIF_MSG(?, bts_nr)) -> value pcu_msg {
288 PCUIF.send(pcu_msg);
289 repeat;
290 }
291}
292
Pau Espin Pedrol65bab9e2019-12-04 21:05:10 +0100293/* Handle schedule events and manage actions: Send msgs over PCUIF to PCU,
294 * advertise Test Case about sent messages, etc. */
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200295private altstep as_BTS_CT_TDMASched(integer bts_nr)
296runs on RAW_PCU_BTS_CT {
297 var PCUIF_Message pcu_msg;
298 var RAW_PCU_Event event;
Pau Espin Pedrol60727252019-12-04 21:40:25 +0100299 var integer ev_begin_fn;
Pau Espin Pedrol65bab9e2019-12-04 21:05:10 +0100300 var integer next_fn;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200301
302 [] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_BEG)) -> value event {
303 /* If the RTS queue for PDTCH is not empty, send a message */
304 if (lengthof(pdtch_rts_queue) > 0) {
305 f_PCUIF_MsgQueue_dequeue(pdtch_rts_queue, pcu_msg);
306
307 /* Patch TDMA frame / block number and send */
308 pcu_msg.u.rts_req.fn := event.data.tdma_fn;
309 pcu_msg.u.rts_req.block_nr := 0; /* FIXME! */
310 PCUIF.send(pcu_msg);
311 }
312
313 /* We don't really need to send every frame to OsmoPCU, because
314 * it omits frame numbers not starting at a MAC block. */
315 PCUIF.send(ts_PCUIF_TIME_IND(bts_nr, event.data.tdma_fn));
316 repeat;
317 }
318 [lengthof(pdtch_data_queue) > 0] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_END)) -> value event {
Pau Espin Pedrol60727252019-12-04 21:40:25 +0100319 /* FN matching the beginning of current block: */
320 ev_begin_fn := event.data.tdma_fn - 3;
Pau Espin Pedrol65bab9e2019-12-04 21:05:10 +0100321
322 /* Check if we reached time to serve the first DATA.ind message in the queue: */
323 f_PCUIF_MsgQueue_first(pdtch_data_queue, pcu_msg);
324 next_fn := pcu_msg.u.data_ind.fn;
325 if (next_fn != 0 and next_fn != ev_begin_fn) {
326 if (next_fn < ev_begin_fn) {
327 setverdict(fail, "We are late scheduling the block! ", next_fn, " < ", ev_begin_fn);
328 mtc.stop;
329 }
330 repeat;
331 }
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200332 /* Dequeue a DATA.ind message */
333 f_PCUIF_MsgQueue_dequeue(pdtch_data_queue, pcu_msg);
334
335 /* Patch TDMA frame / block number */
Pau Espin Pedrol60727252019-12-04 21:40:25 +0100336 pcu_msg.u.data_ind.fn := ev_begin_fn;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200337 pcu_msg.u.data_ind.block_nr := 0; /* FIXME! */
338
339 PCUIF.send(pcu_msg); /* Send to the PCU and notify the TC */
Pau Espin Pedrol60727252019-12-04 21:40:25 +0100340 TC.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_SENT, ev_begin_fn));
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200341 repeat;
342 }
343 [lengthof(ptcch_rts_queue) > 0] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PTCCH_DL_BLOCK)) -> value event {
Pau Espin Pedrol60727252019-12-04 21:40:25 +0100344 /* FN matching the beginning of current block (PTCCH is interleaved over 4 non-consecutive bursts): */
345 ev_begin_fn := event.data.tdma_fn - 78;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200346 /* Dequeue an RTS.req message for PTCCH */
347 f_PCUIF_MsgQueue_dequeue(ptcch_rts_queue, pcu_msg);
348
349 /* Patch TDMA frame / block number and send */
Pau Espin Pedrol60727252019-12-04 21:40:25 +0100350 pcu_msg.u.rts_req.fn := ev_begin_fn;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200351 pcu_msg.u.rts_req.block_nr := 0; /* FIXME! */
352 PCUIF.send(pcu_msg);
353 repeat;
354 }
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700355 /* Optional forwarding of PTCCH/U burst indications to the test case */
356 [cfg_ptcch_burst_fwd] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PTCCH_UL_BURST)) -> value event {
357 TC.send(event);
358 repeat;
359 }
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200360 /* Ignore other clock events (and guard against an empty queue) */
361 [] CLCK.receive(tr_RAW_PCU_CLCK_EV) { repeat; }
362}
363
364function f_BTS_CT_handler(integer bts_nr, PCUIF_info_ind info_ind)
365runs on RAW_PCU_BTS_CT {
366 var PCUIF_Message pcu_msg;
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700367 var RAW_PCU_Command cmd;
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200368 var RAW_PCU_Event event;
369
370 /* Init TDMA clock generator (so we can stop and start it) */
371 vc_CLCK_GEN := RAW_PCU_ClckGen_CT.create("ClckGen-" & int2str(bts_nr)) alive;
372 connect(vc_CLCK_GEN:CLCK, self:CLCK);
373
374 /* Wait until the PCU is connected */
375 PCUIF.receive(tr_RAW_PCU_EV(PCU_EV_CONNECT));
376
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200377 alt {
378 /* Wait for TXT.ind (PCU_VERSION) and respond with INFO.ind (SI13) */
379 [] PCUIF.receive(tr_PCUIF_TXT_IND(bts_nr, PCU_VERSION, ?)) -> value pcu_msg {
380 log("Rx TXT.ind from the PCU, version is ", pcu_msg.u.txt_ind.text);
381
382 /* Send System Information 13 to the PCU */
383 PCUIF.send(PCUIF_Message:{
384 msg_type := PCU_IF_MSG_INFO_IND,
385 bts_nr := bts_nr,
386 spare := '0000'O,
387 u := { info_ind := info_ind }
388 });
389
390 /* Notify the test case that we're done with SI13 */
391 TC.send(ts_RAW_PCU_EV(BTS_EV_SI13_NEGO));
392
393 /* Start feeding clock to the PCU */
394 vc_CLCK_GEN.start(f_ClckGen_CT_handler());
395 repeat;
396 }
Pau Espin Pedrold16bb272019-12-02 12:57:03 +0100397 /* PCU -> TS becomes active */
398 [] PCUIF.receive(tr_PCUIF_ACT_REQ(bts_nr, ?, ?)) -> value pcu_msg {
399 log("Rx ACT.req from the PCU: TRX" & int2str(pcu_msg.u.act_req.trx_nr) &
400 "/TS" & int2str(pcu_msg.u.act_req.ts_nr));
401 repeat;
402 }
403 /* PCU -> TS becomes inactive */
404 [] PCUIF.receive(tr_PCUIF_DEACT_REQ(bts_nr, ?, ?)) -> value pcu_msg {
405 log("Rx DEACT.req from the PCU: TRX" & int2str(pcu_msg.u.act_req.trx_nr) &
406 "/TS" & int2str(pcu_msg.u.act_req.ts_nr));
407 repeat;
408 }
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200409 /* PCU -> test case forwarding (filter by the BTS number) */
410 [] PCUIF.receive(tr_PCUIF_MSG(?, bts_nr)) -> value pcu_msg {
411 TC.send(pcu_msg);
412 repeat;
413 }
414
415 /* TC -> [Queue] -> PCU forwarding */
416 [] as_BTS_CT_MsgQueue(bts_nr);
417 /* TDMA scheduler (clock and queue handling) */
418 [] as_BTS_CT_TDMASched(bts_nr);
419
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700420 /* Command handling */
Vadim Yanitskiy91f8a092020-05-06 21:41:05 +0700421 [] TC.receive(tr_RAW_PCU_CMD(GENERAL_CMD_SHUTDOWN)) {
422 log("Shutting down virtual BTS #", bts_nr, "...");
423 vc_CLCK_GEN.stop;
424 break;
425 }
Vadim Yanitskiy02f77d82019-10-04 17:12:35 +0700426 [] TC.receive(tr_RAW_PCU_CMD(TDMA_CMD_ENABLE_PTCCH_UL_FWD)) {
427 log("Enabling forwarding of PTCCH/U TDMA events to the TC");
428 cfg_ptcch_burst_fwd := true;
429 repeat;
430 }
431 [] TC.receive(tr_RAW_PCU_CMD) -> value cmd {
432 log("Ignore unhandled command: ", cmd);
433 repeat;
434 }
435
Vadim Yanitskiyf7d9c0f2019-09-06 00:08:17 +0200436 /* TODO: handle events (e.g. disconnection) from the PCU interface */
437 [] PCUIF.receive(tr_RAW_PCU_EV) -> value event {
438 log("Ignore unhandled event: ", event);
439 repeat;
440 }
441 }
442}
443
444/* PCU interface (UNIX domain socket) handler */
445type component RAW_PCUIF_CT {
446 var ConnectionId g_pcu_conn_id := -1;
447 var boolean g_pcu_connected := false;
448 port PCUIF_CODEC_PT PCU;
449
450 /* Connection towards BTS component(s) */
451 port RAW_PCU_MSG_PT BTS;
452 /* Connection to the MTC (test case) */
453 port RAW_PCU_MSG_PT MTC;
454};
455
456/* All received messages and events from OsmoPCU can be additionally sent
457 * directly to the MTC component. Pass direct := true to enable this mode. */
458function f_PCUIF_CT_handler(charstring pcu_sock_path, boolean direct := false)
459runs on RAW_PCUIF_CT {
460 var PCUIF_send_data pcu_sd_msg;
461 var PCUIF_Message pcu_msg;
462 timer T_Conn := 10.0;
463
464 log("Init PCU interface on '" & pcu_sock_path & "', waiting for connection...");
465 g_pcu_conn_id := f_pcuif_listen(PCU, pcu_sock_path);
466
467 /* Wait for connection */
468 T_Conn.start;
469 alt {
470 [not g_pcu_connected] PCU.receive(UD_connected:?) {
471 log("OsmoPCU is now connected");
472 /* Duplicate this event to the MTC if requested */
473 if (direct) { MTC.send(ts_RAW_PCU_EV(PCU_EV_CONNECT)); }
474 BTS.send(ts_RAW_PCU_EV(PCU_EV_CONNECT));
475 g_pcu_connected := true;
476 setverdict(pass);
477 T_Conn.stop;
478 repeat;
479 }
480 /* PCU -> BTS / MTC message forwarding */
481 [g_pcu_connected] PCU.receive(PCUIF_send_data:?) -> value pcu_sd_msg {
482 /* Send to the BTSes if at least one is connected */
483 if (BTS.checkstate("Connected")) { BTS.send(pcu_sd_msg.data); }
484 /* Duplicate this message to the MTC if requested */
485 if (direct) { MTC.send(pcu_sd_msg.data); }
486 repeat;
487 }
488 /* MTC -> PCU message forwarding */
489 [g_pcu_connected] MTC.receive(PCUIF_Message:?) -> value pcu_msg {
490 PCU.send(t_SD_PCUIF(g_pcu_conn_id, pcu_msg));
491 repeat;
492 }
493 /* BTS -> PCU message forwarding */
494 [g_pcu_connected] BTS.receive(PCUIF_Message:?) -> value pcu_msg {
495 PCU.send(t_SD_PCUIF(g_pcu_conn_id, pcu_msg));
496 repeat;
497 }
498 [not g_pcu_connected] MTC.receive(PCUIF_Message:?) -> value pcu_msg {
499 log("PCU is not connected, dropping ", pcu_msg);
500 repeat;
501 }
502 [not g_pcu_connected] BTS.receive(PCUIF_Message:?) -> value pcu_msg {
503 log("PCU is not connected, dropping ", pcu_msg);
504 repeat;
505 }
506 /* TODO: handle disconnect and reconnect of the PCU */
507 [] PCU.receive {
508 log("Unhandled message on PCU interface");
509 repeat;
510 }
511 [not g_pcu_connected] T_Conn.timeout {
512 setverdict(fail, "Timeout waiting for PCU connection");
513 mtc.stop;
514 }
515 }
516}
517
518}