Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 1 | module BSSGP_Emulation { |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 2 | |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 3 | /* BSSGP Emulation in TTCN-3 |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 4 | * (C) 2018-2020 Harald Welte <laforge@gnumonks.org> |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 5 | * All rights reserved. |
| 6 | * |
| 7 | * Released under the terms of GNU General Public License, Version 2 or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0-or-later |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 11 | * |
| 12 | * This code implements BSSGP asa hierarchy of components: |
| 13 | * - the main BSSGP_CT which runs on top of a NSE (NS Entity). |
| 14 | * - demultiplex based on BVCI. BVCI=0 is handled to a user port |
| 15 | * - a per-BVC BSSGP_BVC_CT which runs on top of BSSGP_CT, it handles |
| 16 | * one PTP BVCI (i.e. one cell) |
| 17 | * - demultiplex based on TLLI |
| 18 | * - a per-TLLI BSSGP_Client_CT which runs on top of BSSGP_BVC_CT |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 19 | */ |
| 20 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 21 | import from General_Types all; |
| 22 | import from Osmocom_Types all; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 23 | import from NS_Types all; |
| 24 | import from NS_Emulation all; |
| 25 | import from BSSGP_Types all; |
| 26 | import from Osmocom_Gb_Types all; |
| 27 | import from IPL4asp_Types all; |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 28 | |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 29 | #ifdef BSSGP_EM_L3 |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 30 | import from MobileL3_GMM_SM_Types all; |
| 31 | import from MobileL3_Types all; |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 32 | #endif |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 33 | |
| 34 | import from LLC_Types all; |
| 35 | import from LLC_Templates all; |
| 36 | |
Harald Welte | a2526a8 | 2018-02-18 19:03:36 +0100 | [diff] [blame] | 37 | import from SNDCP_Types all; |
| 38 | |
Harald Welte | 12d19b8 | 2020-10-09 11:41:06 +0200 | [diff] [blame] | 39 | |
| 40 | modulepar { |
| 41 | /* tolerate CellID absence/presence in BVC-RESET in violation to spec */ |
| 42 | boolean mp_tolerate_bvc_reset_cellid := false; |
| 43 | } |
| 44 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 45 | /*********************************************************************** |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 46 | * Communication between Client Components and per-BVC component |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 47 | ***********************************************************************/ |
| 48 | |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 49 | type record BssgpStatusIndication { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 50 | Nsei nsei optional, |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 51 | BssgpBvci bvci, |
| 52 | BvcState state |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | type record BssgpResetIndication { |
| 56 | BssgpBvci bvci |
| 57 | }; |
| 58 | |
| 59 | template (value) BssgpStatusIndication |
| 60 | ts_BssgpStsInd(template (omit) Nsei nsei, template (value) BssgpBvci bvci, |
| 61 | template (value) BvcState state) := { |
| 62 | nsei := nsei, |
| 63 | bvci := bvci, |
| 64 | state := state |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 65 | } |
| 66 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 67 | template (present) BssgpStatusIndication |
| 68 | tr_BssgpStsInd(template Nsei nsei, template (present) BssgpBvci bvci, |
| 69 | template (present) BvcState state) := { |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 70 | nsei := nsei, |
| 71 | bvci := bvci, |
| 72 | state := state |
| 73 | } |
| 74 | |
| 75 | type enumerated BvcState { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 76 | /* SGSN role: waiting to be reset by the peer */ |
| 77 | BVC_S_WAIT_RESET, |
| 78 | /* PCU role: waiting for NS_ALIVE_UNBLOCKED */ |
| 79 | BVC_S_WAIT_NS_ALIVE_UNBLOCKED, |
| 80 | /* BVC-BLOCKED state */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 81 | BVC_S_BLOCKED, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 82 | /* BVC-UNBLOCKED state */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 83 | BVC_S_UNBLOCKED |
| 84 | }; |
| 85 | |
| 86 | /* port from our (internal) point of view */ |
| 87 | type port BSSGP_SP_PT message { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 88 | in PDU_BSSGP, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 89 | PDU_LLC |
| 90 | #ifdef BSSGP_EM_L3 |
| 91 | , |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 92 | PDU_L3_MS_SGSN, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 93 | PDU_L3_SGSN_MS |
| 94 | #endif |
| 95 | ; |
Harald Welte | 955aa94 | 2019-05-03 01:29:29 +0200 | [diff] [blame] | 96 | out PDU_BSSGP, |
| 97 | PDU_LLC, |
| 98 | PDU_SN, |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 99 | NsStatusIndication, |
| 100 | BssgpStatusIndication, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 101 | ASP_Event |
| 102 | #ifdef BSSGP_EM_L3 |
| 103 | , |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 104 | PDU_L3_MS_SGSN, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 105 | PDU_L3_SGSN_MS |
| 106 | #endif |
| 107 | ; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 108 | } with { extension "internal" }; |
| 109 | |
| 110 | /* port from the user point of view */ |
| 111 | type port BSSGP_PT message { |
| 112 | in ASP_Event, |
| 113 | NsStatusIndication, |
| 114 | BssgpStatusIndication, |
Harald Welte | 955aa94 | 2019-05-03 01:29:29 +0200 | [diff] [blame] | 115 | PDU_BSSGP, |
| 116 | PDU_LLC, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 117 | PDU_SN |
| 118 | #ifdef BSSGP_EM_L3 |
| 119 | , |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 120 | PDU_L3_MS_SGSN, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 121 | PDU_L3_SGSN_MS |
| 122 | #endif |
| 123 | ; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 124 | out PDU_BSSGP, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 125 | PDU_LLC |
| 126 | #ifdef BSSGP_EM_L3 |
| 127 | , |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 128 | PDU_L3_SGSN_MS, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 129 | PDU_L3_MS_SGSN |
| 130 | #endif |
| 131 | ; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 132 | } with { extension "internal" }; |
| 133 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 134 | signature BSSGP_register_client(hexstring imsi, OCT4 tlli); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 135 | signature BSSGP_unregister_client(hexstring imsi); |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 136 | signature BSSGP_llgmm_assign(OCT4 tlli_old, OCT4 tlli); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 137 | |
| 138 | type port BSSGP_PROC_PT procedure { |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 139 | inout BSSGP_register_client, BSSGP_unregister_client, BSSGP_llgmm_assign; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 140 | } with { extension "internal" }; |
| 141 | |
| 142 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 143 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 144 | /*********************************************************************** |
| 145 | * Client Component for a single MS/TLLI |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 146 | *********************************************************************** |
| 147 | * This is what most users will want to derive their test cases from. It |
| 148 | * provides a set of three different ports (PTP, signaling, procedure) |
| 149 | * for (currently up to 3) different Cells. Those ports are all connected |
| 150 | * to one or multiple different per-BVC compoennts, depending on whether |
| 151 | * they share the same BSS or not. |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 152 | ***********************************************************************/ |
| 153 | |
| 154 | type component BSSGP_Client_CT { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 155 | /* one port array for each client; allows talking to up to 3 BVC/Cell (handover, ...) */ |
| 156 | port BSSGP_PT BSSGP[3]; /* PTP-BVC */ |
| 157 | port BSSGP_PT BSSGP_SIG[3]; /* Signaling BVC */ |
| 158 | port BSSGP_PROC_PT BSSGP_PROC[3]; /* registration / deregistration */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 159 | }; |
| 160 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 161 | function f_bssgp_client_register(hexstring imsi, OCT4 tlli, BSSGP_PROC_PT PT := BSSGP_PROC[0]) |
| 162 | runs on BSSGP_Client_CT { |
| 163 | PT.call(BSSGP_register_client:{imsi, tlli}) { |
| 164 | [] PT.getreply(BSSGP_register_client:{imsi, tlli}) {}; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | function f_bssgp_client_unregister(hexstring imsi, BSSGP_PROC_PT PT := BSSGP_PROC[0]) |
| 169 | runs on BSSGP_Client_CT { |
| 170 | PT.call(BSSGP_unregister_client:{imsi}) { |
| 171 | [] PT.getreply(BSSGP_unregister_client:{imsi}) {}; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /* TS 44.064 7.2.1.1 LLGMM-ASSIGN */ |
| 176 | function f_bssgp_client_llgmm_assign(OCT4 tlli_old, OCT4 tlli_new, BSSGP_PROC_PT PT := BSSGP_PROC[0]) |
| 177 | runs on BSSGP_Client_CT { |
| 178 | PT.call(BSSGP_llgmm_assign:{tlli_old, tlli_new}) { |
| 179 | [] PT.getreply(BSSGP_llgmm_assign:{tlli_old, tlli_new}) {}; |
| 180 | } |
| 181 | } |
| 182 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 183 | /*********************************************************************** |
| 184 | * Main Component |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 185 | *********************************************************************** |
| 186 | * This component exists once, and it runs on to of the NS_Emulation. |
| 187 | * It handles the BVC-RESET for the signaling BVCI, and dispatches messages |
| 188 | * to the per-BVC components running above it. Messages are routed by: |
| 189 | * - PTP BVCI in NS header (if non-0) |
| 190 | * - BVCI IE in messages on BVCI=0 in NS header |
| 191 | * Messages for which no unique BVC can be identified (like paging without |
| 192 | * a BVCI IE set) are broadcast to all BVC components. |
| 193 | * We also broadcast state changes (BssgpStatusIndication) and reset events |
| 194 | * (BssgpResetIndication) of the signaling BVC to all per-BVC components. |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 195 | ***********************************************************************/ |
| 196 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 197 | function BssgpStart(BssgpConfig cfg, charstring id) runs on BSSGP_CT { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 198 | g_cfg := cfg; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 199 | |
| 200 | /* create the per-BVC components based on the configuration */ |
| 201 | for (var integer i := 0; i < lengthof(g_cfg.bvc); i := i+1) { |
| 202 | var BssgpBvcConfig bvc_cfg := g_cfg.bvc[i]; |
| 203 | var charstring bvc_id := id & "-BVCI" & int2str(bvc_cfg.bvci); |
| 204 | /* create, connect and start the BVC component */ |
| 205 | var BSSGP_BVC_CT bvc_ct := BSSGP_BVC_CT.create(bvc_id); |
| 206 | connect(bvc_ct:BVC, self:BVC); |
| 207 | bvc_ct.start(f_bssgp_bvc_main(bvc_cfg, g_cfg.sgsn_role, bvc_id)); |
| 208 | /* populate the BVC state table */ |
| 209 | BvcTable[i] := { |
| 210 | bvci := bvc_cfg.bvci, |
| 211 | cell_id := bvc_cfg.cell_id, |
| 212 | comp_ref := bvc_ct |
| 213 | }; |
| 214 | } |
| 215 | |
| 216 | if (g_cfg.sgsn_role) { |
| 217 | /* The SGSN side waits for an inbound BVC-RESET on the signaling BVC */ |
| 218 | f_sign_change_state(BVC_S_WAIT_RESET); |
| 219 | } else { |
| 220 | /* The BSS/PCU side waits for an inbound NsStatusIndication to Tx BVC-RESET */ |
| 221 | f_sign_change_state(BVC_S_WAIT_NS_ALIVE_UNBLOCKED); |
| 222 | } |
| 223 | |
| 224 | /* main loop */ |
| 225 | f_bssgp_ScanEvents(); |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 226 | } |
| 227 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 228 | /* master component, exists once per BSSGP instance (NSE) */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 229 | type component BSSGP_CT { |
Stefan Sperling | f82bbb6 | 2018-05-03 19:14:28 +0200 | [diff] [blame] | 230 | /* UDP ports towards the bottom (IUT) */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 231 | port NS_PT BSCP; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 232 | |
| 233 | /* control by the user */ |
| 234 | port BSSGP_CT_PROC_PT PROC; |
| 235 | |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 236 | /* global port for procedures without any relation to a BVC |
| 237 | * (currently only) SUSPEND/RESUME */ |
| 238 | port BSSGP_SP_PT GLOBAL; |
| 239 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 240 | var BssgpConfig g_cfg; |
| 241 | |
| 242 | /* Signaling BVC (BVCI=0) */ |
| 243 | var BvcState g_sign_bvc_state := BVC_S_WAIT_RESET; |
| 244 | timer g_T2 := 60.0; |
| 245 | |
| 246 | /* port to per-BVC components */ |
| 247 | port BSSGP_BVC_SP_PT BVC; |
| 248 | /* per-BVC state table */ |
| 249 | var BvcEntity BvcTable[16]; |
| 250 | }; |
| 251 | |
| 252 | /* one element in the per-BVC state table */ |
| 253 | type record BvcEntity { |
| 254 | /* PTP BVCI of this BVC/Cell */ |
| 255 | BssgpBvci bvci, |
| 256 | /* Cell Identity of this cell */ |
| 257 | BssgpCellId cell_id, |
| 258 | /* reference to the per-BVC/cell component */ |
| 259 | BSSGP_BVC_CT comp_ref |
| 260 | }; |
| 261 | |
| 262 | /* find the per-BVC component for a given BVCI */ |
| 263 | private function f_comp_for_bvci(BssgpBvci bvci) runs on BSSGP_CT return BSSGP_BVC_CT { |
| 264 | var integer i; |
| 265 | |
| 266 | for (i := 0; i < lengthof(BvcTable); i := i+1) { |
| 267 | if (BvcTable[i].bvci == bvci) { |
| 268 | return BvcTable[i].comp_ref; |
| 269 | } |
| 270 | } |
| 271 | return null; |
| 272 | } |
| 273 | |
| 274 | /* We are in BVC_S_WAIT_RSET state (only happens in SGSN role) */ |
| 275 | altstep as_sig_wait_reset() runs on BSSGP_CT { |
| 276 | var NsUnitdataIndication udi; |
| 277 | |
| 278 | /* Respond to RESET for signalling BVCI 0 */ |
| 279 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, omit), 0)) -> value udi { |
| 280 | log("Rx BVC-RESET for Signaling BVCI=0"); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 281 | BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 282 | f_sign_change_state(BVC_S_UNBLOCKED); |
| 283 | } |
| 284 | |
| 285 | /* work-around for old, buggy libosmogb before Change-Id Ie87820537d6d616da4fd4bbf73eab06e28fda5e1 */ |
| 286 | [mp_tolerate_bvc_reset_cellid] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, g_cfg.bvc[0].cell_id), 0)) -> value udi { |
| 287 | log("Rx BVC-RESET for Signaling BVCI=0"); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 288 | BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 289 | f_sign_change_state(BVC_S_UNBLOCKED); |
| 290 | } |
| 291 | } |
| 292 | |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 293 | private template PDU_BSSGP tr_GLOBAL := ( |
| 294 | {pDU_BSSGP_SUSPEND:=?}, {pDU_BSSGP_SUSPEND_ACK:=?}, {pDU_BSSGP_SUSPEND_NACK:=?}, |
| 295 | {pDU_BSSGP_RESUME:=?}, {pDU_BSSGP_RESUME_ACK:=?}, {pDU_BSSGP_RESUME_NACK:=?} |
| 296 | ); |
| 297 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 298 | /* We are in BVC_S_UNBLOCKED state */ |
| 299 | altstep as_sig_unblocked() runs on BSSGP_CT { |
| 300 | var BSSGP_BVC_CT bvc_comp_ref; |
| 301 | var BSSGP_Client_CT vc_conn; |
| 302 | var NsUnitdataIndication udi; |
| 303 | var NsUnitdataRequest udr; |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 304 | var PDU_BSSGP bssgp; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 305 | |
| 306 | /* Messages PTP BVCI in BVCI field of NS: dispatch by that */ |
| 307 | [] BSCP.receive(f_BnsUdInd(?, (2..65535))) -> value udi { |
| 308 | bvc_comp_ref := f_comp_for_bvci(valueof(udi.bvci)); |
| 309 | if (isbound(bvc_comp_ref) and bvc_comp_ref != null) { |
| 310 | /* dispatch to BVC component */ |
| 311 | BVC.send(udi) to bvc_comp_ref; |
| 312 | } else { |
| 313 | setverdict(fail, "Rx BSSGP for unknown PTP BVCI ", udi.bvci, ": ", udi.bssgp); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 314 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(udi.bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), udi.bvci, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
| 318 | /* Messages with BVCI = 0 (Signaling) in BVCI field of NS */ |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 319 | [] BSCP.receive(f_BnsUdInd(tr_GLOBAL, 0)) -> value udi { |
| 320 | GLOBAL.send(udi.bssgp); |
| 321 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 322 | |
| 323 | /* Route based on PTP BVCI in payload/IE of signaling PDU */ |
| 324 | [] BSCP.receive(f_BnsUdInd(?, 0)) -> value udi { |
| 325 | var template (omit) BssgpBvci ptp_bvci := f_BSSGP_BVCI_get(udi.bssgp); |
| 326 | if (istemplatekind(ptp_bvci, "omit")) { |
| 327 | log("Rx on SIG BVCI without PTP BVCI: broadcasting"); |
| 328 | for (var integer i := 0; i < lengthof(BvcTable); i := i+1) { |
| 329 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 330 | BVC.send(udi) to BvcTable[i].comp_ref; |
| 331 | } |
| 332 | } |
| 333 | } else { |
| 334 | bvc_comp_ref := f_comp_for_bvci(valueof(ptp_bvci)); |
| 335 | if (isbound(bvc_comp_ref) and bvc_comp_ref != null) { |
| 336 | /* dispatch to BVC component */ |
| 337 | BVC.send(udi) to bvc_comp_ref; |
| 338 | } else { |
| 339 | setverdict(fail, "Rx SIG BSSGP for unknown PTP BVCI ", ptp_bvci, ": ", udi.bssgp); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 340 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(udi.bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | /* Handle PS-PAGING on SIGN BVCI with no conditional BVCI IE */ |
| 346 | [] BSCP.receive(f_BnsUdInd(PDU_BSSGP:{pDU_BSSGP_PAGING_PS:=?}, 0)) -> value udi { |
| 347 | /* FIXME: use LA, RA or BSS Area to dispatch instead of broadcast */ |
| 348 | for (var integer i := 0; i < lengthof(BvcTable); i := i+1) { |
| 349 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 350 | BVC.send(udi) to BvcTable[i].comp_ref; |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | /* Handle CS-PAGING on SIGN BVCI with no conditional BVCI IE */ |
| 355 | [] BSCP.receive(f_BnsUdInd(PDU_BSSGP:{pDU_BSSGP_PAGING_CS:=?}, 0)) -> value udi { |
| 356 | /* FIXME: use LA, RA or BSS Area to dispatch instead of broadcast */ |
| 357 | for (var integer i := 0; i < lengthof(BvcTable); i := i+1) { |
| 358 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 359 | BVC.send(udi) to BvcTable[i].comp_ref; |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | /* per-BVC component sends us something; forward to NS without any validation */ |
| 365 | [] BVC.receive(NsUnitdataRequest:?) -> value udr { |
| 366 | /* patch in the NSEI, as the per-BVC components have no idea about it */ |
| 367 | udr.nsei := g_cfg.nsei; |
| 368 | BSCP.send(udr); |
| 369 | } |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 370 | |
| 371 | [] GLOBAL.receive(tr_GLOBAL) -> value bssgp { |
| 372 | BSCP.send(f_BnsUdReq(bssgp, 0, 0)); |
| 373 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /* We are in BVC_S_WAIT_NS_ALIVE_UNBLOCKED (only happens in BSS role) */ |
| 377 | altstep as_sig_wait_ns_alive_unblocked() runs on BSSGP_CT { |
| 378 | var NsStatusIndication nsi; |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 379 | [] BSCP.receive(NsStatusIndication:{g_cfg.nsei,?, complement (NSVC_S_ALIVE_UNBLOCKED), NSVC_S_ALIVE_UNBLOCKED, true}) -> value nsi { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 380 | /* if we just became NS-unblocked, send a BCC-RESET */ |
| 381 | if (g_cfg.sgsn_role == false) { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 382 | BSCP.send(f_BnsUdReq(ts_BVC_RESET(BSSGP_CAUSE_OM_INTERVENTION, 0, omit), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 383 | g_T2.start; |
| 384 | /* The BVC_RESET_ACK is handled in the as_sig_allstate() below */ |
| 385 | } |
| 386 | /* Idea: We could send BVC-UNBLOCK here like some SGSN do */ |
| 387 | } |
| 388 | |
| 389 | } |
| 390 | |
| 391 | /* handling of events irrespective of BVC state */ |
| 392 | altstep as_sig_allstate() runs on BSSGP_CT { |
| 393 | var BSSGP_Client_CT vc_conn; |
| 394 | var NsUnitdataIndication udi; |
| 395 | var NsStatusIndication nsi; |
| 396 | var ASP_Event evt; |
| 397 | var BSSGP_BVC_CT bvc_comp_ref; |
| 398 | var BssgpBvci bvci; |
| 399 | |
| 400 | /* Respond to RESET for signalling BVCI 0 */ |
| 401 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, omit), 0)) -> value udi { |
| 402 | log("Rx BVC-RESET for Signaling BVCI=0"); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 403 | BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 404 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 405 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 406 | BVC.send(BssgpResetIndication:{0}) to BvcTable[i].comp_ref; |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | /* any BLOCK or UNBLOCK for the SIGNALING BVCI are illegal */ |
| 412 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK(0, ?), 0)) -> value udi { |
| 413 | setverdict(fail, "Rx BVC-BLOCK illegal for BVCI=0: ", udi); |
| 414 | } |
| 415 | [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK(0), 0)) -> value udi { |
| 416 | setverdict(fail, "Rx BVC-UNBLOCK illegal for BVCI=0: ", udi); |
| 417 | } |
| 418 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK_ACK(0), 0)) -> value udi { |
| 419 | setverdict(fail, "Rx BVC-BLOCK-ACK illegal for BVCI=0: ", udi); |
| 420 | } |
| 421 | [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK_ACK(0), 0)) -> value udi { |
| 422 | setverdict(fail, "Rx BVC-UNBLOCK-ACK illegal for BVCI=0: ", udi); |
| 423 | } |
| 424 | |
| 425 | /* Respond to BLOCK for wrong BVCI */ |
| 426 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK(?, ?), 0)) -> value udi { |
| 427 | setverdict(fail, "Rx BVC-BLOCK for unknown BVCI"); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 428 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(0, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | /* Respond to RESET with wrong BVCI */ |
| 432 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, ?, ?), 0)) -> value udi { |
| 433 | var BssgpBvci ptp_bvci := oct2int(udi.bssgp.pDU_BSSGP_BVC_RESET.bVCI.unstructured_value); |
| 434 | setverdict(fail, "Rx BVC-RESET for unknown BVCI ", ptp_bvci); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 435 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(ptp_bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /* BVC-RESET-ACK for BVCI=0 while T2 is running: Answer to a BVC-RESET we sent earlier */ |
| 439 | [g_T2.running] BSCP.receive(f_BnsUdInd(tr_BVC_RESET_ACK(0, omit), 0)) -> value udi { |
| 440 | log("BVCI(0) Rx BVC-RESET-ACK"); |
| 441 | g_T2.stop; |
| 442 | f_sign_change_state(BVC_S_UNBLOCKED); |
| 443 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 444 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 445 | BVC.send(BssgpResetIndication:{0}) to BvcTable[i].comp_ref; |
| 446 | } |
| 447 | } |
| 448 | } |
| 449 | [] g_T2.timeout { |
| 450 | setverdict(fail, "Timeout waiting for BVC-RESET-ACK on BVCI=0"); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 451 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(udi.bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 452 | g_T2.start; |
| 453 | } |
| 454 | |
| 455 | /* default case of handling unknown PDUs */ |
| 456 | [] BSCP.receive(f_BnsUdInd(?, ?)) -> value udi { |
| 457 | setverdict(fail, "Rx Unexpected BSSGP PDU ", udi.bssgp," in state ", g_sign_bvc_state); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 458 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(0, BSSGP_CAUSE_PDU_NOT_COMPATIBLE_WITH_PROTOCOL_STATE, udi.bssgp), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /* Forwarding of ASP_Event to per-BVC components */ |
| 462 | [] BSCP.receive(ASP_Event:?) -> value evt { |
| 463 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 464 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 465 | BVC.send(evt) to BvcTable[i].comp_ref; |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | /* Keep NS Status Indicaitons to us; no need to inform per-BVC components [for now?] */ |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 470 | [] BSCP.receive(tr_NsStsInd(g_cfg.nsei)) -> value nsi { } |
Harald Welte | 445fc61 | 2020-11-10 19:15:30 +0100 | [diff] [blame] | 471 | /* We should never see any different NSEI: There's one BSSGP_CT per NSE */ |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 472 | [] BSCP.receive(tr_NsStsInd(?)) -> value nsi { |
Harald Welte | 445fc61 | 2020-11-10 19:15:30 +0100 | [diff] [blame] | 473 | setverdict(fail, "Rx NsStatusInd for wrong NSEI ", nsi); |
| 474 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 475 | |
| 476 | /* Procedure port request to resolve the per-BVC component for a given ptp BVCI */ |
| 477 | [] PROC.getcall(BSSGP_get_bvci_ct:{?}) -> param(bvci) sender vc_conn { |
| 478 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 479 | if (BvcTable[i].bvci == bvci) { |
| 480 | PROC.reply(BSSGP_get_bvci_ct:{bvci} value BvcTable[i].comp_ref) to vc_conn; |
| 481 | return; |
| 482 | } |
| 483 | } |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | /* send the highest decoded layer of the message through given port */ |
| 488 | private function f_send_bssgp_dec(BssgpDecoded dec, BSSGP_Client_CT vc_conn, BSSGP_SP_PT pt) { |
| 489 | #ifdef BSSGP_EM_L3 |
| 490 | if (ispresent(dec.l3_mt)) { |
| 491 | pt.send(dec.l3_mt) to vc_conn; |
| 492 | } else if (ispresent(dec.l3_mo)) { |
| 493 | pt.send(dec.l3_mo) to vc_conn; |
| 494 | } else |
| 495 | #endif |
| 496 | if (ispresent(dec.sndcp)) { |
| 497 | pt.send(dec.sndcp) to vc_conn; |
| 498 | } else if (ispresent(dec.llc)) { |
| 499 | pt.send(dec.llc) to vc_conn; |
| 500 | } else { |
| 501 | pt.send(dec.bssgp) to vc_conn; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | |
| 506 | function f_llc_get_n_u_tx(inout LLC_Entity llc) return uint9_t { |
| 507 | var uint9_t ret := llc.n_u_tx_next; |
| 508 | llc.n_u_tx_next := llc.n_u_tx_next + 1; |
| 509 | return ret; |
| 510 | } |
| 511 | |
| 512 | #ifdef BSSGP_EM_L3 |
| 513 | function f_llc_sapi_by_l3_mo(PDU_L3_MS_SGSN l3_mo) return BIT4 { |
| 514 | if (ischosen(l3_mo.msgs.gprs_mm)) { |
| 515 | return c_LLC_SAPI_LLGMM; |
| 516 | } else if (ischosen(l3_mo.msgs.gprs_sm)) { |
| 517 | return c_LLC_SAPI_LLGMM; |
| 518 | } else if (ischosen(l3_mo.msgs.sms)) { |
| 519 | return c_LLC_SAPI_LLSMS; |
| 520 | } |
| 521 | setverdict(fail, "No LLC SAPI for ", l3_mo); |
| 522 | mtc.stop; |
| 523 | } |
| 524 | |
| 525 | private function f_llc_sapi_by_l3_mt(PDU_L3_SGSN_MS l3_mt) return BIT4 { |
| 526 | if (ischosen(l3_mt.msgs.gprs_mm)) { |
| 527 | return c_LLC_SAPI_LLGMM; |
| 528 | } else if (ischosen(l3_mt.msgs.gprs_sm)) { |
| 529 | return c_LLC_SAPI_LLGMM; |
| 530 | } else if (ischosen(l3_mt.msgs.sms)) { |
| 531 | return c_LLC_SAPI_LLSMS; |
| 532 | } |
| 533 | setverdict(fail, "No LLC SAPI for ", l3_mt); |
| 534 | mtc.stop; |
| 535 | } |
| 536 | #endif |
| 537 | |
| 538 | /* main loop of BSSGP_CT */ |
| 539 | private function f_bssgp_ScanEvents() runs on BSSGP_CT { |
| 540 | while (true) { |
| 541 | alt { |
| 542 | [g_sign_bvc_state == BVC_S_WAIT_RESET] as_sig_wait_reset(); |
| 543 | [g_sign_bvc_state == BVC_S_WAIT_NS_ALIVE_UNBLOCKED] as_sig_wait_ns_alive_unblocked(); |
| 544 | [g_sign_bvc_state == BVC_S_UNBLOCKED] as_sig_unblocked(); |
| 545 | [] as_sig_allstate(); |
| 546 | } |
| 547 | } /* while */ |
| 548 | } |
| 549 | |
| 550 | /* generate a send template. Cannot be a real template as we want to use g_cfg.nsei */ |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 551 | private function f_BnsUdReq(template PDU_BSSGP pdu, BssgpBvci bvci, integer lsp) |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 552 | runs on BSSGP_CT return NsUnitdataRequest { |
| 553 | var NsUnitdataRequest udr := { |
| 554 | bvci := bvci, |
| 555 | nsei := g_cfg.nsei, |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 556 | lsp := lsp, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 557 | /* for some weird reason we get "Dynamic test case error: Text encoder: Encoding an |
| 558 | * unbound integer value." when trying to send the reocrd rather than the octetstring */ |
| 559 | //sdu := omit, |
| 560 | //bssgp := valueof(pdu) |
| 561 | sdu := enc_PDU_BSSGP(valueof(pdu)), |
| 562 | bssgp := omit |
| 563 | } |
| 564 | return udr; |
| 565 | } |
| 566 | |
| 567 | /* generate a receive template. Cannot be a real template as we want to use g_cfg.nsei */ |
| 568 | private function f_BnsUdInd(template PDU_BSSGP pdu, template BssgpBvci bvci) |
| 569 | runs on BSSGP_CT return template (present) NsUnitdataIndication { |
| 570 | var template (present) NsUnitdataIndication udi := { |
| 571 | bvci := bvci, |
| 572 | nsei := g_cfg.nsei, |
Harald Welte | 80a249a | 2020-11-17 19:57:40 +0100 | [diff] [blame] | 573 | nsvci := ?, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 574 | sdu := *, |
| 575 | bssgp := pdu |
| 576 | } |
| 577 | return udi; |
| 578 | } |
| 579 | |
| 580 | /* change state of signaling BVCI; notify per-BVC components */ |
| 581 | private function f_sign_change_state(BvcState new_state) runs on BSSGP_CT { |
| 582 | if (new_state == g_sign_bvc_state) { |
| 583 | return; |
| 584 | } |
| 585 | log("BVCI(0) State Transition: ", g_sign_bvc_state, " -> ", new_state); |
| 586 | g_sign_bvc_state := new_state; |
| 587 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 588 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 589 | BVC.send(ts_BssgpStsInd(g_cfg.nsei, 0, g_sign_bvc_state)) to BvcTable[i].comp_ref; |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | /* User wants to get per-BVC component reference from BSSGP_CT */ |
| 595 | signature BSSGP_get_bvci_ct(BssgpBvci bvci) return BSSGP_BVC_CT; |
| 596 | |
| 597 | type port BSSGP_CT_PROC_PT procedure { |
| 598 | inout BSSGP_get_bvci_ct |
| 599 | } with { extension "internal" }; |
| 600 | |
| 601 | /* convenience wrapper function for user */ |
| 602 | function f_bssgp_get_bvci_ct(BssgpBvci bvci, BSSGP_CT_PROC_PT PT) return BSSGP_BVC_CT { |
| 603 | var BSSGP_BVC_CT res; |
| 604 | PT.call(BSSGP_get_bvci_ct:{bvci}) { |
| 605 | [] PT.getreply(BSSGP_get_bvci_ct:{bvci})-> value res { |
| 606 | return res; |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | /*********************************************************************** |
| 612 | * per-BVC (Cell) Component |
| 613 | *********************************************************************** |
| 614 | * Any number of these components runs on top of the BSSGP_CT, each |
| 615 | * representing one PTP BVC within this NSE. Users (test cases) can |
| 616 | * register with TLLI and/or IMSI via the procedure port. |
| 617 | ***********************************************************************/ |
| 618 | |
| 619 | /* per-BVC component. Exists once per cell within a BSSGP_CT */ |
| 620 | type component BSSGP_BVC_CT { |
| 621 | /* port towards the underlying BSSGP_CT */ |
| 622 | port BSSGP_BVC_PT BVC; |
| 623 | |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 624 | /* port to a management instance */ |
| 625 | port BSSGP_BVC_MGMT_SP_PT MGMT; |
| 626 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 627 | /* BSSGP-User SAP towards the user (Client) */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 628 | port BSSGP_SP_PT BSSGP_SP; |
Stefan Sperling | f82bbb6 | 2018-05-03 19:14:28 +0200 | [diff] [blame] | 629 | port BSSGP_SP_PT BSSGP_SP_SIG; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 630 | port BSSGP_PROC_PT BSSGP_PROC; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 631 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 632 | var BssgpBvcConfig g_cfg; |
| 633 | var boolean g_sgsn_role; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 634 | |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 635 | /* default Link Selector Parameter for this BVC (for traffic unrelated to a TLLI) */ |
| 636 | var integer g_bvc_lsp; |
| 637 | |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 638 | var BvcState g_ptp_bvc_state := BVC_S_BLOCKED; |
| 639 | timer g_T1 := 15.0; |
| 640 | timer g_T2 := 60.0; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 641 | var boolean g_t1_waits_for_block_ack := false; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 642 | /* for re-transmissions */ |
| 643 | var BssgpCause g_last_block_cause; |
| 644 | var BssgpCause g_last_reset_cause; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 645 | |
| 646 | var ClientEntity ClientTable[16]; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 647 | }; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 648 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 649 | /* port between global BSSGP_CT and per-BVC BSSGP_BVC_CT */ |
| 650 | type port BSSGP_BVC_SP_PT message { |
| 651 | in NsUnitdataRequest; |
| 652 | out ASP_Event, |
| 653 | BssgpStatusIndication, |
| 654 | BssgpResetIndication, |
| 655 | NsUnitdataIndication; |
| 656 | } with { extension "internal" }; |
| 657 | type port BSSGP_BVC_PT message { |
| 658 | in ASP_Event, |
| 659 | BssgpStatusIndication, |
| 660 | BssgpResetIndication, |
| 661 | NsUnitdataIndication; |
| 662 | out NsUnitdataRequest; |
| 663 | } with { extension "internal" }; |
Alexander Couzens | 6b449fb | 2018-07-31 14:19:36 +0200 | [diff] [blame] | 664 | |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 665 | /* port between BSSGP_BVC_CT and a management instance */ |
| 666 | type port BSSGP_BVC_MGMT_SP_PT message { |
| 667 | in BssgpResetRequest, |
| 668 | BssgpBlockRequest, |
| 669 | BssgpUnblockRequest; |
| 670 | out BssgpStatusIndication, |
| 671 | BssgpResetIndication; |
| 672 | } with { extension "internal" }; |
| 673 | type port BSSGP_BVC_MGMT_PT message { |
| 674 | in BssgpStatusIndication, |
| 675 | BssgpResetIndication; |
| 676 | out BssgpResetRequest, |
| 677 | BssgpBlockRequest, |
| 678 | BssgpUnblockRequest; |
| 679 | } with { extension "internal" }; |
| 680 | |
| 681 | type record BssgpResetRequest { |
| 682 | BssgpCause cause |
| 683 | }; |
| 684 | type record BssgpBlockRequest { |
| 685 | BssgpCause cause |
| 686 | }; |
| 687 | type record BssgpUnblockRequest { |
| 688 | }; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 689 | |
| 690 | /* one element in the per-TLLI state table */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 691 | type record ClientEntity { |
| 692 | OCT4 tlli, |
| 693 | OCT4 tlli_old optional, |
| 694 | hexstring imsi, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 695 | BSSGP_Client_CT comp_ref, |
| 696 | /* LLC entities, one for each SAPI */ |
| 697 | LLC_Entity llc[16] |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 698 | }; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 699 | type record LLC_Entity { |
| 700 | boolean sgsn_role, |
| 701 | /* N(U) on transmit side for next PDU */ |
| 702 | uint9_t n_u_tx_next, |
| 703 | /* N(U) on receive side, last PDU */ |
| 704 | uint9_t n_u_rx_last optional |
| 705 | }; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 706 | type record length(16) of LLC_Entity LLC_Entities; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 707 | |
Alexander Couzens | cdfb751 | 2018-07-31 15:37:14 +0200 | [diff] [blame] | 708 | function f_llc_create(boolean sgsn_role := false) return LLC_Entities { |
| 709 | var LLC_Entities llc; |
| 710 | for (var integer i := 0; i < 16; i := i+1) { |
| 711 | llc[i] := valueof(t_LLC_init(sgsn_role)); |
| 712 | } |
| 713 | return llc; |
| 714 | } |
| 715 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 716 | private template LLC_Entity t_LLC_init(boolean sgsn_role := false) := { |
| 717 | sgsn_role := sgsn_role, |
| 718 | n_u_tx_next := 0, |
| 719 | n_u_rx_last := - |
| 720 | } |
| 721 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 722 | /* configuration of BSSGP_CT */ |
| 723 | type record BssgpConfig { |
| 724 | Nsvci nsei, |
| 725 | boolean sgsn_role, |
| 726 | BssgpBvcConfigs bvc |
| 727 | }; |
| 728 | /* Configuration of one BVC (Cell) BSSGP_BVC_CT */ |
| 729 | type record BssgpBvcConfig { |
| 730 | BssgpBvci bvci, |
| 731 | BssgpCellId cell_id, |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 732 | BssgpDecodeDepth depth, |
| 733 | BssgpCreateCallback create_cb |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 734 | }; |
| 735 | type record of BssgpBvcConfig BssgpBvcConfigs; |
Oliver Smith | aac9b9c | 2019-09-02 08:36:36 +0200 | [diff] [blame] | 736 | type enumerated BssgpDecodeDepth { |
| 737 | BSSGP_DECODE_DEPTH_BSSGP, |
| 738 | BSSGP_DECODE_DEPTH_LLC, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 739 | BSSGP_DECODE_DEPTH_SNDCP |
| 740 | #ifdef BSSGP_EM_L3 |
| 741 | , |
Oliver Smith | aac9b9c | 2019-09-02 08:36:36 +0200 | [diff] [blame] | 742 | BSSGP_DECODE_DEPTH_L3 |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 743 | #endif |
Oliver Smith | aac9b9c | 2019-09-02 08:36:36 +0200 | [diff] [blame] | 744 | }; |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 745 | /* call-back function type: Called for inbound BSSGP for unknown TLLIs; could create BSSGP_ClienT_CT */ |
| 746 | type function BssgpCreateCallback(BssgpBvci bvci, BssgpCellId cell_id, OCT4 tlli, BssgpDecoded dec) runs on BSSGP_BVC_CT; |
| 747 | |
| 748 | /* Default Create Callback function: Fail and terminate */ |
| 749 | function DefaultCreateCallback(BssgpBvci bvci, BssgpCellId cell_id, OCT4 tlli, BssgpDecoded dec) runs on BSSGP_BVC_CT { |
| 750 | setverdict(fail, "Couldn't find Component for TLLI ", tlli); |
| 751 | mtc.stop; |
| 752 | } |
Oliver Smith | aac9b9c | 2019-09-02 08:36:36 +0200 | [diff] [blame] | 753 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 754 | /* |
| 755 | private function f_tbl_init() runs on BSSGP_BVC_CT { |
| 756 | var integer i; |
| 757 | for (i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 758 | ImsiTable[i] := -; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 759 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 760 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 761 | for (i := 0; i < sizeof(TlliTable); i := i+1) { |
| 762 | TlliTable[i] := -; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 763 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 764 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 765 | */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 766 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 767 | private function f_tbl_client_add(hexstring imsi, OCT4 tlli, BSSGP_Client_CT vc_conn) |
| 768 | runs on BSSGP_BVC_CT { |
| 769 | var integer i; |
| 770 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 771 | if (not isvalue(ClientTable[i].comp_ref)) { |
| 772 | log("Adding Client=", vc_conn, ", IMSI=", imsi, ", TLLI=", tlli, ", index=", i); |
| 773 | ClientTable[i] := { |
| 774 | tlli := tlli, |
| 775 | tlli_old := omit, |
| 776 | imsi := imsi, |
| 777 | comp_ref := vc_conn, |
| 778 | llc := - |
| 779 | }; |
| 780 | for (var integer j := 0; j < sizeof(ClientTable[i].llc); j := j+1) { |
| 781 | ClientTable[i].llc[j] := valueof(t_LLC_init(g_sgsn_role)); |
| 782 | } |
| 783 | return; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 784 | } |
| 785 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 786 | testcase.stop("Client Table full"); |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 787 | } |
| 788 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 789 | private function f_tbl_client_del(hexstring imsi, BSSGP_Client_CT vc_conn) runs on BSSGP_BVC_CT { |
| 790 | var integer i; |
| 791 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 792 | if (isvalue(ClientTable[i].imsi) and ClientTable[i].imsi == imsi) { |
| 793 | if (ClientTable[i].comp_ref != vc_conn) { |
| 794 | setverdict(fail, "Cannot unregister index=", i, " IMSI ", imsi, " registred to ", |
| 795 | ClientTable[i].comp_ref, " from ", vc_conn); |
| 796 | mtc.stop; |
| 797 | } |
| 798 | log("Removing Client IMSI=", imsi, ", index=", i); |
| 799 | ClientTable[i] := { |
| 800 | tlli := -, |
| 801 | tlli_old := omit, |
| 802 | imsi := ''H, |
| 803 | comp_ref := null, |
| 804 | llc := - }; |
| 805 | return; |
| 806 | } |
| 807 | } |
| 808 | log("Warning: Could not find client for IMSI ", imsi); |
| 809 | return; |
| 810 | } |
| 811 | |
| 812 | /* TS 44.064 7.2.1.1 LLGMM-ASSIGN */ |
| 813 | private function f_tbl_client_llgmm_assign(OCT4 tlli_old, OCT4 tlli_new, BSSGP_Client_CT vc_conn) |
| 814 | runs on BSSGP_BVC_CT { |
| 815 | var integer i := f_tbl_idx_by_comp(vc_conn); |
| 816 | |
| 817 | if (tlli_old == 'FFFFFFFF'O and tlli_new != 'FFFFFFFF'O) { |
| 818 | /* TLLI assignment */ |
| 819 | ClientTable[i].tlli := tlli_new; |
| 820 | ClientTable[i].tlli_old := omit; |
| 821 | } else if (tlli_old != 'FFFFFFFF'O and tlli_new != 'FFFFFFFF'O) { |
| 822 | /* TLLI change: both active */ |
| 823 | ClientTable[i].tlli := tlli_new; |
| 824 | ClientTable[i].tlli_old := tlli_old; |
| 825 | } else if (tlli_old != 'FFFFFFFF'O and tlli_new == 'FFFFFFFF'O) { |
| 826 | /* TLLI unassignment: old shall be unassigned; new stays */ |
| 827 | ClientTable[i].tlli_old := omit; |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | private function f_tbl_comp_by_imsi(hexstring imsi) runs on BSSGP_BVC_CT return BSSGP_Client_CT { |
| 832 | var integer i; |
| 833 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 834 | if (isvalue(ClientTable[i].imsi) and isvalue(ClientTable[i].comp_ref) |
| 835 | and ClientTable[i].imsi == imsi) { |
| 836 | return ClientTable[i].comp_ref; |
| 837 | } |
| 838 | } |
| 839 | setverdict(fail, "Couldn't find Component for IMSI ", imsi); |
| 840 | mtc.stop; |
| 841 | } |
| 842 | |
| 843 | private function f_tbl_comp_by_tlli(OCT4 tlli) runs on BSSGP_BVC_CT return BSSGP_Client_CT { |
| 844 | var integer i; |
| 845 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 846 | if (isvalue(ClientTable[i].comp_ref) and |
| 847 | (isvalue(ClientTable[i].tlli) and (ClientTable[i].tlli == tlli or |
| 848 | isvalue(ClientTable[i].tlli_old) and ClientTable[i].tlli_old == tlli) )) { |
| 849 | return ClientTable[i].comp_ref; |
| 850 | } |
| 851 | } |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 852 | return null; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | private function f_tbl_idx_by_comp(BSSGP_Client_CT comp_ref) runs on BSSGP_BVC_CT return integer { |
| 856 | var integer i; |
| 857 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 858 | if (isvalue(ClientTable[i].comp_ref) and ClientTable[i].comp_ref == comp_ref) { |
| 859 | return i; |
| 860 | } |
| 861 | } |
| 862 | setverdict(fail, "Couldn't find Client for Component ", comp_ref); |
| 863 | mtc.stop; |
| 864 | } |
| 865 | |
| 866 | private function f_tbl_tlli_by_comp(BSSGP_Client_CT comp_ref) runs on BSSGP_BVC_CT return OCT4 { |
| 867 | var integer i; |
| 868 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 869 | if (isvalue(ClientTable[i].tlli) and isvalue(ClientTable[i].comp_ref) |
| 870 | and ClientTable[i].comp_ref == comp_ref) { |
| 871 | return ClientTable[i].tlli; |
| 872 | } |
| 873 | } |
| 874 | setverdict(fail, "Couldn't find TLLI for Component ", comp_ref); |
| 875 | mtc.stop; |
| 876 | } |
| 877 | |
| 878 | /* PDU_BSSGP enhanced with LLC and possibly L3 decoded payloads */ |
| 879 | type record BssgpDecoded { |
| 880 | PDU_BSSGP bssgp, |
| 881 | PDU_LLC llc optional, |
| 882 | #ifdef BSSGP_EM_L3 |
| 883 | PDU_L3_MS_SGSN l3_mo optional, |
| 884 | PDU_L3_SGSN_MS l3_mt optional, |
| 885 | #endif |
| 886 | PDU_SN sndcp optional |
| 887 | } |
| 888 | |
| 889 | /* Decode a PDU_BSSGP into a BssgpDecoded (i.e. with LLC/L3 decoded, as applicable) */ |
| 890 | private function f_dec_bssgp(PDU_BSSGP bssgp) runs on BSSGP_BVC_CT return BssgpDecoded { |
| 891 | var BssgpDecoded dec := { |
| 892 | bssgp := bssgp, |
| 893 | llc := omit, |
| 894 | #ifdef BSSGP_EM_L3 |
| 895 | l3_mo := omit, |
| 896 | l3_mt := omit, |
| 897 | #endif |
| 898 | sndcp := omit |
| 899 | }; |
| 900 | |
| 901 | /* Decode LLC, if it is a PDU that contains LLC */ |
| 902 | if (g_cfg.depth >= BSSGP_DECODE_DEPTH_LLC) { |
| 903 | if (ischosen(bssgp.pDU_BSSGP_DL_UNITDATA)) { |
| 904 | dec.llc := dec_PDU_LLC(bssgp.pDU_BSSGP_DL_UNITDATA.lLC_PDU.lLC_PDU); |
| 905 | } else if (ischosen(bssgp.pDU_BSSGP_UL_UNITDATA)) { |
| 906 | dec.llc := dec_PDU_LLC(bssgp.pDU_BSSGP_UL_UNITDATA.lLC_PDU.lLC_PDU); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | /* Decode SNDCP, if it is a LLC PDU containing user plane data */ |
| 911 | if (g_cfg.depth >= BSSGP_DECODE_DEPTH_SNDCP) { |
| 912 | if (isvalue(dec.llc) and match(dec.llc, tr_LLC_UI_USER)) { |
| 913 | dec.sndcp := dec_PDU_SN(dec.llc.pDU_LLC_UI.information_field_UI); |
| 914 | } |
| 915 | } |
| 916 | |
| 917 | #ifdef BSSGP_EM_L3 |
| 918 | /* Decode L3, if it is a LLC PDU containing L3 */ |
| 919 | if (g_cfg.depth >= BSSGP_DECODE_DEPTH_L3) { |
| 920 | if (isvalue(dec.llc) and match(dec.llc, tr_LLC_UI_L3)) { |
| 921 | if (g_sgsn_role) { |
| 922 | dec.l3_mo := dec_PDU_L3_MS_SGSN(dec.llc.pDU_LLC_UI.information_field_UI); |
| 923 | } else { |
| 924 | dec.l3_mt := dec_PDU_L3_SGSN_MS(dec.llc.pDU_LLC_UI.information_field_UI); |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | #endif |
| 929 | |
| 930 | return dec; |
| 931 | } |
| 932 | |
| 933 | private function f_ptp_sendUnblock() runs on BSSGP_BVC_CT { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 934 | BVC.send(ts_ptp_BnsUdReq(t_BVC_UNBLOCK(g_cfg.bvci), 0, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 935 | g_t1_waits_for_block_ack := false; |
| 936 | g_T1.start; |
| 937 | } |
| 938 | |
| 939 | private function f_ptp_sendBlock(BssgpCause cause) runs on BSSGP_BVC_CT { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 940 | BVC.send(ts_ptp_BnsUdReq(t_BVC_BLOCK(g_cfg.bvci, cause), 0, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 941 | g_t1_waits_for_block_ack := true; |
| 942 | g_T1.start; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 943 | g_last_block_cause := cause; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | private function f_ptp_sendStatus(BssgpCause cause, PDU_BSSGP pdu) runs on BSSGP_BVC_CT { |
| 947 | /* FIXME: Make sure correct Signaling or PTP BVCI is used! */ |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 948 | BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_STATUS(g_cfg.bvci, cause, pdu), g_cfg.bvci, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 949 | } |
| 950 | |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 951 | private function f_ptp_sendReset(BssgpCause cause := BSSGP_CAUSE_OM_INTERVENTION) runs on BSSGP_BVC_CT { |
Harald Welte | c967d0e | 2020-09-14 16:07:26 +0200 | [diff] [blame] | 952 | var PDU_BSSGP pdu; |
| 953 | |
| 954 | /* The Cell Identifier IE is mandatory in the BVC-RESET PDU sent from BSS to |
| 955 | * SGSN in order to reset a BVC corresponding to a PTP functional entity. The |
| 956 | * Cell Identifier IE shall not be used in any other BVC-RESET PDU. */ |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 957 | if (g_sgsn_role) { |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 958 | pdu := valueof(ts_BVC_RESET(cause, g_cfg.bvci, omit)); |
Harald Welte | c967d0e | 2020-09-14 16:07:26 +0200 | [diff] [blame] | 959 | } else { |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 960 | pdu := valueof(ts_BVC_RESET(cause, g_cfg.bvci, g_cfg.cell_id)); |
Harald Welte | c967d0e | 2020-09-14 16:07:26 +0200 | [diff] [blame] | 961 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 962 | |
| 963 | /* BVC-RESET is always sent via the SIGNALLING BVCI, see Table 5.4.1 */ |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 964 | BVC.send(ts_ptp_BnsUdReq(pdu, 0, g_bvc_lsp)); |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 965 | g_T2.start; |
| 966 | //f_change_state(BVC_S_WAIT_RESET); |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 967 | g_last_reset_cause := cause; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 968 | } |
| 969 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 970 | /* PTP-BVC is in BVC_S_BLOCKED state */ |
| 971 | private altstep as_ptp_blocked() runs on BSSGP_BVC_CT { |
| 972 | var NsUnitdataIndication udi; |
| 973 | |
| 974 | [g_T1.running and not g_t1_waits_for_block_ack] BVC.receive(tr_ptp_BnsUdInd(t_BVC_UNBLOCK_ACK(g_cfg.bvci), 0)) { |
| 975 | g_T1.stop; |
| 976 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 977 | } |
| 978 | |
| 979 | /* RESET-ACK before T2 timeout: reset successful. In SGSN role, CellID must be present */ |
| 980 | [g_T2.running and g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET_ACK(g_cfg.bvci, g_cfg.cell_id), 0)) -> value udi { |
| 981 | g_T2.stop; |
| 982 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 983 | } |
| 984 | /* RESET-ACK before T2 timeout: reset successful. In BSS role, CellID must be absent */ |
| 985 | [g_T2.running and not g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET_ACK(g_cfg.bvci, omit), 0)) -> value udi { |
| 986 | g_T2.stop; |
| 987 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 988 | } |
| 989 | |
| 990 | [] g_T2.timeout { |
| 991 | /* BVC-RESET-ACK PDU was not received within T2: retransmit */ |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 992 | f_ptp_sendReset(g_last_reset_cause); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 993 | } |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 994 | |
| 995 | [] MGMT.receive(BssgpUnblockRequest:?) { |
| 996 | f_ptp_sendUnblock(); |
| 997 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 998 | } |
| 999 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1000 | /* PTP-BVC is in UNBLOCKED state */ |
| 1001 | private altstep as_ptp_unblocked() runs on BSSGP_BVC_CT { |
| 1002 | var NsUnitdataIndication udi; |
| 1003 | var NsStatusIndication nsi; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1004 | var BssgpBlockRequest bbr; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1005 | var BSSGP_Client_CT vc_conn; |
| 1006 | var ASP_Event evt; |
| 1007 | var PDU_BSSGP bs_pdu; |
| 1008 | var PDU_LLC llc; |
| 1009 | #ifdef BSSGP_EM_L3 |
| 1010 | var PDU_L3_MS_SGSN l3_mo; |
| 1011 | var PDU_L3_SGSN_MS l3_mt; |
| 1012 | #endif |
| 1013 | |
| 1014 | /* bogus unblock, just respond with ACK */ |
| 1015 | [] BVC.receive(tr_ptp_BnsUdInd(t_BVC_UNBLOCK(g_cfg.bvci), 0)) -> value udi { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1016 | BVC.send(ts_ptp_BnsUdReq(t_BVC_UNBLOCK_ACK(g_cfg.bvci), 0, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1017 | } |
| 1018 | /* Respond to BLOCK with BLOCK-ACK + change state */ |
| 1019 | [] BVC.receive(tr_ptp_BnsUdInd(t_BVC_BLOCK(g_cfg.bvci, ?), 0)) -> value udi { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1020 | BVC.send(ts_ptp_BnsUdReq(t_BVC_BLOCK_ACK(g_cfg.bvci), 0, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1021 | g_T1.stop; |
| 1022 | f_ptp_change_state(BVC_S_BLOCKED); |
| 1023 | } |
| 1024 | /* BLOCK-ACK before T1 timeout: mark as blocked */ |
| 1025 | [g_T1.running and g_t1_waits_for_block_ack] BVC.receive(tr_ptp_BnsUdInd(t_BVC_BLOCK_ACK(g_cfg.bvci), 0)) -> value udi { |
| 1026 | g_T1.stop; |
| 1027 | f_ptp_change_state(BVC_S_BLOCKED); |
| 1028 | } |
| 1029 | /* Re-transmit BLOCK / UNBLOCK on T1 timeout */ |
| 1030 | [not g_t1_waits_for_block_ack] g_T1.timeout { |
| 1031 | f_ptp_sendUnblock(); |
| 1032 | } |
| 1033 | [g_t1_waits_for_block_ack] g_T1.timeout { |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1034 | f_ptp_sendBlock(g_last_block_cause); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | /* simply acknowledge all per-BVC Flow Control Messages */ |
| 1038 | [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_FC_BVC, g_cfg.bvci)) -> value udi { |
| 1039 | var OCT1 tag := udi.bssgp.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value; |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1040 | BVC.send(ts_ptp_BnsUdReq(t_BVC_FC_BVC_ACK(tag), g_cfg.bvci, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1041 | } |
| 1042 | /* |
| 1043 | [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(t_BVC_FC_MS, g_cfg.bvci)) { |
| 1044 | BVC.send(ts_ptp_BnsUdReq(t_BVC_FC_MS_ACK, g_cfg.bvci)); |
| 1045 | } |
| 1046 | */ |
| 1047 | /* Any other PTP BSSGP message: If it has TLLI, route to component; otherwise broadcast */ |
| 1048 | [] BVC.receive(tr_ptp_BnsUdInd(?, g_cfg.bvci)) -> value udi { |
| 1049 | var BssgpDecoded dec := f_dec_bssgp(udi.bssgp); |
| 1050 | var template OCT4 tlli := f_bssgp_get_tlli(udi.bssgp); |
| 1051 | if (isvalue(tlli)) { |
| 1052 | vc_conn := f_tbl_comp_by_tlli(valueof(tlli)); |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 1053 | if (vc_conn == null) { |
| 1054 | g_cfg.create_cb.apply(g_cfg.bvci, g_cfg.cell_id, valueof(tlli), dec); |
| 1055 | } else { |
| 1056 | f_send_bssgp_dec(dec, vc_conn, BSSGP_SP); |
| 1057 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1058 | } else { |
| 1059 | log("No TLLI: Broadcasting ", dec); |
| 1060 | /* broadcast this message to all components */ |
| 1061 | // TITAN DOESN'T DO THIS, *SIGH*: "BSSGP_SP.send(dec) to all component;" |
| 1062 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 1063 | if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) { |
| 1064 | f_send_bssgp_dec(dec, ClientTable[i].comp_ref, BSSGP_SP); |
| 1065 | } |
| 1066 | } |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | /* Any other SIG BSSGP message: If it has TLLI, route to component; otherwise broadcast */ |
| 1071 | [] BVC.receive(tr_ptp_BnsUdInd(?, 0)) -> value udi { |
| 1072 | var BssgpDecoded dec := f_dec_bssgp(udi.bssgp); |
| 1073 | var template OCT4 tlli := f_bssgp_get_tlli(udi.bssgp); |
| 1074 | if (isvalue(tlli)) { |
| 1075 | vc_conn := f_tbl_comp_by_tlli(valueof(tlli)); |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 1076 | if (vc_conn == null) { |
| 1077 | g_cfg.create_cb.apply(g_cfg.bvci, g_cfg.cell_id, valueof(tlli), dec); |
| 1078 | } else { |
| 1079 | f_send_bssgp_dec(dec, vc_conn, BSSGP_SP_SIG); |
| 1080 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1081 | } else { |
| 1082 | log("No TLLI: Broadcasting ", dec); |
| 1083 | /* broadcast this message to all components */ |
| 1084 | // TITAN DOESN'T DO THIS, *SIGH*: "BSSGP_SP.send(dec) to all component;" |
| 1085 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 1086 | if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) { |
| 1087 | f_send_bssgp_dec(dec, ClientTable[i].comp_ref, BSSGP_SP_SIG); |
| 1088 | } |
| 1089 | } |
| 1090 | } |
| 1091 | } |
| 1092 | |
| 1093 | /* ConnHdlr sends BSSGP on BVCI=0 port: forward it to BSSGP_CT */ |
| 1094 | [] BSSGP_SP_SIG.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1095 | BVC.send(ts_ptp_BnsUdReq(bs_pdu, 0, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | /* ConnHdlr sends BSSGP on BVCI=PTP port: forward it to BSSGP_CT */ |
| 1099 | [] BSSGP_SP.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1100 | BVC.send(ts_ptp_BnsUdReq(bs_pdu, g_cfg.bvci, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | #ifdef BSSGP_EM_L3 |
| 1104 | /* ConnHdlr sends L3: Encode and send as UL_UD / DL_UD */ |
| 1105 | [g_sgsn_role] BSSGP_SP.receive(PDU_L3_SGSN_MS:?) -> value l3_mt sender vc_conn { |
| 1106 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1107 | var OCT4 tlli := ClientTable[idx].tlli; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1108 | var octetstring l3_enc := enc_PDU_L3_SGSN_MS(l3_mt); |
| 1109 | var BIT4 sapi := f_llc_sapi_by_l3_mt(l3_mt); |
| 1110 | var integer n_u := f_llc_get_n_u_tx(ClientTable[idx].llc[bit2int(sapi)]); |
| 1111 | var octetstring llc_enc := enc_PDU_LLC(valueof(ts_LLC_UI(l3_enc, sapi, '1'B, n_u))); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1112 | BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_DL_UD(tlli, llc_enc), g_cfg.bvci, oct2int(tlli))); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1113 | } |
| 1114 | [not g_sgsn_role] BSSGP_SP.receive(PDU_L3_MS_SGSN:?) -> value l3_mo sender vc_conn { |
| 1115 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1116 | var OCT4 tlli := ClientTable[idx].tlli; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1117 | var octetstring l3_enc := enc_PDU_L3_MS_SGSN(l3_mo); |
| 1118 | var BIT4 sapi := f_llc_sapi_by_l3_mo(l3_mo); |
| 1119 | var integer n_u := f_llc_get_n_u_tx(ClientTable[idx].llc[bit2int(sapi)]); |
| 1120 | var octetstring llc_enc := enc_PDU_LLC(valueof(ts_LLC_UI(l3_enc, sapi, '1'B, n_u))); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1121 | BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_UL_UD(tlli, g_cfg.cell_id, llc_enc), g_cfg.bvci, oct2int(tlli))); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1122 | } |
| 1123 | #endif |
| 1124 | |
| 1125 | /* ConnHdlr sends raw LLC: Encode and send as UL_UD / DL_UD */ |
| 1126 | [not g_sgsn_role] BSSGP_SP.receive(PDU_LLC:?) -> value llc sender vc_conn { |
| 1127 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1128 | var OCT4 tlli := ClientTable[idx].tlli; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1129 | var octetstring llc_enc := enc_PDU_LLC(llc); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1130 | BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_UL_UD(tlli, g_cfg.cell_id, llc_enc), g_cfg.bvci, oct2int(tlli))); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1131 | } |
| 1132 | [g_sgsn_role] BSSGP_SP.receive(PDU_LLC:?) -> value llc sender vc_conn { |
| 1133 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1134 | var OCT4 tlli := ClientTable[idx].tlli; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1135 | var octetstring llc_enc := enc_PDU_LLC(llc); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1136 | BVC.send(ts_ptp_BnsUdReq(ts_BSSGP_DL_UD(tlli, llc_enc), g_cfg.bvci, oct2int(tlli))); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1137 | } |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1138 | |
| 1139 | [] MGMT.receive(BssgpBlockRequest:?) -> value bbr { |
| 1140 | f_ptp_sendBlock(bbr.cause); |
| 1141 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 1142 | } |
| 1143 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1144 | /* Events permitted in all states */ |
| 1145 | private altstep as_ptp_allstate() runs on BSSGP_BVC_CT { |
| 1146 | var NsUnitdataIndication udi; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1147 | var BssgpResetRequest brr; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1148 | var BSSGP_Client_CT vc_conn; |
| 1149 | var OCT4 tlli, tlli_old; |
| 1150 | var hexstring imsi; |
| 1151 | |
| 1152 | /* Signaling BVC was reset */ |
| 1153 | [] BVC.receive(BssgpResetIndication:{0}) { |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1154 | if (MGMT.checkstate("Connected")) { |
| 1155 | MGMT.send(BssgpResetIndication:{0}); |
| 1156 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1157 | if (not g_sgsn_role) { |
| 1158 | f_ptp_change_state(BVC_S_BLOCKED); |
| 1159 | /* when the BSS side signaling PTP is RESET, all PTP BVC must start the |
| 1160 | * reset procedure */ |
| 1161 | f_ptp_sendReset(); |
| 1162 | } else { |
| 1163 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | /* we are a SGSN: BSS/PCU-originated RESET must have a cell ID */ |
| 1168 | [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET(?, g_cfg.bvci, g_cfg.cell_id), 0)) -> value udi { |
| 1169 | log("Rx BVC-RESET from BVCI=", g_cfg.bvci); |
| 1170 | /* Respond to RESET with correct BVCI but without CellID */ |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1171 | BVC.send(ts_ptp_BnsUdReq(ts_BVC_RESET_ACK(g_cfg.bvci, omit), 0, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1172 | /* FIXME: reset all state? What about clients? */ |
| 1173 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1174 | } |
| 1175 | /* we are a BSS/PCU: SGSN-originated RESET must not have a cell ID */ |
| 1176 | [not g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET(?, g_cfg.bvci, omit), 0)) -> value udi { |
| 1177 | log("Rx BVC-RESET from BVCI=", g_cfg.bvci); |
| 1178 | /* Respond to RESET with correct BVCI with CellID */ |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1179 | BVC.send(ts_ptp_BnsUdReq(ts_BVC_RESET_ACK(g_cfg.bvci, g_cfg.cell_id), 0, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1180 | /* FIXME: reset all state? What about clients? */ |
| 1181 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1182 | } |
| 1183 | |
| 1184 | /* Ignore those for now */ |
| 1185 | [] BVC.receive(ASP_Event:?) { } |
| 1186 | [] BVC.receive(BssgpStatusIndication:?) { } |
| 1187 | |
| 1188 | /* catch-all */ |
| 1189 | [] BVC.receive(tr_ptp_BnsUdInd(?, 0)) -> value udi { |
| 1190 | setverdict(fail, "Received unexpected NS (SIG): ", udi); |
| 1191 | } |
| 1192 | [] BVC.receive(tr_ptp_BnsUdInd(?, ?)) -> value udi { |
| 1193 | setverdict(fail, "Received unexpected NS (PTP): ", udi); |
| 1194 | } |
| 1195 | [] BVC.receive { |
| 1196 | setverdict(fail, "Received unexpected message from BSSGP_CT"); |
| 1197 | } |
| 1198 | |
| 1199 | /* registration/deregistration of Clients (per-TLLI components) */ |
| 1200 | [] BSSGP_PROC.getcall(BSSGP_register_client:{?,?}) -> param(imsi, tlli) sender vc_conn { |
| 1201 | f_tbl_client_add(imsi, tlli, vc_conn); |
| 1202 | BSSGP_PROC.reply(BSSGP_register_client:{imsi, tlli}) to vc_conn; |
| 1203 | } |
| 1204 | [] BSSGP_PROC.getcall(BSSGP_unregister_client:{?}) -> param(imsi) sender vc_conn { |
| 1205 | f_tbl_client_del(imsi, vc_conn); |
| 1206 | BSSGP_PROC.reply(BSSGP_unregister_client:{imsi}) to vc_conn; |
| 1207 | } |
| 1208 | [] BSSGP_PROC.getcall(BSSGP_llgmm_assign:{?,?}) -> param(tlli_old, tlli) sender vc_conn { |
| 1209 | f_tbl_client_llgmm_assign(tlli_old, tlli, vc_conn); |
| 1210 | BSSGP_PROC.reply(BSSGP_llgmm_assign:{tlli_old, tlli}) to vc_conn; |
| 1211 | } |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1212 | |
| 1213 | [] MGMT.receive(BssgpResetRequest:?) -> value brr { |
| 1214 | f_ptp_sendReset(brr.cause); |
| 1215 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | /* main loop for per-BVC component */ |
| 1219 | private function f_bssgp_bvc_ScanEvents() runs on BSSGP_BVC_CT { |
| 1220 | while (true) { |
| 1221 | alt { |
| 1222 | [g_ptp_bvc_state == BVC_S_BLOCKED] as_ptp_blocked(); |
| 1223 | [g_ptp_bvc_state == BVC_S_UNBLOCKED] as_ptp_unblocked(); |
| 1224 | [] as_ptp_allstate(); |
| 1225 | } |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | /* main function for per-BVC Component */ |
| 1230 | private function f_bssgp_bvc_main(BssgpBvcConfig cfg, boolean sgsn_role, charstring id) runs on BSSGP_BVC_CT { |
| 1231 | g_cfg := cfg; |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1232 | g_bvc_lsp := cfg.bvci; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1233 | g_sgsn_role := sgsn_role; |
| 1234 | f_bssgp_bvc_ScanEvents(); |
| 1235 | } |
| 1236 | |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1237 | template (value) NsUnitdataRequest ts_ptp_BnsUdReq(template (value) PDU_BSSGP pdu, template (value) BssgpBvci bvci, |
| 1238 | template (value) integer lsp) := { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1239 | bvci := bvci, |
| 1240 | nsei := 0, // overwritten in BSSGP_CT |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1241 | lsp := lsp, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1242 | /* for some weird reason we get "Dynamic test case error: Text encoder: Encoding an |
| 1243 | * unbound integer value." when trying to send the reocrd rather than the octetstring */ |
| 1244 | //sdu := omit, |
| 1245 | //bssgp := valueof(pdu) |
| 1246 | sdu := enc_PDU_BSSGP(valueof(pdu)), |
| 1247 | bssgp := omit |
| 1248 | } |
| 1249 | |
| 1250 | template (present) NsUnitdataIndication tr_ptp_BnsUdInd(template (present) PDU_BSSGP pdu, template (present) BssgpBvci bvci) := { |
| 1251 | bvci := bvci, |
| 1252 | nsei := ?, |
Harald Welte | 80a249a | 2020-11-17 19:57:40 +0100 | [diff] [blame] | 1253 | nsvci := ?, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1254 | sdu := *, |
| 1255 | bssgp := pdu |
| 1256 | } |
| 1257 | |
| 1258 | /* change state of PTP BVC; broadcast state change to clients */ |
| 1259 | private function f_ptp_change_state(BvcState new_state) runs on BSSGP_BVC_CT { |
| 1260 | if (new_state == g_ptp_bvc_state) { |
| 1261 | return; |
| 1262 | } |
| 1263 | log("BVCI(", g_cfg.bvci, ") State Transition: ", g_ptp_bvc_state, " -> ", new_state); |
| 1264 | g_ptp_bvc_state := new_state; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1265 | if (MGMT.checkstate("Connected")) { |
| 1266 | MGMT.send(ts_BssgpStsInd(omit, g_cfg.bvci, g_ptp_bvc_state)); |
| 1267 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1268 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 1269 | if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) { |
| 1270 | BSSGP_SP.send(ts_BssgpStsInd(omit, g_cfg.bvci, g_ptp_bvc_state)) to ClientTable[i].comp_ref; |
| 1271 | } |
| 1272 | } |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | /* attempt to extract the TLLI from a BSSGP PDU */ |
| 1276 | function f_bssgp_get_tlli(PDU_BSSGP bssgp) return template OCT4 { |
| 1277 | if (ischosen(bssgp.pDU_BSSGP_DL_UNITDATA)) { |
| 1278 | return bssgp.pDU_BSSGP_DL_UNITDATA.tLLI_current; |
| 1279 | } else if (ischosen(bssgp.pDU_BSSGP_UL_UNITDATA)) { |
| 1280 | return bssgp.pDU_BSSGP_UL_UNITDATA.tLLI; |
| 1281 | } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY)) { |
| 1282 | return bssgp.pDU_BSSGP_RA_CAPABILITY.tLLI.tLLI_Value; |
| 1283 | } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE)) { |
| 1284 | return bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE.tLLI.tLLI_Value; |
| 1285 | } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK)) { |
| 1286 | return bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK.tLLI.tLLI_Value; |
| 1287 | } else if (ischosen(bssgp.pDU_BSSGP_RADIO_STATUS)) { |
| 1288 | return bssgp.pDU_BSSGP_RADIO_STATUS.tLLI.tLLI_Value; |
| 1289 | } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND)) { |
| 1290 | return bssgp.pDU_BSSGP_SUSPEND.tLLI.tLLI_Value; |
| 1291 | } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND_ACK)) { |
| 1292 | return bssgp.pDU_BSSGP_SUSPEND_ACK.tLLI.tLLI_Value; |
| 1293 | } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND_NACK)) { |
| 1294 | return bssgp.pDU_BSSGP_SUSPEND_NACK.tLLI.tLLI_Value; |
| 1295 | } else if (ischosen(bssgp.pDU_BSSGP_RESUME)) { |
| 1296 | return bssgp.pDU_BSSGP_RESUME.tLLI.tLLI_Value; |
| 1297 | } else if (ischosen(bssgp.pDU_BSSGP_RESUME_ACK)) { |
| 1298 | return bssgp.pDU_BSSGP_RESUME_ACK.tLLI.tLLI_Value; |
| 1299 | } else if (ischosen(bssgp.pDU_BSSGP_RESUME_NACK)) { |
| 1300 | return bssgp.pDU_BSSGP_RESUME_NACK.tLLI.tLLI_Value; |
| 1301 | } else if (ischosen(bssgp.pDU_BSSGP_FLUSH_LL)) { |
| 1302 | return bssgp.pDU_BSSGP_FLUSH_LL.tLLI.tLLI_Value; |
| 1303 | } else if (ischosen(bssgp.pDU_BSSGP_FLUSH_LL_ACK)) { |
| 1304 | return bssgp.pDU_BSSGP_FLUSH_LL_ACK.tLLI.tLLI_Value; |
| 1305 | } else if (ischosen(bssgp.pDU_BSSGP_LLC_DISCARDED)) { |
| 1306 | return bssgp.pDU_BSSGP_LLC_DISCARDED.tLLI.tLLI_Value; |
| 1307 | } else if (ischosen(bssgp.pDU_BSSGP_LLC_DISCARDED)) { |
| 1308 | return bssgp.pDU_BSSGP_LLC_DISCARDED.tLLI.tLLI_Value; |
| 1309 | } else if (ischosen(bssgp.pDU_BSSGP_PAGING_CS) and |
| 1310 | isvalue(bssgp.pDU_BSSGP_PAGING_CS.tLLI)) { |
| 1311 | return bssgp.pDU_BSSGP_PAGING_CS.tLLI.tLLI_Value; |
| 1312 | } else if (ischosen(bssgp.pDU_BSSGP_FLOW_CONTROL_MS)) { |
| 1313 | return bssgp.pDU_BSSGP_FLOW_CONTROL_MS.tLLI.tLLI_Value; |
| 1314 | } else if (ischosen(bssgp.pDU_BSSGP_FLOW_CONTROL_MS_ACK)) { |
| 1315 | return bssgp.pDU_BSSGP_FLOW_CONTROL_MS_ACK.tLLI.tLLI_Value; |
| 1316 | } |
| 1317 | /* TODO: Handover, PFC, LCS */ |
| 1318 | return omit; |
| 1319 | } |
| 1320 | |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 1321 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 1322 | |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 1323 | } |