Pau Espin Pedrol | 8dd59fb | 2020-04-29 15:08:16 +0200 | [diff] [blame] | 1 | module PCUIF_Components { |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 2 | |
| 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 | |
| 16 | import from IPL4asp_Types all; |
| 17 | import from UD_Types all; |
| 18 | |
| 19 | import from PCUIF_Types all; |
| 20 | import from PCUIF_CodecPort all; |
| 21 | |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 22 | import from Osmocom_Types all; |
Philipp Maier | db9d894 | 2023-07-18 15:23:15 +0200 | [diff] [blame] | 23 | import from General_Types all; |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 24 | import from RLCMAC_Types all; |
| 25 | import from GSM_RR_Types all; |
| 26 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 27 | /* Component communication diagram: |
| 28 | * |
| 29 | * +-----+ +----------+ +---------+ |
| 30 | * | MTC +---------------+ PCUIF_CT +------+ OsmoPCU | |
| 31 | * +--+--+ +----+-----+ +---------+ |
| 32 | * | | |
| 33 | * | | |
| 34 | * | | |
| 35 | * | +-----------+ | +---------------+ |
| 36 | * +----+ BTS_CT #1 +------+ | ClckGen_CT #1 | |
| 37 | * | +-----+-----+ | +-------+-------+ |
| 38 | * | | | | |
| 39 | * | +---------------------------+ |
| 40 | * | | |
| 41 | * | +-----------+ | +---------------+ |
| 42 | * +----+ BTS_CT #2 +------+ | ClckGen_CT #2 | |
| 43 | * | +-----+-----+ | +-------+-------+ |
| 44 | * | | | | |
| 45 | * | +---------------------------+ |
| 46 | * | | |
| 47 | * | +-----------+ | +---------------+ |
| 48 | * +----+ BTS_CT #N +------+ | ClckGen_CT #N | |
| 49 | * +-----+-----+ +-------+-------+ |
| 50 | * | | |
| 51 | * +---------------------------+ |
| 52 | */ |
| 53 | |
| 54 | /* Events are used by the components to indicate that something |
| 55 | * has happened, e.g. we have got a connection from the PCU. */ |
| 56 | type enumerated RAW_PCU_EventType { |
| 57 | /* Events related to RAW_PCUIF_CT */ |
| 58 | PCU_EV_DISCONNECT, /*!< OsmoPCU has disconnected */ |
| 59 | PCU_EV_CONNECT, /*!< OsmoPCU is now connected */ |
| 60 | |
| 61 | /* Events related to RAW_PCU_BTS_CT */ |
| 62 | BTS_EV_SI13_NEGO, /*!< SI13 negotiation complete */ |
| 63 | |
| 64 | /* TDMA clock related events (TDMA frame-number in parameters) */ |
| 65 | TDMA_EV_PDTCH_BLOCK_BEG, /*!< 1/4 bursts of a PDTCH block on both Uplink and Downlink */ |
| 66 | TDMA_EV_PDTCH_BLOCK_END, /*!< 4/4 bursts of a PDTCH block on both Uplink and Downlink */ |
| 67 | TDMA_EV_PTCCH_DL_BLOCK, /*!< 4/4 bursts of a PTCCH block on Downlink */ |
| 68 | TDMA_EV_PTCCH_UL_BURST, /*!< One Access Burst on PTCCH/U */ |
| 69 | |
| 70 | TDMA_EV_PDTCH_BLOCK_SENT /*!< A PDTCH block has been sent to the PCU */ |
| 71 | }; |
| 72 | |
| 73 | /* Union of all possible parameters of the events */ |
| 74 | type union RAW_PCU_EventParam { |
| 75 | integer tdma_fn |
| 76 | }; |
| 77 | |
| 78 | type record RAW_PCU_Event { |
| 79 | RAW_PCU_EventType event, |
| 80 | /* TODO: can we use 'anytype' here? */ |
| 81 | RAW_PCU_EventParam data optional |
| 82 | }; |
| 83 | |
| 84 | template (value) RAW_PCU_Event ts_RAW_PCU_EV(RAW_PCU_EventType event) := { |
| 85 | event := event, |
| 86 | data := omit |
| 87 | } |
| 88 | template RAW_PCU_Event tr_RAW_PCU_EV(template RAW_PCU_EventType event := ?, |
| 89 | template RAW_PCU_EventParam data := *) := { |
| 90 | event := event, |
| 91 | data := data |
| 92 | } |
| 93 | |
| 94 | template (value) RAW_PCU_Event ts_RAW_PCU_CLCK_EV(RAW_PCU_EventType event, integer fn) := { |
| 95 | event := event, |
| 96 | data := { tdma_fn := fn } |
| 97 | } |
| 98 | template RAW_PCU_Event tr_RAW_PCU_CLCK_EV := { |
| 99 | event := (TDMA_EV_PDTCH_BLOCK_BEG, TDMA_EV_PDTCH_BLOCK_END, |
| 100 | TDMA_EV_PTCCH_DL_BLOCK, TDMA_EV_PTCCH_UL_BURST, |
| 101 | TDMA_EV_PDTCH_BLOCK_SENT), |
| 102 | data := { tdma_fn := ? } |
| 103 | } |
| 104 | |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 105 | /* Commands are mostly used by the MTC to configure the components |
| 106 | * at run-time, e.g. to enable or disable some optional features. */ |
| 107 | type enumerated RAW_PCU_CommandType { |
Vadim Yanitskiy | 91f8a09 | 2020-05-06 21:41:05 +0700 | [diff] [blame] | 108 | GENERAL_CMD_SHUTDOWN, /*!< Shut down component and all its child components */ |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 109 | TDMA_CMD_ENABLE_PTCCH_UL_FWD /*!< Enable forwarding of TDMA_EV_PTCCH_UL_BURST to the MTC */ |
| 110 | }; |
| 111 | |
| 112 | type record RAW_PCU_Command { |
| 113 | RAW_PCU_CommandType cmd, |
| 114 | anytype data optional |
| 115 | }; |
| 116 | |
| 117 | template (value) RAW_PCU_Command ts_RAW_PCU_CMD(RAW_PCU_CommandType cmd) := { |
| 118 | cmd := cmd, |
| 119 | data := omit |
| 120 | } |
| 121 | template RAW_PCU_Command tr_RAW_PCU_CMD(template RAW_PCU_CommandType cmd := ?, |
| 122 | template anytype data := *) := { |
| 123 | cmd := cmd, |
| 124 | data := data |
| 125 | } |
| 126 | |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 127 | /* PCUIF req_data containing decoded rlcmac/rr, for users to be able to match |
| 128 | * directly on receive() |
| 129 | */ |
| 130 | type record BTS_PDTCH_Block { |
| 131 | uint8_t bts_nr, |
| 132 | PCUIF_data raw, |
Pau Espin Pedrol | cf2ada5 | 2021-09-22 14:11:44 +0200 | [diff] [blame] | 133 | RlcmacDlBlock dl_block optional |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 134 | }; |
| 135 | type record BTS_PTCCH_Block { |
| 136 | uint8_t bts_nr, |
| 137 | PCUIF_data raw, |
Pau Espin Pedrol | cf2ada5 | 2021-09-22 14:11:44 +0200 | [diff] [blame] | 138 | PTCCHDownlinkMsg dl_block optional |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 139 | }; |
| 140 | type record BTS_CCCH_Block { |
| 141 | uint8_t bts_nr, |
| 142 | PCUIF_data raw, |
Philipp Maier | a6708cf | 2023-08-08 16:12:27 +0200 | [diff] [blame^] | 143 | OCT4 msg_id optional, |
Philipp Maier | db9d894 | 2023-07-18 15:23:15 +0200 | [diff] [blame] | 144 | charstring imsi optional, |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 145 | GsmRrMessage rr_msg |
| 146 | }; |
| 147 | template BTS_PDTCH_Block tr_PCUIF_DATA_PDTCH(template uint8_t bts_nr, |
| 148 | template PCUIF_data raw, |
| 149 | template RlcmacDlBlock dl_block := ?) := { |
| 150 | bts_nr := bts_nr, |
| 151 | raw := raw, |
| 152 | dl_block := dl_block |
| 153 | }; |
| 154 | template BTS_PTCCH_Block tr_PCUIF_DATA_PTCCH(template uint8_t bts_nr, |
| 155 | template PCUIF_data raw, |
| 156 | template PTCCHDownlinkMsg dl_block := ?) := { |
| 157 | bts_nr := bts_nr, |
| 158 | raw := raw, |
| 159 | dl_block := dl_block |
| 160 | }; |
| 161 | template BTS_CCCH_Block tr_PCUIF_DATA_RR(template uint8_t bts_nr, |
| 162 | template PCUIF_data raw, |
Philipp Maier | db9d894 | 2023-07-18 15:23:15 +0200 | [diff] [blame] | 163 | template GsmRrMessage rr_msg := ?, |
Philipp Maier | a6708cf | 2023-08-08 16:12:27 +0200 | [diff] [blame^] | 164 | template OCT4 msg_id := *, |
Philipp Maier | db9d894 | 2023-07-18 15:23:15 +0200 | [diff] [blame] | 165 | template charstring imsi := *) := { |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 166 | bts_nr := bts_nr, |
| 167 | raw := raw, |
Philipp Maier | a6708cf | 2023-08-08 16:12:27 +0200 | [diff] [blame^] | 168 | msg_id := msg_id, |
Philipp Maier | db9d894 | 2023-07-18 15:23:15 +0200 | [diff] [blame] | 169 | imsi := imsi, |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 170 | rr_msg := rr_msg |
| 171 | }; |
| 172 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 173 | /* Generic port for messages and events */ |
| 174 | type port RAW_PCU_MSG_PT message { |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 175 | inout RAW_PCU_Command; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 176 | inout RAW_PCU_Event; |
| 177 | inout PCUIF_Message; |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 178 | inout BTS_PDTCH_Block; |
| 179 | inout BTS_PTCCH_Block; |
| 180 | inout BTS_CCCH_Block; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 181 | } with { extension "internal" }; |
| 182 | |
| 183 | /* TDMA frame clock generator */ |
| 184 | type component RAW_PCU_ClckGen_CT { |
| 185 | /* One TDMA frame is 4.615 ms long */ |
| 186 | timer T_TDMAClock := 4.615 / 1000.0; |
| 187 | port RAW_PCU_MSG_PT CLCK; |
| 188 | var integer fn := 0; |
| 189 | } |
| 190 | |
Vadim Yanitskiy | 20f8700 | 2019-10-06 00:51:50 +0700 | [diff] [blame] | 191 | /* Derive PTCCH/U sub-slot from a given TDMA frame-number */ |
| 192 | function f_tdma_ptcch_fn2ss(integer fn) return integer |
| 193 | { |
| 194 | var integer ss := -1; |
| 195 | |
| 196 | /* See 3GPP TS 45.002, table 6 */ |
| 197 | select (fn mod 416) { |
| 198 | case (12) { ss := 0; } |
| 199 | case (38) { ss := 1; } |
| 200 | case (64) { ss := 2; } |
| 201 | case (90) { ss := 3; } |
| 202 | |
| 203 | case (116) { ss := 4; } |
| 204 | case (142) { ss := 5; } |
| 205 | case (168) { ss := 6; } |
| 206 | case (194) { ss := 7; } |
| 207 | |
| 208 | case (220) { ss := 8; } |
| 209 | case (246) { ss := 9; } |
| 210 | case (272) { ss := 10; } |
| 211 | case (298) { ss := 11; } |
| 212 | |
| 213 | case (324) { ss := 12; } |
| 214 | case (350) { ss := 13; } |
| 215 | case (376) { ss := 14; } |
| 216 | case (402) { ss := 15; } |
| 217 | } |
| 218 | |
| 219 | return ss; |
| 220 | } |
| 221 | |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 222 | function f_ClckGen_CT_handler(integer start_fn := 0) |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 223 | runs on RAW_PCU_ClckGen_CT { |
| 224 | var integer fn104, fn52, fn13; |
| 225 | |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 226 | fn := start_fn; |
| 227 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 228 | while (true) { |
| 229 | fn104 := fn mod 104; |
| 230 | fn52 := fn mod 52; |
| 231 | fn13 := fn mod 13; |
| 232 | |
| 233 | if (fn13 == 0 or fn13 == 4 or fn13 == 8) { |
| 234 | /* 1/4 bursts of a PDTCH block on both Uplink and Downlink */ |
| 235 | CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_BEG, fn)); |
| 236 | } else if (fn13 == 3 or fn13 == 7 or fn13 == 11) { |
| 237 | /* 4/4 bursts of a PDTCH block on both Uplink and Downlink */ |
| 238 | CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_END, fn)); |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 239 | } else if (fn52 == 12 or fn52 == 38) { |
Vadim Yanitskiy | b58b730 | 2019-10-06 01:01:48 +0700 | [diff] [blame] | 240 | /* 4/4 bursts of a PTCCH (Timing Advance Control) block on Downlink */ |
| 241 | if (fn104 == 90) { |
| 242 | CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PTCCH_DL_BLOCK, fn)); |
| 243 | } |
| 244 | /* One Access Burst on PTCCH/U (goes 3 time-slots after PTCCH/D) */ |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 245 | CLCK.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PTCCH_UL_BURST, fn)); |
| 246 | } |
| 247 | |
| 248 | /* TDMA hyperframe period is (2048 * 51 * 26) frames */ |
| 249 | fn := (fn + 1) mod (2048 * 51 * 26); |
| 250 | |
| 251 | /* (Re)start TDMA clock timer and wait */ |
| 252 | T_TDMAClock.start; |
| 253 | T_TDMAClock.timeout; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | type record of PCUIF_Message PCUIF_MsgQueue; |
| 258 | |
| 259 | /* Enqueue a given message to the end of a given queue */ |
| 260 | private function f_PCUIF_MsgQueue_enqueue(inout PCUIF_MsgQueue queue, |
| 261 | in PCUIF_Message msg) |
| 262 | { |
| 263 | queue := queue & { msg }; |
| 264 | } |
| 265 | |
| 266 | /* Dequeue the first message of a given queue */ |
| 267 | private function f_PCUIF_MsgQueue_dequeue(inout PCUIF_MsgQueue queue, |
| 268 | out PCUIF_Message msg) |
| 269 | { |
| 270 | var integer len := lengthof(queue); |
| 271 | |
| 272 | if (len == 0) { |
| 273 | setverdict(fail, "Failed to dequeue a message: the queue is empty!"); |
| 274 | mtc.stop; |
| 275 | } |
| 276 | |
| 277 | /* Store the first message */ |
| 278 | msg := queue[0]; |
| 279 | |
| 280 | /* Remove the first message from queue */ |
| 281 | if (len > 1) { |
| 282 | queue := substr(queue, 1, len - 1); |
| 283 | } else { |
| 284 | queue := { }; |
| 285 | } |
| 286 | } |
| 287 | |
Pau Espin Pedrol | 65bab9e | 2019-12-04 21:05:10 +0100 | [diff] [blame] | 288 | /* Get first message from queue. true if non-empty, false otherwise */ |
| 289 | private function f_PCUIF_MsgQueue_first(inout PCUIF_MsgQueue queue, |
| 290 | out PCUIF_Message msg) return boolean |
| 291 | { |
| 292 | if (lengthof(queue) == 0) { |
| 293 | return false; |
| 294 | } |
| 295 | |
| 296 | msg := queue[0]; |
| 297 | return true; |
| 298 | } |
| 299 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 300 | /* Multiple base stations can be connected to the PCU. This component |
| 301 | * represents one BTS with an associated TDMA clock generator. */ |
| 302 | type component RAW_PCU_BTS_CT { |
| 303 | /* TDMA clock generator */ |
| 304 | var RAW_PCU_ClckGen_CT vc_CLCK_GEN; |
| 305 | port RAW_PCU_MSG_PT CLCK; |
| 306 | |
| 307 | /* Queues of PCUIF messages to be sent |
| 308 | * TODO: we may have multiple PDCH time-slots */ |
| 309 | var PCUIF_MsgQueue pdtch_data_queue := { }; |
| 310 | var PCUIF_MsgQueue pdtch_rts_queue := { }; |
| 311 | var PCUIF_MsgQueue ptcch_rts_queue := { }; |
| 312 | |
| 313 | /* Connection towards the PCU interface */ |
| 314 | port RAW_PCU_MSG_PT PCUIF; |
| 315 | /* Connection towards the test case */ |
| 316 | port RAW_PCU_MSG_PT TC; |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 317 | |
| 318 | /* Whether to forward PTCCH/U burst events to the TC */ |
| 319 | var boolean cfg_ptcch_burst_fwd := false; |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 320 | |
| 321 | var PCUIF_info_ind g_info_ind; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 322 | } |
| 323 | |
Pau Espin Pedrol | 65bab9e | 2019-12-04 21:05:10 +0100 | [diff] [blame] | 324 | /* Queue received messages from Test Case, they will eventually be scheduled and |
| 325 | * sent according to their FN. FN value of 0 has the special meaning of "schedule |
| 326 | * as soon as possible". */ |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 327 | private altstep as_BTS_CT_MsgQueue(integer bts_nr) |
| 328 | runs on RAW_PCU_BTS_CT { |
| 329 | var PCUIF_Message pcu_msg; |
| 330 | |
| 331 | /* Enqueue DATA.ind and RTS.req messages */ |
| 332 | [] TC.receive(tr_PCUIF_MSG(PCU_IF_MSG_DATA_IND, bts_nr)) -> value pcu_msg { |
Pau Espin Pedrol | aa45707 | 2021-04-19 18:06:16 +0200 | [diff] [blame] | 333 | if (pcu_msg.u.data_ind.sapi == PCU_IF_SAPI_BCCH) { |
| 334 | PCUIF.send(pcu_msg); /* Forward directly ASAP */ |
| 335 | } else { |
| 336 | f_PCUIF_MsgQueue_enqueue(pdtch_data_queue, pcu_msg); |
| 337 | } |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 338 | repeat; |
| 339 | } |
| 340 | [] TC.receive(tr_PCUIF_RTS_REQ(bts_nr, sapi := PCU_IF_SAPI_PDTCH)) -> value pcu_msg { |
| 341 | f_PCUIF_MsgQueue_enqueue(pdtch_rts_queue, pcu_msg); |
| 342 | repeat; |
| 343 | } |
| 344 | [] TC.receive(tr_PCUIF_RTS_REQ(bts_nr, sapi := PCU_IF_SAPI_PTCCH)) -> value pcu_msg { |
| 345 | f_PCUIF_MsgQueue_enqueue(ptcch_rts_queue, pcu_msg); |
| 346 | repeat; |
| 347 | } |
| 348 | /* Forward other messages directly to the PCU */ |
| 349 | [] TC.receive(tr_PCUIF_MSG(?, bts_nr)) -> value pcu_msg { |
| 350 | PCUIF.send(pcu_msg); |
| 351 | repeat; |
| 352 | } |
| 353 | } |
| 354 | |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 355 | /* Submit empty data on any available TS, to set up initial TDMA clock */ |
| 356 | private function f_tx_first_data_ind(integer bts_nr, PCUIF_info_ind info_ind, integer start_fn) |
| 357 | runs on RAW_PCU_BTS_CT |
| 358 | { |
| 359 | var PCUIF_Message pcu_msg; |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 360 | |
| 361 | /* Find an active TS: */ |
| 362 | for (var uint8_t ts_nr := 0; ts_nr < 8; ts_nr := ts_nr + 1) { |
Vadim Yanitskiy | 1da1fef | 2021-03-23 04:28:18 +0100 | [diff] [blame] | 363 | for (var integer trx_nr := 0; trx_nr < lengthof(g_info_ind.trx); trx_nr := trx_nr + 1) { |
| 364 | if (g_info_ind.trx[trx_nr].pdch_mask[ts_nr] == '0'B) { |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 365 | continue; /* TRX+TS not activated */ |
| 366 | } |
| 367 | |
| 368 | /* Send empty DATA.ind to set up FN */ |
| 369 | pcu_msg := valueof(ts_PCUIF_DATA_IND(bts_nr, trx_nr, ts_nr, 0 /* FIXME */, |
| 370 | PCU_IF_SAPI_PDTCH, ''O, start_fn, |
Vadim Yanitskiy | 1da1fef | 2021-03-23 04:28:18 +0100 | [diff] [blame] | 371 | g_info_ind.trx[trx_nr].arfcn, |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 372 | rssi := -80, ber10k := 0, |
| 373 | ta_offs_qbits := 0, lqual_cb := 10)); |
| 374 | PCUIF.send(pcu_msg); |
| 375 | return; |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
Pau Espin Pedrol | 9fc065a | 2021-05-11 17:05:39 +0200 | [diff] [blame] | 380 | private function fn2macblock(uint32_t fn) return uint8_t |
| 381 | { |
| 382 | return (fn mod 52) / 4; |
| 383 | } |
| 384 | |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 385 | /* Get first message from queue. true if non-empty, false otherwise */ |
| 386 | private function f_tx_data_ind_fn(integer bts_nr, integer fn) |
| 387 | runs on RAW_PCU_BTS_CT |
| 388 | { |
| 389 | var PCUIF_Message pcu_msg; |
| 390 | var boolean has_msg, use_msg; |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 391 | |
| 392 | for (var uint8_t ts_nr := 0; ts_nr < 8; ts_nr := ts_nr + 1) { |
Vadim Yanitskiy | 1da1fef | 2021-03-23 04:28:18 +0100 | [diff] [blame] | 393 | for (var integer trx_nr := 0; trx_nr < lengthof(g_info_ind.trx); trx_nr := trx_nr + 1) { |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 394 | //var charstring prefix := "BTS=" & int2str(bts_nr) & ",TRX=" & int2str(trx_nr) & ",TS=" & int2str(ts_nr) & ",FN=" & int2str(fn) & ": "; |
Vadim Yanitskiy | 1da1fef | 2021-03-23 04:28:18 +0100 | [diff] [blame] | 395 | if (g_info_ind.trx[trx_nr].pdch_mask[ts_nr] == '0'B) { |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 396 | //log(prefix, "disabled"); |
| 397 | continue; /* TRX+TS not activated */ |
| 398 | } |
| 399 | |
| 400 | /* Check if we reached time to serve the first DATA.ind message in the queue: */ |
| 401 | has_msg := f_PCUIF_MsgQueue_first(pdtch_data_queue, pcu_msg) and |
| 402 | pcu_msg.u.data_ind.trx_nr == trx_nr and |
| 403 | pcu_msg.u.data_ind.ts_nr == ts_nr; |
| 404 | use_msg := has_msg and (pcu_msg.u.data_ind.fn == 0 or pcu_msg.u.data_ind.fn == fn); |
| 405 | if (use_msg) { |
| 406 | /* Dequeue a DATA.ind message */ |
| 407 | f_PCUIF_MsgQueue_dequeue(pdtch_data_queue, pcu_msg); |
| 408 | /* Patch TDMA frame / block number */ |
| 409 | pcu_msg.u.data_ind.fn := fn; |
Pau Espin Pedrol | 9fc065a | 2021-05-11 17:05:39 +0200 | [diff] [blame] | 410 | pcu_msg.u.data_ind.block_nr := fn2macblock(fn); |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 411 | //log(prefix, "DATA.ind"); |
| 412 | } else if (has_msg and pcu_msg.u.data_ind.fn < fn) { |
Vadim Yanitskiy | 1030b7a | 2022-10-05 01:03:01 +0700 | [diff] [blame] | 413 | setverdict(fail, "We are late scheduling the block! ", pcu_msg.u.data_ind.fn, " < ", fn); |
| 414 | mtc.stop; |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 415 | } else { |
| 416 | /* NOPE.ind: */ |
| 417 | pcu_msg := valueof(ts_PCUIF_DATA_IND(bts_nr, trx_nr, ts_nr, 0 /* FIXME */, |
| 418 | PCU_IF_SAPI_PDTCH, ''O, fn, |
Vadim Yanitskiy | 1da1fef | 2021-03-23 04:28:18 +0100 | [diff] [blame] | 419 | g_info_ind.trx[trx_nr].arfcn, |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 420 | rssi := -80, ber10k := 0, |
| 421 | ta_offs_qbits := 0, lqual_cb := 10)); |
| 422 | //log(prefix, "DATA.ind (len=0)"); |
| 423 | } |
| 424 | |
Pau Espin Pedrol | 4c23aea | 2021-11-16 19:14:00 +0100 | [diff] [blame] | 425 | PCUIF.send(pcu_msg); /* Send to the PCU and notify the TC */ |
| 426 | if (use_msg) { |
| 427 | TC.send(ts_RAW_PCU_CLCK_EV(TDMA_EV_PDTCH_BLOCK_SENT, fn)); |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | |
Pau Espin Pedrol | 65bab9e | 2019-12-04 21:05:10 +0100 | [diff] [blame] | 433 | /* Handle schedule events and manage actions: Send msgs over PCUIF to PCU, |
| 434 | * advertise Test Case about sent messages, etc. */ |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 435 | private altstep as_BTS_CT_TDMASched(integer bts_nr) |
| 436 | runs on RAW_PCU_BTS_CT { |
| 437 | var PCUIF_Message pcu_msg; |
| 438 | var RAW_PCU_Event event; |
Pau Espin Pedrol | 6072725 | 2019-12-04 21:40:25 +0100 | [diff] [blame] | 439 | var integer ev_begin_fn; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 440 | |
| 441 | [] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_BEG)) -> value event { |
| 442 | /* If the RTS queue for PDTCH is not empty, send a message */ |
| 443 | if (lengthof(pdtch_rts_queue) > 0) { |
| 444 | f_PCUIF_MsgQueue_dequeue(pdtch_rts_queue, pcu_msg); |
| 445 | |
| 446 | /* Patch TDMA frame / block number and send */ |
| 447 | pcu_msg.u.rts_req.fn := event.data.tdma_fn; |
Pau Espin Pedrol | 9fc065a | 2021-05-11 17:05:39 +0200 | [diff] [blame] | 448 | pcu_msg.u.rts_req.block_nr := fn2macblock(event.data.tdma_fn); |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 449 | PCUIF.send(pcu_msg); |
| 450 | } |
| 451 | |
| 452 | /* We don't really need to send every frame to OsmoPCU, because |
| 453 | * it omits frame numbers not starting at a MAC block. */ |
| 454 | PCUIF.send(ts_PCUIF_TIME_IND(bts_nr, event.data.tdma_fn)); |
| 455 | repeat; |
| 456 | } |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 457 | [] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PDTCH_BLOCK_END)) -> value event { |
Pau Espin Pedrol | 6072725 | 2019-12-04 21:40:25 +0100 | [diff] [blame] | 458 | /* FN matching the beginning of current block: */ |
| 459 | ev_begin_fn := event.data.tdma_fn - 3; |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 460 | f_tx_data_ind_fn(bts_nr, ev_begin_fn); |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 461 | repeat; |
| 462 | } |
| 463 | [lengthof(ptcch_rts_queue) > 0] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PTCCH_DL_BLOCK)) -> value event { |
Pau Espin Pedrol | 6072725 | 2019-12-04 21:40:25 +0100 | [diff] [blame] | 464 | /* FN matching the beginning of current block (PTCCH is interleaved over 4 non-consecutive bursts): */ |
| 465 | ev_begin_fn := event.data.tdma_fn - 78; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 466 | /* Dequeue an RTS.req message for PTCCH */ |
| 467 | f_PCUIF_MsgQueue_dequeue(ptcch_rts_queue, pcu_msg); |
| 468 | |
| 469 | /* Patch TDMA frame / block number and send */ |
Pau Espin Pedrol | 6072725 | 2019-12-04 21:40:25 +0100 | [diff] [blame] | 470 | pcu_msg.u.rts_req.fn := ev_begin_fn; |
Pau Espin Pedrol | 9fc065a | 2021-05-11 17:05:39 +0200 | [diff] [blame] | 471 | pcu_msg.u.rts_req.block_nr := fn2macblock(ev_begin_fn); |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 472 | PCUIF.send(pcu_msg); |
| 473 | repeat; |
| 474 | } |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 475 | /* Optional forwarding of PTCCH/U burst indications to the test case */ |
| 476 | [cfg_ptcch_burst_fwd] CLCK.receive(tr_RAW_PCU_EV(TDMA_EV_PTCCH_UL_BURST)) -> value event { |
| 477 | TC.send(event); |
| 478 | repeat; |
| 479 | } |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 480 | /* Ignore other clock events (and guard against an empty queue) */ |
| 481 | [] CLCK.receive(tr_RAW_PCU_CLCK_EV) { repeat; } |
| 482 | } |
| 483 | |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 484 | function f_BTS_CT_handler(integer bts_nr, PCUIF_info_ind info_ind, boolean decode_data_req := false) |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 485 | runs on RAW_PCU_BTS_CT { |
| 486 | var PCUIF_Message pcu_msg; |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 487 | var RAW_PCU_Command cmd; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 488 | var RAW_PCU_Event event; |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 489 | var BTS_PDTCH_Block pcu_msg_pdtch; |
| 490 | var BTS_PTCCH_Block pcu_msg_ptcch; |
| 491 | var BTS_CCCH_Block pcu_msg_rr; |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 492 | |
Pau Espin Pedrol | 873686f | 2021-03-05 14:57:58 +0100 | [diff] [blame] | 493 | g_info_ind := info_ind; |
| 494 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 495 | /* Init TDMA clock generator (so we can stop and start it) */ |
| 496 | vc_CLCK_GEN := RAW_PCU_ClckGen_CT.create("ClckGen-" & int2str(bts_nr)) alive; |
| 497 | connect(vc_CLCK_GEN:CLCK, self:CLCK); |
| 498 | |
| 499 | /* Wait until the PCU is connected */ |
| 500 | PCUIF.receive(tr_RAW_PCU_EV(PCU_EV_CONNECT)); |
| 501 | |
Philipp Maier | db9d894 | 2023-07-18 15:23:15 +0200 | [diff] [blame] | 502 | var template PCUIF_Sapi tr_ccch_sapi := (PCU_IF_SAPI_PCH, PCU_IF_SAPI_PCH_DT, PCU_IF_SAPI_AGCH); |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 503 | alt { |
| 504 | /* Wait for TXT.ind (PCU_VERSION) and respond with INFO.ind (SI13) */ |
| 505 | [] PCUIF.receive(tr_PCUIF_TXT_IND(bts_nr, PCU_VERSION, ?)) -> value pcu_msg { |
| 506 | log("Rx TXT.ind from the PCU, version is ", pcu_msg.u.txt_ind.text); |
| 507 | |
| 508 | /* Send System Information 13 to the PCU */ |
| 509 | PCUIF.send(PCUIF_Message:{ |
| 510 | msg_type := PCU_IF_MSG_INFO_IND, |
| 511 | bts_nr := bts_nr, |
| 512 | spare := '0000'O, |
| 513 | u := { info_ind := info_ind } |
| 514 | }); |
| 515 | |
Pau Espin Pedrol | c62ebac | 2021-03-12 15:07:06 +0100 | [diff] [blame] | 516 | const integer start_fn := 0; |
Pau Espin Pedrol | 4c23aea | 2021-11-16 19:14:00 +0100 | [diff] [blame] | 517 | f_tx_first_data_ind(bts_nr, info_ind, start_fn); |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 518 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 519 | /* Notify the test case that we're done with SI13 */ |
| 520 | TC.send(ts_RAW_PCU_EV(BTS_EV_SI13_NEGO)); |
| 521 | |
| 522 | /* Start feeding clock to the PCU */ |
Pau Espin Pedrol | ed9ca97 | 2021-03-11 20:53:21 +0100 | [diff] [blame] | 523 | vc_CLCK_GEN.start(f_ClckGen_CT_handler(start_fn)); |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 524 | repeat; |
| 525 | } |
Pau Espin Pedrol | d16bb27 | 2019-12-02 12:57:03 +0100 | [diff] [blame] | 526 | /* PCU -> TS becomes active */ |
| 527 | [] PCUIF.receive(tr_PCUIF_ACT_REQ(bts_nr, ?, ?)) -> value pcu_msg { |
| 528 | log("Rx ACT.req from the PCU: TRX" & int2str(pcu_msg.u.act_req.trx_nr) & |
| 529 | "/TS" & int2str(pcu_msg.u.act_req.ts_nr)); |
| 530 | repeat; |
| 531 | } |
| 532 | /* PCU -> TS becomes inactive */ |
| 533 | [] PCUIF.receive(tr_PCUIF_DEACT_REQ(bts_nr, ?, ?)) -> value pcu_msg { |
| 534 | log("Rx DEACT.req from the PCU: TRX" & int2str(pcu_msg.u.act_req.trx_nr) & |
| 535 | "/TS" & int2str(pcu_msg.u.act_req.ts_nr)); |
| 536 | repeat; |
| 537 | } |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 538 | [decode_data_req] PCUIF.receive(tr_PCUIF_DATA_REQ(bts_nr, ?, ?, sapi := tr_ccch_sapi)) -> value pcu_msg { |
| 539 | var octetstring data; |
Philipp Maier | db9d894 | 2023-07-18 15:23:15 +0200 | [diff] [blame] | 540 | var PCUIF_pch_dt pch_dt; |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 541 | /* On PCH the payload is prefixed with paging group (3 octets): skip it. |
| 542 | * TODO: add an additional template parameter, so we can match it. */ |
| 543 | if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_PCH) { |
| 544 | data := substr(pcu_msg.u.data_req.data, 3, pcu_msg.u.data_req.len - 3); |
| 545 | } else if (pcu_msg.u.data_req.sapi == PCU_IF_SAPI_AGCH) { |
| 546 | data := pcu_msg.u.data_req.data; |
| 547 | } |
| 548 | pcu_msg_rr.bts_nr := bts_nr; |
| 549 | pcu_msg_rr.raw := pcu_msg.u.data_req; |
Philipp Maier | db9d894 | 2023-07-18 15:23:15 +0200 | [diff] [blame] | 550 | |
| 551 | if (pcu_msg_rr.raw.sapi == PCU_IF_SAPI_PCH_DT) { |
| 552 | pch_dt := dec_PCUIF_pch_dt(pcu_msg_rr.raw.data); |
Philipp Maier | a6708cf | 2023-08-08 16:12:27 +0200 | [diff] [blame^] | 553 | pcu_msg_rr.msg_id := pch_dt.msg_id; |
Philipp Maier | db9d894 | 2023-07-18 15:23:15 +0200 | [diff] [blame] | 554 | pcu_msg_rr.imsi := pch_dt.imsi; |
| 555 | pcu_msg_rr.rr_msg := dec_GsmRrMessage(pch_dt.data); |
| 556 | } else { |
Philipp Maier | a6708cf | 2023-08-08 16:12:27 +0200 | [diff] [blame^] | 557 | pcu_msg_rr.msg_id := omit; |
Philipp Maier | db9d894 | 2023-07-18 15:23:15 +0200 | [diff] [blame] | 558 | pcu_msg_rr.imsi := omit; |
| 559 | pcu_msg_rr.rr_msg := dec_GsmRrMessage(data); |
| 560 | } |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 561 | TC.send(pcu_msg_rr); |
| 562 | repeat; |
| 563 | } |
| 564 | [decode_data_req] PCUIF.receive(tr_PCUIF_DATA_REQ(bts_nr, ?, ?, sapi := PCU_IF_SAPI_PDTCH)) -> value pcu_msg { |
| 565 | pcu_msg_pdtch.bts_nr := bts_nr; |
| 566 | pcu_msg_pdtch.raw := pcu_msg.u.data_req; |
Pau Espin Pedrol | cf2ada5 | 2021-09-22 14:11:44 +0200 | [diff] [blame] | 567 | if (pcu_msg_pdtch.raw.len != 0) { |
| 568 | pcu_msg_pdtch.dl_block := dec_RlcmacDlBlock(pcu_msg_pdtch.raw.data); |
| 569 | } else { |
| 570 | pcu_msg_pdtch.dl_block := omit; |
| 571 | } |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 572 | TC.send(pcu_msg_pdtch); |
| 573 | repeat; |
| 574 | } |
| 575 | [decode_data_req] PCUIF.receive(tr_PCUIF_DATA_REQ(bts_nr, ?, ?, sapi := PCU_IF_SAPI_PTCCH)) -> value pcu_msg { |
| 576 | pcu_msg_ptcch.bts_nr := bts_nr; |
| 577 | pcu_msg_ptcch.raw := pcu_msg.u.data_req; |
Pau Espin Pedrol | cf2ada5 | 2021-09-22 14:11:44 +0200 | [diff] [blame] | 578 | if (pcu_msg_ptcch.raw.len != 0) { |
| 579 | pcu_msg_ptcch.dl_block := dec_PTCCHDownlinkMsg(pcu_msg_ptcch.raw.data); |
| 580 | } else { |
| 581 | pcu_msg_ptcch.dl_block := omit; |
| 582 | } |
Pau Espin Pedrol | cf5c33e | 2021-01-19 18:56:55 +0100 | [diff] [blame] | 583 | TC.send(pcu_msg_ptcch); |
| 584 | repeat; |
| 585 | } |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 586 | /* PCU -> test case forwarding (filter by the BTS number) */ |
| 587 | [] PCUIF.receive(tr_PCUIF_MSG(?, bts_nr)) -> value pcu_msg { |
| 588 | TC.send(pcu_msg); |
| 589 | repeat; |
| 590 | } |
| 591 | |
| 592 | /* TC -> [Queue] -> PCU forwarding */ |
| 593 | [] as_BTS_CT_MsgQueue(bts_nr); |
| 594 | /* TDMA scheduler (clock and queue handling) */ |
| 595 | [] as_BTS_CT_TDMASched(bts_nr); |
| 596 | |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 597 | /* Command handling */ |
Vadim Yanitskiy | 91f8a09 | 2020-05-06 21:41:05 +0700 | [diff] [blame] | 598 | [] TC.receive(tr_RAW_PCU_CMD(GENERAL_CMD_SHUTDOWN)) { |
| 599 | log("Shutting down virtual BTS #", bts_nr, "..."); |
| 600 | vc_CLCK_GEN.stop; |
| 601 | break; |
| 602 | } |
Vadim Yanitskiy | 02f77d8 | 2019-10-04 17:12:35 +0700 | [diff] [blame] | 603 | [] TC.receive(tr_RAW_PCU_CMD(TDMA_CMD_ENABLE_PTCCH_UL_FWD)) { |
| 604 | log("Enabling forwarding of PTCCH/U TDMA events to the TC"); |
| 605 | cfg_ptcch_burst_fwd := true; |
| 606 | repeat; |
| 607 | } |
| 608 | [] TC.receive(tr_RAW_PCU_CMD) -> value cmd { |
| 609 | log("Ignore unhandled command: ", cmd); |
| 610 | repeat; |
| 611 | } |
| 612 | |
Vadim Yanitskiy | f7d9c0f | 2019-09-06 00:08:17 +0200 | [diff] [blame] | 613 | /* TODO: handle events (e.g. disconnection) from the PCU interface */ |
| 614 | [] PCUIF.receive(tr_RAW_PCU_EV) -> value event { |
| 615 | log("Ignore unhandled event: ", event); |
| 616 | repeat; |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | /* PCU interface (UNIX domain socket) handler */ |
| 622 | type component RAW_PCUIF_CT { |
| 623 | var ConnectionId g_pcu_conn_id := -1; |
| 624 | var boolean g_pcu_connected := false; |
| 625 | port PCUIF_CODEC_PT PCU; |
| 626 | |
| 627 | /* Connection towards BTS component(s) */ |
| 628 | port RAW_PCU_MSG_PT BTS; |
| 629 | /* Connection to the MTC (test case) */ |
| 630 | port RAW_PCU_MSG_PT MTC; |
| 631 | }; |
| 632 | |
| 633 | /* All received messages and events from OsmoPCU can be additionally sent |
| 634 | * directly to the MTC component. Pass direct := true to enable this mode. */ |
| 635 | function f_PCUIF_CT_handler(charstring pcu_sock_path, boolean direct := false) |
| 636 | runs on RAW_PCUIF_CT { |
| 637 | var PCUIF_send_data pcu_sd_msg; |
| 638 | var PCUIF_Message pcu_msg; |
| 639 | timer T_Conn := 10.0; |
| 640 | |
| 641 | log("Init PCU interface on '" & pcu_sock_path & "', waiting for connection..."); |
| 642 | g_pcu_conn_id := f_pcuif_listen(PCU, pcu_sock_path); |
| 643 | |
| 644 | /* Wait for connection */ |
| 645 | T_Conn.start; |
| 646 | alt { |
| 647 | [not g_pcu_connected] PCU.receive(UD_connected:?) { |
| 648 | log("OsmoPCU is now connected"); |
| 649 | /* Duplicate this event to the MTC if requested */ |
| 650 | if (direct) { MTC.send(ts_RAW_PCU_EV(PCU_EV_CONNECT)); } |
| 651 | BTS.send(ts_RAW_PCU_EV(PCU_EV_CONNECT)); |
| 652 | g_pcu_connected := true; |
| 653 | setverdict(pass); |
| 654 | T_Conn.stop; |
| 655 | repeat; |
| 656 | } |
| 657 | /* PCU -> BTS / MTC message forwarding */ |
| 658 | [g_pcu_connected] PCU.receive(PCUIF_send_data:?) -> value pcu_sd_msg { |
| 659 | /* Send to the BTSes if at least one is connected */ |
| 660 | if (BTS.checkstate("Connected")) { BTS.send(pcu_sd_msg.data); } |
| 661 | /* Duplicate this message to the MTC if requested */ |
| 662 | if (direct) { MTC.send(pcu_sd_msg.data); } |
| 663 | repeat; |
| 664 | } |
| 665 | /* MTC -> PCU message forwarding */ |
| 666 | [g_pcu_connected] MTC.receive(PCUIF_Message:?) -> value pcu_msg { |
| 667 | PCU.send(t_SD_PCUIF(g_pcu_conn_id, pcu_msg)); |
| 668 | repeat; |
| 669 | } |
| 670 | /* BTS -> PCU message forwarding */ |
| 671 | [g_pcu_connected] BTS.receive(PCUIF_Message:?) -> value pcu_msg { |
| 672 | PCU.send(t_SD_PCUIF(g_pcu_conn_id, pcu_msg)); |
| 673 | repeat; |
| 674 | } |
| 675 | [not g_pcu_connected] MTC.receive(PCUIF_Message:?) -> value pcu_msg { |
| 676 | log("PCU is not connected, dropping ", pcu_msg); |
| 677 | repeat; |
| 678 | } |
| 679 | [not g_pcu_connected] BTS.receive(PCUIF_Message:?) -> value pcu_msg { |
| 680 | log("PCU is not connected, dropping ", pcu_msg); |
| 681 | repeat; |
| 682 | } |
| 683 | /* TODO: handle disconnect and reconnect of the PCU */ |
| 684 | [] PCU.receive { |
| 685 | log("Unhandled message on PCU interface"); |
| 686 | repeat; |
| 687 | } |
| 688 | [not g_pcu_connected] T_Conn.timeout { |
| 689 | setverdict(fail, "Timeout waiting for PCU connection"); |
| 690 | mtc.stop; |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | } |