Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 1 | module RSL_Emulation { |
| 2 | |
Harald Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 3 | /* 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 Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 13 | * 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 Welte | 35bb716 | 2018-01-03 21:07:52 +0100 | [diff] [blame] | 20 | * 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 Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 26 | import from General_Types all; |
| 27 | import from Osmocom_Types all; |
| 28 | import from GSM_Types all; |
| 29 | import from GSM_RR_Types all; |
| 30 | import from RSL_Types all; |
| 31 | import from IPA_Types all; |
| 32 | import 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 */ |
| 37 | type component RSL_DchanHdlr { |
| 38 | /* port facing up towards dedicated channel handler */ |
| 39 | port RSL_DCHAN_PT RSL; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 40 | port RSLEM_PROC_PT RSL_PROC; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 41 | var RslChannelNr g_chan_nr; |
Harald Welte | 421e4d4 | 2018-02-12 20:04:50 +0100 | [diff] [blame] | 42 | /* second BTS / DChan during hand-over */ |
| 43 | port RSL_DCHAN_PT RSL1; |
| 44 | port RSLEM_PROC_PT RSL1_PROC; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | type record RSLDC_ChanRqd { |
| 48 | OCT1 ra, |
| 49 | GsmFrameNumber fn |
| 50 | }; |
| 51 | |
| 52 | template RSLDC_ChanRqd ts_RSLDC_ChanRqd(OCT1 ra, GsmFrameNumber fn) := { |
| 53 | ra := ra, |
| 54 | fn := fn |
| 55 | } |
| 56 | |
| 57 | type port RSL_DCHAN_PT message { |
| 58 | inout RSLDC_ChanRqd, RSL_Message; |
| 59 | } with { extension "internal" }; |
| 60 | |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 61 | type port RSL_CCHAN_PT message { |
Harald Welte | bb6aed3 | 2018-02-21 12:19:18 +0100 | [diff] [blame] | 62 | inout ASP_RSL_Unitdata, ASP_IPA_Event; |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 63 | } with { extension "internal" }; |
| 64 | |
| 65 | |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 66 | signature RSLEM_register(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr hdlr); |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 67 | signature RSLEM_unregister(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr hdlr); |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 68 | signature RSLEM_suspend(boolean suspend); |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 69 | signature RSLEM_get_last_act(in uint8_t trx_nr, in RslChannelNr chan_nr, out RSL_Message chan_act); |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 70 | |
| 71 | type port RSLEM_PROC_PT procedure { |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 72 | inout RSLEM_register, RSLEM_unregister, RSLEM_suspend, RSLEM_get_last_act; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 73 | } with { extension "internal" }; |
| 74 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 75 | /*********************************************************************** |
| 76 | * Client Component for a single dedicated channel |
| 77 | ***********************************************************************/ |
| 78 | |
| 79 | private 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' */ |
| 105 | function f_chan_est(OCT1 ra, octetstring est_l3, template RslLinkId link_id, GsmFrameNumber fn := 23) |
| 106 | runs 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 | |
| 119 | function 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 | |
| 134 | private 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 | |
| 146 | private function f_cid_by_comp_ref(RSL_DchanHdlr comp_ref) |
| 147 | runs 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 | |
| 159 | private function f_cid_by_chan_nr(uint8_t trx_nr, RslChannelNr chan_nr) |
| 160 | runs 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 | |
| 172 | private function f_cid_by_ra_fn(OCT1 ra, GsmFrameNumber fn) |
| 173 | runs 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 */ |
| 186 | private function f_cid_create(OCT1 ra, GsmFrameNumber fn, RSL_DchanHdlr comp_ref) |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 187 | runs on RSL_Emulation_CT { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 188 | var integer i; |
| 189 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 190 | if (not ispresent(ConnectionTable[i].ra) and |
| 191 | not ispresent(ConnectionTable[i].trx_nr)) { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 192 | ConnectionTable[i].ra := ra; |
| 193 | ConnectionTable[i].ra_fn := fn; |
| 194 | ConnectionTable[i].comp_ref := comp_ref; |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 195 | return; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 196 | } |
| 197 | } |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 198 | setverdict(fail, "No free entry in conn table for ", ra, fn); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 199 | } |
| 200 | |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 201 | /* create an ew client with given RA and FN */ |
| 202 | private function f_cid_create_cnr(uint8_t trx_nr, RslChannelNr chan_nr, RSL_DchanHdlr comp_ref) |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 203 | runs on RSL_Emulation_CT { |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 204 | var integer i; |
| 205 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 206 | if (not ispresent(ConnectionTable[i].ra) and |
| 207 | not ispresent(ConnectionTable[i].trx_nr)) { |
| 208 | ConnectionTable[i].stream_id := f_streamId_by_trx(trx_nr); |
| 209 | ConnectionTable[i].trx_nr := trx_nr; |
| 210 | ConnectionTable[i].chan_nr := chan_nr; |
| 211 | ConnectionTable[i].comp_ref := comp_ref; |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 212 | return; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 213 | } |
| 214 | } |
Harald Welte | 930d0a7 | 2018-03-22 22:08:40 +0100 | [diff] [blame] | 215 | setverdict(fail, "No free entry in conn table for ", trx_nr, chan_nr, comp_ref); |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | |
| 219 | /* create an ew client with given RA and FN */ |
| 220 | private function f_cid_delete_cnr(IpaStreamId stream_id, RslChannelNr chan_nr, RSL_DchanHdlr comp_ref) |
| 221 | runs on RSL_Emulation_CT return integer { |
| 222 | var integer i; |
| 223 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 224 | if (ConnectionTable[i].comp_ref == null) { |
| 225 | continue; |
| 226 | } |
| 227 | if (ConnectionTable[i].stream_id == stream_id and |
| 228 | ConnectionTable[i].chan_nr == chan_nr and |
| 229 | ConnectionTable[i].comp_ref == comp_ref) { |
| 230 | f_cid_clear(i); |
| 231 | } |
| 232 | } |
| 233 | log("Unable to find entry to delete for ", stream_id, chan_nr, comp_ref); |
| 234 | return -1; |
| 235 | } |
| 236 | |
| 237 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 238 | private function f_cid_clear(integer cid) |
| 239 | runs on RSL_Emulation_CT { |
| 240 | ConnectionTable[cid].ra := omit; |
| 241 | ConnectionTable[cid].ra_fn := omit; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 242 | ConnectionTable[cid].trx_nr := omit; |
| 243 | ConnectionTable[cid].stream_id := omit; |
| 244 | ConnectionTable[cid].chan_nr := omit; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 245 | ConnectionTable[cid].comp_ref := null; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 246 | } |
| 247 | |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 248 | /* last activation for a given channel number */ |
| 249 | type record LastActData { |
| 250 | uint8_t trx_nr optional, |
| 251 | RslChannelNr chan_nr optional, |
| 252 | RSL_Message chan_act optional |
| 253 | } |
| 254 | |
| 255 | private function f_store_last_act_data(uint8_t trx_nr, RslChannelNr chan_nr, RSL_Message chan_act) |
| 256 | runs on RSL_Emulation_CT { |
| 257 | for (var integer i := 0; i < sizeof(LastActTable); i := i+1) { |
| 258 | if (not ispresent(LastActTable[i].chan_nr) or |
| 259 | (LastActTable[i].chan_nr == chan_nr and LastActTable[i].trx_nr == trx_nr)) { |
| 260 | LastActTable[i].trx_nr := trx_nr; |
| 261 | LastActTable[i].chan_nr := chan_nr; |
| 262 | LastActTable[i].chan_act := chan_act; |
| 263 | return; |
| 264 | } |
| 265 | } |
| 266 | setverdict(fail, "No space left in LastActTable to store chan_act for ", chan_nr); |
| 267 | self.stop; |
| 268 | } |
| 269 | |
| 270 | private function f_lookup_last_act(uint8_t trx_nr, RslChannelNr chan_nr) |
| 271 | runs on RSL_Emulation_CT return RSL_Message { |
| 272 | for (var integer i := 0; i < sizeof(LastActTable); i := i+1) { |
| 273 | if (ispresent(LastActTable[i].chan_nr) and LastActTable[i].chan_nr == chan_nr |
| 274 | and LastActTable[i].trx_nr == trx_nr) { |
| 275 | return LastActTable[i].chan_act; |
| 276 | } |
| 277 | } |
| 278 | setverdict(fail, "No LastActTable entry found for TRX ", trx_nr, " ", chan_nr); |
| 279 | self.stop; |
| 280 | } |
| 281 | |
| 282 | private function f_last_act_table_init() runs on RSL_Emulation_CT { |
| 283 | for (var integer i := 0; i < sizeof(LastActTable); i := i+1) { |
| 284 | LastActTable[i] := { omit, omit, omit }; |
| 285 | } |
| 286 | } |
| 287 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 288 | type component RSL_Emulation_CT { |
| 289 | /* port facing down towards IPA emulation */ |
| 290 | port IPA_RSL_PT IPA_PT; |
| 291 | /* port facing up towards dedicated channel handler */ |
| 292 | port RSL_DCHAN_PT CLIENT_PT; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 293 | port RSLEM_PROC_PT RSL_PROC; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 294 | |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 295 | /* port for Common Channel / TRX Management */ |
| 296 | port RSL_CCHAN_PT CCHAN_PT; |
| 297 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 298 | /* state of all concurrent connections / dedicated channels */ |
| 299 | var ConnectionData ConnectionTable[64]; |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 300 | |
| 301 | /* last RSL CHAN ACT for each chan_nr */ |
| 302 | var LastActData LastActTable[64]; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | |
| 306 | /* template for an ASP_RSL_Unitdata as we receive it from the IPA_Emulateion component */ |
| 307 | private template ASP_RSL_Unitdata tr_RSL(template RSL_Message rsl, template IpaStreamId sid := ?) := { |
| 308 | streamId := sid, |
| 309 | rsl := rsl |
| 310 | } |
| 311 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 312 | private function f_trx_by_streamId(IpaStreamId id) return integer { |
| 313 | return enum2int(id); |
| 314 | } |
| 315 | |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 316 | private function f_streamId_by_trx(uint8_t trx_nr) return IpaStreamId { |
| 317 | select (trx_nr) { |
| 318 | case (0) { return IPAC_PROTO_RSL_TRX0; } |
| 319 | case (1) { return IPAC_PROTO_RSL_TRX1; } |
| 320 | case (2) { return IPAC_PROTO_RSL_TRX2; } |
| 321 | case (3) { return IPAC_PROTO_RSL_TRX3; } |
| 322 | } |
| 323 | self.stop; |
| 324 | } |
| 325 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 326 | |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 327 | function main(boolean bts_role := true) runs on RSL_Emulation_CT { |
Harald Welte | bb6aed3 | 2018-02-21 12:19:18 +0100 | [diff] [blame] | 328 | var ASP_IPA_Event evt; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 329 | var ASP_RSL_Unitdata rx_rsl; |
| 330 | var RSL_Message rx_rsl_msg; |
| 331 | var RSLDC_ChanRqd chan_rqd; |
| 332 | var RSL_DchanHdlr vc_conn; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 333 | var RslChannelNr chan_nr; |
| 334 | var uint8_t trx_nr; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 335 | var integer cid; |
| 336 | var integer i; |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 337 | /* special synchronization handling during hand-over */ |
| 338 | var boolean dchan_suspended := false; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 339 | |
Daniel Willmann | 17f970f | 2018-01-17 12:03:19 +0100 | [diff] [blame] | 340 | f_conn_table_init(); |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 341 | f_last_act_table_init(); |
Daniel Willmann | 17f970f | 2018-01-17 12:03:19 +0100 | [diff] [blame] | 342 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 343 | while (true) { |
| 344 | alt { |
Harald Welte | bb6aed3 | 2018-02-21 12:19:18 +0100 | [diff] [blame] | 345 | [bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP}) { |
| 346 | } |
| 347 | [not bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_UP}) -> value evt { |
| 348 | CCHAN_PT.send(evt); |
Harald Welte | 624f963 | 2017-12-16 19:26:04 +0100 | [diff] [blame] | 349 | } |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 350 | [bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) { |
Harald Welte | 7ae019e | 2017-12-09 00:54:15 +0100 | [diff] [blame] | 351 | IPA_PT.send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23))); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 352 | } |
Harald Welte | d879e2f | 2018-05-27 20:22:13 +0200 | [diff] [blame^] | 353 | [not bts_role] IPA_PT.receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) { } |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 354 | [bts_role] IPA_PT.receive(tr_RSL(tr_RSL_IMM_ASSIGN)) -> value rx_rsl { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 355 | var GsmRrMessage rr; |
| 356 | var OCT1 ra; |
| 357 | var GsmFrameNumber fn; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 358 | rr := dec_GsmRrMessage(rx_rsl.rsl.ies[1].body.full_imm_ass_info.payload); |
| 359 | if (ischosen(rr.payload.imm_ass)) { |
| 360 | ra := bit2oct(rr.payload.imm_ass.req_ref.ra); |
| 361 | fn := 23; //FIXME(rr.payload.imm_ass); |
| 362 | /* lookup client based on RA+time, deliver to client */ |
| 363 | cid := f_cid_by_ra_fn(ra, fn); |
| 364 | if (cid == -1) { |
| 365 | setverdict(fail, "IMM ASS for unknown DChan"); |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 366 | self.stop; |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 367 | } |
| 368 | /* update client with trx_nr */ |
| 369 | ConnectionTable[cid].trx_nr := f_trx_by_streamId(rx_rsl.streamId); |
| 370 | ConnectionTable[cid].stream_id := rx_rsl.streamId; |
| 371 | /* update client with chan_nr */ |
| 372 | ConnectionTable[cid].chan_nr := rr.payload.imm_ass.chan_desc.chan_nr; |
| 373 | /* TODO: add timer to time-out ConnectionTable entries which |
| 374 | * never get followed-up to */ |
| 375 | CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref; |
| 376 | } else if (ischosen(rr.payload.imm_ass_rej)) { |
| 377 | for (i := 0; i < sizeof(rr.payload.imm_ass_rej.payload); i := i + 1) { |
| 378 | ra := bit2oct(rr.payload.imm_ass_rej.payload[i].req_ref.ra); |
| 379 | fn := 23; //FIXME(); |
| 380 | /* lookup client based on RA+time, deliver to client */ |
| 381 | cid := f_cid_by_ra_fn(ra, fn); |
| 382 | if (cid != -1) { |
| 383 | CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref; |
| 384 | /* delete ClientTable entry, as it failed */ |
| 385 | f_cid_clear(cid); |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 391 | [bts_role] IPA_PT.receive(tr_RSL(tr_RSL_PAGING_CMD(?, ?))) -> value rx_rsl { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 392 | /* broadcast to all clients? */ |
| 393 | for (i := 0; i < sizeof(ConnectionTable); i := i + 1) { |
| 394 | if (ispresent(ConnectionTable[i].comp_ref)) { |
| 395 | CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[i].comp_ref; |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 400 | /* Forward common channel management to the special port for it */ |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 401 | [] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeT(?))) -> value rx_rsl { |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 402 | CCHAN_PT.send(rx_rsl); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 403 | } |
| 404 | |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 405 | /* Forward common channel management to the special port for it */ |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 406 | [] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeC(?))) -> value rx_rsl { |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 407 | CCHAN_PT.send(rx_rsl); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | /* blindly acknowledge all channel activations */ |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 411 | [bts_role] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV))) -> value rx_rsl { |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 412 | chan_nr := rx_rsl.rsl.ies[0].body.chan_nr; |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 413 | trx_nr := f_trx_by_streamId(rx_rsl.streamId); |
| 414 | f_store_last_act_data(trx_nr, chan_nr, rx_rsl.rsl); |
Harald Welte | 7ae019e | 2017-12-09 00:54:15 +0100 | [diff] [blame] | 415 | IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.streamId, ts_RSL_CHAN_ACT_ACK(chan_nr, 23))); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 416 | } |
| 417 | |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 418 | [not dchan_suspended] IPA_PT.receive(tr_RSL(tr_RSL_MsgTypeDR(?))) -> value rx_rsl { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 419 | /* dispatch to channel based on ChanId */ |
| 420 | cid := f_cid_by_chan_nr(f_trx_by_streamId(rx_rsl.streamId), |
| 421 | rx_rsl.rsl.ies[0].body.chan_nr); |
| 422 | if (cid != -1) { |
| 423 | CLIENT_PT.send(rx_rsl.rsl) to ConnectionTable[cid].comp_ref; |
| 424 | } else { |
| 425 | setverdict(fail, "RSL for unknown Dchan"); |
| 426 | } |
| 427 | } |
| 428 | |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 429 | [not dchan_suspended] IPA_PT.receive { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 430 | setverdict(fail, "Received unknown primitive from IPA"); |
| 431 | self.stop; |
| 432 | } |
| 433 | |
Harald Welte | 1c02fd1 | 2018-02-19 19:20:47 +0100 | [diff] [blame] | 434 | [bts_role] CLIENT_PT.receive(RSLDC_ChanRqd:?) -> value chan_rqd sender vc_conn { |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 435 | /* Store the knowledge that this sender has requested a certain RQ+time */ |
| 436 | f_cid_create(chan_rqd.ra, chan_rqd.fn, vc_conn); |
Harald Welte | 7ae019e | 2017-12-09 00:54:15 +0100 | [diff] [blame] | 437 | IPA_PT.send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0, |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 438 | ts_RSL_CHAN_RQD(chan_rqd.ra, chan_rqd.fn))); |
| 439 | } |
| 440 | |
| 441 | [] CLIENT_PT.receive(tr_RSL_MsgType(?)) -> value rx_rsl_msg sender vc_conn { |
| 442 | /* forward to BSC */ |
| 443 | cid := f_cid_by_comp_ref(vc_conn); |
Harald Welte | 7ae019e | 2017-12-09 00:54:15 +0100 | [diff] [blame] | 444 | IPA_PT.send(ts_ASP_RSL_UD(ConnectionTable[cid].stream_id, rx_rsl_msg)); |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 445 | } |
| 446 | |
Harald Welte | 34252c5 | 2018-02-24 04:51:50 +0100 | [diff] [blame] | 447 | [] CCHAN_PT.receive(tr_RSL(?)) -> value rx_rsl { |
| 448 | IPA_PT.send(ts_ASP_RSL_UD(rx_rsl.streamId, rx_rsl.rsl)); |
| 449 | } |
| 450 | |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 451 | /* explicit registration, e.g. in (non-immediate) assignment case */ |
| 452 | [] RSL_PROC.getcall(RSLEM_register:{?,?,?}) -> param(trx_nr, chan_nr, vc_conn) { |
| 453 | f_cid_create_cnr(trx_nr, chan_nr, vc_conn); |
| 454 | RSL_PROC.reply(RSLEM_register:{trx_nr, chan_nr, vc_conn}); |
| 455 | } |
| 456 | |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 457 | [] RSL_PROC.getcall(RSLEM_unregister:{?,?,?}) -> param(trx_nr, chan_nr, vc_conn) { |
| 458 | cid := f_cid_by_chan_nr(trx_nr, chan_nr); |
| 459 | f_cid_clear(cid); |
| 460 | RSL_PROC.reply(RSLEM_unregister:{trx_nr, chan_nr, vc_conn}); |
| 461 | } |
| 462 | |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 463 | [] RSL_PROC.getcall(RSLEM_suspend:{true}) { |
| 464 | log("Suspending DChan"); |
| 465 | dchan_suspended := true; |
| 466 | RSL_PROC.reply(RSLEM_suspend:{true}); |
| 467 | } |
| 468 | |
| 469 | [] RSL_PROC.getcall(RSLEM_suspend:{false}) { |
| 470 | log("Resuming DChan"); |
| 471 | dchan_suspended := false; |
| 472 | RSL_PROC.reply(RSLEM_suspend:{false}); |
| 473 | } |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 474 | |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 475 | [] RSL_PROC.getcall(RSLEM_get_last_act:{?,?,?}) -> param(trx_nr, chan_nr) { |
| 476 | var RSL_Message last_chan_act := f_lookup_last_act(trx_nr, chan_nr); |
| 477 | RSL_PROC.reply(RSLEM_get_last_act:{trx_nr, chan_nr, last_chan_act}); |
| 478 | } |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | } |
| 482 | |
Daniel Willmann | 17f970f | 2018-01-17 12:03:19 +0100 | [diff] [blame] | 483 | private function f_conn_table_init() |
| 484 | runs on RSL_Emulation_CT { |
| 485 | var integer i; |
| 486 | |
| 487 | /* Initialize the ConnectionTable */ |
| 488 | for (i := 0; i < sizeof(ConnectionTable); i := i+1) { |
| 489 | f_cid_clear(i); |
| 490 | } |
| 491 | } |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 492 | |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 493 | /* client/conn_hdlr side function to use procedure port to register stream_id/chan_nr */ |
Harald Welte | 421e4d4 | 2018-02-12 20:04:50 +0100 | [diff] [blame] | 494 | function f_rslem_register(uint8_t trx_nr, RslChannelNr chan_nr, RSLEM_PROC_PT PT := RSL_PROC) |
| 495 | runs on RSL_DchanHdlr { |
| 496 | PT.call(RSLEM_register:{trx_nr, chan_nr, self}) { |
| 497 | [] PT.getreply(RSLEM_register:{?,?,?}) {}; |
Harald Welte | f70df65 | 2018-01-29 22:00:23 +0100 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 501 | /* client/conn_hdlr side function to use procedure port to unregister stream_id/chan_nr */ |
Harald Welte | 421e4d4 | 2018-02-12 20:04:50 +0100 | [diff] [blame] | 502 | function f_rslem_unregister(uint8_t trx_nr, RslChannelNr chan_nr, RSLEM_PROC_PT PT := RSL_PROC) |
| 503 | runs on RSL_DchanHdlr { |
| 504 | PT.call(RSLEM_unregister:{trx_nr, chan_nr, self}) { |
| 505 | [] PT.getreply(RSLEM_unregister:{?,?,?}) {}; |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 506 | } |
| 507 | } |
| 508 | |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 509 | /* resume handling of RSL DChan messages from IPA until f_rslem_resume() is called */ |
| 510 | function f_rslem_suspend(RSLEM_PROC_PT PT) |
| 511 | runs on RSL_DchanHdlr { |
| 512 | PT.call(RSLEM_suspend:{true}) { |
| 513 | [] PT.getreply(RSLEM_suspend:{true}) {}; |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | /* resume handling of RSL DChan messages after f_rslem_suspend() is called */ |
| 518 | function f_rslem_resume(RSLEM_PROC_PT PT) |
| 519 | runs on RSL_DchanHdlr { |
| 520 | PT.call(RSLEM_suspend:{false}) { |
| 521 | [] PT.getreply(RSLEM_suspend:{false}) {}; |
| 522 | } |
| 523 | } |
| 524 | |
Harald Welte | ad2647b | 2018-03-22 19:53:55 +0100 | [diff] [blame] | 525 | /* obtain the last RSL_CHAN_ACT message for the given chan_nr */ |
| 526 | function f_rslem_get_last_act(RSLEM_PROC_PT PT, uint8_t trx_nr, RslChannelNr chan_nr) |
| 527 | runs on RSL_DchanHdlr return RSL_Message { |
| 528 | var RSL_Message chan_act; |
| 529 | PT.call(RSLEM_get_last_act:{trx_nr, chan_nr, -}) { |
| 530 | [] PT.getreply(RSLEM_get_last_act:{trx_nr, chan_nr, ?}) -> param(chan_act) {}; |
| 531 | } |
| 532 | return chan_act; |
| 533 | } |
| 534 | |
| 535 | |
Harald Welte | 70b52c9 | 2018-02-12 20:47:31 +0100 | [diff] [blame] | 536 | |
Harald Welte | 1909f46 | 2018-01-29 22:29:29 +0100 | [diff] [blame] | 537 | |
Harald Welte | 714ded9 | 2017-12-08 14:00:22 +0100 | [diff] [blame] | 538 | } |