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); |
Harald Welte | fba7afd | 2020-11-24 23:12:31 +0100 | [diff] [blame] | 207 | bvc_ct.start(f_bssgp_bvc_main(bvc_cfg, g_cfg.sgsn_role, g_cfg.nsei, bvc_id)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 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 | 0083ea6 | 2020-12-02 21:30:44 +0100 | [diff] [blame] | 240 | /* RAN INFORMATION MGMT */ |
| 241 | port BSSGP_SP_PT RIM; |
| 242 | |
Harald Welte | bdf96d8 | 2020-11-27 18:58:46 +0100 | [diff] [blame] | 243 | /* port to a management instance */ |
| 244 | port BSSGP_BVC_MGMT_SP_PT MGMT; |
| 245 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 246 | var BssgpConfig g_cfg; |
| 247 | |
| 248 | /* Signaling BVC (BVCI=0) */ |
| 249 | var BvcState g_sign_bvc_state := BVC_S_WAIT_RESET; |
| 250 | timer g_T2 := 60.0; |
| 251 | |
| 252 | /* port to per-BVC components */ |
| 253 | port BSSGP_BVC_SP_PT BVC; |
| 254 | /* per-BVC state table */ |
| 255 | var BvcEntity BvcTable[16]; |
| 256 | }; |
| 257 | |
| 258 | /* one element in the per-BVC state table */ |
| 259 | type record BvcEntity { |
| 260 | /* PTP BVCI of this BVC/Cell */ |
| 261 | BssgpBvci bvci, |
| 262 | /* Cell Identity of this cell */ |
| 263 | BssgpCellId cell_id, |
| 264 | /* reference to the per-BVC/cell component */ |
| 265 | BSSGP_BVC_CT comp_ref |
| 266 | }; |
| 267 | |
| 268 | /* find the per-BVC component for a given BVCI */ |
| 269 | private function f_comp_for_bvci(BssgpBvci bvci) runs on BSSGP_CT return BSSGP_BVC_CT { |
| 270 | var integer i; |
| 271 | |
| 272 | for (i := 0; i < lengthof(BvcTable); i := i+1) { |
| 273 | if (BvcTable[i].bvci == bvci) { |
| 274 | return BvcTable[i].comp_ref; |
| 275 | } |
| 276 | } |
| 277 | return null; |
| 278 | } |
| 279 | |
| 280 | /* We are in BVC_S_WAIT_RSET state (only happens in SGSN role) */ |
| 281 | altstep as_sig_wait_reset() runs on BSSGP_CT { |
| 282 | var NsUnitdataIndication udi; |
| 283 | |
| 284 | /* Respond to RESET for signalling BVCI 0 */ |
| 285 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, omit), 0)) -> value udi { |
| 286 | log("Rx BVC-RESET for Signaling BVCI=0"); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 287 | f_sign_change_state(BVC_S_UNBLOCKED); |
Harald Welte | bdf96d8 | 2020-11-27 18:58:46 +0100 | [diff] [blame] | 288 | if (MGMT.checkstate("Connected")) { |
| 289 | MGMT.send(BssgpResetIndication:{0}); |
| 290 | } |
| 291 | BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /* work-around for old, buggy libosmogb before Change-Id Ie87820537d6d616da4fd4bbf73eab06e28fda5e1 */ |
| 295 | [mp_tolerate_bvc_reset_cellid] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, g_cfg.bvc[0].cell_id), 0)) -> value udi { |
| 296 | log("Rx BVC-RESET for Signaling BVCI=0"); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 297 | f_sign_change_state(BVC_S_UNBLOCKED); |
Harald Welte | bdf96d8 | 2020-11-27 18:58:46 +0100 | [diff] [blame] | 298 | if (MGMT.checkstate("Connected")) { |
| 299 | MGMT.send(BssgpResetIndication:{0}); |
| 300 | } |
| 301 | BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
Harald Welte | 27a70cc | 2020-12-09 11:57:41 +0100 | [diff] [blame] | 305 | private template PDU_BSSGP tr_GLOBAL_SIG := ( |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 306 | {pDU_BSSGP_SUSPEND:=?}, {pDU_BSSGP_SUSPEND_ACK:=?}, {pDU_BSSGP_SUSPEND_NACK:=?}, |
Harald Welte | f8e5c5d | 2020-11-27 22:37:23 +0100 | [diff] [blame] | 307 | {pDU_BSSGP_RESUME:=?}, {pDU_BSSGP_RESUME_ACK:=?}, {pDU_BSSGP_RESUME_NACK:=?}, |
Harald Welte | f20af41 | 2020-11-28 16:11:11 +0100 | [diff] [blame] | 308 | {pDU_BSSGP_SGSN_INVOKE_TRACE:=?}, {pDU_BSSGP_OVERLOAD:=?} |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 309 | ); |
| 310 | |
Harald Welte | 0083ea6 | 2020-12-02 21:30:44 +0100 | [diff] [blame] | 311 | /* BSSGP messages that should arrive on the RIM port */ |
| 312 | private template PDU_BSSGP tr_RIM := ( |
| 313 | {pDU_BSSGP_RAN_INFORMATION:=?}, {pDU_BSSGP_RAN_INFORMATION_REQUEST:=?}, |
| 314 | {pDU_BSSGP_RAN_INFORMATION_ACK:=?}, {pDU_BSSGP_RAN_INFORMATION_ERROR:=?}, |
| 315 | {pDU_BSSGP_RAN_INFORMATION_APPLICATION_ERROR:=?} |
| 316 | ); |
| 317 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 318 | /* We are in BVC_S_UNBLOCKED state */ |
| 319 | altstep as_sig_unblocked() runs on BSSGP_CT { |
| 320 | var BSSGP_BVC_CT bvc_comp_ref; |
| 321 | var BSSGP_Client_CT vc_conn; |
| 322 | var NsUnitdataIndication udi; |
| 323 | var NsUnitdataRequest udr; |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 324 | var PDU_BSSGP bssgp; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 325 | |
| 326 | /* Messages PTP BVCI in BVCI field of NS: dispatch by that */ |
| 327 | [] BSCP.receive(f_BnsUdInd(?, (2..65535))) -> value udi { |
| 328 | bvc_comp_ref := f_comp_for_bvci(valueof(udi.bvci)); |
| 329 | if (isbound(bvc_comp_ref) and bvc_comp_ref != null) { |
| 330 | /* dispatch to BVC component */ |
| 331 | BVC.send(udi) to bvc_comp_ref; |
| 332 | } else { |
| 333 | setverdict(fail, "Rx BSSGP for unknown PTP BVCI ", udi.bvci, ": ", udi.bssgp); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 334 | 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] | 335 | } |
| 336 | } |
| 337 | |
| 338 | /* Messages with BVCI = 0 (Signaling) in BVCI field of NS */ |
Harald Welte | 27a70cc | 2020-12-09 11:57:41 +0100 | [diff] [blame] | 339 | [] BSCP.receive(f_BnsUdInd(tr_GLOBAL_SIG, 0)) -> value udi { |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 340 | GLOBAL.send(udi.bssgp); |
| 341 | } |
Harald Welte | 0083ea6 | 2020-12-02 21:30:44 +0100 | [diff] [blame] | 342 | [] BSCP.receive(f_BnsUdInd(tr_RIM, 0)) -> value udi { |
| 343 | if (RIM.checkstate("Connected")) { |
| 344 | RIM.send(udi.bssgp); |
| 345 | } |
| 346 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 347 | |
| 348 | /* Route based on PTP BVCI in payload/IE of signaling PDU */ |
| 349 | [] BSCP.receive(f_BnsUdInd(?, 0)) -> value udi { |
| 350 | var template (omit) BssgpBvci ptp_bvci := f_BSSGP_BVCI_get(udi.bssgp); |
| 351 | if (istemplatekind(ptp_bvci, "omit")) { |
| 352 | log("Rx on SIG BVCI without PTP BVCI: broadcasting"); |
| 353 | for (var integer i := 0; i < lengthof(BvcTable); i := i+1) { |
| 354 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 355 | BVC.send(udi) to BvcTable[i].comp_ref; |
| 356 | } |
| 357 | } |
| 358 | } else { |
| 359 | bvc_comp_ref := f_comp_for_bvci(valueof(ptp_bvci)); |
| 360 | if (isbound(bvc_comp_ref) and bvc_comp_ref != null) { |
| 361 | /* dispatch to BVC component */ |
| 362 | BVC.send(udi) to bvc_comp_ref; |
| 363 | } else { |
| 364 | 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] | 365 | 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] | 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /* Handle PS-PAGING on SIGN BVCI with no conditional BVCI IE */ |
| 371 | [] BSCP.receive(f_BnsUdInd(PDU_BSSGP:{pDU_BSSGP_PAGING_PS:=?}, 0)) -> value udi { |
| 372 | /* FIXME: use LA, RA or BSS Area to dispatch instead of broadcast */ |
| 373 | for (var integer i := 0; i < lengthof(BvcTable); i := i+1) { |
| 374 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 375 | BVC.send(udi) to BvcTable[i].comp_ref; |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | /* Handle CS-PAGING on SIGN BVCI with no conditional BVCI IE */ |
| 380 | [] BSCP.receive(f_BnsUdInd(PDU_BSSGP:{pDU_BSSGP_PAGING_CS:=?}, 0)) -> value udi { |
| 381 | /* FIXME: use LA, RA or BSS Area to dispatch instead of broadcast */ |
| 382 | for (var integer i := 0; i < lengthof(BvcTable); i := i+1) { |
| 383 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 384 | BVC.send(udi) to BvcTable[i].comp_ref; |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | /* per-BVC component sends us something; forward to NS without any validation */ |
| 390 | [] BVC.receive(NsUnitdataRequest:?) -> value udr { |
| 391 | /* patch in the NSEI, as the per-BVC components have no idea about it */ |
| 392 | udr.nsei := g_cfg.nsei; |
| 393 | BSCP.send(udr); |
| 394 | } |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 395 | |
Harald Welte | 27a70cc | 2020-12-09 11:57:41 +0100 | [diff] [blame] | 396 | [] GLOBAL.receive(tr_GLOBAL_SIG) -> value bssgp { |
Harald Welte | 57de220 | 2020-11-24 18:15:02 +0100 | [diff] [blame] | 397 | BSCP.send(f_BnsUdReq(bssgp, 0, 0)); |
| 398 | } |
Harald Welte | 0083ea6 | 2020-12-02 21:30:44 +0100 | [diff] [blame] | 399 | |
| 400 | [] RIM.receive(tr_RIM) -> value bssgp { |
| 401 | BSCP.send(f_BnsUdReq(bssgp, 0, 0)); |
| 402 | } |
| 403 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | /* We are in BVC_S_WAIT_NS_ALIVE_UNBLOCKED (only happens in BSS role) */ |
| 407 | altstep as_sig_wait_ns_alive_unblocked() runs on BSSGP_CT { |
| 408 | var NsStatusIndication nsi; |
Harald Welte | dc0a090 | 2020-11-10 21:03:29 +0100 | [diff] [blame] | 409 | [] 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] | 410 | /* if we just became NS-unblocked, send a BCC-RESET */ |
| 411 | if (g_cfg.sgsn_role == false) { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 412 | 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] | 413 | g_T2.start; |
| 414 | /* The BVC_RESET_ACK is handled in the as_sig_allstate() below */ |
| 415 | } |
| 416 | /* Idea: We could send BVC-UNBLOCK here like some SGSN do */ |
| 417 | } |
| 418 | |
| 419 | } |
| 420 | |
Harald Welte | e588792 | 2020-11-27 19:04:46 +0100 | [diff] [blame] | 421 | /* handling of events irrespective of BVC state (before state-specific handling) */ |
| 422 | altstep as_sig_allstate_pre() runs on BSSGP_CT { |
| 423 | var NsUnitdataIndication udi; |
| 424 | |
| 425 | /* Respond to RESET for signalling BVCI 0 */ |
| 426 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, omit), 0)) -> value udi { |
| 427 | log("Rx BVC-RESET for Signaling BVCI=0"); |
| 428 | if (MGMT.checkstate("Connected")) { |
| 429 | MGMT.send(BssgpResetIndication:{0}); |
| 430 | } |
| 431 | BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0)); |
| 432 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 433 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 434 | BVC.send(BssgpResetIndication:{0}) to BvcTable[i].comp_ref; |
| 435 | } |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | /* any BLOCK or UNBLOCK for the SIGNALING BVCI are illegal */ |
| 440 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK(0, ?), 0)) -> value udi { |
| 441 | setverdict(fail, "Rx BVC-BLOCK illegal for BVCI=0: ", udi); |
| 442 | } |
| 443 | [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK(0), 0)) -> value udi { |
| 444 | setverdict(fail, "Rx BVC-UNBLOCK illegal for BVCI=0: ", udi); |
| 445 | } |
| 446 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK_ACK(0), 0)) -> value udi { |
| 447 | setverdict(fail, "Rx BVC-BLOCK-ACK illegal for BVCI=0: ", udi); |
| 448 | } |
| 449 | [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK_ACK(0), 0)) -> value udi { |
| 450 | setverdict(fail, "Rx BVC-UNBLOCK-ACK illegal for BVCI=0: ", udi); |
| 451 | } |
| 452 | |
| 453 | /* BVC-RESET-ACK for BVCI=0 while T2 is running: Answer to a BVC-RESET we sent earlier */ |
| 454 | [g_T2.running] BSCP.receive(f_BnsUdInd(tr_BVC_RESET_ACK(0, omit), 0)) -> value udi { |
| 455 | log("BVCI(0) Rx BVC-RESET-ACK"); |
| 456 | g_T2.stop; |
| 457 | f_sign_change_state(BVC_S_UNBLOCKED); |
| 458 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 459 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 460 | BVC.send(BssgpResetIndication:{0}) to BvcTable[i].comp_ref; |
| 461 | } |
| 462 | } |
| 463 | } |
| 464 | [] g_T2.timeout { |
| 465 | setverdict(fail, "Timeout waiting for BVC-RESET-ACK on BVCI=0"); |
| 466 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(udi.bvci, BSSGP_CAUSE_BVCI_UNKNOWN, udi.bssgp), 0, 0)); |
| 467 | g_T2.start; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | /* handling of events irrespective of BVC state (after state-specific handling) */ |
| 472 | altstep as_sig_allstate_post() runs on BSSGP_CT { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 473 | var BSSGP_Client_CT vc_conn; |
| 474 | var NsUnitdataIndication udi; |
| 475 | var NsStatusIndication nsi; |
| 476 | var ASP_Event evt; |
| 477 | var BSSGP_BVC_CT bvc_comp_ref; |
| 478 | var BssgpBvci bvci; |
Harald Welte | e588792 | 2020-11-27 19:04:46 +0100 | [diff] [blame] | 479 | var BssgpResetRequest brr; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 480 | |
| 481 | /* Respond to RESET for signalling BVCI 0 */ |
| 482 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, 0, omit), 0)) -> value udi { |
| 483 | log("Rx BVC-RESET for Signaling BVCI=0"); |
Harald Welte | bdf96d8 | 2020-11-27 18:58:46 +0100 | [diff] [blame] | 484 | if (MGMT.checkstate("Connected")) { |
| 485 | MGMT.send(BssgpResetIndication:{0}); |
| 486 | } |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 487 | BSCP.send(f_BnsUdReq(ts_BVC_RESET_ACK(0, omit), 0, 0)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 488 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 489 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 490 | BVC.send(BssgpResetIndication:{0}) to BvcTable[i].comp_ref; |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | /* any BLOCK or UNBLOCK for the SIGNALING BVCI are illegal */ |
| 496 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK(0, ?), 0)) -> value udi { |
| 497 | setverdict(fail, "Rx BVC-BLOCK illegal for BVCI=0: ", udi); |
| 498 | } |
| 499 | [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK(0), 0)) -> value udi { |
| 500 | setverdict(fail, "Rx BVC-UNBLOCK illegal for BVCI=0: ", udi); |
| 501 | } |
| 502 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK_ACK(0), 0)) -> value udi { |
| 503 | setverdict(fail, "Rx BVC-BLOCK-ACK illegal for BVCI=0: ", udi); |
| 504 | } |
| 505 | [] BSCP.receive(f_BnsUdInd(t_BVC_UNBLOCK_ACK(0), 0)) -> value udi { |
| 506 | setverdict(fail, "Rx BVC-UNBLOCK-ACK illegal for BVCI=0: ", udi); |
| 507 | } |
| 508 | |
| 509 | /* Respond to BLOCK for wrong BVCI */ |
| 510 | [] BSCP.receive(f_BnsUdInd(t_BVC_BLOCK(?, ?), 0)) -> value udi { |
| 511 | setverdict(fail, "Rx BVC-BLOCK for unknown BVCI"); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 512 | 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] | 513 | } |
| 514 | |
| 515 | /* Respond to RESET with wrong BVCI */ |
| 516 | [] BSCP.receive(f_BnsUdInd(tr_BVC_RESET(?, ?, ?), 0)) -> value udi { |
| 517 | var BssgpBvci ptp_bvci := oct2int(udi.bssgp.pDU_BSSGP_BVC_RESET.bVCI.unstructured_value); |
| 518 | setverdict(fail, "Rx BVC-RESET for unknown BVCI ", ptp_bvci); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 519 | 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] | 520 | } |
| 521 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 522 | /* Forwarding of ASP_Event to per-BVC components */ |
| 523 | [] BSCP.receive(ASP_Event:?) -> value evt { |
| 524 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 525 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 526 | BVC.send(evt) to BvcTable[i].comp_ref; |
| 527 | } |
| 528 | } |
| 529 | } |
| 530 | /* 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] | 531 | [] BSCP.receive(tr_NsStsInd(g_cfg.nsei)) -> value nsi { } |
Harald Welte | 445fc61 | 2020-11-10 19:15:30 +0100 | [diff] [blame] | 532 | /* 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] | 533 | [] BSCP.receive(tr_NsStsInd(?)) -> value nsi { |
Harald Welte | 445fc61 | 2020-11-10 19:15:30 +0100 | [diff] [blame] | 534 | setverdict(fail, "Rx NsStatusInd for wrong NSEI ", nsi); |
| 535 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 536 | |
| 537 | /* Procedure port request to resolve the per-BVC component for a given ptp BVCI */ |
| 538 | [] PROC.getcall(BSSGP_get_bvci_ct:{?}) -> param(bvci) sender vc_conn { |
| 539 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 540 | if (BvcTable[i].bvci == bvci) { |
| 541 | PROC.reply(BSSGP_get_bvci_ct:{bvci} value BvcTable[i].comp_ref) to vc_conn; |
| 542 | return; |
| 543 | } |
| 544 | } |
| 545 | } |
Harald Welte | e588792 | 2020-11-27 19:04:46 +0100 | [diff] [blame] | 546 | |
| 547 | /* default case of handling unknown PDUs */ |
| 548 | [] BSCP.receive(f_BnsUdInd(?, ?)) -> value udi { |
| 549 | setverdict(fail, "Rx Unexpected BSSGP PDU ", udi.bssgp," in state ", g_sign_bvc_state); |
| 550 | BSCP.send(f_BnsUdReq(ts_BSSGP_STATUS(0, BSSGP_CAUSE_PDU_NOT_COMPATIBLE_WITH_PROTOCOL_STATE, udi.bssgp), 0, 0)); |
| 551 | } |
| 552 | |
| 553 | [] MGMT.receive(BssgpResetRequest:?) -> value brr { |
| 554 | BSCP.send(f_BnsUdReq(ts_BVC_RESET(brr.cause, 0, omit), 0, 0)); |
| 555 | g_T2.start; |
| 556 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | /* send the highest decoded layer of the message through given port */ |
| 560 | private function f_send_bssgp_dec(BssgpDecoded dec, BSSGP_Client_CT vc_conn, BSSGP_SP_PT pt) { |
| 561 | #ifdef BSSGP_EM_L3 |
| 562 | if (ispresent(dec.l3_mt)) { |
| 563 | pt.send(dec.l3_mt) to vc_conn; |
| 564 | } else if (ispresent(dec.l3_mo)) { |
| 565 | pt.send(dec.l3_mo) to vc_conn; |
| 566 | } else |
| 567 | #endif |
| 568 | if (ispresent(dec.sndcp)) { |
| 569 | pt.send(dec.sndcp) to vc_conn; |
| 570 | } else if (ispresent(dec.llc)) { |
| 571 | pt.send(dec.llc) to vc_conn; |
| 572 | } else { |
| 573 | pt.send(dec.bssgp) to vc_conn; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | |
| 578 | function f_llc_get_n_u_tx(inout LLC_Entity llc) return uint9_t { |
| 579 | var uint9_t ret := llc.n_u_tx_next; |
| 580 | llc.n_u_tx_next := llc.n_u_tx_next + 1; |
| 581 | return ret; |
| 582 | } |
| 583 | |
| 584 | #ifdef BSSGP_EM_L3 |
| 585 | function f_llc_sapi_by_l3_mo(PDU_L3_MS_SGSN l3_mo) return BIT4 { |
| 586 | if (ischosen(l3_mo.msgs.gprs_mm)) { |
| 587 | return c_LLC_SAPI_LLGMM; |
| 588 | } else if (ischosen(l3_mo.msgs.gprs_sm)) { |
| 589 | return c_LLC_SAPI_LLGMM; |
| 590 | } else if (ischosen(l3_mo.msgs.sms)) { |
| 591 | return c_LLC_SAPI_LLSMS; |
| 592 | } |
| 593 | setverdict(fail, "No LLC SAPI for ", l3_mo); |
| 594 | mtc.stop; |
| 595 | } |
| 596 | |
| 597 | private function f_llc_sapi_by_l3_mt(PDU_L3_SGSN_MS l3_mt) return BIT4 { |
| 598 | if (ischosen(l3_mt.msgs.gprs_mm)) { |
| 599 | return c_LLC_SAPI_LLGMM; |
| 600 | } else if (ischosen(l3_mt.msgs.gprs_sm)) { |
| 601 | return c_LLC_SAPI_LLGMM; |
| 602 | } else if (ischosen(l3_mt.msgs.sms)) { |
| 603 | return c_LLC_SAPI_LLSMS; |
| 604 | } |
| 605 | setverdict(fail, "No LLC SAPI for ", l3_mt); |
| 606 | mtc.stop; |
| 607 | } |
| 608 | #endif |
| 609 | |
| 610 | /* main loop of BSSGP_CT */ |
| 611 | private function f_bssgp_ScanEvents() runs on BSSGP_CT { |
| 612 | while (true) { |
| 613 | alt { |
| 614 | [g_sign_bvc_state == BVC_S_WAIT_RESET] as_sig_wait_reset(); |
Harald Welte | e588792 | 2020-11-27 19:04:46 +0100 | [diff] [blame] | 615 | [] as_sig_allstate_pre(); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 616 | [g_sign_bvc_state == BVC_S_WAIT_NS_ALIVE_UNBLOCKED] as_sig_wait_ns_alive_unblocked(); |
| 617 | [g_sign_bvc_state == BVC_S_UNBLOCKED] as_sig_unblocked(); |
Harald Welte | e588792 | 2020-11-27 19:04:46 +0100 | [diff] [blame] | 618 | [g_sign_bvc_state == BVC_S_WAIT_RESET] as_sig_wait_reset(); |
| 619 | [] as_sig_allstate_post(); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 620 | } |
| 621 | } /* while */ |
| 622 | } |
| 623 | |
| 624 | /* 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] | 625 | private function f_BnsUdReq(template PDU_BSSGP pdu, BssgpBvci bvci, integer lsp) |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 626 | runs on BSSGP_CT return NsUnitdataRequest { |
| 627 | var NsUnitdataRequest udr := { |
| 628 | bvci := bvci, |
| 629 | nsei := g_cfg.nsei, |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 630 | lsp := lsp, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 631 | /* for some weird reason we get "Dynamic test case error: Text encoder: Encoding an |
| 632 | * unbound integer value." when trying to send the reocrd rather than the octetstring */ |
| 633 | //sdu := omit, |
| 634 | //bssgp := valueof(pdu) |
| 635 | sdu := enc_PDU_BSSGP(valueof(pdu)), |
| 636 | bssgp := omit |
| 637 | } |
| 638 | return udr; |
| 639 | } |
| 640 | |
| 641 | /* generate a receive template. Cannot be a real template as we want to use g_cfg.nsei */ |
| 642 | private function f_BnsUdInd(template PDU_BSSGP pdu, template BssgpBvci bvci) |
| 643 | runs on BSSGP_CT return template (present) NsUnitdataIndication { |
| 644 | var template (present) NsUnitdataIndication udi := { |
| 645 | bvci := bvci, |
| 646 | nsei := g_cfg.nsei, |
Harald Welte | 80a249a | 2020-11-17 19:57:40 +0100 | [diff] [blame] | 647 | nsvci := ?, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 648 | sdu := *, |
| 649 | bssgp := pdu |
| 650 | } |
| 651 | return udi; |
| 652 | } |
| 653 | |
| 654 | /* change state of signaling BVCI; notify per-BVC components */ |
| 655 | private function f_sign_change_state(BvcState new_state) runs on BSSGP_CT { |
| 656 | if (new_state == g_sign_bvc_state) { |
| 657 | return; |
| 658 | } |
| 659 | log("BVCI(0) State Transition: ", g_sign_bvc_state, " -> ", new_state); |
| 660 | g_sign_bvc_state := new_state; |
| 661 | for (var integer i := 0; i < sizeof(BvcTable); i := i+1) { |
| 662 | if (isbound(BvcTable[i].comp_ref) and BvcTable[i].comp_ref != null) { |
| 663 | BVC.send(ts_BssgpStsInd(g_cfg.nsei, 0, g_sign_bvc_state)) to BvcTable[i].comp_ref; |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | /* User wants to get per-BVC component reference from BSSGP_CT */ |
| 669 | signature BSSGP_get_bvci_ct(BssgpBvci bvci) return BSSGP_BVC_CT; |
| 670 | |
| 671 | type port BSSGP_CT_PROC_PT procedure { |
| 672 | inout BSSGP_get_bvci_ct |
| 673 | } with { extension "internal" }; |
| 674 | |
| 675 | /* convenience wrapper function for user */ |
| 676 | function f_bssgp_get_bvci_ct(BssgpBvci bvci, BSSGP_CT_PROC_PT PT) return BSSGP_BVC_CT { |
| 677 | var BSSGP_BVC_CT res; |
| 678 | PT.call(BSSGP_get_bvci_ct:{bvci}) { |
| 679 | [] PT.getreply(BSSGP_get_bvci_ct:{bvci})-> value res { |
| 680 | return res; |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | /*********************************************************************** |
| 686 | * per-BVC (Cell) Component |
| 687 | *********************************************************************** |
| 688 | * Any number of these components runs on top of the BSSGP_CT, each |
| 689 | * representing one PTP BVC within this NSE. Users (test cases) can |
| 690 | * register with TLLI and/or IMSI via the procedure port. |
| 691 | ***********************************************************************/ |
| 692 | |
| 693 | /* per-BVC component. Exists once per cell within a BSSGP_CT */ |
| 694 | type component BSSGP_BVC_CT { |
| 695 | /* port towards the underlying BSSGP_CT */ |
| 696 | port BSSGP_BVC_PT BVC; |
| 697 | |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 698 | /* port to a management instance */ |
| 699 | port BSSGP_BVC_MGMT_SP_PT MGMT; |
| 700 | |
Harald Welte | 71449b0 | 2020-12-09 11:58:23 +0100 | [diff] [blame] | 701 | /* per-BVC global port for e.g. BVC Flow Control */ |
| 702 | port BSSGP_SP_PT GLOBAL; |
| 703 | |
| 704 | /* BSSGP-User SAP towards the user (per-TLLI, Client) */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 705 | port BSSGP_SP_PT BSSGP_SP; |
Stefan Sperling | f82bbb6 | 2018-05-03 19:14:28 +0200 | [diff] [blame] | 706 | port BSSGP_SP_PT BSSGP_SP_SIG; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 707 | port BSSGP_PROC_PT BSSGP_PROC; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 708 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 709 | var BssgpBvcConfig g_cfg; |
| 710 | var boolean g_sgsn_role; |
Harald Welte | fba7afd | 2020-11-24 23:12:31 +0100 | [diff] [blame] | 711 | var Nsei g_nsei; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 712 | |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 713 | /* default Link Selector Parameter for this BVC (for traffic unrelated to a TLLI) */ |
| 714 | var integer g_bvc_lsp; |
| 715 | |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 716 | var BvcState g_ptp_bvc_state := BVC_S_BLOCKED; |
| 717 | timer g_T1 := 15.0; |
| 718 | timer g_T2 := 60.0; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 719 | var boolean g_t1_waits_for_block_ack := false; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 720 | /* for re-transmissions */ |
| 721 | var BssgpCause g_last_block_cause; |
| 722 | var BssgpCause g_last_reset_cause; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 723 | |
| 724 | var ClientEntity ClientTable[16]; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 725 | }; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 726 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 727 | /* port between global BSSGP_CT and per-BVC BSSGP_BVC_CT */ |
| 728 | type port BSSGP_BVC_SP_PT message { |
| 729 | in NsUnitdataRequest; |
| 730 | out ASP_Event, |
| 731 | BssgpStatusIndication, |
| 732 | BssgpResetIndication, |
| 733 | NsUnitdataIndication; |
| 734 | } with { extension "internal" }; |
| 735 | type port BSSGP_BVC_PT message { |
| 736 | in ASP_Event, |
| 737 | BssgpStatusIndication, |
| 738 | BssgpResetIndication, |
| 739 | NsUnitdataIndication; |
| 740 | out NsUnitdataRequest; |
| 741 | } with { extension "internal" }; |
Alexander Couzens | 6b449fb | 2018-07-31 14:19:36 +0200 | [diff] [blame] | 742 | |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 743 | /* port between BSSGP_BVC_CT and a management instance */ |
| 744 | type port BSSGP_BVC_MGMT_SP_PT message { |
| 745 | in BssgpResetRequest, |
| 746 | BssgpBlockRequest, |
| 747 | BssgpUnblockRequest; |
| 748 | out BssgpStatusIndication, |
| 749 | BssgpResetIndication; |
| 750 | } with { extension "internal" }; |
| 751 | type port BSSGP_BVC_MGMT_PT message { |
| 752 | in BssgpStatusIndication, |
| 753 | BssgpResetIndication; |
| 754 | out BssgpResetRequest, |
| 755 | BssgpBlockRequest, |
| 756 | BssgpUnblockRequest; |
| 757 | } with { extension "internal" }; |
| 758 | |
| 759 | type record BssgpResetRequest { |
| 760 | BssgpCause cause |
| 761 | }; |
| 762 | type record BssgpBlockRequest { |
| 763 | BssgpCause cause |
| 764 | }; |
| 765 | type record BssgpUnblockRequest { |
| 766 | }; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 767 | |
| 768 | /* one element in the per-TLLI state table */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 769 | type record ClientEntity { |
| 770 | OCT4 tlli, |
| 771 | OCT4 tlli_old optional, |
| 772 | hexstring imsi, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 773 | BSSGP_Client_CT comp_ref, |
| 774 | /* LLC entities, one for each SAPI */ |
| 775 | LLC_Entity llc[16] |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 776 | }; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 777 | type record LLC_Entity { |
| 778 | boolean sgsn_role, |
| 779 | /* N(U) on transmit side for next PDU */ |
| 780 | uint9_t n_u_tx_next, |
| 781 | /* N(U) on receive side, last PDU */ |
| 782 | uint9_t n_u_rx_last optional |
| 783 | }; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 784 | type record length(16) of LLC_Entity LLC_Entities; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 785 | |
Alexander Couzens | cdfb751 | 2018-07-31 15:37:14 +0200 | [diff] [blame] | 786 | function f_llc_create(boolean sgsn_role := false) return LLC_Entities { |
| 787 | var LLC_Entities llc; |
| 788 | for (var integer i := 0; i < 16; i := i+1) { |
| 789 | llc[i] := valueof(t_LLC_init(sgsn_role)); |
| 790 | } |
| 791 | return llc; |
| 792 | } |
| 793 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 794 | private template LLC_Entity t_LLC_init(boolean sgsn_role := false) := { |
| 795 | sgsn_role := sgsn_role, |
| 796 | n_u_tx_next := 0, |
| 797 | n_u_rx_last := - |
| 798 | } |
| 799 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 800 | /* configuration of BSSGP_CT */ |
| 801 | type record BssgpConfig { |
| 802 | Nsvci nsei, |
| 803 | boolean sgsn_role, |
| 804 | BssgpBvcConfigs bvc |
| 805 | }; |
| 806 | /* Configuration of one BVC (Cell) BSSGP_BVC_CT */ |
| 807 | type record BssgpBvcConfig { |
| 808 | BssgpBvci bvci, |
| 809 | BssgpCellId cell_id, |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 810 | BssgpDecodeDepth depth, |
| 811 | BssgpCreateCallback create_cb |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 812 | }; |
| 813 | type record of BssgpBvcConfig BssgpBvcConfigs; |
Oliver Smith | aac9b9c | 2019-09-02 08:36:36 +0200 | [diff] [blame] | 814 | type enumerated BssgpDecodeDepth { |
| 815 | BSSGP_DECODE_DEPTH_BSSGP, |
| 816 | BSSGP_DECODE_DEPTH_LLC, |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 817 | BSSGP_DECODE_DEPTH_SNDCP |
| 818 | #ifdef BSSGP_EM_L3 |
| 819 | , |
Oliver Smith | aac9b9c | 2019-09-02 08:36:36 +0200 | [diff] [blame] | 820 | BSSGP_DECODE_DEPTH_L3 |
Harald Welte | 93331e7 | 2020-09-12 20:51:05 +0200 | [diff] [blame] | 821 | #endif |
Oliver Smith | aac9b9c | 2019-09-02 08:36:36 +0200 | [diff] [blame] | 822 | }; |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 823 | /* call-back function type: Called for inbound BSSGP for unknown TLLIs; could create BSSGP_ClienT_CT */ |
| 824 | type function BssgpCreateCallback(BssgpBvci bvci, BssgpCellId cell_id, OCT4 tlli, BssgpDecoded dec) runs on BSSGP_BVC_CT; |
| 825 | |
| 826 | /* Default Create Callback function: Fail and terminate */ |
| 827 | function DefaultCreateCallback(BssgpBvci bvci, BssgpCellId cell_id, OCT4 tlli, BssgpDecoded dec) runs on BSSGP_BVC_CT { |
| 828 | setverdict(fail, "Couldn't find Component for TLLI ", tlli); |
| 829 | mtc.stop; |
| 830 | } |
Oliver Smith | aac9b9c | 2019-09-02 08:36:36 +0200 | [diff] [blame] | 831 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 832 | /* |
| 833 | private function f_tbl_init() runs on BSSGP_BVC_CT { |
| 834 | var integer i; |
| 835 | for (i := 0; i < sizeof(ImsiTable); i := i+1) { |
| 836 | ImsiTable[i] := -; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 837 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 838 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 839 | for (i := 0; i < sizeof(TlliTable); i := i+1) { |
| 840 | TlliTable[i] := -; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 841 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 842 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 843 | */ |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 844 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 845 | private function f_tbl_client_add(hexstring imsi, OCT4 tlli, BSSGP_Client_CT vc_conn) |
| 846 | runs on BSSGP_BVC_CT { |
| 847 | var integer i; |
| 848 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 849 | if (not isvalue(ClientTable[i].comp_ref)) { |
| 850 | log("Adding Client=", vc_conn, ", IMSI=", imsi, ", TLLI=", tlli, ", index=", i); |
| 851 | ClientTable[i] := { |
| 852 | tlli := tlli, |
| 853 | tlli_old := omit, |
| 854 | imsi := imsi, |
| 855 | comp_ref := vc_conn, |
| 856 | llc := - |
| 857 | }; |
| 858 | for (var integer j := 0; j < sizeof(ClientTable[i].llc); j := j+1) { |
| 859 | ClientTable[i].llc[j] := valueof(t_LLC_init(g_sgsn_role)); |
| 860 | } |
| 861 | return; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 862 | } |
| 863 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 864 | testcase.stop("Client Table full"); |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 865 | } |
| 866 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 867 | private function f_tbl_client_del(hexstring imsi, BSSGP_Client_CT vc_conn) runs on BSSGP_BVC_CT { |
| 868 | var integer i; |
| 869 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 870 | if (isvalue(ClientTable[i].imsi) and ClientTable[i].imsi == imsi) { |
| 871 | if (ClientTable[i].comp_ref != vc_conn) { |
| 872 | setverdict(fail, "Cannot unregister index=", i, " IMSI ", imsi, " registred to ", |
| 873 | ClientTable[i].comp_ref, " from ", vc_conn); |
| 874 | mtc.stop; |
| 875 | } |
| 876 | log("Removing Client IMSI=", imsi, ", index=", i); |
| 877 | ClientTable[i] := { |
| 878 | tlli := -, |
| 879 | tlli_old := omit, |
| 880 | imsi := ''H, |
| 881 | comp_ref := null, |
| 882 | llc := - }; |
| 883 | return; |
| 884 | } |
| 885 | } |
| 886 | log("Warning: Could not find client for IMSI ", imsi); |
| 887 | return; |
| 888 | } |
| 889 | |
| 890 | /* TS 44.064 7.2.1.1 LLGMM-ASSIGN */ |
| 891 | private function f_tbl_client_llgmm_assign(OCT4 tlli_old, OCT4 tlli_new, BSSGP_Client_CT vc_conn) |
| 892 | runs on BSSGP_BVC_CT { |
| 893 | var integer i := f_tbl_idx_by_comp(vc_conn); |
| 894 | |
| 895 | if (tlli_old == 'FFFFFFFF'O and tlli_new != 'FFFFFFFF'O) { |
| 896 | /* TLLI assignment */ |
| 897 | ClientTable[i].tlli := tlli_new; |
| 898 | ClientTable[i].tlli_old := omit; |
| 899 | } else if (tlli_old != 'FFFFFFFF'O and tlli_new != 'FFFFFFFF'O) { |
| 900 | /* TLLI change: both active */ |
| 901 | ClientTable[i].tlli := tlli_new; |
| 902 | ClientTable[i].tlli_old := tlli_old; |
| 903 | } else if (tlli_old != 'FFFFFFFF'O and tlli_new == 'FFFFFFFF'O) { |
| 904 | /* TLLI unassignment: old shall be unassigned; new stays */ |
| 905 | ClientTable[i].tlli_old := omit; |
| 906 | } |
| 907 | } |
| 908 | |
| 909 | private function f_tbl_comp_by_imsi(hexstring imsi) runs on BSSGP_BVC_CT return BSSGP_Client_CT { |
| 910 | var integer i; |
| 911 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 912 | if (isvalue(ClientTable[i].imsi) and isvalue(ClientTable[i].comp_ref) |
| 913 | and ClientTable[i].imsi == imsi) { |
| 914 | return ClientTable[i].comp_ref; |
| 915 | } |
| 916 | } |
| 917 | setverdict(fail, "Couldn't find Component for IMSI ", imsi); |
| 918 | mtc.stop; |
| 919 | } |
| 920 | |
| 921 | private function f_tbl_comp_by_tlli(OCT4 tlli) runs on BSSGP_BVC_CT return BSSGP_Client_CT { |
| 922 | var integer i; |
| 923 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 924 | if (isvalue(ClientTable[i].comp_ref) and |
| 925 | (isvalue(ClientTable[i].tlli) and (ClientTable[i].tlli == tlli or |
| 926 | isvalue(ClientTable[i].tlli_old) and ClientTable[i].tlli_old == tlli) )) { |
| 927 | return ClientTable[i].comp_ref; |
| 928 | } |
| 929 | } |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 930 | return null; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | private function f_tbl_idx_by_comp(BSSGP_Client_CT comp_ref) runs on BSSGP_BVC_CT return integer { |
| 934 | var integer i; |
| 935 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 936 | if (isvalue(ClientTable[i].comp_ref) and ClientTable[i].comp_ref == comp_ref) { |
| 937 | return i; |
| 938 | } |
| 939 | } |
| 940 | setverdict(fail, "Couldn't find Client for Component ", comp_ref); |
| 941 | mtc.stop; |
| 942 | } |
| 943 | |
| 944 | private function f_tbl_tlli_by_comp(BSSGP_Client_CT comp_ref) runs on BSSGP_BVC_CT return OCT4 { |
| 945 | var integer i; |
| 946 | for (i := 0; i < sizeof(ClientTable); i := i+1) { |
| 947 | if (isvalue(ClientTable[i].tlli) and isvalue(ClientTable[i].comp_ref) |
| 948 | and ClientTable[i].comp_ref == comp_ref) { |
| 949 | return ClientTable[i].tlli; |
| 950 | } |
| 951 | } |
| 952 | setverdict(fail, "Couldn't find TLLI for Component ", comp_ref); |
| 953 | mtc.stop; |
| 954 | } |
| 955 | |
| 956 | /* PDU_BSSGP enhanced with LLC and possibly L3 decoded payloads */ |
| 957 | type record BssgpDecoded { |
| 958 | PDU_BSSGP bssgp, |
| 959 | PDU_LLC llc optional, |
| 960 | #ifdef BSSGP_EM_L3 |
| 961 | PDU_L3_MS_SGSN l3_mo optional, |
| 962 | PDU_L3_SGSN_MS l3_mt optional, |
| 963 | #endif |
| 964 | PDU_SN sndcp optional |
| 965 | } |
| 966 | |
| 967 | /* Decode a PDU_BSSGP into a BssgpDecoded (i.e. with LLC/L3 decoded, as applicable) */ |
| 968 | private function f_dec_bssgp(PDU_BSSGP bssgp) runs on BSSGP_BVC_CT return BssgpDecoded { |
| 969 | var BssgpDecoded dec := { |
| 970 | bssgp := bssgp, |
| 971 | llc := omit, |
| 972 | #ifdef BSSGP_EM_L3 |
| 973 | l3_mo := omit, |
| 974 | l3_mt := omit, |
| 975 | #endif |
| 976 | sndcp := omit |
| 977 | }; |
| 978 | |
| 979 | /* Decode LLC, if it is a PDU that contains LLC */ |
| 980 | if (g_cfg.depth >= BSSGP_DECODE_DEPTH_LLC) { |
| 981 | if (ischosen(bssgp.pDU_BSSGP_DL_UNITDATA)) { |
| 982 | dec.llc := dec_PDU_LLC(bssgp.pDU_BSSGP_DL_UNITDATA.lLC_PDU.lLC_PDU); |
| 983 | } else if (ischosen(bssgp.pDU_BSSGP_UL_UNITDATA)) { |
| 984 | dec.llc := dec_PDU_LLC(bssgp.pDU_BSSGP_UL_UNITDATA.lLC_PDU.lLC_PDU); |
| 985 | } |
| 986 | } |
| 987 | |
| 988 | /* Decode SNDCP, if it is a LLC PDU containing user plane data */ |
| 989 | if (g_cfg.depth >= BSSGP_DECODE_DEPTH_SNDCP) { |
| 990 | if (isvalue(dec.llc) and match(dec.llc, tr_LLC_UI_USER)) { |
| 991 | dec.sndcp := dec_PDU_SN(dec.llc.pDU_LLC_UI.information_field_UI); |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | #ifdef BSSGP_EM_L3 |
| 996 | /* Decode L3, if it is a LLC PDU containing L3 */ |
| 997 | if (g_cfg.depth >= BSSGP_DECODE_DEPTH_L3) { |
| 998 | if (isvalue(dec.llc) and match(dec.llc, tr_LLC_UI_L3)) { |
| 999 | if (g_sgsn_role) { |
| 1000 | dec.l3_mo := dec_PDU_L3_MS_SGSN(dec.llc.pDU_LLC_UI.information_field_UI); |
| 1001 | } else { |
| 1002 | dec.l3_mt := dec_PDU_L3_SGSN_MS(dec.llc.pDU_LLC_UI.information_field_UI); |
| 1003 | } |
| 1004 | } |
| 1005 | } |
| 1006 | #endif |
| 1007 | |
| 1008 | return dec; |
| 1009 | } |
| 1010 | |
| 1011 | private function f_ptp_sendUnblock() runs on BSSGP_BVC_CT { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1012 | 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] | 1013 | g_t1_waits_for_block_ack := false; |
| 1014 | g_T1.start; |
| 1015 | } |
| 1016 | |
| 1017 | private function f_ptp_sendBlock(BssgpCause cause) runs on BSSGP_BVC_CT { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1018 | 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] | 1019 | g_t1_waits_for_block_ack := true; |
| 1020 | g_T1.start; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1021 | g_last_block_cause := cause; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | private function f_ptp_sendStatus(BssgpCause cause, PDU_BSSGP pdu) runs on BSSGP_BVC_CT { |
| 1025 | /* FIXME: Make sure correct Signaling or PTP BVCI is used! */ |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1026 | 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] | 1027 | } |
| 1028 | |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1029 | 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] | 1030 | var PDU_BSSGP pdu; |
| 1031 | |
| 1032 | /* The Cell Identifier IE is mandatory in the BVC-RESET PDU sent from BSS to |
| 1033 | * SGSN in order to reset a BVC corresponding to a PTP functional entity. The |
| 1034 | * 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] | 1035 | if (g_sgsn_role) { |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1036 | pdu := valueof(ts_BVC_RESET(cause, g_cfg.bvci, omit)); |
Harald Welte | c967d0e | 2020-09-14 16:07:26 +0200 | [diff] [blame] | 1037 | } else { |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1038 | 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] | 1039 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 1040 | |
| 1041 | /* 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] | 1042 | BVC.send(ts_ptp_BnsUdReq(pdu, 0, g_bvc_lsp)); |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 1043 | g_T2.start; |
| 1044 | //f_change_state(BVC_S_WAIT_RESET); |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1045 | g_last_reset_cause := cause; |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 1046 | } |
| 1047 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1048 | /* PTP-BVC is in BVC_S_BLOCKED state */ |
| 1049 | private altstep as_ptp_blocked() runs on BSSGP_BVC_CT { |
| 1050 | var NsUnitdataIndication udi; |
| 1051 | |
| 1052 | [g_T1.running and not g_t1_waits_for_block_ack] BVC.receive(tr_ptp_BnsUdInd(t_BVC_UNBLOCK_ACK(g_cfg.bvci), 0)) { |
| 1053 | g_T1.stop; |
| 1054 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1055 | } |
| 1056 | |
Harald Welte | ddfc667 | 2020-11-24 23:13:01 +0100 | [diff] [blame] | 1057 | /* Inbound BVC-UNBLOCK from peer */ |
| 1058 | [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(t_BVC_UNBLOCK(g_cfg.bvci), 0)) { |
| 1059 | BVC.send(ts_ptp_BnsUdReq(t_BVC_UNBLOCK_ACK(g_cfg.bvci), 0, g_bvc_lsp)); |
| 1060 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1061 | } |
| 1062 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1063 | /* RESET-ACK before T2 timeout: reset successful. In SGSN role, CellID must be present */ |
| 1064 | [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 { |
| 1065 | g_T2.stop; |
| 1066 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1067 | } |
| 1068 | /* RESET-ACK before T2 timeout: reset successful. In BSS role, CellID must be absent */ |
| 1069 | [g_T2.running and not g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET_ACK(g_cfg.bvci, omit), 0)) -> value udi { |
| 1070 | g_T2.stop; |
| 1071 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1072 | } |
| 1073 | |
Harald Welte | ab50cc2 | 2020-11-25 17:11:08 +0100 | [diff] [blame] | 1074 | [] as_ptp_handle_inbound_reset(); |
| 1075 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1076 | [] g_T2.timeout { |
| 1077 | /* BVC-RESET-ACK PDU was not received within T2: retransmit */ |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1078 | f_ptp_sendReset(g_last_reset_cause); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1079 | } |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1080 | |
| 1081 | [] MGMT.receive(BssgpUnblockRequest:?) { |
| 1082 | f_ptp_sendUnblock(); |
| 1083 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 1084 | } |
| 1085 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1086 | /* PTP-BVC is in UNBLOCKED state */ |
| 1087 | private altstep as_ptp_unblocked() runs on BSSGP_BVC_CT { |
| 1088 | var NsUnitdataIndication udi; |
| 1089 | var NsStatusIndication nsi; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1090 | var BssgpBlockRequest bbr; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1091 | var BSSGP_Client_CT vc_conn; |
| 1092 | var ASP_Event evt; |
| 1093 | var PDU_BSSGP bs_pdu; |
| 1094 | var PDU_LLC llc; |
| 1095 | #ifdef BSSGP_EM_L3 |
| 1096 | var PDU_L3_MS_SGSN l3_mo; |
| 1097 | var PDU_L3_SGSN_MS l3_mt; |
| 1098 | #endif |
| 1099 | |
| 1100 | /* bogus unblock, just respond with ACK */ |
| 1101 | [] 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] | 1102 | 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] | 1103 | } |
| 1104 | /* Respond to BLOCK with BLOCK-ACK + change state */ |
| 1105 | [] 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] | 1106 | 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] | 1107 | g_T1.stop; |
| 1108 | f_ptp_change_state(BVC_S_BLOCKED); |
| 1109 | } |
| 1110 | /* BLOCK-ACK before T1 timeout: mark as blocked */ |
| 1111 | [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 { |
| 1112 | g_T1.stop; |
| 1113 | f_ptp_change_state(BVC_S_BLOCKED); |
| 1114 | } |
| 1115 | /* Re-transmit BLOCK / UNBLOCK on T1 timeout */ |
| 1116 | [not g_t1_waits_for_block_ack] g_T1.timeout { |
| 1117 | f_ptp_sendUnblock(); |
| 1118 | } |
| 1119 | [g_t1_waits_for_block_ack] g_T1.timeout { |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1120 | f_ptp_sendBlock(g_last_block_cause); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1121 | } |
| 1122 | |
Harald Welte | ab50cc2 | 2020-11-25 17:11:08 +0100 | [diff] [blame] | 1123 | [] as_ptp_handle_inbound_reset(); |
| 1124 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1125 | [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_FC_BVC, g_cfg.bvci)) -> value udi { |
Harald Welte | 71449b0 | 2020-12-09 11:58:23 +0100 | [diff] [blame] | 1126 | if (GLOBAL.checkstate("Connected")) { |
| 1127 | GLOBAL.send(udi.bssgp); |
| 1128 | } else { |
| 1129 | /* simply acknowledge all per-BVC Flow Control Messages */ |
| 1130 | var OCT1 tag := udi.bssgp.pDU_BSSGP_FLOW_CONTROL_BVC.tag.unstructured_Value; |
| 1131 | BVC.send(ts_ptp_BnsUdReq(t_BVC_FC_BVC_ACK(tag), g_cfg.bvci, g_bvc_lsp)); |
| 1132 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1133 | } |
Harald Welte | 71449b0 | 2020-12-09 11:58:23 +0100 | [diff] [blame] | 1134 | |
| 1135 | [not g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(t_BVC_FC_BVC_ACK(?), g_cfg.bvci)) -> value udi { |
| 1136 | if (GLOBAL.checkstate("Connected")) { |
| 1137 | GLOBAL.send(udi.bssgp); |
| 1138 | } else { |
| 1139 | /* ignore any incoming flow control ACK */ |
| 1140 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1141 | } |
Harald Welte | 71449b0 | 2020-12-09 11:58:23 +0100 | [diff] [blame] | 1142 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1143 | /* Any other PTP BSSGP message: If it has TLLI, route to component; otherwise broadcast */ |
| 1144 | [] BVC.receive(tr_ptp_BnsUdInd(?, g_cfg.bvci)) -> value udi { |
| 1145 | var BssgpDecoded dec := f_dec_bssgp(udi.bssgp); |
| 1146 | var template OCT4 tlli := f_bssgp_get_tlli(udi.bssgp); |
| 1147 | if (isvalue(tlli)) { |
| 1148 | vc_conn := f_tbl_comp_by_tlli(valueof(tlli)); |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 1149 | if (vc_conn == null) { |
| 1150 | g_cfg.create_cb.apply(g_cfg.bvci, g_cfg.cell_id, valueof(tlli), dec); |
| 1151 | } else { |
| 1152 | f_send_bssgp_dec(dec, vc_conn, BSSGP_SP); |
| 1153 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1154 | } else { |
| 1155 | log("No TLLI: Broadcasting ", dec); |
| 1156 | /* broadcast this message to all components */ |
| 1157 | // TITAN DOESN'T DO THIS, *SIGH*: "BSSGP_SP.send(dec) to all component;" |
| 1158 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 1159 | if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) { |
| 1160 | f_send_bssgp_dec(dec, ClientTable[i].comp_ref, BSSGP_SP); |
| 1161 | } |
| 1162 | } |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | /* Any other SIG BSSGP message: If it has TLLI, route to component; otherwise broadcast */ |
| 1167 | [] BVC.receive(tr_ptp_BnsUdInd(?, 0)) -> value udi { |
| 1168 | var BssgpDecoded dec := f_dec_bssgp(udi.bssgp); |
| 1169 | var template OCT4 tlli := f_bssgp_get_tlli(udi.bssgp); |
| 1170 | if (isvalue(tlli)) { |
| 1171 | vc_conn := f_tbl_comp_by_tlli(valueof(tlli)); |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 1172 | if (vc_conn == null) { |
| 1173 | g_cfg.create_cb.apply(g_cfg.bvci, g_cfg.cell_id, valueof(tlli), dec); |
| 1174 | } else { |
| 1175 | f_send_bssgp_dec(dec, vc_conn, BSSGP_SP_SIG); |
| 1176 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1177 | } else { |
| 1178 | log("No TLLI: Broadcasting ", dec); |
| 1179 | /* broadcast this message to all components */ |
| 1180 | // TITAN DOESN'T DO THIS, *SIGH*: "BSSGP_SP.send(dec) to all component;" |
| 1181 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 1182 | if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) { |
| 1183 | f_send_bssgp_dec(dec, ClientTable[i].comp_ref, BSSGP_SP_SIG); |
| 1184 | } |
| 1185 | } |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | /* ConnHdlr sends BSSGP on BVCI=0 port: forward it to BSSGP_CT */ |
| 1190 | [] BSSGP_SP_SIG.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1191 | BVC.send(ts_ptp_BnsUdReq(bs_pdu, 0, g_bvc_lsp)); |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | /* ConnHdlr sends BSSGP on BVCI=PTP port: forward it to BSSGP_CT */ |
| 1195 | [] BSSGP_SP.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn { |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1196 | 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] | 1197 | } |
| 1198 | |
| 1199 | #ifdef BSSGP_EM_L3 |
| 1200 | /* ConnHdlr sends L3: Encode and send as UL_UD / DL_UD */ |
| 1201 | [g_sgsn_role] BSSGP_SP.receive(PDU_L3_SGSN_MS:?) -> value l3_mt sender vc_conn { |
| 1202 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1203 | var OCT4 tlli := ClientTable[idx].tlli; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1204 | var octetstring l3_enc := enc_PDU_L3_SGSN_MS(l3_mt); |
| 1205 | var BIT4 sapi := f_llc_sapi_by_l3_mt(l3_mt); |
| 1206 | var integer n_u := f_llc_get_n_u_tx(ClientTable[idx].llc[bit2int(sapi)]); |
| 1207 | 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] | 1208 | 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] | 1209 | } |
| 1210 | [not g_sgsn_role] BSSGP_SP.receive(PDU_L3_MS_SGSN:?) -> value l3_mo sender vc_conn { |
| 1211 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1212 | var OCT4 tlli := ClientTable[idx].tlli; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1213 | var octetstring l3_enc := enc_PDU_L3_MS_SGSN(l3_mo); |
| 1214 | var BIT4 sapi := f_llc_sapi_by_l3_mo(l3_mo); |
| 1215 | var integer n_u := f_llc_get_n_u_tx(ClientTable[idx].llc[bit2int(sapi)]); |
| 1216 | 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] | 1217 | 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] | 1218 | } |
| 1219 | #endif |
| 1220 | |
| 1221 | /* ConnHdlr sends raw LLC: Encode and send as UL_UD / DL_UD */ |
| 1222 | [not g_sgsn_role] BSSGP_SP.receive(PDU_LLC:?) -> value llc sender vc_conn { |
| 1223 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1224 | var OCT4 tlli := ClientTable[idx].tlli; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1225 | var octetstring llc_enc := enc_PDU_LLC(llc); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1226 | 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] | 1227 | } |
| 1228 | [g_sgsn_role] BSSGP_SP.receive(PDU_LLC:?) -> value llc sender vc_conn { |
| 1229 | var integer idx := f_tbl_idx_by_comp(vc_conn); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1230 | var OCT4 tlli := ClientTable[idx].tlli; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1231 | var octetstring llc_enc := enc_PDU_LLC(llc); |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1232 | 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] | 1233 | } |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1234 | |
Harald Welte | 71449b0 | 2020-12-09 11:58:23 +0100 | [diff] [blame] | 1235 | /* Testcase sends us BSSGP on global port */ |
| 1236 | [] GLOBAL.receive(PDU_BSSGP:?)-> value bs_pdu sender vc_conn { |
| 1237 | BVC.send(ts_ptp_BnsUdReq(bs_pdu, g_cfg.bvci, g_bvc_lsp)); |
| 1238 | } |
| 1239 | |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1240 | [] MGMT.receive(BssgpBlockRequest:?) -> value bbr { |
| 1241 | f_ptp_sendBlock(bbr.cause); |
| 1242 | } |
Harald Welte | 853c0ad | 2018-02-15 17:45:29 +0100 | [diff] [blame] | 1243 | } |
| 1244 | |
Harald Welte | ab50cc2 | 2020-11-25 17:11:08 +0100 | [diff] [blame] | 1245 | private altstep as_ptp_handle_inbound_reset() runs on BSSGP_BVC_CT { |
| 1246 | var NsUnitdataIndication udi; |
| 1247 | /* we are a SGSN: BSS/PCU-originated RESET must have a cell ID */ |
| 1248 | [g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET(?, g_cfg.bvci, g_cfg.cell_id), 0)) -> value udi { |
| 1249 | log("Rx BVC-RESET from BVCI=", g_cfg.bvci); |
Harald Welte | 3c90515 | 2020-11-26 20:56:09 +0100 | [diff] [blame] | 1250 | if (MGMT.checkstate("Connected")) { |
| 1251 | MGMT.send(BssgpResetIndication:{g_cfg.bvci}); |
| 1252 | } |
Harald Welte | ab50cc2 | 2020-11-25 17:11:08 +0100 | [diff] [blame] | 1253 | /* Respond to RESET with correct BVCI but without CellID */ |
| 1254 | BVC.send(ts_ptp_BnsUdReq(ts_BVC_RESET_ACK(g_cfg.bvci, omit), 0, g_bvc_lsp)); |
| 1255 | /* FIXME: reset all state? What about clients? */ |
| 1256 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1257 | } |
| 1258 | /* we are a BSS/PCU: SGSN-originated RESET must not have a cell ID */ |
| 1259 | [not g_sgsn_role] BVC.receive(tr_ptp_BnsUdInd(tr_BVC_RESET(?, g_cfg.bvci, omit), 0)) -> value udi { |
| 1260 | log("Rx BVC-RESET from BVCI=", g_cfg.bvci); |
Harald Welte | 3c90515 | 2020-11-26 20:56:09 +0100 | [diff] [blame] | 1261 | if (MGMT.checkstate("Connected")) { |
| 1262 | MGMT.send(BssgpResetIndication:{g_cfg.bvci}); |
| 1263 | } |
Harald Welte | ab50cc2 | 2020-11-25 17:11:08 +0100 | [diff] [blame] | 1264 | /* Respond to RESET with correct BVCI with CellID */ |
| 1265 | BVC.send(ts_ptp_BnsUdReq(ts_BVC_RESET_ACK(g_cfg.bvci, g_cfg.cell_id), 0, g_bvc_lsp)); |
| 1266 | /* FIXME: reset all state? What about clients? */ |
| 1267 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1268 | } |
| 1269 | } |
| 1270 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1271 | /* Events permitted in all states */ |
| 1272 | private altstep as_ptp_allstate() runs on BSSGP_BVC_CT { |
| 1273 | var NsUnitdataIndication udi; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1274 | var BssgpResetRequest brr; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1275 | var BSSGP_Client_CT vc_conn; |
| 1276 | var OCT4 tlli, tlli_old; |
| 1277 | var hexstring imsi; |
| 1278 | |
| 1279 | /* Signaling BVC was reset */ |
| 1280 | [] BVC.receive(BssgpResetIndication:{0}) { |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1281 | if (MGMT.checkstate("Connected")) { |
| 1282 | MGMT.send(BssgpResetIndication:{0}); |
| 1283 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1284 | if (not g_sgsn_role) { |
| 1285 | f_ptp_change_state(BVC_S_BLOCKED); |
| 1286 | /* when the BSS side signaling PTP is RESET, all PTP BVC must start the |
| 1287 | * reset procedure */ |
| 1288 | f_ptp_sendReset(); |
| 1289 | } else { |
| 1290 | f_ptp_change_state(BVC_S_UNBLOCKED); |
| 1291 | } |
| 1292 | } |
| 1293 | |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1294 | /* Ignore those for now */ |
| 1295 | [] BVC.receive(ASP_Event:?) { } |
| 1296 | [] BVC.receive(BssgpStatusIndication:?) { } |
| 1297 | |
| 1298 | /* catch-all */ |
| 1299 | [] BVC.receive(tr_ptp_BnsUdInd(?, 0)) -> value udi { |
| 1300 | setverdict(fail, "Received unexpected NS (SIG): ", udi); |
| 1301 | } |
| 1302 | [] BVC.receive(tr_ptp_BnsUdInd(?, ?)) -> value udi { |
| 1303 | setverdict(fail, "Received unexpected NS (PTP): ", udi); |
| 1304 | } |
| 1305 | [] BVC.receive { |
| 1306 | setverdict(fail, "Received unexpected message from BSSGP_CT"); |
| 1307 | } |
| 1308 | |
| 1309 | /* registration/deregistration of Clients (per-TLLI components) */ |
| 1310 | [] BSSGP_PROC.getcall(BSSGP_register_client:{?,?}) -> param(imsi, tlli) sender vc_conn { |
| 1311 | f_tbl_client_add(imsi, tlli, vc_conn); |
| 1312 | BSSGP_PROC.reply(BSSGP_register_client:{imsi, tlli}) to vc_conn; |
| 1313 | } |
| 1314 | [] BSSGP_PROC.getcall(BSSGP_unregister_client:{?}) -> param(imsi) sender vc_conn { |
| 1315 | f_tbl_client_del(imsi, vc_conn); |
| 1316 | BSSGP_PROC.reply(BSSGP_unregister_client:{imsi}) to vc_conn; |
| 1317 | } |
| 1318 | [] BSSGP_PROC.getcall(BSSGP_llgmm_assign:{?,?}) -> param(tlli_old, tlli) sender vc_conn { |
| 1319 | f_tbl_client_llgmm_assign(tlli_old, tlli, vc_conn); |
| 1320 | BSSGP_PROC.reply(BSSGP_llgmm_assign:{tlli_old, tlli}) to vc_conn; |
| 1321 | } |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1322 | |
| 1323 | [] MGMT.receive(BssgpResetRequest:?) -> value brr { |
Harald Welte | 52cecbb | 2020-11-25 21:57:31 +0100 | [diff] [blame] | 1324 | f_ptp_change_state(BVC_S_BLOCKED); |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1325 | f_ptp_sendReset(brr.cause); |
| 1326 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | /* main loop for per-BVC component */ |
| 1330 | private function f_bssgp_bvc_ScanEvents() runs on BSSGP_BVC_CT { |
| 1331 | while (true) { |
| 1332 | alt { |
| 1333 | [g_ptp_bvc_state == BVC_S_BLOCKED] as_ptp_blocked(); |
| 1334 | [g_ptp_bvc_state == BVC_S_UNBLOCKED] as_ptp_unblocked(); |
| 1335 | [] as_ptp_allstate(); |
| 1336 | } |
| 1337 | } |
| 1338 | } |
| 1339 | |
| 1340 | /* main function for per-BVC Component */ |
Harald Welte | fba7afd | 2020-11-24 23:12:31 +0100 | [diff] [blame] | 1341 | private function f_bssgp_bvc_main(BssgpBvcConfig cfg, boolean sgsn_role, Nsei nsei, charstring id) runs on BSSGP_BVC_CT { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1342 | g_cfg := cfg; |
Harald Welte | fba7afd | 2020-11-24 23:12:31 +0100 | [diff] [blame] | 1343 | g_nsei := nsei; |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1344 | g_bvc_lsp := cfg.bvci; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1345 | g_sgsn_role := sgsn_role; |
| 1346 | f_bssgp_bvc_ScanEvents(); |
| 1347 | } |
| 1348 | |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1349 | template (value) NsUnitdataRequest ts_ptp_BnsUdReq(template (value) PDU_BSSGP pdu, template (value) BssgpBvci bvci, |
| 1350 | template (value) integer lsp) := { |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1351 | bvci := bvci, |
| 1352 | nsei := 0, // overwritten in BSSGP_CT |
Harald Welte | c450552 | 2020-11-11 18:55:09 +0100 | [diff] [blame] | 1353 | lsp := lsp, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1354 | /* for some weird reason we get "Dynamic test case error: Text encoder: Encoding an |
| 1355 | * unbound integer value." when trying to send the reocrd rather than the octetstring */ |
| 1356 | //sdu := omit, |
| 1357 | //bssgp := valueof(pdu) |
| 1358 | sdu := enc_PDU_BSSGP(valueof(pdu)), |
| 1359 | bssgp := omit |
| 1360 | } |
| 1361 | |
| 1362 | template (present) NsUnitdataIndication tr_ptp_BnsUdInd(template (present) PDU_BSSGP pdu, template (present) BssgpBvci bvci) := { |
| 1363 | bvci := bvci, |
| 1364 | nsei := ?, |
Harald Welte | 80a249a | 2020-11-17 19:57:40 +0100 | [diff] [blame] | 1365 | nsvci := ?, |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1366 | sdu := *, |
| 1367 | bssgp := pdu |
| 1368 | } |
| 1369 | |
| 1370 | /* change state of PTP BVC; broadcast state change to clients */ |
| 1371 | private function f_ptp_change_state(BvcState new_state) runs on BSSGP_BVC_CT { |
| 1372 | if (new_state == g_ptp_bvc_state) { |
| 1373 | return; |
| 1374 | } |
| 1375 | log("BVCI(", g_cfg.bvci, ") State Transition: ", g_ptp_bvc_state, " -> ", new_state); |
| 1376 | g_ptp_bvc_state := new_state; |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1377 | if (MGMT.checkstate("Connected")) { |
Harald Welte | fba7afd | 2020-11-24 23:12:31 +0100 | [diff] [blame] | 1378 | MGMT.send(ts_BssgpStsInd(g_nsei, g_cfg.bvci, g_ptp_bvc_state)); |
Harald Welte | 199f386 | 2020-11-15 22:37:45 +0100 | [diff] [blame] | 1379 | } |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1380 | for (var integer i := 0; i < sizeof(ClientTable); i := i+1) { |
| 1381 | if (isbound(ClientTable[i].comp_ref) and ClientTable[i].comp_ref != null) { |
Harald Welte | fba7afd | 2020-11-24 23:12:31 +0100 | [diff] [blame] | 1382 | BSSGP_SP.send(ts_BssgpStsInd(g_nsei, g_cfg.bvci, g_ptp_bvc_state)) to ClientTable[i].comp_ref; |
Harald Welte | 5339b2e | 2020-10-04 22:52:56 +0200 | [diff] [blame] | 1383 | } |
| 1384 | } |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | /* attempt to extract the TLLI from a BSSGP PDU */ |
| 1388 | function f_bssgp_get_tlli(PDU_BSSGP bssgp) return template OCT4 { |
| 1389 | if (ischosen(bssgp.pDU_BSSGP_DL_UNITDATA)) { |
| 1390 | return bssgp.pDU_BSSGP_DL_UNITDATA.tLLI_current; |
| 1391 | } else if (ischosen(bssgp.pDU_BSSGP_UL_UNITDATA)) { |
| 1392 | return bssgp.pDU_BSSGP_UL_UNITDATA.tLLI; |
| 1393 | } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY)) { |
| 1394 | return bssgp.pDU_BSSGP_RA_CAPABILITY.tLLI.tLLI_Value; |
| 1395 | } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE)) { |
| 1396 | return bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE.tLLI.tLLI_Value; |
| 1397 | } else if (ischosen(bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK)) { |
| 1398 | return bssgp.pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK.tLLI.tLLI_Value; |
| 1399 | } else if (ischosen(bssgp.pDU_BSSGP_RADIO_STATUS)) { |
| 1400 | return bssgp.pDU_BSSGP_RADIO_STATUS.tLLI.tLLI_Value; |
| 1401 | } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND)) { |
| 1402 | return bssgp.pDU_BSSGP_SUSPEND.tLLI.tLLI_Value; |
| 1403 | } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND_ACK)) { |
| 1404 | return bssgp.pDU_BSSGP_SUSPEND_ACK.tLLI.tLLI_Value; |
| 1405 | } else if (ischosen(bssgp.pDU_BSSGP_SUSPEND_NACK)) { |
| 1406 | return bssgp.pDU_BSSGP_SUSPEND_NACK.tLLI.tLLI_Value; |
| 1407 | } else if (ischosen(bssgp.pDU_BSSGP_RESUME)) { |
| 1408 | return bssgp.pDU_BSSGP_RESUME.tLLI.tLLI_Value; |
| 1409 | } else if (ischosen(bssgp.pDU_BSSGP_RESUME_ACK)) { |
| 1410 | return bssgp.pDU_BSSGP_RESUME_ACK.tLLI.tLLI_Value; |
| 1411 | } else if (ischosen(bssgp.pDU_BSSGP_RESUME_NACK)) { |
| 1412 | return bssgp.pDU_BSSGP_RESUME_NACK.tLLI.tLLI_Value; |
| 1413 | } else if (ischosen(bssgp.pDU_BSSGP_FLUSH_LL)) { |
| 1414 | return bssgp.pDU_BSSGP_FLUSH_LL.tLLI.tLLI_Value; |
| 1415 | } else if (ischosen(bssgp.pDU_BSSGP_FLUSH_LL_ACK)) { |
| 1416 | return bssgp.pDU_BSSGP_FLUSH_LL_ACK.tLLI.tLLI_Value; |
| 1417 | } else if (ischosen(bssgp.pDU_BSSGP_LLC_DISCARDED)) { |
| 1418 | return bssgp.pDU_BSSGP_LLC_DISCARDED.tLLI.tLLI_Value; |
| 1419 | } else if (ischosen(bssgp.pDU_BSSGP_LLC_DISCARDED)) { |
| 1420 | return bssgp.pDU_BSSGP_LLC_DISCARDED.tLLI.tLLI_Value; |
| 1421 | } else if (ischosen(bssgp.pDU_BSSGP_PAGING_CS) and |
| 1422 | isvalue(bssgp.pDU_BSSGP_PAGING_CS.tLLI)) { |
| 1423 | return bssgp.pDU_BSSGP_PAGING_CS.tLLI.tLLI_Value; |
| 1424 | } else if (ischosen(bssgp.pDU_BSSGP_FLOW_CONTROL_MS)) { |
| 1425 | return bssgp.pDU_BSSGP_FLOW_CONTROL_MS.tLLI.tLLI_Value; |
| 1426 | } else if (ischosen(bssgp.pDU_BSSGP_FLOW_CONTROL_MS_ACK)) { |
| 1427 | return bssgp.pDU_BSSGP_FLOW_CONTROL_MS_ACK.tLLI.tLLI_Value; |
| 1428 | } |
| 1429 | /* TODO: Handover, PFC, LCS */ |
| 1430 | return omit; |
| 1431 | } |
| 1432 | |
Harald Welte | f70997d | 2018-02-17 10:11:19 +0100 | [diff] [blame] | 1433 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 1434 | |
Harald Welte | 1733a38 | 2017-07-23 17:26:17 +0200 | [diff] [blame] | 1435 | } |